From 5355709f4eb8a4376c2868d9422c4f08dc344e6b Mon Sep 17 00:00:00 2001 From: klee0kai Date: Sat, 27 Sep 2025 12:55:57 +0200 Subject: [PATCH 001/122] migrate to gradle kotlin p1 --- build.gradle | 6 +-- kotlin_lib/build.gradle | 12 +----- libs.versions.toml | 46 ++++++++++++++++++++ settings.gradle | 39 ----------------- settings.gradle.kts | 47 +++++++++++++++++++++ test_feature/finance/api/build.gradle | 10 ----- test_feature/finance/api/build.gradle.kts | 6 +++ test_feature/finance/impl/build.gradle | 19 --------- test_feature/finance/impl/build.gradle.kts | 15 +++++++ test_feature/hr/api/build.gradle | 10 ----- test_feature/hr/api/build.gradle.kts | 6 +++ test_feature/hr/impl/build.gradle | 18 -------- test_feature/hr/impl/build.gradle.kts | 14 ++++++ test_feature/planning/impl/build.gradle | 20 --------- test_feature/planning/impl/build.gradle.kts | 16 +++++++ test_feature_core_deps/build.gradle | 24 ----------- test_feature_core_deps/build.gradle.kts | 13 ++++++ tests/build.gradle | 21 --------- tests/build.gradle.kts | 13 ++++++ tests_compile/build.gradle | 21 --------- tests_compile/build.gradle.kts | 14 ++++++ tests_ext/build.gradle | 23 ---------- tests_ext/build.gradle.kts | 15 +++++++ tests_kotlin/build.gradle | 24 +++-------- tests_wraps/build.gradle | 21 --------- tests_wraps/build.gradle.kts | 13 ++++++ tests_wraps_kotlin/build.gradle | 29 ------------- tests_wraps_kotlin/build.gradle.kts | 15 +++++++ wiki_java/build.gradle | 13 ------ wiki_java/build.gradle.kts | 13 ++++++ wiki_kotlin/build.gradle | 23 ---------- wiki_kotlin/build.gradle.kts | 15 +++++++ 32 files changed, 271 insertions(+), 323 deletions(-) create mode 100644 libs.versions.toml delete mode 100644 settings.gradle create mode 100644 settings.gradle.kts delete mode 100644 test_feature/finance/api/build.gradle create mode 100644 test_feature/finance/api/build.gradle.kts delete mode 100644 test_feature/finance/impl/build.gradle create mode 100644 test_feature/finance/impl/build.gradle.kts delete mode 100644 test_feature/hr/api/build.gradle create mode 100644 test_feature/hr/api/build.gradle.kts delete mode 100644 test_feature/hr/impl/build.gradle create mode 100644 test_feature/hr/impl/build.gradle.kts delete mode 100644 test_feature/planning/impl/build.gradle create mode 100644 test_feature/planning/impl/build.gradle.kts delete mode 100644 test_feature_core_deps/build.gradle create mode 100644 test_feature_core_deps/build.gradle.kts delete mode 100644 tests/build.gradle create mode 100644 tests/build.gradle.kts delete mode 100644 tests_compile/build.gradle create mode 100644 tests_compile/build.gradle.kts delete mode 100644 tests_ext/build.gradle create mode 100644 tests_ext/build.gradle.kts delete mode 100644 tests_wraps/build.gradle create mode 100644 tests_wraps/build.gradle.kts delete mode 100644 tests_wraps_kotlin/build.gradle create mode 100644 tests_wraps_kotlin/build.gradle.kts delete mode 100644 wiki_java/build.gradle create mode 100644 wiki_java/build.gradle.kts delete mode 100644 wiki_kotlin/build.gradle create mode 100644 wiki_kotlin/build.gradle.kts diff --git a/build.gradle b/build.gradle index 77949b39..bb544ed8 100644 --- a/build.gradle +++ b/build.gradle @@ -5,13 +5,13 @@ buildscript { google() } dependencies { - classpath 'com.android.tools.build:gradle:7.2.2' + classpath("com.android.tools.build:gradle:7.2.2") } } allprojects { - group 'com.github.klee0kai.stone' - version '1.0.7' + group("com.github.klee0kai.stone") + version("1.0.7") } diff --git a/kotlin_lib/build.gradle b/kotlin_lib/build.gradle index 917356d0..a153c973 100644 --- a/kotlin_lib/build.gradle +++ b/kotlin_lib/build.gradle @@ -1,6 +1,6 @@ plugins { - id "org.jetbrains.kotlin.jvm" version '1.7.0' - id "org.jetbrains.kotlin.kapt" version "1.7.21" + id("org.jetbrains.kotlin.jvm").version("1.7.0") + id("org.jetbrains.kotlin.kapt").version("1.7.21") } apply from: '../jitpack.gradle' @@ -18,14 +18,6 @@ publishing { } } -compileKotlin { - kotlinOptions.jvmTarget = JavaVersion.VERSION_11 -} - -compileTestKotlin { - kotlinOptions.jvmTarget = JavaVersion.VERSION_11 -} - dependencies { api(project(":stone_lib")) diff --git a/libs.versions.toml b/libs.versions.toml new file mode 100644 index 00000000..4bb6eeb6 --- /dev/null +++ b/libs.versions.toml @@ -0,0 +1,46 @@ +[versions] + +crossbox = "0.0.1" + +kotlin = "2.1.10" +ksp = "2.1.10-1.0.30" + +jetbrain-immutable = "0.3.7" +jetbrain-coroutines = "1.10.1" + +stone = "1.0.7" +kotlinpoet = "2.0.0" + +jupiter = "5.9.2" + + +[libraries] + +jetbrain-immutable = { group = "org.jetbrains.kotlinx", name = "kotlinx-collections-immutable", version.ref = "jetbrain-immutable" } +jetbrain-coroutines = { group = "org.jetbrains.kotlinx", name = "kotlinx-coroutines-core", version.ref = "jetbrain-coroutines" } + +# https://github.com/klee0kai/stone +stone-kotlin = { group = "com.github.klee0kai.stone", name = "kotlin_lib", version.ref = "stone" } +stone-kapt = { group = "com.github.klee0kai.stone", name = "stone_processor", version.ref = "stone" } + +ksp = { group = "com.google.devtools.ksp", name = "symbol-processing-api", version.ref = "ksp" } + +kotlinpoet = { group = "com.squareup", name = "kotlinpoet", version.ref = "kotlinpoet" } +kotlinpoet-ksp = { group = "com.squareup", name = "kotlinpoet-ksp", version.ref = "kotlinpoet" } + +# test +jupiter-api = { group = "org.junit.jupiter", name = "junit-jupiter-api", version.ref = "jupiter" } +jupiter-engine = { group = "org.junit.jupiter", name = "junit-jupiter-engine", version.ref = "jupiter" } + +[bundles] + +kotlin = ["jetbrain-coroutines", "jetbrain-immutable"] +kotlinpoet = ["kotlinpoet", "kotlinpoet-ksp"] + +[plugins] + +ksp = { id = "com.google.devtools.ksp", version.ref = "ksp" } +jvm = { id = "org.jetbrains.kotlin.jvm", version.ref = "kotlin" } + +publish-maven = { id = "org.gradle.maven-publish" } +publish-crossbox = { id = "com.github.klee0kai.crossbox.publish" } diff --git a/settings.gradle b/settings.gradle deleted file mode 100644 index f0f0000d..00000000 --- a/settings.gradle +++ /dev/null @@ -1,39 +0,0 @@ -pluginManagement { - repositories { - gradlePluginPortal() - google() - mavenCentral() - } -} -dependencyResolutionManagement { - repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS) - repositories { - mavenLocal() - google() - mavenCentral() - } -} - -rootProject.name = 'Stone' -include 'stone_lib' -include 'stone_processor' -include 'android_lib' -include 'kotlin_lib' - -include 'wiki_java' -include 'wiki_kotlin' -include 'tests' -include 'tests_ext' -include 'tests_kotlin' -include 'tests_wraps' -include 'tests_wraps_kotlin' -include 'tests_compile' -include ':test_feature:companies:consulting' -include ':test_feature:hr:api' -include ':test_feature:hr:impl' -include ':test_feature:planning:api' -include ':test_feature:planning:impl' -include ':test_feature:finance:api' -include ':test_feature:finance:impl' -include ':test_feature_core_deps' - diff --git a/settings.gradle.kts b/settings.gradle.kts new file mode 100644 index 00000000..3a935204 --- /dev/null +++ b/settings.gradle.kts @@ -0,0 +1,47 @@ +import org.gradle.api.initialization.resolve.RepositoriesMode + +pluginManagement { + repositories { + gradlePluginPortal() + google() + mavenCentral() + } +} +dependencyResolutionManagement { + repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS) + repositories { + mavenLocal() + google() + mavenCentral() + } + + versionCatalogs { + create("libs") { + from(files("libs.versions.toml")) + } + } +} + +rootProject.name = "Stone" +include(":stone_lib") +include(":stone_processor") +include(":android_lib") +include(":kotlin_lib") + +include(":wiki_java") +include(":wiki_kotlin") +include(":tests") +include(":tests_ext") +include(":tests_kotlin") +include(":tests_wraps") +include(":tests_wraps_kotlin") +include(":tests_compile") +include(":test_feature:companies:consulting") +include(":test_feature:hr:api") +include(":test_feature:hr:impl") +include(":test_feature:planning:api") +include(":test_feature:planning:impl") +include(":test_feature:finance:api") +include(":test_feature:finance:impl") +include(":test_feature_core_deps") + diff --git a/test_feature/finance/api/build.gradle b/test_feature/finance/api/build.gradle deleted file mode 100644 index 1349fc97..00000000 --- a/test_feature/finance/api/build.gradle +++ /dev/null @@ -1,10 +0,0 @@ -plugins { - id 'java' -} - -group = 'com.github.klee0kai.stone.test_feature.finance' - -java { - sourceCompatibility = JavaVersion.VERSION_11 - targetCompatibility = JavaVersion.VERSION_11 -} \ No newline at end of file diff --git a/test_feature/finance/api/build.gradle.kts b/test_feature/finance/api/build.gradle.kts new file mode 100644 index 00000000..00946c9b --- /dev/null +++ b/test_feature/finance/api/build.gradle.kts @@ -0,0 +1,6 @@ +plugins { + id("java") +} + +group = "com.github.klee0kai.stone.test_feature.finance" + diff --git a/test_feature/finance/impl/build.gradle b/test_feature/finance/impl/build.gradle deleted file mode 100644 index 8ab0b18f..00000000 --- a/test_feature/finance/impl/build.gradle +++ /dev/null @@ -1,19 +0,0 @@ -plugins { - id 'java' -} - -group = 'com.github.klee0kai.stone.test_feature.finance' - -dependencies { - implementation project(path: ':test_feature:finance:api') - implementation project(path: ':test_feature:hr:api') - implementation project(path: ':test_feature:planning:api') - - implementation project(":stone_lib") - annotationProcessor project(":stone_processor") -} - -java { - sourceCompatibility = JavaVersion.VERSION_11 - targetCompatibility = JavaVersion.VERSION_11 -} \ No newline at end of file diff --git a/test_feature/finance/impl/build.gradle.kts b/test_feature/finance/impl/build.gradle.kts new file mode 100644 index 00000000..b8dc5a50 --- /dev/null +++ b/test_feature/finance/impl/build.gradle.kts @@ -0,0 +1,15 @@ +plugins { + id("java") +} + +group = "com.github.klee0kai.stone.test_feature.finance" + +dependencies { + implementation(project(":test_feature:finance:api")) + implementation(project(":test_feature:hr:api")) + implementation(project(":test_feature:planning:api")) + + implementation(project(":stone_lib")) + annotationProcessor(project(":stone_processor")) +} + diff --git a/test_feature/hr/api/build.gradle b/test_feature/hr/api/build.gradle deleted file mode 100644 index dec1b237..00000000 --- a/test_feature/hr/api/build.gradle +++ /dev/null @@ -1,10 +0,0 @@ -plugins { - id 'java' -} - -group = 'com.github.klee0kai.stone.test_feature.hr' - -java { - sourceCompatibility = JavaVersion.VERSION_11 - targetCompatibility = JavaVersion.VERSION_11 -} \ No newline at end of file diff --git a/test_feature/hr/api/build.gradle.kts b/test_feature/hr/api/build.gradle.kts new file mode 100644 index 00000000..73bcea1e --- /dev/null +++ b/test_feature/hr/api/build.gradle.kts @@ -0,0 +1,6 @@ +plugins { + id("java") +} + +group = "com.github.klee0kai.stone.test_feature.hr" + diff --git a/test_feature/hr/impl/build.gradle b/test_feature/hr/impl/build.gradle deleted file mode 100644 index d0fea063..00000000 --- a/test_feature/hr/impl/build.gradle +++ /dev/null @@ -1,18 +0,0 @@ -plugins { - id 'java' -} - -group = 'com.github.klee0kai.stone.test_feature.hr' - - -dependencies { - implementation project(path: ':test_feature:hr:api') - - implementation project(":stone_lib") - annotationProcessor project(":stone_processor") -} - -java { - sourceCompatibility = JavaVersion.VERSION_11 - targetCompatibility = JavaVersion.VERSION_11 -} \ No newline at end of file diff --git a/test_feature/hr/impl/build.gradle.kts b/test_feature/hr/impl/build.gradle.kts new file mode 100644 index 00000000..fac0dca0 --- /dev/null +++ b/test_feature/hr/impl/build.gradle.kts @@ -0,0 +1,14 @@ +plugins { + id("java") +} + +group = "com.github.klee0kai.stone.test_feature.hr" + + +dependencies { + implementation(project(":test_feature:hr:api")) + + implementation(project(":stone_lib")) + annotationProcessor(project(":stone_processor")) +} + diff --git a/test_feature/planning/impl/build.gradle b/test_feature/planning/impl/build.gradle deleted file mode 100644 index 0928b5d0..00000000 --- a/test_feature/planning/impl/build.gradle +++ /dev/null @@ -1,20 +0,0 @@ -plugins { - id 'java' -} - -group = 'com.github.klee0kai.stone.test_feature.planning' - - -dependencies { - implementation project(path: ':test_feature:planning:api') - implementation project(path: ':test_feature:finance:api') - implementation project(path: ':test_feature:hr:api') - - implementation project(":stone_lib") - annotationProcessor project(":stone_processor") -} - -java { - sourceCompatibility = JavaVersion.VERSION_11 - targetCompatibility = JavaVersion.VERSION_11 -} \ No newline at end of file diff --git a/test_feature/planning/impl/build.gradle.kts b/test_feature/planning/impl/build.gradle.kts new file mode 100644 index 00000000..df31a177 --- /dev/null +++ b/test_feature/planning/impl/build.gradle.kts @@ -0,0 +1,16 @@ +plugins { + id("java") +} + +group = "com.github.klee0kai.stone.test_feature.planning" + + +dependencies { + implementation(project(":test_feature:planning:api")) + implementation(project(":test_feature:finance:api")) + implementation(project(":test_feature:hr:api")) + + implementation(project(":stone_lib")) + annotationProcessor(project(":stone_processor")) +} + diff --git a/test_feature_core_deps/build.gradle b/test_feature_core_deps/build.gradle deleted file mode 100644 index 8cfc328e..00000000 --- a/test_feature_core_deps/build.gradle +++ /dev/null @@ -1,24 +0,0 @@ -plugins { - id "org.jetbrains.kotlin.jvm" version '1.7.0' - id "org.jetbrains.kotlin.kapt" version "1.7.21" -} - - -test { - useJUnitPlatform() -} - -java { - sourceCompatibility = JavaVersion.VERSION_11 - targetCompatibility = JavaVersion.VERSION_11 -} - - -dependencies { - implementation(project(":kotlin_lib")) - kapt(project(":stone_processor")) - - - testImplementation 'org.junit.jupiter:junit-jupiter-api:5.9.1' - testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.11.0-M2' -} diff --git a/test_feature_core_deps/build.gradle.kts b/test_feature_core_deps/build.gradle.kts new file mode 100644 index 00000000..3be87d78 --- /dev/null +++ b/test_feature_core_deps/build.gradle.kts @@ -0,0 +1,13 @@ +plugins { + id("org.jetbrains.kotlin.jvm").version("1.7.0") + id("org.jetbrains.kotlin.kapt").version("1.7.21") +} + + +dependencies { + implementation(project(":kotlin_lib")) + kapt(project(":stone_processor")) + + testImplementation("org.junit.jupiter:junit-jupiter-api:5.9.1") + testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:5.11.0-M2") +} diff --git a/tests/build.gradle b/tests/build.gradle deleted file mode 100644 index 51958316..00000000 --- a/tests/build.gradle +++ /dev/null @@ -1,21 +0,0 @@ -plugins { - id 'java' -} - -dependencies { - implementation project(":stone_lib") - annotationProcessor project(":stone_processor") - - - testImplementation 'org.junit.jupiter:junit-jupiter-api:5.9.1' - testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.9.1' -} - -test { - useJUnitPlatform() -} - -java { - sourceCompatibility = JavaVersion.VERSION_11 - targetCompatibility = JavaVersion.VERSION_11 -} \ No newline at end of file diff --git a/tests/build.gradle.kts b/tests/build.gradle.kts new file mode 100644 index 00000000..6d59fc08 --- /dev/null +++ b/tests/build.gradle.kts @@ -0,0 +1,13 @@ +plugins { + id("java") +} + +dependencies { + implementation(project(":stone_lib")) + annotationProcessor(project(":stone_processor")) + + + testImplementation("org.junit.jupiter:junit-jupiter-api:5.9.1") + testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:5.9.1") +} + diff --git a/tests_compile/build.gradle b/tests_compile/build.gradle deleted file mode 100644 index 728c3d0e..00000000 --- a/tests_compile/build.gradle +++ /dev/null @@ -1,21 +0,0 @@ -plugins { - id 'java' -} - -dependencies { - implementation project(":stone_lib") - implementation project(":stone_processor") - - testImplementation 'com.google.testing.compile:compile-testing:0.21.0' - testImplementation 'org.junit.jupiter:junit-jupiter-api:5.9.1' - testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.9.1' -} - -test { - useJUnitPlatform() -} - -java { - sourceCompatibility = JavaVersion.VERSION_11 - targetCompatibility = JavaVersion.VERSION_11 -} \ No newline at end of file diff --git a/tests_compile/build.gradle.kts b/tests_compile/build.gradle.kts new file mode 100644 index 00000000..7010fbe4 --- /dev/null +++ b/tests_compile/build.gradle.kts @@ -0,0 +1,14 @@ +plugins { + id("java") +} + +dependencies { + implementation(project(":stone_lib")) + implementation(project(":stone_processor")) + + testImplementation("com.google.testing.compile:compile-testing:0.21.0") + testImplementation("org.junit.jupiter:junit-jupiter-api:5.9.1") + testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:5.9.1") +} + + diff --git a/tests_ext/build.gradle b/tests_ext/build.gradle deleted file mode 100644 index 49d9ac4a..00000000 --- a/tests_ext/build.gradle +++ /dev/null @@ -1,23 +0,0 @@ -plugins { - id 'java' -} - -test { - useJUnitPlatform() -} - -dependencies { - implementation project(":stone_lib") - annotationProcessor project(":stone_processor") - - implementation project(":tests") - - testImplementation 'org.junit.jupiter:junit-jupiter-api:5.9.1' - testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.9.1' -} - - -java { - sourceCompatibility = JavaVersion.VERSION_11 - targetCompatibility = JavaVersion.VERSION_11 -} \ No newline at end of file diff --git a/tests_ext/build.gradle.kts b/tests_ext/build.gradle.kts new file mode 100644 index 00000000..94a75d8f --- /dev/null +++ b/tests_ext/build.gradle.kts @@ -0,0 +1,15 @@ +plugins { + id("java") +} + +dependencies { + implementation(project(":stone_lib")) + annotationProcessor(project(":stone_processor")) + + implementation(project(":tests")) + + testImplementation("org.junit.jupiter:junit-jupiter-api:5.9.1") + testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:5.9.1") +} + + diff --git a/tests_kotlin/build.gradle b/tests_kotlin/build.gradle index dbc03b68..57bc7511 100644 --- a/tests_kotlin/build.gradle +++ b/tests_kotlin/build.gradle @@ -1,30 +1,16 @@ plugins { - id "org.jetbrains.kotlin.jvm" version '1.7.0' - id "org.jetbrains.kotlin.kapt" version "1.7.21" + id("org.jetbrains.kotlin.jvm").version("1.7.0") + id("org.jetbrains.kotlin.kapt").version("1.7.21") } -test { - useJUnitPlatform() -} - - -compileKotlin { - kotlinOptions.jvmTarget = JavaVersion.VERSION_11 -} - -compileTestKotlin { - kotlinOptions.jvmTarget = JavaVersion.VERSION_11 -} - - dependencies { - implementation project(":tests") + implementation(project(":tests")) implementation(project(":kotlin_lib")) kapt(project(":stone_processor")) - testImplementation 'org.junit.jupiter:junit-jupiter-api:5.9.0' - testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.9.0' + testImplementation("org.junit.jupiter:junit-jupiter-api:5.9.0") + testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:5.9.0") } diff --git a/tests_wraps/build.gradle b/tests_wraps/build.gradle deleted file mode 100644 index 51958316..00000000 --- a/tests_wraps/build.gradle +++ /dev/null @@ -1,21 +0,0 @@ -plugins { - id 'java' -} - -dependencies { - implementation project(":stone_lib") - annotationProcessor project(":stone_processor") - - - testImplementation 'org.junit.jupiter:junit-jupiter-api:5.9.1' - testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.9.1' -} - -test { - useJUnitPlatform() -} - -java { - sourceCompatibility = JavaVersion.VERSION_11 - targetCompatibility = JavaVersion.VERSION_11 -} \ No newline at end of file diff --git a/tests_wraps/build.gradle.kts b/tests_wraps/build.gradle.kts new file mode 100644 index 00000000..6d59fc08 --- /dev/null +++ b/tests_wraps/build.gradle.kts @@ -0,0 +1,13 @@ +plugins { + id("java") +} + +dependencies { + implementation(project(":stone_lib")) + annotationProcessor(project(":stone_processor")) + + + testImplementation("org.junit.jupiter:junit-jupiter-api:5.9.1") + testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:5.9.1") +} + diff --git a/tests_wraps_kotlin/build.gradle b/tests_wraps_kotlin/build.gradle deleted file mode 100644 index 2bc74994..00000000 --- a/tests_wraps_kotlin/build.gradle +++ /dev/null @@ -1,29 +0,0 @@ -plugins { - id "org.jetbrains.kotlin.jvm" version '1.7.0' - id "org.jetbrains.kotlin.kapt" version "1.7.21" -} - -test { - useJUnitPlatform() -} - - -compileKotlin { - kotlinOptions.jvmTarget = JavaVersion.VERSION_11 -} - -compileTestKotlin { - kotlinOptions.jvmTarget = JavaVersion.VERSION_11 -} - - -dependencies { - implementation project(":tests") - - implementation(project(":kotlin_lib")) - kapt(project(":stone_processor")) - - testImplementation 'org.junit.jupiter:junit-jupiter-api:5.9.1' - testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.9.1' -} - diff --git a/tests_wraps_kotlin/build.gradle.kts b/tests_wraps_kotlin/build.gradle.kts new file mode 100644 index 00000000..c3f53fc3 --- /dev/null +++ b/tests_wraps_kotlin/build.gradle.kts @@ -0,0 +1,15 @@ +plugins { + id("org.jetbrains.kotlin.jvm").version("1.7.0") + id("org.jetbrains.kotlin.kapt").version("1.7.21") +} + +dependencies { + implementation(project(":tests")) + + implementation(project(":kotlin_lib")) + kapt(project(":stone_processor")) + + testImplementation("org.junit.jupiter:junit-jupiter-api:5.9.1") + testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:5.9.1") +} + diff --git a/wiki_java/build.gradle b/wiki_java/build.gradle deleted file mode 100644 index bc7c8314..00000000 --- a/wiki_java/build.gradle +++ /dev/null @@ -1,13 +0,0 @@ -plugins { - id 'java' - id 'application' -} - -dependencies { - implementation project(":tests") - implementation project(":test_feature:finance:api") - - implementation(project(":kotlin_lib")) - annotationProcessor project(":stone_processor") -} - diff --git a/wiki_java/build.gradle.kts b/wiki_java/build.gradle.kts new file mode 100644 index 00000000..30bb82b8 --- /dev/null +++ b/wiki_java/build.gradle.kts @@ -0,0 +1,13 @@ +plugins { + id("java") + id("application") +} + +dependencies { + implementation(project(":tests")) + implementation(project(":test_feature:finance:api")) + + implementation(project(":kotlin_lib")) + annotationProcessor(project(":stone_processor")) +} + diff --git a/wiki_kotlin/build.gradle b/wiki_kotlin/build.gradle deleted file mode 100644 index 7e287b33..00000000 --- a/wiki_kotlin/build.gradle +++ /dev/null @@ -1,23 +0,0 @@ -plugins { - id "org.jetbrains.kotlin.jvm" version '1.7.0' - id "org.jetbrains.kotlin.kapt" version "1.7.21" -} - -compileKotlin { - kotlinOptions.jvmTarget = JavaVersion.VERSION_11 -} - -compileTestKotlin { - kotlinOptions.jvmTarget = JavaVersion.VERSION_11 -} - - -dependencies { - implementation project(":tests") - implementation project(":test_feature:finance:api") - - implementation(project(":kotlin_lib")) - kapt(project(":stone_processor")) - -} - diff --git a/wiki_kotlin/build.gradle.kts b/wiki_kotlin/build.gradle.kts new file mode 100644 index 00000000..c8271694 --- /dev/null +++ b/wiki_kotlin/build.gradle.kts @@ -0,0 +1,15 @@ +plugins { + id("org.jetbrains.kotlin.jvm").version("1.7.0") + id("org.jetbrains.kotlin.kapt").version("1.7.21") +} + + +dependencies { + implementation(project(":tests")) + implementation(project(":test_feature:finance:api")) + + implementation(project(":kotlin_lib")) + kapt(project(":stone_processor")) + +} + From 1f6de81e2abef18ef693d0732301db1fbf007869 Mon Sep 17 00:00:00 2001 From: klee0kai Date: Sun, 5 Oct 2025 23:52:15 +0200 Subject: [PATCH 002/122] migrate to gradle kotlin p2 --- .github/workflows/deploy_dev.yml | 2 - .github/workflows/deploy_pull_request.yml | 4 +- .github/workflows/deploy_release.yml | 4 +- android_lib/build.gradle | 52 ------------------- android_lib/build.gradle.kts | 39 ++++++++++++++ android_lib/proguard-rules.pro | 2 +- build.gradle | 18 ------- build.gradle.kts | 0 gradle/wrapper/gradle-wrapper.properties | 2 +- jitpack.gradle | 38 -------------- kotlin_lib/{build.gradle => build.gradle.kts} | 13 ++--- libs.versions.toml | 3 +- plugin_publish/.gitignore | 1 + plugin_publish/build.gradle.kts | 11 ++++ plugin_publish/settings.gradle.kts | 20 +++++++ .../klee0kai/stone/publish/MavenPublishExt.kt | 48 +++++++++++++++++ .../stone/publish/StonePublishPlugin.kt | 22 ++++++++ settings.gradle.kts | 6 +-- stone_lib/build.gradle | 43 --------------- stone_lib/build.gradle.kts | 26 ++++++++++ stone_processor/build.gradle | 41 --------------- stone_processor/build.gradle.kts | 30 +++++++++++ .../companies/consulting/build.gradle | 29 ----------- .../companies/consulting/build.gradle.kts | 26 ++++++++++ test_feature/finance/api/build.gradle.kts | 4 ++ test_feature/finance/impl/build.gradle.kts | 4 ++ test_feature/hr/api/build.gradle.kts | 4 ++ test_feature/hr/impl/build.gradle.kts | 3 ++ test_feature/planning/api/build.gradle | 11 ---- test_feature/planning/api/build.gradle.kts | 11 ++++ test_feature/planning/impl/build.gradle.kts | 3 ++ test_feature_core_deps/build.gradle.kts | 3 ++ tests/build.gradle.kts | 4 ++ tests_compile/build.gradle.kts | 4 ++ tests_ext/build.gradle.kts | 4 ++ .../{build.gradle => build.gradle.kts} | 6 ++- tests_wraps/build.gradle.kts | 4 ++ tests_wraps_kotlin/build.gradle.kts | 4 ++ wiki_java/build.gradle.kts | 4 ++ wiki_kotlin/build.gradle.kts | 3 ++ 40 files changed, 300 insertions(+), 256 deletions(-) delete mode 100644 android_lib/build.gradle create mode 100644 android_lib/build.gradle.kts delete mode 100644 build.gradle create mode 100644 build.gradle.kts delete mode 100644 jitpack.gradle rename kotlin_lib/{build.gradle => build.gradle.kts} (60%) create mode 100644 plugin_publish/.gitignore create mode 100644 plugin_publish/build.gradle.kts create mode 100644 plugin_publish/settings.gradle.kts create mode 100644 plugin_publish/src/main/kotlin/com/github/klee0kai/stone/publish/MavenPublishExt.kt create mode 100644 plugin_publish/src/main/kotlin/com/github/klee0kai/stone/publish/StonePublishPlugin.kt delete mode 100644 stone_lib/build.gradle create mode 100644 stone_lib/build.gradle.kts delete mode 100644 stone_processor/build.gradle create mode 100644 stone_processor/build.gradle.kts delete mode 100644 test_feature/companies/consulting/build.gradle create mode 100644 test_feature/companies/consulting/build.gradle.kts delete mode 100644 test_feature/planning/api/build.gradle create mode 100644 test_feature/planning/api/build.gradle.kts rename tests_kotlin/{build.gradle => build.gradle.kts} (75%) diff --git a/.github/workflows/deploy_dev.yml b/.github/workflows/deploy_dev.yml index f27c5de9..ded9b430 100644 --- a/.github/workflows/deploy_dev.yml +++ b/.github/workflows/deploy_dev.yml @@ -13,8 +13,6 @@ jobs: strategy: matrix: include: - - java_version: 11 - java_distribution: "temurin" - java_version: 17 java_distribution: "temurin" - java_version: 17 diff --git a/.github/workflows/deploy_pull_request.yml b/.github/workflows/deploy_pull_request.yml index ab8cee27..c5c2c6e7 100644 --- a/.github/workflows/deploy_pull_request.yml +++ b/.github/workflows/deploy_pull_request.yml @@ -9,8 +9,6 @@ jobs: strategy: matrix: include: - - java_version: 11 - java_distribution: "temurin" - java_version: 17 java_distribution: "temurin" - java_version: 17 @@ -21,7 +19,7 @@ jobs: name: Run Unit Tests on Java ${{ matrix.java_distribution }} ${{ matrix.java_version }} steps: - uses: actions/checkout@v3 - - name: set up JDK 11 + - name: set up JDK uses: actions/setup-java@v3 with: java-version: ${{ matrix.java_version }} diff --git a/.github/workflows/deploy_release.yml b/.github/workflows/deploy_release.yml index 1971eb2b..1f26fd56 100644 --- a/.github/workflows/deploy_release.yml +++ b/.github/workflows/deploy_release.yml @@ -36,10 +36,10 @@ jobs: if: ${{ always() }} steps: - uses: actions/checkout@v3 - - name: set up JDK 11 + - name: set up JDK uses: actions/setup-java@v3 with: - java-version: '11' + java-version: '17' distribution: 'temurin' cache: gradle - name: Grant execute permission for gradlew diff --git a/android_lib/build.gradle b/android_lib/build.gradle deleted file mode 100644 index 90b4418e..00000000 --- a/android_lib/build.gradle +++ /dev/null @@ -1,52 +0,0 @@ -plugins { - id 'com.android.library' -} - -apply from: '../jitpack.gradle' - -android { - namespace 'com.github.klee0kai.stone' - compileSdk 33 - - defaultConfig { - minSdk 21 - targetSdk 33 - - consumerProguardFiles "consumer-rules.pro" - } - - - buildTypes { - release { - minifyEnabled false - proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' - } - } - compileOptions { - sourceCompatibility JavaVersion.VERSION_11 - targetCompatibility JavaVersion.VERSION_11 - } - publishing { - singleVariant("release") { - withSourcesJar() - withJavadocJar() - } - } -} - -publishing { - publications { - maven(MavenPublication) { - afterEvaluate { - from components.release - } - } - } -} - - -dependencies { - api project(':stone_lib') - - implementation 'androidx.appcompat:appcompat:1.6.1' -} \ No newline at end of file diff --git a/android_lib/build.gradle.kts b/android_lib/build.gradle.kts new file mode 100644 index 00000000..6af5a5df --- /dev/null +++ b/android_lib/build.gradle.kts @@ -0,0 +1,39 @@ +plugins { + alias(libs.plugins.android.libarary) + alias(libs.plugins.publish.maven) + alias(libs.plugins.publish.stone) +} + +android { + namespace = "com.github.klee0kai.stone" + compileSdk = 33 + + defaultConfig { + minSdk = 21 + targetSdk = 33 + + consumerProguardFiles("consumer-rules.pro") + } + + + buildTypes { + release { + isMinifyEnabled = false + proguardFile(getDefaultProguardFile("proguard-android-optimize.txt")) + consumerProguardFiles("proguard-rules.pro") + } + } + publishing { + singleVariant("release") { + withSourcesJar() + withJavadocJar() + } + } +} + + +dependencies { + api(project(":stone_lib")) + + implementation("androidx.appcompat:appcompat:1.6.1") +} \ No newline at end of file diff --git a/android_lib/proguard-rules.pro b/android_lib/proguard-rules.pro index 481bb434..ff59496d 100644 --- a/android_lib/proguard-rules.pro +++ b/android_lib/proguard-rules.pro @@ -1,6 +1,6 @@ # Add project specific ProGuard rules here. # You can control the set of applied configuration files using the -# proguardFiles setting in build.gradle. +# proguardFiles setting in build.gradle.kts. # # For more details, see # http://developer.android.com/guide/developing/tools/proguard.html diff --git a/build.gradle b/build.gradle deleted file mode 100644 index bb544ed8..00000000 --- a/build.gradle +++ /dev/null @@ -1,18 +0,0 @@ -buildscript { - repositories { - gradlePluginPortal() - mavenCentral() - google() - } - dependencies { - classpath("com.android.tools.build:gradle:7.2.2") - } -} - -allprojects { - group("com.github.klee0kai.stone") - version("1.0.7") -} - - - diff --git a/build.gradle.kts b/build.gradle.kts new file mode 100644 index 00000000..e69de29b diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 41dfb879..2733ed5d 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-7.4-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.13-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/jitpack.gradle b/jitpack.gradle deleted file mode 100644 index 7dbacd9f..00000000 --- a/jitpack.gradle +++ /dev/null @@ -1,38 +0,0 @@ -apply plugin: 'maven-publish' - -publishing { - publications { - maven(MavenPublication) { - groupId project.group - artifactId project.name - version project.version - - pom { - name = 'Stone' - description = 'Library DI designed on weak references.' - url = 'https://github.com/klee0kai/stone' - - licenses { - license { - name = 'GNU GENERAL PUBLIC LICENSE, Version 3' - url = 'https://github.com/klee0kai/stone/blob/dev/LICENCE.md' - } - } - - developers { - developer { - id = 'klee0kai' - name = 'Andrey Kuzubov' - email = 'klee0kai@gmail.com' - } - } - - } - - } - } -} -java { - sourceCompatibility = JavaVersion.VERSION_11 - targetCompatibility = JavaVersion.VERSION_11 -} \ No newline at end of file diff --git a/kotlin_lib/build.gradle b/kotlin_lib/build.gradle.kts similarity index 60% rename from kotlin_lib/build.gradle rename to kotlin_lib/build.gradle.kts index a153c973..9a8a3142 100644 --- a/kotlin_lib/build.gradle +++ b/kotlin_lib/build.gradle.kts @@ -1,24 +1,19 @@ plugins { id("org.jetbrains.kotlin.jvm").version("1.7.0") id("org.jetbrains.kotlin.kapt").version("1.7.21") + alias(libs.plugins.publish.maven) + alias(libs.plugins.publish.stone) } -apply from: '../jitpack.gradle' - java { withSourcesJar() withJavadocJar() } -publishing { - publications { - maven(MavenPublication) { - from components.java - } - } +tasks.test { + useJUnitPlatform() } - dependencies { api(project(":stone_lib")) } diff --git a/libs.versions.toml b/libs.versions.toml index 4bb6eeb6..66b8a6c1 100644 --- a/libs.versions.toml +++ b/libs.versions.toml @@ -41,6 +41,7 @@ kotlinpoet = ["kotlinpoet", "kotlinpoet-ksp"] ksp = { id = "com.google.devtools.ksp", version.ref = "ksp" } jvm = { id = "org.jetbrains.kotlin.jvm", version.ref = "kotlin" } +android-libarary = { id = "com.android.library",version="8.12.3" } publish-maven = { id = "org.gradle.maven-publish" } -publish-crossbox = { id = "com.github.klee0kai.crossbox.publish" } +publish-stone = { id = "com.github.klee0kai.stone.publish" } diff --git a/plugin_publish/.gitignore b/plugin_publish/.gitignore new file mode 100644 index 00000000..42afabfd --- /dev/null +++ b/plugin_publish/.gitignore @@ -0,0 +1 @@ +/build \ No newline at end of file diff --git a/plugin_publish/build.gradle.kts b/plugin_publish/build.gradle.kts new file mode 100644 index 00000000..db3880da --- /dev/null +++ b/plugin_publish/build.gradle.kts @@ -0,0 +1,11 @@ +plugins { + `kotlin-dsl` + `java-gradle-plugin` +} + +gradlePlugin { + plugins.register("stone-publish") { + id = "com.github.klee0kai.stone.publish" + implementationClass = "com.github.klee0kai.stone.publish.StonePublishPlugin" + } +} diff --git a/plugin_publish/settings.gradle.kts b/plugin_publish/settings.gradle.kts new file mode 100644 index 00000000..7b5865f8 --- /dev/null +++ b/plugin_publish/settings.gradle.kts @@ -0,0 +1,20 @@ +pluginManagement { + repositories { + gradlePluginPortal() + google() + mavenCentral() + } +} + +dependencyResolutionManagement { + repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS) + repositories { + google() + mavenCentral() + } + versionCatalogs { + create("libs") { + from(files("../libs.versions.toml")) + } + } +} diff --git a/plugin_publish/src/main/kotlin/com/github/klee0kai/stone/publish/MavenPublishExt.kt b/plugin_publish/src/main/kotlin/com/github/klee0kai/stone/publish/MavenPublishExt.kt new file mode 100644 index 00000000..79a5954c --- /dev/null +++ b/plugin_publish/src/main/kotlin/com/github/klee0kai/stone/publish/MavenPublishExt.kt @@ -0,0 +1,48 @@ +package com.github.klee0kai.stone.publish + +import org.gradle.api.Project +import org.gradle.api.publish.PublishingExtension +import org.gradle.api.publish.maven.MavenPublication +import org.gradle.kotlin.dsl.create +import org.gradle.kotlin.dsl.get + + +fun PublishingExtension.stoneToMaven(project: Project) { + publications { + create("maven") { + groupId = project.group.toString() + artifactId = project.name + version = project.version.toString() + + when { + "java" in project.components.names -> { + //publish simple java lib + from(project.components["java"]) + } + "release" in project.components.names -> { + //publish android lib + from(project.components["release"]) + } + } + + pom { + name.set("Stone") + description.set("Library DI designed on weak references.") + url.set("https://github.com/klee0kai/stone") + licenses { + license { + name.set("GNU General Public License, Version 3") + url.set("https://github.com/klee0kai/stone/blob/dev/LICENCE.md") + } + } + developers { + developer { + id.set("klee0kai") + name.set("Andrei Kuzubov") + email.set("klee0kai@gmail.com") + } + } + } + } + } +} \ No newline at end of file diff --git a/plugin_publish/src/main/kotlin/com/github/klee0kai/stone/publish/StonePublishPlugin.kt b/plugin_publish/src/main/kotlin/com/github/klee0kai/stone/publish/StonePublishPlugin.kt new file mode 100644 index 00000000..15db3637 --- /dev/null +++ b/plugin_publish/src/main/kotlin/com/github/klee0kai/stone/publish/StonePublishPlugin.kt @@ -0,0 +1,22 @@ +package com.github.klee0kai.stone.publish + +import org.gradle.api.Plugin +import org.gradle.api.Project +import org.gradle.api.publish.PublishingExtension +import org.gradle.api.publish.plugins.PublishingPlugin + +/** + * apply MavenPublishPlugin with configs + */ +class StonePublishPlugin : Plugin { + + override fun apply(project: Project) { + project.pluginManager.apply(PublishingPlugin::class.java) + + project.afterEvaluate { + project.extensions.configure(PublishingExtension::class.java) { + stoneToMaven(project) + } + } + } +} \ No newline at end of file diff --git a/settings.gradle.kts b/settings.gradle.kts index 3a935204..58ab43ce 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -1,5 +1,3 @@ -import org.gradle.api.initialization.resolve.RepositoriesMode - pluginManagement { repositories { gradlePluginPortal() @@ -7,14 +5,13 @@ pluginManagement { mavenCentral() } } + dependencyResolutionManagement { repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS) repositories { - mavenLocal() google() mavenCentral() } - versionCatalogs { create("libs") { from(files("libs.versions.toml")) @@ -23,6 +20,7 @@ dependencyResolutionManagement { } rootProject.name = "Stone" +includeBuild("plugin_publish") include(":stone_lib") include(":stone_processor") include(":android_lib") diff --git a/stone_lib/build.gradle b/stone_lib/build.gradle deleted file mode 100644 index ca085034..00000000 --- a/stone_lib/build.gradle +++ /dev/null @@ -1,43 +0,0 @@ -plugins { - id 'java' -} - -apply from: '../jitpack.gradle' - -java { - withSourcesJar() - withJavadocJar() -} - -javadoc { - exclude("com/github/klee0kai/stone/closed/") -} - -publishing { - publications { - maven(MavenPublication) { - from components.java - } - } -} - -dependencies { - - // https://mvnrepository.com/artifact/javax.inject/javax.inject - apiElements 'javax.inject:javax.inject:1' - implementation 'javax.inject:javax.inject:1' - - - testImplementation 'org.junit.jupiter:junit-jupiter-api:5.9.1' - testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.9.1' -} - -test { - useJUnitPlatform() -} - - -java { - sourceCompatibility = JavaVersion.VERSION_11 - targetCompatibility = JavaVersion.VERSION_11 -} \ No newline at end of file diff --git a/stone_lib/build.gradle.kts b/stone_lib/build.gradle.kts new file mode 100644 index 00000000..6ef3ae0c --- /dev/null +++ b/stone_lib/build.gradle.kts @@ -0,0 +1,26 @@ +plugins { + `java-library` + alias(libs.plugins.publish.maven) + alias(libs.plugins.publish.stone) +} + +java { + withSourcesJar() + withJavadocJar() +} + +tasks.javadoc { + exclude("com/github/klee0kai/stone/closed/") +} + +tasks.test { + useJUnitPlatform() +} + +dependencies { + // https://mvnrepository.com/artifact/javax.inject/javax.inject + api("javax.inject:javax.inject:1") + + testImplementation("org.junit.jupiter:junit-jupiter-api:5.9.1") + testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:5.9.1") +} diff --git a/stone_processor/build.gradle b/stone_processor/build.gradle deleted file mode 100644 index 77df3cfa..00000000 --- a/stone_processor/build.gradle +++ /dev/null @@ -1,41 +0,0 @@ -apply plugin: 'java-library' -apply plugin: 'java' -apply from: '../jitpack.gradle' - - -java { - withSourcesJar() - withJavadocJar() -} - -javadoc { - enabled(false) -} - -publishing { - publications { - maven(MavenPublication) { - from components.java - } - } -} - -dependencies { - implementation project(':stone_lib') - - implementation "com.google.auto.service:auto-service:1.0.1" - annotationProcessor "com.google.auto.service:auto-service:1.0.1" - - // incap - implementation "net.ltgt.gradle.incap:incap:0.3" - implementation "net.ltgt.gradle.incap:incap-processor:0.3" - - // squareup - кодогенерация - implementation "com.squareup:javapoet:1.13.0" -} - - -java { - sourceCompatibility = JavaVersion.VERSION_11 - targetCompatibility = JavaVersion.VERSION_11 -} \ No newline at end of file diff --git a/stone_processor/build.gradle.kts b/stone_processor/build.gradle.kts new file mode 100644 index 00000000..522ea6cb --- /dev/null +++ b/stone_processor/build.gradle.kts @@ -0,0 +1,30 @@ +plugins { + `java-library` + alias(libs.plugins.publish.maven) + alias(libs.plugins.publish.stone) +} + +java { + withSourcesJar() + withJavadocJar() +} + +tasks.javadoc { + isEnabled = false +} + +dependencies { + implementation(project(":stone_lib")) + + implementation("com.google.auto.service:auto-service:1.0.1") + annotationProcessor("com.google.auto.service:auto-service:1.0.1") + + // incap + implementation("net.ltgt.gradle.incap:incap:0.3") + implementation("net.ltgt.gradle.incap:incap-processor:0.3") + + // squareup - кодогенерация + implementation("com.squareup:javapoet:1.13.0") +} + + diff --git a/test_feature/companies/consulting/build.gradle b/test_feature/companies/consulting/build.gradle deleted file mode 100644 index d59a2319..00000000 --- a/test_feature/companies/consulting/build.gradle +++ /dev/null @@ -1,29 +0,0 @@ -plugins { - id 'java' -} - -group = 'com.github.klee0kai.stone.test_feature.consulting' - -dependencies { - implementation project(path: ':test_feature:hr:api') - implementation project(path: ':test_feature:finance:api') - implementation project(path: ':test_feature:planning:api') - - implementation project(path: ':test_feature:hr:impl') - implementation project(path: ':test_feature:finance:impl') - implementation project(path: ':test_feature:planning:impl') - - implementation project(":stone_lib") - annotationProcessor project(":stone_processor") - - testImplementation platform('org.junit:junit-bom:5.9.1') - testImplementation 'org.junit.jupiter:junit-jupiter' -} - -test { - useJUnitPlatform() -} -java { - sourceCompatibility = JavaVersion.VERSION_11 - targetCompatibility = JavaVersion.VERSION_11 -} \ No newline at end of file diff --git a/test_feature/companies/consulting/build.gradle.kts b/test_feature/companies/consulting/build.gradle.kts new file mode 100644 index 00000000..20028ef4 --- /dev/null +++ b/test_feature/companies/consulting/build.gradle.kts @@ -0,0 +1,26 @@ +plugins { + id("java") +} + +group = "com.github.klee0kai.stone.test_feature.consulting" + +tasks.test { + useJUnitPlatform() +} + +dependencies { + implementation(project(":test_feature:hr:api")) + implementation(project(":test_feature:finance:api")) + implementation(project(":test_feature:planning:api")) + + implementation(project(":test_feature:hr:impl")) + implementation(project(":test_feature:finance:impl")) + implementation(project(":test_feature:planning:impl")) + + implementation(project(":stone_lib")) + annotationProcessor(project(":stone_processor")) + + testImplementation(platform("org.junit:junit-bom:5.9.1")) + testImplementation("org.junit.jupiter:junit-jupiter") +} + diff --git a/test_feature/finance/api/build.gradle.kts b/test_feature/finance/api/build.gradle.kts index 00946c9b..4d7ecb98 100644 --- a/test_feature/finance/api/build.gradle.kts +++ b/test_feature/finance/api/build.gradle.kts @@ -4,3 +4,7 @@ plugins { group = "com.github.klee0kai.stone.test_feature.finance" +tasks.test { + useJUnitPlatform() +} + diff --git a/test_feature/finance/impl/build.gradle.kts b/test_feature/finance/impl/build.gradle.kts index b8dc5a50..e09c1cff 100644 --- a/test_feature/finance/impl/build.gradle.kts +++ b/test_feature/finance/impl/build.gradle.kts @@ -4,6 +4,10 @@ plugins { group = "com.github.klee0kai.stone.test_feature.finance" +tasks.test { + useJUnitPlatform() +} + dependencies { implementation(project(":test_feature:finance:api")) implementation(project(":test_feature:hr:api")) diff --git a/test_feature/hr/api/build.gradle.kts b/test_feature/hr/api/build.gradle.kts index 73bcea1e..bf65d621 100644 --- a/test_feature/hr/api/build.gradle.kts +++ b/test_feature/hr/api/build.gradle.kts @@ -4,3 +4,7 @@ plugins { group = "com.github.klee0kai.stone.test_feature.hr" +tasks.test { + useJUnitPlatform() +} + diff --git a/test_feature/hr/impl/build.gradle.kts b/test_feature/hr/impl/build.gradle.kts index fac0dca0..421e251d 100644 --- a/test_feature/hr/impl/build.gradle.kts +++ b/test_feature/hr/impl/build.gradle.kts @@ -4,6 +4,9 @@ plugins { group = "com.github.klee0kai.stone.test_feature.hr" +tasks.test { + useJUnitPlatform() +} dependencies { implementation(project(":test_feature:hr:api")) diff --git a/test_feature/planning/api/build.gradle b/test_feature/planning/api/build.gradle deleted file mode 100644 index db2434cb..00000000 --- a/test_feature/planning/api/build.gradle +++ /dev/null @@ -1,11 +0,0 @@ -plugins { - id 'java' -} - -group = 'com.github.klee0kai.stone.test_feature.planning' - - -java { - sourceCompatibility = JavaVersion.VERSION_11 - targetCompatibility = JavaVersion.VERSION_11 -} \ No newline at end of file diff --git a/test_feature/planning/api/build.gradle.kts b/test_feature/planning/api/build.gradle.kts new file mode 100644 index 00000000..2c15d550 --- /dev/null +++ b/test_feature/planning/api/build.gradle.kts @@ -0,0 +1,11 @@ +plugins { + id("java") +} + +group = "com.github.klee0kai.stone.test_feature.planning" + +tasks.test { + useJUnitPlatform() +} + + diff --git a/test_feature/planning/impl/build.gradle.kts b/test_feature/planning/impl/build.gradle.kts index df31a177..91d585d0 100644 --- a/test_feature/planning/impl/build.gradle.kts +++ b/test_feature/planning/impl/build.gradle.kts @@ -4,6 +4,9 @@ plugins { group = "com.github.klee0kai.stone.test_feature.planning" +tasks.test { + useJUnitPlatform() +} dependencies { implementation(project(":test_feature:planning:api")) diff --git a/test_feature_core_deps/build.gradle.kts b/test_feature_core_deps/build.gradle.kts index 3be87d78..bb717a56 100644 --- a/test_feature_core_deps/build.gradle.kts +++ b/test_feature_core_deps/build.gradle.kts @@ -3,6 +3,9 @@ plugins { id("org.jetbrains.kotlin.kapt").version("1.7.21") } +tasks.test { + useJUnitPlatform() +} dependencies { implementation(project(":kotlin_lib")) diff --git a/tests/build.gradle.kts b/tests/build.gradle.kts index 6d59fc08..e1ca92a3 100644 --- a/tests/build.gradle.kts +++ b/tests/build.gradle.kts @@ -2,6 +2,10 @@ plugins { id("java") } +tasks.test { + useJUnitPlatform() +} + dependencies { implementation(project(":stone_lib")) annotationProcessor(project(":stone_processor")) diff --git a/tests_compile/build.gradle.kts b/tests_compile/build.gradle.kts index 7010fbe4..104b6ebf 100644 --- a/tests_compile/build.gradle.kts +++ b/tests_compile/build.gradle.kts @@ -2,6 +2,10 @@ plugins { id("java") } +tasks.test { + useJUnitPlatform() +} + dependencies { implementation(project(":stone_lib")) implementation(project(":stone_processor")) diff --git a/tests_ext/build.gradle.kts b/tests_ext/build.gradle.kts index 94a75d8f..439e0dfc 100644 --- a/tests_ext/build.gradle.kts +++ b/tests_ext/build.gradle.kts @@ -2,6 +2,10 @@ plugins { id("java") } +tasks.test { + useJUnitPlatform() +} + dependencies { implementation(project(":stone_lib")) annotationProcessor(project(":stone_processor")) diff --git a/tests_kotlin/build.gradle b/tests_kotlin/build.gradle.kts similarity index 75% rename from tests_kotlin/build.gradle rename to tests_kotlin/build.gradle.kts index 57bc7511..1cfa145d 100644 --- a/tests_kotlin/build.gradle +++ b/tests_kotlin/build.gradle.kts @@ -1,6 +1,10 @@ plugins { id("org.jetbrains.kotlin.jvm").version("1.7.0") - id("org.jetbrains.kotlin.kapt").version("1.7.21") + id("org.jetbrains.kotlin.kapt").version("1.7.21") +} + +tasks.getByName("test") { + useJUnitPlatform() } dependencies { diff --git a/tests_wraps/build.gradle.kts b/tests_wraps/build.gradle.kts index 6d59fc08..e1ca92a3 100644 --- a/tests_wraps/build.gradle.kts +++ b/tests_wraps/build.gradle.kts @@ -2,6 +2,10 @@ plugins { id("java") } +tasks.test { + useJUnitPlatform() +} + dependencies { implementation(project(":stone_lib")) annotationProcessor(project(":stone_processor")) diff --git a/tests_wraps_kotlin/build.gradle.kts b/tests_wraps_kotlin/build.gradle.kts index c3f53fc3..9f829dff 100644 --- a/tests_wraps_kotlin/build.gradle.kts +++ b/tests_wraps_kotlin/build.gradle.kts @@ -3,6 +3,10 @@ plugins { id("org.jetbrains.kotlin.kapt").version("1.7.21") } +tasks.test { + useJUnitPlatform() +} + dependencies { implementation(project(":tests")) diff --git a/wiki_java/build.gradle.kts b/wiki_java/build.gradle.kts index 30bb82b8..ecdf17db 100644 --- a/wiki_java/build.gradle.kts +++ b/wiki_java/build.gradle.kts @@ -3,6 +3,10 @@ plugins { id("application") } +tasks.test { + useJUnitPlatform() +} + dependencies { implementation(project(":tests")) implementation(project(":test_feature:finance:api")) diff --git a/wiki_kotlin/build.gradle.kts b/wiki_kotlin/build.gradle.kts index c8271694..0d101513 100644 --- a/wiki_kotlin/build.gradle.kts +++ b/wiki_kotlin/build.gradle.kts @@ -3,6 +3,9 @@ plugins { id("org.jetbrains.kotlin.kapt").version("1.7.21") } +tasks.test { + useJUnitPlatform() +} dependencies { implementation(project(":tests")) From 8aea35a62d78653d6da18b7afd79d57123162685 Mon Sep 17 00:00:00 2001 From: klee0kai Date: Mon, 6 Oct 2025 09:19:30 +0200 Subject: [PATCH 003/122] correct stone publications --- android_lib/build.gradle.kts | 5 ++++- kotlin_lib/build.gradle.kts | 3 +++ libs.versions.toml | 3 +-- stone_lib/build.gradle.kts | 3 +++ stone_processor/build.gradle.kts | 3 +++ 5 files changed, 14 insertions(+), 3 deletions(-) diff --git a/android_lib/build.gradle.kts b/android_lib/build.gradle.kts index 6af5a5df..cfd66cfa 100644 --- a/android_lib/build.gradle.kts +++ b/android_lib/build.gradle.kts @@ -4,8 +4,11 @@ plugins { alias(libs.plugins.publish.stone) } +group = "com.github.klee0kai.stone" +version = libs.versions.stone.get() + android { - namespace = "com.github.klee0kai.stone" + namespace = project.group.toString() compileSdk = 33 defaultConfig { diff --git a/kotlin_lib/build.gradle.kts b/kotlin_lib/build.gradle.kts index 9a8a3142..f1042f9b 100644 --- a/kotlin_lib/build.gradle.kts +++ b/kotlin_lib/build.gradle.kts @@ -5,6 +5,9 @@ plugins { alias(libs.plugins.publish.stone) } +group = "com.github.klee0kai.stone" +version = libs.versions.stone.get() + java { withSourcesJar() withJavadocJar() diff --git a/libs.versions.toml b/libs.versions.toml index 66b8a6c1..67b00fa7 100644 --- a/libs.versions.toml +++ b/libs.versions.toml @@ -1,6 +1,6 @@ [versions] -crossbox = "0.0.1" +stone = "1.0.7" kotlin = "2.1.10" ksp = "2.1.10-1.0.30" @@ -8,7 +8,6 @@ ksp = "2.1.10-1.0.30" jetbrain-immutable = "0.3.7" jetbrain-coroutines = "1.10.1" -stone = "1.0.7" kotlinpoet = "2.0.0" jupiter = "5.9.2" diff --git a/stone_lib/build.gradle.kts b/stone_lib/build.gradle.kts index 6ef3ae0c..9e9d46ba 100644 --- a/stone_lib/build.gradle.kts +++ b/stone_lib/build.gradle.kts @@ -4,6 +4,9 @@ plugins { alias(libs.plugins.publish.stone) } +group = "com.github.klee0kai.stone" +version = libs.versions.stone.get() + java { withSourcesJar() withJavadocJar() diff --git a/stone_processor/build.gradle.kts b/stone_processor/build.gradle.kts index 522ea6cb..3a84d116 100644 --- a/stone_processor/build.gradle.kts +++ b/stone_processor/build.gradle.kts @@ -4,6 +4,9 @@ plugins { alias(libs.plugins.publish.stone) } +group = "com.github.klee0kai.stone" +version = libs.versions.stone.get() + java { withSourcesJar() withJavadocJar() From a604e02d1a162a51cc3f78dd3a9d5e7b939ff3f3 Mon Sep 17 00:00:00 2001 From: klee0kai Date: Mon, 6 Oct 2025 22:47:43 +0200 Subject: [PATCH 004/122] apply plugins from toml file --- kotlin_lib/build.gradle.kts | 4 ++-- libs.versions.toml | 13 +++++-------- test_feature/companies/consulting/build.gradle.kts | 2 +- test_feature/finance/api/build.gradle.kts | 2 +- test_feature/finance/impl/build.gradle.kts | 2 +- test_feature/hr/api/build.gradle.kts | 2 +- test_feature/hr/impl/build.gradle.kts | 2 +- test_feature/planning/api/build.gradle.kts | 2 +- test_feature/planning/impl/build.gradle.kts | 2 +- test_feature_core_deps/build.gradle.kts | 4 ++-- tests/build.gradle.kts | 2 +- tests_compile/build.gradle.kts | 2 +- tests_ext/build.gradle.kts | 2 +- tests_kotlin/build.gradle.kts | 6 +++--- tests_wraps/build.gradle.kts | 2 +- tests_wraps_kotlin/build.gradle.kts | 4 ++-- wiki_java/build.gradle.kts | 3 +-- wiki_kotlin/build.gradle.kts | 5 ++--- 18 files changed, 28 insertions(+), 33 deletions(-) diff --git a/kotlin_lib/build.gradle.kts b/kotlin_lib/build.gradle.kts index f1042f9b..f3f5d804 100644 --- a/kotlin_lib/build.gradle.kts +++ b/kotlin_lib/build.gradle.kts @@ -1,6 +1,6 @@ plugins { - id("org.jetbrains.kotlin.jvm").version("1.7.0") - id("org.jetbrains.kotlin.kapt").version("1.7.21") + alias(libs.plugins.kotlin.jvm) + alias(libs.plugins.kotlin.kapt) alias(libs.plugins.publish.maven) alias(libs.plugins.publish.stone) } diff --git a/libs.versions.toml b/libs.versions.toml index 67b00fa7..3b033926 100644 --- a/libs.versions.toml +++ b/libs.versions.toml @@ -2,7 +2,7 @@ stone = "1.0.7" -kotlin = "2.1.10" +kotlin = "1.7.0" ksp = "2.1.10-1.0.30" jetbrain-immutable = "0.3.7" @@ -18,10 +18,6 @@ jupiter = "5.9.2" jetbrain-immutable = { group = "org.jetbrains.kotlinx", name = "kotlinx-collections-immutable", version.ref = "jetbrain-immutable" } jetbrain-coroutines = { group = "org.jetbrains.kotlinx", name = "kotlinx-coroutines-core", version.ref = "jetbrain-coroutines" } -# https://github.com/klee0kai/stone -stone-kotlin = { group = "com.github.klee0kai.stone", name = "kotlin_lib", version.ref = "stone" } -stone-kapt = { group = "com.github.klee0kai.stone", name = "stone_processor", version.ref = "stone" } - ksp = { group = "com.google.devtools.ksp", name = "symbol-processing-api", version.ref = "ksp" } kotlinpoet = { group = "com.squareup", name = "kotlinpoet", version.ref = "kotlinpoet" } @@ -38,9 +34,10 @@ kotlinpoet = ["kotlinpoet", "kotlinpoet-ksp"] [plugins] -ksp = { id = "com.google.devtools.ksp", version.ref = "ksp" } -jvm = { id = "org.jetbrains.kotlin.jvm", version.ref = "kotlin" } -android-libarary = { id = "com.android.library",version="8.12.3" } +kotlin-ksp = { id = "com.google.devtools.ksp", version.ref = "ksp" } +kotlin-jvm = { id = "org.jetbrains.kotlin.jvm", version.ref = "kotlin" } +kotlin-kapt = { id = "org.jetbrains.kotlin.kapt", version.ref = "kotlin" } +android-libarary = { id = "com.android.library", version = "8.12.3" } publish-maven = { id = "org.gradle.maven-publish" } publish-stone = { id = "com.github.klee0kai.stone.publish" } diff --git a/test_feature/companies/consulting/build.gradle.kts b/test_feature/companies/consulting/build.gradle.kts index 20028ef4..b03ecfe7 100644 --- a/test_feature/companies/consulting/build.gradle.kts +++ b/test_feature/companies/consulting/build.gradle.kts @@ -1,5 +1,5 @@ plugins { - id("java") + java } group = "com.github.klee0kai.stone.test_feature.consulting" diff --git a/test_feature/finance/api/build.gradle.kts b/test_feature/finance/api/build.gradle.kts index 4d7ecb98..f0a4d6b9 100644 --- a/test_feature/finance/api/build.gradle.kts +++ b/test_feature/finance/api/build.gradle.kts @@ -1,5 +1,5 @@ plugins { - id("java") + java } group = "com.github.klee0kai.stone.test_feature.finance" diff --git a/test_feature/finance/impl/build.gradle.kts b/test_feature/finance/impl/build.gradle.kts index e09c1cff..f7bf4a8b 100644 --- a/test_feature/finance/impl/build.gradle.kts +++ b/test_feature/finance/impl/build.gradle.kts @@ -1,5 +1,5 @@ plugins { - id("java") + java } group = "com.github.klee0kai.stone.test_feature.finance" diff --git a/test_feature/hr/api/build.gradle.kts b/test_feature/hr/api/build.gradle.kts index bf65d621..63a737e3 100644 --- a/test_feature/hr/api/build.gradle.kts +++ b/test_feature/hr/api/build.gradle.kts @@ -1,5 +1,5 @@ plugins { - id("java") + java } group = "com.github.klee0kai.stone.test_feature.hr" diff --git a/test_feature/hr/impl/build.gradle.kts b/test_feature/hr/impl/build.gradle.kts index 421e251d..2717d94a 100644 --- a/test_feature/hr/impl/build.gradle.kts +++ b/test_feature/hr/impl/build.gradle.kts @@ -1,5 +1,5 @@ plugins { - id("java") + java } group = "com.github.klee0kai.stone.test_feature.hr" diff --git a/test_feature/planning/api/build.gradle.kts b/test_feature/planning/api/build.gradle.kts index 2c15d550..f421159e 100644 --- a/test_feature/planning/api/build.gradle.kts +++ b/test_feature/planning/api/build.gradle.kts @@ -1,5 +1,5 @@ plugins { - id("java") + java } group = "com.github.klee0kai.stone.test_feature.planning" diff --git a/test_feature/planning/impl/build.gradle.kts b/test_feature/planning/impl/build.gradle.kts index 91d585d0..4e49ba81 100644 --- a/test_feature/planning/impl/build.gradle.kts +++ b/test_feature/planning/impl/build.gradle.kts @@ -1,5 +1,5 @@ plugins { - id("java") + java } group = "com.github.klee0kai.stone.test_feature.planning" diff --git a/test_feature_core_deps/build.gradle.kts b/test_feature_core_deps/build.gradle.kts index bb717a56..b63ed095 100644 --- a/test_feature_core_deps/build.gradle.kts +++ b/test_feature_core_deps/build.gradle.kts @@ -1,6 +1,6 @@ plugins { - id("org.jetbrains.kotlin.jvm").version("1.7.0") - id("org.jetbrains.kotlin.kapt").version("1.7.21") + alias(libs.plugins.kotlin.jvm) + alias(libs.plugins.kotlin.kapt) } tasks.test { diff --git a/tests/build.gradle.kts b/tests/build.gradle.kts index e1ca92a3..2cee0a53 100644 --- a/tests/build.gradle.kts +++ b/tests/build.gradle.kts @@ -1,5 +1,5 @@ plugins { - id("java") + java } tasks.test { diff --git a/tests_compile/build.gradle.kts b/tests_compile/build.gradle.kts index 104b6ebf..7a201680 100644 --- a/tests_compile/build.gradle.kts +++ b/tests_compile/build.gradle.kts @@ -1,5 +1,5 @@ plugins { - id("java") + java } tasks.test { diff --git a/tests_ext/build.gradle.kts b/tests_ext/build.gradle.kts index 439e0dfc..072a4b24 100644 --- a/tests_ext/build.gradle.kts +++ b/tests_ext/build.gradle.kts @@ -1,5 +1,5 @@ plugins { - id("java") + java } tasks.test { diff --git a/tests_kotlin/build.gradle.kts b/tests_kotlin/build.gradle.kts index 1cfa145d..87a8c7f3 100644 --- a/tests_kotlin/build.gradle.kts +++ b/tests_kotlin/build.gradle.kts @@ -1,9 +1,9 @@ plugins { - id("org.jetbrains.kotlin.jvm").version("1.7.0") - id("org.jetbrains.kotlin.kapt").version("1.7.21") + alias(libs.plugins.kotlin.jvm) + alias(libs.plugins.kotlin.kapt) } -tasks.getByName("test") { +tasks.test { useJUnitPlatform() } diff --git a/tests_wraps/build.gradle.kts b/tests_wraps/build.gradle.kts index e1ca92a3..2cee0a53 100644 --- a/tests_wraps/build.gradle.kts +++ b/tests_wraps/build.gradle.kts @@ -1,5 +1,5 @@ plugins { - id("java") + java } tasks.test { diff --git a/tests_wraps_kotlin/build.gradle.kts b/tests_wraps_kotlin/build.gradle.kts index 9f829dff..61b17ca7 100644 --- a/tests_wraps_kotlin/build.gradle.kts +++ b/tests_wraps_kotlin/build.gradle.kts @@ -1,6 +1,6 @@ plugins { - id("org.jetbrains.kotlin.jvm").version("1.7.0") - id("org.jetbrains.kotlin.kapt").version("1.7.21") + alias(libs.plugins.kotlin.jvm) + alias(libs.plugins.kotlin.kapt) } tasks.test { diff --git a/wiki_java/build.gradle.kts b/wiki_java/build.gradle.kts index ecdf17db..218be786 100644 --- a/wiki_java/build.gradle.kts +++ b/wiki_java/build.gradle.kts @@ -1,6 +1,5 @@ plugins { - id("java") - id("application") + application } tasks.test { diff --git a/wiki_kotlin/build.gradle.kts b/wiki_kotlin/build.gradle.kts index 0d101513..c68b5fd8 100644 --- a/wiki_kotlin/build.gradle.kts +++ b/wiki_kotlin/build.gradle.kts @@ -1,6 +1,6 @@ plugins { - id("org.jetbrains.kotlin.jvm").version("1.7.0") - id("org.jetbrains.kotlin.kapt").version("1.7.21") + alias(libs.plugins.kotlin.jvm) + alias(libs.plugins.kotlin.kapt) } tasks.test { @@ -13,6 +13,5 @@ dependencies { implementation(project(":kotlin_lib")) kapt(project(":stone_processor")) - } From 4ce6b8d46cdd67d3b0d36147d0ae420ca0e52395 Mon Sep 17 00:00:00 2001 From: klee0kai Date: Mon, 6 Oct 2025 23:06:55 +0200 Subject: [PATCH 005/122] lib versions via toml --- android_lib/build.gradle.kts | 2 +- libs.versions.toml | 31 ++++++++++++------- stone_lib/build.gradle.kts | 6 ++-- stone_processor/build.gradle.kts | 12 +++---- .../companies/consulting/build.gradle.kts | 3 +- test_feature_core_deps/build.gradle.kts | 4 +-- tests/build.gradle.kts | 4 +-- tests_compile/build.gradle.kts | 7 +++-- tests_ext/build.gradle.kts | 3 +- tests_kotlin/build.gradle.kts | 4 +-- tests_wraps/build.gradle.kts | 4 +-- tests_wraps_kotlin/build.gradle.kts | 3 +- 12 files changed, 41 insertions(+), 42 deletions(-) diff --git a/android_lib/build.gradle.kts b/android_lib/build.gradle.kts index cfd66cfa..33d71ef6 100644 --- a/android_lib/build.gradle.kts +++ b/android_lib/build.gradle.kts @@ -38,5 +38,5 @@ android { dependencies { api(project(":stone_lib")) - implementation("androidx.appcompat:appcompat:1.6.1") + implementation(libs.android.appcompat) } \ No newline at end of file diff --git a/libs.versions.toml b/libs.versions.toml index 3b033926..adb600ca 100644 --- a/libs.versions.toml +++ b/libs.versions.toml @@ -5,32 +5,41 @@ stone = "1.0.7" kotlin = "1.7.0" ksp = "2.1.10-1.0.30" -jetbrain-immutable = "0.3.7" -jetbrain-coroutines = "1.10.1" +appcompat = "1.6.1" +javax-inject = "1" -kotlinpoet = "2.0.0" +auto-service = "1.0.1" +incap = "0.3" +javapoet = "1.13.0" jupiter = "5.9.2" +testing-compile = "0.21.0" [libraries] -jetbrain-immutable = { group = "org.jetbrains.kotlinx", name = "kotlinx-collections-immutable", version.ref = "jetbrain-immutable" } -jetbrain-coroutines = { group = "org.jetbrains.kotlinx", name = "kotlinx-coroutines-core", version.ref = "jetbrain-coroutines" } +android-appcompat = { group = "androidx.appcompat", name = "appcompat", version.ref = "appcompat" } -ksp = { group = "com.google.devtools.ksp", name = "symbol-processing-api", version.ref = "ksp" } +# https://mvnrepository.com/artifact/javax.inject/javax.inject +java-inject = { group = "javax.inject", name = "javax.inject", version.ref = "javax-inject" } + +auto-service = { group = "com.google.auto.service", name = "auto-service", version.ref = "auto-service" } + +incap = { group = "net.ltgt.gradle.incap", name = "incap", version.ref = "incap" } +incap-processor = { group = "net.ltgt.gradle.incap", name = "incap-processor", version.ref = "incap" } -kotlinpoet = { group = "com.squareup", name = "kotlinpoet", version.ref = "kotlinpoet" } -kotlinpoet-ksp = { group = "com.squareup", name = "kotlinpoet-ksp", version.ref = "kotlinpoet" } +javapoet = { group = "com.squareup", name = "javapoet", version.ref = "javapoet" } + +ksp = { group = "com.google.devtools.ksp", name = "symbol-processing-api", version.ref = "ksp" } -# test jupiter-api = { group = "org.junit.jupiter", name = "junit-jupiter-api", version.ref = "jupiter" } jupiter-engine = { group = "org.junit.jupiter", name = "junit-jupiter-engine", version.ref = "jupiter" } +testing-compile = { group = "com.google.testing.compile", name = "compile-testing", version.ref = "testing-compile" } + [bundles] -kotlin = ["jetbrain-coroutines", "jetbrain-immutable"] -kotlinpoet = ["kotlinpoet", "kotlinpoet-ksp"] +jupiter = ["jupiter-api", "jupiter-engine"] [plugins] diff --git a/stone_lib/build.gradle.kts b/stone_lib/build.gradle.kts index 9e9d46ba..af867e1c 100644 --- a/stone_lib/build.gradle.kts +++ b/stone_lib/build.gradle.kts @@ -21,9 +21,7 @@ tasks.test { } dependencies { - // https://mvnrepository.com/artifact/javax.inject/javax.inject - api("javax.inject:javax.inject:1") + api(libs.java.inject) - testImplementation("org.junit.jupiter:junit-jupiter-api:5.9.1") - testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:5.9.1") + testImplementation(libs.bundles.jupiter) } diff --git a/stone_processor/build.gradle.kts b/stone_processor/build.gradle.kts index 3a84d116..1381dd21 100644 --- a/stone_processor/build.gradle.kts +++ b/stone_processor/build.gradle.kts @@ -19,15 +19,13 @@ tasks.javadoc { dependencies { implementation(project(":stone_lib")) - implementation("com.google.auto.service:auto-service:1.0.1") - annotationProcessor("com.google.auto.service:auto-service:1.0.1") + implementation(libs.auto.service) + annotationProcessor(libs.auto.service) - // incap - implementation("net.ltgt.gradle.incap:incap:0.3") - implementation("net.ltgt.gradle.incap:incap-processor:0.3") + implementation(libs.incap) + implementation(libs.incap.processor) - // squareup - кодогенерация - implementation("com.squareup:javapoet:1.13.0") + implementation(libs.javapoet) } diff --git a/test_feature/companies/consulting/build.gradle.kts b/test_feature/companies/consulting/build.gradle.kts index b03ecfe7..15ac540d 100644 --- a/test_feature/companies/consulting/build.gradle.kts +++ b/test_feature/companies/consulting/build.gradle.kts @@ -20,7 +20,6 @@ dependencies { implementation(project(":stone_lib")) annotationProcessor(project(":stone_processor")) - testImplementation(platform("org.junit:junit-bom:5.9.1")) - testImplementation("org.junit.jupiter:junit-jupiter") + testImplementation(libs.bundles.jupiter) } diff --git a/test_feature_core_deps/build.gradle.kts b/test_feature_core_deps/build.gradle.kts index b63ed095..e2380adf 100644 --- a/test_feature_core_deps/build.gradle.kts +++ b/test_feature_core_deps/build.gradle.kts @@ -11,6 +11,6 @@ dependencies { implementation(project(":kotlin_lib")) kapt(project(":stone_processor")) - testImplementation("org.junit.jupiter:junit-jupiter-api:5.9.1") - testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:5.11.0-M2") + + testImplementation(libs.bundles.jupiter) } diff --git a/tests/build.gradle.kts b/tests/build.gradle.kts index 2cee0a53..e4d958d2 100644 --- a/tests/build.gradle.kts +++ b/tests/build.gradle.kts @@ -10,8 +10,6 @@ dependencies { implementation(project(":stone_lib")) annotationProcessor(project(":stone_processor")) - - testImplementation("org.junit.jupiter:junit-jupiter-api:5.9.1") - testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:5.9.1") + testImplementation(libs.bundles.jupiter) } diff --git a/tests_compile/build.gradle.kts b/tests_compile/build.gradle.kts index 7a201680..b6d88794 100644 --- a/tests_compile/build.gradle.kts +++ b/tests_compile/build.gradle.kts @@ -10,9 +10,10 @@ dependencies { implementation(project(":stone_lib")) implementation(project(":stone_processor")) - testImplementation("com.google.testing.compile:compile-testing:0.21.0") - testImplementation("org.junit.jupiter:junit-jupiter-api:5.9.1") - testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:5.9.1") + + testImplementation(libs.bundles.jupiter) + testImplementation(libs.testing.compile) + } diff --git a/tests_ext/build.gradle.kts b/tests_ext/build.gradle.kts index 072a4b24..8781f985 100644 --- a/tests_ext/build.gradle.kts +++ b/tests_ext/build.gradle.kts @@ -12,8 +12,7 @@ dependencies { implementation(project(":tests")) - testImplementation("org.junit.jupiter:junit-jupiter-api:5.9.1") - testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:5.9.1") + testImplementation(libs.bundles.jupiter) } diff --git a/tests_kotlin/build.gradle.kts b/tests_kotlin/build.gradle.kts index 87a8c7f3..65956549 100644 --- a/tests_kotlin/build.gradle.kts +++ b/tests_kotlin/build.gradle.kts @@ -13,8 +13,8 @@ dependencies { implementation(project(":kotlin_lib")) kapt(project(":stone_processor")) - testImplementation("org.junit.jupiter:junit-jupiter-api:5.9.0") - testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:5.9.0") + testImplementation(libs.bundles.jupiter) + } diff --git a/tests_wraps/build.gradle.kts b/tests_wraps/build.gradle.kts index 2cee0a53..e4d958d2 100644 --- a/tests_wraps/build.gradle.kts +++ b/tests_wraps/build.gradle.kts @@ -10,8 +10,6 @@ dependencies { implementation(project(":stone_lib")) annotationProcessor(project(":stone_processor")) - - testImplementation("org.junit.jupiter:junit-jupiter-api:5.9.1") - testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:5.9.1") + testImplementation(libs.bundles.jupiter) } diff --git a/tests_wraps_kotlin/build.gradle.kts b/tests_wraps_kotlin/build.gradle.kts index 61b17ca7..db3aa524 100644 --- a/tests_wraps_kotlin/build.gradle.kts +++ b/tests_wraps_kotlin/build.gradle.kts @@ -13,7 +13,6 @@ dependencies { implementation(project(":kotlin_lib")) kapt(project(":stone_processor")) - testImplementation("org.junit.jupiter:junit-jupiter-api:5.9.1") - testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:5.9.1") + testImplementation(libs.bundles.jupiter) } From 1a3ad59ea45b99677bccb969e73a6fdff57caf7f Mon Sep 17 00:00:00 2001 From: klee0kai Date: Mon, 6 Oct 2025 23:30:10 +0200 Subject: [PATCH 006/122] update lib versions. migrate to latest gradle --- gradle/wrapper/gradle-wrapper.properties | 2 +- libs.versions.toml | 20 ++++++++++--------- stone_lib/build.gradle.kts | 2 +- .../companies/consulting/build.gradle.kts | 2 +- test_feature_core_deps/build.gradle.kts | 3 +-- tests/build.gradle.kts | 2 +- tests_compile/build.gradle.kts | 2 +- tests_ext/build.gradle.kts | 2 +- tests_kotlin/build.gradle.kts | 2 +- tests_wraps/build.gradle.kts | 2 +- tests_wraps_kotlin/build.gradle.kts | 2 +- 11 files changed, 21 insertions(+), 20 deletions(-) diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 2733ed5d..d706aba6 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.13-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-9.1.0-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/libs.versions.toml b/libs.versions.toml index adb600ca..15f56755 100644 --- a/libs.versions.toml +++ b/libs.versions.toml @@ -2,18 +2,19 @@ stone = "1.0.7" -kotlin = "1.7.0" +kotlin = "2.2.20" ksp = "2.1.10-1.0.30" -appcompat = "1.6.1" +appcompat = "1.7.1" javax-inject = "1" -auto-service = "1.0.1" -incap = "0.3" +auto-service = "1.1.1" +incap = "1.0.0" javapoet = "1.13.0" -jupiter = "5.9.2" -testing-compile = "0.21.0" +junit = "6.0.0" +junit-launcher = "6.0.0" +testing-compile = "0.23.0" [libraries] @@ -32,14 +33,15 @@ javapoet = { group = "com.squareup", name = "javapoet", version.ref = "javapoet" ksp = { group = "com.google.devtools.ksp", name = "symbol-processing-api", version.ref = "ksp" } -jupiter-api = { group = "org.junit.jupiter", name = "junit-jupiter-api", version.ref = "jupiter" } -jupiter-engine = { group = "org.junit.jupiter", name = "junit-jupiter-engine", version.ref = "jupiter" } +jupiter-api = { group = "org.junit.jupiter", name = "junit-jupiter-api", version.ref = "junit" } +jupiter-engine = { group = "org.junit.jupiter", name = "junit-jupiter-engine", version.ref = "junit" } +jupiter-launcher = { group = "org.junit.platform", name = "junit-platform-launcher", version.ref = "junit-launcher" } testing-compile = { group = "com.google.testing.compile", name = "compile-testing", version.ref = "testing-compile" } [bundles] -jupiter = ["jupiter-api", "jupiter-engine"] +junit = ["jupiter-api", "jupiter-engine", "jupiter-launcher"] [plugins] diff --git a/stone_lib/build.gradle.kts b/stone_lib/build.gradle.kts index af867e1c..92cb002c 100644 --- a/stone_lib/build.gradle.kts +++ b/stone_lib/build.gradle.kts @@ -23,5 +23,5 @@ tasks.test { dependencies { api(libs.java.inject) - testImplementation(libs.bundles.jupiter) + testImplementation(libs.bundles.junit) } diff --git a/test_feature/companies/consulting/build.gradle.kts b/test_feature/companies/consulting/build.gradle.kts index 15ac540d..26e6aea2 100644 --- a/test_feature/companies/consulting/build.gradle.kts +++ b/test_feature/companies/consulting/build.gradle.kts @@ -20,6 +20,6 @@ dependencies { implementation(project(":stone_lib")) annotationProcessor(project(":stone_processor")) - testImplementation(libs.bundles.jupiter) + testImplementation(libs.bundles.junit) } diff --git a/test_feature_core_deps/build.gradle.kts b/test_feature_core_deps/build.gradle.kts index e2380adf..b01854ca 100644 --- a/test_feature_core_deps/build.gradle.kts +++ b/test_feature_core_deps/build.gradle.kts @@ -11,6 +11,5 @@ dependencies { implementation(project(":kotlin_lib")) kapt(project(":stone_processor")) - - testImplementation(libs.bundles.jupiter) + testImplementation(libs.bundles.junit) } diff --git a/tests/build.gradle.kts b/tests/build.gradle.kts index e4d958d2..10cbe8a0 100644 --- a/tests/build.gradle.kts +++ b/tests/build.gradle.kts @@ -10,6 +10,6 @@ dependencies { implementation(project(":stone_lib")) annotationProcessor(project(":stone_processor")) - testImplementation(libs.bundles.jupiter) + testImplementation(libs.bundles.junit) } diff --git a/tests_compile/build.gradle.kts b/tests_compile/build.gradle.kts index b6d88794..8c823144 100644 --- a/tests_compile/build.gradle.kts +++ b/tests_compile/build.gradle.kts @@ -11,7 +11,7 @@ dependencies { implementation(project(":stone_processor")) - testImplementation(libs.bundles.jupiter) + testImplementation(libs.bundles.junit) testImplementation(libs.testing.compile) } diff --git a/tests_ext/build.gradle.kts b/tests_ext/build.gradle.kts index 8781f985..1da66512 100644 --- a/tests_ext/build.gradle.kts +++ b/tests_ext/build.gradle.kts @@ -12,7 +12,7 @@ dependencies { implementation(project(":tests")) - testImplementation(libs.bundles.jupiter) + testImplementation(libs.bundles.junit) } diff --git a/tests_kotlin/build.gradle.kts b/tests_kotlin/build.gradle.kts index 65956549..c1273ae8 100644 --- a/tests_kotlin/build.gradle.kts +++ b/tests_kotlin/build.gradle.kts @@ -13,7 +13,7 @@ dependencies { implementation(project(":kotlin_lib")) kapt(project(":stone_processor")) - testImplementation(libs.bundles.jupiter) + testImplementation(libs.bundles.junit) } diff --git a/tests_wraps/build.gradle.kts b/tests_wraps/build.gradle.kts index e4d958d2..10cbe8a0 100644 --- a/tests_wraps/build.gradle.kts +++ b/tests_wraps/build.gradle.kts @@ -10,6 +10,6 @@ dependencies { implementation(project(":stone_lib")) annotationProcessor(project(":stone_processor")) - testImplementation(libs.bundles.jupiter) + testImplementation(libs.bundles.junit) } diff --git a/tests_wraps_kotlin/build.gradle.kts b/tests_wraps_kotlin/build.gradle.kts index db3aa524..5925044e 100644 --- a/tests_wraps_kotlin/build.gradle.kts +++ b/tests_wraps_kotlin/build.gradle.kts @@ -13,6 +13,6 @@ dependencies { implementation(project(":kotlin_lib")) kapt(project(":stone_processor")) - testImplementation(libs.bundles.jupiter) + testImplementation(libs.bundles.junit) } From fcd81fe3bbf13c24292b2791a563bd2f9909a49e Mon Sep 17 00:00:00 2001 From: klee0kai Date: Mon, 6 Oct 2025 23:43:44 +0200 Subject: [PATCH 007/122] Fixed argument for calling function from DefaultImpls --- .../com/github/klee0kai/stone/codegen/ModuleFactoryBuilder.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stone_processor/src/main/java/com/github/klee0kai/stone/codegen/ModuleFactoryBuilder.java b/stone_processor/src/main/java/com/github/klee0kai/stone/codegen/ModuleFactoryBuilder.java index 98c30799..eb084270 100644 --- a/stone_processor/src/main/java/com/github/klee0kai/stone/codegen/ModuleFactoryBuilder.java +++ b/stone_processor/src/main/java/com/github/klee0kai/stone/codegen/ModuleFactoryBuilder.java @@ -82,7 +82,7 @@ public ModuleFactoryBuilder provideMethodFrom(MethodDetail m, ClassDetail defaul String argStr = m.args == null ? "" : String.join("", ListUtils.format(m.args, (it) -> ", " + it.name)); SmartCode genCode = SmartCode.builder() - .add(CodeBlock.of("$T.$L( null $L )", defaultImpl.className, m.methodName, argStr)) + .add(CodeBlock.of("$T.$L( this $L )", defaultImpl.className, m.methodName, argStr)) .providingType(providingClass.className); builder.addCode( From de22caa11e0f4e3c7cddbf034e01a165772c7712 Mon Sep 17 00:00:00 2001 From: klee0kai Date: Sun, 12 Oct 2025 19:57:00 +0200 Subject: [PATCH 008/122] multiplatform library common api arch --- .gitignore | 3 +- android_lib/build.gradle.kts | 2 +- gradle.properties | 2 + libs.versions.toml | 7 +- settings.gradle.kts | 1 + stone_multiplatform/build.gradle.kts | 77 ++++++ .../stone/annotations/component/Component.kt | 260 ++++++++++++++++++ .../stone/annotations/component/ExtendOf.kt | 30 ++ .../stone/annotations/component/GcAllScope.kt | 10 + .../component/GcScopeAnnotation.kt | 29 ++ .../annotations/component/GcSoftScope.kt | 14 + .../annotations/component/GcStrongScope.kt | 14 + .../annotations/component/GcWeakScope.kt | 14 + .../stone/annotations/component/Init.kt | 32 +++ .../component/ModuleOriginFactory.kt | 26 ++ .../annotations/component/ProtectInjected.kt | 31 +++ .../stone/annotations/component/RunGc.kt | 38 +++ .../annotations/component/SwitchCache.kt | 73 +++++ .../annotations/dependencies/Dependencies.kt | 47 ++++ .../stone/annotations/module/BindInstance.kt | 86 ++++++ .../stone/annotations/module/Module.kt | 82 ++++++ .../stone/annotations/module/Provide.kt | 48 ++++ .../annotations/wrappers/WrappersCreator.kt | 22 ++ .../stone/lifecycle/StoneLifeCycleListener.kt | 7 + .../stone/lifecycle/StoneLifeCycleOwner.kt | 56 ++++ .../stone/wrappers/AsyncCoroutineProvide.kt | 22 ++ .../klee0kai/stone/wrappers/LazyProvide.kt | 21 ++ .../klee0kai/stone/wrappers/PhantomProvide.kt | 23 ++ .../com/github/klee0kai/stone/wrappers/Ref.kt | 9 + .../stone/wrappers/creators/CircleWrapper.kt | 15 + .../wrappers/creators/ProviderWrapper.kt | 16 ++ .../stone/wrappers/creators/Wrapper.kt | 14 + 32 files changed, 1128 insertions(+), 3 deletions(-) create mode 100644 stone_multiplatform/build.gradle.kts create mode 100644 stone_multiplatform/src/main/kotlin/com/github/klee0kai/stone/annotations/component/Component.kt create mode 100644 stone_multiplatform/src/main/kotlin/com/github/klee0kai/stone/annotations/component/ExtendOf.kt create mode 100644 stone_multiplatform/src/main/kotlin/com/github/klee0kai/stone/annotations/component/GcAllScope.kt create mode 100644 stone_multiplatform/src/main/kotlin/com/github/klee0kai/stone/annotations/component/GcScopeAnnotation.kt create mode 100644 stone_multiplatform/src/main/kotlin/com/github/klee0kai/stone/annotations/component/GcSoftScope.kt create mode 100644 stone_multiplatform/src/main/kotlin/com/github/klee0kai/stone/annotations/component/GcStrongScope.kt create mode 100644 stone_multiplatform/src/main/kotlin/com/github/klee0kai/stone/annotations/component/GcWeakScope.kt create mode 100644 stone_multiplatform/src/main/kotlin/com/github/klee0kai/stone/annotations/component/Init.kt create mode 100644 stone_multiplatform/src/main/kotlin/com/github/klee0kai/stone/annotations/component/ModuleOriginFactory.kt create mode 100644 stone_multiplatform/src/main/kotlin/com/github/klee0kai/stone/annotations/component/ProtectInjected.kt create mode 100644 stone_multiplatform/src/main/kotlin/com/github/klee0kai/stone/annotations/component/RunGc.kt create mode 100644 stone_multiplatform/src/main/kotlin/com/github/klee0kai/stone/annotations/component/SwitchCache.kt create mode 100644 stone_multiplatform/src/main/kotlin/com/github/klee0kai/stone/annotations/dependencies/Dependencies.kt create mode 100644 stone_multiplatform/src/main/kotlin/com/github/klee0kai/stone/annotations/module/BindInstance.kt create mode 100644 stone_multiplatform/src/main/kotlin/com/github/klee0kai/stone/annotations/module/Module.kt create mode 100644 stone_multiplatform/src/main/kotlin/com/github/klee0kai/stone/annotations/module/Provide.kt create mode 100644 stone_multiplatform/src/main/kotlin/com/github/klee0kai/stone/annotations/wrappers/WrappersCreator.kt create mode 100644 stone_multiplatform/src/main/kotlin/com/github/klee0kai/stone/lifecycle/StoneLifeCycleListener.kt create mode 100644 stone_multiplatform/src/main/kotlin/com/github/klee0kai/stone/lifecycle/StoneLifeCycleOwner.kt create mode 100644 stone_multiplatform/src/main/kotlin/com/github/klee0kai/stone/wrappers/AsyncCoroutineProvide.kt create mode 100644 stone_multiplatform/src/main/kotlin/com/github/klee0kai/stone/wrappers/LazyProvide.kt create mode 100644 stone_multiplatform/src/main/kotlin/com/github/klee0kai/stone/wrappers/PhantomProvide.kt create mode 100644 stone_multiplatform/src/main/kotlin/com/github/klee0kai/stone/wrappers/Ref.kt create mode 100644 stone_multiplatform/src/main/kotlin/com/github/klee0kai/stone/wrappers/creators/CircleWrapper.kt create mode 100644 stone_multiplatform/src/main/kotlin/com/github/klee0kai/stone/wrappers/creators/ProviderWrapper.kt create mode 100644 stone_multiplatform/src/main/kotlin/com/github/klee0kai/stone/wrappers/creators/Wrapper.kt diff --git a/.gitignore b/.gitignore index 835e8dca..8b636d9c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ .gradle .idea -build \ No newline at end of file +build +.kotlin \ No newline at end of file diff --git a/android_lib/build.gradle.kts b/android_lib/build.gradle.kts index 33d71ef6..07cfd5a0 100644 --- a/android_lib/build.gradle.kts +++ b/android_lib/build.gradle.kts @@ -1,5 +1,5 @@ plugins { - alias(libs.plugins.android.libarary) + alias(libs.plugins.android.library) alias(libs.plugins.publish.maven) alias(libs.plugins.publish.stone) } diff --git a/gradle.properties b/gradle.properties index 01b80d70..bfe48ae2 100644 --- a/gradle.properties +++ b/gradle.properties @@ -17,3 +17,5 @@ org.gradle.jvmargs=-Xmx2048m -Dfile.encoding=UTF-8 android.useAndroidX=true # Automatically convert third-party libraries to use AndroidX android.enableJetifier=true + +kotlin.mpp.enableCInteropCommonization=false diff --git a/libs.versions.toml b/libs.versions.toml index 15f56755..3c216b75 100644 --- a/libs.versions.toml +++ b/libs.versions.toml @@ -4,9 +4,11 @@ stone = "1.0.7" kotlin = "2.2.20" ksp = "2.1.10-1.0.30" +agp = "8.12.3" appcompat = "1.7.1" javax-inject = "1" +kotlinx-coroutines = "1.10.1" auto-service = "1.1.1" incap = "1.0.0" @@ -24,6 +26,8 @@ android-appcompat = { group = "androidx.appcompat", name = "appcompat", version. # https://mvnrepository.com/artifact/javax.inject/javax.inject java-inject = { group = "javax.inject", name = "javax.inject", version.ref = "javax-inject" } +kotlinx-coroutines = { group = "org.jetbrains.kotlinx", name = "kotlinx-coroutines-core", version.ref = "kotlinx-coroutines" } + auto-service = { group = "com.google.auto.service", name = "auto-service", version.ref = "auto-service" } incap = { group = "net.ltgt.gradle.incap", name = "incap", version.ref = "incap" } @@ -48,7 +52,8 @@ junit = ["jupiter-api", "jupiter-engine", "jupiter-launcher"] kotlin-ksp = { id = "com.google.devtools.ksp", version.ref = "ksp" } kotlin-jvm = { id = "org.jetbrains.kotlin.jvm", version.ref = "kotlin" } kotlin-kapt = { id = "org.jetbrains.kotlin.kapt", version.ref = "kotlin" } -android-libarary = { id = "com.android.library", version = "8.12.3" } +kotlin-multiplatform = { id = "org.jetbrains.kotlin.multiplatform", version.ref = "kotlin" } +android-library = { id = "com.android.library", version.ref = "agp" } publish-maven = { id = "org.gradle.maven-publish" } publish-stone = { id = "com.github.klee0kai.stone.publish" } diff --git a/settings.gradle.kts b/settings.gradle.kts index 58ab43ce..696b0223 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -22,6 +22,7 @@ dependencyResolutionManagement { rootProject.name = "Stone" includeBuild("plugin_publish") include(":stone_lib") +include(":stone_multiplatform") include(":stone_processor") include(":android_lib") include(":kotlin_lib") diff --git a/stone_multiplatform/build.gradle.kts b/stone_multiplatform/build.gradle.kts new file mode 100644 index 00000000..d5804fcf --- /dev/null +++ b/stone_multiplatform/build.gradle.kts @@ -0,0 +1,77 @@ +plugins { + alias(libs.plugins.kotlin.multiplatform) + alias(libs.plugins.android.library) +} + +group = "com.github.klee0kai.stone" +version = libs.versions.stone.get() + +android { + namespace = project.group.toString() + compileSdk = 36 + defaultConfig { + minSdk = 21 + } +} + +kotlin { + androidTarget() + + jvm() + js(IR) { + browser() + nodejs() + } + + targets.all { + compilations.all { + compilerOptions.configure { + freeCompilerArgs.add("-Xskip-prerelease-check") + } + } + } + + sourceSets { + val commonMain by getting { + dependencies { + api(libs.java.inject) + api(libs.kotlinx.coroutines) + } + } + } +} + +val isMac = System.getProperty("os.name").contains("Mac") +if (isMac) kotlin { + iosX64() + iosArm64() + iosSimulatorArm64() + + sourceSets { + val commonMain by getting + val commonTest by getting + val iosX64Main by getting + val iosArm64Main by getting + val iosSimulatorArm64Main by getting + + val iosMain by creating { + dependsOn(commonMain) + iosX64Main.dependsOn(this) + iosArm64Main.dependsOn(this) + iosSimulatorArm64Main.dependsOn(this) + } + + + val iosX64Test by getting + val iosArm64Test by getting + val iosSimulatorArm64Test by getting + val iosTest by creating { + dependsOn(commonTest) + iosX64Test.dependsOn(this) + iosArm64Test.dependsOn(this) + iosSimulatorArm64Test.dependsOn(this) + } + } +} + + diff --git a/stone_multiplatform/src/main/kotlin/com/github/klee0kai/stone/annotations/component/Component.kt b/stone_multiplatform/src/main/kotlin/com/github/klee0kai/stone/annotations/component/Component.kt new file mode 100644 index 00000000..59e29fe1 --- /dev/null +++ b/stone_multiplatform/src/main/kotlin/com/github/klee0kai/stone/annotations/component/Component.kt @@ -0,0 +1,260 @@ +package com.github.klee0kai.stone.annotations.component + +import kotlin.reflect.KClass + + +/** + * The main component of providing dependencies. + * Here we list the modules for creating objects. + * Can be a public class, an abstract class, or an interface. + * + * + * Based on this class, the library generates a child class `ClassName`StoneComponent. + * Which can be used directly, or simplified notation. + * + * + * `ClassName` DI = Stone.createComponent(`ClassName`.class); + * + * + * **Modules** + * + * + * In the DI component, you can declare the modules used. + * To do this, you need to create a class with the @Module annotation, and provide it in the component. + * + * + *
`ㅤ@Component
+ * public abstract class AppComponent {
+ * public abstract RepositoriesModule repositories();
+ * }
+ *
+ * ㅤ@Module
+ * public interface RepositoriesModule{
+ * // some code
+ * }
+`
* + * Modules can be used directly. + * Also, declared modules in the component are used to resolve dependencies into injection methods, + * as well as into provider methods in the component. + * + * + * Providing a module can be replaced by calling an initialization method. + *
`ㅤ@Component
+ * public abstract class AppComponent {
+ * public abstract RepositoriesModule repositories();
+ * ㅤ@Init
+ * void initRepositories(RepositoriesModule repositories);
+ * }
+ *
+`
* + * + * + * Moreover, this initialization can be performed as when creating a component, + * and when using this component directly. + * In this case, the objects provided in the module will be replaced gradually as they are destroyed in memory. + * + * + * + * **Dependencies** + * + * + * All component dependencies are declared in the same way as modules. + * Dependency classes must use the `@Dependencies` annotation + *
`ㅤ@Component
+ * public abstract class FeatureComponent {
+ * public abstract CommonDependencies dependencies();
+ * ㅤ@Init
+ * void initDependencies(CommonDependencies dependencies);
+ * }
+ *
+ * ㅤ@Dependencies
+ * public interface CommonDependencies{
+ * // some code
+ * }
+`
* + * Note that dependencies must be initialized before use. + * + * + * Dependencies are not cached because + * they are already cached in their component or in their factory, the provider. + * + * + * + * **Provide objects** + * + * + * If a component contains at least one module, it can directly provide the dependencies + * of that and its other modules directly. + * + * + * In a component, you can declare a provider method of any object that is provided in one of its modules. + * By providing this object, dependencies will be resolved automatically. + *
`ㅤ@Component
+ * public interface CarComponent {
+ *
+ * CarModule module();
+ *
+ * Car car();
+ * }
+ *
+ * ㅤ@Module
+ * public interface CarModule{
+ * Wheel wheel();
+ * Window window();
+ * Bumper bumper();
+ *
+ * Car car(Wheel wheel,Window window, Bumper bumper);
+ * }
+`
* + * You can also use additional identifiers to provide a unique object instance. + * The result can be wrapped in declared wrappers, for example, lazy providing, and asynchronous providing. + * + * + * + * **Bind Instances** + * + * + * The library allows you to use already known objects in the application as dependencies, as well as provisioning. + * + * + * To do this, it is enough to declare the provision of an object with the `@BindInstance` annotation, if the declaration is performed directly in the component. + * Or without this annotation, if it has already been used in the module. + * + * + * + * **Inject** + * + * + * DI allows you to provide objects to classes. + * To do this, it is enough to declare an injection method without a return type, + * with only one argument - the injection class. + *
`ㅤ@Component
+ * public interface AppComponent {
+ * void inject(Activity activity);
+ * }
+`
* + * When this method is called, + * all fields and methods with the `@Inject` annotation will be initialized or called. + * + * + * + * **Initialization** + * + * + * The component allows you to initialize its dependencies and modules with the @Init annotation. + * + * + * + * **Extension** + * + * + * A component can extend another component with the `ExtendOf` annotation. + * When one component is extended by another, both begin to provide child component objects. + * + * + * At the same time, object caching is temporarily preserved for the parent component. + * New objects are provided after being cleared from memory, + * or after explicitly using a child component. + * + *
`ㅤ@Component
+ * public interface AppProComponent extends AppComponent {
+ *
+ * ㅤ@ExtendOf
+ * void extOf(AppComponent parent);
+ *
+ * }
+`
* + * + * + * **GC collect** + * + * + * The library allows you to explicitly call garbage collection for cached objects. + * To do this, you need to declare a method without arguments and a return value + * with the @RunGc annotation and one or more scopes. + *
`ㅤ@Component
+ * public interface AppProComponent extends AppComponent {
+ *
+ * ㅤ@RunGc
+ * ㅤ@GcAllScope
+ * void gcAll();
+ *
+ * }
+`
* + * Caching will be cleared only for those objects + * that are not actually used in the application and are not held by anyone. + * If you hold on to the provided and cached object when calling this method, it will not be destroyed. + * + * + * **Switch cache** + * + * + * DI also allows you to change the caching for provided objects. + * To do this, you need to declare a method without arguments and a return value, + * use one of the GC scopes, and additionally use the `@SwitchCache` annotation + */ +@Retention(AnnotationRetention.BINARY) +@Target(AnnotationTarget.CLASS) +annotation class Component( + /** + * You can use object identifiers. + * Identifiers allow you to provide and cache unique instances of an object. + * + * + * To use identifiers, you need to declare object types, + * implementing the `hashCode` and `equals` methods (Kotlin data classes) + * and list them when declaring the component. + *
`ㅤ@Component(identifiers = [PresenterTag::class])
+     * interface AppComponent {
+     * PresentersModule module();
+     * WelcomePresenter welcomePresenter(PresenterTag tag);
+     * }
+     *
+     * ㅤ@Module
+     * interface PresentersModule {
+     * WelcomePresenter createWelcomePresenter(PresenterTag tag);
+     * }
+    `
* + * + * + * Identifiers are also used when resolving dependencies. + * For example, if a dependency uses an identifier, + * then when providing an object with dependencies, + * the dependency will be created by a unique identifier. + * + * + * If you want to use different identifiers for a provided object and its dependencies, + * use identifiers of different types. + * + * + * If no identifier is specified when providing the object, it will be null instead. + */ + val identifiers: Array> = [], + /** + * The library allows you to provide objects in wrappers. + * Various wrappers allow, for example, to perform lazy or asynchronous providingF of objects, + * or not to keep cached objects in DI. + * Wrapping also allows you to render several different objects into one list. + * + * + * The library contains a sufficient set of provider wrappers. + * However, if that's not enough, you can implement your own wrapping implementation + * class-based: `ProviderWrapper` and `Wrapper`. + * It is enough to override these classes, and use the `@WrappersCreator` annotation + * to list the wrappers implemented in this class. + *
`ㅤ@WrappersCreator(wrappers = {CarRef.class})
+     * public class CarWrapper implements Wrapper {
+     *
+     * ㅤ@Override
+     * public  Wr wrap(Class wrapperCl, T original) {
+     * if (wrapperCl.equals(CarRef.class)) {
+     * return (Wr) new CarRef<>(original);
+     *
+     * }
+     * return null;
+     * }
+     * }
+    `
* + */ + val wrapperProviders: Array> = [] +) diff --git a/stone_multiplatform/src/main/kotlin/com/github/klee0kai/stone/annotations/component/ExtendOf.kt b/stone_multiplatform/src/main/kotlin/com/github/klee0kai/stone/annotations/component/ExtendOf.kt new file mode 100644 index 00000000..366a3693 --- /dev/null +++ b/stone_multiplatform/src/main/kotlin/com/github/klee0kai/stone/annotations/component/ExtendOf.kt @@ -0,0 +1,30 @@ +package com.github.klee0kai.stone.annotations.component + + +/** + * A component extends a parent component. + * With the help of such an annotation, an extension method is declared on the parent component. + *
`ㅤ@Component
+ * public interface AppExtendComponent extends AppComponent {
+ *
+ * ㅤ@ExtendOf
+ * void extOf(AppComponent parent);
+ *
+ * }
+`
* + * + * + * For the parent component, all object creation factories are replaced with new ones, + * from the child extending component. + * Components become interconnected, all cleanups, + * caching type changes are performed simultaneously for both components. + * + * + * The replacement of generated and provided objects is not done immediately, but gradually. + * As they are cleared from memory. + * Be careful, the new objects provided should extend the functionality of the previous ones, not break the old logic. + * In some cases, interaction between objects of different versions is possible. + */ +@Retention(AnnotationRetention.BINARY) +@Target(AnnotationTarget.FUNCTION, AnnotationTarget.PROPERTY_GETTER, AnnotationTarget.PROPERTY_SETTER) +annotation class ExtendOf diff --git a/stone_multiplatform/src/main/kotlin/com/github/klee0kai/stone/annotations/component/GcAllScope.kt b/stone_multiplatform/src/main/kotlin/com/github/klee0kai/stone/annotations/component/GcAllScope.kt new file mode 100644 index 00000000..28333808 --- /dev/null +++ b/stone_multiplatform/src/main/kotlin/com/github/klee0kai/stone/annotations/component/GcAllScope.kt @@ -0,0 +1,10 @@ +package com.github.klee0kai.stone.annotations.component + +/** + * A scope that defines all exposed objects in DI. + * Used for garbage collection and caching change methods. + */ +@GcScopeAnnotation +@Retention(AnnotationRetention.BINARY) +@Target(AnnotationTarget.FUNCTION, AnnotationTarget.PROPERTY_GETTER, AnnotationTarget.PROPERTY_SETTER) +annotation class GcAllScope diff --git a/stone_multiplatform/src/main/kotlin/com/github/klee0kai/stone/annotations/component/GcScopeAnnotation.kt b/stone_multiplatform/src/main/kotlin/com/github/klee0kai/stone/annotations/component/GcScopeAnnotation.kt new file mode 100644 index 00000000..30af6d98 --- /dev/null +++ b/stone_multiplatform/src/main/kotlin/com/github/klee0kai/stone/annotations/component/GcScopeAnnotation.kt @@ -0,0 +1,29 @@ +package com.github.klee0kai.stone.annotations.component + + +/** + * Annotation announcing new scopes for garbage collection and changing the caching method. + * Announce new scopes in the following way. + * + *
`ㅤ@GcScopeAnnotation
+ * ㅤ@Retention(RUNTIME)
+ * ㅤ@Target(METHOD)
+ * public @interface GcPlanetScope {
+ * }
+`
* + * Instead of this annotation, you can use the more general [javax.inject.Scope] + * annotation. + * + *
`ㅤ@Scope
+ * ㅤ@Retention(RUNTIME)
+ * ㅤ@Target(METHOD)
+ * public @interface GcPlanetScope {
+ * }
+`
* + * + * + * Not Follow [javax.inject.Scope] documentation. + */ +@Retention(AnnotationRetention.BINARY) +@Target(AnnotationTarget.ANNOTATION_CLASS) +annotation class GcScopeAnnotation diff --git a/stone_multiplatform/src/main/kotlin/com/github/klee0kai/stone/annotations/component/GcSoftScope.kt b/stone_multiplatform/src/main/kotlin/com/github/klee0kai/stone/annotations/component/GcSoftScope.kt new file mode 100644 index 00000000..cb22574c --- /dev/null +++ b/stone_multiplatform/src/main/kotlin/com/github/klee0kai/stone/annotations/component/GcSoftScope.kt @@ -0,0 +1,14 @@ +package com.github.klee0kai.stone.annotations.component + + +import javax.inject.Scope + +/** + * A standard library scope that lists all cached objects using soft references. + * Used for garbage collection and caching change methods. + */ +@GcScopeAnnotation +@Scope +@Retention(AnnotationRetention.BINARY) +@Target(AnnotationTarget.FUNCTION, AnnotationTarget.PROPERTY_GETTER, AnnotationTarget.PROPERTY_SETTER) +annotation class GcSoftScope diff --git a/stone_multiplatform/src/main/kotlin/com/github/klee0kai/stone/annotations/component/GcStrongScope.kt b/stone_multiplatform/src/main/kotlin/com/github/klee0kai/stone/annotations/component/GcStrongScope.kt new file mode 100644 index 00000000..a6efcfcb --- /dev/null +++ b/stone_multiplatform/src/main/kotlin/com/github/klee0kai/stone/annotations/component/GcStrongScope.kt @@ -0,0 +1,14 @@ +package com.github.klee0kai.stone.annotations.component + + +import javax.inject.Scope + +/** + * A standard library scope that enumerates all cacheable objects using strong references. + * Used for garbage collection and caching change methods. + */ +@GcScopeAnnotation +@Scope +@Retention(AnnotationRetention.BINARY) +@Target(AnnotationTarget.FUNCTION, AnnotationTarget.PROPERTY_GETTER, AnnotationTarget.PROPERTY_SETTER) +annotation class GcStrongScope diff --git a/stone_multiplatform/src/main/kotlin/com/github/klee0kai/stone/annotations/component/GcWeakScope.kt b/stone_multiplatform/src/main/kotlin/com/github/klee0kai/stone/annotations/component/GcWeakScope.kt new file mode 100644 index 00000000..32a2d218 --- /dev/null +++ b/stone_multiplatform/src/main/kotlin/com/github/klee0kai/stone/annotations/component/GcWeakScope.kt @@ -0,0 +1,14 @@ +package com.github.klee0kai.stone.annotations.component + + +import javax.inject.Scope + +/** + * A standard library scope that enumerates all cacheable objects using weak references. + * Used for garbage collection and caching change methods. + */ +@GcScopeAnnotation +@Scope +@Retention(AnnotationRetention.BINARY) +@Target(AnnotationTarget.FUNCTION, AnnotationTarget.PROPERTY_GETTER, AnnotationTarget.PROPERTY_SETTER) +annotation class GcWeakScope diff --git a/stone_multiplatform/src/main/kotlin/com/github/klee0kai/stone/annotations/component/Init.kt b/stone_multiplatform/src/main/kotlin/com/github/klee0kai/stone/annotations/component/Init.kt new file mode 100644 index 00000000..f3e0d55a --- /dev/null +++ b/stone_multiplatform/src/main/kotlin/com/github/klee0kai/stone/annotations/component/Init.kt @@ -0,0 +1,32 @@ +package com.github.klee0kai.stone.annotations.component + + +/** + * Initializing a module or dependency in a component. + * + * + * An initialization method is declared in a component that accepts an instance of the module or its class. + * + *
`ㅤ@Component
+ * interface AppComponent() {
+ *
+ * ㅤ@Init
+ * void initRepositoriesModule(RepositoriesModule module);
+ *
+ * ㅤ@Init
+ * void initRepositoriesModule(Class module);
+ *
+ * }
+ *
+ * ㅤㅤ@Module
+ * interface RepositoriesModule{
+ * // some code
+ * }
+`
* + * + * + * Dependencies can only be initialized on an instance. + */ +@Retention(AnnotationRetention.BINARY) +@Target(AnnotationTarget.FUNCTION, AnnotationTarget.PROPERTY_GETTER, AnnotationTarget.PROPERTY_SETTER) +annotation class Init diff --git a/stone_multiplatform/src/main/kotlin/com/github/klee0kai/stone/annotations/component/ModuleOriginFactory.kt b/stone_multiplatform/src/main/kotlin/com/github/klee0kai/stone/annotations/component/ModuleOriginFactory.kt new file mode 100644 index 00000000..ea0a1660 --- /dev/null +++ b/stone_multiplatform/src/main/kotlin/com/github/klee0kai/stone/annotations/component/ModuleOriginFactory.kt @@ -0,0 +1,26 @@ +package com.github.klee0kai.stone.annotations.component + + +/** + * Provide origin module's factory + * + *
`ㅤ@Component
+ * interface AppComponent() {
+ *
+ * ㅤ@ModuleOriginFactory
+ * RepositoriesModule repModuleFactory();
+ *
+ * }
+ *
+ * ㅤㅤ@Module
+ * interface RepositoriesModule{
+ * // some code
+ * }
+`
* + * + * + * Dependencies can only be initialized on an instance. + */ +@Retention(AnnotationRetention.BINARY) +@Target(AnnotationTarget.FUNCTION, AnnotationTarget.PROPERTY_GETTER, AnnotationTarget.PROPERTY_SETTER) +annotation class ModuleOriginFactory diff --git a/stone_multiplatform/src/main/kotlin/com/github/klee0kai/stone/annotations/component/ProtectInjected.kt b/stone_multiplatform/src/main/kotlin/com/github/klee0kai/stone/annotations/component/ProtectInjected.kt new file mode 100644 index 00000000..6d1614c7 --- /dev/null +++ b/stone_multiplatform/src/main/kotlin/com/github/klee0kai/stone/annotations/component/ProtectInjected.kt @@ -0,0 +1,31 @@ +package com.github.klee0kai.stone.annotations.component + + +/** + * Protect provided objects from being destroyed by injection. + * When a dependency consumer class is re-created, cached objects may be garbage collected. + * This can be prevented by calling the deletion protection method. + *
`ㅤ@Component
+ * public interface AppComponent {
+ *
+ *
+ * void inject(Activity activity);
+ *
+ * ㅤ@ProtectInjected
+ * void protectInjected();
+ *
+ * }
+`
* + * + * + * Deletion protection changes object caching to strict. Objects cannot be deleted for some time. + */ +@Retention(AnnotationRetention.BINARY) +@Target(AnnotationTarget.FUNCTION, AnnotationTarget.PROPERTY_GETTER, AnnotationTarget.PROPERTY_SETTER) +annotation class ProtectInjected( + /** + * protect time millis. + * Default protect 5 sec. + */ + val timeMillis: Long = 5000L +) diff --git a/stone_multiplatform/src/main/kotlin/com/github/klee0kai/stone/annotations/component/RunGc.kt b/stone_multiplatform/src/main/kotlin/com/github/klee0kai/stone/annotations/component/RunGc.kt new file mode 100644 index 00000000..1dbb8a79 --- /dev/null +++ b/stone_multiplatform/src/main/kotlin/com/github/klee0kai/stone/annotations/component/RunGc.kt @@ -0,0 +1,38 @@ +package com.github.klee0kai.stone.annotations.component + + +/** + * Garbage collection in the selected scope. + * We explicitly clean up unused objects in DI. + * + * + * In fact, only those objects that are used and not held by anyone will be deleted. + *
`ㅤ@Component
+ * interface AppComponent {
+ *
+ * ㅤ@GcAllScope
+ * ㅤ@AuthScope
+ * ㅤ@RunGc
+ * public void authWeak();
+ *
+ * }
+ *
+ * ㅤ@GcScopeAnnotation
+ * ㅤ@Retention(value = RetentionPolicy.CLASS)
+ * ㅤ@Target(value = ElementType.METHOD)
+ * public @interface AuthScope {
+ * }
+`
* + * + * + * Can be used with multiple garbage collector scopes. + * The final scope will be the intersection of several. + * + * + * Caching will be cleared only for those objects that are not actually used in the application and are not held by anyone. + * If you hold on to the provided and cached object when calling this method, it will not be destroyed. + * Objects cached by a Weak link will almost always be collected when not in use. + */ +@Retention(AnnotationRetention.BINARY) +@Target(AnnotationTarget.FUNCTION, AnnotationTarget.PROPERTY_GETTER, AnnotationTarget.PROPERTY_SETTER) +annotation class RunGc diff --git a/stone_multiplatform/src/main/kotlin/com/github/klee0kai/stone/annotations/component/SwitchCache.kt b/stone_multiplatform/src/main/kotlin/com/github/klee0kai/stone/annotations/component/SwitchCache.kt new file mode 100644 index 00000000..0cba3ec7 --- /dev/null +++ b/stone_multiplatform/src/main/kotlin/com/github/klee0kai/stone/annotations/component/SwitchCache.kt @@ -0,0 +1,73 @@ +package com.github.klee0kai.stone.annotations.component + + +/** + * Changing the caching method. + * Changes the caching method for cached objects, temporarily or permanently. + * + * + * Allows in this way either to speed up the cleaning of unused objects from memory, or to protect them from deletion. + * + *
`ㅤ@Component
+ * interface AppComponent {
+ *
+ * ㅤ@GcAllScope
+ * ㅤ@AuthScope
+ * ㅤ@SwitchCache(cache = SwitchCache.CacheType.Weak)
+ * public void authWeak();
+ *
+ * }
+ *
+ * ㅤ@GcScopeAnnotation
+ * ㅤ@Retention(value = RetentionPolicy.CLASS)
+ * ㅤ@Target(value = ElementType.METHOD)
+ * public @interface AuthScope {
+ * }
+`
* + * + * + * Can be used with multiple garbage collector scopes. + * The final scope will be the intersection of several. + */ +@Retention(AnnotationRetention.BINARY) +@Target(AnnotationTarget.FUNCTION, AnnotationTarget.PROPERTY_GETTER, AnnotationTarget.PROPERTY_SETTER) +annotation class SwitchCache( + /** + * new cache type for providing items + * + */ + val cache: CacheType = CacheType.Default, + /** + * Switch cache time duration. + * After time cache restored to default. + * + */ + val timeMillis: Long = -1 +) { + enum class CacheType { + /** + * restore Default config cache + */ + Default, + + /** + * reset cache + */ + Reset, + + /** + * switch cache to weak. + */ + Weak, + + /** + * switch cache to soft. + */ + Soft, + + /** + * switch cache to strong. + */ + Strong + } +} diff --git a/stone_multiplatform/src/main/kotlin/com/github/klee0kai/stone/annotations/dependencies/Dependencies.kt b/stone_multiplatform/src/main/kotlin/com/github/klee0kai/stone/annotations/dependencies/Dependencies.kt new file mode 100644 index 00000000..049d2ea0 --- /dev/null +++ b/stone_multiplatform/src/main/kotlin/com/github/klee0kai/stone/annotations/dependencies/Dependencies.kt @@ -0,0 +1,47 @@ +package com.github.klee0kai.stone.annotations.dependencies + + +/** + * Component dependencies are provided through a class annotated with `@Dependencies`. + * When resolving dependencies, the objects declared in this class will also be used. + * + * + * The signature of a dependency class is the same as that of a module. + * In this class, you just need to enumerate the provided objects and dependencies as interface methods. + * + *
`ㅤ@Dependencies
+ * public interface CarDependencies {
+ *
+ * Wheel wheel();
+ *
+ * Bumper bumper();
+ *
+ * Window window();
+ *
+ * }
+`
* + * Any factory, provider, or DI component can provide these dependencies by simply implementing this interface. + *
`ㅤ@Component
+ * public abstract class AppComponent implements CommonDependencies {
+ * // some code
+ * }
+ *
+ * ㅤ@Dependencies
+ * public interface CommonDependencies{
+ * // some code
+ * }
+`
* + * + * + * In your component, you simply initialize these dependencies. + *
`ㅤ@Comonent
+ * public abstract class FeatureComponent {
+ * public abstract CommonDependencies dependencies();
+ * ㅤ@Init
+ * void initDependencies(CommonDependencies dependencies);
+ * }
+`
* + */ +@Retention(AnnotationRetention.BINARY) +@Target(AnnotationTarget.CLASS) +annotation class Dependencies diff --git a/stone_multiplatform/src/main/kotlin/com/github/klee0kai/stone/annotations/module/BindInstance.kt b/stone_multiplatform/src/main/kotlin/com/github/klee0kai/stone/annotations/module/BindInstance.kt new file mode 100644 index 00000000..69c63ac7 --- /dev/null +++ b/stone_multiplatform/src/main/kotlin/com/github/klee0kai/stone/annotations/module/BindInstance.kt @@ -0,0 +1,86 @@ +package com.github.klee0kai.stone.annotations.module + +import java.lang.annotation.Inherited + + +/** + * Those objects that are created outside of DI. + * Can be included in DI by using the `@BindInstance` annotation + * + * + * Binding can be declared in a module. + * To do this, we define the provider method in the module and the binding method in the module. + *
`ㅤ@Component
+ * public interface SpaceComponent {
+ *
+ * SunSystemModule sunSystem();
+ *
+ * ㅤ@BindInstance
+ * void bindSun(Sun sun);
+ *
+ * }
+ *
+ * ㅤ@Module
+ * public interface SunSystemModule {
+ *
+ * ㅤ@BindInstance
+ * Sun sun();
+ *
+ * }
+`
* + * + * + * The method in the module should not contain arguments, but only return an object. + * A method in a component should only receive that object as an argument. + * Further, this object can already be passed in the component directly or through injection. + *
`ㅤ@Component
+ * public interface SpaceComponent {
+ * // some code
+ *
+ * // providing method
+ * Sun sun();
+ *
+ * }
+`
* + * + * + * The second way to declare the use of binding is to declare everything in one method in the DI component. + *
`ㅤ@Component
+ * public interface SpaceComponent {
+ *
+ * ㅤ@BindInstance
+ * Sun sun(Sun sun);
+ *
+ * }
+`
* + * + * + * The method receives and returns the same type. If null is passed as an argument, + * then the value of the binding does not change, but the object is simply provided. + * + * + * Binding does not support nulling. Use different caching methods. + */ +@Retention(AnnotationRetention.BINARY) +@Target(AnnotationTarget.FUNCTION, AnnotationTarget.PROPERTY_GETTER, AnnotationTarget.PROPERTY_SETTER) +@Inherited +annotation class BindInstance( + /** + * Object caching type + * + * * Factory - creation of new objects without caching. + * * Weak - caching weak reference objects. + * * Soft - caching objects with a soft link. + * * Strong - caching objects with a strong link. + * + * + * + */ + val cache: CacheType = CacheType.Soft +) { + enum class CacheType { + Weak, + Soft, + Strong + } +} diff --git a/stone_multiplatform/src/main/kotlin/com/github/klee0kai/stone/annotations/module/Module.kt b/stone_multiplatform/src/main/kotlin/com/github/klee0kai/stone/annotations/module/Module.kt new file mode 100644 index 00000000..91c0b934 --- /dev/null +++ b/stone_multiplatform/src/main/kotlin/com/github/klee0kai/stone/annotations/module/Module.kt @@ -0,0 +1,82 @@ +package com.github.klee0kai.stone.annotations.module + + +/** + * You can provide new dependencies and objects via modules. + * Stone supports the announcement of new dependencies and providers. + * A module can be a public class, an abstract class, or an interface. + * + * + * Each object provision must use one of the 2 annotations. + * `@Provide` - providing a new object + * `@BindInstance` - providing an already known object in the application. + * If you do not specify any of the specified annotations, + * then the `@Provide` annotation is assumed by default. + * + * + * So for example in the machine creation module + *
`ㅤ@Module
+ * public abstract class CarModule {
+ *
+ * ㅤ@BindInstance
+ * abstract Wheel wheel();
+ *
+ * ㅤ@Provide
+ * Bumper bumper(){
+ * return new Bumper();
+ * }
+ *
+ * Window window(){
+ * return new Window();
+ * }
+ *
+ * }
+`
* + * + * + * In our case, the wheel must be defined when initializing the DI component, + * the bumper and the window have the same behavior - each time a new one is created. + * + * + * Each element can be cached by specifying how the object is cached. + *
`ㅤ@Module
+ * public abstract class CarModule {
+ *
+ * ㅤ@BindInstance(cache = BindInstance.CacheType.Weak)
+ * abstract Wheel wheel();
+ *
+ * ㅤ@Provide(cache = Provide.CacheType.Weak)
+ * Bumper bumper(){
+ * return new Bumper();
+ * }
+ *
+ * ㅤ@Provide(cache = Provide.CacheType.Soft)
+ * Window window(){
+ * return new Window();
+ * }
+ *
+ * }
+`
* + * + * + * And also, you can not explicitly specify the use of the constructor. + * The constructor will be found by the library automatically when using parameters. + * + *
`ㅤ@Module
+ * public interface CarModule {
+ *
+ * ㅤ@BindInstance(cache = BindInstance.CacheType.Weak)
+ * Wheel wheel();
+ *
+ * ㅤ@Provide(cache = Provide.CacheType.Weak)
+ * Bumper bumper();
+ *
+ * ㅤ@Provide(cache = Provide.CacheType.Soft)
+ * Window window();
+ *
+ * }
+`
* + */ +@Retention(AnnotationRetention.BINARY) +@Target(AnnotationTarget.CLASS) +annotation class Module diff --git a/stone_multiplatform/src/main/kotlin/com/github/klee0kai/stone/annotations/module/Provide.kt b/stone_multiplatform/src/main/kotlin/com/github/klee0kai/stone/annotations/module/Provide.kt new file mode 100644 index 00000000..6695e33d --- /dev/null +++ b/stone_multiplatform/src/main/kotlin/com/github/klee0kai/stone/annotations/module/Provide.kt @@ -0,0 +1,48 @@ +package com.github.klee0kai.stone.annotations.module + +import java.lang.annotation.Inherited + + +/** + * Providing objects. + * This annotation marks the methods in the module for providing objects. + * + * + * The object can be created each time a new one, or cached. + * To use a specific caching method, you must explicitly select a caching method. + * + * * Factory - creation of new objects without caching. + * * Weak - caching weak reference objects. + * The old object will be provided until the previous object is destroyed. None of the holders will let him go. + * * Soft - caching objects with a soft link. + * The old object will be provided until the previous object is destroyed. None of the holders will let him go. + * * Strong - caching objects with a strong link. + * + * + * + * Dependencies for an object can be listed using function arguments. + *
`ㅤ@Module
+ * interface CarModule {
+ *
+ * ㅤ@Provide(cache = Provide.CacheType.Weak)
+ * Car car(Bumper bumper, Wheel wheel, Window window);
+ *
+ * }
+`
* + */ +@Retention(AnnotationRetention.BINARY) +@Target(AnnotationTarget.FUNCTION, AnnotationTarget.PROPERTY_GETTER, AnnotationTarget.PROPERTY_SETTER) +@Inherited +annotation class Provide( + /** + * Object caching type + */ + val cache: CacheType = CacheType.Factory +) { + enum class CacheType { + Factory, + Weak, + Soft, + Strong + } +} diff --git a/stone_multiplatform/src/main/kotlin/com/github/klee0kai/stone/annotations/wrappers/WrappersCreator.kt b/stone_multiplatform/src/main/kotlin/com/github/klee0kai/stone/annotations/wrappers/WrappersCreator.kt new file mode 100644 index 00000000..b9ae1ebb --- /dev/null +++ b/stone_multiplatform/src/main/kotlin/com/github/klee0kai/stone/annotations/wrappers/WrappersCreator.kt @@ -0,0 +1,22 @@ +package com.github.klee0kai.stone.annotations.wrappers + + +import java.lang.annotation.Inherited +import kotlin.reflect.KClass + +/** + * Provide custom wrappers creator, class + * + * + * Should implement [Wrapper] or [ProviderWrapper] or [CircleWrapper] + * and declare custom wrappers in annotation + */ +@Retention(AnnotationRetention.BINARY) +@Target(AnnotationTarget.CLASS) +@Inherited +annotation class WrappersCreator( + /** + * Custom Wrappers, can be provided + */ + val wrappers: Array> = [] +) diff --git a/stone_multiplatform/src/main/kotlin/com/github/klee0kai/stone/lifecycle/StoneLifeCycleListener.kt b/stone_multiplatform/src/main/kotlin/com/github/klee0kai/stone/lifecycle/StoneLifeCycleListener.kt new file mode 100644 index 00000000..2acd3cf0 --- /dev/null +++ b/stone_multiplatform/src/main/kotlin/com/github/klee0kai/stone/lifecycle/StoneLifeCycleListener.kt @@ -0,0 +1,7 @@ +package com.github.klee0kai.stone.lifecycle + +interface StoneLifeCycleListener { + + fun protectForInjected(timeMillis: Long) + +} diff --git a/stone_multiplatform/src/main/kotlin/com/github/klee0kai/stone/lifecycle/StoneLifeCycleOwner.kt b/stone_multiplatform/src/main/kotlin/com/github/klee0kai/stone/lifecycle/StoneLifeCycleOwner.kt new file mode 100644 index 00000000..dbd443c3 --- /dev/null +++ b/stone_multiplatform/src/main/kotlin/com/github/klee0kai/stone/lifecycle/StoneLifeCycleOwner.kt @@ -0,0 +1,56 @@ +package com.github.klee0kai.stone.lifecycle + +/** + * Objects in an application can have a life cycle. + * Various components of your application can be created, destroyed, and re-created. + * + * + * At the time of re-creation of the object, it may be necessary to save the objects provided to it from DI. + * In a normal case, this can be done by declaring an additional `@ProtectInjected` method in the component. + * For example: + *
`ㅤ@Component
+ * interface AppComponent {
+ *
+ * void inject(Activity activity);
+ *
+ * ㅤ@ProtectInjected
+ * void protectInjected(Activity activity);
+ *
+ * }
+`
* + * + * + * If your class can track life cycle events. + * Then for such classes, you can implement the Stone life cycle, + * which independently calls the deletion protection methods. + * + * + * For example, for Android Activity it will look like this. + *
`public static StoneLifeCycleOwner lifeCycleOwner(Lifecycle lifecycle, long protectTimeMillis) {
+ * return listener -> lifecycle.addObserver(new DefaultLifecycleObserver() {
+ * ㅤ@Override
+ * public void onPause(@NonNull @NotNull LifecycleOwner owner1) {
+ * DefaultLifecycleObserver.super.onPause(owner1);
+ * listener.protectForInjected(protectTimeMillis);
+ * }
+ * });
+ * }
+`
* + * + * + * Further, you simply use your class when injecting itself (if it implements StoneLifeCycleOwner), + * or with an additional StoneLifeCycleOwner argument + * + *
`ㅤ@Component
+ * interface AppComponent {
+ *
+ * void inject(Activity activity, StoneLifeCycleOwner owner);
+ *
+ * }
+`
* + */ +interface StoneLifeCycleOwner { + + fun subscribe(listener: StoneLifeCycleListener?) + +} diff --git a/stone_multiplatform/src/main/kotlin/com/github/klee0kai/stone/wrappers/AsyncCoroutineProvide.kt b/stone_multiplatform/src/main/kotlin/com/github/klee0kai/stone/wrappers/AsyncCoroutineProvide.kt new file mode 100644 index 00000000..2790221f --- /dev/null +++ b/stone_multiplatform/src/main/kotlin/com/github/klee0kai/stone/wrappers/AsyncCoroutineProvide.kt @@ -0,0 +1,22 @@ +package com.github.klee0kai.stone.wrappers + +import kotlinx.coroutines.* + +class AsyncCoroutineProvide( + private val provider: suspend () -> T +) { + + constructor(call: Ref) : this(provider = { call.get() }) + + @OptIn(DelicateCoroutinesApi::class) + private val asyncValue = GlobalScope.async(Dispatchers.Default) { + provider.invoke() + } + + suspend fun get(): T = asyncValue.await() + + suspend operator fun invoke(): T = asyncValue.await() + + fun syncGet() = runBlocking { provider.invoke() } + +} \ No newline at end of file diff --git a/stone_multiplatform/src/main/kotlin/com/github/klee0kai/stone/wrappers/LazyProvide.kt b/stone_multiplatform/src/main/kotlin/com/github/klee0kai/stone/wrappers/LazyProvide.kt new file mode 100644 index 00000000..e2984e75 --- /dev/null +++ b/stone_multiplatform/src/main/kotlin/com/github/klee0kai/stone/wrappers/LazyProvide.kt @@ -0,0 +1,21 @@ +package com.github.klee0kai.stone.wrappers + +/** + * Providing an object with lazy providing. + * The object will be provided the first time it is used. + *
`ㅤ@Component
+ * interface Component {
+ *
+ * LazyProvide presenter();
+ *
+ * }
+`
* + */ +class LazyProvide(private val call: Ref) : Ref { + private var value: T? = null + + override fun get(): T? { + if (value != null) return value + return call.get().also { value = it } + } +} diff --git a/stone_multiplatform/src/main/kotlin/com/github/klee0kai/stone/wrappers/PhantomProvide.kt b/stone_multiplatform/src/main/kotlin/com/github/klee0kai/stone/wrappers/PhantomProvide.kt new file mode 100644 index 00000000..d1e7fbc5 --- /dev/null +++ b/stone_multiplatform/src/main/kotlin/com/github/klee0kai/stone/wrappers/PhantomProvide.kt @@ -0,0 +1,23 @@ +package com.github.klee0kai.stone.wrappers + +/** + * Providing an object without any deduction. + * Each time you use this object through a provider, + * the object is not cached in your class, but is taken from the component each time. + * + * + * Together with the use of Kotlin delegates, you can fully use the objects from the + * DI component directly without keeping them from being deleted in your class. + *
`ㅤ@Component
+ * interface Component {
+ *
+ * PhantomProvide presenter();
+ *
+ * }
+`
* + */ +class PhantomProvide(private val call: Ref) : Ref { + override fun get(): T? { + return call.get() + } +} diff --git a/stone_multiplatform/src/main/kotlin/com/github/klee0kai/stone/wrappers/Ref.kt b/stone_multiplatform/src/main/kotlin/com/github/klee0kai/stone/wrappers/Ref.kt new file mode 100644 index 00000000..fb163a4d --- /dev/null +++ b/stone_multiplatform/src/main/kotlin/com/github/klee0kai/stone/wrappers/Ref.kt @@ -0,0 +1,9 @@ +package com.github.klee0kai.stone.wrappers + +import javax.inject.Provider + +interface Ref : Provider { + + override fun get(): T + +} diff --git a/stone_multiplatform/src/main/kotlin/com/github/klee0kai/stone/wrappers/creators/CircleWrapper.kt b/stone_multiplatform/src/main/kotlin/com/github/klee0kai/stone/wrappers/creators/CircleWrapper.kt new file mode 100644 index 00000000..73f67ac0 --- /dev/null +++ b/stone_multiplatform/src/main/kotlin/com/github/klee0kai/stone/wrappers/creators/CircleWrapper.kt @@ -0,0 +1,15 @@ +package com.github.klee0kai.stone.wrappers.creators + +interface CircleWrapper : ProviderWrapper { + /** + * UnProvide wrapped object. + * + * @param wrapperCl type of wrapper + * @param objectType original provide object type + * @param wrapper wrapper to unwrap + * @param type of wrapper + * @param type of providing original object + * @return wrapped object provider + */ + fun unwrap(wrapperCl: Class?, objectType: Class?, wrapper: Wr?): T? +} diff --git a/stone_multiplatform/src/main/kotlin/com/github/klee0kai/stone/wrappers/creators/ProviderWrapper.kt b/stone_multiplatform/src/main/kotlin/com/github/klee0kai/stone/wrappers/creators/ProviderWrapper.kt new file mode 100644 index 00000000..b86d68c3 --- /dev/null +++ b/stone_multiplatform/src/main/kotlin/com/github/klee0kai/stone/wrappers/creators/ProviderWrapper.kt @@ -0,0 +1,16 @@ +package com.github.klee0kai.stone.wrappers.creators + +import javax.inject.Provider + +interface ProviderWrapper { + /** + * Provide wrapped object. + * + * @param wrapperCl type of wrapper + * @param originalProvider original object provider + * @param type of wrapper + * @param type of providing original object + * @return wrapped object provider + */ + fun wrap(wrapperCl: Class?, originalProvider: Provider?): Wr? +} diff --git a/stone_multiplatform/src/main/kotlin/com/github/klee0kai/stone/wrappers/creators/Wrapper.kt b/stone_multiplatform/src/main/kotlin/com/github/klee0kai/stone/wrappers/creators/Wrapper.kt new file mode 100644 index 00000000..5437d5da --- /dev/null +++ b/stone_multiplatform/src/main/kotlin/com/github/klee0kai/stone/wrappers/creators/Wrapper.kt @@ -0,0 +1,14 @@ +package com.github.klee0kai.stone.wrappers.creators + +interface Wrapper { + /** + * Provide wrapped object. + * + * @param wrapperCl type of wrapper + * @param original original object + * @param type of wrapper + * @param type of providing original object + * @return wrapped object provider + */ + fun wrap(wrapperCl: Class?, original: T?): Wr? +} From a0878f3ef8b45c2c879f8c9bb1fcb414c098b717 Mon Sep 17 00:00:00 2001 From: klee0kai Date: Sun, 12 Oct 2025 20:03:19 +0200 Subject: [PATCH 009/122] kmp common components interfaces --- .../klee0kai/stone/__hidden__/IModule.kt | 53 +++++++++++++++++++ .../stone/__hidden__/IModuleFactory.kt | 6 +++ .../stone/__hidden__/IPrivateComponent.kt | 49 +++++++++++++++++ 3 files changed, 108 insertions(+) create mode 100644 stone_multiplatform/src/main/kotlin/com/github/klee0kai/stone/__hidden__/IModule.kt create mode 100644 stone_multiplatform/src/main/kotlin/com/github/klee0kai/stone/__hidden__/IModuleFactory.kt create mode 100644 stone_multiplatform/src/main/kotlin/com/github/klee0kai/stone/__hidden__/IPrivateComponent.kt diff --git a/stone_multiplatform/src/main/kotlin/com/github/klee0kai/stone/__hidden__/IModule.kt b/stone_multiplatform/src/main/kotlin/com/github/klee0kai/stone/__hidden__/IModule.kt new file mode 100644 index 00000000..ea741c72 --- /dev/null +++ b/stone_multiplatform/src/main/kotlin/com/github/klee0kai/stone/__hidden__/IModule.kt @@ -0,0 +1,53 @@ +package com.github.klee0kai.stone.__hidden__ + +/** + * Stone Private class + */ +interface IModule { + /** + * Init module + * + * @param ob can be: + * - a factory instance + * - a factory class + */ + fun __init(ob: Any?): Boolean + + /** + * Init caches from module prototype. + * using in extOf method + */ + fun __initCachesFrom(module: IModule?) + + /** + * Update values of bindInstance variables + * + * @param module related module, source to update + */ + fun __updateBindInstancesFrom(module: IModule?) + + /** + * bind instance objects + * + * @param object - An instance of bindable objects + */ + fun __bind(`object`: Any?): Boolean + + /** + * get component's factory + * + * @return + */ + fun __getFactory(): Any? + + /** + * TODO Switch cache type for scope + */ +// fun __switchRef(scopes: MutableSet?>?, param: SwitchCacheParam?) + + /** + * Clear null refs. + * Useful after gc + */ + fun __clearNulls() +} diff --git a/stone_multiplatform/src/main/kotlin/com/github/klee0kai/stone/__hidden__/IModuleFactory.kt b/stone_multiplatform/src/main/kotlin/com/github/klee0kai/stone/__hidden__/IModuleFactory.kt new file mode 100644 index 00000000..00a61bd2 --- /dev/null +++ b/stone_multiplatform/src/main/kotlin/com/github/klee0kai/stone/__hidden__/IModuleFactory.kt @@ -0,0 +1,6 @@ +package com.github.klee0kai.stone.__hidden__ + +/** + * Stone Private class + */ +interface IModuleFactory diff --git a/stone_multiplatform/src/main/kotlin/com/github/klee0kai/stone/__hidden__/IPrivateComponent.kt b/stone_multiplatform/src/main/kotlin/com/github/klee0kai/stone/__hidden__/IPrivateComponent.kt new file mode 100644 index 00000000..e0d8b909 --- /dev/null +++ b/stone_multiplatform/src/main/kotlin/com/github/klee0kai/stone/__hidden__/IPrivateComponent.kt @@ -0,0 +1,49 @@ +package com.github.klee0kai.stone.__hidden__ + + +/** + * Private Stone class + * Each Stone component implement this interface. + */ +interface IPrivateComponent { + /** + * init modules. + * + * @param modules can be: + * - a factory instance + * - a factory class + */ + @Deprecated("Create init method with module type as argument") + fun __init(vararg modules: Any?) + + /** + * init dependencies + * + * @param dependencies - An instance of dependencies + */ + @Deprecated("Create init method with dependency type as argument") + fun __initDependencies(vararg dependencies: Any?) + + /** + * bind instance objects + * + * @param objects - An instance of bindable objects + */ + fun __bind(vararg objects: Any?) + + /** + * this component extends of other + */ + fun __extOf(components: IPrivateComponent?) + + /** + * hidden module + */ + fun __hidden(): IModule? + + /** + * + * @param callback + */ + fun __eachModule(callback: (IModule) -> Unit) +} From 88c3a52bd0101dc453f2cedccfc2f337cb9893a3 Mon Sep 17 00:00:00 2001 From: klee0kai Date: Sun, 9 Nov 2025 17:34:30 +0100 Subject: [PATCH 010/122] weak ref design --- libs.versions.toml | 3 +- plugin_publish/build.gradle.kts | 1 + settings.gradle.kts | 4 +- stone_multiplatform/build.gradle.kts | 11 +-- .../src/commonTest/kotlin/stone/RefJvmTest.kt | 12 +++ .../com/github/klee0kai/stone/wrappers/Ref.kt | 3 +- .../com/github/klee0kai/stone/RefJvmTest.kt | 12 +++ weakref_multiplatform/build.gradle.kts | 83 +++++++++++++++++++ .../github/klee0kai/stone/weakref/WeakRef.kt | 9 ++ .../klee0kai/stone/weakref/WeakRef.js.kt | 33 ++++++++ .../github/klee0kai/stone/weakref/WeakRef.kt | 15 ++++ 11 files changed, 178 insertions(+), 8 deletions(-) create mode 100644 stone_multiplatform/src/commonTest/kotlin/stone/RefJvmTest.kt create mode 100644 stone_multiplatform/src/test/kotlin/com/github/klee0kai/stone/RefJvmTest.kt create mode 100644 weakref_multiplatform/build.gradle.kts create mode 100644 weakref_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/weakref/WeakRef.kt create mode 100644 weakref_multiplatform/src/jsMain/kotlin/com/github/klee0kai/stone/weakref/WeakRef.js.kt create mode 100644 weakref_multiplatform/src/jvmMain/kotlin/com/github/klee0kai/stone/weakref/WeakRef.kt diff --git a/libs.versions.toml b/libs.versions.toml index 3c216b75..d0d93077 100644 --- a/libs.versions.toml +++ b/libs.versions.toml @@ -2,7 +2,7 @@ stone = "1.0.7" -kotlin = "2.2.20" +kotlin = "2.2.21" ksp = "2.1.10-1.0.30" agp = "8.12.3" @@ -52,6 +52,7 @@ junit = ["jupiter-api", "jupiter-engine", "jupiter-launcher"] kotlin-ksp = { id = "com.google.devtools.ksp", version.ref = "ksp" } kotlin-jvm = { id = "org.jetbrains.kotlin.jvm", version.ref = "kotlin" } kotlin-kapt = { id = "org.jetbrains.kotlin.kapt", version.ref = "kotlin" } +kotlin-dsl = { id = "org.gradle.kotlin.kotlin-dsl", version.ref = "kotlin" } kotlin-multiplatform = { id = "org.jetbrains.kotlin.multiplatform", version.ref = "kotlin" } android-library = { id = "com.android.library", version.ref = "agp" } diff --git a/plugin_publish/build.gradle.kts b/plugin_publish/build.gradle.kts index db3880da..a884f458 100644 --- a/plugin_publish/build.gradle.kts +++ b/plugin_publish/build.gradle.kts @@ -1,5 +1,6 @@ plugins { `kotlin-dsl` +// alias(libs.plugins.kotlin.dsl) `java-gradle-plugin` } diff --git a/settings.gradle.kts b/settings.gradle.kts index 696b0223..3d92622f 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -22,7 +22,7 @@ dependencyResolutionManagement { rootProject.name = "Stone" includeBuild("plugin_publish") include(":stone_lib") -include(":stone_multiplatform") +//include(":stone_multiplatform") include(":stone_processor") include(":android_lib") include(":kotlin_lib") @@ -44,3 +44,5 @@ include(":test_feature:finance:api") include(":test_feature:finance:impl") include(":test_feature_core_deps") + +include("weakref_multiplatform") \ No newline at end of file diff --git a/stone_multiplatform/build.gradle.kts b/stone_multiplatform/build.gradle.kts index d5804fcf..bb47342b 100644 --- a/stone_multiplatform/build.gradle.kts +++ b/stone_multiplatform/build.gradle.kts @@ -32,11 +32,12 @@ kotlin { } sourceSets { - val commonMain by getting { - dependencies { - api(libs.java.inject) - api(libs.kotlinx.coroutines) - } + commonMain.dependencies { + api(libs.java.inject) + api(libs.kotlinx.coroutines) + } + commonTest.dependencies { + implementation(kotlin("test")) } } } diff --git a/stone_multiplatform/src/commonTest/kotlin/stone/RefJvmTest.kt b/stone_multiplatform/src/commonTest/kotlin/stone/RefJvmTest.kt new file mode 100644 index 00000000..0636ed50 --- /dev/null +++ b/stone_multiplatform/src/commonTest/kotlin/stone/RefJvmTest.kt @@ -0,0 +1,12 @@ +package com.github.klee0kai.stone + +import kotlin.test.Test + +class RefJvmTest { + + @Test + fun simpleTest() { + println("hello") + } + +} \ No newline at end of file diff --git a/stone_multiplatform/src/main/kotlin/com/github/klee0kai/stone/wrappers/Ref.kt b/stone_multiplatform/src/main/kotlin/com/github/klee0kai/stone/wrappers/Ref.kt index fb163a4d..37516848 100644 --- a/stone_multiplatform/src/main/kotlin/com/github/klee0kai/stone/wrappers/Ref.kt +++ b/stone_multiplatform/src/main/kotlin/com/github/klee0kai/stone/wrappers/Ref.kt @@ -2,8 +2,9 @@ package com.github.klee0kai.stone.wrappers import javax.inject.Provider -interface Ref : Provider { +fun interface Ref : Provider { override fun get(): T } + diff --git a/stone_multiplatform/src/test/kotlin/com/github/klee0kai/stone/RefJvmTest.kt b/stone_multiplatform/src/test/kotlin/com/github/klee0kai/stone/RefJvmTest.kt new file mode 100644 index 00000000..0636ed50 --- /dev/null +++ b/stone_multiplatform/src/test/kotlin/com/github/klee0kai/stone/RefJvmTest.kt @@ -0,0 +1,12 @@ +package com.github.klee0kai.stone + +import kotlin.test.Test + +class RefJvmTest { + + @Test + fun simpleTest() { + println("hello") + } + +} \ No newline at end of file diff --git a/weakref_multiplatform/build.gradle.kts b/weakref_multiplatform/build.gradle.kts new file mode 100644 index 00000000..ccf1593a --- /dev/null +++ b/weakref_multiplatform/build.gradle.kts @@ -0,0 +1,83 @@ +plugins { + alias(libs.plugins.kotlin.multiplatform) +// alias(libs.plugins.android.library) +} + +group = "com.github.klee0kai.stone.weakref" +version = libs.versions.stone.get() + +//android { +// namespace = project.group.toString() +// compileSdk = 36 +// defaultConfig { +// minSdk = 21 +// } +//} + +kotlin { +// androidTarget() + jvm() + js(IR) { + browser() + nodejs() + } + +// linuxX64("linux") +// mingwX64() + +// targets.all { +// compilations.all { +// compilerOptions.configure { +// freeCompilerArgs.add("-Xskip-prerelease-check") +// } +// } +// } + + sourceSets { + + commonMain.dependencies { + api(libs.java.inject) + api(libs.kotlinx.coroutines) + } + commonTest.dependencies { + implementation(kotlin("test")) + } + } +} + +val isMac = System.getProperty("os.name").contains("Mac") +if (isMac) kotlin { + macosX64() + macosArm64() + iosX64() + iosArm64() + iosSimulatorArm64() + + sourceSets { + val commonMain by getting + val commonTest by getting + val iosX64Main by getting + val iosArm64Main by getting + val iosSimulatorArm64Main by getting + + val iosMain by creating { + dependsOn(commonMain) + iosX64Main.dependsOn(this) + iosArm64Main.dependsOn(this) + iosSimulatorArm64Main.dependsOn(this) + } + + + val iosX64Test by getting + val iosArm64Test by getting + val iosSimulatorArm64Test by getting + val iosTest by creating { + dependsOn(commonTest) + iosX64Test.dependsOn(this) + iosArm64Test.dependsOn(this) + iosSimulatorArm64Test.dependsOn(this) + } + } +} + + diff --git a/weakref_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/weakref/WeakRef.kt b/weakref_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/weakref/WeakRef.kt new file mode 100644 index 00000000..f2f69c03 --- /dev/null +++ b/weakref_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/weakref/WeakRef.kt @@ -0,0 +1,9 @@ +package com.github.klee0kai.stone.weakref + +expect class WeakRef constructor(value: T) { + + fun get(): T? + + fun clear() + +} \ No newline at end of file diff --git a/weakref_multiplatform/src/jsMain/kotlin/com/github/klee0kai/stone/weakref/WeakRef.js.kt b/weakref_multiplatform/src/jsMain/kotlin/com/github/klee0kai/stone/weakref/WeakRef.js.kt new file mode 100644 index 00000000..3d1eb4d5 --- /dev/null +++ b/weakref_multiplatform/src/jsMain/kotlin/com/github/klee0kai/stone/weakref/WeakRef.js.kt @@ -0,0 +1,33 @@ +package com.github.klee0kai.stone.weakref + +actual class WeakRef actual constructor(value: T) { + + private var weakRefDynamic: dynamic = null + private var strongFallback: T? = null + + init { + val hasWeakRef = js("typeof WeakRef !== 'undefined'") as Boolean + if (hasWeakRef) { + weakRefDynamic = js("new WeakRef")(value) + strongFallback = null + } else { + weakRefDynamic = null + strongFallback = value + } + } + + actual fun get(): T? { + return if (weakRefDynamic != null) { + val derefResult = weakRefDynamic.deref?.invoke() + derefResult as T? + } else { + strongFallback + } + } + + actual fun clear() { + weakRefDynamic = null + strongFallback = null + } + +} \ No newline at end of file diff --git a/weakref_multiplatform/src/jvmMain/kotlin/com/github/klee0kai/stone/weakref/WeakRef.kt b/weakref_multiplatform/src/jvmMain/kotlin/com/github/klee0kai/stone/weakref/WeakRef.kt new file mode 100644 index 00000000..d8094fac --- /dev/null +++ b/weakref_multiplatform/src/jvmMain/kotlin/com/github/klee0kai/stone/weakref/WeakRef.kt @@ -0,0 +1,15 @@ +package com.github.klee0kai.stone.weakref + +import java.lang.ref.WeakReference + +actual class WeakRef actual constructor(value: T) { + + val weakRef: WeakReference = WeakReference(value) + + actual fun get(): T? = weakRef.get() + + actual fun clear() { + weakRef.clear() + } + +} \ No newline at end of file From 998cecae9b67e9f163eb010ba63a0f646fda3966 Mon Sep 17 00:00:00 2001 From: klee0kai Date: Sun, 9 Nov 2025 18:59:30 +0100 Subject: [PATCH 011/122] weak ref few targets --- settings.gradle.kts | 43 ++++--- weakref_multiplatform/build.gradle.kts | 105 +++++++++--------- .../github/klee0kai/stone/weakref/WeakRef.kt | 15 +++ .../github/klee0kai/stone/weakref/WeakRef.kt | 2 +- .../klee0kai/stone/weakref/WeakRefTests.kt | 20 ++++ .../weakref/{WeakRef.js.kt => WeakRef.kt} | 2 +- .../github/klee0kai/stone/weakref/WeakRef.kt | 2 +- .../github/klee0kai/stone/weakref/WeakRef.kt | 18 +++ .../github/klee0kai/stone/weakref/WeakRef.kt | 18 +++ 9 files changed, 146 insertions(+), 79 deletions(-) create mode 100644 weakref_multiplatform/src/androidMain/kotlin/com/github/klee0kai/stone/weakref/WeakRef.kt create mode 100644 weakref_multiplatform/src/commonTest/kotlin/com/github/klee0kai/stone/weakref/WeakRefTests.kt rename weakref_multiplatform/src/jsMain/kotlin/com/github/klee0kai/stone/weakref/{WeakRef.js.kt => WeakRef.kt} (92%) create mode 100644 weakref_multiplatform/src/linuxMain/kotlin/com/github/klee0kai/stone/weakref/WeakRef.kt create mode 100644 weakref_multiplatform/src/mingwX64Main/kotlin/com/github/klee0kai/stone/weakref/WeakRef.kt diff --git a/settings.gradle.kts b/settings.gradle.kts index 3d92622f..d131d309 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -7,7 +7,6 @@ pluginManagement { } dependencyResolutionManagement { - repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS) repositories { google() mavenCentral() @@ -21,28 +20,28 @@ dependencyResolutionManagement { rootProject.name = "Stone" includeBuild("plugin_publish") +include("weakref_multiplatform") include(":stone_lib") -//include(":stone_multiplatform") -include(":stone_processor") +////include(":stone_multiplatform") +//include(":stone_processor") include(":android_lib") -include(":kotlin_lib") +//include(":kotlin_lib") +// +//include(":wiki_java") +//include(":wiki_kotlin") +//include(":tests") +//include(":tests_ext") +//include(":tests_kotlin") +//include(":tests_wraps") +//include(":tests_wraps_kotlin") +//include(":tests_compile") +//include(":test_feature:companies:consulting") +//include(":test_feature:hr:api") +//include(":test_feature:hr:impl") +//include(":test_feature:planning:api") +//include(":test_feature:planning:impl") +//include(":test_feature:finance:api") +//include(":test_feature:finance:impl") +//include(":test_feature_core_deps") -include(":wiki_java") -include(":wiki_kotlin") -include(":tests") -include(":tests_ext") -include(":tests_kotlin") -include(":tests_wraps") -include(":tests_wraps_kotlin") -include(":tests_compile") -include(":test_feature:companies:consulting") -include(":test_feature:hr:api") -include(":test_feature:hr:impl") -include(":test_feature:planning:api") -include(":test_feature:planning:impl") -include(":test_feature:finance:api") -include(":test_feature:finance:impl") -include(":test_feature_core_deps") - -include("weakref_multiplatform") \ No newline at end of file diff --git a/weakref_multiplatform/build.gradle.kts b/weakref_multiplatform/build.gradle.kts index ccf1593a..2b358c35 100644 --- a/weakref_multiplatform/build.gradle.kts +++ b/weakref_multiplatform/build.gradle.kts @@ -1,40 +1,37 @@ plugins { alias(libs.plugins.kotlin.multiplatform) -// alias(libs.plugins.android.library) + alias(libs.plugins.android.library) } group = "com.github.klee0kai.stone.weakref" version = libs.versions.stone.get() -//android { -// namespace = project.group.toString() -// compileSdk = 36 -// defaultConfig { -// minSdk = 21 -// } -//} +android { + namespace = project.group.toString() + compileSdk = 36 + defaultConfig { + minSdk = 21 + } +} kotlin { -// androidTarget() + androidTarget() jvm() js(IR) { browser() nodejs() } -// linuxX64("linux") -// mingwX64() - -// targets.all { -// compilations.all { -// compilerOptions.configure { -// freeCompilerArgs.add("-Xskip-prerelease-check") -// } -// } -// } + linuxX64("linux"){ + binaries { + executable { + entryPoint = "main" + } + } + } + mingwX64() sourceSets { - commonMain.dependencies { api(libs.java.inject) api(libs.kotlinx.coroutines) @@ -45,39 +42,39 @@ kotlin { } } -val isMac = System.getProperty("os.name").contains("Mac") -if (isMac) kotlin { - macosX64() - macosArm64() - iosX64() - iosArm64() - iosSimulatorArm64() - - sourceSets { - val commonMain by getting - val commonTest by getting - val iosX64Main by getting - val iosArm64Main by getting - val iosSimulatorArm64Main by getting - - val iosMain by creating { - dependsOn(commonMain) - iosX64Main.dependsOn(this) - iosArm64Main.dependsOn(this) - iosSimulatorArm64Main.dependsOn(this) - } - - - val iosX64Test by getting - val iosArm64Test by getting - val iosSimulatorArm64Test by getting - val iosTest by creating { - dependsOn(commonTest) - iosX64Test.dependsOn(this) - iosArm64Test.dependsOn(this) - iosSimulatorArm64Test.dependsOn(this) - } - } -} +//val isMac = System.getProperty("os.name").contains("Mac") +//if (isMac) kotlin { +// macosX64() +// macosArm64() +// iosX64() +// iosArm64() +// iosSimulatorArm64() +// +// sourceSets { +// val commonMain by getting +// val commonTest by getting +// val iosX64Main by getting +// val iosArm64Main by getting +// val iosSimulatorArm64Main by getting +// +// val iosMain by creating { +// dependsOn(commonMain) +// iosX64Main.dependsOn(this) +// iosArm64Main.dependsOn(this) +// iosSimulatorArm64Main.dependsOn(this) +// } +// +// +// val iosX64Test by getting +// val iosArm64Test by getting +// val iosSimulatorArm64Test by getting +// val iosTest by creating { +// dependsOn(commonTest) +// iosX64Test.dependsOn(this) +// iosArm64Test.dependsOn(this) +// iosSimulatorArm64Test.dependsOn(this) +// } +// } +//} diff --git a/weakref_multiplatform/src/androidMain/kotlin/com/github/klee0kai/stone/weakref/WeakRef.kt b/weakref_multiplatform/src/androidMain/kotlin/com/github/klee0kai/stone/weakref/WeakRef.kt new file mode 100644 index 00000000..d8094fac --- /dev/null +++ b/weakref_multiplatform/src/androidMain/kotlin/com/github/klee0kai/stone/weakref/WeakRef.kt @@ -0,0 +1,15 @@ +package com.github.klee0kai.stone.weakref + +import java.lang.ref.WeakReference + +actual class WeakRef actual constructor(value: T) { + + val weakRef: WeakReference = WeakReference(value) + + actual fun get(): T? = weakRef.get() + + actual fun clear() { + weakRef.clear() + } + +} \ No newline at end of file diff --git a/weakref_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/weakref/WeakRef.kt b/weakref_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/weakref/WeakRef.kt index f2f69c03..0893f2ca 100644 --- a/weakref_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/weakref/WeakRef.kt +++ b/weakref_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/weakref/WeakRef.kt @@ -1,6 +1,6 @@ package com.github.klee0kai.stone.weakref -expect class WeakRef constructor(value: T) { +expect class WeakRef constructor(value: T) { fun get(): T? diff --git a/weakref_multiplatform/src/commonTest/kotlin/com/github/klee0kai/stone/weakref/WeakRefTests.kt b/weakref_multiplatform/src/commonTest/kotlin/com/github/klee0kai/stone/weakref/WeakRefTests.kt new file mode 100644 index 00000000..77cab36e --- /dev/null +++ b/weakref_multiplatform/src/commonTest/kotlin/com/github/klee0kai/stone/weakref/WeakRefTests.kt @@ -0,0 +1,20 @@ +package com.github.klee0kai.stone.weakref + +import kotlin.test.Test +import kotlin.test.assertEquals +import kotlin.test.assertNull + +class WeakRefTests { + + @Test + fun clearRefTest() { + val ref = WeakRef("some text") + + assertEquals("some text", ref.get()) + + ref.clear() + + assertNull(ref.get()) + } + +} \ No newline at end of file diff --git a/weakref_multiplatform/src/jsMain/kotlin/com/github/klee0kai/stone/weakref/WeakRef.js.kt b/weakref_multiplatform/src/jsMain/kotlin/com/github/klee0kai/stone/weakref/WeakRef.kt similarity index 92% rename from weakref_multiplatform/src/jsMain/kotlin/com/github/klee0kai/stone/weakref/WeakRef.js.kt rename to weakref_multiplatform/src/jsMain/kotlin/com/github/klee0kai/stone/weakref/WeakRef.kt index 3d1eb4d5..7ce13a42 100644 --- a/weakref_multiplatform/src/jsMain/kotlin/com/github/klee0kai/stone/weakref/WeakRef.js.kt +++ b/weakref_multiplatform/src/jsMain/kotlin/com/github/klee0kai/stone/weakref/WeakRef.kt @@ -1,6 +1,6 @@ package com.github.klee0kai.stone.weakref -actual class WeakRef actual constructor(value: T) { +actual class WeakRef actual constructor(value: T) { private var weakRefDynamic: dynamic = null private var strongFallback: T? = null diff --git a/weakref_multiplatform/src/jvmMain/kotlin/com/github/klee0kai/stone/weakref/WeakRef.kt b/weakref_multiplatform/src/jvmMain/kotlin/com/github/klee0kai/stone/weakref/WeakRef.kt index d8094fac..a2e3e801 100644 --- a/weakref_multiplatform/src/jvmMain/kotlin/com/github/klee0kai/stone/weakref/WeakRef.kt +++ b/weakref_multiplatform/src/jvmMain/kotlin/com/github/klee0kai/stone/weakref/WeakRef.kt @@ -2,7 +2,7 @@ package com.github.klee0kai.stone.weakref import java.lang.ref.WeakReference -actual class WeakRef actual constructor(value: T) { +actual class WeakRef actual constructor(value: T) { val weakRef: WeakReference = WeakReference(value) diff --git a/weakref_multiplatform/src/linuxMain/kotlin/com/github/klee0kai/stone/weakref/WeakRef.kt b/weakref_multiplatform/src/linuxMain/kotlin/com/github/klee0kai/stone/weakref/WeakRef.kt new file mode 100644 index 00000000..ee0057b9 --- /dev/null +++ b/weakref_multiplatform/src/linuxMain/kotlin/com/github/klee0kai/stone/weakref/WeakRef.kt @@ -0,0 +1,18 @@ +@file:OptIn(ExperimentalNativeApi::class) + +package com.github.klee0kai.stone.weakref + +import kotlin.experimental.ExperimentalNativeApi +import kotlin.native.ref.WeakReference + +actual class WeakRef actual constructor(value: T) { + + val weakRef: WeakReference? = value?.let { WeakReference(value) } + + actual fun get(): T? = weakRef?.get() + + actual fun clear() { + weakRef?.clear() + } + +} \ No newline at end of file diff --git a/weakref_multiplatform/src/mingwX64Main/kotlin/com/github/klee0kai/stone/weakref/WeakRef.kt b/weakref_multiplatform/src/mingwX64Main/kotlin/com/github/klee0kai/stone/weakref/WeakRef.kt new file mode 100644 index 00000000..ee0057b9 --- /dev/null +++ b/weakref_multiplatform/src/mingwX64Main/kotlin/com/github/klee0kai/stone/weakref/WeakRef.kt @@ -0,0 +1,18 @@ +@file:OptIn(ExperimentalNativeApi::class) + +package com.github.klee0kai.stone.weakref + +import kotlin.experimental.ExperimentalNativeApi +import kotlin.native.ref.WeakReference + +actual class WeakRef actual constructor(value: T) { + + val weakRef: WeakReference? = value?.let { WeakReference(value) } + + actual fun get(): T? = weakRef?.get() + + actual fun clear() { + weakRef?.clear() + } + +} \ No newline at end of file From efab24acf17cacdd028d3106bd60de8812cefdaa Mon Sep 17 00:00:00 2001 From: klee0kai Date: Sun, 9 Nov 2025 19:05:29 +0100 Subject: [PATCH 012/122] stone multiplatform move to common main src --- settings.gradle.kts | 6 +- stone_multiplatform/build.gradle.kts | 13 +--- .../kotlin}/stone/__hidden__/IModule.kt | 2 +- .../stone/__hidden__/IModuleFactory.kt | 2 +- .../stone/__hidden__/IPrivateComponent.kt | 8 +- .../stone/annotations/component/Component.kt | 2 +- .../stone/annotations/component/ExtendOf.kt | 2 +- .../stone/annotations/component/GcAllScope.kt | 4 +- .../component/GcScopeAnnotation.kt | 2 +- .../annotations/component/GcSoftScope.kt | 6 +- .../annotations/component/GcStrongScope.kt | 4 +- .../annotations/component/GcWeakScope.kt | 4 +- .../stone/annotations/component/Init.kt | 2 +- .../component/ModuleOriginFactory.kt | 2 +- .../annotations/component/ProtectInjected.kt | 2 +- .../stone/annotations/component/RunGc.kt | 2 +- .../annotations/component/SwitchCache.kt | 2 +- .../annotations/dependencies/Dependencies.kt | 2 +- .../stone/annotations/module/BindInstance.kt | 2 +- .../stone/annotations/module/Module.kt | 2 +- .../stone/annotations/module/Provide.kt | 2 +- .../annotations/wrappers/WrappersCreator.kt | 2 +- .../stone/lifecycle/StoneLifeCycleListener.kt | 2 +- .../stone/lifecycle/StoneLifeCycleOwner.kt | 4 +- .../stone/wrappers/AsyncCoroutineProvide.kt | 4 +- .../kotlin}/stone/wrappers/LazyProvide.kt | 4 +- .../kotlin}/stone/wrappers/PhantomProvide.kt | 4 +- .../commonMain/kotlin/stone/wrappers/Ref.kt | 10 +++ .../stone/wrappers/creators/CircleWrapper.kt | 4 +- .../wrappers/creators/ProviderWrapper.kt | 2 +- .../stone/wrappers/creators/Wrapper.kt | 2 +- .../com/github/klee0kai/stone/wrappers/Ref.kt | 10 --- .../com/github/klee0kai/stone/RefJvmTest.kt | 12 --- weakref_multiplatform/build.gradle.kts | 76 +++++++++---------- 34 files changed, 93 insertions(+), 116 deletions(-) rename stone_multiplatform/src/{main/kotlin/com/github/klee0kai => commonMain/kotlin}/stone/__hidden__/IModule.kt (95%) rename stone_multiplatform/src/{main/kotlin/com/github/klee0kai => commonMain/kotlin}/stone/__hidden__/IModuleFactory.kt (56%) rename stone_multiplatform/src/{main/kotlin/com/github/klee0kai => commonMain/kotlin}/stone/__hidden__/IPrivateComponent.kt (80%) rename stone_multiplatform/src/{main/kotlin/com/github/klee0kai => commonMain/kotlin}/stone/annotations/component/Component.kt (99%) rename stone_multiplatform/src/{main/kotlin/com/github/klee0kai => commonMain/kotlin}/stone/annotations/component/ExtendOf.kt (95%) rename stone_multiplatform/src/{main/kotlin/com/github/klee0kai => commonMain/kotlin}/stone/annotations/component/GcAllScope.kt (77%) rename stone_multiplatform/src/{main/kotlin/com/github/klee0kai => commonMain/kotlin}/stone/annotations/component/GcScopeAnnotation.kt (92%) rename stone_multiplatform/src/{main/kotlin/com/github/klee0kai => commonMain/kotlin}/stone/annotations/component/GcSoftScope.kt (77%) rename stone_multiplatform/src/{main/kotlin/com/github/klee0kai => commonMain/kotlin}/stone/annotations/component/GcStrongScope.kt (81%) rename stone_multiplatform/src/{main/kotlin/com/github/klee0kai => commonMain/kotlin}/stone/annotations/component/GcWeakScope.kt (81%) rename stone_multiplatform/src/{main/kotlin/com/github/klee0kai => commonMain/kotlin}/stone/annotations/component/Init.kt (92%) rename stone_multiplatform/src/{main/kotlin/com/github/klee0kai => commonMain/kotlin}/stone/annotations/component/ModuleOriginFactory.kt (90%) rename stone_multiplatform/src/{main/kotlin/com/github/klee0kai => commonMain/kotlin}/stone/annotations/component/ProtectInjected.kt (93%) rename stone_multiplatform/src/{main/kotlin/com/github/klee0kai => commonMain/kotlin}/stone/annotations/component/RunGc.kt (95%) rename stone_multiplatform/src/{main/kotlin/com/github/klee0kai => commonMain/kotlin}/stone/annotations/component/SwitchCache.kt (96%) rename stone_multiplatform/src/{main/kotlin/com/github/klee0kai => commonMain/kotlin}/stone/annotations/dependencies/Dependencies.kt (95%) rename stone_multiplatform/src/{main/kotlin/com/github/klee0kai => commonMain/kotlin}/stone/annotations/module/BindInstance.kt (97%) rename stone_multiplatform/src/{main/kotlin/com/github/klee0kai => commonMain/kotlin}/stone/annotations/module/Module.kt (97%) rename stone_multiplatform/src/{main/kotlin/com/github/klee0kai => commonMain/kotlin}/stone/annotations/module/Provide.kt (96%) rename stone_multiplatform/src/{main/kotlin/com/github/klee0kai => commonMain/kotlin}/stone/annotations/wrappers/WrappersCreator.kt (89%) rename stone_multiplatform/src/{main/kotlin/com/github/klee0kai => commonMain/kotlin}/stone/lifecycle/StoneLifeCycleListener.kt (65%) rename stone_multiplatform/src/{main/kotlin/com/github/klee0kai => commonMain/kotlin}/stone/lifecycle/StoneLifeCycleOwner.kt (94%) rename stone_multiplatform/src/{main/kotlin/com/github/klee0kai => commonMain/kotlin}/stone/wrappers/AsyncCoroutineProvide.kt (79%) rename stone_multiplatform/src/{main/kotlin/com/github/klee0kai => commonMain/kotlin}/stone/wrappers/LazyProvide.kt (77%) rename stone_multiplatform/src/{main/kotlin/com/github/klee0kai => commonMain/kotlin}/stone/wrappers/PhantomProvide.kt (82%) create mode 100644 stone_multiplatform/src/commonMain/kotlin/stone/wrappers/Ref.kt rename stone_multiplatform/src/{main/kotlin/com/github/klee0kai => commonMain/kotlin}/stone/wrappers/creators/CircleWrapper.kt (81%) rename stone_multiplatform/src/{main/kotlin/com/github/klee0kai => commonMain/kotlin}/stone/wrappers/creators/ProviderWrapper.kt (89%) rename stone_multiplatform/src/{main/kotlin/com/github/klee0kai => commonMain/kotlin}/stone/wrappers/creators/Wrapper.kt (87%) delete mode 100644 stone_multiplatform/src/main/kotlin/com/github/klee0kai/stone/wrappers/Ref.kt delete mode 100644 stone_multiplatform/src/test/kotlin/com/github/klee0kai/stone/RefJvmTest.kt diff --git a/settings.gradle.kts b/settings.gradle.kts index d131d309..d28f648b 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -21,10 +21,10 @@ dependencyResolutionManagement { rootProject.name = "Stone" includeBuild("plugin_publish") include("weakref_multiplatform") -include(":stone_lib") -////include(":stone_multiplatform") +//include(":stone_lib") +include(":stone_multiplatform") //include(":stone_processor") -include(":android_lib") +//include(":android_lib") //include(":kotlin_lib") // //include(":wiki_java") diff --git a/stone_multiplatform/build.gradle.kts b/stone_multiplatform/build.gradle.kts index bb47342b..a21038e0 100644 --- a/stone_multiplatform/build.gradle.kts +++ b/stone_multiplatform/build.gradle.kts @@ -16,20 +16,14 @@ android { kotlin { androidTarget() - jvm() js(IR) { browser() nodejs() } - targets.all { - compilations.all { - compilerOptions.configure { - freeCompilerArgs.add("-Xskip-prerelease-check") - } - } - } + linuxX64() + mingwX64() sourceSets { commonMain.dependencies { @@ -44,6 +38,8 @@ kotlin { val isMac = System.getProperty("os.name").contains("Mac") if (isMac) kotlin { + macosX64() + macosArm64() iosX64() iosArm64() iosSimulatorArm64() @@ -75,4 +71,3 @@ if (isMac) kotlin { } } - diff --git a/stone_multiplatform/src/main/kotlin/com/github/klee0kai/stone/__hidden__/IModule.kt b/stone_multiplatform/src/commonMain/kotlin/stone/__hidden__/IModule.kt similarity index 95% rename from stone_multiplatform/src/main/kotlin/com/github/klee0kai/stone/__hidden__/IModule.kt rename to stone_multiplatform/src/commonMain/kotlin/stone/__hidden__/IModule.kt index ea741c72..76aa2eb7 100644 --- a/stone_multiplatform/src/main/kotlin/com/github/klee0kai/stone/__hidden__/IModule.kt +++ b/stone_multiplatform/src/commonMain/kotlin/stone/__hidden__/IModule.kt @@ -1,4 +1,4 @@ -package com.github.klee0kai.stone.__hidden__ +package stone.__hidden__ /** * Stone Private class diff --git a/stone_multiplatform/src/main/kotlin/com/github/klee0kai/stone/__hidden__/IModuleFactory.kt b/stone_multiplatform/src/commonMain/kotlin/stone/__hidden__/IModuleFactory.kt similarity index 56% rename from stone_multiplatform/src/main/kotlin/com/github/klee0kai/stone/__hidden__/IModuleFactory.kt rename to stone_multiplatform/src/commonMain/kotlin/stone/__hidden__/IModuleFactory.kt index 00a61bd2..fdd5b665 100644 --- a/stone_multiplatform/src/main/kotlin/com/github/klee0kai/stone/__hidden__/IModuleFactory.kt +++ b/stone_multiplatform/src/commonMain/kotlin/stone/__hidden__/IModuleFactory.kt @@ -1,4 +1,4 @@ -package com.github.klee0kai.stone.__hidden__ +package stone.__hidden__ /** * Stone Private class diff --git a/stone_multiplatform/src/main/kotlin/com/github/klee0kai/stone/__hidden__/IPrivateComponent.kt b/stone_multiplatform/src/commonMain/kotlin/stone/__hidden__/IPrivateComponent.kt similarity index 80% rename from stone_multiplatform/src/main/kotlin/com/github/klee0kai/stone/__hidden__/IPrivateComponent.kt rename to stone_multiplatform/src/commonMain/kotlin/stone/__hidden__/IPrivateComponent.kt index e0d8b909..cb8d7e84 100644 --- a/stone_multiplatform/src/main/kotlin/com/github/klee0kai/stone/__hidden__/IPrivateComponent.kt +++ b/stone_multiplatform/src/commonMain/kotlin/stone/__hidden__/IPrivateComponent.kt @@ -1,4 +1,4 @@ -package com.github.klee0kai.stone.__hidden__ +package stone.__hidden__ /** @@ -34,16 +34,16 @@ interface IPrivateComponent { /** * this component extends of other */ - fun __extOf(components: IPrivateComponent?) + fun __extOf(components: stone.__hidden__.IPrivateComponent?) /** * hidden module */ - fun __hidden(): IModule? + fun __hidden(): stone.__hidden__.IModule? /** * * @param callback */ - fun __eachModule(callback: (IModule) -> Unit) + fun __eachModule(callback: (stone.__hidden__.IModule) -> Unit) } diff --git a/stone_multiplatform/src/main/kotlin/com/github/klee0kai/stone/annotations/component/Component.kt b/stone_multiplatform/src/commonMain/kotlin/stone/annotations/component/Component.kt similarity index 99% rename from stone_multiplatform/src/main/kotlin/com/github/klee0kai/stone/annotations/component/Component.kt rename to stone_multiplatform/src/commonMain/kotlin/stone/annotations/component/Component.kt index 59e29fe1..599ce8ee 100644 --- a/stone_multiplatform/src/main/kotlin/com/github/klee0kai/stone/annotations/component/Component.kt +++ b/stone_multiplatform/src/commonMain/kotlin/stone/annotations/component/Component.kt @@ -1,4 +1,4 @@ -package com.github.klee0kai.stone.annotations.component +package stone.annotations.component import kotlin.reflect.KClass diff --git a/stone_multiplatform/src/main/kotlin/com/github/klee0kai/stone/annotations/component/ExtendOf.kt b/stone_multiplatform/src/commonMain/kotlin/stone/annotations/component/ExtendOf.kt similarity index 95% rename from stone_multiplatform/src/main/kotlin/com/github/klee0kai/stone/annotations/component/ExtendOf.kt rename to stone_multiplatform/src/commonMain/kotlin/stone/annotations/component/ExtendOf.kt index 366a3693..9b08fe5b 100644 --- a/stone_multiplatform/src/main/kotlin/com/github/klee0kai/stone/annotations/component/ExtendOf.kt +++ b/stone_multiplatform/src/commonMain/kotlin/stone/annotations/component/ExtendOf.kt @@ -1,4 +1,4 @@ -package com.github.klee0kai.stone.annotations.component +package stone.annotations.component /** diff --git a/stone_multiplatform/src/main/kotlin/com/github/klee0kai/stone/annotations/component/GcAllScope.kt b/stone_multiplatform/src/commonMain/kotlin/stone/annotations/component/GcAllScope.kt similarity index 77% rename from stone_multiplatform/src/main/kotlin/com/github/klee0kai/stone/annotations/component/GcAllScope.kt rename to stone_multiplatform/src/commonMain/kotlin/stone/annotations/component/GcAllScope.kt index 28333808..a8338748 100644 --- a/stone_multiplatform/src/main/kotlin/com/github/klee0kai/stone/annotations/component/GcAllScope.kt +++ b/stone_multiplatform/src/commonMain/kotlin/stone/annotations/component/GcAllScope.kt @@ -1,10 +1,10 @@ -package com.github.klee0kai.stone.annotations.component +package stone.annotations.component /** * A scope that defines all exposed objects in DI. * Used for garbage collection and caching change methods. */ -@GcScopeAnnotation +@stone.annotations.component.GcScopeAnnotation @Retention(AnnotationRetention.BINARY) @Target(AnnotationTarget.FUNCTION, AnnotationTarget.PROPERTY_GETTER, AnnotationTarget.PROPERTY_SETTER) annotation class GcAllScope diff --git a/stone_multiplatform/src/main/kotlin/com/github/klee0kai/stone/annotations/component/GcScopeAnnotation.kt b/stone_multiplatform/src/commonMain/kotlin/stone/annotations/component/GcScopeAnnotation.kt similarity index 92% rename from stone_multiplatform/src/main/kotlin/com/github/klee0kai/stone/annotations/component/GcScopeAnnotation.kt rename to stone_multiplatform/src/commonMain/kotlin/stone/annotations/component/GcScopeAnnotation.kt index 30af6d98..ac95c85b 100644 --- a/stone_multiplatform/src/main/kotlin/com/github/klee0kai/stone/annotations/component/GcScopeAnnotation.kt +++ b/stone_multiplatform/src/commonMain/kotlin/stone/annotations/component/GcScopeAnnotation.kt @@ -1,4 +1,4 @@ -package com.github.klee0kai.stone.annotations.component +package stone.annotations.component /** diff --git a/stone_multiplatform/src/main/kotlin/com/github/klee0kai/stone/annotations/component/GcSoftScope.kt b/stone_multiplatform/src/commonMain/kotlin/stone/annotations/component/GcSoftScope.kt similarity index 77% rename from stone_multiplatform/src/main/kotlin/com/github/klee0kai/stone/annotations/component/GcSoftScope.kt rename to stone_multiplatform/src/commonMain/kotlin/stone/annotations/component/GcSoftScope.kt index cb22574c..90efaea8 100644 --- a/stone_multiplatform/src/main/kotlin/com/github/klee0kai/stone/annotations/component/GcSoftScope.kt +++ b/stone_multiplatform/src/commonMain/kotlin/stone/annotations/component/GcSoftScope.kt @@ -1,4 +1,4 @@ -package com.github.klee0kai.stone.annotations.component +package stone.annotations.component import javax.inject.Scope @@ -7,8 +7,8 @@ import javax.inject.Scope * A standard library scope that lists all cached objects using soft references. * Used for garbage collection and caching change methods. */ -@GcScopeAnnotation -@Scope +@stone.annotations.component.GcScopeAnnotation +@javax.inject.Scope @Retention(AnnotationRetention.BINARY) @Target(AnnotationTarget.FUNCTION, AnnotationTarget.PROPERTY_GETTER, AnnotationTarget.PROPERTY_SETTER) annotation class GcSoftScope diff --git a/stone_multiplatform/src/main/kotlin/com/github/klee0kai/stone/annotations/component/GcStrongScope.kt b/stone_multiplatform/src/commonMain/kotlin/stone/annotations/component/GcStrongScope.kt similarity index 81% rename from stone_multiplatform/src/main/kotlin/com/github/klee0kai/stone/annotations/component/GcStrongScope.kt rename to stone_multiplatform/src/commonMain/kotlin/stone/annotations/component/GcStrongScope.kt index a6efcfcb..e3e65197 100644 --- a/stone_multiplatform/src/main/kotlin/com/github/klee0kai/stone/annotations/component/GcStrongScope.kt +++ b/stone_multiplatform/src/commonMain/kotlin/stone/annotations/component/GcStrongScope.kt @@ -1,4 +1,4 @@ -package com.github.klee0kai.stone.annotations.component +package stone.annotations.component import javax.inject.Scope @@ -7,7 +7,7 @@ import javax.inject.Scope * A standard library scope that enumerates all cacheable objects using strong references. * Used for garbage collection and caching change methods. */ -@GcScopeAnnotation +@stone.annotations.component.GcScopeAnnotation @Scope @Retention(AnnotationRetention.BINARY) @Target(AnnotationTarget.FUNCTION, AnnotationTarget.PROPERTY_GETTER, AnnotationTarget.PROPERTY_SETTER) diff --git a/stone_multiplatform/src/main/kotlin/com/github/klee0kai/stone/annotations/component/GcWeakScope.kt b/stone_multiplatform/src/commonMain/kotlin/stone/annotations/component/GcWeakScope.kt similarity index 81% rename from stone_multiplatform/src/main/kotlin/com/github/klee0kai/stone/annotations/component/GcWeakScope.kt rename to stone_multiplatform/src/commonMain/kotlin/stone/annotations/component/GcWeakScope.kt index 32a2d218..03f16b7e 100644 --- a/stone_multiplatform/src/main/kotlin/com/github/klee0kai/stone/annotations/component/GcWeakScope.kt +++ b/stone_multiplatform/src/commonMain/kotlin/stone/annotations/component/GcWeakScope.kt @@ -1,4 +1,4 @@ -package com.github.klee0kai.stone.annotations.component +package stone.annotations.component import javax.inject.Scope @@ -7,7 +7,7 @@ import javax.inject.Scope * A standard library scope that enumerates all cacheable objects using weak references. * Used for garbage collection and caching change methods. */ -@GcScopeAnnotation +@stone.annotations.component.GcScopeAnnotation @Scope @Retention(AnnotationRetention.BINARY) @Target(AnnotationTarget.FUNCTION, AnnotationTarget.PROPERTY_GETTER, AnnotationTarget.PROPERTY_SETTER) diff --git a/stone_multiplatform/src/main/kotlin/com/github/klee0kai/stone/annotations/component/Init.kt b/stone_multiplatform/src/commonMain/kotlin/stone/annotations/component/Init.kt similarity index 92% rename from stone_multiplatform/src/main/kotlin/com/github/klee0kai/stone/annotations/component/Init.kt rename to stone_multiplatform/src/commonMain/kotlin/stone/annotations/component/Init.kt index f3e0d55a..f833430e 100644 --- a/stone_multiplatform/src/main/kotlin/com/github/klee0kai/stone/annotations/component/Init.kt +++ b/stone_multiplatform/src/commonMain/kotlin/stone/annotations/component/Init.kt @@ -1,4 +1,4 @@ -package com.github.klee0kai.stone.annotations.component +package stone.annotations.component /** diff --git a/stone_multiplatform/src/main/kotlin/com/github/klee0kai/stone/annotations/component/ModuleOriginFactory.kt b/stone_multiplatform/src/commonMain/kotlin/stone/annotations/component/ModuleOriginFactory.kt similarity index 90% rename from stone_multiplatform/src/main/kotlin/com/github/klee0kai/stone/annotations/component/ModuleOriginFactory.kt rename to stone_multiplatform/src/commonMain/kotlin/stone/annotations/component/ModuleOriginFactory.kt index ea0a1660..cd02889a 100644 --- a/stone_multiplatform/src/main/kotlin/com/github/klee0kai/stone/annotations/component/ModuleOriginFactory.kt +++ b/stone_multiplatform/src/commonMain/kotlin/stone/annotations/component/ModuleOriginFactory.kt @@ -1,4 +1,4 @@ -package com.github.klee0kai.stone.annotations.component +package stone.annotations.component /** diff --git a/stone_multiplatform/src/main/kotlin/com/github/klee0kai/stone/annotations/component/ProtectInjected.kt b/stone_multiplatform/src/commonMain/kotlin/stone/annotations/component/ProtectInjected.kt similarity index 93% rename from stone_multiplatform/src/main/kotlin/com/github/klee0kai/stone/annotations/component/ProtectInjected.kt rename to stone_multiplatform/src/commonMain/kotlin/stone/annotations/component/ProtectInjected.kt index 6d1614c7..0879ee7d 100644 --- a/stone_multiplatform/src/main/kotlin/com/github/klee0kai/stone/annotations/component/ProtectInjected.kt +++ b/stone_multiplatform/src/commonMain/kotlin/stone/annotations/component/ProtectInjected.kt @@ -1,4 +1,4 @@ -package com.github.klee0kai.stone.annotations.component +package stone.annotations.component /** diff --git a/stone_multiplatform/src/main/kotlin/com/github/klee0kai/stone/annotations/component/RunGc.kt b/stone_multiplatform/src/commonMain/kotlin/stone/annotations/component/RunGc.kt similarity index 95% rename from stone_multiplatform/src/main/kotlin/com/github/klee0kai/stone/annotations/component/RunGc.kt rename to stone_multiplatform/src/commonMain/kotlin/stone/annotations/component/RunGc.kt index 1dbb8a79..34db1f65 100644 --- a/stone_multiplatform/src/main/kotlin/com/github/klee0kai/stone/annotations/component/RunGc.kt +++ b/stone_multiplatform/src/commonMain/kotlin/stone/annotations/component/RunGc.kt @@ -1,4 +1,4 @@ -package com.github.klee0kai.stone.annotations.component +package stone.annotations.component /** diff --git a/stone_multiplatform/src/main/kotlin/com/github/klee0kai/stone/annotations/component/SwitchCache.kt b/stone_multiplatform/src/commonMain/kotlin/stone/annotations/component/SwitchCache.kt similarity index 96% rename from stone_multiplatform/src/main/kotlin/com/github/klee0kai/stone/annotations/component/SwitchCache.kt rename to stone_multiplatform/src/commonMain/kotlin/stone/annotations/component/SwitchCache.kt index 0cba3ec7..f202ea69 100644 --- a/stone_multiplatform/src/main/kotlin/com/github/klee0kai/stone/annotations/component/SwitchCache.kt +++ b/stone_multiplatform/src/commonMain/kotlin/stone/annotations/component/SwitchCache.kt @@ -1,4 +1,4 @@ -package com.github.klee0kai.stone.annotations.component +package stone.annotations.component /** diff --git a/stone_multiplatform/src/main/kotlin/com/github/klee0kai/stone/annotations/dependencies/Dependencies.kt b/stone_multiplatform/src/commonMain/kotlin/stone/annotations/dependencies/Dependencies.kt similarity index 95% rename from stone_multiplatform/src/main/kotlin/com/github/klee0kai/stone/annotations/dependencies/Dependencies.kt rename to stone_multiplatform/src/commonMain/kotlin/stone/annotations/dependencies/Dependencies.kt index 049d2ea0..071bc323 100644 --- a/stone_multiplatform/src/main/kotlin/com/github/klee0kai/stone/annotations/dependencies/Dependencies.kt +++ b/stone_multiplatform/src/commonMain/kotlin/stone/annotations/dependencies/Dependencies.kt @@ -1,4 +1,4 @@ -package com.github.klee0kai.stone.annotations.dependencies +package stone.annotations.dependencies /** diff --git a/stone_multiplatform/src/main/kotlin/com/github/klee0kai/stone/annotations/module/BindInstance.kt b/stone_multiplatform/src/commonMain/kotlin/stone/annotations/module/BindInstance.kt similarity index 97% rename from stone_multiplatform/src/main/kotlin/com/github/klee0kai/stone/annotations/module/BindInstance.kt rename to stone_multiplatform/src/commonMain/kotlin/stone/annotations/module/BindInstance.kt index 69c63ac7..494d6c21 100644 --- a/stone_multiplatform/src/main/kotlin/com/github/klee0kai/stone/annotations/module/BindInstance.kt +++ b/stone_multiplatform/src/commonMain/kotlin/stone/annotations/module/BindInstance.kt @@ -1,4 +1,4 @@ -package com.github.klee0kai.stone.annotations.module +package stone.annotations.module import java.lang.annotation.Inherited diff --git a/stone_multiplatform/src/main/kotlin/com/github/klee0kai/stone/annotations/module/Module.kt b/stone_multiplatform/src/commonMain/kotlin/stone/annotations/module/Module.kt similarity index 97% rename from stone_multiplatform/src/main/kotlin/com/github/klee0kai/stone/annotations/module/Module.kt rename to stone_multiplatform/src/commonMain/kotlin/stone/annotations/module/Module.kt index 91c0b934..2043188f 100644 --- a/stone_multiplatform/src/main/kotlin/com/github/klee0kai/stone/annotations/module/Module.kt +++ b/stone_multiplatform/src/commonMain/kotlin/stone/annotations/module/Module.kt @@ -1,4 +1,4 @@ -package com.github.klee0kai.stone.annotations.module +package stone.annotations.module /** diff --git a/stone_multiplatform/src/main/kotlin/com/github/klee0kai/stone/annotations/module/Provide.kt b/stone_multiplatform/src/commonMain/kotlin/stone/annotations/module/Provide.kt similarity index 96% rename from stone_multiplatform/src/main/kotlin/com/github/klee0kai/stone/annotations/module/Provide.kt rename to stone_multiplatform/src/commonMain/kotlin/stone/annotations/module/Provide.kt index 6695e33d..831b7101 100644 --- a/stone_multiplatform/src/main/kotlin/com/github/klee0kai/stone/annotations/module/Provide.kt +++ b/stone_multiplatform/src/commonMain/kotlin/stone/annotations/module/Provide.kt @@ -1,4 +1,4 @@ -package com.github.klee0kai.stone.annotations.module +package stone.annotations.module import java.lang.annotation.Inherited diff --git a/stone_multiplatform/src/main/kotlin/com/github/klee0kai/stone/annotations/wrappers/WrappersCreator.kt b/stone_multiplatform/src/commonMain/kotlin/stone/annotations/wrappers/WrappersCreator.kt similarity index 89% rename from stone_multiplatform/src/main/kotlin/com/github/klee0kai/stone/annotations/wrappers/WrappersCreator.kt rename to stone_multiplatform/src/commonMain/kotlin/stone/annotations/wrappers/WrappersCreator.kt index b9ae1ebb..c1aed87b 100644 --- a/stone_multiplatform/src/main/kotlin/com/github/klee0kai/stone/annotations/wrappers/WrappersCreator.kt +++ b/stone_multiplatform/src/commonMain/kotlin/stone/annotations/wrappers/WrappersCreator.kt @@ -1,4 +1,4 @@ -package com.github.klee0kai.stone.annotations.wrappers +package stone.annotations.wrappers import java.lang.annotation.Inherited diff --git a/stone_multiplatform/src/main/kotlin/com/github/klee0kai/stone/lifecycle/StoneLifeCycleListener.kt b/stone_multiplatform/src/commonMain/kotlin/stone/lifecycle/StoneLifeCycleListener.kt similarity index 65% rename from stone_multiplatform/src/main/kotlin/com/github/klee0kai/stone/lifecycle/StoneLifeCycleListener.kt rename to stone_multiplatform/src/commonMain/kotlin/stone/lifecycle/StoneLifeCycleListener.kt index 2acd3cf0..7085fcec 100644 --- a/stone_multiplatform/src/main/kotlin/com/github/klee0kai/stone/lifecycle/StoneLifeCycleListener.kt +++ b/stone_multiplatform/src/commonMain/kotlin/stone/lifecycle/StoneLifeCycleListener.kt @@ -1,4 +1,4 @@ -package com.github.klee0kai.stone.lifecycle +package stone.lifecycle interface StoneLifeCycleListener { diff --git a/stone_multiplatform/src/main/kotlin/com/github/klee0kai/stone/lifecycle/StoneLifeCycleOwner.kt b/stone_multiplatform/src/commonMain/kotlin/stone/lifecycle/StoneLifeCycleOwner.kt similarity index 94% rename from stone_multiplatform/src/main/kotlin/com/github/klee0kai/stone/lifecycle/StoneLifeCycleOwner.kt rename to stone_multiplatform/src/commonMain/kotlin/stone/lifecycle/StoneLifeCycleOwner.kt index dbd443c3..383fa845 100644 --- a/stone_multiplatform/src/main/kotlin/com/github/klee0kai/stone/lifecycle/StoneLifeCycleOwner.kt +++ b/stone_multiplatform/src/commonMain/kotlin/stone/lifecycle/StoneLifeCycleOwner.kt @@ -1,4 +1,4 @@ -package com.github.klee0kai.stone.lifecycle +package stone.lifecycle /** * Objects in an application can have a life cycle. @@ -51,6 +51,6 @@ package com.github.klee0kai.stone.lifecycle */ interface StoneLifeCycleOwner { - fun subscribe(listener: StoneLifeCycleListener?) + fun subscribe(listener: stone.lifecycle.StoneLifeCycleListener?) } diff --git a/stone_multiplatform/src/main/kotlin/com/github/klee0kai/stone/wrappers/AsyncCoroutineProvide.kt b/stone_multiplatform/src/commonMain/kotlin/stone/wrappers/AsyncCoroutineProvide.kt similarity index 79% rename from stone_multiplatform/src/main/kotlin/com/github/klee0kai/stone/wrappers/AsyncCoroutineProvide.kt rename to stone_multiplatform/src/commonMain/kotlin/stone/wrappers/AsyncCoroutineProvide.kt index 2790221f..2d93483d 100644 --- a/stone_multiplatform/src/main/kotlin/com/github/klee0kai/stone/wrappers/AsyncCoroutineProvide.kt +++ b/stone_multiplatform/src/commonMain/kotlin/stone/wrappers/AsyncCoroutineProvide.kt @@ -1,4 +1,4 @@ -package com.github.klee0kai.stone.wrappers +package stone.wrappers import kotlinx.coroutines.* @@ -6,7 +6,7 @@ class AsyncCoroutineProvide( private val provider: suspend () -> T ) { - constructor(call: Ref) : this(provider = { call.get() }) + constructor(call: stone.wrappers.Ref) : this(provider = { call.get() }) @OptIn(DelicateCoroutinesApi::class) private val asyncValue = GlobalScope.async(Dispatchers.Default) { diff --git a/stone_multiplatform/src/main/kotlin/com/github/klee0kai/stone/wrappers/LazyProvide.kt b/stone_multiplatform/src/commonMain/kotlin/stone/wrappers/LazyProvide.kt similarity index 77% rename from stone_multiplatform/src/main/kotlin/com/github/klee0kai/stone/wrappers/LazyProvide.kt rename to stone_multiplatform/src/commonMain/kotlin/stone/wrappers/LazyProvide.kt index e2984e75..ed5a4a5f 100644 --- a/stone_multiplatform/src/main/kotlin/com/github/klee0kai/stone/wrappers/LazyProvide.kt +++ b/stone_multiplatform/src/commonMain/kotlin/stone/wrappers/LazyProvide.kt @@ -1,4 +1,4 @@ -package com.github.klee0kai.stone.wrappers +package stone.wrappers /** * Providing an object with lazy providing. @@ -11,7 +11,7 @@ package com.github.klee0kai.stone.wrappers * } ` * */ -class LazyProvide(private val call: Ref) : Ref { +class LazyProvide(private val call: stone.wrappers.Ref) : stone.wrappers.Ref { private var value: T? = null override fun get(): T? { diff --git a/stone_multiplatform/src/main/kotlin/com/github/klee0kai/stone/wrappers/PhantomProvide.kt b/stone_multiplatform/src/commonMain/kotlin/stone/wrappers/PhantomProvide.kt similarity index 82% rename from stone_multiplatform/src/main/kotlin/com/github/klee0kai/stone/wrappers/PhantomProvide.kt rename to stone_multiplatform/src/commonMain/kotlin/stone/wrappers/PhantomProvide.kt index d1e7fbc5..84f8a156 100644 --- a/stone_multiplatform/src/main/kotlin/com/github/klee0kai/stone/wrappers/PhantomProvide.kt +++ b/stone_multiplatform/src/commonMain/kotlin/stone/wrappers/PhantomProvide.kt @@ -1,4 +1,4 @@ -package com.github.klee0kai.stone.wrappers +package stone.wrappers /** * Providing an object without any deduction. @@ -16,7 +16,7 @@ package com.github.klee0kai.stone.wrappers * } ` * */ -class PhantomProvide(private val call: Ref) : Ref { +class PhantomProvide(private val call: stone.wrappers.Ref) : stone.wrappers.Ref { override fun get(): T? { return call.get() } diff --git a/stone_multiplatform/src/commonMain/kotlin/stone/wrappers/Ref.kt b/stone_multiplatform/src/commonMain/kotlin/stone/wrappers/Ref.kt new file mode 100644 index 00000000..7860f77a --- /dev/null +++ b/stone_multiplatform/src/commonMain/kotlin/stone/wrappers/Ref.kt @@ -0,0 +1,10 @@ +package stone.wrappers + +import javax.inject.Provider + +fun interface Ref : javax.inject.Provider { + + override fun get(): T + +} + diff --git a/stone_multiplatform/src/main/kotlin/com/github/klee0kai/stone/wrappers/creators/CircleWrapper.kt b/stone_multiplatform/src/commonMain/kotlin/stone/wrappers/creators/CircleWrapper.kt similarity index 81% rename from stone_multiplatform/src/main/kotlin/com/github/klee0kai/stone/wrappers/creators/CircleWrapper.kt rename to stone_multiplatform/src/commonMain/kotlin/stone/wrappers/creators/CircleWrapper.kt index 73f67ac0..8dd4b18c 100644 --- a/stone_multiplatform/src/main/kotlin/com/github/klee0kai/stone/wrappers/creators/CircleWrapper.kt +++ b/stone_multiplatform/src/commonMain/kotlin/stone/wrappers/creators/CircleWrapper.kt @@ -1,6 +1,6 @@ -package com.github.klee0kai.stone.wrappers.creators +package stone.wrappers.creators -interface CircleWrapper : ProviderWrapper { +interface CircleWrapper : stone.wrappers.creators.ProviderWrapper { /** * UnProvide wrapped object. * diff --git a/stone_multiplatform/src/main/kotlin/com/github/klee0kai/stone/wrappers/creators/ProviderWrapper.kt b/stone_multiplatform/src/commonMain/kotlin/stone/wrappers/creators/ProviderWrapper.kt similarity index 89% rename from stone_multiplatform/src/main/kotlin/com/github/klee0kai/stone/wrappers/creators/ProviderWrapper.kt rename to stone_multiplatform/src/commonMain/kotlin/stone/wrappers/creators/ProviderWrapper.kt index b86d68c3..218539d2 100644 --- a/stone_multiplatform/src/main/kotlin/com/github/klee0kai/stone/wrappers/creators/ProviderWrapper.kt +++ b/stone_multiplatform/src/commonMain/kotlin/stone/wrappers/creators/ProviderWrapper.kt @@ -1,4 +1,4 @@ -package com.github.klee0kai.stone.wrappers.creators +package stone.wrappers.creators import javax.inject.Provider diff --git a/stone_multiplatform/src/main/kotlin/com/github/klee0kai/stone/wrappers/creators/Wrapper.kt b/stone_multiplatform/src/commonMain/kotlin/stone/wrappers/creators/Wrapper.kt similarity index 87% rename from stone_multiplatform/src/main/kotlin/com/github/klee0kai/stone/wrappers/creators/Wrapper.kt rename to stone_multiplatform/src/commonMain/kotlin/stone/wrappers/creators/Wrapper.kt index 5437d5da..7e150d23 100644 --- a/stone_multiplatform/src/main/kotlin/com/github/klee0kai/stone/wrappers/creators/Wrapper.kt +++ b/stone_multiplatform/src/commonMain/kotlin/stone/wrappers/creators/Wrapper.kt @@ -1,4 +1,4 @@ -package com.github.klee0kai.stone.wrappers.creators +package stone.wrappers.creators interface Wrapper { /** diff --git a/stone_multiplatform/src/main/kotlin/com/github/klee0kai/stone/wrappers/Ref.kt b/stone_multiplatform/src/main/kotlin/com/github/klee0kai/stone/wrappers/Ref.kt deleted file mode 100644 index 37516848..00000000 --- a/stone_multiplatform/src/main/kotlin/com/github/klee0kai/stone/wrappers/Ref.kt +++ /dev/null @@ -1,10 +0,0 @@ -package com.github.klee0kai.stone.wrappers - -import javax.inject.Provider - -fun interface Ref : Provider { - - override fun get(): T - -} - diff --git a/stone_multiplatform/src/test/kotlin/com/github/klee0kai/stone/RefJvmTest.kt b/stone_multiplatform/src/test/kotlin/com/github/klee0kai/stone/RefJvmTest.kt deleted file mode 100644 index 0636ed50..00000000 --- a/stone_multiplatform/src/test/kotlin/com/github/klee0kai/stone/RefJvmTest.kt +++ /dev/null @@ -1,12 +0,0 @@ -package com.github.klee0kai.stone - -import kotlin.test.Test - -class RefJvmTest { - - @Test - fun simpleTest() { - println("hello") - } - -} \ No newline at end of file diff --git a/weakref_multiplatform/build.gradle.kts b/weakref_multiplatform/build.gradle.kts index 2b358c35..a11b741f 100644 --- a/weakref_multiplatform/build.gradle.kts +++ b/weakref_multiplatform/build.gradle.kts @@ -22,13 +22,7 @@ kotlin { nodejs() } - linuxX64("linux"){ - binaries { - executable { - entryPoint = "main" - } - } - } + linuxX64() mingwX64() sourceSets { @@ -42,39 +36,39 @@ kotlin { } } -//val isMac = System.getProperty("os.name").contains("Mac") -//if (isMac) kotlin { -// macosX64() -// macosArm64() -// iosX64() -// iosArm64() -// iosSimulatorArm64() -// -// sourceSets { -// val commonMain by getting -// val commonTest by getting -// val iosX64Main by getting -// val iosArm64Main by getting -// val iosSimulatorArm64Main by getting -// -// val iosMain by creating { -// dependsOn(commonMain) -// iosX64Main.dependsOn(this) -// iosArm64Main.dependsOn(this) -// iosSimulatorArm64Main.dependsOn(this) -// } -// -// -// val iosX64Test by getting -// val iosArm64Test by getting -// val iosSimulatorArm64Test by getting -// val iosTest by creating { -// dependsOn(commonTest) -// iosX64Test.dependsOn(this) -// iosArm64Test.dependsOn(this) -// iosSimulatorArm64Test.dependsOn(this) -// } -// } -//} +val isMac = System.getProperty("os.name").contains("Mac") +if (isMac) kotlin { + macosX64() + macosArm64() + iosX64() + iosArm64() + iosSimulatorArm64() + + sourceSets { + val commonMain by getting + val commonTest by getting + val iosX64Main by getting + val iosArm64Main by getting + val iosSimulatorArm64Main by getting + + val iosMain by creating { + dependsOn(commonMain) + iosX64Main.dependsOn(this) + iosArm64Main.dependsOn(this) + iosSimulatorArm64Main.dependsOn(this) + } + + + val iosX64Test by getting + val iosArm64Test by getting + val iosSimulatorArm64Test by getting + val iosTest by creating { + dependsOn(commonTest) + iosX64Test.dependsOn(this) + iosArm64Test.dependsOn(this) + iosSimulatorArm64Test.dependsOn(this) + } + } +} From cc184e6078555871aded89c91a506b7f25af463a Mon Sep 17 00:00:00 2001 From: klee0kai Date: Sun, 9 Nov 2025 20:01:12 +0100 Subject: [PATCH 013/122] javax inject multiplatform --- inject_multiplatform/build.gradle.kts | 74 +++++++++++++++++++ .../github/klee0kai/stone/weakref/Inject.kt | 3 + .../github/klee0kai/stone/weakref/Named.kt | 3 + .../github/klee0kai/stone/weakref/Provider.kt | 5 ++ .../klee0kai/stone/weakref/Qualifier.kt | 3 + .../github/klee0kai/stone/weakref/Scope.kt | 3 + .../klee0kai/stone/weakref/Singleton.kt | 3 + .../github/klee0kai/stone/weakref/Inject.kt | 3 + .../github/klee0kai/stone/weakref/Named.kt | 5 ++ .../github/klee0kai/stone/weakref/Provider.kt | 7 ++ .../klee0kai/stone/weakref/Qualifier.kt | 3 + .../github/klee0kai/stone/weakref/Scope.kt | 3 + .../klee0kai/stone/weakref/Singleton.kt | 3 + .../github/klee0kai/stone/weakref/Inject.kt | 5 ++ .../github/klee0kai/stone/weakref/Named.kt | 5 ++ .../github/klee0kai/stone/weakref/Provider.kt | 5 ++ .../klee0kai/stone/weakref/Qualifier.kt | 5 ++ .../github/klee0kai/stone/weakref/Scope.kt | 3 + .../klee0kai/stone/weakref/Singleton.kt | 3 + .../github/klee0kai/stone/weakref/Inject.kt | 3 + .../github/klee0kai/stone/weakref/Named.kt | 3 + .../github/klee0kai/stone/weakref/Provider.kt | 5 ++ .../klee0kai/stone/weakref/Qualifier.kt | 3 + .../github/klee0kai/stone/weakref/Scope.kt | 3 + .../klee0kai/stone/weakref/Singleton.kt | 3 + .../github/klee0kai/stone/weakref/Inject.kt | 3 + .../github/klee0kai/stone/weakref/Named.kt | 3 + .../github/klee0kai/stone/weakref/Provider.kt | 5 ++ .../klee0kai/stone/weakref/Qualifier.kt | 3 + .../github/klee0kai/stone/weakref/Scope.kt | 3 + .../klee0kai/stone/weakref/Singleton.kt | 3 + settings.gradle.kts | 1 + 32 files changed, 185 insertions(+) create mode 100644 inject_multiplatform/build.gradle.kts create mode 100644 inject_multiplatform/src/androidMain/kotlin/com/github/klee0kai/stone/weakref/Inject.kt create mode 100644 inject_multiplatform/src/androidMain/kotlin/com/github/klee0kai/stone/weakref/Named.kt create mode 100644 inject_multiplatform/src/androidMain/kotlin/com/github/klee0kai/stone/weakref/Provider.kt create mode 100644 inject_multiplatform/src/androidMain/kotlin/com/github/klee0kai/stone/weakref/Qualifier.kt create mode 100644 inject_multiplatform/src/androidMain/kotlin/com/github/klee0kai/stone/weakref/Scope.kt create mode 100644 inject_multiplatform/src/androidMain/kotlin/com/github/klee0kai/stone/weakref/Singleton.kt create mode 100644 inject_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/weakref/Inject.kt create mode 100644 inject_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/weakref/Named.kt create mode 100644 inject_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/weakref/Provider.kt create mode 100644 inject_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/weakref/Qualifier.kt create mode 100644 inject_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/weakref/Scope.kt create mode 100644 inject_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/weakref/Singleton.kt create mode 100644 inject_multiplatform/src/jvmMain/kotlin/com/github/klee0kai/stone/weakref/Inject.kt create mode 100644 inject_multiplatform/src/jvmMain/kotlin/com/github/klee0kai/stone/weakref/Named.kt create mode 100644 inject_multiplatform/src/jvmMain/kotlin/com/github/klee0kai/stone/weakref/Provider.kt create mode 100644 inject_multiplatform/src/jvmMain/kotlin/com/github/klee0kai/stone/weakref/Qualifier.kt create mode 100644 inject_multiplatform/src/jvmMain/kotlin/com/github/klee0kai/stone/weakref/Scope.kt create mode 100644 inject_multiplatform/src/jvmMain/kotlin/com/github/klee0kai/stone/weakref/Singleton.kt create mode 100644 inject_multiplatform/src/nativeMain/kotlin/com/github/klee0kai/stone/weakref/Inject.kt create mode 100644 inject_multiplatform/src/nativeMain/kotlin/com/github/klee0kai/stone/weakref/Named.kt create mode 100644 inject_multiplatform/src/nativeMain/kotlin/com/github/klee0kai/stone/weakref/Provider.kt create mode 100644 inject_multiplatform/src/nativeMain/kotlin/com/github/klee0kai/stone/weakref/Qualifier.kt create mode 100644 inject_multiplatform/src/nativeMain/kotlin/com/github/klee0kai/stone/weakref/Scope.kt create mode 100644 inject_multiplatform/src/nativeMain/kotlin/com/github/klee0kai/stone/weakref/Singleton.kt create mode 100644 inject_multiplatform/src/webMain/kotlin/com/github/klee0kai/stone/weakref/Inject.kt create mode 100644 inject_multiplatform/src/webMain/kotlin/com/github/klee0kai/stone/weakref/Named.kt create mode 100644 inject_multiplatform/src/webMain/kotlin/com/github/klee0kai/stone/weakref/Provider.kt create mode 100644 inject_multiplatform/src/webMain/kotlin/com/github/klee0kai/stone/weakref/Qualifier.kt create mode 100644 inject_multiplatform/src/webMain/kotlin/com/github/klee0kai/stone/weakref/Scope.kt create mode 100644 inject_multiplatform/src/webMain/kotlin/com/github/klee0kai/stone/weakref/Singleton.kt diff --git a/inject_multiplatform/build.gradle.kts b/inject_multiplatform/build.gradle.kts new file mode 100644 index 00000000..afd5e7d3 --- /dev/null +++ b/inject_multiplatform/build.gradle.kts @@ -0,0 +1,74 @@ +plugins { + alias(libs.plugins.kotlin.multiplatform) + alias(libs.plugins.android.library) +} + +group = "com.github.klee0kai.stone.inject" +version = libs.versions.stone.get() + +android { + namespace = project.group.toString() + compileSdk = 36 + defaultConfig { + minSdk = 21 + } +} + +kotlin { + androidTarget() + jvm() + js(IR) { + browser() + nodejs() + } + + linuxX64() + mingwX64() + + sourceSets { + commonMain.dependencies { + api(libs.kotlinx.coroutines) + } + jvmMain.dependencies { + api(libs.java.inject) + } + + } +} + +val isMac = System.getProperty("os.name").contains("Mac") +if (isMac) kotlin { + macosX64() + macosArm64() + iosX64() + iosArm64() + iosSimulatorArm64() + + sourceSets { + val commonMain by getting + val commonTest by getting + val iosX64Main by getting + val iosArm64Main by getting + val iosSimulatorArm64Main by getting + + val iosMain by creating { + dependsOn(commonMain) + iosX64Main.dependsOn(this) + iosArm64Main.dependsOn(this) + iosSimulatorArm64Main.dependsOn(this) + } + + + val iosX64Test by getting + val iosArm64Test by getting + val iosSimulatorArm64Test by getting + val iosTest by creating { + dependsOn(commonTest) + iosX64Test.dependsOn(this) + iosArm64Test.dependsOn(this) + iosSimulatorArm64Test.dependsOn(this) + } + } +} + + diff --git a/inject_multiplatform/src/androidMain/kotlin/com/github/klee0kai/stone/weakref/Inject.kt b/inject_multiplatform/src/androidMain/kotlin/com/github/klee0kai/stone/weakref/Inject.kt new file mode 100644 index 00000000..9d8e703d --- /dev/null +++ b/inject_multiplatform/src/androidMain/kotlin/com/github/klee0kai/stone/weakref/Inject.kt @@ -0,0 +1,3 @@ +package com.github.klee0kai.stone.weakref + +actual annotation class Inject actual constructor() \ No newline at end of file diff --git a/inject_multiplatform/src/androidMain/kotlin/com/github/klee0kai/stone/weakref/Named.kt b/inject_multiplatform/src/androidMain/kotlin/com/github/klee0kai/stone/weakref/Named.kt new file mode 100644 index 00000000..6a8ffaf9 --- /dev/null +++ b/inject_multiplatform/src/androidMain/kotlin/com/github/klee0kai/stone/weakref/Named.kt @@ -0,0 +1,3 @@ +package com.github.klee0kai.stone.weakref + +actual annotation class Named actual constructor(actual val value: String) \ No newline at end of file diff --git a/inject_multiplatform/src/androidMain/kotlin/com/github/klee0kai/stone/weakref/Provider.kt b/inject_multiplatform/src/androidMain/kotlin/com/github/klee0kai/stone/weakref/Provider.kt new file mode 100644 index 00000000..cc771814 --- /dev/null +++ b/inject_multiplatform/src/androidMain/kotlin/com/github/klee0kai/stone/weakref/Provider.kt @@ -0,0 +1,5 @@ +package com.github.klee0kai.stone.weakref + +actual interface Provider { + actual fun get(): T +} \ No newline at end of file diff --git a/inject_multiplatform/src/androidMain/kotlin/com/github/klee0kai/stone/weakref/Qualifier.kt b/inject_multiplatform/src/androidMain/kotlin/com/github/klee0kai/stone/weakref/Qualifier.kt new file mode 100644 index 00000000..7382be14 --- /dev/null +++ b/inject_multiplatform/src/androidMain/kotlin/com/github/klee0kai/stone/weakref/Qualifier.kt @@ -0,0 +1,3 @@ +package com.github.klee0kai.stone.weakref + +actual annotation class Qualifier actual constructor() \ No newline at end of file diff --git a/inject_multiplatform/src/androidMain/kotlin/com/github/klee0kai/stone/weakref/Scope.kt b/inject_multiplatform/src/androidMain/kotlin/com/github/klee0kai/stone/weakref/Scope.kt new file mode 100644 index 00000000..14247bbd --- /dev/null +++ b/inject_multiplatform/src/androidMain/kotlin/com/github/klee0kai/stone/weakref/Scope.kt @@ -0,0 +1,3 @@ +package com.github.klee0kai.stone.weakref + +actual annotation class Scope actual constructor() \ No newline at end of file diff --git a/inject_multiplatform/src/androidMain/kotlin/com/github/klee0kai/stone/weakref/Singleton.kt b/inject_multiplatform/src/androidMain/kotlin/com/github/klee0kai/stone/weakref/Singleton.kt new file mode 100644 index 00000000..18f8cb56 --- /dev/null +++ b/inject_multiplatform/src/androidMain/kotlin/com/github/klee0kai/stone/weakref/Singleton.kt @@ -0,0 +1,3 @@ +package com.github.klee0kai.stone.weakref + +actual annotation class Singleton actual constructor() \ No newline at end of file diff --git a/inject_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/weakref/Inject.kt b/inject_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/weakref/Inject.kt new file mode 100644 index 00000000..7b882f7b --- /dev/null +++ b/inject_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/weakref/Inject.kt @@ -0,0 +1,3 @@ +package com.github.klee0kai.stone.weakref + +expect annotation class Inject() \ No newline at end of file diff --git a/inject_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/weakref/Named.kt b/inject_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/weakref/Named.kt new file mode 100644 index 00000000..2f6ad9be --- /dev/null +++ b/inject_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/weakref/Named.kt @@ -0,0 +1,5 @@ +package com.github.klee0kai.stone.weakref + +expect annotation class Named( + val value: String = "" +) diff --git a/inject_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/weakref/Provider.kt b/inject_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/weakref/Provider.kt new file mode 100644 index 00000000..35bc0ff8 --- /dev/null +++ b/inject_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/weakref/Provider.kt @@ -0,0 +1,7 @@ +package com.github.klee0kai.stone.weakref + +expect interface Provider { + + fun get(): T + +} \ No newline at end of file diff --git a/inject_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/weakref/Qualifier.kt b/inject_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/weakref/Qualifier.kt new file mode 100644 index 00000000..633b3608 --- /dev/null +++ b/inject_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/weakref/Qualifier.kt @@ -0,0 +1,3 @@ +package com.github.klee0kai.stone.weakref + +expect annotation class Qualifier() \ No newline at end of file diff --git a/inject_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/weakref/Scope.kt b/inject_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/weakref/Scope.kt new file mode 100644 index 00000000..78fe2b5a --- /dev/null +++ b/inject_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/weakref/Scope.kt @@ -0,0 +1,3 @@ +package com.github.klee0kai.stone.weakref + +expect annotation class Scope() \ No newline at end of file diff --git a/inject_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/weakref/Singleton.kt b/inject_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/weakref/Singleton.kt new file mode 100644 index 00000000..95fe5867 --- /dev/null +++ b/inject_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/weakref/Singleton.kt @@ -0,0 +1,3 @@ +package com.github.klee0kai.stone.weakref + +expect annotation class Singleton() \ No newline at end of file diff --git a/inject_multiplatform/src/jvmMain/kotlin/com/github/klee0kai/stone/weakref/Inject.kt b/inject_multiplatform/src/jvmMain/kotlin/com/github/klee0kai/stone/weakref/Inject.kt new file mode 100644 index 00000000..d160177c --- /dev/null +++ b/inject_multiplatform/src/jvmMain/kotlin/com/github/klee0kai/stone/weakref/Inject.kt @@ -0,0 +1,5 @@ +package com.github.klee0kai.stone.weakref + +import javax.inject.Inject + +actual typealias Inject = Inject \ No newline at end of file diff --git a/inject_multiplatform/src/jvmMain/kotlin/com/github/klee0kai/stone/weakref/Named.kt b/inject_multiplatform/src/jvmMain/kotlin/com/github/klee0kai/stone/weakref/Named.kt new file mode 100644 index 00000000..971644a6 --- /dev/null +++ b/inject_multiplatform/src/jvmMain/kotlin/com/github/klee0kai/stone/weakref/Named.kt @@ -0,0 +1,5 @@ +package com.github.klee0kai.stone.weakref + +import javax.inject.Named + +actual typealias Named = Named \ No newline at end of file diff --git a/inject_multiplatform/src/jvmMain/kotlin/com/github/klee0kai/stone/weakref/Provider.kt b/inject_multiplatform/src/jvmMain/kotlin/com/github/klee0kai/stone/weakref/Provider.kt new file mode 100644 index 00000000..c786672f --- /dev/null +++ b/inject_multiplatform/src/jvmMain/kotlin/com/github/klee0kai/stone/weakref/Provider.kt @@ -0,0 +1,5 @@ +package com.github.klee0kai.stone.weakref + +import javax.inject.Provider + +actual typealias Provider = Provider \ No newline at end of file diff --git a/inject_multiplatform/src/jvmMain/kotlin/com/github/klee0kai/stone/weakref/Qualifier.kt b/inject_multiplatform/src/jvmMain/kotlin/com/github/klee0kai/stone/weakref/Qualifier.kt new file mode 100644 index 00000000..cfe609f7 --- /dev/null +++ b/inject_multiplatform/src/jvmMain/kotlin/com/github/klee0kai/stone/weakref/Qualifier.kt @@ -0,0 +1,5 @@ +package com.github.klee0kai.stone.weakref + +import javax.inject.Qualifier + +actual typealias Qualifier = Qualifier \ No newline at end of file diff --git a/inject_multiplatform/src/jvmMain/kotlin/com/github/klee0kai/stone/weakref/Scope.kt b/inject_multiplatform/src/jvmMain/kotlin/com/github/klee0kai/stone/weakref/Scope.kt new file mode 100644 index 00000000..97f7550f --- /dev/null +++ b/inject_multiplatform/src/jvmMain/kotlin/com/github/klee0kai/stone/weakref/Scope.kt @@ -0,0 +1,3 @@ +package com.github.klee0kai.stone.weakref + +actual typealias Scope = javax.inject.Scope \ No newline at end of file diff --git a/inject_multiplatform/src/jvmMain/kotlin/com/github/klee0kai/stone/weakref/Singleton.kt b/inject_multiplatform/src/jvmMain/kotlin/com/github/klee0kai/stone/weakref/Singleton.kt new file mode 100644 index 00000000..49e37e58 --- /dev/null +++ b/inject_multiplatform/src/jvmMain/kotlin/com/github/klee0kai/stone/weakref/Singleton.kt @@ -0,0 +1,3 @@ +package com.github.klee0kai.stone.weakref + +actual typealias Singleton = javax.inject.Singleton \ No newline at end of file diff --git a/inject_multiplatform/src/nativeMain/kotlin/com/github/klee0kai/stone/weakref/Inject.kt b/inject_multiplatform/src/nativeMain/kotlin/com/github/klee0kai/stone/weakref/Inject.kt new file mode 100644 index 00000000..9d8e703d --- /dev/null +++ b/inject_multiplatform/src/nativeMain/kotlin/com/github/klee0kai/stone/weakref/Inject.kt @@ -0,0 +1,3 @@ +package com.github.klee0kai.stone.weakref + +actual annotation class Inject actual constructor() \ No newline at end of file diff --git a/inject_multiplatform/src/nativeMain/kotlin/com/github/klee0kai/stone/weakref/Named.kt b/inject_multiplatform/src/nativeMain/kotlin/com/github/klee0kai/stone/weakref/Named.kt new file mode 100644 index 00000000..6a8ffaf9 --- /dev/null +++ b/inject_multiplatform/src/nativeMain/kotlin/com/github/klee0kai/stone/weakref/Named.kt @@ -0,0 +1,3 @@ +package com.github.klee0kai.stone.weakref + +actual annotation class Named actual constructor(actual val value: String) \ No newline at end of file diff --git a/inject_multiplatform/src/nativeMain/kotlin/com/github/klee0kai/stone/weakref/Provider.kt b/inject_multiplatform/src/nativeMain/kotlin/com/github/klee0kai/stone/weakref/Provider.kt new file mode 100644 index 00000000..cc771814 --- /dev/null +++ b/inject_multiplatform/src/nativeMain/kotlin/com/github/klee0kai/stone/weakref/Provider.kt @@ -0,0 +1,5 @@ +package com.github.klee0kai.stone.weakref + +actual interface Provider { + actual fun get(): T +} \ No newline at end of file diff --git a/inject_multiplatform/src/nativeMain/kotlin/com/github/klee0kai/stone/weakref/Qualifier.kt b/inject_multiplatform/src/nativeMain/kotlin/com/github/klee0kai/stone/weakref/Qualifier.kt new file mode 100644 index 00000000..7382be14 --- /dev/null +++ b/inject_multiplatform/src/nativeMain/kotlin/com/github/klee0kai/stone/weakref/Qualifier.kt @@ -0,0 +1,3 @@ +package com.github.klee0kai.stone.weakref + +actual annotation class Qualifier actual constructor() \ No newline at end of file diff --git a/inject_multiplatform/src/nativeMain/kotlin/com/github/klee0kai/stone/weakref/Scope.kt b/inject_multiplatform/src/nativeMain/kotlin/com/github/klee0kai/stone/weakref/Scope.kt new file mode 100644 index 00000000..14247bbd --- /dev/null +++ b/inject_multiplatform/src/nativeMain/kotlin/com/github/klee0kai/stone/weakref/Scope.kt @@ -0,0 +1,3 @@ +package com.github.klee0kai.stone.weakref + +actual annotation class Scope actual constructor() \ No newline at end of file diff --git a/inject_multiplatform/src/nativeMain/kotlin/com/github/klee0kai/stone/weakref/Singleton.kt b/inject_multiplatform/src/nativeMain/kotlin/com/github/klee0kai/stone/weakref/Singleton.kt new file mode 100644 index 00000000..18f8cb56 --- /dev/null +++ b/inject_multiplatform/src/nativeMain/kotlin/com/github/klee0kai/stone/weakref/Singleton.kt @@ -0,0 +1,3 @@ +package com.github.klee0kai.stone.weakref + +actual annotation class Singleton actual constructor() \ No newline at end of file diff --git a/inject_multiplatform/src/webMain/kotlin/com/github/klee0kai/stone/weakref/Inject.kt b/inject_multiplatform/src/webMain/kotlin/com/github/klee0kai/stone/weakref/Inject.kt new file mode 100644 index 00000000..9d8e703d --- /dev/null +++ b/inject_multiplatform/src/webMain/kotlin/com/github/klee0kai/stone/weakref/Inject.kt @@ -0,0 +1,3 @@ +package com.github.klee0kai.stone.weakref + +actual annotation class Inject actual constructor() \ No newline at end of file diff --git a/inject_multiplatform/src/webMain/kotlin/com/github/klee0kai/stone/weakref/Named.kt b/inject_multiplatform/src/webMain/kotlin/com/github/klee0kai/stone/weakref/Named.kt new file mode 100644 index 00000000..6a8ffaf9 --- /dev/null +++ b/inject_multiplatform/src/webMain/kotlin/com/github/klee0kai/stone/weakref/Named.kt @@ -0,0 +1,3 @@ +package com.github.klee0kai.stone.weakref + +actual annotation class Named actual constructor(actual val value: String) \ No newline at end of file diff --git a/inject_multiplatform/src/webMain/kotlin/com/github/klee0kai/stone/weakref/Provider.kt b/inject_multiplatform/src/webMain/kotlin/com/github/klee0kai/stone/weakref/Provider.kt new file mode 100644 index 00000000..cc771814 --- /dev/null +++ b/inject_multiplatform/src/webMain/kotlin/com/github/klee0kai/stone/weakref/Provider.kt @@ -0,0 +1,5 @@ +package com.github.klee0kai.stone.weakref + +actual interface Provider { + actual fun get(): T +} \ No newline at end of file diff --git a/inject_multiplatform/src/webMain/kotlin/com/github/klee0kai/stone/weakref/Qualifier.kt b/inject_multiplatform/src/webMain/kotlin/com/github/klee0kai/stone/weakref/Qualifier.kt new file mode 100644 index 00000000..7382be14 --- /dev/null +++ b/inject_multiplatform/src/webMain/kotlin/com/github/klee0kai/stone/weakref/Qualifier.kt @@ -0,0 +1,3 @@ +package com.github.klee0kai.stone.weakref + +actual annotation class Qualifier actual constructor() \ No newline at end of file diff --git a/inject_multiplatform/src/webMain/kotlin/com/github/klee0kai/stone/weakref/Scope.kt b/inject_multiplatform/src/webMain/kotlin/com/github/klee0kai/stone/weakref/Scope.kt new file mode 100644 index 00000000..14247bbd --- /dev/null +++ b/inject_multiplatform/src/webMain/kotlin/com/github/klee0kai/stone/weakref/Scope.kt @@ -0,0 +1,3 @@ +package com.github.klee0kai.stone.weakref + +actual annotation class Scope actual constructor() \ No newline at end of file diff --git a/inject_multiplatform/src/webMain/kotlin/com/github/klee0kai/stone/weakref/Singleton.kt b/inject_multiplatform/src/webMain/kotlin/com/github/klee0kai/stone/weakref/Singleton.kt new file mode 100644 index 00000000..18f8cb56 --- /dev/null +++ b/inject_multiplatform/src/webMain/kotlin/com/github/klee0kai/stone/weakref/Singleton.kt @@ -0,0 +1,3 @@ +package com.github.klee0kai.stone.weakref + +actual annotation class Singleton actual constructor() \ No newline at end of file diff --git a/settings.gradle.kts b/settings.gradle.kts index d28f648b..97ad2d7b 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -21,6 +21,7 @@ dependencyResolutionManagement { rootProject.name = "Stone" includeBuild("plugin_publish") include("weakref_multiplatform") +include("inject_multiplatform") //include(":stone_lib") include(":stone_multiplatform") //include(":stone_processor") From 456666d2bb37e729f9015d30b1318e3d569bf459 Mon Sep 17 00:00:00 2001 From: klee0kai Date: Sun, 9 Nov 2025 20:09:38 +0100 Subject: [PATCH 014/122] weak ref optimize code --- .../klee0kai/stone/weakref/WeakRefDelegate.kt | 22 +++++++++++++++++++ .../github/klee0kai/stone/weakref/WeakRef.kt | 15 ------------- .../github/klee0kai/stone/weakref/WeakRef.kt | 18 --------------- .../github/klee0kai/stone/weakref/WeakRef.kt | 0 .../github/klee0kai/stone/weakref/WeakRef.kt | 1 + 5 files changed, 23 insertions(+), 33 deletions(-) create mode 100644 weakref_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/weakref/WeakRefDelegate.kt delete mode 100644 weakref_multiplatform/src/jvmMain/kotlin/com/github/klee0kai/stone/weakref/WeakRef.kt delete mode 100644 weakref_multiplatform/src/mingwX64Main/kotlin/com/github/klee0kai/stone/weakref/WeakRef.kt rename weakref_multiplatform/src/{linuxMain => nativeMain}/kotlin/com/github/klee0kai/stone/weakref/WeakRef.kt (100%) rename weakref_multiplatform/src/{jsMain => webMain}/kotlin/com/github/klee0kai/stone/weakref/WeakRef.kt (99%) diff --git a/weakref_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/weakref/WeakRefDelegate.kt b/weakref_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/weakref/WeakRefDelegate.kt new file mode 100644 index 00000000..3eed3c5c --- /dev/null +++ b/weakref_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/weakref/WeakRefDelegate.kt @@ -0,0 +1,22 @@ +package com.github.klee0kai.stone.weakref + +import kotlin.reflect.KProperty + +class WeakRefDelegate(value: T) { + + private var weakRef = WeakRef(value) + + operator fun getValue(thisRef: Any?, property: KProperty<*>): T? { + return weakRef.get() + } + + operator fun setValue(thisRef: Any?, property: KProperty<*>, value: T?) { + if (value != null) { + weakRef = WeakRef(value) + } + } + + fun clear() { + weakRef.clear() + } +} \ No newline at end of file diff --git a/weakref_multiplatform/src/jvmMain/kotlin/com/github/klee0kai/stone/weakref/WeakRef.kt b/weakref_multiplatform/src/jvmMain/kotlin/com/github/klee0kai/stone/weakref/WeakRef.kt deleted file mode 100644 index a2e3e801..00000000 --- a/weakref_multiplatform/src/jvmMain/kotlin/com/github/klee0kai/stone/weakref/WeakRef.kt +++ /dev/null @@ -1,15 +0,0 @@ -package com.github.klee0kai.stone.weakref - -import java.lang.ref.WeakReference - -actual class WeakRef actual constructor(value: T) { - - val weakRef: WeakReference = WeakReference(value) - - actual fun get(): T? = weakRef.get() - - actual fun clear() { - weakRef.clear() - } - -} \ No newline at end of file diff --git a/weakref_multiplatform/src/mingwX64Main/kotlin/com/github/klee0kai/stone/weakref/WeakRef.kt b/weakref_multiplatform/src/mingwX64Main/kotlin/com/github/klee0kai/stone/weakref/WeakRef.kt deleted file mode 100644 index ee0057b9..00000000 --- a/weakref_multiplatform/src/mingwX64Main/kotlin/com/github/klee0kai/stone/weakref/WeakRef.kt +++ /dev/null @@ -1,18 +0,0 @@ -@file:OptIn(ExperimentalNativeApi::class) - -package com.github.klee0kai.stone.weakref - -import kotlin.experimental.ExperimentalNativeApi -import kotlin.native.ref.WeakReference - -actual class WeakRef actual constructor(value: T) { - - val weakRef: WeakReference? = value?.let { WeakReference(value) } - - actual fun get(): T? = weakRef?.get() - - actual fun clear() { - weakRef?.clear() - } - -} \ No newline at end of file diff --git a/weakref_multiplatform/src/linuxMain/kotlin/com/github/klee0kai/stone/weakref/WeakRef.kt b/weakref_multiplatform/src/nativeMain/kotlin/com/github/klee0kai/stone/weakref/WeakRef.kt similarity index 100% rename from weakref_multiplatform/src/linuxMain/kotlin/com/github/klee0kai/stone/weakref/WeakRef.kt rename to weakref_multiplatform/src/nativeMain/kotlin/com/github/klee0kai/stone/weakref/WeakRef.kt diff --git a/weakref_multiplatform/src/jsMain/kotlin/com/github/klee0kai/stone/weakref/WeakRef.kt b/weakref_multiplatform/src/webMain/kotlin/com/github/klee0kai/stone/weakref/WeakRef.kt similarity index 99% rename from weakref_multiplatform/src/jsMain/kotlin/com/github/klee0kai/stone/weakref/WeakRef.kt rename to weakref_multiplatform/src/webMain/kotlin/com/github/klee0kai/stone/weakref/WeakRef.kt index 7ce13a42..a43f751f 100644 --- a/weakref_multiplatform/src/jsMain/kotlin/com/github/klee0kai/stone/weakref/WeakRef.kt +++ b/weakref_multiplatform/src/webMain/kotlin/com/github/klee0kai/stone/weakref/WeakRef.kt @@ -16,6 +16,7 @@ actual class WeakRef actual constructor(value: T) { } } + actual fun get(): T? { return if (weakRefDynamic != null) { val derefResult = weakRefDynamic.deref?.invoke() From d567e3f984eaa162001ae2cf3feba44fcaa13815 Mon Sep 17 00:00:00 2001 From: klee0kai Date: Sun, 9 Nov 2025 20:36:33 +0100 Subject: [PATCH 015/122] using inject lib --- stone_multiplatform/build.gradle.kts | 3 ++- .../stone/annotations/component/GcAllScope.kt | 2 +- .../annotations/component/GcScopeAnnotation.kt | 1 - .../stone/annotations/component/GcSoftScope.kt | 6 +++--- .../stone/annotations/component/GcStrongScope.kt | 4 ++-- .../stone/annotations/component/GcWeakScope.kt | 4 ++-- .../annotations/component/ModuleOriginFactory.kt | 1 - .../annotations/component/ProtectInjected.kt | 1 - .../stone/annotations/module/BindInstance.kt | 3 --- .../kotlin/stone/annotations/module/Provide.kt | 4 ---- .../stone/annotations/wrappers/WrappersCreator.kt | 3 --- .../stone/wrappers/AsyncCoroutineProvide.kt | 9 +++++---- .../kotlin/stone/wrappers/LazyProvide.kt | 4 +++- .../kotlin/stone/wrappers/PhantomProvide.kt | 4 +++- .../src/commonMain/kotlin/stone/wrappers/Ref.kt | 4 ++-- .../stone/wrappers/creators/CircleWrapper.kt | 6 ++++-- .../stone/wrappers/creators/ProviderWrapper.kt | 5 +++-- .../kotlin/stone/wrappers/creators/Wrapper.kt | 4 +++- .../com/github/klee0kai/stone/weakref/WeakRef.kt | 15 +++++++++++++++ 19 files changed, 48 insertions(+), 35 deletions(-) create mode 100644 weakref_multiplatform/src/jvmMain/kotlin/com/github/klee0kai/stone/weakref/WeakRef.kt diff --git a/stone_multiplatform/build.gradle.kts b/stone_multiplatform/build.gradle.kts index a21038e0..640b167d 100644 --- a/stone_multiplatform/build.gradle.kts +++ b/stone_multiplatform/build.gradle.kts @@ -27,7 +27,8 @@ kotlin { sourceSets { commonMain.dependencies { - api(libs.java.inject) + api(project(":inject_multiplatform")) + api(project(":weakref_multiplatform")) api(libs.kotlinx.coroutines) } commonTest.dependencies { diff --git a/stone_multiplatform/src/commonMain/kotlin/stone/annotations/component/GcAllScope.kt b/stone_multiplatform/src/commonMain/kotlin/stone/annotations/component/GcAllScope.kt index a8338748..ef57d997 100644 --- a/stone_multiplatform/src/commonMain/kotlin/stone/annotations/component/GcAllScope.kt +++ b/stone_multiplatform/src/commonMain/kotlin/stone/annotations/component/GcAllScope.kt @@ -4,7 +4,7 @@ package stone.annotations.component * A scope that defines all exposed objects in DI. * Used for garbage collection and caching change methods. */ -@stone.annotations.component.GcScopeAnnotation +@GcScopeAnnotation @Retention(AnnotationRetention.BINARY) @Target(AnnotationTarget.FUNCTION, AnnotationTarget.PROPERTY_GETTER, AnnotationTarget.PROPERTY_SETTER) annotation class GcAllScope diff --git a/stone_multiplatform/src/commonMain/kotlin/stone/annotations/component/GcScopeAnnotation.kt b/stone_multiplatform/src/commonMain/kotlin/stone/annotations/component/GcScopeAnnotation.kt index ac95c85b..4de6f58c 100644 --- a/stone_multiplatform/src/commonMain/kotlin/stone/annotations/component/GcScopeAnnotation.kt +++ b/stone_multiplatform/src/commonMain/kotlin/stone/annotations/component/GcScopeAnnotation.kt @@ -1,6 +1,5 @@ package stone.annotations.component - /** * Annotation announcing new scopes for garbage collection and changing the caching method. * Announce new scopes in the following way. diff --git a/stone_multiplatform/src/commonMain/kotlin/stone/annotations/component/GcSoftScope.kt b/stone_multiplatform/src/commonMain/kotlin/stone/annotations/component/GcSoftScope.kt index 90efaea8..e1f1d238 100644 --- a/stone_multiplatform/src/commonMain/kotlin/stone/annotations/component/GcSoftScope.kt +++ b/stone_multiplatform/src/commonMain/kotlin/stone/annotations/component/GcSoftScope.kt @@ -1,14 +1,14 @@ package stone.annotations.component -import javax.inject.Scope +import com.github.klee0kai.stone.weakref.Scope /** * A standard library scope that lists all cached objects using soft references. * Used for garbage collection and caching change methods. */ -@stone.annotations.component.GcScopeAnnotation -@javax.inject.Scope +@GcScopeAnnotation +@Scope @Retention(AnnotationRetention.BINARY) @Target(AnnotationTarget.FUNCTION, AnnotationTarget.PROPERTY_GETTER, AnnotationTarget.PROPERTY_SETTER) annotation class GcSoftScope diff --git a/stone_multiplatform/src/commonMain/kotlin/stone/annotations/component/GcStrongScope.kt b/stone_multiplatform/src/commonMain/kotlin/stone/annotations/component/GcStrongScope.kt index e3e65197..04871c45 100644 --- a/stone_multiplatform/src/commonMain/kotlin/stone/annotations/component/GcStrongScope.kt +++ b/stone_multiplatform/src/commonMain/kotlin/stone/annotations/component/GcStrongScope.kt @@ -1,13 +1,13 @@ package stone.annotations.component +import com.github.klee0kai.stone.weakref.Scope -import javax.inject.Scope /** * A standard library scope that enumerates all cacheable objects using strong references. * Used for garbage collection and caching change methods. */ -@stone.annotations.component.GcScopeAnnotation +@GcScopeAnnotation @Scope @Retention(AnnotationRetention.BINARY) @Target(AnnotationTarget.FUNCTION, AnnotationTarget.PROPERTY_GETTER, AnnotationTarget.PROPERTY_SETTER) diff --git a/stone_multiplatform/src/commonMain/kotlin/stone/annotations/component/GcWeakScope.kt b/stone_multiplatform/src/commonMain/kotlin/stone/annotations/component/GcWeakScope.kt index 03f16b7e..a06f8f2b 100644 --- a/stone_multiplatform/src/commonMain/kotlin/stone/annotations/component/GcWeakScope.kt +++ b/stone_multiplatform/src/commonMain/kotlin/stone/annotations/component/GcWeakScope.kt @@ -1,13 +1,13 @@ package stone.annotations.component -import javax.inject.Scope +import com.github.klee0kai.stone.weakref.Scope /** * A standard library scope that enumerates all cacheable objects using weak references. * Used for garbage collection and caching change methods. */ -@stone.annotations.component.GcScopeAnnotation +@GcScopeAnnotation @Scope @Retention(AnnotationRetention.BINARY) @Target(AnnotationTarget.FUNCTION, AnnotationTarget.PROPERTY_GETTER, AnnotationTarget.PROPERTY_SETTER) diff --git a/stone_multiplatform/src/commonMain/kotlin/stone/annotations/component/ModuleOriginFactory.kt b/stone_multiplatform/src/commonMain/kotlin/stone/annotations/component/ModuleOriginFactory.kt index cd02889a..01be93db 100644 --- a/stone_multiplatform/src/commonMain/kotlin/stone/annotations/component/ModuleOriginFactory.kt +++ b/stone_multiplatform/src/commonMain/kotlin/stone/annotations/component/ModuleOriginFactory.kt @@ -1,6 +1,5 @@ package stone.annotations.component - /** * Provide origin module's factory * diff --git a/stone_multiplatform/src/commonMain/kotlin/stone/annotations/component/ProtectInjected.kt b/stone_multiplatform/src/commonMain/kotlin/stone/annotations/component/ProtectInjected.kt index 0879ee7d..68e1c28b 100644 --- a/stone_multiplatform/src/commonMain/kotlin/stone/annotations/component/ProtectInjected.kt +++ b/stone_multiplatform/src/commonMain/kotlin/stone/annotations/component/ProtectInjected.kt @@ -1,6 +1,5 @@ package stone.annotations.component - /** * Protect provided objects from being destroyed by injection. * When a dependency consumer class is re-created, cached objects may be garbage collected. diff --git a/stone_multiplatform/src/commonMain/kotlin/stone/annotations/module/BindInstance.kt b/stone_multiplatform/src/commonMain/kotlin/stone/annotations/module/BindInstance.kt index 494d6c21..dd148d5a 100644 --- a/stone_multiplatform/src/commonMain/kotlin/stone/annotations/module/BindInstance.kt +++ b/stone_multiplatform/src/commonMain/kotlin/stone/annotations/module/BindInstance.kt @@ -1,7 +1,5 @@ package stone.annotations.module -import java.lang.annotation.Inherited - /** * Those objects that are created outside of DI. @@ -63,7 +61,6 @@ import java.lang.annotation.Inherited */ @Retention(AnnotationRetention.BINARY) @Target(AnnotationTarget.FUNCTION, AnnotationTarget.PROPERTY_GETTER, AnnotationTarget.PROPERTY_SETTER) -@Inherited annotation class BindInstance( /** * Object caching type diff --git a/stone_multiplatform/src/commonMain/kotlin/stone/annotations/module/Provide.kt b/stone_multiplatform/src/commonMain/kotlin/stone/annotations/module/Provide.kt index 831b7101..9d9cde98 100644 --- a/stone_multiplatform/src/commonMain/kotlin/stone/annotations/module/Provide.kt +++ b/stone_multiplatform/src/commonMain/kotlin/stone/annotations/module/Provide.kt @@ -1,8 +1,5 @@ package stone.annotations.module -import java.lang.annotation.Inherited - - /** * Providing objects. * This annotation marks the methods in the module for providing objects. @@ -32,7 +29,6 @@ import java.lang.annotation.Inherited */ @Retention(AnnotationRetention.BINARY) @Target(AnnotationTarget.FUNCTION, AnnotationTarget.PROPERTY_GETTER, AnnotationTarget.PROPERTY_SETTER) -@Inherited annotation class Provide( /** * Object caching type diff --git a/stone_multiplatform/src/commonMain/kotlin/stone/annotations/wrappers/WrappersCreator.kt b/stone_multiplatform/src/commonMain/kotlin/stone/annotations/wrappers/WrappersCreator.kt index c1aed87b..96397592 100644 --- a/stone_multiplatform/src/commonMain/kotlin/stone/annotations/wrappers/WrappersCreator.kt +++ b/stone_multiplatform/src/commonMain/kotlin/stone/annotations/wrappers/WrappersCreator.kt @@ -1,7 +1,5 @@ package stone.annotations.wrappers - -import java.lang.annotation.Inherited import kotlin.reflect.KClass /** @@ -13,7 +11,6 @@ import kotlin.reflect.KClass */ @Retention(AnnotationRetention.BINARY) @Target(AnnotationTarget.CLASS) -@Inherited annotation class WrappersCreator( /** * Custom Wrappers, can be provided diff --git a/stone_multiplatform/src/commonMain/kotlin/stone/wrappers/AsyncCoroutineProvide.kt b/stone_multiplatform/src/commonMain/kotlin/stone/wrappers/AsyncCoroutineProvide.kt index 2d93483d..047d1ba3 100644 --- a/stone_multiplatform/src/commonMain/kotlin/stone/wrappers/AsyncCoroutineProvide.kt +++ b/stone_multiplatform/src/commonMain/kotlin/stone/wrappers/AsyncCoroutineProvide.kt @@ -1,12 +1,15 @@ package stone.wrappers -import kotlinx.coroutines.* +import kotlinx.coroutines.DelicateCoroutinesApi +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.GlobalScope +import kotlinx.coroutines.async class AsyncCoroutineProvide( private val provider: suspend () -> T ) { - constructor(call: stone.wrappers.Ref) : this(provider = { call.get() }) + constructor(call: Ref) : this(provider = { call.get() }) @OptIn(DelicateCoroutinesApi::class) private val asyncValue = GlobalScope.async(Dispatchers.Default) { @@ -17,6 +20,4 @@ class AsyncCoroutineProvide( suspend operator fun invoke(): T = asyncValue.await() - fun syncGet() = runBlocking { provider.invoke() } - } \ No newline at end of file diff --git a/stone_multiplatform/src/commonMain/kotlin/stone/wrappers/LazyProvide.kt b/stone_multiplatform/src/commonMain/kotlin/stone/wrappers/LazyProvide.kt index ed5a4a5f..3f273d70 100644 --- a/stone_multiplatform/src/commonMain/kotlin/stone/wrappers/LazyProvide.kt +++ b/stone_multiplatform/src/commonMain/kotlin/stone/wrappers/LazyProvide.kt @@ -11,11 +11,13 @@ package stone.wrappers * } ` * */ -class LazyProvide(private val call: stone.wrappers.Ref) : stone.wrappers.Ref { +class LazyProvide(private val call: Ref) : Ref { + private var value: T? = null override fun get(): T? { if (value != null) return value return call.get().also { value = it } } + } diff --git a/stone_multiplatform/src/commonMain/kotlin/stone/wrappers/PhantomProvide.kt b/stone_multiplatform/src/commonMain/kotlin/stone/wrappers/PhantomProvide.kt index 84f8a156..a223eb0e 100644 --- a/stone_multiplatform/src/commonMain/kotlin/stone/wrappers/PhantomProvide.kt +++ b/stone_multiplatform/src/commonMain/kotlin/stone/wrappers/PhantomProvide.kt @@ -16,8 +16,10 @@ package stone.wrappers * } ` * */ -class PhantomProvide(private val call: stone.wrappers.Ref) : stone.wrappers.Ref { +class PhantomProvide(private val call: Ref) : Ref { + override fun get(): T? { return call.get() } + } diff --git a/stone_multiplatform/src/commonMain/kotlin/stone/wrappers/Ref.kt b/stone_multiplatform/src/commonMain/kotlin/stone/wrappers/Ref.kt index 7860f77a..76ae086e 100644 --- a/stone_multiplatform/src/commonMain/kotlin/stone/wrappers/Ref.kt +++ b/stone_multiplatform/src/commonMain/kotlin/stone/wrappers/Ref.kt @@ -1,8 +1,8 @@ package stone.wrappers -import javax.inject.Provider +import com.github.klee0kai.stone.weakref.Provider -fun interface Ref : javax.inject.Provider { +fun interface Ref : Provider { override fun get(): T diff --git a/stone_multiplatform/src/commonMain/kotlin/stone/wrappers/creators/CircleWrapper.kt b/stone_multiplatform/src/commonMain/kotlin/stone/wrappers/creators/CircleWrapper.kt index 8dd4b18c..fc8d8bce 100644 --- a/stone_multiplatform/src/commonMain/kotlin/stone/wrappers/creators/CircleWrapper.kt +++ b/stone_multiplatform/src/commonMain/kotlin/stone/wrappers/creators/CircleWrapper.kt @@ -1,6 +1,8 @@ package stone.wrappers.creators -interface CircleWrapper : stone.wrappers.creators.ProviderWrapper { +import kotlin.reflect.KClass + +interface CircleWrapper : ProviderWrapper { /** * UnProvide wrapped object. * @@ -11,5 +13,5 @@ interface CircleWrapper : stone.wrappers.creators.ProviderWrapper { * @param type of providing original object * @return wrapped object provider */ - fun unwrap(wrapperCl: Class?, objectType: Class?, wrapper: Wr?): T? + fun unwrap(wrapperCl: KClass?, objectType: KClass?, wrapper: Wr?): T? } diff --git a/stone_multiplatform/src/commonMain/kotlin/stone/wrappers/creators/ProviderWrapper.kt b/stone_multiplatform/src/commonMain/kotlin/stone/wrappers/creators/ProviderWrapper.kt index 218539d2..93a1f5e8 100644 --- a/stone_multiplatform/src/commonMain/kotlin/stone/wrappers/creators/ProviderWrapper.kt +++ b/stone_multiplatform/src/commonMain/kotlin/stone/wrappers/creators/ProviderWrapper.kt @@ -1,6 +1,7 @@ package stone.wrappers.creators -import javax.inject.Provider +import com.github.klee0kai.stone.weakref.Provider +import kotlin.reflect.KClass interface ProviderWrapper { /** @@ -12,5 +13,5 @@ interface ProviderWrapper { * @param type of providing original object * @return wrapped object provider */ - fun wrap(wrapperCl: Class?, originalProvider: Provider?): Wr? + fun wrap(wrapperCl: KClass?, originalProvider: Provider?): Wr? } diff --git a/stone_multiplatform/src/commonMain/kotlin/stone/wrappers/creators/Wrapper.kt b/stone_multiplatform/src/commonMain/kotlin/stone/wrappers/creators/Wrapper.kt index 7e150d23..876d9573 100644 --- a/stone_multiplatform/src/commonMain/kotlin/stone/wrappers/creators/Wrapper.kt +++ b/stone_multiplatform/src/commonMain/kotlin/stone/wrappers/creators/Wrapper.kt @@ -1,5 +1,7 @@ package stone.wrappers.creators +import kotlin.reflect.KClass + interface Wrapper { /** * Provide wrapped object. @@ -10,5 +12,5 @@ interface Wrapper { * @param type of providing original object * @return wrapped object provider */ - fun wrap(wrapperCl: Class?, original: T?): Wr? + fun wrap(wrapperCl: KClass?, original: T?): Wr? } diff --git a/weakref_multiplatform/src/jvmMain/kotlin/com/github/klee0kai/stone/weakref/WeakRef.kt b/weakref_multiplatform/src/jvmMain/kotlin/com/github/klee0kai/stone/weakref/WeakRef.kt new file mode 100644 index 00000000..d8094fac --- /dev/null +++ b/weakref_multiplatform/src/jvmMain/kotlin/com/github/klee0kai/stone/weakref/WeakRef.kt @@ -0,0 +1,15 @@ +package com.github.klee0kai.stone.weakref + +import java.lang.ref.WeakReference + +actual class WeakRef actual constructor(value: T) { + + val weakRef: WeakReference = WeakReference(value) + + actual fun get(): T? = weakRef.get() + + actual fun clear() { + weakRef.clear() + } + +} \ No newline at end of file From c2f942bf4dd2dde3bbecc90d3a12a9be91f62f80 Mon Sep 17 00:00:00 2001 From: klee0kai Date: Sun, 9 Nov 2025 21:02:47 +0100 Subject: [PATCH 016/122] ksp arch --- libs.versions.toml | 12 ++ settings.gradle.kts | 1 + stone_ksp/build.gradle.kts | 22 ++++ .../klee0kai/thekey/stone/ksp/Processor.kt | 116 ++++++++++++++++++ .../thekey/stone/ksp/ProcessorProvider.kt | 17 +++ .../stone/ksp/coroutines/LaunchConductor.kt | 23 ++++ .../klee0kai/thekey/stone/ksp/ksp/GenSpec.kt | 9 ++ .../thekey/stone/ksp/ksp/SymbolsToProcess.kt | 28 +++++ .../stone/ksp/ksp/TargetFileProcessor.kt | 20 +++ .../thekey/stone/ksp/poet/FileSpecDsl.kt | 82 +++++++++++++ .../thekey/stone/ksp/poet/NamingExt.kt | 7 ++ .../klee0kai/thekey/stone/ksp/poet/PoetExt.kt | 28 +++++ .../thekey/stone/ksp/poet/PropertySpecDsl.kt | 32 +++++ .../thekey/stone/ksp/poet/TypeSpecDsl.kt | 91 ++++++++++++++ ...ols.ksp.processing.SymbolProcessorProvider | 1 + 15 files changed, 489 insertions(+) create mode 100644 stone_ksp/build.gradle.kts create mode 100644 stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/Processor.kt create mode 100644 stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/ProcessorProvider.kt create mode 100644 stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/coroutines/LaunchConductor.kt create mode 100644 stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/ksp/GenSpec.kt create mode 100644 stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/ksp/SymbolsToProcess.kt create mode 100644 stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/ksp/TargetFileProcessor.kt create mode 100644 stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/poet/FileSpecDsl.kt create mode 100644 stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/poet/NamingExt.kt create mode 100644 stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/poet/PoetExt.kt create mode 100644 stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/poet/PropertySpecDsl.kt create mode 100644 stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/poet/TypeSpecDsl.kt create mode 100644 stone_ksp/src/commonMain/resources/services/com.google.devtools.ksp.processing.SymbolProcessorProvider diff --git a/libs.versions.toml b/libs.versions.toml index d0d93077..f907bb81 100644 --- a/libs.versions.toml +++ b/libs.versions.toml @@ -9,10 +9,13 @@ agp = "8.12.3" appcompat = "1.7.1" javax-inject = "1" kotlinx-coroutines = "1.10.1" +jetbrain-immutable = "0.3.7" +jetbrain-coroutines = "1.10.1" auto-service = "1.1.1" incap = "1.0.0" javapoet = "1.13.0" +kotlinpoet = "2.0.0" junit = "6.0.0" junit-launcher = "6.0.0" @@ -21,6 +24,10 @@ testing-compile = "0.23.0" [libraries] + +jetbrain-immutable = { group = "org.jetbrains.kotlinx", name = "kotlinx-collections-immutable", version.ref = "jetbrain-immutable" } +jetbrain-coroutines = { group = "org.jetbrains.kotlinx", name = "kotlinx-coroutines-core", version.ref = "jetbrain-coroutines" } + android-appcompat = { group = "androidx.appcompat", name = "appcompat", version.ref = "appcompat" } # https://mvnrepository.com/artifact/javax.inject/javax.inject @@ -37,6 +44,9 @@ javapoet = { group = "com.squareup", name = "javapoet", version.ref = "javapoet" ksp = { group = "com.google.devtools.ksp", name = "symbol-processing-api", version.ref = "ksp" } +kotlinpoet = { group = "com.squareup", name = "kotlinpoet", version.ref = "kotlinpoet" } +kotlinpoet-ksp = { group = "com.squareup", name = "kotlinpoet-ksp", version.ref = "kotlinpoet" } + jupiter-api = { group = "org.junit.jupiter", name = "junit-jupiter-api", version.ref = "junit" } jupiter-engine = { group = "org.junit.jupiter", name = "junit-jupiter-engine", version.ref = "junit" } jupiter-launcher = { group = "org.junit.platform", name = "junit-platform-launcher", version.ref = "junit-launcher" } @@ -46,6 +56,8 @@ testing-compile = { group = "com.google.testing.compile", name = "compile-testin [bundles] junit = ["jupiter-api", "jupiter-engine", "jupiter-launcher"] +kotlinpoet = ["kotlinpoet", "kotlinpoet-ksp"] +kotlin = ["jetbrain-coroutines", "jetbrain-immutable"] [plugins] diff --git a/settings.gradle.kts b/settings.gradle.kts index 97ad2d7b..e8c25cda 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -46,3 +46,4 @@ include(":stone_multiplatform") //include(":test_feature_core_deps") +include("stone_ksp") \ No newline at end of file diff --git a/stone_ksp/build.gradle.kts b/stone_ksp/build.gradle.kts new file mode 100644 index 00000000..32c98e9c --- /dev/null +++ b/stone_ksp/build.gradle.kts @@ -0,0 +1,22 @@ +plugins { + alias(libs.plugins.kotlin.multiplatform) +} + +group = "com.github.klee0kai.thekey.stone.ksp" +version = libs.versions.stone.get() + + +kotlin { + jvm() + + sourceSets { + commonMain.dependencies { + implementation(libs.bundles.kotlin) + implementation(libs.bundles.kotlinpoet) + implementation(libs.ksp) + } + } +} + + + diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/Processor.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/Processor.kt new file mode 100644 index 00000000..8a6ecb64 --- /dev/null +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/Processor.kt @@ -0,0 +1,116 @@ +package com.github.klee0kai.thekey.stone.ksp + +import com.github.klee0kai.thekey.stone.ksp.coroutines.LaunchConductor +import com.github.klee0kai.thekey.stone.ksp.ksp.GenSpec +import com.github.klee0kai.thekey.stone.ksp.ksp.TargetFileProcessor +import com.github.klee0kai.thekey.stone.ksp.ksp.forceProcess +import com.github.klee0kai.thekey.stone.ksp.ksp.takeOnly +import com.google.devtools.ksp.processing.CodeGenerator +import com.google.devtools.ksp.processing.KSPLogger +import com.google.devtools.ksp.processing.Resolver +import com.google.devtools.ksp.processing.SymbolProcessor +import com.google.devtools.ksp.symbol.KSAnnotated +import com.squareup.kotlinpoet.ksp.writeTo +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.launch +import kotlinx.coroutines.runBlocking +import kotlinx.coroutines.sync.Mutex +import kotlinx.coroutines.sync.withLock +import java.util.concurrent.ConcurrentLinkedQueue +import java.util.concurrent.atomic.AtomicInteger +import kotlin.math.max +import kotlin.math.min + + +class Processor( + private val options: Map, + private val logger: KSPLogger, + private val codeGenerator: CodeGenerator, +) : SymbolProcessor { + + companion object { + const val PROJECT_URL = "https://github.com/klee0kai/stone" + + val ONE_RUN_SYMBOLS_COUNT = max(Runtime.getRuntime().availableProcessors(), 4) + } + + val targetProcessors = arrayOf( +// CrossboxGenInterfaceProcessor(), +// CrossboxModelProcessor(), +// CrossboxSuspendInterfaceProcessor(), +// CrossboxAsyncInterfaceProcessor(), +// CrossboxProxyClassProcessor(), + ) + + override fun process( + resolver: Resolver + ): List = runBlocking(Dispatchers.Default) { + + val processSymbolsCounter = AtomicInteger(0) + val findSymbolsMutex = Mutex() + val globalSymbolsForProcessing = ConcurrentLinkedQueue() + val globalSymbolsForReprocessing = ConcurrentLinkedQueue() + val genSpecs = ConcurrentLinkedQueue() + + val launchConductor = LaunchConductor() + + val generateCodeJob = launch { + targetProcessors.forEach { processor -> + launch { + var symbols = launchConductor.finishTogether { + var symbols = findSymbolsMutex.withLock { processor.findSymbolsToProcess(resolver) } + var takeSymbolsCount = 0 + processSymbolsCounter.updateAndGet { totalCount -> + takeSymbolsCount = + min(symbols.symbolsForProcessing.size, ONE_RUN_SYMBOLS_COUNT - totalCount) + takeSymbolsCount = max(takeSymbolsCount, 0) + totalCount + takeSymbolsCount + } + symbols = symbols.takeOnly(takeSymbolsCount) + globalSymbolsForProcessing.addAll(symbols.symbolsForProcessing) + symbols + } + + symbols = symbols.forceProcess { it in globalSymbolsForProcessing } + globalSymbolsForReprocessing.addAll(symbols.symbolsForReprocessing) + + genSpecs.addAll( + symbols.symbolsForProcessing + .mapNotNull { targetSymbol -> + processor.process( + targetSymbol = targetSymbol, + resolver = resolver, + options = options, + logger = logger, + ) + } + ) + } + } + } + + // join generate code + // we provide separate file recording + // with symbol resolution so that the processor can link the input and output of generation + generateCodeJob.join() + + genSpecs.forEach { genSpec -> + genSpec?.fileSpec?.writeTo( + codeGenerator = codeGenerator, + dependencies = genSpec.dependencies + ) + } + + globalSymbolsForReprocessing.toList() + } + + override fun finish() { + super.finish() + } + + override fun onError() { + super.onError() + } + + +} \ No newline at end of file diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/ProcessorProvider.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/ProcessorProvider.kt new file mode 100644 index 00000000..10363a5c --- /dev/null +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/ProcessorProvider.kt @@ -0,0 +1,17 @@ +package com.github.klee0kai.thekey.stone.ksp + +import com.google.devtools.ksp.processing.SymbolProcessor +import com.google.devtools.ksp.processing.SymbolProcessorEnvironment +import com.google.devtools.ksp.processing.SymbolProcessorProvider + +class ProcessorProvider : SymbolProcessorProvider { + + override fun create(environment: SymbolProcessorEnvironment): SymbolProcessor { + return Processor( + options = environment.options, + logger = environment.logger, + codeGenerator = environment.codeGenerator, + ) + } + +} \ No newline at end of file diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/coroutines/LaunchConductor.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/coroutines/LaunchConductor.kt new file mode 100644 index 00000000..217a6e27 --- /dev/null +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/coroutines/LaunchConductor.kt @@ -0,0 +1,23 @@ +package com.github.klee0kai.thekey.stone.ksp.coroutines + +import kotlinx.coroutines.flow.MutableStateFlow +import kotlinx.coroutines.flow.first +import kotlinx.coroutines.flow.update + +class LaunchConductor { + + private val parallelWorkCounter = MutableStateFlow(0) + + suspend fun finishTogether( + suspendFun: suspend () -> T, + ): T { + parallelWorkCounter.update { it + 1 } + try { + return suspendFun() + } finally { + parallelWorkCounter.update { it - 1 } + parallelWorkCounter.first { it <= 0 } + } + } + +} \ No newline at end of file diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/ksp/GenSpec.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/ksp/GenSpec.kt new file mode 100644 index 00000000..fe6cccfd --- /dev/null +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/ksp/GenSpec.kt @@ -0,0 +1,9 @@ +package com.github.klee0kai.thekey.stone.ksp.ksp + +import com.google.devtools.ksp.processing.Dependencies +import com.squareup.kotlinpoet.FileSpec + +data class GenSpec( + val fileSpec: FileSpec, + val dependencies: Dependencies, +) diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/ksp/SymbolsToProcess.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/ksp/SymbolsToProcess.kt new file mode 100644 index 00000000..6f02b800 --- /dev/null +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/ksp/SymbolsToProcess.kt @@ -0,0 +1,28 @@ +package com.github.klee0kai.thekey.stone.ksp.ksp + +import com.google.devtools.ksp.symbol.KSAnnotated + +data class SymbolsToProcess( + val symbolsForProcessing: List, + val symbolsForReprocessing: List, +) + +fun SymbolsToProcess.takeOnly( + takeSymbolsCount: Int, +): SymbolsToProcess { + return copy( + symbolsForProcessing = symbolsForProcessing.take(takeSymbolsCount), + symbolsForReprocessing = symbolsForReprocessing + symbolsForProcessing.drop(takeSymbolsCount), + ) +} + + +fun SymbolsToProcess.forceProcess( + filter: (KSAnnotated) -> Boolean = { false }, +): SymbolsToProcess { + val symbolsForProcessing = (symbolsForProcessing + symbolsForReprocessing.filter(filter)).toSet() + return copy( + symbolsForProcessing = symbolsForProcessing.toList(), + symbolsForReprocessing = symbolsForReprocessing.filter { it !in symbolsForProcessing } + ) +} \ No newline at end of file diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/ksp/TargetFileProcessor.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/ksp/TargetFileProcessor.kt new file mode 100644 index 00000000..c4ad509e --- /dev/null +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/ksp/TargetFileProcessor.kt @@ -0,0 +1,20 @@ +package com.github.klee0kai.thekey.stone.ksp.ksp + +import com.google.devtools.ksp.processing.KSPLogger +import com.google.devtools.ksp.processing.Resolver +import com.google.devtools.ksp.symbol.KSAnnotated + +interface TargetFileProcessor { + + suspend fun findSymbolsToProcess( + resolver: Resolver, + ): SymbolsToProcess + + suspend fun process( + targetSymbol: KSAnnotated, + resolver: Resolver, + options: Map, + logger: KSPLogger, + ): GenSpec? + +} \ No newline at end of file diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/poet/FileSpecDsl.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/poet/FileSpecDsl.kt new file mode 100644 index 00000000..79500b37 --- /dev/null +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/poet/FileSpecDsl.kt @@ -0,0 +1,82 @@ +package com.github.klee0kai.thekey.stone.ksp.poet + +import com.squareup.kotlinpoet.* + +@DslMarker +annotation class FileSpecDsl + +@FileSpecDsl +fun genFileSpec( + packageName: String, + fileName: String, + block: FileSpec.Builder.() -> Unit, +): FileSpec { + return FileSpec.builder(packageName, fileName) + .also(block) + .build() +} + +@FileSpecDsl +fun FileSpec.Builder.genProperty( + name: String, + type: TypeName, + vararg modifiers: KModifier, + block: PropertySpec.Builder.() -> Unit = {} +) { + addProperty( + PropertySpec.builder(name, type, *modifiers) + .apply(block) + .build() + ) +} + +@FileSpecDsl +fun FileSpec.Builder.genClass( + className: ClassName, + block: TypeSpec.Builder.() -> Unit = {}, +) { + addType( + TypeSpec.classBuilder(className) + .apply(block) + .build() + ) +} + + +@FileSpecDsl +fun FileSpec.Builder.genObject( + className: ClassName, + block: TypeSpec.Builder.() -> Unit = {}, +) { + addType( + TypeSpec.objectBuilder(className) + .apply(block) + .build() + ) +} + +@FileSpecDsl +fun FileSpec.Builder.genInterface( + className: ClassName, + block: TypeSpec.Builder.() -> Unit = {}, +) { + addType( + TypeSpec.interfaceBuilder(className) + .apply(block) + .build() + ) +} + +@FileSpecDsl +fun FileSpec.Builder.genFun( + name: String, + block: FunSpec.Builder.() -> Unit = {}, +) { + addFunction( + FunSpec.builder(name) + .apply(block) + .build() + ) +} + + diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/poet/NamingExt.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/poet/NamingExt.kt new file mode 100644 index 00000000..860111a5 --- /dev/null +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/poet/NamingExt.kt @@ -0,0 +1,7 @@ +package com.github.klee0kai.thekey.stone.ksp.poet + +val String.crossboxPackageName: String + get() { + return if (endsWith(".crossbox")) this + else "$this.crossbox" + } \ No newline at end of file diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/poet/PoetExt.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/poet/PoetExt.kt new file mode 100644 index 00000000..a4cd95da --- /dev/null +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/poet/PoetExt.kt @@ -0,0 +1,28 @@ +package com.github.klee0kai.thekey.stone.ksp.poet + +import com.github.klee0kai.thekey.stone.ksp.Processor +import com.squareup.kotlinpoet.CodeBlock +import com.squareup.kotlinpoet.FileSpec +import com.squareup.kotlinpoet.ParameterSpec +import com.squareup.kotlinpoet.PropertySpec + + +fun FileSpec.Builder.genLibComment() { + addFileComment("Generated by Stone Library\n") + addFileComment("Project " + Processor.PROJECT_URL + "\n") + addFileComment("Copyright (c) 2025 Andrey Kuzubov") +} + + +fun PropertySpec.asParameter(): ParameterSpec = ParameterSpec.builder(name, type).build() + +fun PropertySpec.Builder.initFromConstructor(): PropertySpec.Builder = apply { initializer(build().name) } + +fun Collection.toCodeBlock(): CodeBlock { + val blocks = this + return CodeBlock.builder().apply { + blocks.forEach { + add(it) + } + }.build() +} diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/poet/PropertySpecDsl.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/poet/PropertySpecDsl.kt new file mode 100644 index 00000000..75508429 --- /dev/null +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/poet/PropertySpecDsl.kt @@ -0,0 +1,32 @@ +package com.github.klee0kai.thekey.stone.ksp.poet + +import com.squareup.kotlinpoet.FunSpec +import com.squareup.kotlinpoet.PropertySpec + +@DslMarker +annotation class PropertySpecDsl + +@PropertySpecDsl +fun PropertySpec.Builder.genGetter( + block: FunSpec.Builder.() -> Unit = {} +): FunSpec { + return FunSpec.getterBuilder() + .apply(block) + .build() + .also { + getter(it) + } +} + + +@PropertySpecDsl +fun PropertySpec.Builder.genSetter( + block: FunSpec.Builder.() -> Unit = {} +): FunSpec { + return FunSpec.setterBuilder() + .apply(block) + .build() + .also { + setter(it) + } +} \ No newline at end of file diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/poet/TypeSpecDsl.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/poet/TypeSpecDsl.kt new file mode 100644 index 00000000..66d269a7 --- /dev/null +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/poet/TypeSpecDsl.kt @@ -0,0 +1,91 @@ +package com.github.klee0kai.thekey.stone.ksp.poet + +import com.squareup.kotlinpoet.* + +@DslMarker +annotation class TypeSpecDsl + +@TypeSpecDsl +fun TypeSpec.Builder.genProperty( + name: String, + type: TypeName, + vararg modifiers: KModifier, + block: PropertySpec.Builder.() -> Unit = {} +): PropertySpec { + return PropertySpec.builder(name, type, *modifiers) + .apply(block) + .build() + .also { + addProperty(it) + } +} + +@TypeSpecDsl +fun TypeSpec.Builder.genClass( + className: ClassName, + block: TypeSpec.Builder.() -> Unit = {}, +) { + addType( + TypeSpec.classBuilder(className) + .apply(block) + .build() + ) +} + +@TypeSpecDsl +fun TypeSpec.Builder.genObject( + className: ClassName, + block: TypeSpec.Builder.() -> Unit = {}, +) { + addType( + TypeSpec.objectBuilder(className) + .apply(block) + .build() + ) +} + +@TypeSpecDsl +fun TypeSpec.Builder.genInterface( + className: ClassName, + block: TypeSpec.Builder.() -> Unit = {}, +) { + addType( + TypeSpec.interfaceBuilder(className) + .apply(block) + .build() + ) +} + +@TypeSpecDsl +fun TypeSpec.Builder.genFun( + name: String, + block: FunSpec.Builder.() -> Unit = {}, +) { + addFunction( + FunSpec.builder(name) + .apply(block) + .build() + ) +} + +@TypeSpecDsl +fun TypeSpec.Builder.genPrimaryConstructor( + block: FunSpec.Builder.() -> Unit = {}, +) { + primaryConstructor( + FunSpec.constructorBuilder() + .apply(block) + .build() + ) +} + +@TypeSpecDsl +fun TypeSpec.Builder.genConstructor( + block: FunSpec.Builder.() -> Unit = {}, +) { + addFunction( + FunSpec.constructorBuilder() + .apply(block) + .build() + ) +} \ No newline at end of file diff --git a/stone_ksp/src/commonMain/resources/services/com.google.devtools.ksp.processing.SymbolProcessorProvider b/stone_ksp/src/commonMain/resources/services/com.google.devtools.ksp.processing.SymbolProcessorProvider new file mode 100644 index 00000000..517c103f --- /dev/null +++ b/stone_ksp/src/commonMain/resources/services/com.google.devtools.ksp.processing.SymbolProcessorProvider @@ -0,0 +1 @@ +com.github.klee0kai.thekey.stone.ksp.ProcessorProvider \ No newline at end of file From 63e7ad7c1de8ae3aeb2fe4520c6dddfcbb8e65ce Mon Sep 17 00:00:00 2001 From: klee0kai Date: Sun, 9 Nov 2025 22:21:00 +0100 Subject: [PATCH 017/122] ksp processor start --- libs.versions.toml | 3 +- settings.gradle.kts | 6 +- stone_ksp/build.gradle.kts | 1 + .../klee0kai/thekey/stone/ksp/Processor.kt | 16 ++-- .../stone/ksp/ksp/TargetFileProcessor.kt | 2 +- .../thekey/stone/ksp/poet/NamingExt.kt | 6 +- .../thekey/stone/ksp/target/CommonPoetExt.kt | 47 ++++++++++ .../ksp/target/ModuleFactoryProcessor.kt | 89 +++++++++++++++++++ ...ols.ksp.processing.SymbolProcessorProvider | 0 .../klee0kai}/stone/__hidden__/IModule.kt | 6 +- .../stone/__hidden__/IModuleFactory.kt | 2 +- .../stone/__hidden__/IPrivateComponent.kt | 8 +- .../stone/annotations/component/Component.kt | 2 +- .../stone/annotations/component/ExtendOf.kt | 2 +- .../stone/annotations/component/GcAllScope.kt | 4 +- .../component/GcScopeAnnotation.kt | 2 +- .../annotations/component/GcSoftScope.kt | 4 +- .../annotations/component/GcStrongScope.kt | 4 +- .../annotations/component/GcWeakScope.kt | 4 +- .../stone/annotations/component/Init.kt | 2 +- .../component/ModuleOriginFactory.kt | 2 +- .../annotations/component/ProtectInjected.kt | 2 +- .../stone/annotations/component/RunGc.kt | 2 +- .../annotations/component/SwitchCache.kt | 2 +- .../annotations/dependencies/Dependencies.kt | 2 +- .../stone/annotations/module/BindInstance.kt | 2 +- .../stone/annotations/module/Module.kt | 2 +- .../stone/annotations/module/Provide.kt | 2 +- .../annotations/wrappers/WrappersCreator.kt | 2 +- .../stone/lifecycle/StoneLifeCycleListener.kt | 2 +- .../stone/lifecycle/StoneLifeCycleOwner.kt | 4 +- .../stone/wrappers/AsyncCoroutineProvide.kt | 2 +- .../klee0kai}/stone/wrappers/LazyProvide.kt | 2 +- .../stone/wrappers/PhantomProvide.kt | 2 +- .../github/klee0kai}/stone/wrappers/Ref.kt | 2 +- .../stone/wrappers/creators/CircleWrapper.kt | 2 +- .../wrappers/creators/ProviderWrapper.kt | 2 +- .../stone/wrappers/creators/Wrapper.kt | 2 +- tests_kotlin/build.gradle.kts | 8 +- 39 files changed, 195 insertions(+), 61 deletions(-) create mode 100644 stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/CommonPoetExt.kt create mode 100644 stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/ModuleFactoryProcessor.kt rename stone_ksp/src/commonMain/resources/{ => META-INF}/services/com.google.devtools.ksp.processing.SymbolProcessorProvider (100%) rename stone_multiplatform/src/commonMain/kotlin/{ => com/github/klee0kai}/stone/__hidden__/IModule.kt (80%) rename stone_multiplatform/src/commonMain/kotlin/{ => com/github/klee0kai}/stone/__hidden__/IModuleFactory.kt (56%) rename stone_multiplatform/src/commonMain/kotlin/{ => com/github/klee0kai}/stone/__hidden__/IPrivateComponent.kt (75%) rename stone_multiplatform/src/commonMain/kotlin/{ => com/github/klee0kai}/stone/annotations/component/Component.kt (99%) rename stone_multiplatform/src/commonMain/kotlin/{ => com/github/klee0kai}/stone/annotations/component/ExtendOf.kt (95%) rename stone_multiplatform/src/commonMain/kotlin/{ => com/github/klee0kai}/stone/annotations/component/GcAllScope.kt (70%) rename stone_multiplatform/src/commonMain/kotlin/{ => com/github/klee0kai}/stone/annotations/component/GcScopeAnnotation.kt (92%) rename stone_multiplatform/src/commonMain/kotlin/{ => com/github/klee0kai}/stone/annotations/component/GcSoftScope.kt (75%) rename stone_multiplatform/src/commonMain/kotlin/{ => com/github/klee0kai}/stone/annotations/component/GcStrongScope.kt (75%) rename stone_multiplatform/src/commonMain/kotlin/{ => com/github/klee0kai}/stone/annotations/component/GcWeakScope.kt (75%) rename stone_multiplatform/src/commonMain/kotlin/{ => com/github/klee0kai}/stone/annotations/component/Init.kt (92%) rename stone_multiplatform/src/commonMain/kotlin/{ => com/github/klee0kai}/stone/annotations/component/ModuleOriginFactory.kt (90%) rename stone_multiplatform/src/commonMain/kotlin/{ => com/github/klee0kai}/stone/annotations/component/ProtectInjected.kt (93%) rename stone_multiplatform/src/commonMain/kotlin/{ => com/github/klee0kai}/stone/annotations/component/RunGc.kt (95%) rename stone_multiplatform/src/commonMain/kotlin/{ => com/github/klee0kai}/stone/annotations/component/SwitchCache.kt (96%) rename stone_multiplatform/src/commonMain/kotlin/{ => com/github/klee0kai}/stone/annotations/dependencies/Dependencies.kt (95%) rename stone_multiplatform/src/commonMain/kotlin/{ => com/github/klee0kai}/stone/annotations/module/BindInstance.kt (97%) rename stone_multiplatform/src/commonMain/kotlin/{ => com/github/klee0kai}/stone/annotations/module/Module.kt (97%) rename stone_multiplatform/src/commonMain/kotlin/{ => com/github/klee0kai}/stone/annotations/module/Provide.kt (96%) rename stone_multiplatform/src/commonMain/kotlin/{ => com/github/klee0kai}/stone/annotations/wrappers/WrappersCreator.kt (88%) rename stone_multiplatform/src/commonMain/kotlin/{ => com/github/klee0kai}/stone/lifecycle/StoneLifeCycleListener.kt (65%) rename stone_multiplatform/src/commonMain/kotlin/{ => com/github/klee0kai}/stone/lifecycle/StoneLifeCycleOwner.kt (94%) rename stone_multiplatform/src/commonMain/kotlin/{ => com/github/klee0kai}/stone/wrappers/AsyncCoroutineProvide.kt (92%) rename stone_multiplatform/src/commonMain/kotlin/{ => com/github/klee0kai}/stone/wrappers/LazyProvide.kt (91%) rename stone_multiplatform/src/commonMain/kotlin/{ => com/github/klee0kai}/stone/wrappers/PhantomProvide.kt (93%) rename stone_multiplatform/src/commonMain/kotlin/{ => com/github/klee0kai}/stone/wrappers/Ref.kt (73%) rename stone_multiplatform/src/commonMain/kotlin/{ => com/github/klee0kai}/stone/wrappers/creators/CircleWrapper.kt (90%) rename stone_multiplatform/src/commonMain/kotlin/{ => com/github/klee0kai}/stone/wrappers/creators/ProviderWrapper.kt (90%) rename stone_multiplatform/src/commonMain/kotlin/{ => com/github/klee0kai}/stone/wrappers/creators/Wrapper.kt (88%) diff --git a/libs.versions.toml b/libs.versions.toml index f907bb81..df82c017 100644 --- a/libs.versions.toml +++ b/libs.versions.toml @@ -3,7 +3,7 @@ stone = "1.0.7" kotlin = "2.2.21" -ksp = "2.1.10-1.0.30" +ksp = "2.2.21-2.0.4" agp = "8.12.3" appcompat = "1.7.1" @@ -64,7 +64,6 @@ kotlin = ["jetbrain-coroutines", "jetbrain-immutable"] kotlin-ksp = { id = "com.google.devtools.ksp", version.ref = "ksp" } kotlin-jvm = { id = "org.jetbrains.kotlin.jvm", version.ref = "kotlin" } kotlin-kapt = { id = "org.jetbrains.kotlin.kapt", version.ref = "kotlin" } -kotlin-dsl = { id = "org.gradle.kotlin.kotlin-dsl", version.ref = "kotlin" } kotlin-multiplatform = { id = "org.jetbrains.kotlin.multiplatform", version.ref = "kotlin" } android-library = { id = "com.android.library", version.ref = "agp" } diff --git a/settings.gradle.kts b/settings.gradle.kts index e8c25cda..14765687 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -22,9 +22,9 @@ rootProject.name = "Stone" includeBuild("plugin_publish") include("weakref_multiplatform") include("inject_multiplatform") -//include(":stone_lib") +include(":stone_lib") include(":stone_multiplatform") -//include(":stone_processor") +include(":stone_processor") //include(":android_lib") //include(":kotlin_lib") // @@ -32,7 +32,7 @@ include(":stone_multiplatform") //include(":wiki_kotlin") //include(":tests") //include(":tests_ext") -//include(":tests_kotlin") +include(":tests_kotlin") //include(":tests_wraps") //include(":tests_wraps_kotlin") //include(":tests_compile") diff --git a/stone_ksp/build.gradle.kts b/stone_ksp/build.gradle.kts index 32c98e9c..072bc616 100644 --- a/stone_ksp/build.gradle.kts +++ b/stone_ksp/build.gradle.kts @@ -11,6 +11,7 @@ kotlin { sourceSets { commonMain.dependencies { + implementation(project(":stone_multiplatform")) implementation(libs.bundles.kotlin) implementation(libs.bundles.kotlinpoet) implementation(libs.ksp) diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/Processor.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/Processor.kt index 8a6ecb64..53e8fe3e 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/Processor.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/Processor.kt @@ -5,6 +5,7 @@ import com.github.klee0kai.thekey.stone.ksp.ksp.GenSpec import com.github.klee0kai.thekey.stone.ksp.ksp.TargetFileProcessor import com.github.klee0kai.thekey.stone.ksp.ksp.forceProcess import com.github.klee0kai.thekey.stone.ksp.ksp.takeOnly +import com.github.klee0kai.thekey.stone.ksp.target.ModuleFactoryProcessor import com.google.devtools.ksp.processing.CodeGenerator import com.google.devtools.ksp.processing.KSPLogger import com.google.devtools.ksp.processing.Resolver @@ -35,11 +36,7 @@ class Processor( } val targetProcessors = arrayOf( -// CrossboxGenInterfaceProcessor(), -// CrossboxModelProcessor(), -// CrossboxSuspendInterfaceProcessor(), -// CrossboxAsyncInterfaceProcessor(), -// CrossboxProxyClassProcessor(), + ModuleFactoryProcessor(), ) override fun process( @@ -61,8 +58,11 @@ class Processor( var symbols = findSymbolsMutex.withLock { processor.findSymbolsToProcess(resolver) } var takeSymbolsCount = 0 processSymbolsCounter.updateAndGet { totalCount -> - takeSymbolsCount = - min(symbols.symbolsForProcessing.size, ONE_RUN_SYMBOLS_COUNT - totalCount) + takeSymbolsCount = min( + symbols.symbolsForProcessing.size, + ONE_RUN_SYMBOLS_COUNT - totalCount + ) + takeSymbolsCount = max(takeSymbolsCount, 0) totalCount + takeSymbolsCount } @@ -78,7 +78,7 @@ class Processor( symbols.symbolsForProcessing .mapNotNull { targetSymbol -> processor.process( - targetSymbol = targetSymbol, + validSymbol = targetSymbol, resolver = resolver, options = options, logger = logger, diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/ksp/TargetFileProcessor.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/ksp/TargetFileProcessor.kt index c4ad509e..0df30f38 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/ksp/TargetFileProcessor.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/ksp/TargetFileProcessor.kt @@ -11,7 +11,7 @@ interface TargetFileProcessor { ): SymbolsToProcess suspend fun process( - targetSymbol: KSAnnotated, + validSymbol: KSAnnotated, resolver: Resolver, options: Map, logger: KSPLogger, diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/poet/NamingExt.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/poet/NamingExt.kt index 860111a5..563ac3fa 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/poet/NamingExt.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/poet/NamingExt.kt @@ -1,7 +1,7 @@ package com.github.klee0kai.thekey.stone.ksp.poet -val String.crossboxPackageName: String +val String.stonePackageName: String get() { - return if (endsWith(".crossbox")) this - else "$this.crossbox" + return if (endsWith(".stone")) this + else "$this.stone" } \ No newline at end of file diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/CommonPoetExt.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/CommonPoetExt.kt new file mode 100644 index 00000000..b1b32ab2 --- /dev/null +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/CommonPoetExt.kt @@ -0,0 +1,47 @@ +package com.github.klee0kai.thekey.stone.ksp.target + +import com.google.devtools.ksp.symbol.KSFunctionDeclaration +import com.google.devtools.ksp.symbol.Modifier +import com.squareup.kotlinpoet.FunSpec +import com.squareup.kotlinpoet.KModifier +import com.squareup.kotlinpoet.ParameterSpec +import com.squareup.kotlinpoet.ParameterizedTypeName.Companion.parameterizedBy +import com.squareup.kotlinpoet.TypeName +import com.squareup.kotlinpoet.asClassName +import com.squareup.kotlinpoet.ksp.toClassName +import com.squareup.kotlinpoet.ksp.toTypeName +import kotlinx.coroutines.Deferred +import kotlinx.coroutines.Job + +val KSFunctionDeclaration.isSuspend: Boolean get() = modifiers.contains(Modifier.SUSPEND) + +val KSFunctionDeclaration.asyncReturnType: TypeName? + get() { + val returnType = returnType?.resolve()?.toClassName() + return when { + returnType != null && !isSuspend -> returnType + returnType != null && returnType != Unit::class.asClassName() -> + Deferred::class.asClassName().parameterizedBy(returnType) + + isSuspend -> Job::class.asClassName() + else -> returnType + } + } + +fun FunSpec.Builder.declareSameParameters( + function: KSFunctionDeclaration, +) = apply { + function.returnType?.resolve()?.toClassName()?.let { returns(it) } + function.extensionReceiver?.resolve()?.toClassName()?.let { receiver(it) } + + function.parameters.forEach { param -> + addParameter( + ParameterSpec.builder( + name = param.name?.asString() ?: "", + type = param.type.resolve().toTypeName(), + ).apply { + if (param.isVararg) addModifiers(KModifier.VARARG) + }.build() + ) + } +} diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/ModuleFactoryProcessor.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/ModuleFactoryProcessor.kt new file mode 100644 index 00000000..bbbd56a1 --- /dev/null +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/ModuleFactoryProcessor.kt @@ -0,0 +1,89 @@ +@file:OptIn(KspExperimental::class) + +package com.github.klee0kai.thekey.stone.ksp.target + +import com.github.klee0kai.stone.annotations.module.BindInstance +import com.github.klee0kai.stone.annotations.module.Module +import com.github.klee0kai.thekey.stone.ksp.ksp.GenSpec +import com.github.klee0kai.thekey.stone.ksp.ksp.SymbolsToProcess +import com.github.klee0kai.thekey.stone.ksp.ksp.TargetFileProcessor +import com.github.klee0kai.thekey.stone.ksp.poet.* +import com.google.devtools.ksp.KspExperimental +import com.google.devtools.ksp.containingFile +import com.google.devtools.ksp.getAnnotationsByType +import com.google.devtools.ksp.processing.Dependencies +import com.google.devtools.ksp.processing.KSPLogger +import com.google.devtools.ksp.processing.Resolver +import com.google.devtools.ksp.symbol.KSAnnotated +import com.google.devtools.ksp.symbol.KSClassDeclaration +import com.squareup.kotlinpoet.ClassName +import com.squareup.kotlinpoet.KModifier +import com.squareup.kotlinpoet.asClassName +import com.squareup.kotlinpoet.ksp.toClassName + +class ModuleFactoryProcessor : TargetFileProcessor { + + override suspend fun findSymbolsToProcess( + resolver: Resolver, + ) = SymbolsToProcess( + symbolsForProcessing = resolver + .getSymbolsWithAnnotation(Module::class.asClassName().canonicalName) + .toList(), + symbolsForReprocessing = emptyList(), + ) + + override suspend fun process( + validSymbol: KSAnnotated, + resolver: Resolver, + options: Map, + logger: KSPLogger + ): GenSpec? { + + val fileOwner = validSymbol.containingFile ?: return null + val classDeclaration = validSymbol as? KSClassDeclaration ?: return null + + val moduleInterfaceInterfaceAnn = + classDeclaration.getAnnotationsByType(Module::class) + .firstOrNull() ?: return null + + val genClassName = ClassName( + fileOwner.packageName.asString().stonePackageName, + "I${classDeclaration.simpleName.getShortName()}" + ) + + val fileSpec = genFileSpec(genClassName.packageName, genClassName.simpleName) { + genLibComment() + + genClass(genClassName) { + validSymbol.getAllFunctions().forEach { function -> + if (!function.isAbstract) return@genClass + val returnType = function.returnType?.resolve()?.toClassName() ?: return@genClass + val moduleInterfaceInterfaceAnn = function.getAnnotationsByType(BindInstance::class) + .firstOrNull() ?: return@genClass + + genFun(function.simpleName.asString()) { + declareSameParameters(function) + returns(returnType) + if (function.isSuspend) addModifiers(KModifier.SUSPEND) + + if (moduleInterfaceInterfaceAnn != null) { + addStatement("return null") + } else { + + } + } + + + } + } + } + + + + return GenSpec( + fileSpec = fileSpec, + // https://kotlinlang.org/docs/ksp-incremental.html + dependencies = Dependencies(aggregating = false, fileOwner), + ) + } +} \ No newline at end of file diff --git a/stone_ksp/src/commonMain/resources/services/com.google.devtools.ksp.processing.SymbolProcessorProvider b/stone_ksp/src/commonMain/resources/META-INF/services/com.google.devtools.ksp.processing.SymbolProcessorProvider similarity index 100% rename from stone_ksp/src/commonMain/resources/services/com.google.devtools.ksp.processing.SymbolProcessorProvider rename to stone_ksp/src/commonMain/resources/META-INF/services/com.google.devtools.ksp.processing.SymbolProcessorProvider diff --git a/stone_multiplatform/src/commonMain/kotlin/stone/__hidden__/IModule.kt b/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/__hidden__/IModule.kt similarity index 80% rename from stone_multiplatform/src/commonMain/kotlin/stone/__hidden__/IModule.kt rename to stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/__hidden__/IModule.kt index 76aa2eb7..fa45ba86 100644 --- a/stone_multiplatform/src/commonMain/kotlin/stone/__hidden__/IModule.kt +++ b/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/__hidden__/IModule.kt @@ -1,4 +1,4 @@ -package stone.__hidden__ +package com.github.klee0kai.stone.__hidden__ /** * Stone Private class @@ -17,14 +17,14 @@ interface IModule { * Init caches from module prototype. * using in extOf method */ - fun __initCachesFrom(module: IModule?) + fun __initCachesFrom(module: com.github.klee0kai.stone.__hidden__.IModule?) /** * Update values of bindInstance variables * * @param module related module, source to update */ - fun __updateBindInstancesFrom(module: IModule?) + fun __updateBindInstancesFrom(module: com.github.klee0kai.stone.__hidden__.IModule?) /** * bind instance objects diff --git a/stone_multiplatform/src/commonMain/kotlin/stone/__hidden__/IModuleFactory.kt b/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/__hidden__/IModuleFactory.kt similarity index 56% rename from stone_multiplatform/src/commonMain/kotlin/stone/__hidden__/IModuleFactory.kt rename to stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/__hidden__/IModuleFactory.kt index fdd5b665..00a61bd2 100644 --- a/stone_multiplatform/src/commonMain/kotlin/stone/__hidden__/IModuleFactory.kt +++ b/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/__hidden__/IModuleFactory.kt @@ -1,4 +1,4 @@ -package stone.__hidden__ +package com.github.klee0kai.stone.__hidden__ /** * Stone Private class diff --git a/stone_multiplatform/src/commonMain/kotlin/stone/__hidden__/IPrivateComponent.kt b/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/__hidden__/IPrivateComponent.kt similarity index 75% rename from stone_multiplatform/src/commonMain/kotlin/stone/__hidden__/IPrivateComponent.kt rename to stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/__hidden__/IPrivateComponent.kt index cb8d7e84..8206f3b6 100644 --- a/stone_multiplatform/src/commonMain/kotlin/stone/__hidden__/IPrivateComponent.kt +++ b/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/__hidden__/IPrivateComponent.kt @@ -1,4 +1,4 @@ -package stone.__hidden__ +package com.github.klee0kai.stone.__hidden__ /** @@ -34,16 +34,16 @@ interface IPrivateComponent { /** * this component extends of other */ - fun __extOf(components: stone.__hidden__.IPrivateComponent?) + fun __extOf(components: com.github.klee0kai.stone.__hidden__.IPrivateComponent?) /** * hidden module */ - fun __hidden(): stone.__hidden__.IModule? + fun __hidden(): com.github.klee0kai.stone.__hidden__.IModule? /** * * @param callback */ - fun __eachModule(callback: (stone.__hidden__.IModule) -> Unit) + fun __eachModule(callback: (com.github.klee0kai.stone.__hidden__.IModule) -> Unit) } diff --git a/stone_multiplatform/src/commonMain/kotlin/stone/annotations/component/Component.kt b/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/annotations/component/Component.kt similarity index 99% rename from stone_multiplatform/src/commonMain/kotlin/stone/annotations/component/Component.kt rename to stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/annotations/component/Component.kt index 599ce8ee..59e29fe1 100644 --- a/stone_multiplatform/src/commonMain/kotlin/stone/annotations/component/Component.kt +++ b/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/annotations/component/Component.kt @@ -1,4 +1,4 @@ -package stone.annotations.component +package com.github.klee0kai.stone.annotations.component import kotlin.reflect.KClass diff --git a/stone_multiplatform/src/commonMain/kotlin/stone/annotations/component/ExtendOf.kt b/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/annotations/component/ExtendOf.kt similarity index 95% rename from stone_multiplatform/src/commonMain/kotlin/stone/annotations/component/ExtendOf.kt rename to stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/annotations/component/ExtendOf.kt index 9b08fe5b..366a3693 100644 --- a/stone_multiplatform/src/commonMain/kotlin/stone/annotations/component/ExtendOf.kt +++ b/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/annotations/component/ExtendOf.kt @@ -1,4 +1,4 @@ -package stone.annotations.component +package com.github.klee0kai.stone.annotations.component /** diff --git a/stone_multiplatform/src/commonMain/kotlin/stone/annotations/component/GcAllScope.kt b/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/annotations/component/GcAllScope.kt similarity index 70% rename from stone_multiplatform/src/commonMain/kotlin/stone/annotations/component/GcAllScope.kt rename to stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/annotations/component/GcAllScope.kt index ef57d997..8fa10fd7 100644 --- a/stone_multiplatform/src/commonMain/kotlin/stone/annotations/component/GcAllScope.kt +++ b/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/annotations/component/GcAllScope.kt @@ -1,10 +1,10 @@ -package stone.annotations.component +package com.github.klee0kai.stone.annotations.component /** * A scope that defines all exposed objects in DI. * Used for garbage collection and caching change methods. */ -@GcScopeAnnotation +@com.github.klee0kai.stone.annotations.component.GcScopeAnnotation @Retention(AnnotationRetention.BINARY) @Target(AnnotationTarget.FUNCTION, AnnotationTarget.PROPERTY_GETTER, AnnotationTarget.PROPERTY_SETTER) annotation class GcAllScope diff --git a/stone_multiplatform/src/commonMain/kotlin/stone/annotations/component/GcScopeAnnotation.kt b/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/annotations/component/GcScopeAnnotation.kt similarity index 92% rename from stone_multiplatform/src/commonMain/kotlin/stone/annotations/component/GcScopeAnnotation.kt rename to stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/annotations/component/GcScopeAnnotation.kt index 4de6f58c..a62b149a 100644 --- a/stone_multiplatform/src/commonMain/kotlin/stone/annotations/component/GcScopeAnnotation.kt +++ b/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/annotations/component/GcScopeAnnotation.kt @@ -1,4 +1,4 @@ -package stone.annotations.component +package com.github.klee0kai.stone.annotations.component /** * Annotation announcing new scopes for garbage collection and changing the caching method. diff --git a/stone_multiplatform/src/commonMain/kotlin/stone/annotations/component/GcSoftScope.kt b/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/annotations/component/GcSoftScope.kt similarity index 75% rename from stone_multiplatform/src/commonMain/kotlin/stone/annotations/component/GcSoftScope.kt rename to stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/annotations/component/GcSoftScope.kt index e1f1d238..d9932b57 100644 --- a/stone_multiplatform/src/commonMain/kotlin/stone/annotations/component/GcSoftScope.kt +++ b/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/annotations/component/GcSoftScope.kt @@ -1,4 +1,4 @@ -package stone.annotations.component +package com.github.klee0kai.stone.annotations.component import com.github.klee0kai.stone.weakref.Scope @@ -7,7 +7,7 @@ import com.github.klee0kai.stone.weakref.Scope * A standard library scope that lists all cached objects using soft references. * Used for garbage collection and caching change methods. */ -@GcScopeAnnotation +@com.github.klee0kai.stone.annotations.component.GcScopeAnnotation @Scope @Retention(AnnotationRetention.BINARY) @Target(AnnotationTarget.FUNCTION, AnnotationTarget.PROPERTY_GETTER, AnnotationTarget.PROPERTY_SETTER) diff --git a/stone_multiplatform/src/commonMain/kotlin/stone/annotations/component/GcStrongScope.kt b/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/annotations/component/GcStrongScope.kt similarity index 75% rename from stone_multiplatform/src/commonMain/kotlin/stone/annotations/component/GcStrongScope.kt rename to stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/annotations/component/GcStrongScope.kt index 04871c45..feb349a3 100644 --- a/stone_multiplatform/src/commonMain/kotlin/stone/annotations/component/GcStrongScope.kt +++ b/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/annotations/component/GcStrongScope.kt @@ -1,4 +1,4 @@ -package stone.annotations.component +package com.github.klee0kai.stone.annotations.component import com.github.klee0kai.stone.weakref.Scope @@ -7,7 +7,7 @@ import com.github.klee0kai.stone.weakref.Scope * A standard library scope that enumerates all cacheable objects using strong references. * Used for garbage collection and caching change methods. */ -@GcScopeAnnotation +@com.github.klee0kai.stone.annotations.component.GcScopeAnnotation @Scope @Retention(AnnotationRetention.BINARY) @Target(AnnotationTarget.FUNCTION, AnnotationTarget.PROPERTY_GETTER, AnnotationTarget.PROPERTY_SETTER) diff --git a/stone_multiplatform/src/commonMain/kotlin/stone/annotations/component/GcWeakScope.kt b/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/annotations/component/GcWeakScope.kt similarity index 75% rename from stone_multiplatform/src/commonMain/kotlin/stone/annotations/component/GcWeakScope.kt rename to stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/annotations/component/GcWeakScope.kt index a06f8f2b..82cd3cb5 100644 --- a/stone_multiplatform/src/commonMain/kotlin/stone/annotations/component/GcWeakScope.kt +++ b/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/annotations/component/GcWeakScope.kt @@ -1,4 +1,4 @@ -package stone.annotations.component +package com.github.klee0kai.stone.annotations.component import com.github.klee0kai.stone.weakref.Scope @@ -7,7 +7,7 @@ import com.github.klee0kai.stone.weakref.Scope * A standard library scope that enumerates all cacheable objects using weak references. * Used for garbage collection and caching change methods. */ -@GcScopeAnnotation +@com.github.klee0kai.stone.annotations.component.GcScopeAnnotation @Scope @Retention(AnnotationRetention.BINARY) @Target(AnnotationTarget.FUNCTION, AnnotationTarget.PROPERTY_GETTER, AnnotationTarget.PROPERTY_SETTER) diff --git a/stone_multiplatform/src/commonMain/kotlin/stone/annotations/component/Init.kt b/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/annotations/component/Init.kt similarity index 92% rename from stone_multiplatform/src/commonMain/kotlin/stone/annotations/component/Init.kt rename to stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/annotations/component/Init.kt index f833430e..f3e0d55a 100644 --- a/stone_multiplatform/src/commonMain/kotlin/stone/annotations/component/Init.kt +++ b/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/annotations/component/Init.kt @@ -1,4 +1,4 @@ -package stone.annotations.component +package com.github.klee0kai.stone.annotations.component /** diff --git a/stone_multiplatform/src/commonMain/kotlin/stone/annotations/component/ModuleOriginFactory.kt b/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/annotations/component/ModuleOriginFactory.kt similarity index 90% rename from stone_multiplatform/src/commonMain/kotlin/stone/annotations/component/ModuleOriginFactory.kt rename to stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/annotations/component/ModuleOriginFactory.kt index 01be93db..02248c55 100644 --- a/stone_multiplatform/src/commonMain/kotlin/stone/annotations/component/ModuleOriginFactory.kt +++ b/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/annotations/component/ModuleOriginFactory.kt @@ -1,4 +1,4 @@ -package stone.annotations.component +package com.github.klee0kai.stone.annotations.component /** * Provide origin module's factory diff --git a/stone_multiplatform/src/commonMain/kotlin/stone/annotations/component/ProtectInjected.kt b/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/annotations/component/ProtectInjected.kt similarity index 93% rename from stone_multiplatform/src/commonMain/kotlin/stone/annotations/component/ProtectInjected.kt rename to stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/annotations/component/ProtectInjected.kt index 68e1c28b..b53b048c 100644 --- a/stone_multiplatform/src/commonMain/kotlin/stone/annotations/component/ProtectInjected.kt +++ b/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/annotations/component/ProtectInjected.kt @@ -1,4 +1,4 @@ -package stone.annotations.component +package com.github.klee0kai.stone.annotations.component /** * Protect provided objects from being destroyed by injection. diff --git a/stone_multiplatform/src/commonMain/kotlin/stone/annotations/component/RunGc.kt b/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/annotations/component/RunGc.kt similarity index 95% rename from stone_multiplatform/src/commonMain/kotlin/stone/annotations/component/RunGc.kt rename to stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/annotations/component/RunGc.kt index 34db1f65..1dbb8a79 100644 --- a/stone_multiplatform/src/commonMain/kotlin/stone/annotations/component/RunGc.kt +++ b/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/annotations/component/RunGc.kt @@ -1,4 +1,4 @@ -package stone.annotations.component +package com.github.klee0kai.stone.annotations.component /** diff --git a/stone_multiplatform/src/commonMain/kotlin/stone/annotations/component/SwitchCache.kt b/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/annotations/component/SwitchCache.kt similarity index 96% rename from stone_multiplatform/src/commonMain/kotlin/stone/annotations/component/SwitchCache.kt rename to stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/annotations/component/SwitchCache.kt index f202ea69..0cba3ec7 100644 --- a/stone_multiplatform/src/commonMain/kotlin/stone/annotations/component/SwitchCache.kt +++ b/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/annotations/component/SwitchCache.kt @@ -1,4 +1,4 @@ -package stone.annotations.component +package com.github.klee0kai.stone.annotations.component /** diff --git a/stone_multiplatform/src/commonMain/kotlin/stone/annotations/dependencies/Dependencies.kt b/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/annotations/dependencies/Dependencies.kt similarity index 95% rename from stone_multiplatform/src/commonMain/kotlin/stone/annotations/dependencies/Dependencies.kt rename to stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/annotations/dependencies/Dependencies.kt index 071bc323..049d2ea0 100644 --- a/stone_multiplatform/src/commonMain/kotlin/stone/annotations/dependencies/Dependencies.kt +++ b/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/annotations/dependencies/Dependencies.kt @@ -1,4 +1,4 @@ -package stone.annotations.dependencies +package com.github.klee0kai.stone.annotations.dependencies /** diff --git a/stone_multiplatform/src/commonMain/kotlin/stone/annotations/module/BindInstance.kt b/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/annotations/module/BindInstance.kt similarity index 97% rename from stone_multiplatform/src/commonMain/kotlin/stone/annotations/module/BindInstance.kt rename to stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/annotations/module/BindInstance.kt index dd148d5a..898ac693 100644 --- a/stone_multiplatform/src/commonMain/kotlin/stone/annotations/module/BindInstance.kt +++ b/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/annotations/module/BindInstance.kt @@ -1,4 +1,4 @@ -package stone.annotations.module +package com.github.klee0kai.stone.annotations.module /** diff --git a/stone_multiplatform/src/commonMain/kotlin/stone/annotations/module/Module.kt b/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/annotations/module/Module.kt similarity index 97% rename from stone_multiplatform/src/commonMain/kotlin/stone/annotations/module/Module.kt rename to stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/annotations/module/Module.kt index 2043188f..91c0b934 100644 --- a/stone_multiplatform/src/commonMain/kotlin/stone/annotations/module/Module.kt +++ b/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/annotations/module/Module.kt @@ -1,4 +1,4 @@ -package stone.annotations.module +package com.github.klee0kai.stone.annotations.module /** diff --git a/stone_multiplatform/src/commonMain/kotlin/stone/annotations/module/Provide.kt b/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/annotations/module/Provide.kt similarity index 96% rename from stone_multiplatform/src/commonMain/kotlin/stone/annotations/module/Provide.kt rename to stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/annotations/module/Provide.kt index 9d9cde98..8f9c65e2 100644 --- a/stone_multiplatform/src/commonMain/kotlin/stone/annotations/module/Provide.kt +++ b/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/annotations/module/Provide.kt @@ -1,4 +1,4 @@ -package stone.annotations.module +package com.github.klee0kai.stone.annotations.module /** * Providing objects. diff --git a/stone_multiplatform/src/commonMain/kotlin/stone/annotations/wrappers/WrappersCreator.kt b/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/annotations/wrappers/WrappersCreator.kt similarity index 88% rename from stone_multiplatform/src/commonMain/kotlin/stone/annotations/wrappers/WrappersCreator.kt rename to stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/annotations/wrappers/WrappersCreator.kt index 96397592..612ff828 100644 --- a/stone_multiplatform/src/commonMain/kotlin/stone/annotations/wrappers/WrappersCreator.kt +++ b/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/annotations/wrappers/WrappersCreator.kt @@ -1,4 +1,4 @@ -package stone.annotations.wrappers +package com.github.klee0kai.stone.annotations.wrappers import kotlin.reflect.KClass diff --git a/stone_multiplatform/src/commonMain/kotlin/stone/lifecycle/StoneLifeCycleListener.kt b/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/lifecycle/StoneLifeCycleListener.kt similarity index 65% rename from stone_multiplatform/src/commonMain/kotlin/stone/lifecycle/StoneLifeCycleListener.kt rename to stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/lifecycle/StoneLifeCycleListener.kt index 7085fcec..2acd3cf0 100644 --- a/stone_multiplatform/src/commonMain/kotlin/stone/lifecycle/StoneLifeCycleListener.kt +++ b/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/lifecycle/StoneLifeCycleListener.kt @@ -1,4 +1,4 @@ -package stone.lifecycle +package com.github.klee0kai.stone.lifecycle interface StoneLifeCycleListener { diff --git a/stone_multiplatform/src/commonMain/kotlin/stone/lifecycle/StoneLifeCycleOwner.kt b/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/lifecycle/StoneLifeCycleOwner.kt similarity index 94% rename from stone_multiplatform/src/commonMain/kotlin/stone/lifecycle/StoneLifeCycleOwner.kt rename to stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/lifecycle/StoneLifeCycleOwner.kt index 383fa845..dbd443c3 100644 --- a/stone_multiplatform/src/commonMain/kotlin/stone/lifecycle/StoneLifeCycleOwner.kt +++ b/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/lifecycle/StoneLifeCycleOwner.kt @@ -1,4 +1,4 @@ -package stone.lifecycle +package com.github.klee0kai.stone.lifecycle /** * Objects in an application can have a life cycle. @@ -51,6 +51,6 @@ package stone.lifecycle */ interface StoneLifeCycleOwner { - fun subscribe(listener: stone.lifecycle.StoneLifeCycleListener?) + fun subscribe(listener: StoneLifeCycleListener?) } diff --git a/stone_multiplatform/src/commonMain/kotlin/stone/wrappers/AsyncCoroutineProvide.kt b/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/wrappers/AsyncCoroutineProvide.kt similarity index 92% rename from stone_multiplatform/src/commonMain/kotlin/stone/wrappers/AsyncCoroutineProvide.kt rename to stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/wrappers/AsyncCoroutineProvide.kt index 047d1ba3..a9d01053 100644 --- a/stone_multiplatform/src/commonMain/kotlin/stone/wrappers/AsyncCoroutineProvide.kt +++ b/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/wrappers/AsyncCoroutineProvide.kt @@ -1,4 +1,4 @@ -package stone.wrappers +package com.github.klee0kai.stone.wrappers import kotlinx.coroutines.DelicateCoroutinesApi import kotlinx.coroutines.Dispatchers diff --git a/stone_multiplatform/src/commonMain/kotlin/stone/wrappers/LazyProvide.kt b/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/wrappers/LazyProvide.kt similarity index 91% rename from stone_multiplatform/src/commonMain/kotlin/stone/wrappers/LazyProvide.kt rename to stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/wrappers/LazyProvide.kt index 3f273d70..85785ede 100644 --- a/stone_multiplatform/src/commonMain/kotlin/stone/wrappers/LazyProvide.kt +++ b/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/wrappers/LazyProvide.kt @@ -1,4 +1,4 @@ -package stone.wrappers +package com.github.klee0kai.stone.wrappers /** * Providing an object with lazy providing. diff --git a/stone_multiplatform/src/commonMain/kotlin/stone/wrappers/PhantomProvide.kt b/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/wrappers/PhantomProvide.kt similarity index 93% rename from stone_multiplatform/src/commonMain/kotlin/stone/wrappers/PhantomProvide.kt rename to stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/wrappers/PhantomProvide.kt index a223eb0e..5c0a9892 100644 --- a/stone_multiplatform/src/commonMain/kotlin/stone/wrappers/PhantomProvide.kt +++ b/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/wrappers/PhantomProvide.kt @@ -1,4 +1,4 @@ -package stone.wrappers +package com.github.klee0kai.stone.wrappers /** * Providing an object without any deduction. diff --git a/stone_multiplatform/src/commonMain/kotlin/stone/wrappers/Ref.kt b/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/wrappers/Ref.kt similarity index 73% rename from stone_multiplatform/src/commonMain/kotlin/stone/wrappers/Ref.kt rename to stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/wrappers/Ref.kt index 76ae086e..09a0c284 100644 --- a/stone_multiplatform/src/commonMain/kotlin/stone/wrappers/Ref.kt +++ b/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/wrappers/Ref.kt @@ -1,4 +1,4 @@ -package stone.wrappers +package com.github.klee0kai.stone.wrappers import com.github.klee0kai.stone.weakref.Provider diff --git a/stone_multiplatform/src/commonMain/kotlin/stone/wrappers/creators/CircleWrapper.kt b/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/wrappers/creators/CircleWrapper.kt similarity index 90% rename from stone_multiplatform/src/commonMain/kotlin/stone/wrappers/creators/CircleWrapper.kt rename to stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/wrappers/creators/CircleWrapper.kt index fc8d8bce..da1e0107 100644 --- a/stone_multiplatform/src/commonMain/kotlin/stone/wrappers/creators/CircleWrapper.kt +++ b/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/wrappers/creators/CircleWrapper.kt @@ -1,4 +1,4 @@ -package stone.wrappers.creators +package com.github.klee0kai.stone.wrappers.creators import kotlin.reflect.KClass diff --git a/stone_multiplatform/src/commonMain/kotlin/stone/wrappers/creators/ProviderWrapper.kt b/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/wrappers/creators/ProviderWrapper.kt similarity index 90% rename from stone_multiplatform/src/commonMain/kotlin/stone/wrappers/creators/ProviderWrapper.kt rename to stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/wrappers/creators/ProviderWrapper.kt index 93a1f5e8..7e58b9e6 100644 --- a/stone_multiplatform/src/commonMain/kotlin/stone/wrappers/creators/ProviderWrapper.kt +++ b/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/wrappers/creators/ProviderWrapper.kt @@ -1,4 +1,4 @@ -package stone.wrappers.creators +package com.github.klee0kai.stone.wrappers.creators import com.github.klee0kai.stone.weakref.Provider import kotlin.reflect.KClass diff --git a/stone_multiplatform/src/commonMain/kotlin/stone/wrappers/creators/Wrapper.kt b/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/wrappers/creators/Wrapper.kt similarity index 88% rename from stone_multiplatform/src/commonMain/kotlin/stone/wrappers/creators/Wrapper.kt rename to stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/wrappers/creators/Wrapper.kt index 876d9573..61ed7fe2 100644 --- a/stone_multiplatform/src/commonMain/kotlin/stone/wrappers/creators/Wrapper.kt +++ b/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/wrappers/creators/Wrapper.kt @@ -1,4 +1,4 @@ -package stone.wrappers.creators +package com.github.klee0kai.stone.wrappers.creators import kotlin.reflect.KClass diff --git a/tests_kotlin/build.gradle.kts b/tests_kotlin/build.gradle.kts index c1273ae8..8d1e60d2 100644 --- a/tests_kotlin/build.gradle.kts +++ b/tests_kotlin/build.gradle.kts @@ -1,6 +1,6 @@ plugins { alias(libs.plugins.kotlin.jvm) - alias(libs.plugins.kotlin.kapt) + alias(libs.plugins.kotlin.ksp) } tasks.test { @@ -8,10 +8,8 @@ tasks.test { } dependencies { - implementation(project(":tests")) - - implementation(project(":kotlin_lib")) - kapt(project(":stone_processor")) + implementation(project(":stone_multiplatform")) + ksp(project(":stone_ksp")) testImplementation(libs.bundles.junit) From d1c9801a1c2c9c171c96400bd110798786482bd5 Mon Sep 17 00:00:00 2001 From: klee0kai Date: Mon, 10 Nov 2025 00:05:27 +0100 Subject: [PATCH 018/122] ksp tests --- libs.versions.toml | 4 ++-- plugin_publish/build.gradle.kts | 1 - settings.gradle.kts | 2 +- .../stone/ksp/target/ModuleFactoryProcessor.kt | 13 ++++++------- stone_lib/build.gradle.kts | 4 ++-- stone_processor/build.gradle.kts | 4 ++-- 6 files changed, 13 insertions(+), 15 deletions(-) diff --git a/libs.versions.toml b/libs.versions.toml index df82c017..0410f2d4 100644 --- a/libs.versions.toml +++ b/libs.versions.toml @@ -2,8 +2,8 @@ stone = "1.0.7" -kotlin = "2.2.21" -ksp = "2.2.21-2.0.4" +kotlin = "2.1.20" +ksp = "2.1.20-1.0.31" agp = "8.12.3" appcompat = "1.7.1" diff --git a/plugin_publish/build.gradle.kts b/plugin_publish/build.gradle.kts index a884f458..db3880da 100644 --- a/plugin_publish/build.gradle.kts +++ b/plugin_publish/build.gradle.kts @@ -1,6 +1,5 @@ plugins { `kotlin-dsl` -// alias(libs.plugins.kotlin.dsl) `java-gradle-plugin` } diff --git a/settings.gradle.kts b/settings.gradle.kts index 14765687..5ff52cbd 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -19,7 +19,7 @@ dependencyResolutionManagement { } rootProject.name = "Stone" -includeBuild("plugin_publish") +//includeBuild("plugin_publish") include("weakref_multiplatform") include("inject_multiplatform") include(":stone_lib") diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/ModuleFactoryProcessor.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/ModuleFactoryProcessor.kt index bbbd56a1..1ec3af5f 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/ModuleFactoryProcessor.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/ModuleFactoryProcessor.kt @@ -42,9 +42,8 @@ class ModuleFactoryProcessor : TargetFileProcessor { val fileOwner = validSymbol.containingFile ?: return null val classDeclaration = validSymbol as? KSClassDeclaration ?: return null - val moduleInterfaceInterfaceAnn = - classDeclaration.getAnnotationsByType(Module::class) - .firstOrNull() ?: return null + val moduleAnn = classDeclaration.getAnnotationsByType(Module::class) + .firstOrNull() ?: return null val genClassName = ClassName( fileOwner.packageName.asString().stonePackageName, @@ -56,17 +55,17 @@ class ModuleFactoryProcessor : TargetFileProcessor { genClass(genClassName) { validSymbol.getAllFunctions().forEach { function -> - if (!function.isAbstract) return@genClass +// if (!function.isAbstract) return@genClass val returnType = function.returnType?.resolve()?.toClassName() ?: return@genClass - val moduleInterfaceInterfaceAnn = function.getAnnotationsByType(BindInstance::class) - .firstOrNull() ?: return@genClass + val bindInstanceAnn = function.getAnnotationsByType(BindInstance::class) + .firstOrNull() genFun(function.simpleName.asString()) { declareSameParameters(function) returns(returnType) if (function.isSuspend) addModifiers(KModifier.SUSPEND) - if (moduleInterfaceInterfaceAnn != null) { + if (bindInstanceAnn != null) { addStatement("return null") } else { diff --git a/stone_lib/build.gradle.kts b/stone_lib/build.gradle.kts index 92cb002c..d6f22d23 100644 --- a/stone_lib/build.gradle.kts +++ b/stone_lib/build.gradle.kts @@ -1,7 +1,7 @@ plugins { `java-library` - alias(libs.plugins.publish.maven) - alias(libs.plugins.publish.stone) +// alias(libs.plugins.publish.maven) +// alias(libs.plugins.publish.stone) } group = "com.github.klee0kai.stone" diff --git a/stone_processor/build.gradle.kts b/stone_processor/build.gradle.kts index 1381dd21..8401a6ee 100644 --- a/stone_processor/build.gradle.kts +++ b/stone_processor/build.gradle.kts @@ -1,7 +1,7 @@ plugins { `java-library` - alias(libs.plugins.publish.maven) - alias(libs.plugins.publish.stone) +// alias(libs.plugins.publish.maven) +// alias(libs.plugins.publish.stone) } group = "com.github.klee0kai.stone" From 6c15b2ba88b019c028d4f5829d1fa9b1202f7b78 Mon Sep 17 00:00:00 2001 From: klee0kai Date: Mon, 10 Nov 2025 08:39:25 +0100 Subject: [PATCH 019/122] disable multithread --- libs.versions.toml | 4 ++-- .../kotlin/com/github/klee0kai/thekey/stone/ksp/Processor.kt | 5 ++++- .../thekey/stone/ksp/target/ModuleFactoryProcessor.kt | 2 +- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/libs.versions.toml b/libs.versions.toml index 0410f2d4..c747ced5 100644 --- a/libs.versions.toml +++ b/libs.versions.toml @@ -2,8 +2,8 @@ stone = "1.0.7" -kotlin = "2.1.20" -ksp = "2.1.20-1.0.31" +kotlin = "2.2.21" +ksp = "2.3.2" agp = "8.12.3" appcompat = "1.7.1" diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/Processor.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/Processor.kt index 53e8fe3e..33d43e36 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/Processor.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/Processor.kt @@ -35,13 +35,16 @@ class Processor( val ONE_RUN_SYMBOLS_COUNT = max(Runtime.getRuntime().availableProcessors(), 4) } + private val multithread = options["multithread"]?.toBoolean() ?: false + + val dispatcher by lazy { if (multithread) Dispatchers.Default else Dispatchers.Unconfined } val targetProcessors = arrayOf( ModuleFactoryProcessor(), ) override fun process( resolver: Resolver - ): List = runBlocking(Dispatchers.Default) { + ): List = runBlocking(dispatcher) { val processSymbolsCounter = AtomicInteger(0) val findSymbolsMutex = Mutex() diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/ModuleFactoryProcessor.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/ModuleFactoryProcessor.kt index 1ec3af5f..1facac10 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/ModuleFactoryProcessor.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/ModuleFactoryProcessor.kt @@ -55,7 +55,7 @@ class ModuleFactoryProcessor : TargetFileProcessor { genClass(genClassName) { validSymbol.getAllFunctions().forEach { function -> -// if (!function.isAbstract) return@genClass + if (!function.isAbstract) return@genClass val returnType = function.returnType?.resolve()?.toClassName() ?: return@genClass val bindInstanceAnn = function.getAnnotationsByType(BindInstance::class) .firstOrNull() From 66f757e8cae8194c9002ea13bc307065274f4416 Mon Sep 17 00:00:00 2001 From: klee0kai Date: Thu, 13 Nov 2025 00:29:17 +0100 Subject: [PATCH 020/122] module factory generator --- .../klee0kai/thekey/stone/ksp/Processor.kt | 10 +-- .../stone/ksp/ksp/KSClassDeclarationExt.kt | 55 ++++++++++++ .../stone/ksp/ksp/KSFunctionDeclarationExt.kt | 20 +++++ .../stone/ksp/ksp/{ => arch}/GenSpec.kt | 2 +- .../ksp/ksp/{ => arch}/SymbolsToProcess.kt | 3 +- .../ksp/ksp/{ => arch}/TargetFileProcessor.kt | 2 +- .../ksp/target/ModuleFactoryProcessor.kt | 89 +++++++++++++------ .../stone/ksp/target/StoneFileNamesExt.kt | 13 +++ .../thekey/stone/ksp/utils/CollectionExt.kt | 15 ++++ 9 files changed, 174 insertions(+), 35 deletions(-) create mode 100644 stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/ksp/KSClassDeclarationExt.kt create mode 100644 stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/ksp/KSFunctionDeclarationExt.kt rename stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/ksp/{ => arch}/GenSpec.kt (77%) rename stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/ksp/{ => arch}/SymbolsToProcess.kt (94%) rename stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/ksp/{ => arch}/TargetFileProcessor.kt (89%) create mode 100644 stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/StoneFileNamesExt.kt create mode 100644 stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/utils/CollectionExt.kt diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/Processor.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/Processor.kt index 33d43e36..c673ee0e 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/Processor.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/Processor.kt @@ -1,10 +1,10 @@ package com.github.klee0kai.thekey.stone.ksp import com.github.klee0kai.thekey.stone.ksp.coroutines.LaunchConductor -import com.github.klee0kai.thekey.stone.ksp.ksp.GenSpec -import com.github.klee0kai.thekey.stone.ksp.ksp.TargetFileProcessor -import com.github.klee0kai.thekey.stone.ksp.ksp.forceProcess -import com.github.klee0kai.thekey.stone.ksp.ksp.takeOnly +import com.github.klee0kai.thekey.stone.ksp.ksp.arch.GenSpec +import com.github.klee0kai.thekey.stone.ksp.ksp.arch.TargetFileProcessor +import com.github.klee0kai.thekey.stone.ksp.ksp.arch.forceProcess +import com.github.klee0kai.thekey.stone.ksp.ksp.arch.takeOnly import com.github.klee0kai.thekey.stone.ksp.target.ModuleFactoryProcessor import com.google.devtools.ksp.processing.CodeGenerator import com.google.devtools.ksp.processing.KSPLogger @@ -69,7 +69,7 @@ class Processor( takeSymbolsCount = max(takeSymbolsCount, 0) totalCount + takeSymbolsCount } - symbols = symbols.takeOnly(takeSymbolsCount) +// symbols = symbols.takeOnly(takeSymbolsCount) globalSymbolsForProcessing.addAll(symbols.symbolsForProcessing) symbols } diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/ksp/KSClassDeclarationExt.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/ksp/KSClassDeclarationExt.kt new file mode 100644 index 00000000..1a252a26 --- /dev/null +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/ksp/KSClassDeclarationExt.kt @@ -0,0 +1,55 @@ +package com.github.klee0kai.thekey.stone.ksp.ksp + +import com.github.klee0kai.thekey.stone.ksp.utils.removeDoubles +import com.google.devtools.ksp.getAllSuperTypes +import com.google.devtools.ksp.getDeclaredFunctions +import com.google.devtools.ksp.symbol.KSClassDeclaration +import com.google.devtools.ksp.symbol.KSFunctionDeclaration +import com.google.devtools.ksp.symbol.KSValueParameter + + +fun KSClassDeclaration.findConstructor( + parameters: List, +): KSFunctionDeclaration? = getDeclaredFunctions().firstOrNull { function -> + function.simpleName.asString() == "" + && parameters.map { it.type } == function.parameters.map { it.type } +} + + +fun KSClassDeclaration.getAllMethods( + includeObjectMethods: Boolean = false, + allowDoubles: Boolean = false, + vararg exceptNames: String = emptyArray(), +): Sequence = sequence { + val cl = this@getAllMethods + if (!includeObjectMethods && cl.qualifiedName?.asString() in listOf( + Object::class.qualifiedName, + Any::class.qualifiedName + ) + ) { + return@sequence + } + + val allMethods = mutableListOf() + getAllSuperTypes().forEach { superType -> + allMethods.addAll( + (superType.declaration as KSClassDeclaration) + .getAllMethods( + includeObjectMethods = includeObjectMethods, + allowDoubles = allowDoubles, + exceptNames = exceptNames, + ) + ) + } + allMethods.addAll(getDeclaredFunctions()) + + yieldAll( + allMethods + .filter { + it.simpleName.asString() !in exceptNames + } + .removeDoubles { it1, it2 -> + it1.isSameMethods(it2) + } + ) +} \ No newline at end of file diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/ksp/KSFunctionDeclarationExt.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/ksp/KSFunctionDeclarationExt.kt new file mode 100644 index 00000000..eb128f96 --- /dev/null +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/ksp/KSFunctionDeclarationExt.kt @@ -0,0 +1,20 @@ +package com.github.klee0kai.thekey.stone.ksp.ksp + +import com.google.devtools.ksp.symbol.KSFunctionDeclaration + +fun KSFunctionDeclaration.isSameMethods( + other: KSFunctionDeclaration, +): Boolean { + if (simpleName != other.simpleName + || parameters.size != other.parameters.size + ) { + return false + } + for (idx in parameters.indices) { + if (parameters[idx].type != other.parameters[idx].type) { + return false + } + } + + return true +} \ No newline at end of file diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/ksp/GenSpec.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/ksp/arch/GenSpec.kt similarity index 77% rename from stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/ksp/GenSpec.kt rename to stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/ksp/arch/GenSpec.kt index fe6cccfd..159da457 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/ksp/GenSpec.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/ksp/arch/GenSpec.kt @@ -1,4 +1,4 @@ -package com.github.klee0kai.thekey.stone.ksp.ksp +package com.github.klee0kai.thekey.stone.ksp.ksp.arch import com.google.devtools.ksp.processing.Dependencies import com.squareup.kotlinpoet.FileSpec diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/ksp/SymbolsToProcess.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/ksp/arch/SymbolsToProcess.kt similarity index 94% rename from stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/ksp/SymbolsToProcess.kt rename to stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/ksp/arch/SymbolsToProcess.kt index 6f02b800..98c80f45 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/ksp/SymbolsToProcess.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/ksp/arch/SymbolsToProcess.kt @@ -1,4 +1,4 @@ -package com.github.klee0kai.thekey.stone.ksp.ksp +package com.github.klee0kai.thekey.stone.ksp.ksp.arch import com.google.devtools.ksp.symbol.KSAnnotated @@ -16,7 +16,6 @@ fun SymbolsToProcess.takeOnly( ) } - fun SymbolsToProcess.forceProcess( filter: (KSAnnotated) -> Boolean = { false }, ): SymbolsToProcess { diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/ksp/TargetFileProcessor.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/ksp/arch/TargetFileProcessor.kt similarity index 89% rename from stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/ksp/TargetFileProcessor.kt rename to stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/ksp/arch/TargetFileProcessor.kt index 0df30f38..a200b8be 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/ksp/TargetFileProcessor.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/ksp/arch/TargetFileProcessor.kt @@ -1,4 +1,4 @@ -package com.github.klee0kai.thekey.stone.ksp.ksp +package com.github.klee0kai.thekey.stone.ksp.ksp.arch import com.google.devtools.ksp.processing.KSPLogger import com.google.devtools.ksp.processing.Resolver diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/ModuleFactoryProcessor.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/ModuleFactoryProcessor.kt index 1facac10..d5d075e2 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/ModuleFactoryProcessor.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/ModuleFactoryProcessor.kt @@ -4,18 +4,23 @@ package com.github.klee0kai.thekey.stone.ksp.target import com.github.klee0kai.stone.annotations.module.BindInstance import com.github.klee0kai.stone.annotations.module.Module -import com.github.klee0kai.thekey.stone.ksp.ksp.GenSpec -import com.github.klee0kai.thekey.stone.ksp.ksp.SymbolsToProcess -import com.github.klee0kai.thekey.stone.ksp.ksp.TargetFileProcessor +import com.github.klee0kai.thekey.stone.ksp.ksp.arch.GenSpec +import com.github.klee0kai.thekey.stone.ksp.ksp.arch.SymbolsToProcess +import com.github.klee0kai.thekey.stone.ksp.ksp.arch.TargetFileProcessor +import com.github.klee0kai.thekey.stone.ksp.ksp.findConstructor +import com.github.klee0kai.thekey.stone.ksp.ksp.getAllMethods import com.github.klee0kai.thekey.stone.ksp.poet.* import com.google.devtools.ksp.KspExperimental import com.google.devtools.ksp.containingFile import com.google.devtools.ksp.getAnnotationsByType +import com.google.devtools.ksp.isAbstract import com.google.devtools.ksp.processing.Dependencies import com.google.devtools.ksp.processing.KSPLogger import com.google.devtools.ksp.processing.Resolver +import com.google.devtools.ksp.symbol.ClassKind import com.google.devtools.ksp.symbol.KSAnnotated import com.google.devtools.ksp.symbol.KSClassDeclaration +import com.google.devtools.ksp.symbol.Modifier import com.squareup.kotlinpoet.ClassName import com.squareup.kotlinpoet.KModifier import com.squareup.kotlinpoet.asClassName @@ -28,6 +33,7 @@ class ModuleFactoryProcessor : TargetFileProcessor { ) = SymbolsToProcess( symbolsForProcessing = resolver .getSymbolsWithAnnotation(Module::class.asClassName().canonicalName) + .take(2) .toList(), symbolsForReprocessing = emptyList(), ) @@ -40,45 +46,76 @@ class ModuleFactoryProcessor : TargetFileProcessor { ): GenSpec? { val fileOwner = validSymbol.containingFile ?: return null - val classDeclaration = validSymbol as? KSClassDeclaration ?: return null + val moduleCl = validSymbol as? KSClassDeclaration ?: return null - val moduleAnn = classDeclaration.getAnnotationsByType(Module::class) + if (!moduleCl.isAbstract()) { + // factory not needed + return null + } + + val moduleAnn = moduleCl.getAnnotationsByType(Module::class) .firstOrNull() ?: return null val genClassName = ClassName( fileOwner.packageName.asString().stonePackageName, - "I${classDeclaration.simpleName.getShortName()}" + moduleCl.simpleName.getShortName().factoryClName, ) val fileSpec = genFileSpec(genClassName.packageName, genClassName.simpleName) { genLibComment() genClass(genClassName) { - validSymbol.getAllFunctions().forEach { function -> - if (!function.isAbstract) return@genClass - val returnType = function.returnType?.resolve()?.toClassName() ?: return@genClass - val bindInstanceAnn = function.getAnnotationsByType(BindInstance::class) - .firstOrNull() - - genFun(function.simpleName.asString()) { - declareSameParameters(function) - returns(returnType) - if (function.isSuspend) addModifiers(KModifier.SUSPEND) - - if (bindInstanceAnn != null) { - addStatement("return null") - } else { - + if (moduleCl.classKind == ClassKind.INTERFACE) { + addSuperinterface(moduleCl.toClassName()) + } else { + superclass(moduleCl.toClassName()) + } + addModifiers(KModifier.OPEN) + + + + validSymbol.getAllMethods(false, false, "") + .forEach { function -> + if (!function.modifiers.contains(Modifier.ABSTRACT) && moduleCl.classKind != ClassKind.INTERFACE) return@forEach + val returnCl = function.returnType?.resolve() + ?.declaration as? KSClassDeclaration ?: return@forEach + val bindInstanceAnn = function.getAnnotationsByType(BindInstance::class) + .firstOrNull() + + val constructorFun by lazy { returnCl.findConstructor(function.parameters) } + + genFun(function.simpleName.asString()) { + addModifiers(KModifier.OVERRIDE) + declareSameParameters(function) + returns(returnCl.toClassName()) + if (function.isSuspend) addModifiers(KModifier.SUSPEND) + + when { + bindInstanceAnn != null -> { + addStatement("return null") + } + + constructorFun != null -> { + addStatement( + "return %T( %L )", + returnCl.toClassName(), + function.parameters.joinToString(", ") { it.name?.asString() ?: "it" }, + ) + } + + else -> { + addStatement( + "return super.%L( %L )", + function.simpleName.asString(), + function.parameters.joinToString(", ") { it.name?.asString() ?: "it" }, + ) + } + } } } - - - } } } - - return GenSpec( fileSpec = fileSpec, // https://kotlinlang.org/docs/ksp-incremental.html diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/StoneFileNamesExt.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/StoneFileNamesExt.kt new file mode 100644 index 00000000..34eda160 --- /dev/null +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/StoneFileNamesExt.kt @@ -0,0 +1,13 @@ +package com.github.klee0kai.thekey.stone.ksp.target + +val String.componentClName: String get() = "${this}StoneComponent" + +val String.factoryClName: String get() = "${this}_FStone" + +val String.moduleClName: String get() = "${this}_MStone" + +val String.cacheControlClName: String get() = "${this}_CCMStone" + +val String.hiddenModuleClName: String get() = "${this}_HMStone" + +val String.wrapperClName: String get() = "${this}_TWStone" diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/utils/CollectionExt.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/utils/CollectionExt.kt new file mode 100644 index 00000000..bc7f7a68 --- /dev/null +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/utils/CollectionExt.kt @@ -0,0 +1,15 @@ +package com.github.klee0kai.thekey.stone.ksp.utils + +import java.util.* + + +fun List.removeDoubles( + compare: (T, T) -> Boolean, +): LinkedList { + val out = LinkedList() + for (item in this) { + val contains = out.any { compare.invoke(item, it) } + if (!contains) out.add(item) + } + return out +} \ No newline at end of file From 701601bd99df286018b4b75dd56b055695779862 Mon Sep 17 00:00:00 2001 From: klee0kai Date: Sat, 15 Nov 2025 22:26:19 +0100 Subject: [PATCH 021/122] module generator iter 1 --- .../klee0kai/thekey/stone/ksp/Processor.kt | 32 ++-- .../ksp/helpers/ComponentDeclarationExt.kt | 62 +++++++ .../stone/ksp/helpers/StoneFileNamesExt.kt | 55 ++++++ .../ksp/helpers/itemholder/ItemCacheType.kt | 53 ++++++ .../stone/ksp/ksp/KSClassDeclarationExt.kt | 7 +- .../stone/ksp/poet/smartcode/SmartCode.kt | 3 + ...cessor.kt => GenModuleFactoryProcessor.kt} | 27 ++- .../stone/ksp/target/GenModuleProcessor.kt | 158 ++++++++++++++++++ .../stone/ksp/target/StoneFileNamesExt.kt | 13 -- .../stone/__hidden__/types/MultiKey.kt | 28 ++++ .../stone/__hidden__/types/WeakList.kt | 47 ++++++ .../__hidden__/types/holders/StoneRefType.kt | 45 +++++ .../stone/wrappers/AsyncCoroutineProvide.kt | 1 + .../klee0kai/stone/wrappers/LazyProvide.kt | 2 + .../klee0kai/stone/wrappers/PhantomProvide.kt | 2 + .../com/github/klee0kai/stone/wrappers/Ref.kt | 10 -- .../ICompFactoryWrappersComponent.kt | 2 +- .../klee0kai/test_kotlin/mowgli/University.kt | 2 +- .../test_kotlin/mowgli/animal/Cougar.kt | 2 +- .../test_kotlin/mowgli/animal/Gorilla.kt | 2 +- .../identifiers/TechFactoryWrappersTests.kt | 2 +- .../MonitorFactoryWrappersTests.kt | 2 +- .../com/github/klee0kai/stone/weakref/Ref.kt | 7 + .../github/klee0kai/stone/weakref/SoftRef.kt | 9 + .../github/klee0kai/stone/weakref/WeakRef.kt | 4 +- .../github/klee0kai/stone/weakref/SoftRef.kt | 15 ++ .../github/klee0kai/stone/weakref/WeakRef.kt | 4 +- .../github/klee0kai/stone/weakref/SoftRef.kt | 18 ++ .../github/klee0kai/stone/weakref/WeakRef.kt | 4 +- .../github/klee0kai/stone/weakref/SoftRef.kt | 34 ++++ .../github/klee0kai/stone/weakref/WeakRef.kt | 4 +- 31 files changed, 590 insertions(+), 66 deletions(-) create mode 100644 stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/ComponentDeclarationExt.kt create mode 100644 stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/StoneFileNamesExt.kt create mode 100644 stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/itemholder/ItemCacheType.kt create mode 100644 stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/poet/smartcode/SmartCode.kt rename stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/{ModuleFactoryProcessor.kt => GenModuleFactoryProcessor.kt} (86%) create mode 100644 stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/GenModuleProcessor.kt delete mode 100644 stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/StoneFileNamesExt.kt create mode 100644 stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/__hidden__/types/MultiKey.kt create mode 100644 stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/__hidden__/types/WeakList.kt create mode 100644 stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/__hidden__/types/holders/StoneRefType.kt delete mode 100644 stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/wrappers/Ref.kt create mode 100644 weakref_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/weakref/Ref.kt create mode 100644 weakref_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/weakref/SoftRef.kt create mode 100644 weakref_multiplatform/src/jvmMain/kotlin/com/github/klee0kai/stone/weakref/SoftRef.kt create mode 100644 weakref_multiplatform/src/nativeMain/kotlin/com/github/klee0kai/stone/weakref/SoftRef.kt create mode 100644 weakref_multiplatform/src/webMain/kotlin/com/github/klee0kai/stone/weakref/SoftRef.kt diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/Processor.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/Processor.kt index c673ee0e..d7936e54 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/Processor.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/Processor.kt @@ -5,7 +5,8 @@ import com.github.klee0kai.thekey.stone.ksp.ksp.arch.GenSpec import com.github.klee0kai.thekey.stone.ksp.ksp.arch.TargetFileProcessor import com.github.klee0kai.thekey.stone.ksp.ksp.arch.forceProcess import com.github.klee0kai.thekey.stone.ksp.ksp.arch.takeOnly -import com.github.klee0kai.thekey.stone.ksp.target.ModuleFactoryProcessor +import com.github.klee0kai.thekey.stone.ksp.target.GenModuleFactoryProcessor +import com.github.klee0kai.thekey.stone.ksp.target.GenModuleProcessor import com.google.devtools.ksp.processing.CodeGenerator import com.google.devtools.ksp.processing.KSPLogger import com.google.devtools.ksp.processing.Resolver @@ -39,7 +40,8 @@ class Processor( val dispatcher by lazy { if (multithread) Dispatchers.Default else Dispatchers.Unconfined } val targetProcessors = arrayOf( - ModuleFactoryProcessor(), + GenModuleFactoryProcessor(), + GenModuleProcessor(), ) override fun process( @@ -59,17 +61,23 @@ class Processor( launch { var symbols = launchConductor.finishTogether { var symbols = findSymbolsMutex.withLock { processor.findSymbolsToProcess(resolver) } - var takeSymbolsCount = 0 - processSymbolsCounter.updateAndGet { totalCount -> - takeSymbolsCount = min( - symbols.symbolsForProcessing.size, - ONE_RUN_SYMBOLS_COUNT - totalCount - ) - - takeSymbolsCount = max(takeSymbolsCount, 0) - totalCount + takeSymbolsCount + + if (multithread) { + // skip to next ksp run + + var takeSymbolsCount = 0 + processSymbolsCounter.updateAndGet { totalCount -> + takeSymbolsCount = min( + symbols.symbolsForProcessing.size, + ONE_RUN_SYMBOLS_COUNT - totalCount + ) + + takeSymbolsCount = max(takeSymbolsCount, 0) + totalCount + takeSymbolsCount + } + symbols = symbols.takeOnly(takeSymbolsCount) } -// symbols = symbols.takeOnly(takeSymbolsCount) + globalSymbolsForProcessing.addAll(symbols.symbolsForProcessing) symbols } diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/ComponentDeclarationExt.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/ComponentDeclarationExt.kt new file mode 100644 index 00000000..958db450 --- /dev/null +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/ComponentDeclarationExt.kt @@ -0,0 +1,62 @@ +@file:OptIn(KspExperimental::class) + +package com.github.klee0kai.thekey.stone.ksp.helpers + +import com.github.klee0kai.stone.annotations.component.* +import com.github.klee0kai.thekey.stone.ksp.ksp.isType +import com.google.devtools.ksp.KspExperimental +import com.google.devtools.ksp.getAnnotationsByType +import com.google.devtools.ksp.processing.Resolver +import com.google.devtools.ksp.symbol.KSAnnotation +import com.google.devtools.ksp.symbol.KSClassDeclaration +import com.google.devtools.ksp.symbol.KSFunctionDeclaration +import com.google.devtools.ksp.symbol.KSTypeReference +import com.squareup.kotlinpoet.ClassName +import com.squareup.kotlinpoet.asClassName +import kotlin.reflect.KClass + +fun Resolver.findComponentForModuleOrDep( + moduleCl: ClassName, +): Sequence { + return getSymbolsWithAnnotation(Component::class.asClassName().canonicalName) + .filterIsInstance() + .filter { componentCl -> + componentCl.getAllFunctions().any { + it.returnType?.resolve()?.declaration?.isType(moduleCl) ?: false + } + } +} + + +val KSClassDeclaration.allIdentifierTypes: Sequence> + get() { + val componentCl = this@allIdentifierTypes as? KSTypeReference + val allParentsSequence = (sequenceOf(componentCl) + superTypes) + return allParentsSequence + .flatMap { it?.getAnnotationsByType(Component::class) ?: emptySequence() } + .flatMap { it.identifiers.asSequence() } + } + +val KSClassDeclaration.wrapperProviders: Sequence> + get() { + val componentCl = this@wrapperProviders as? KSTypeReference + val allParentsSequence = (sequenceOf(componentCl) + superTypes) + return allParentsSequence + .flatMap { it?.getAnnotationsByType(Component::class) ?: emptySequence() } + .flatMap { it.wrapperProviders.asSequence() } + } + +val KSFunctionDeclaration.scopeAnnotations: Sequence + get() { + val standardScopeAnnotations = listOf( + GcAllScope::class, GcWeakScope::class, + GcSoftScope::class, GcStrongScope::class + ) + + return annotations.filter { funAnnotation -> + standardScopeAnnotations.any { funAnnotation.annotationType.resolve().declaration.isType(it) } + || funAnnotation.annotationType.resolve().annotations.any { annotationOfAnnotation -> + annotationOfAnnotation.annotationType.resolve().declaration.isType(GcScopeAnnotation::class) + } + } + } \ No newline at end of file diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/StoneFileNamesExt.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/StoneFileNamesExt.kt new file mode 100644 index 00000000..0c904694 --- /dev/null +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/StoneFileNamesExt.kt @@ -0,0 +1,55 @@ +package com.github.klee0kai.thekey.stone.ksp.helpers + +import com.google.devtools.ksp.symbol.KSClassDeclaration +import com.squareup.kotlinpoet.ClassName + +val String.componentClName: String get() = "${this}StoneComponent" + +val String.factoryClName: String get() = "${this}_FStone" + +val String.moduleClName: String get() = "${this}_MStone" + +val String.cacheControlClName: String get() = "${this}_CCMStone" + +val String.hiddenModuleClName: String get() = "${this}_HMStone" + +val String.wrapperClName: String get() = "${this}_TWStone" + + +val KSClassDeclaration.componentStoneClName + get() = ClassName( + packageName.asString(), + simpleName.getShortName().componentClName, + ) + +val KSClassDeclaration.factoryStoneClName + get() = ClassName( + packageName.asString(), + simpleName.getShortName().factoryClName, + ) + +val KSClassDeclaration.moduleStoneClName + get() = ClassName( + packageName.asString(), + simpleName.getShortName().moduleClName, + ) + + +val KSClassDeclaration.cacheControlStoneClName + get() = ClassName( + packageName.asString(), + simpleName.getShortName().cacheControlClName, + ) + + +val KSClassDeclaration.hiddenModuleStoneClName + get() = ClassName( + packageName.asString(), + simpleName.getShortName().hiddenModuleClName, + ) + +val KSClassDeclaration.wrapperStoneClName + get() = ClassName( + packageName.asString(), + simpleName.getShortName().wrapperClName, + ) \ No newline at end of file diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/itemholder/ItemCacheType.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/itemholder/ItemCacheType.kt new file mode 100644 index 00000000..2d8246ba --- /dev/null +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/itemholder/ItemCacheType.kt @@ -0,0 +1,53 @@ +package com.github.klee0kai.thekey.stone.ksp.helpers.itemholder + +import com.github.klee0kai.stone.__hidden__.types.holders.StoneRefType +import com.github.klee0kai.stone.annotations.component.GcSoftScope +import com.github.klee0kai.stone.annotations.component.GcStrongScope +import com.github.klee0kai.stone.annotations.component.GcWeakScope +import com.github.klee0kai.stone.annotations.module.BindInstance +import com.github.klee0kai.stone.annotations.module.Provide +import kotlin.reflect.KClass + +enum class ItemCacheType { + Strong, Soft, Weak; + + val gcScopeClassName: KClass + get() = when (this) { + Weak -> GcWeakScope::class + Strong -> GcStrongScope::class + Soft -> GcSoftScope::class + } +} + +fun ItemCacheType.toRefTypeSingle( + +): StoneRefType? = when (this) { + ItemCacheType.Strong -> StoneRefType.StrongObject + ItemCacheType.Soft -> StoneRefType.SoftObject + ItemCacheType.Weak -> StoneRefType.WeakObject +} + +fun ItemCacheType.toRefTypeList( + +): StoneRefType? = when (this) { + ItemCacheType.Strong -> StoneRefType.ListObject + ItemCacheType.Soft -> StoneRefType.ListSoftObject + ItemCacheType.Weak -> StoneRefType.ListWeakObject +} + + +fun BindInstance.CacheType.toItemCacheType( +): ItemCacheType = when (this) { + BindInstance.CacheType.Weak -> ItemCacheType.Weak + BindInstance.CacheType.Soft -> ItemCacheType.Soft + BindInstance.CacheType.Strong -> ItemCacheType.Strong +} + +fun Provide.CacheType.toItemCacheType( +): ItemCacheType = when (this) { + Provide.CacheType.Factory -> TODO() + Provide.CacheType.Weak -> TODO() + Provide.CacheType.Soft -> TODO() + Provide.CacheType.Strong -> TODO() +} + diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/ksp/KSClassDeclarationExt.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/ksp/KSClassDeclarationExt.kt index 1a252a26..fb75899a 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/ksp/KSClassDeclarationExt.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/ksp/KSClassDeclarationExt.kt @@ -4,9 +4,11 @@ import com.github.klee0kai.thekey.stone.ksp.utils.removeDoubles import com.google.devtools.ksp.getAllSuperTypes import com.google.devtools.ksp.getDeclaredFunctions import com.google.devtools.ksp.symbol.KSClassDeclaration +import com.google.devtools.ksp.symbol.KSDeclaration import com.google.devtools.ksp.symbol.KSFunctionDeclaration import com.google.devtools.ksp.symbol.KSValueParameter - +import com.squareup.kotlinpoet.ClassName +import kotlin.reflect.KClass fun KSClassDeclaration.findConstructor( parameters: List, @@ -15,6 +17,9 @@ fun KSClassDeclaration.findConstructor( && parameters.map { it.type } == function.parameters.map { it.type } } +fun KSDeclaration.isType(cl: KClass<*>): Boolean = qualifiedName?.asString() == cl.qualifiedName.toString() + +fun KSDeclaration.isType(cl: ClassName): Boolean = qualifiedName?.asString() == cl.toString() fun KSClassDeclaration.getAllMethods( includeObjectMethods: Boolean = false, diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/poet/smartcode/SmartCode.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/poet/smartcode/SmartCode.kt new file mode 100644 index 00000000..f7b3e1f5 --- /dev/null +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/poet/smartcode/SmartCode.kt @@ -0,0 +1,3 @@ +package com.github.klee0kai.thekey.stone.ksp.poet.smartcode + +interface SmartCode diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/ModuleFactoryProcessor.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/GenModuleFactoryProcessor.kt similarity index 86% rename from stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/ModuleFactoryProcessor.kt rename to stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/GenModuleFactoryProcessor.kt index d5d075e2..804ad82f 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/ModuleFactoryProcessor.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/GenModuleFactoryProcessor.kt @@ -2,18 +2,22 @@ package com.github.klee0kai.thekey.stone.ksp.target +import com.github.klee0kai.stone.__hidden__.IModuleFactory import com.github.klee0kai.stone.annotations.module.BindInstance import com.github.klee0kai.stone.annotations.module.Module +import com.github.klee0kai.thekey.stone.ksp.helpers.factoryStoneClName import com.github.klee0kai.thekey.stone.ksp.ksp.arch.GenSpec import com.github.klee0kai.thekey.stone.ksp.ksp.arch.SymbolsToProcess import com.github.klee0kai.thekey.stone.ksp.ksp.arch.TargetFileProcessor import com.github.klee0kai.thekey.stone.ksp.ksp.findConstructor import com.github.klee0kai.thekey.stone.ksp.ksp.getAllMethods -import com.github.klee0kai.thekey.stone.ksp.poet.* +import com.github.klee0kai.thekey.stone.ksp.poet.genClass +import com.github.klee0kai.thekey.stone.ksp.poet.genFileSpec +import com.github.klee0kai.thekey.stone.ksp.poet.genFun +import com.github.klee0kai.thekey.stone.ksp.poet.genLibComment import com.google.devtools.ksp.KspExperimental import com.google.devtools.ksp.containingFile import com.google.devtools.ksp.getAnnotationsByType -import com.google.devtools.ksp.isAbstract import com.google.devtools.ksp.processing.Dependencies import com.google.devtools.ksp.processing.KSPLogger import com.google.devtools.ksp.processing.Resolver @@ -21,12 +25,11 @@ import com.google.devtools.ksp.symbol.ClassKind import com.google.devtools.ksp.symbol.KSAnnotated import com.google.devtools.ksp.symbol.KSClassDeclaration import com.google.devtools.ksp.symbol.Modifier -import com.squareup.kotlinpoet.ClassName import com.squareup.kotlinpoet.KModifier import com.squareup.kotlinpoet.asClassName import com.squareup.kotlinpoet.ksp.toClassName -class ModuleFactoryProcessor : TargetFileProcessor { +class GenModuleFactoryProcessor : TargetFileProcessor { override suspend fun findSymbolsToProcess( resolver: Resolver, @@ -48,32 +51,24 @@ class ModuleFactoryProcessor : TargetFileProcessor { val fileOwner = validSymbol.containingFile ?: return null val moduleCl = validSymbol as? KSClassDeclaration ?: return null - if (!moduleCl.isAbstract()) { - // factory not needed - return null - } - val moduleAnn = moduleCl.getAnnotationsByType(Module::class) .firstOrNull() ?: return null - val genClassName = ClassName( - fileOwner.packageName.asString().stonePackageName, - moduleCl.simpleName.getShortName().factoryClName, - ) + val genFactoryClassName = moduleCl.factoryStoneClName - val fileSpec = genFileSpec(genClassName.packageName, genClassName.simpleName) { + val fileSpec = genFileSpec(genFactoryClassName.packageName, fileName = genFactoryClassName.simpleName) { genLibComment() - genClass(genClassName) { + genClass(genFactoryClassName) { if (moduleCl.classKind == ClassKind.INTERFACE) { addSuperinterface(moduleCl.toClassName()) } else { superclass(moduleCl.toClassName()) } + addSuperinterface(IModuleFactory::class) addModifiers(KModifier.OPEN) - validSymbol.getAllMethods(false, false, "") .forEach { function -> if (!function.modifiers.contains(Modifier.ABSTRACT) && moduleCl.classKind != ClassKind.INTERFACE) return@forEach diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/GenModuleProcessor.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/GenModuleProcessor.kt new file mode 100644 index 00000000..ede46ec9 --- /dev/null +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/GenModuleProcessor.kt @@ -0,0 +1,158 @@ +@file:OptIn(KspExperimental::class) + +package com.github.klee0kai.thekey.stone.ksp.target + +import com.github.klee0kai.stone.__hidden__.IModule +import com.github.klee0kai.stone.annotations.module.BindInstance +import com.github.klee0kai.stone.annotations.module.Module +import com.github.klee0kai.stone.annotations.module.Provide +import com.github.klee0kai.thekey.stone.ksp.helpers.* +import com.github.klee0kai.thekey.stone.ksp.ksp.arch.GenSpec +import com.github.klee0kai.thekey.stone.ksp.ksp.arch.SymbolsToProcess +import com.github.klee0kai.thekey.stone.ksp.ksp.arch.TargetFileProcessor +import com.github.klee0kai.thekey.stone.ksp.ksp.getAllMethods +import com.github.klee0kai.thekey.stone.ksp.poet.* +import com.google.devtools.ksp.KspExperimental +import com.google.devtools.ksp.containingFile +import com.google.devtools.ksp.getAnnotationsByType +import com.google.devtools.ksp.processing.Dependencies +import com.google.devtools.ksp.processing.KSPLogger +import com.google.devtools.ksp.processing.Resolver +import com.google.devtools.ksp.symbol.ClassKind +import com.google.devtools.ksp.symbol.KSAnnotated +import com.google.devtools.ksp.symbol.KSClassDeclaration +import com.squareup.kotlinpoet.KModifier +import com.squareup.kotlinpoet.TypeSpec +import com.squareup.kotlinpoet.asClassName +import com.squareup.kotlinpoet.ksp.toClassName + +class GenModuleProcessor : TargetFileProcessor { + + companion object { + const val overridedModuleFieldName: String = "overridedModule" + const val factoryFieldName: String = "factory" + const val appliedLocalFieldName: String = "applied" + const val initMethodName: String = "__init" + const val initCachesFromMethodName: String = "__initCachesFrom" + const val updateBindInstancesFrom: String = "__updateBindInstancesFrom" + const val bindMethodName: String = "__bind" + const val getFactoryMethodName: String = "__getFactory" + const val switchRefMethodName: String = "__switchRef" + const val clearNullsMethodName: String = "__clearNulls" + } + + + override suspend fun findSymbolsToProcess( + resolver: Resolver, + ) = SymbolsToProcess( + symbolsForProcessing = resolver + .getSymbolsWithAnnotation(Module::class.asClassName().canonicalName) + .take(2) + .toList(), + symbolsForReprocessing = emptyList(), + ) + + override suspend fun process( + validSymbol: KSAnnotated, + resolver: Resolver, + options: Map, + logger: KSPLogger + ): GenSpec? { + val fileOwner = validSymbol.containingFile ?: return null + val moduleCl = validSymbol as? KSClassDeclaration ?: return null + + val moduleAnn = moduleCl.getAnnotationsByType(Module::class) + .firstOrNull() ?: return null + + val componentCl = resolver.findComponentForModuleOrDep(moduleCl.toClassName()) + .firstOrNull() + + val identifierTypes = componentCl?.allIdentifierTypes + val wrapperTypes = componentCl?.wrapperProviders + + val genModuleClassName = moduleCl.moduleStoneClName + + val fileSpec = genFileSpec(genModuleClassName.packageName, genModuleClassName.simpleName) { + genLibComment() + + genClass(genModuleClassName) { + if (moduleCl.classKind == ClassKind.INTERFACE) { + addSuperinterface(moduleCl.toClassName()) + } else { + superclass(moduleCl.toClassName()) + } + addSuperinterface(IModule::class) + addModifiers(KModifier.OPEN) + + + genProperty(factoryFieldName, moduleCl.toClassName()) { + addModifiers(KModifier.PRIVATE) + mutable(true) + initializer("%T()", moduleCl.factoryStoneClName) + } + + validSymbol.getAllMethods(false, false, "") + .forEachIndexed { funIdx, function -> + + val bindAnn = function.getAnnotationsByType(BindInstance::class).firstOrNull() + val provideAnn = function.getAnnotationsByType(Provide::class).firstOrNull() + + if (provideAnn != null) { + genProperty("${function.simpleName.asString()}${funIdx}", moduleCl.toClassName()) { + addModifiers(KModifier.OPEN) + mutable(true) + initializer("%T()", moduleCl.factoryStoneClName) + } + + + } + + + } + + + genIModelMethods(moduleCl) + } + } + + return GenSpec( + fileSpec = fileSpec, + // https://kotlinlang.org/docs/ksp-incremental.html + dependencies = Dependencies(aggregating = false, fileOwner), + ) + } + + private fun TypeSpec.Builder.genIModelMethods( + moduleCl: KSClassDeclaration, + ) { + genFun(initMethodName) { + + } + + genFun(initCachesFromMethodName) { + + } + + genFun(bindMethodName) { + + } + + genFun(getFactoryMethodName) { + + } + + genFun(switchRefMethodName) { + + } + + genFun(updateBindInstancesFrom) { + + } + + genFun(clearNullsMethodName) { + + } + + } + +} \ No newline at end of file diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/StoneFileNamesExt.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/StoneFileNamesExt.kt deleted file mode 100644 index 34eda160..00000000 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/StoneFileNamesExt.kt +++ /dev/null @@ -1,13 +0,0 @@ -package com.github.klee0kai.thekey.stone.ksp.target - -val String.componentClName: String get() = "${this}StoneComponent" - -val String.factoryClName: String get() = "${this}_FStone" - -val String.moduleClName: String get() = "${this}_MStone" - -val String.cacheControlClName: String get() = "${this}_CCMStone" - -val String.hiddenModuleClName: String get() = "${this}_HMStone" - -val String.wrapperClName: String get() = "${this}_TWStone" diff --git a/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/__hidden__/types/MultiKey.kt b/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/__hidden__/types/MultiKey.kt new file mode 100644 index 00000000..4377f439 --- /dev/null +++ b/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/__hidden__/types/MultiKey.kt @@ -0,0 +1,28 @@ +package com.github.klee0kai.stone.__hidden__.types + +/** + * Stone Private class + */ +class MultiKey(vararg subKeys: Any?) { + + private val subKeys = mutableListOf() + + init { + this.subKeys.addAll(subKeys) + } + + override fun equals(other: Any?): Boolean { + if (this === other) return true + if (other == null || this::class != other::class) return false + + other as MultiKey + + return subKeys == other.subKeys + } + + override fun hashCode(): Int { + return subKeys.hashCode() + } + + +} diff --git a/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/__hidden__/types/WeakList.kt b/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/__hidden__/types/WeakList.kt new file mode 100644 index 00000000..3be12ad4 --- /dev/null +++ b/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/__hidden__/types/WeakList.kt @@ -0,0 +1,47 @@ +package com.github.klee0kai.stone.__hidden__.types + + +import com.github.klee0kai.stone.weakref.Ref +import com.github.klee0kai.stone.weakref.WeakRef + +/** + * Stone Private class + */ +class WeakList { + private val list: MutableList?> = mutableListOf() + + val size get() = list.size + + val isEmpty: Boolean get() = list.isEmpty() + + fun add(it: T?): Boolean { + clearNulls() + return list.add(WeakRef(it)) + } + + fun add(idx: Int, it: T?) { + clearNulls() + list.add(idx, WeakRef(it)) + } + + fun remove(it: T?): Boolean { + return clearNulls(it) + } + + fun clear() { + list.clear() + } + + fun clearNulls( + ob: T? = null, + ) = list.removeAll { item -> item?.get() == null || item.get() == ob } + + + fun toList(): List { + clearNulls() + return list.mapNotNull { item -> item?.get() } + } + + fun get(idx: Int): T? = list[idx]?.get() + +} diff --git a/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/__hidden__/types/holders/StoneRefType.kt b/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/__hidden__/types/holders/StoneRefType.kt new file mode 100644 index 00000000..96dc758a --- /dev/null +++ b/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/__hidden__/types/holders/StoneRefType.kt @@ -0,0 +1,45 @@ +package com.github.klee0kai.stone.__hidden__.types.holders + +import com.github.klee0kai.stone.weakref.Ref +import com.github.klee0kai.stone.weakref.SoftRef +import com.github.klee0kai.stone.weakref.WeakRef + +enum class StoneRefType { + StrongObject, + WeakObject, + SoftObject, + ListObject, + ListWeakObject, + ListSoftObject; + + val isList: Boolean + get() = when (this) { + StrongObject, WeakObject, SoftObject -> false + ListObject, ListWeakObject, ListSoftObject -> true + } + + fun forList( + ): StoneRefType = when (this) { + StrongObject -> ListObject + WeakObject -> ListWeakObject + SoftObject -> ListSoftObject + else -> this + } + + + fun forSingle( + ): StoneRefType = when (this) { + ListObject -> StrongObject + ListWeakObject -> WeakObject + ListSoftObject -> SoftObject + else -> this + } + + fun formatter(): ((T) -> Ref)? { + when (this) { + WeakObject, ListWeakObject -> return { WeakRef(it) } + SoftObject, ListSoftObject -> return { SoftRef(it) } + else -> return null + } + } +} diff --git a/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/wrappers/AsyncCoroutineProvide.kt b/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/wrappers/AsyncCoroutineProvide.kt index a9d01053..d6939165 100644 --- a/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/wrappers/AsyncCoroutineProvide.kt +++ b/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/wrappers/AsyncCoroutineProvide.kt @@ -1,5 +1,6 @@ package com.github.klee0kai.stone.wrappers +import com.github.klee0kai.stone.weakref.Ref import kotlinx.coroutines.DelicateCoroutinesApi import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.GlobalScope diff --git a/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/wrappers/LazyProvide.kt b/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/wrappers/LazyProvide.kt index 85785ede..7497b250 100644 --- a/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/wrappers/LazyProvide.kt +++ b/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/wrappers/LazyProvide.kt @@ -1,5 +1,7 @@ package com.github.klee0kai.stone.wrappers +import com.github.klee0kai.stone.weakref.Ref + /** * Providing an object with lazy providing. * The object will be provided the first time it is used. diff --git a/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/wrappers/PhantomProvide.kt b/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/wrappers/PhantomProvide.kt index 5c0a9892..1695835a 100644 --- a/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/wrappers/PhantomProvide.kt +++ b/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/wrappers/PhantomProvide.kt @@ -1,5 +1,7 @@ package com.github.klee0kai.stone.wrappers +import com.github.klee0kai.stone.weakref.Ref + /** * Providing an object without any deduction. * Each time you use this object through a provider, diff --git a/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/wrappers/Ref.kt b/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/wrappers/Ref.kt deleted file mode 100644 index 09a0c284..00000000 --- a/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/wrappers/Ref.kt +++ /dev/null @@ -1,10 +0,0 @@ -package com.github.klee0kai.stone.wrappers - -import com.github.klee0kai.stone.weakref.Provider - -fun interface Ref : Provider { - - override fun get(): T - -} - diff --git a/tests_kotlin/src/main/kotlin/com/github/klee0kai/test_kotlin/di/compfactory/ICompFactoryWrappersComponent.kt b/tests_kotlin/src/main/kotlin/com/github/klee0kai/test_kotlin/di/compfactory/ICompFactoryWrappersComponent.kt index 5a0d8bea..f7e4fe4f 100644 --- a/tests_kotlin/src/main/kotlin/com/github/klee0kai/test_kotlin/di/compfactory/ICompFactoryWrappersComponent.kt +++ b/tests_kotlin/src/main/kotlin/com/github/klee0kai/test_kotlin/di/compfactory/ICompFactoryWrappersComponent.kt @@ -1,8 +1,8 @@ package com.github.klee0kai.test_kotlin.di.compfactory +import com.github.klee0kai.stone.weakref.Ref import com.github.klee0kai.stone.wrappers.LazyProvide import com.github.klee0kai.stone.wrappers.PhantomProvide -import com.github.klee0kai.stone.wrappers.Ref import com.github.klee0kai.test_kotlin.tech.components.Monitor import java.lang.ref.SoftReference import java.lang.ref.WeakReference diff --git a/tests_kotlin/src/main/kotlin/com/github/klee0kai/test_kotlin/mowgli/University.kt b/tests_kotlin/src/main/kotlin/com/github/klee0kai/test_kotlin/mowgli/University.kt index b0fdff4e..89e16301 100644 --- a/tests_kotlin/src/main/kotlin/com/github/klee0kai/test_kotlin/mowgli/University.kt +++ b/tests_kotlin/src/main/kotlin/com/github/klee0kai/test_kotlin/mowgli/University.kt @@ -1,8 +1,8 @@ package com.github.klee0kai.test_kotlin.mowgli +import com.github.klee0kai.stone.weakref.Ref import com.github.klee0kai.stone.wrappers.LazyProvide import com.github.klee0kai.stone.wrappers.PhantomProvide -import com.github.klee0kai.stone.wrappers.Ref import com.github.klee0kai.test.mowgli.community.History import com.github.klee0kai.test.mowgli.identity.Knowledge import javax.inject.Inject diff --git a/tests_kotlin/src/main/kotlin/com/github/klee0kai/test_kotlin/mowgli/animal/Cougar.kt b/tests_kotlin/src/main/kotlin/com/github/klee0kai/test_kotlin/mowgli/animal/Cougar.kt index 495ad393..0f87cb6c 100644 --- a/tests_kotlin/src/main/kotlin/com/github/klee0kai/test_kotlin/mowgli/animal/Cougar.kt +++ b/tests_kotlin/src/main/kotlin/com/github/klee0kai/test_kotlin/mowgli/animal/Cougar.kt @@ -1,8 +1,8 @@ package com.github.klee0kai.test_kotlin.mowgli.animal +import com.github.klee0kai.stone.weakref.Ref import com.github.klee0kai.stone.wrappers.LazyProvide import com.github.klee0kai.stone.wrappers.PhantomProvide -import com.github.klee0kai.stone.wrappers.Ref import com.github.klee0kai.test.mowgli.animal.IAnimal import com.github.klee0kai.test.mowgli.body.Blood import com.github.klee0kai.test.mowgli.community.History diff --git a/tests_kotlin/src/main/kotlin/com/github/klee0kai/test_kotlin/mowgli/animal/Gorilla.kt b/tests_kotlin/src/main/kotlin/com/github/klee0kai/test_kotlin/mowgli/animal/Gorilla.kt index 69b913b5..9f625c2c 100644 --- a/tests_kotlin/src/main/kotlin/com/github/klee0kai/test_kotlin/mowgli/animal/Gorilla.kt +++ b/tests_kotlin/src/main/kotlin/com/github/klee0kai/test_kotlin/mowgli/animal/Gorilla.kt @@ -1,8 +1,8 @@ package com.github.klee0kai.test_kotlin.mowgli.animal +import com.github.klee0kai.stone.weakref.Ref import com.github.klee0kai.stone.wrappers.LazyProvide import com.github.klee0kai.stone.wrappers.PhantomProvide -import com.github.klee0kai.stone.wrappers.Ref import com.github.klee0kai.test.mowgli.animal.IAnimal import com.github.klee0kai.test.mowgli.body.Blood import com.github.klee0kai.test.mowgli.community.History diff --git a/tests_kotlin/src/test/kotlin/com/github/klee0kai/tests/java_models/identifiers/TechFactoryWrappersTests.kt b/tests_kotlin/src/test/kotlin/com/github/klee0kai/tests/java_models/identifiers/TechFactoryWrappersTests.kt index b9005d8c..683c4fda 100644 --- a/tests_kotlin/src/test/kotlin/com/github/klee0kai/tests/java_models/identifiers/TechFactoryWrappersTests.kt +++ b/tests_kotlin/src/test/kotlin/com/github/klee0kai/tests/java_models/identifiers/TechFactoryWrappersTests.kt @@ -1,7 +1,7 @@ package com.github.klee0kai.tests.java_models.identifiers import com.github.klee0kai.stone.Stone -import com.github.klee0kai.stone.wrappers.Ref +import com.github.klee0kai.stone.weakref.Ref import com.github.klee0kai.test.di.techfactory.TechFactoryComponent import com.github.klee0kai.test.tech.components.Battery import org.junit.jupiter.api.Assertions.* diff --git a/tests_kotlin/src/test/kotlin/com/github/klee0kai/tests/kotlin_models/identifiers/MonitorFactoryWrappersTests.kt b/tests_kotlin/src/test/kotlin/com/github/klee0kai/tests/kotlin_models/identifiers/MonitorFactoryWrappersTests.kt index 51f3582d..ffc54609 100644 --- a/tests_kotlin/src/test/kotlin/com/github/klee0kai/tests/kotlin_models/identifiers/MonitorFactoryWrappersTests.kt +++ b/tests_kotlin/src/test/kotlin/com/github/klee0kai/tests/kotlin_models/identifiers/MonitorFactoryWrappersTests.kt @@ -2,7 +2,7 @@ package com.github.klee0kai.tests.kotlin_models.identifiers import com.github.klee0kai.stone.Stone import com.github.klee0kai.stone.type.wrappers.getValue -import com.github.klee0kai.stone.wrappers.Ref +import com.github.klee0kai.stone.weakref.Ref import com.github.klee0kai.test_kotlin.di.compfactory.CompFactoryComponent import com.github.klee0kai.test_kotlin.tech.components.Monitor import org.junit.jupiter.api.Assertions.* diff --git a/weakref_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/weakref/Ref.kt b/weakref_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/weakref/Ref.kt new file mode 100644 index 00000000..b11f1e9d --- /dev/null +++ b/weakref_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/weakref/Ref.kt @@ -0,0 +1,7 @@ +package com.github.klee0kai.stone.weakref + +fun interface Ref { + + fun get(): T + +} \ No newline at end of file diff --git a/weakref_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/weakref/SoftRef.kt b/weakref_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/weakref/SoftRef.kt new file mode 100644 index 00000000..0dd7d877 --- /dev/null +++ b/weakref_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/weakref/SoftRef.kt @@ -0,0 +1,9 @@ +package com.github.klee0kai.stone.weakref + +expect class SoftRef constructor(value: T) : Ref { + + override fun get(): T? + + fun clear() + +} \ No newline at end of file diff --git a/weakref_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/weakref/WeakRef.kt b/weakref_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/weakref/WeakRef.kt index 0893f2ca..76ebc039 100644 --- a/weakref_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/weakref/WeakRef.kt +++ b/weakref_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/weakref/WeakRef.kt @@ -1,8 +1,8 @@ package com.github.klee0kai.stone.weakref -expect class WeakRef constructor(value: T) { +expect class WeakRef constructor(value: T) : Ref { - fun get(): T? + override fun get(): T? fun clear() diff --git a/weakref_multiplatform/src/jvmMain/kotlin/com/github/klee0kai/stone/weakref/SoftRef.kt b/weakref_multiplatform/src/jvmMain/kotlin/com/github/klee0kai/stone/weakref/SoftRef.kt new file mode 100644 index 00000000..94f654de --- /dev/null +++ b/weakref_multiplatform/src/jvmMain/kotlin/com/github/klee0kai/stone/weakref/SoftRef.kt @@ -0,0 +1,15 @@ +package com.github.klee0kai.stone.weakref + +import java.lang.ref.SoftReference + +actual class SoftRef actual constructor(value: T) : Ref { + + val weakRef: SoftReference = SoftReference(value) + + actual override fun get(): T? = weakRef.get() + + actual fun clear() { + weakRef.clear() + } + +} \ No newline at end of file diff --git a/weakref_multiplatform/src/jvmMain/kotlin/com/github/klee0kai/stone/weakref/WeakRef.kt b/weakref_multiplatform/src/jvmMain/kotlin/com/github/klee0kai/stone/weakref/WeakRef.kt index d8094fac..d4cc44ec 100644 --- a/weakref_multiplatform/src/jvmMain/kotlin/com/github/klee0kai/stone/weakref/WeakRef.kt +++ b/weakref_multiplatform/src/jvmMain/kotlin/com/github/klee0kai/stone/weakref/WeakRef.kt @@ -2,11 +2,11 @@ package com.github.klee0kai.stone.weakref import java.lang.ref.WeakReference -actual class WeakRef actual constructor(value: T) { +actual class WeakRef actual constructor(value: T) : Ref { val weakRef: WeakReference = WeakReference(value) - actual fun get(): T? = weakRef.get() + actual override fun get(): T? = weakRef.get() actual fun clear() { weakRef.clear() diff --git a/weakref_multiplatform/src/nativeMain/kotlin/com/github/klee0kai/stone/weakref/SoftRef.kt b/weakref_multiplatform/src/nativeMain/kotlin/com/github/klee0kai/stone/weakref/SoftRef.kt new file mode 100644 index 00000000..0289aa8a --- /dev/null +++ b/weakref_multiplatform/src/nativeMain/kotlin/com/github/klee0kai/stone/weakref/SoftRef.kt @@ -0,0 +1,18 @@ +@file:OptIn(ExperimentalNativeApi::class) + +package com.github.klee0kai.stone.weakref + +import kotlin.experimental.ExperimentalNativeApi +import kotlin.native.ref.WeakReference + +actual class SoftRef actual constructor(value: T) : Ref { + + val weakRef: WeakReference? = value?.let { WeakReference(value) } + + actual override fun get(): T? = weakRef?.get() + + actual fun clear() { + weakRef?.clear() + } + +} \ No newline at end of file diff --git a/weakref_multiplatform/src/nativeMain/kotlin/com/github/klee0kai/stone/weakref/WeakRef.kt b/weakref_multiplatform/src/nativeMain/kotlin/com/github/klee0kai/stone/weakref/WeakRef.kt index ee0057b9..2ea53dde 100644 --- a/weakref_multiplatform/src/nativeMain/kotlin/com/github/klee0kai/stone/weakref/WeakRef.kt +++ b/weakref_multiplatform/src/nativeMain/kotlin/com/github/klee0kai/stone/weakref/WeakRef.kt @@ -5,11 +5,11 @@ package com.github.klee0kai.stone.weakref import kotlin.experimental.ExperimentalNativeApi import kotlin.native.ref.WeakReference -actual class WeakRef actual constructor(value: T) { +actual class WeakRef actual constructor(value: T) : Ref { val weakRef: WeakReference? = value?.let { WeakReference(value) } - actual fun get(): T? = weakRef?.get() + actual override fun get(): T? = weakRef?.get() actual fun clear() { weakRef?.clear() diff --git a/weakref_multiplatform/src/webMain/kotlin/com/github/klee0kai/stone/weakref/SoftRef.kt b/weakref_multiplatform/src/webMain/kotlin/com/github/klee0kai/stone/weakref/SoftRef.kt new file mode 100644 index 00000000..489fa9b9 --- /dev/null +++ b/weakref_multiplatform/src/webMain/kotlin/com/github/klee0kai/stone/weakref/SoftRef.kt @@ -0,0 +1,34 @@ +package com.github.klee0kai.stone.weakref + +actual class SoftRef actual constructor(value: T) : Ref { + + private var weakRefDynamic: dynamic = null + private var strongFallback: T? = null + + init { + val hasWeakRef = js("typeof WeakRef !== 'undefined'") as Boolean + if (hasWeakRef) { + weakRefDynamic = js("new WeakRef")(value) + strongFallback = null + } else { + weakRefDynamic = null + strongFallback = value + } + } + + + actual override fun get(): T? { + return if (weakRefDynamic != null) { + val derefResult = weakRefDynamic.deref?.invoke() + derefResult as T? + } else { + strongFallback + } + } + + actual fun clear() { + weakRefDynamic = null + strongFallback = null + } + +} \ No newline at end of file diff --git a/weakref_multiplatform/src/webMain/kotlin/com/github/klee0kai/stone/weakref/WeakRef.kt b/weakref_multiplatform/src/webMain/kotlin/com/github/klee0kai/stone/weakref/WeakRef.kt index a43f751f..8a541b58 100644 --- a/weakref_multiplatform/src/webMain/kotlin/com/github/klee0kai/stone/weakref/WeakRef.kt +++ b/weakref_multiplatform/src/webMain/kotlin/com/github/klee0kai/stone/weakref/WeakRef.kt @@ -1,6 +1,6 @@ package com.github.klee0kai.stone.weakref -actual class WeakRef actual constructor(value: T) { +actual class WeakRef actual constructor(value: T) : Ref { private var weakRefDynamic: dynamic = null private var strongFallback: T? = null @@ -17,7 +17,7 @@ actual class WeakRef actual constructor(value: T) { } - actual fun get(): T? { + actual override fun get(): T? { return if (weakRefDynamic != null) { val derefResult = weakRefDynamic.deref?.invoke() derefResult as T? From 32aa98dec073b9bbface02067bbb063b129f1cad Mon Sep 17 00:00:00 2001 From: klee0kai Date: Sun, 16 Nov 2025 10:12:00 +0100 Subject: [PATCH 022/122] smark code builder --- .../thekey/stone/ksp/poet/FileSpecDsl.kt | 15 ++--- .../klee0kai/thekey/stone/ksp/poet/PoetExt.kt | 2 + .../thekey/stone/ksp/poet/PropertySpecDsl.kt | 7 +-- .../thekey/stone/ksp/poet/TypeSpecDsl.kt | 17 +++-- .../ksp/poet/smartcode/CollectedSmartCode.kt | 43 +++++++++++++ .../ksp/poet/smartcode/SimpleCodeBuilder.kt | 12 ++++ .../stone/ksp/poet/smartcode/SmartCode.kt | 3 - .../stone/ksp/poet/smartcode/SmartCodeExt.kt | 63 +++++++++++++++++++ .../poet/smartcode/SmartCodeScopeBuilder.kt | 55 ++++++++++++++++ 9 files changed, 190 insertions(+), 27 deletions(-) create mode 100644 stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/poet/smartcode/CollectedSmartCode.kt create mode 100644 stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/poet/smartcode/SimpleCodeBuilder.kt delete mode 100644 stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/poet/smartcode/SmartCode.kt create mode 100644 stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/poet/smartcode/SmartCodeExt.kt create mode 100644 stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/poet/smartcode/SmartCodeScopeBuilder.kt diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/poet/FileSpecDsl.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/poet/FileSpecDsl.kt index 79500b37..bfcc3c7e 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/poet/FileSpecDsl.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/poet/FileSpecDsl.kt @@ -2,10 +2,7 @@ package com.github.klee0kai.thekey.stone.ksp.poet import com.squareup.kotlinpoet.* -@DslMarker -annotation class FileSpecDsl - -@FileSpecDsl +@PoetDsl fun genFileSpec( packageName: String, fileName: String, @@ -16,7 +13,7 @@ fun genFileSpec( .build() } -@FileSpecDsl +@PoetDsl fun FileSpec.Builder.genProperty( name: String, type: TypeName, @@ -30,7 +27,7 @@ fun FileSpec.Builder.genProperty( ) } -@FileSpecDsl +@PoetDsl fun FileSpec.Builder.genClass( className: ClassName, block: TypeSpec.Builder.() -> Unit = {}, @@ -43,7 +40,7 @@ fun FileSpec.Builder.genClass( } -@FileSpecDsl +@PoetDsl fun FileSpec.Builder.genObject( className: ClassName, block: TypeSpec.Builder.() -> Unit = {}, @@ -55,7 +52,7 @@ fun FileSpec.Builder.genObject( ) } -@FileSpecDsl +@PoetDsl fun FileSpec.Builder.genInterface( className: ClassName, block: TypeSpec.Builder.() -> Unit = {}, @@ -67,7 +64,7 @@ fun FileSpec.Builder.genInterface( ) } -@FileSpecDsl +@PoetDsl fun FileSpec.Builder.genFun( name: String, block: FunSpec.Builder.() -> Unit = {}, diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/poet/PoetExt.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/poet/PoetExt.kt index a4cd95da..02168db2 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/poet/PoetExt.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/poet/PoetExt.kt @@ -6,6 +6,8 @@ import com.squareup.kotlinpoet.FileSpec import com.squareup.kotlinpoet.ParameterSpec import com.squareup.kotlinpoet.PropertySpec +@DslMarker +annotation class PoetDsl fun FileSpec.Builder.genLibComment() { addFileComment("Generated by Stone Library\n") diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/poet/PropertySpecDsl.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/poet/PropertySpecDsl.kt index 75508429..2bc38c11 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/poet/PropertySpecDsl.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/poet/PropertySpecDsl.kt @@ -3,10 +3,7 @@ package com.github.klee0kai.thekey.stone.ksp.poet import com.squareup.kotlinpoet.FunSpec import com.squareup.kotlinpoet.PropertySpec -@DslMarker -annotation class PropertySpecDsl - -@PropertySpecDsl +@PoetDsl fun PropertySpec.Builder.genGetter( block: FunSpec.Builder.() -> Unit = {} ): FunSpec { @@ -19,7 +16,7 @@ fun PropertySpec.Builder.genGetter( } -@PropertySpecDsl +@PoetDsl fun PropertySpec.Builder.genSetter( block: FunSpec.Builder.() -> Unit = {} ): FunSpec { diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/poet/TypeSpecDsl.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/poet/TypeSpecDsl.kt index 66d269a7..07cffc6d 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/poet/TypeSpecDsl.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/poet/TypeSpecDsl.kt @@ -2,10 +2,7 @@ package com.github.klee0kai.thekey.stone.ksp.poet import com.squareup.kotlinpoet.* -@DslMarker -annotation class TypeSpecDsl - -@TypeSpecDsl +@PoetDsl fun TypeSpec.Builder.genProperty( name: String, type: TypeName, @@ -20,7 +17,7 @@ fun TypeSpec.Builder.genProperty( } } -@TypeSpecDsl +@PoetDsl fun TypeSpec.Builder.genClass( className: ClassName, block: TypeSpec.Builder.() -> Unit = {}, @@ -32,7 +29,7 @@ fun TypeSpec.Builder.genClass( ) } -@TypeSpecDsl +@PoetDsl fun TypeSpec.Builder.genObject( className: ClassName, block: TypeSpec.Builder.() -> Unit = {}, @@ -44,7 +41,7 @@ fun TypeSpec.Builder.genObject( ) } -@TypeSpecDsl +@PoetDsl fun TypeSpec.Builder.genInterface( className: ClassName, block: TypeSpec.Builder.() -> Unit = {}, @@ -56,7 +53,7 @@ fun TypeSpec.Builder.genInterface( ) } -@TypeSpecDsl +@PoetDsl fun TypeSpec.Builder.genFun( name: String, block: FunSpec.Builder.() -> Unit = {}, @@ -68,7 +65,7 @@ fun TypeSpec.Builder.genFun( ) } -@TypeSpecDsl +@PoetDsl fun TypeSpec.Builder.genPrimaryConstructor( block: FunSpec.Builder.() -> Unit = {}, ) { @@ -79,7 +76,7 @@ fun TypeSpec.Builder.genPrimaryConstructor( ) } -@TypeSpecDsl +@PoetDsl fun TypeSpec.Builder.genConstructor( block: FunSpec.Builder.() -> Unit = {}, ) { diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/poet/smartcode/CollectedSmartCode.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/poet/smartcode/CollectedSmartCode.kt new file mode 100644 index 00000000..9037b147 --- /dev/null +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/poet/smartcode/CollectedSmartCode.kt @@ -0,0 +1,43 @@ +package com.github.klee0kai.thekey.stone.ksp.poet.smartcode + +import com.squareup.kotlinpoet.ClassName +import com.squareup.kotlinpoet.CodeBlock + +class CollectedSmartCode( + val codeBlock: CodeBlock, + val declareLocalVariable: Pair? = null, + val usedVariables: Set = emptySet(), + val providingType: ClassName? = null, +) { + + class ScopedBuilder( + val declaredVariables: Map, + ) { + val codeBuilder = CodeBlock.Builder() + var declareLocalVariable: Pair? = null + val usedVariables = mutableSetOf() + var providingType: ClassName? = null + + fun build() = CollectedSmartCode( + codeBlock = codeBuilder.build(), + declareLocalVariable = declareLocalVariable, + usedVariables = usedVariables, + providingType = providingType, + ) + + } + +} + +fun CollectedSmartCode.ScopedBuilder.add( + string: String, +) { + codeBuilder.add(string) +} + +fun CollectedSmartCode.ScopedBuilder.add( + codeBlock: CodeBlock, +) { + codeBuilder.add(codeBlock) +} + diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/poet/smartcode/SimpleCodeBuilder.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/poet/smartcode/SimpleCodeBuilder.kt new file mode 100644 index 00000000..3cd28cd3 --- /dev/null +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/poet/smartcode/SimpleCodeBuilder.kt @@ -0,0 +1,12 @@ +package com.github.klee0kai.thekey.stone.ksp.poet.smartcode + +import com.squareup.kotlinpoet.ClassName + +fun interface SimpleCodeBuilder { + + fun collect( + declaredVariables: Map + ): CollectedSmartCode + +} + diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/poet/smartcode/SmartCode.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/poet/smartcode/SmartCode.kt deleted file mode 100644 index f7b3e1f5..00000000 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/poet/smartcode/SmartCode.kt +++ /dev/null @@ -1,3 +0,0 @@ -package com.github.klee0kai.thekey.stone.ksp.poet.smartcode - -interface SmartCode diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/poet/smartcode/SmartCodeExt.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/poet/smartcode/SmartCodeExt.kt new file mode 100644 index 00000000..4ac497ed --- /dev/null +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/poet/smartcode/SmartCodeExt.kt @@ -0,0 +1,63 @@ +package com.github.klee0kai.thekey.stone.ksp.poet.smartcode + +import com.github.klee0kai.thekey.stone.ksp.poet.PoetDsl +import com.squareup.kotlinpoet.ClassName +import com.squareup.kotlinpoet.CodeBlock + + +@PoetDsl +fun SmartCodeScopeBuilder.add( + codeBlock: CodeBlock, + usedVariables: Set = emptySet(), + providingType: ClassName? = null, +) { + codes.add( + SimpleCodeBuilder { + CollectedSmartCode( + codeBlock = codeBlock, + usedVariables = usedVariables, + providingType = providingType, + ) + }) +} + +@PoetDsl +fun SmartCodeScopeBuilder.add( + codeBlock: String, + usedVariables: Set = emptySet(), + providingType: ClassName? = null, +) { + codes.add( + SimpleCodeBuilder { + CollectedSmartCode( + codeBlock = CodeBlock.Builder().apply { + add(codeBlock) + }.build(), + usedVariables = usedVariables, + providingType = providingType, + ) + }) +} + +@PoetDsl +fun SmartCodeScopeBuilder.add( + codeBlock: CollectedSmartCode.ScopedBuilder.() -> Unit, +) { + codes.add( + SimpleCodeBuilder { + CollectedSmartCode.ScopedBuilder(it).apply(codeBlock).build() + } + ) +} + +@PoetDsl +fun SmartCodeScopeBuilder.smartCode( + codeBlock: SmartCodeScopeBuilder.() -> Unit, +) { + codes.add( + SmartCodeScopeBuilder() + .apply(codeBlock) + ) +} + + diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/poet/smartcode/SmartCodeScopeBuilder.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/poet/smartcode/SmartCodeScopeBuilder.kt new file mode 100644 index 00000000..bf3ebc6b --- /dev/null +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/poet/smartcode/SmartCodeScopeBuilder.kt @@ -0,0 +1,55 @@ +package com.github.klee0kai.thekey.stone.ksp.poet.smartcode + +import com.github.klee0kai.thekey.stone.ksp.poet.PoetDsl +import com.squareup.kotlinpoet.ClassName +import com.squareup.kotlinpoet.CodeBlock + +open class SmartCodeScopeBuilder() : SimpleCodeBuilder { + + val codes = mutableListOf() + + var declareLocalVariable: Pair? = null + var providingType: ClassName? = null + + override fun collect( + declaredVariables: Map, + ): CollectedSmartCode { + val declaredVariables = declaredVariables.toMutableMap() + val usedVariables = mutableSetOf() + val collectedList = mutableListOf() + for (code in codes) { + val collected = code.collect(declaredVariables) + if (collected.declareLocalVariable != null) { + declaredVariables += collected.declareLocalVariable + } + + usedVariables += collected.usedVariables + collectedList += collected + } + + val optimized = collectedList.filter { + it.declareLocalVariable == null + || it.declareLocalVariable.first in usedVariables + } + + return CollectedSmartCode( + codeBlock = CodeBlock.builder().also { builder -> + optimized.forEach { + builder.add(it.codeBlock) + } + }.build(), + declareLocalVariable = declareLocalVariable, + usedVariables = usedVariables, + providingType = providingType, + ) + } + +} + +@PoetDsl +fun smartCode( + block: SmartCodeScopeBuilder.() -> Unit, +) = SmartCodeScopeBuilder() + .apply(block) + .collect(declaredVariables = emptyMap()) + .codeBlock \ No newline at end of file From 2559512641c7fe4561d0ef16cbad9841e773b5cc Mon Sep 17 00:00:00 2001 From: klee0kai Date: Sun, 16 Nov 2025 14:56:10 +0100 Subject: [PATCH 023/122] single item holder --- libs.versions.toml | 2 + stone_multiplatform/build.gradle.kts | 3 +- .../klee0kai/stone/__hidden__/StoneScope.kt | 9 ++ .../__hidden__/types/SwitchCacheParam.kt | 17 ++ .../types/holders/SingleItemHolder.kt | 147 ++++++++++++++++++ .../__hidden__/types/holders/StoneRefType.kt | 2 +- 6 files changed, 178 insertions(+), 2 deletions(-) create mode 100644 stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/__hidden__/StoneScope.kt create mode 100644 stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/__hidden__/types/SwitchCacheParam.kt create mode 100644 stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/__hidden__/types/holders/SingleItemHolder.kt diff --git a/libs.versions.toml b/libs.versions.toml index c747ced5..ce467f70 100644 --- a/libs.versions.toml +++ b/libs.versions.toml @@ -11,6 +11,7 @@ javax-inject = "1" kotlinx-coroutines = "1.10.1" jetbrain-immutable = "0.3.7" jetbrain-coroutines = "1.10.1" +kotlinx-atomicfu = "0.29.0" auto-service = "1.1.1" incap = "1.0.0" @@ -34,6 +35,7 @@ android-appcompat = { group = "androidx.appcompat", name = "appcompat", version. java-inject = { group = "javax.inject", name = "javax.inject", version.ref = "javax-inject" } kotlinx-coroutines = { group = "org.jetbrains.kotlinx", name = "kotlinx-coroutines-core", version.ref = "kotlinx-coroutines" } +kotlinx-atomicfu = { group = "org.jetbrains.kotlinx", name = "atomicfu", version.ref = "kotlinx-atomicfu" } auto-service = { group = "com.google.auto.service", name = "auto-service", version.ref = "auto-service" } diff --git a/stone_multiplatform/build.gradle.kts b/stone_multiplatform/build.gradle.kts index 640b167d..4c3c6777 100644 --- a/stone_multiplatform/build.gradle.kts +++ b/stone_multiplatform/build.gradle.kts @@ -29,7 +29,8 @@ kotlin { commonMain.dependencies { api(project(":inject_multiplatform")) api(project(":weakref_multiplatform")) - api(libs.kotlinx.coroutines) + implementation(libs.kotlinx.coroutines) + implementation(libs.kotlinx.atomicfu) } commonTest.dependencies { implementation(kotlin("test")) diff --git a/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/__hidden__/StoneScope.kt b/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/__hidden__/StoneScope.kt new file mode 100644 index 00000000..6941cf0f --- /dev/null +++ b/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/__hidden__/StoneScope.kt @@ -0,0 +1,9 @@ +package com.github.klee0kai.stone.__hidden__ + +import kotlinx.coroutines.CoroutineScope +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.SupervisorJob + +object StoneScope { + val stoneCoroutineScope = CoroutineScope(SupervisorJob() + Dispatchers.Default) +} \ No newline at end of file diff --git a/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/__hidden__/types/SwitchCacheParam.kt b/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/__hidden__/types/SwitchCacheParam.kt new file mode 100644 index 00000000..12674c06 --- /dev/null +++ b/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/__hidden__/types/SwitchCacheParam.kt @@ -0,0 +1,17 @@ +package com.github.klee0kai.stone.__hidden__.types + +import com.github.klee0kai.stone.annotations.component.SwitchCache +import kotlin.time.Duration + +/** + * Stone Private class + */ +class SwitchCacheParam( + val cache: SwitchCache.CacheType, + val time: Duration, +) { + companion object { + fun toWeak() = SwitchCacheParam(SwitchCache.CacheType.Weak, Duration.INFINITE) + fun toDef() = SwitchCacheParam(SwitchCache.CacheType.Default, Duration.INFINITE) + } +} diff --git a/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/__hidden__/types/holders/SingleItemHolder.kt b/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/__hidden__/types/holders/SingleItemHolder.kt new file mode 100644 index 00000000..29d9dfd0 --- /dev/null +++ b/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/__hidden__/types/holders/SingleItemHolder.kt @@ -0,0 +1,147 @@ +package com.github.klee0kai.stone.__hidden__.types.holders + +import com.github.klee0kai.stone.__hidden__.StoneScope +import com.github.klee0kai.stone.__hidden__.types.SwitchCacheParam +import com.github.klee0kai.stone.annotations.component.SwitchCache +import com.github.klee0kai.stone.weakref.Ref +import kotlinx.atomicfu.atomic +import kotlinx.coroutines.delay +import kotlinx.coroutines.launch +import kotlin.time.Duration + +/** + * Stone Private class + */ +@Suppress("UNCHECKED_CAST") +class SingleItemHolder( + private val defType: StoneRefType +) { + private var curRefType: StoneRefType = defType + + private var refHolder: Any? = null + private val shedTaskCount = atomic(0) + + + fun get(): T? = when (curRefType) { + StoneRefType.StrongObject -> refHolder as T? + StoneRefType.WeakObject, StoneRefType.SoftObject -> (refHolder as Ref?)?.get() + else -> null + } + + fun getList(): List? = when (curRefType) { + StoneRefType.ListObject -> refHolder as MutableList? + StoneRefType.ListWeakObject, StoneRefType.ListSoftObject -> (refHolder as MutableList?>?)?.map { it?.get() } + else -> null + } + + + fun set( + creator: Ref, + onlyIfNull: Boolean, + ) { + if (curRefType == StoneRefType.StrongObject) { + if (refHolder != null && onlyIfNull) return + refHolder = creator.get() + return + } + val formatter: (T?) -> Ref = curRefType.formatter() ?: return + if (!onlyIfNull) { + //switch ref type case + refHolder = formatter(creator.get()) + return + } + + val ref: Ref? = refHolder as Ref? + if (ref == null || ref.get() == null) { + refHolder = formatter(creator.get()) + } + } + + fun setList( + creator: Ref?>, + onlyIfNull: Boolean, + ) { + if (curRefType == StoneRefType.ListObject) { + if (!onlyIfNull || refHolder == null) { + refHolder = creator.get()?.toMutableList() + return + } + + // init nulls if needed + var created: List? = null + val list = refHolder as MutableList + for (i in list.indices) { + if (list[i] == null) { + if (created == null) created = creator.get() + list[i] = created?.get(i) + } + } + return + } + val formatter = curRefType.formatter() ?: return + val refList = refHolder as MutableList?>? + if (refList == null || !onlyIfNull) { + refHolder = creator.get()?.map { formatter(it) }?.toMutableList() + return + } + + // init nulls if needed + var created: List? = null + for (i in refList.indices) { + if (refList[i] == null || refList[i]?.get() == null) { + if (created == null) created = creator.get() + refList[i] = formatter(created?.get(i)) + } + } + } + + fun setRefType( + refType: StoneRefType, + ) { + if (curRefType === refType) return + if (defType.isList) { + val ob = this.getList() + curRefType = refType.forList() + setList(creator = Ref { ob }, false) + } else { + val ob = get() + curRefType = refType.forSingle() + set(creator = Ref { ob }, false) + } + } + + + fun reset() { + curRefType = defType + refHolder = null + } + + + fun switchCache(args: SwitchCacheParam) { + when (args.cache) { + SwitchCache.CacheType.Default -> { + setRefType(defType) + return + } + + SwitchCache.CacheType.Reset -> { + reset() + return + } + + SwitchCache.CacheType.Weak -> setRefType(StoneRefType.WeakObject) + SwitchCache.CacheType.Soft -> setRefType(StoneRefType.SoftObject) + SwitchCache.CacheType.Strong -> setRefType(StoneRefType.StrongObject) + } + + if (args.time != Duration.INFINITE) { + shedTaskCount.incrementAndGet() + StoneScope.stoneCoroutineScope.launch { + delay(args.time) + if (shedTaskCount.decrementAndGet() <= 0) { + setRefType(defType) + } + } + } + } +} diff --git a/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/__hidden__/types/holders/StoneRefType.kt b/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/__hidden__/types/holders/StoneRefType.kt index 96dc758a..d36240a5 100644 --- a/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/__hidden__/types/holders/StoneRefType.kt +++ b/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/__hidden__/types/holders/StoneRefType.kt @@ -35,7 +35,7 @@ enum class StoneRefType { else -> this } - fun formatter(): ((T) -> Ref)? { + fun formatter(): ((T?) -> Ref)? { when (this) { WeakObject, ListWeakObject -> return { WeakRef(it) } SoftObject, ListSoftObject -> return { SoftRef(it) } From 67ed8cda4e3bcac5d772b9745a0aa37083b07e39 Mon Sep 17 00:00:00 2001 From: klee0kai Date: Sun, 16 Nov 2025 15:15:37 +0100 Subject: [PATCH 024/122] map items holder --- .../__hidden__/types/holders/MapItemHolder.kt | 188 ++++++++++++++++++ .../types/holders/SingleItemHolder.kt | 7 +- 2 files changed, 192 insertions(+), 3 deletions(-) create mode 100644 stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/__hidden__/types/holders/MapItemHolder.kt diff --git a/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/__hidden__/types/holders/MapItemHolder.kt b/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/__hidden__/types/holders/MapItemHolder.kt new file mode 100644 index 00000000..1bf1eb3b --- /dev/null +++ b/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/__hidden__/types/holders/MapItemHolder.kt @@ -0,0 +1,188 @@ +package com.github.klee0kai.stone.__hidden__.types.holders + +import com.github.klee0kai.stone.__hidden__.StoneScope +import com.github.klee0kai.stone.__hidden__.types.SwitchCacheParam +import com.github.klee0kai.stone.annotations.component.SwitchCache +import com.github.klee0kai.stone.weakref.Ref +import kotlinx.atomicfu.atomic +import kotlinx.coroutines.delay +import kotlinx.coroutines.launch +import kotlin.time.Duration + +/** + * Stone Private class + */ +@Suppress("UNCHECKED_CAST") +class MapItemHolder( + private val defType: StoneRefType +) { + + private var curRefType: StoneRefType = defType + + + private val refMap: HashMap = HashMap() + private val shedTaskCount = atomic(0) + + + fun get( + key: Key?, + ): T? { + val holder = refMap[key] ?: return null + return when (curRefType) { + StoneRefType.StrongObject -> holder as T? + StoneRefType.WeakObject, StoneRefType.SoftObject -> (holder as Ref?)?.get() + else -> null + } + } + + fun getList( + key: Key?, + ): List? { + val holder = refMap[key] ?: return null + return when (curRefType) { + StoneRefType.ListObject -> holder as MutableList? + StoneRefType.ListWeakObject, StoneRefType.ListSoftObject -> (holder as MutableList?>?)?.map { it?.get() } + else -> null + } + } + + fun set( + key: Key?, + creator: Ref, + onlyIfNull: Boolean, + ) { + val refHolder = refMap[key] + if (curRefType == StoneRefType.StrongObject) { + if (onlyIfNull && refHolder != null) return + refMap[key] = creator.get() + return + } + val formatter: (T?) -> Ref = curRefType.formatter() ?: return + if (!onlyIfNull) { + //switch ref type case + refMap[key] = formatter(creator.get()) + return + } + + val ref: Ref? = refHolder as Ref? + if (ref == null || ref.get() == null) { + refMap[key] = formatter(creator.get()) + } + } + + fun setList( + key: Key?, + creator: Ref?>, + onlyIfNull: Boolean, + ) { + val refHolder = refMap[key] + if (curRefType == StoneRefType.ListObject) { + if (!onlyIfNull || refHolder == null) { + refMap[key] = creator.get()?.toMutableList() + return + } + + // init nulls if needed + var created: List? = null + val refList = refHolder as MutableList + for (i in refList.indices) { + if (refList[i] == null) { + if (created == null) created = creator.get() + refList[i] = created?.get(i) + } + } + return + } + + val formatter = curRefType.formatter() ?: return + val refList = refHolder as? MutableList?> + if (!onlyIfNull || refList == null) { + //switch ref type case + refMap[key] = creator.get()?.map { formatter(it) }?.toMutableList() + return + } + + var created: List? = null + for (i in refList.indices) { + if (refList[i] == null || refList[i]?.get() == null) { + if (created == null) created = creator.get() + refList[i] = formatter(created?.get(i)) + } + } + } + + + fun setRefType(refType: StoneRefType) { + if (curRefType == refType) return + if (defType.isList) { + val listMap: HashMap?> = HashMap() + for (key in refMap.keys) listMap[key] = getList(key) + curRefType = refType.forList() + for (key in listMap.keys) setList(key, Ref { listMap[key] }, false) + } else { + val itemMap: HashMap = HashMap() + for (key in refMap.keys) itemMap[key] = get(key) + curRefType = refType.forSingle() + for (key in itemMap.keys) set(key, Ref { itemMap[key] }, false) + } + } + + + fun remove(key: Key?) { + refMap.remove(key) + } + + + fun reset() { + curRefType = defType + refMap.clear() + } + + + fun clearNulls() { + val keys: Set = HashSet(refMap.keys) + if (!curRefType.isList) { + for (key in keys) { + if (get(key) == null) { + refMap.remove(key) + } + } + } else { + for (key in keys) { + val list = getList(key) + if (list?.none { it != null } == true) { + refMap.remove(key) + } + } + } + } + + + fun switchCache(args: SwitchCacheParam) { + when (args.cache) { + SwitchCache.CacheType.Default -> { + setRefType(defType) + return + } + + SwitchCache.CacheType.Reset -> { + reset() + return + } + + SwitchCache.CacheType.Weak -> setRefType(StoneRefType.WeakObject) + SwitchCache.CacheType.Soft -> setRefType(StoneRefType.SoftObject) + SwitchCache.CacheType.Strong -> setRefType(StoneRefType.StrongObject) + } + + if (args.time != Duration.INFINITE) { + shedTaskCount.incrementAndGet() + StoneScope.stoneCoroutineScope.launch { + delay(args.time) + if (shedTaskCount.decrementAndGet() <= 0) { + setRefType(defType) + } + } + } + } +} diff --git a/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/__hidden__/types/holders/SingleItemHolder.kt b/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/__hidden__/types/holders/SingleItemHolder.kt index 29d9dfd0..207c434b 100644 --- a/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/__hidden__/types/holders/SingleItemHolder.kt +++ b/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/__hidden__/types/holders/SingleItemHolder.kt @@ -78,9 +78,10 @@ class SingleItemHolder( } return } + val formatter = curRefType.formatter() ?: return - val refList = refHolder as MutableList?>? - if (refList == null || !onlyIfNull) { + val refList = refHolder as? MutableList?>? + if (!onlyIfNull || refList == null) { refHolder = creator.get()?.map { formatter(it) }?.toMutableList() return } @@ -98,7 +99,7 @@ class SingleItemHolder( fun setRefType( refType: StoneRefType, ) { - if (curRefType === refType) return + if (curRefType == refType) return if (defType.isList) { val ob = this.getList() curRefType = refType.forList() From d7cf323d135e369fc9ec128c8576424a0ab42cea Mon Sep 17 00:00:00 2001 From: klee0kai Date: Sun, 16 Nov 2025 15:23:36 +0100 Subject: [PATCH 025/122] cache actions --- .../klee0kai/stone/__hidden__/CacheAction.kt | 52 +++++++++++++++++++ .../{types => }/SwitchCacheParam.kt | 10 ++-- .../__hidden__/types/holders/MapItemHolder.kt | 2 +- .../types/holders/SingleItemHolder.kt | 2 +- .../github/klee0kai/stone/weakref/SoftRef.kt | 15 ++++++ .../github/klee0kai/stone/weakref/WeakRef.kt | 4 +- 6 files changed, 76 insertions(+), 9 deletions(-) create mode 100644 stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/__hidden__/CacheAction.kt rename stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/__hidden__/{types => }/SwitchCacheParam.kt (73%) create mode 100644 weakref_multiplatform/src/androidMain/kotlin/com/github/klee0kai/stone/weakref/SoftRef.kt diff --git a/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/__hidden__/CacheAction.kt b/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/__hidden__/CacheAction.kt new file mode 100644 index 00000000..40240e81 --- /dev/null +++ b/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/__hidden__/CacheAction.kt @@ -0,0 +1,52 @@ +package com.github.klee0kai.stone.__hidden__ + +import com.github.klee0kai.stone.__hidden__.SwitchCacheParam +import com.github.klee0kai.stone.annotations.component.SwitchCache + +/** + * Stone Private class + */ +class CacheAction( + val type: ActionType?, + val swCacheParams: SwitchCacheParam? = null, + val value: Any? = null, +) { + + enum class ActionType { + GET_VALUE, + SET_VALUE, + SET_IF_NULL, + SWITCH_CACHE, + } + + val isGetAction: Boolean get() = type == ActionType.GET_VALUE + + val isSetAction: Boolean get() = type == ActionType.SET_VALUE + + val isSetIfNullAction: Boolean get() = type == ActionType.SET_IF_NULL + + val isSwitchCacheAction: Boolean get() = type == ActionType.SWITCH_CACHE + + companion object { + val valueAction: CacheAction get() = CacheAction(ActionType.GET_VALUE) + + fun setValueAction(value: Any?) = CacheAction(ActionType.SET_VALUE, value = value) + + fun setIfNullValueAction(value: Any?) = CacheAction(ActionType.SET_IF_NULL, value = value) + + fun switchCacheValueAction( + param: SwitchCacheParam?, + ) = CacheAction( + type = ActionType.SWITCH_CACHE, + swCacheParams = param, + ) + + fun switchCacheToDefAction( + ) = CacheAction( + type = ActionType.SWITCH_CACHE, + swCacheParams = SwitchCacheParam(SwitchCache.CacheType.Default), + ) + } +} + + diff --git a/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/__hidden__/types/SwitchCacheParam.kt b/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/__hidden__/SwitchCacheParam.kt similarity index 73% rename from stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/__hidden__/types/SwitchCacheParam.kt rename to stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/__hidden__/SwitchCacheParam.kt index 12674c06..83bdfcbe 100644 --- a/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/__hidden__/types/SwitchCacheParam.kt +++ b/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/__hidden__/SwitchCacheParam.kt @@ -1,4 +1,4 @@ -package com.github.klee0kai.stone.__hidden__.types +package com.github.klee0kai.stone.__hidden__ import com.github.klee0kai.stone.annotations.component.SwitchCache import kotlin.time.Duration @@ -8,10 +8,10 @@ import kotlin.time.Duration */ class SwitchCacheParam( val cache: SwitchCache.CacheType, - val time: Duration, + val time: Duration = Duration.INFINITE, ) { companion object { - fun toWeak() = SwitchCacheParam(SwitchCache.CacheType.Weak, Duration.INFINITE) - fun toDef() = SwitchCacheParam(SwitchCache.CacheType.Default, Duration.INFINITE) + fun toWeak() = SwitchCacheParam(SwitchCache.CacheType.Weak) + fun toDef() = SwitchCacheParam(SwitchCache.CacheType.Default) } -} +} \ No newline at end of file diff --git a/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/__hidden__/types/holders/MapItemHolder.kt b/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/__hidden__/types/holders/MapItemHolder.kt index 1bf1eb3b..3dc081af 100644 --- a/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/__hidden__/types/holders/MapItemHolder.kt +++ b/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/__hidden__/types/holders/MapItemHolder.kt @@ -1,7 +1,7 @@ package com.github.klee0kai.stone.__hidden__.types.holders import com.github.klee0kai.stone.__hidden__.StoneScope -import com.github.klee0kai.stone.__hidden__.types.SwitchCacheParam +import com.github.klee0kai.stone.__hidden__.SwitchCacheParam import com.github.klee0kai.stone.annotations.component.SwitchCache import com.github.klee0kai.stone.weakref.Ref import kotlinx.atomicfu.atomic diff --git a/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/__hidden__/types/holders/SingleItemHolder.kt b/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/__hidden__/types/holders/SingleItemHolder.kt index 207c434b..a87fc3fb 100644 --- a/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/__hidden__/types/holders/SingleItemHolder.kt +++ b/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/__hidden__/types/holders/SingleItemHolder.kt @@ -1,7 +1,7 @@ package com.github.klee0kai.stone.__hidden__.types.holders import com.github.klee0kai.stone.__hidden__.StoneScope -import com.github.klee0kai.stone.__hidden__.types.SwitchCacheParam +import com.github.klee0kai.stone.__hidden__.SwitchCacheParam import com.github.klee0kai.stone.annotations.component.SwitchCache import com.github.klee0kai.stone.weakref.Ref import kotlinx.atomicfu.atomic diff --git a/weakref_multiplatform/src/androidMain/kotlin/com/github/klee0kai/stone/weakref/SoftRef.kt b/weakref_multiplatform/src/androidMain/kotlin/com/github/klee0kai/stone/weakref/SoftRef.kt new file mode 100644 index 00000000..94f654de --- /dev/null +++ b/weakref_multiplatform/src/androidMain/kotlin/com/github/klee0kai/stone/weakref/SoftRef.kt @@ -0,0 +1,15 @@ +package com.github.klee0kai.stone.weakref + +import java.lang.ref.SoftReference + +actual class SoftRef actual constructor(value: T) : Ref { + + val weakRef: SoftReference = SoftReference(value) + + actual override fun get(): T? = weakRef.get() + + actual fun clear() { + weakRef.clear() + } + +} \ No newline at end of file diff --git a/weakref_multiplatform/src/androidMain/kotlin/com/github/klee0kai/stone/weakref/WeakRef.kt b/weakref_multiplatform/src/androidMain/kotlin/com/github/klee0kai/stone/weakref/WeakRef.kt index d8094fac..d4cc44ec 100644 --- a/weakref_multiplatform/src/androidMain/kotlin/com/github/klee0kai/stone/weakref/WeakRef.kt +++ b/weakref_multiplatform/src/androidMain/kotlin/com/github/klee0kai/stone/weakref/WeakRef.kt @@ -2,11 +2,11 @@ package com.github.klee0kai.stone.weakref import java.lang.ref.WeakReference -actual class WeakRef actual constructor(value: T) { +actual class WeakRef actual constructor(value: T) : Ref { val weakRef: WeakReference = WeakReference(value) - actual fun get(): T? = weakRef.get() + actual override fun get(): T? = weakRef.get() actual fun clear() { weakRef.clear() From a73d16f4af205a4a290950aa0ef8a790406717ce Mon Sep 17 00:00:00 2001 From: klee0kai Date: Sun, 16 Nov 2025 15:31:50 +0100 Subject: [PATCH 026/122] ref collection and weak list --- .../__hidden__/collections/RefCollection.kt | 31 +++++++++++++ .../stone/__hidden__/collections/WeakList.kt | 46 +++++++++++++++++++ 2 files changed, 77 insertions(+) create mode 100644 stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/__hidden__/collections/RefCollection.kt create mode 100644 stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/__hidden__/collections/WeakList.kt diff --git a/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/__hidden__/collections/RefCollection.kt b/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/__hidden__/collections/RefCollection.kt new file mode 100644 index 00000000..520cfb34 --- /dev/null +++ b/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/__hidden__/collections/RefCollection.kt @@ -0,0 +1,31 @@ +package com.github.klee0kai.stone.__hidden__.collections + +import com.github.klee0kai.stone.weakref.Ref + +class RefCollection { + + private val refs = mutableListOf>() + + fun add( + ref: Ref, + ) { + clearNulls() + refs.add(ref) + } + + val allRefs: List> + get() { + clearNulls() + return refs + } + + val all: List + get() { + clearNulls() + return refs.mapNotNull { it.get() } + } + + fun clearNulls() { + refs.removeAll { it.get() == null } + } +} diff --git a/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/__hidden__/collections/WeakList.kt b/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/__hidden__/collections/WeakList.kt new file mode 100644 index 00000000..b024a000 --- /dev/null +++ b/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/__hidden__/collections/WeakList.kt @@ -0,0 +1,46 @@ +package com.github.klee0kai.stone.__hidden__.collections + + +import com.github.klee0kai.stone.weakref.Ref +import com.github.klee0kai.stone.weakref.WeakRef + +/** + * Stone Private class + */ +class WeakList { + private val list = mutableListOf?>() + + val size: Int get() = list.size + + val isEmpty: Boolean get() = list.isEmpty() + + fun add(it: T): Boolean { + clearNulls() + return list.add(WeakRef(it)) + } + + fun add(idx: Int, it: T?) { + clearNulls() + list.add(idx, WeakRef(it)) + } + + fun remove(it: Any?): Boolean { + return clearNulls(it) + } + + fun clear() { + list.clear() + } + + fun clearNulls( + ob: Any? = null, + ): Boolean = list.removeAll { it?.get() == null || it.get() == ob } + + fun toList(): List { + clearNulls() + return list.mapNotNull { it?.get() } + } + + fun get(idx: Int): T? = list[idx]?.get() + +} From 26c30bc1391993e746575406b96cd7dafbcdae04 Mon Sep 17 00:00:00 2001 From: klee0kai Date: Sat, 22 Nov 2025 23:31:13 +0100 Subject: [PATCH 027/122] Item Holder helpers --- .../klee0kai/thekey/stone/ksp/Processor.kt | 62 +++++++++++++------ .../ksp/helpers/ComponentDeclarationExt.kt | 22 +++---- .../stone/ksp/helpers/TypeHelpersExt.kt | 38 ++++++++++++ .../helpers/annotations/ComponentAnnMirror.kt | 33 ++++++++++ .../ksp/helpers/itemholder/ItemCacheType.kt | 14 ++--- .../helpers/itemholder/ItemHolderHelper.kt | 62 +++++++++++++++++++ .../itemholder/MultiKeyMapItemHolderHelper.kt | 37 +++++++++++ .../itemholder/SimpleMapItemHolderHelper.kt | 36 +++++++++++ .../itemholder/SingleItemHolderHelper.kt | 32 ++++++++++ .../stone/ksp/ksp/KSClassDeclarationExt.kt | 11 +++- .../stone/ksp/ksp/KSFunctionDeclarationExt.kt | 14 +++++ .../stone/ksp/ksp/arch/SymbolsToProcess.kt | 11 +++- .../ksp/target/GenModuleFactoryProcessor.kt | 10 +-- .../stone/ksp/target/GenModuleProcessor.kt | 43 ++++++++++--- 14 files changed, 370 insertions(+), 55 deletions(-) create mode 100644 stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/TypeHelpersExt.kt create mode 100644 stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/annotations/ComponentAnnMirror.kt create mode 100644 stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/itemholder/ItemHolderHelper.kt create mode 100644 stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/itemholder/MultiKeyMapItemHolderHelper.kt create mode 100644 stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/itemholder/SimpleMapItemHolderHelper.kt create mode 100644 stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/itemholder/SingleItemHolderHelper.kt diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/Processor.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/Processor.kt index d7936e54..69b54ee8 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/Processor.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/Processor.kt @@ -2,11 +2,12 @@ package com.github.klee0kai.thekey.stone.ksp import com.github.klee0kai.thekey.stone.ksp.coroutines.LaunchConductor import com.github.klee0kai.thekey.stone.ksp.ksp.arch.GenSpec -import com.github.klee0kai.thekey.stone.ksp.ksp.arch.TargetFileProcessor +import com.github.klee0kai.thekey.stone.ksp.ksp.arch.filter import com.github.klee0kai.thekey.stone.ksp.ksp.arch.forceProcess -import com.github.klee0kai.thekey.stone.ksp.ksp.arch.takeOnly +import com.github.klee0kai.thekey.stone.ksp.ksp.arch.nowTakeOnly import com.github.klee0kai.thekey.stone.ksp.target.GenModuleFactoryProcessor import com.github.klee0kai.thekey.stone.ksp.target.GenModuleProcessor +import com.google.devtools.ksp.containingFile import com.google.devtools.ksp.processing.CodeGenerator import com.google.devtools.ksp.processing.KSPLogger import com.google.devtools.ksp.processing.Resolver @@ -33,13 +34,35 @@ class Processor( companion object { const val PROJECT_URL = "https://github.com/klee0kai/stone" - val ONE_RUN_SYMBOLS_COUNT = max(Runtime.getRuntime().availableProcessors(), 4) + var oneRunSymbolsCount = 4 + private set + + var multithread = false + private set + + var debug = false + private set + + var debugPkgFilter: String? = null + private set + } + + init { + oneRunSymbolsCount = options["oneRunSymbolsCount"]?.toInt() + ?: max(Runtime.getRuntime().availableProcessors(), 4) + + multithread = options["multithread"]?.toBoolean() ?: false + debug = options["debug"]?.toBoolean() ?: false + debugPkgFilter = options["debugPkgFilter"] + + // force changes + debug = true + debugPkgFilter = "com.github.klee0kai.test_kotlin.di.base_comp" } - private val multithread = options["multithread"]?.toBoolean() ?: false val dispatcher by lazy { if (multithread) Dispatchers.Default else Dispatchers.Unconfined } - val targetProcessors = arrayOf( + val targetProcessors = arrayOf( GenModuleFactoryProcessor(), GenModuleProcessor(), ) @@ -62,27 +85,30 @@ class Processor( var symbols = launchConductor.finishTogether { var symbols = findSymbolsMutex.withLock { processor.findSymbolsToProcess(resolver) } - if (multithread) { - // skip to next ksp run + var takeSymbolsCount = 0 + processSymbolsCounter.updateAndGet { totalCount -> + takeSymbolsCount = min( + symbols.symbolsForProcessing.size, + oneRunSymbolsCount - totalCount + ) - var takeSymbolsCount = 0 - processSymbolsCounter.updateAndGet { totalCount -> - takeSymbolsCount = min( - symbols.symbolsForProcessing.size, - ONE_RUN_SYMBOLS_COUNT - totalCount - ) - - takeSymbolsCount = max(takeSymbolsCount, 0) - totalCount + takeSymbolsCount - } - symbols = symbols.takeOnly(takeSymbolsCount) + takeSymbolsCount = max(takeSymbolsCount, 0) + totalCount + takeSymbolsCount } + // skip to next run + symbols = symbols.nowTakeOnly(takeSymbolsCount) globalSymbolsForProcessing.addAll(symbols.symbolsForProcessing) + symbols } symbols = symbols.forceProcess { it in globalSymbolsForProcessing } + + if (debug && debugPkgFilter != null) { + symbols = symbols + .filter { it.containingFile?.packageName?.asString()?.startsWith(debugPkgFilter!!) ?: true } + } globalSymbolsForReprocessing.addAll(symbols.symbolsForReprocessing) genSpecs.addAll( diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/ComponentDeclarationExt.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/ComponentDeclarationExt.kt index 958db450..498e6f8d 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/ComponentDeclarationExt.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/ComponentDeclarationExt.kt @@ -3,17 +3,16 @@ package com.github.klee0kai.thekey.stone.ksp.helpers import com.github.klee0kai.stone.annotations.component.* +import com.github.klee0kai.thekey.stone.ksp.helpers.annotations.findComponentAnnotation import com.github.klee0kai.thekey.stone.ksp.ksp.isType import com.google.devtools.ksp.KspExperimental -import com.google.devtools.ksp.getAnnotationsByType import com.google.devtools.ksp.processing.Resolver import com.google.devtools.ksp.symbol.KSAnnotation import com.google.devtools.ksp.symbol.KSClassDeclaration import com.google.devtools.ksp.symbol.KSFunctionDeclaration -import com.google.devtools.ksp.symbol.KSTypeReference +import com.google.devtools.ksp.symbol.KSType import com.squareup.kotlinpoet.ClassName import com.squareup.kotlinpoet.asClassName -import kotlin.reflect.KClass fun Resolver.findComponentForModuleOrDep( moduleCl: ClassName, @@ -27,23 +26,22 @@ fun Resolver.findComponentForModuleOrDep( } } - -val KSClassDeclaration.allIdentifierTypes: Sequence> +val KSClassDeclaration.allIdentifierTypes: Sequence get() { - val componentCl = this@allIdentifierTypes as? KSTypeReference + val componentCl = this@allIdentifierTypes val allParentsSequence = (sequenceOf(componentCl) + superTypes) return allParentsSequence - .flatMap { it?.getAnnotationsByType(Component::class) ?: emptySequence() } - .flatMap { it.identifiers.asSequence() } + .flatMap { it.findComponentAnnotation() } + .flatMap { it.identifiers } } -val KSClassDeclaration.wrapperProviders: Sequence> +val KSClassDeclaration.wrapperProviders: Sequence get() { - val componentCl = this@wrapperProviders as? KSTypeReference + val componentCl = this@wrapperProviders val allParentsSequence = (sequenceOf(componentCl) + superTypes) return allParentsSequence - .flatMap { it?.getAnnotationsByType(Component::class) ?: emptySequence() } - .flatMap { it.wrapperProviders.asSequence() } + .flatMap { it.findComponentAnnotation() } + .flatMap { it.wrapperProviders } } val KSFunctionDeclaration.scopeAnnotations: Sequence diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/TypeHelpersExt.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/TypeHelpersExt.kt new file mode 100644 index 00000000..de6c1f91 --- /dev/null +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/TypeHelpersExt.kt @@ -0,0 +1,38 @@ +package com.github.klee0kai.thekey.stone.ksp.helpers + +import com.github.klee0kai.thekey.stone.ksp.ksp.isAnyType +import com.google.devtools.ksp.symbol.KSClassDeclaration +import com.google.devtools.ksp.symbol.KSType + +fun KSType.isListType( +): Boolean { + if ( + declaration.isAnyType( + Iterable::class, + List::class, + MutableList::class, + Collection::class, + ) + ) { + return true + } + + + return (this.declaration as? KSClassDeclaration) + ?.superTypes + ?.any { it.resolve().isListType() } == true +} + + +fun KSType.noWrappedType( + wrappedTypes: List, +): KSType { + if (arguments.isEmpty()) return this + if (this in wrappedTypes) { + return arguments + .first().type?.resolve() + ?.noWrappedType(wrappedTypes) + ?: this + } + return this +} diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/annotations/ComponentAnnMirror.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/annotations/ComponentAnnMirror.kt new file mode 100644 index 00000000..64f2ca72 --- /dev/null +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/annotations/ComponentAnnMirror.kt @@ -0,0 +1,33 @@ +package com.github.klee0kai.thekey.stone.ksp.helpers.annotations + +import com.github.klee0kai.stone.annotations.component.Component +import com.google.devtools.ksp.symbol.KSAnnotated +import com.google.devtools.ksp.symbol.KSType +import com.squareup.kotlinpoet.asClassName +import com.squareup.kotlinpoet.ksp.toClassName + +class ComponentAnnMirror( + val identifiers: List, + val wrapperProviders: List, +) + +@Suppress("UNCHECKED_CAST") +fun KSAnnotated.findComponentAnnotation( +): Sequence = annotations + .filter { it.annotationType.resolve().toClassName() == Component::class.asClassName() } + .map { compAnn -> + val identifiers = compAnn.arguments + .firstOrNull { it.name?.asString() == "identifiers" } + ?.value as? List + ?: emptyList() + + val wrapperProviders = compAnn.arguments + .firstOrNull { it.name?.asString() == "wrapperProviders" } + ?.value as? List + ?: emptyList() + + ComponentAnnMirror( + identifiers = identifiers, + wrapperProviders = wrapperProviders, + ) + } diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/itemholder/ItemCacheType.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/itemholder/ItemCacheType.kt index 2d8246ba..cc418be2 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/itemholder/ItemCacheType.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/itemholder/ItemCacheType.kt @@ -21,7 +21,7 @@ enum class ItemCacheType { fun ItemCacheType.toRefTypeSingle( -): StoneRefType? = when (this) { +): StoneRefType = when (this) { ItemCacheType.Strong -> StoneRefType.StrongObject ItemCacheType.Soft -> StoneRefType.SoftObject ItemCacheType.Weak -> StoneRefType.WeakObject @@ -29,7 +29,7 @@ fun ItemCacheType.toRefTypeSingle( fun ItemCacheType.toRefTypeList( -): StoneRefType? = when (this) { +): StoneRefType = when (this) { ItemCacheType.Strong -> StoneRefType.ListObject ItemCacheType.Soft -> StoneRefType.ListSoftObject ItemCacheType.Weak -> StoneRefType.ListWeakObject @@ -44,10 +44,10 @@ fun BindInstance.CacheType.toItemCacheType( } fun Provide.CacheType.toItemCacheType( -): ItemCacheType = when (this) { - Provide.CacheType.Factory -> TODO() - Provide.CacheType.Weak -> TODO() - Provide.CacheType.Soft -> TODO() - Provide.CacheType.Strong -> TODO() +): ItemCacheType? = when (this) { + Provide.CacheType.Factory -> null + Provide.CacheType.Weak -> ItemCacheType.Weak + Provide.CacheType.Soft -> ItemCacheType.Soft + Provide.CacheType.Strong -> ItemCacheType.Strong } diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/itemholder/ItemHolderHelper.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/itemholder/ItemHolderHelper.kt new file mode 100644 index 00000000..f04dae8a --- /dev/null +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/itemholder/ItemHolderHelper.kt @@ -0,0 +1,62 @@ +package com.github.klee0kai.thekey.stone.ksp.helpers.itemholder + +import com.github.klee0kai.thekey.stone.ksp.helpers.isListType +import com.github.klee0kai.thekey.stone.ksp.helpers.noWrappedType +import com.google.devtools.ksp.symbol.KSType +import com.google.devtools.ksp.symbol.KSValueParameter +import com.squareup.kotlinpoet.TypeSpec + +interface ItemHolderHelper { + companion object; + + fun TypeSpec.Builder.genCacheField() + +} + +fun ItemHolderHelper.Companion.of( + fieldName: String, + returnType: KSType, + idArguments: List, + cacheType: ItemCacheType, +): ItemHolderHelper { + val noWrappedReturnType = returnType + .noWrappedType( + wrappedTypes = idArguments.map { it.type.resolve() } + ) + val defRefType = if (noWrappedReturnType.isListType()) { + cacheType.toRefTypeList() + } else { + cacheType.toRefTypeSingle() + } + + return when { + idArguments.isEmpty() -> SingleItemHolderHelper( + fieldName = fieldName, + returnType = returnType, + nonWrappedReturnType = noWrappedReturnType, + itemCacheType = cacheType, + isListCaching = noWrappedReturnType.isListType(), + defRefType = defRefType, + ) + + idArguments.size == 1 -> SimpleMapItemHolderHelper( + fieldName = fieldName, + returnType = returnType, + nonWrappedReturnType = noWrappedReturnType, + itemCacheType = cacheType, + isListCaching = noWrappedReturnType.isListType(), + defRefType = defRefType, + keyParam = idArguments.first(), + ) + + else -> MultiKeyMapItemHolderHelper( + fieldName = fieldName, + returnType = returnType, + nonWrappedReturnType = noWrappedReturnType, + itemCacheType = cacheType, + isListCaching = noWrappedReturnType.isListType(), + defRefType = defRefType, + keyArguments = idArguments, + ) + } +} diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/itemholder/MultiKeyMapItemHolderHelper.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/itemholder/MultiKeyMapItemHolderHelper.kt new file mode 100644 index 00000000..8f7b0052 --- /dev/null +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/itemholder/MultiKeyMapItemHolderHelper.kt @@ -0,0 +1,37 @@ +package com.github.klee0kai.thekey.stone.ksp.helpers.itemholder + +import com.github.klee0kai.stone.__hidden__.types.MultiKey +import com.github.klee0kai.stone.__hidden__.types.holders.MapItemHolder +import com.github.klee0kai.stone.__hidden__.types.holders.StoneRefType +import com.github.klee0kai.thekey.stone.ksp.poet.genProperty +import com.google.devtools.ksp.symbol.KSType +import com.google.devtools.ksp.symbol.KSValueParameter +import com.squareup.kotlinpoet.KModifier +import com.squareup.kotlinpoet.ParameterizedTypeName.Companion.parameterizedBy +import com.squareup.kotlinpoet.TypeSpec +import com.squareup.kotlinpoet.asClassName +import com.squareup.kotlinpoet.ksp.toClassName + +class MultiKeyMapItemHolderHelper( + val fieldName: String, + val returnType: KSType, + val nonWrappedReturnType: KSType, + val itemCacheType: ItemCacheType, + val isListCaching: Boolean, + val defRefType: StoneRefType, + val keyArguments: List, +) : ItemHolderHelper { + + override fun TypeSpec.Builder.genCacheField() { + val cacheType = MapItemHolder::class.asClassName() + .parameterizedBy( + MultiKey::class.asClassName(), + nonWrappedReturnType.toClassName(), + ) + + genProperty(fieldName, cacheType) { + addModifiers(KModifier.PRIVATE) + initializer("%T(%T.%L)", cacheType, StoneRefType::class, defRefType) + } + } +} \ No newline at end of file diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/itemholder/SimpleMapItemHolderHelper.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/itemholder/SimpleMapItemHolderHelper.kt new file mode 100644 index 00000000..7163fea0 --- /dev/null +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/itemholder/SimpleMapItemHolderHelper.kt @@ -0,0 +1,36 @@ +package com.github.klee0kai.thekey.stone.ksp.helpers.itemholder + +import com.github.klee0kai.stone.__hidden__.types.holders.MapItemHolder +import com.github.klee0kai.stone.__hidden__.types.holders.StoneRefType +import com.github.klee0kai.thekey.stone.ksp.poet.genProperty +import com.google.devtools.ksp.symbol.KSType +import com.google.devtools.ksp.symbol.KSValueParameter +import com.squareup.kotlinpoet.KModifier +import com.squareup.kotlinpoet.ParameterizedTypeName.Companion.parameterizedBy +import com.squareup.kotlinpoet.TypeSpec +import com.squareup.kotlinpoet.asClassName +import com.squareup.kotlinpoet.ksp.toClassName + +class SimpleMapItemHolderHelper( + val fieldName: String, + val returnType: KSType, + val nonWrappedReturnType: KSType, + val itemCacheType: ItemCacheType, + val isListCaching: Boolean, + val defRefType: StoneRefType, + val keyParam: KSValueParameter, +) : ItemHolderHelper { + + override fun TypeSpec.Builder.genCacheField() { + val cacheType = MapItemHolder::class.asClassName() + .parameterizedBy( + keyParam.type.resolve().toClassName(), + nonWrappedReturnType.toClassName(), + ) + + genProperty(fieldName, cacheType) { + addModifiers(KModifier.PRIVATE) + initializer("%T(%T.%L)", cacheType, StoneRefType::class, defRefType) + } + } +} \ No newline at end of file diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/itemholder/SingleItemHolderHelper.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/itemholder/SingleItemHolderHelper.kt new file mode 100644 index 00000000..55fea754 --- /dev/null +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/itemholder/SingleItemHolderHelper.kt @@ -0,0 +1,32 @@ +package com.github.klee0kai.thekey.stone.ksp.helpers.itemholder + +import com.github.klee0kai.stone.__hidden__.types.holders.SingleItemHolder +import com.github.klee0kai.stone.__hidden__.types.holders.StoneRefType +import com.github.klee0kai.thekey.stone.ksp.poet.genProperty +import com.google.devtools.ksp.symbol.KSType +import com.squareup.kotlinpoet.KModifier +import com.squareup.kotlinpoet.ParameterizedTypeName.Companion.parameterizedBy +import com.squareup.kotlinpoet.TypeSpec +import com.squareup.kotlinpoet.asClassName +import com.squareup.kotlinpoet.ksp.toClassName + +class SingleItemHolderHelper( + val fieldName: String, + val returnType: KSType, + val nonWrappedReturnType: KSType, + val itemCacheType: ItemCacheType, + val isListCaching: Boolean, + val defRefType: StoneRefType, +) : ItemHolderHelper { + + override fun TypeSpec.Builder.genCacheField() { + val cacheType = SingleItemHolder::class.asClassName() + .parameterizedBy(nonWrappedReturnType.toClassName()) + + genProperty(fieldName, cacheType) { + addModifiers(KModifier.PRIVATE) + initializer("%T(%T.%L)", cacheType, StoneRefType::class, defRefType) + } + } + +} \ No newline at end of file diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/ksp/KSClassDeclarationExt.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/ksp/KSClassDeclarationExt.kt index fb75899a..1fd78c7a 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/ksp/KSClassDeclarationExt.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/ksp/KSClassDeclarationExt.kt @@ -6,17 +6,22 @@ import com.google.devtools.ksp.getDeclaredFunctions import com.google.devtools.ksp.symbol.KSClassDeclaration import com.google.devtools.ksp.symbol.KSDeclaration import com.google.devtools.ksp.symbol.KSFunctionDeclaration -import com.google.devtools.ksp.symbol.KSValueParameter +import com.google.devtools.ksp.symbol.KSType import com.squareup.kotlinpoet.ClassName import kotlin.reflect.KClass fun KSClassDeclaration.findConstructor( - parameters: List, + parameters: List, ): KSFunctionDeclaration? = getDeclaredFunctions().firstOrNull { function -> function.simpleName.asString() == "" - && parameters.map { it.type } == function.parameters.map { it.type } + && function.parameters.all { it.type.resolve() in parameters || it.hasDefault } } +fun KSDeclaration.isAnyType( + vararg cl: KClass<*>, +) = cl.any { isType(it) } + + fun KSDeclaration.isType(cl: KClass<*>): Boolean = qualifiedName?.asString() == cl.qualifiedName.toString() fun KSDeclaration.isType(cl: ClassName): Boolean = qualifiedName?.asString() == cl.toString() diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/ksp/KSFunctionDeclarationExt.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/ksp/KSFunctionDeclarationExt.kt index eb128f96..421ae687 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/ksp/KSFunctionDeclarationExt.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/ksp/KSFunctionDeclarationExt.kt @@ -1,6 +1,7 @@ package com.github.klee0kai.thekey.stone.ksp.ksp import com.google.devtools.ksp.symbol.KSFunctionDeclaration +import com.google.devtools.ksp.symbol.KSValueParameter fun KSFunctionDeclaration.isSameMethods( other: KSFunctionDeclaration, @@ -17,4 +18,17 @@ fun KSFunctionDeclaration.isSameMethods( } return true +} + +fun KSFunctionDeclaration.joinInvokeArguments( + availableVariables: List, +): String { + return parameters.mapNotNull { parameter -> + val availableVariable = availableVariables.firstOrNull { it.type.resolve() == parameter.type.resolve() } + if (availableVariable != null) { + "${parameter.name!!.asString()} = ${availableVariable.name!!.asString()}" + } else { + null + } + }.joinToString(", ") } \ No newline at end of file diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/ksp/arch/SymbolsToProcess.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/ksp/arch/SymbolsToProcess.kt index 98c80f45..1f29ef01 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/ksp/arch/SymbolsToProcess.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/ksp/arch/SymbolsToProcess.kt @@ -7,7 +7,7 @@ data class SymbolsToProcess( val symbolsForReprocessing: List, ) -fun SymbolsToProcess.takeOnly( +fun SymbolsToProcess.nowTakeOnly( takeSymbolsCount: Int, ): SymbolsToProcess { return copy( @@ -16,6 +16,15 @@ fun SymbolsToProcess.takeOnly( ) } +fun SymbolsToProcess.filter( + filter: (KSAnnotated) -> Boolean, +): SymbolsToProcess { + return copy( + symbolsForProcessing = symbolsForProcessing.filter(filter), + symbolsForReprocessing = symbolsForReprocessing.filter(filter), + ) +} + fun SymbolsToProcess.forceProcess( filter: (KSAnnotated) -> Boolean = { false }, ): SymbolsToProcess { diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/GenModuleFactoryProcessor.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/GenModuleFactoryProcessor.kt index 804ad82f..812b10f5 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/GenModuleFactoryProcessor.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/GenModuleFactoryProcessor.kt @@ -11,6 +11,7 @@ import com.github.klee0kai.thekey.stone.ksp.ksp.arch.SymbolsToProcess import com.github.klee0kai.thekey.stone.ksp.ksp.arch.TargetFileProcessor import com.github.klee0kai.thekey.stone.ksp.ksp.findConstructor import com.github.klee0kai.thekey.stone.ksp.ksp.getAllMethods +import com.github.klee0kai.thekey.stone.ksp.ksp.joinInvokeArguments import com.github.klee0kai.thekey.stone.ksp.poet.genClass import com.github.klee0kai.thekey.stone.ksp.poet.genFileSpec import com.github.klee0kai.thekey.stone.ksp.poet.genFun @@ -36,7 +37,6 @@ class GenModuleFactoryProcessor : TargetFileProcessor { ) = SymbolsToProcess( symbolsForProcessing = resolver .getSymbolsWithAnnotation(Module::class.asClassName().canonicalName) - .take(2) .toList(), symbolsForReprocessing = emptyList(), ) @@ -68,7 +68,6 @@ class GenModuleFactoryProcessor : TargetFileProcessor { addSuperinterface(IModuleFactory::class) addModifiers(KModifier.OPEN) - validSymbol.getAllMethods(false, false, "") .forEach { function -> if (!function.modifiers.contains(Modifier.ABSTRACT) && moduleCl.classKind != ClassKind.INTERFACE) return@forEach @@ -77,7 +76,10 @@ class GenModuleFactoryProcessor : TargetFileProcessor { val bindInstanceAnn = function.getAnnotationsByType(BindInstance::class) .firstOrNull() - val constructorFun by lazy { returnCl.findConstructor(function.parameters) } + val constructorFun by lazy { + returnCl.findConstructor( + parameters = function.parameters.map { it.type.resolve() }) + } genFun(function.simpleName.asString()) { addModifiers(KModifier.OVERRIDE) @@ -94,7 +96,7 @@ class GenModuleFactoryProcessor : TargetFileProcessor { addStatement( "return %T( %L )", returnCl.toClassName(), - function.parameters.joinToString(", ") { it.name?.asString() ?: "it" }, + constructorFun!!.joinInvokeArguments(function.parameters), ) } diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/GenModuleProcessor.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/GenModuleProcessor.kt index ede46ec9..7d82d99b 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/GenModuleProcessor.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/GenModuleProcessor.kt @@ -7,6 +7,9 @@ import com.github.klee0kai.stone.annotations.module.BindInstance import com.github.klee0kai.stone.annotations.module.Module import com.github.klee0kai.stone.annotations.module.Provide import com.github.klee0kai.thekey.stone.ksp.helpers.* +import com.github.klee0kai.thekey.stone.ksp.helpers.itemholder.ItemHolderHelper +import com.github.klee0kai.thekey.stone.ksp.helpers.itemholder.of +import com.github.klee0kai.thekey.stone.ksp.helpers.itemholder.toItemCacheType import com.github.klee0kai.thekey.stone.ksp.ksp.arch.GenSpec import com.github.klee0kai.thekey.stone.ksp.ksp.arch.SymbolsToProcess import com.github.klee0kai.thekey.stone.ksp.ksp.arch.TargetFileProcessor @@ -47,7 +50,6 @@ class GenModuleProcessor : TargetFileProcessor { ) = SymbolsToProcess( symbolsForProcessing = resolver .getSymbolsWithAnnotation(Module::class.asClassName().canonicalName) - .take(2) .toList(), symbolsForReprocessing = emptyList(), ) @@ -67,8 +69,13 @@ class GenModuleProcessor : TargetFileProcessor { val componentCl = resolver.findComponentForModuleOrDep(moduleCl.toClassName()) .firstOrNull() - val identifierTypes = componentCl?.allIdentifierTypes - val wrapperTypes = componentCl?.wrapperProviders + val identifierTypes = componentCl + ?.allIdentifierTypes?.toList() + ?: emptyList() + + val wrapperTypes = componentCl + ?.wrapperProviders?.toList() + ?: emptyList() val genModuleClassName = moduleCl.moduleStoneClName @@ -93,20 +100,36 @@ class GenModuleProcessor : TargetFileProcessor { validSymbol.getAllMethods(false, false, "") .forEachIndexed { funIdx, function -> - val bindAnn = function.getAnnotationsByType(BindInstance::class).firstOrNull() val provideAnn = function.getAnnotationsByType(Provide::class).firstOrNull() + val idArguments = function.parameters + .filter { it.type.resolve() in identifierTypes } + + val returnType = function.returnType?.resolve() ?: return@forEachIndexed + val nonWrappedType = returnType.noWrappedType(wrapperTypes) + val isListReturnType = nonWrappedType.isListType() + + when { + bindAnn != null -> { - if (provideAnn != null) { - genProperty("${function.simpleName.asString()}${funIdx}", moduleCl.toClassName()) { - addModifiers(KModifier.OPEN) - mutable(true) - initializer("%T()", moduleCl.factoryStoneClName) } + provideAnn == null || provideAnn.cache == Provide.CacheType.Factory -> { - } + } + else -> { + val itemHolderHelper = ItemHolderHelper.of( + fieldName = "${function.simpleName.asString()}$funIdx", + returnType = returnType, + idArguments = idArguments, + cacheType = provideAnn.cache.toItemCacheType() ?: return@forEachIndexed, + ) + with(itemHolderHelper) { + genCacheField() + } + } + } } From 679ef6c0fccf58e477f34d5550533b50b69f7993 Mon Sep 17 00:00:00 2001 From: klee0kai Date: Sun, 23 Nov 2025 09:28:40 +0100 Subject: [PATCH 028/122] wrapper helper. desing --- .../stone/ksp/helpers/StoneFileNamesExt.kt | 2 + .../stone/ksp/helpers/TypeHelpersExt.kt | 11 ++ .../stone/ksp/helpers/wrap/FormatInList.kt | 12 ++ .../stone/ksp/helpers/wrap/FormatSimple.kt | 13 +++ .../stone/ksp/helpers/wrap/WrapHelper.kt | 102 ++++++++++++++++ .../thekey/stone/ksp/helpers/wrap/WrapType.kt | 14 +++ .../thekey/stone/ksp/poet/FunSpecDsl.kt | 24 ++++ .../thekey/stone/ksp/poet/TypeSpecDsl.kt | 19 +++ .../ksp/poet/smartcode/CollectedSmartCode.kt | 3 +- .../poet/smartcode/SmartCodeScopeBuilder.kt | 3 +- .../ksp/target/GenModuleFactoryProcessor.kt | 9 +- .../stone/ksp/target/GenModuleProcessor.kt | 110 ++++++++++++++---- .../klee0kai/stone/__hidden__/IModule.kt | 14 ++- 13 files changed, 298 insertions(+), 38 deletions(-) create mode 100644 stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/wrap/FormatInList.kt create mode 100644 stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/wrap/FormatSimple.kt create mode 100644 stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/wrap/WrapHelper.kt create mode 100644 stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/wrap/WrapType.kt create mode 100644 stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/poet/FunSpecDsl.kt diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/StoneFileNamesExt.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/StoneFileNamesExt.kt index 0c904694..7e3c3532 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/StoneFileNamesExt.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/StoneFileNamesExt.kt @@ -1,6 +1,7 @@ package com.github.klee0kai.thekey.stone.ksp.helpers import com.google.devtools.ksp.symbol.KSClassDeclaration +import com.google.devtools.ksp.symbol.KSFunctionDeclaration import com.squareup.kotlinpoet.ClassName val String.componentClName: String get() = "${this}StoneComponent" @@ -15,6 +16,7 @@ val String.hiddenModuleClName: String get() = "${this}_HMStone" val String.wrapperClName: String get() = "${this}_TWStone" +val KSFunctionDeclaration.cacheControlMethodName get() = "__" + simpleName + "_cache" val KSClassDeclaration.componentStoneClName get() = ClassName( diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/TypeHelpersExt.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/TypeHelpersExt.kt index de6c1f91..7a5f79d4 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/TypeHelpersExt.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/TypeHelpersExt.kt @@ -3,6 +3,10 @@ package com.github.klee0kai.thekey.stone.ksp.helpers import com.github.klee0kai.thekey.stone.ksp.ksp.isAnyType import com.google.devtools.ksp.symbol.KSClassDeclaration import com.google.devtools.ksp.symbol.KSType +import com.squareup.kotlinpoet.ParameterizedTypeName.Companion.parameterizedBy +import com.squareup.kotlinpoet.TypeName +import com.squareup.kotlinpoet.asClassName +import com.squareup.kotlinpoet.ksp.toClassName fun KSType.isListType( ): Boolean { @@ -36,3 +40,10 @@ fun KSType.noWrappedType( } return this } + +fun KSType.listWrapTypeIfNeed( + wrappedTypes: List, +): TypeName { + if (!isListType()) return noWrappedType(wrappedTypes).toClassName() + return List::class.asClassName().parameterizedBy(noWrappedType(wrappedTypes).toClassName()) +} diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/wrap/FormatInList.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/wrap/FormatInList.kt new file mode 100644 index 00000000..cafc921f --- /dev/null +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/wrap/FormatInList.kt @@ -0,0 +1,12 @@ +package com.github.klee0kai.thekey.stone.ksp.helpers.wrap + +import com.github.klee0kai.thekey.stone.ksp.poet.smartcode.SmartCodeScopeBuilder + +fun interface FormatInList { + + /** + * @param itemTransformFun format each type + * @return + */ + fun SmartCodeScopeBuilder.formatCode(itemTransformFun: FormatSimple) +} diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/wrap/FormatSimple.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/wrap/FormatSimple.kt new file mode 100644 index 00000000..80516d81 --- /dev/null +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/wrap/FormatSimple.kt @@ -0,0 +1,13 @@ +package com.github.klee0kai.thekey.stone.ksp.helpers.wrap + +import com.github.klee0kai.thekey.stone.ksp.poet.smartcode.SmartCodeScopeBuilder + + +fun interface FormatSimple { + + /** + * @param code code witch return original type + * @return code witch return wanna type + */ + fun SmartCodeScopeBuilder.formatCode(or: SmartCodeScopeBuilder) +} diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/wrap/WrapHelper.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/wrap/WrapHelper.kt new file mode 100644 index 00000000..a421fdc9 --- /dev/null +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/wrap/WrapHelper.kt @@ -0,0 +1,102 @@ +package com.github.klee0kai.thekey.stone.ksp.helpers.wrap + +import com.github.klee0kai.stone.weakref.Ref +import com.github.klee0kai.stone.wrappers.AsyncCoroutineProvide +import com.github.klee0kai.stone.wrappers.LazyProvide +import com.github.klee0kai.stone.wrappers.PhantomProvide +import com.squareup.kotlinpoet.ParameterizedTypeName.Companion.parameterizedBy +import com.squareup.kotlinpoet.TypeName +import com.squareup.kotlinpoet.asClassName +import java.lang.ref.Reference +import java.lang.ref.SoftReference +import java.lang.ref.WeakReference +import javax.inject.Provider + +class WrapHelper { + + var wrapTypes = HashMap() + + init { + fillStdWrappers() + } + + private fun fillStdWrappers() { + for (cl in listOf( + WeakReference::class, + SoftReference::class, + Reference::class + )) { + val wrapper = cl.asClassName() + val creator = if (cl != Reference::class) wrapper else WeakReference::class.asClassName() + + val wrapType = WrapType( + isNoCachingWrapper = false, + typeName = wrapper, + wrap = FormatSimple { or -> + providingType = or.providingType?.let { + wrapper.parameterizedBy(it) + } + TODO() + }, + unwrap = FormatSimple { or -> +// providingType = or.providingType?.let { +// +// } + TODO() + }, + ) + wrapTypes.putIfAbsent(wrapType.typeName, wrapType) + + } + + for (cl in listOf( + PhantomProvide::class, + Ref::class, + Provider::class, + LazyProvide::class, + AsyncCoroutineProvide::class, + )) { + val wrapper = cl.asClassName() + + val wrapType = WrapType( + typeName = wrapper, + isNoCachingWrapper = cl != LazyProvide::class.java && cl != AsyncCoroutineProvide::class.java, + isAsyncProvider = true, + wrap = FormatSimple { or -> + TODO() + }, + unwrap = FormatSimple { or -> + TODO() + } + ) + + wrapTypes.putIfAbsent(wrapType.typeName, wrapType) + } + + for (cl in listOf( + List::class, + Array::class, + MutableList::class, + MutableCollection::class + )) { + + val wrapper = cl.asClassName() + + val wrapType = WrapType( + typeName = wrapper, + wrap = FormatSimple { or -> + TODO() + }, + unwrap = FormatSimple { or -> + TODO() + }, + inListFormat = FormatInList { or -> + TODO() + } + ) + + + } + + } +} \ No newline at end of file diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/wrap/WrapType.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/wrap/WrapType.kt new file mode 100644 index 00000000..fb3072d0 --- /dev/null +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/wrap/WrapType.kt @@ -0,0 +1,14 @@ +package com.github.klee0kai.thekey.stone.ksp.helpers.wrap + +import com.squareup.kotlinpoet.TypeName + +class WrapType( + val typeName: TypeName, + val unwrap: FormatSimple, + val wrap: FormatSimple, + val isAsyncProvider: Boolean = true, + val isNoCachingWrapper: Boolean = true, + val inListFormat: FormatInList? = null, +) { + val isList: Boolean get() = inListFormat != null +} diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/poet/FunSpecDsl.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/poet/FunSpecDsl.kt new file mode 100644 index 00000000..25724522 --- /dev/null +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/poet/FunSpecDsl.kt @@ -0,0 +1,24 @@ +package com.github.klee0kai.thekey.stone.ksp.poet + +import com.squareup.kotlinpoet.CodeBlock +import com.squareup.kotlinpoet.FunSpec + +fun CodeBlock.Builder.controlFlow( + controlFlow: String, + vararg args: Any, + block: CodeBlock.Builder.() -> Unit, +) = apply { + beginControlFlow(controlFlow, args) + .add(CodeBlock.builder().apply(block).build()) + .endControlFlow() +} + +fun FunSpec.Builder.controlFlow( + controlFlow: String, + vararg args: Any, + block: CodeBlock.Builder.() -> Unit, +) = apply { + beginControlFlow(controlFlow, args) + .addCode(CodeBlock.builder().apply(block).build()) + .endControlFlow() +} \ No newline at end of file diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/poet/TypeSpecDsl.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/poet/TypeSpecDsl.kt index 07cffc6d..64040afb 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/poet/TypeSpecDsl.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/poet/TypeSpecDsl.kt @@ -1,6 +1,10 @@ package com.github.klee0kai.thekey.stone.ksp.poet +import com.github.klee0kai.thekey.stone.ksp.target.declareSameParameters +import com.github.klee0kai.thekey.stone.ksp.target.isSuspend +import com.google.devtools.ksp.symbol.KSFunctionDeclaration import com.squareup.kotlinpoet.* +import com.squareup.kotlinpoet.ksp.toClassName @PoetDsl fun TypeSpec.Builder.genProperty( @@ -65,6 +69,21 @@ fun TypeSpec.Builder.genFun( ) } +@PoetDsl +fun TypeSpec.Builder.genOverrideFun( + func: KSFunctionDeclaration, + block: FunSpec.Builder.() -> Unit = {}, +) { + genFun(func.simpleName.asString()) { + addModifiers(KModifier.OVERRIDE) + if (func.isSuspend) addModifiers(KModifier.SUSPEND) + declareSameParameters(func) + func.returnType?.resolve()?.toClassName()?.let { returns(it) } + + block() + } +} + @PoetDsl fun TypeSpec.Builder.genPrimaryConstructor( block: FunSpec.Builder.() -> Unit = {}, diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/poet/smartcode/CollectedSmartCode.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/poet/smartcode/CollectedSmartCode.kt index 9037b147..19fe5221 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/poet/smartcode/CollectedSmartCode.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/poet/smartcode/CollectedSmartCode.kt @@ -2,12 +2,13 @@ package com.github.klee0kai.thekey.stone.ksp.poet.smartcode import com.squareup.kotlinpoet.ClassName import com.squareup.kotlinpoet.CodeBlock +import com.squareup.kotlinpoet.TypeName class CollectedSmartCode( val codeBlock: CodeBlock, val declareLocalVariable: Pair? = null, val usedVariables: Set = emptySet(), - val providingType: ClassName? = null, + val providingType: TypeName? = null, ) { class ScopedBuilder( diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/poet/smartcode/SmartCodeScopeBuilder.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/poet/smartcode/SmartCodeScopeBuilder.kt index bf3ebc6b..3c129e1c 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/poet/smartcode/SmartCodeScopeBuilder.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/poet/smartcode/SmartCodeScopeBuilder.kt @@ -3,13 +3,14 @@ package com.github.klee0kai.thekey.stone.ksp.poet.smartcode import com.github.klee0kai.thekey.stone.ksp.poet.PoetDsl import com.squareup.kotlinpoet.ClassName import com.squareup.kotlinpoet.CodeBlock +import com.squareup.kotlinpoet.TypeName open class SmartCodeScopeBuilder() : SimpleCodeBuilder { val codes = mutableListOf() var declareLocalVariable: Pair? = null - var providingType: ClassName? = null + var providingType: TypeName? = null override fun collect( declaredVariables: Map, diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/GenModuleFactoryProcessor.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/GenModuleFactoryProcessor.kt index 812b10f5..2dd8280c 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/GenModuleFactoryProcessor.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/GenModuleFactoryProcessor.kt @@ -14,8 +14,8 @@ import com.github.klee0kai.thekey.stone.ksp.ksp.getAllMethods import com.github.klee0kai.thekey.stone.ksp.ksp.joinInvokeArguments import com.github.klee0kai.thekey.stone.ksp.poet.genClass import com.github.klee0kai.thekey.stone.ksp.poet.genFileSpec -import com.github.klee0kai.thekey.stone.ksp.poet.genFun import com.github.klee0kai.thekey.stone.ksp.poet.genLibComment +import com.github.klee0kai.thekey.stone.ksp.poet.genOverrideFun import com.google.devtools.ksp.KspExperimental import com.google.devtools.ksp.containingFile import com.google.devtools.ksp.getAnnotationsByType @@ -81,12 +81,7 @@ class GenModuleFactoryProcessor : TargetFileProcessor { parameters = function.parameters.map { it.type.resolve() }) } - genFun(function.simpleName.asString()) { - addModifiers(KModifier.OVERRIDE) - declareSameParameters(function) - returns(returnCl.toClassName()) - if (function.isSuspend) addModifiers(KModifier.SUSPEND) - + genOverrideFun(function) { when { bindInstanceAnn != null -> { addStatement("return null") diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/GenModuleProcessor.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/GenModuleProcessor.kt index 7d82d99b..def0ef0d 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/GenModuleProcessor.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/GenModuleProcessor.kt @@ -3,6 +3,8 @@ package com.github.klee0kai.thekey.stone.ksp.target import com.github.klee0kai.stone.__hidden__.IModule +import com.github.klee0kai.stone.__hidden__.types.holders.SingleItemHolder +import com.github.klee0kai.stone.__hidden__.types.holders.StoneRefType import com.github.klee0kai.stone.annotations.module.BindInstance import com.github.klee0kai.stone.annotations.module.Module import com.github.klee0kai.stone.annotations.module.Provide @@ -15,16 +17,16 @@ import com.github.klee0kai.thekey.stone.ksp.ksp.arch.SymbolsToProcess import com.github.klee0kai.thekey.stone.ksp.ksp.arch.TargetFileProcessor import com.github.klee0kai.thekey.stone.ksp.ksp.getAllMethods import com.github.klee0kai.thekey.stone.ksp.poet.* +import com.github.klee0kai.thekey.stone.ksp.poet.smartcode.SmartCodeScopeBuilder import com.google.devtools.ksp.KspExperimental import com.google.devtools.ksp.containingFile import com.google.devtools.ksp.getAnnotationsByType import com.google.devtools.ksp.processing.Dependencies import com.google.devtools.ksp.processing.KSPLogger import com.google.devtools.ksp.processing.Resolver -import com.google.devtools.ksp.symbol.ClassKind -import com.google.devtools.ksp.symbol.KSAnnotated -import com.google.devtools.ksp.symbol.KSClassDeclaration +import com.google.devtools.ksp.symbol.* import com.squareup.kotlinpoet.KModifier +import com.squareup.kotlinpoet.ParameterizedTypeName.Companion.parameterizedBy import com.squareup.kotlinpoet.TypeSpec import com.squareup.kotlinpoet.asClassName import com.squareup.kotlinpoet.ksp.toClassName @@ -39,11 +41,20 @@ class GenModuleProcessor : TargetFileProcessor { const val initCachesFromMethodName: String = "__initCachesFrom" const val updateBindInstancesFrom: String = "__updateBindInstancesFrom" const val bindMethodName: String = "__bind" - const val getFactoryMethodName: String = "__getFactory" const val switchRefMethodName: String = "__switchRef" const val clearNullsMethodName: String = "__clearNulls" } + class DelayedCodeBlocks( + val initMethodCode: SmartCodeScopeBuilder = SmartCodeScopeBuilder(), + val initCachesFromMethodName: SmartCodeScopeBuilder = SmartCodeScopeBuilder(), + val bindMethodName: SmartCodeScopeBuilder = SmartCodeScopeBuilder(), + val getFactoryMethodName: SmartCodeScopeBuilder = SmartCodeScopeBuilder(), + val switchRefMethodName: SmartCodeScopeBuilder = SmartCodeScopeBuilder(), + val updateBindInstancesFrom: SmartCodeScopeBuilder = SmartCodeScopeBuilder(), + val clearNullsMethodName: SmartCodeScopeBuilder = SmartCodeScopeBuilder(), + ) + override suspend fun findSymbolsToProcess( resolver: Resolver, @@ -79,6 +90,7 @@ class GenModuleProcessor : TargetFileProcessor { val genModuleClassName = moduleCl.moduleStoneClName + val fileSpec = genFileSpec(genModuleClassName.packageName, genModuleClassName.simpleName) { genLibComment() @@ -90,13 +102,7 @@ class GenModuleProcessor : TargetFileProcessor { } addSuperinterface(IModule::class) addModifiers(KModifier.OPEN) - - - genProperty(factoryFieldName, moduleCl.toClassName()) { - addModifiers(KModifier.PRIVATE) - mutable(true) - initializer("%T()", moduleCl.factoryStoneClName) - } + val codeBlocks = DelayedCodeBlocks() validSymbol.getAllMethods(false, false, "") .forEachIndexed { funIdx, function -> @@ -111,11 +117,27 @@ class GenModuleProcessor : TargetFileProcessor { when { bindAnn != null -> { + val itemHolderHelper = ItemHolderHelper.of( + fieldName = "${function.simpleName.asString()}$funIdx", + returnType = returnType, + idArguments = idArguments, + cacheType = bindAnn.cache.toItemCacheType(), + ) + with(itemHolderHelper) { + genCacheField() + genOverrideFun(function) { + + } + } } provideAnn == null || provideAnn.cache == Provide.CacheType.Factory -> { - + genProvideCachedFun( + function, + idArguments, + wrapperTypes, + ) } else -> { @@ -127,6 +149,10 @@ class GenModuleProcessor : TargetFileProcessor { ) with(itemHolderHelper) { genCacheField() + + genOverrideFun(function) { + + } } } } @@ -134,7 +160,7 @@ class GenModuleProcessor : TargetFileProcessor { } - genIModelMethods(moduleCl) + genIModelMethods(moduleCl, codeBlocks) } } @@ -145,37 +171,75 @@ class GenModuleProcessor : TargetFileProcessor { ) } - private fun TypeSpec.Builder.genIModelMethods( - moduleCl: KSClassDeclaration, + private fun TypeSpec.Builder.genProvideCachedFun( + function: KSFunctionDeclaration, + idArguments: List, + wrapperTypes: List, ) { - genFun(initMethodName) { + genOverrideFun(function) { + controlFlow("if (%L.get() != null )", overridedModuleFieldName) { + addStatement( + "%T cached = %L.get().%L( null %L ) ", + function.returnType!!.resolve().listWrapTypeIfNeed(wrapperTypes), + overridedModuleFieldName, function.cacheControlMethodName, + idArguments.joinToString { ", ${it.name}" }, + ) + add("if (cached != null ) return ") + TODO() + } } + } - genFun(initCachesFromMethodName) { - + private fun TypeSpec.Builder.genIModelMethods( + moduleCl: KSClassDeclaration, + codeBlocks: DelayedCodeBlocks, + + ) { + genProperty( + name = factoryFieldName, + type = moduleCl.toClassName(), + ) { + addModifiers(KModifier.OVERRIDE) + mutable(true) + initializer("%T()", moduleCl.factoryStoneClName) } - genFun(bindMethodName) { + val cacheControlHolder = SingleItemHolder::class.asClassName() + .parameterizedBy(moduleCl.cacheControlStoneClName) + genProperty( + name = overridedModuleFieldName, + type = cacheControlHolder, + ) { + mutable(true) + initializer("%T(%T.WeakObject)", cacheControlHolder, StoneRefType::class) + } + genFun(initMethodName) { + codeBlocks.initMethodCode.collect(declaredVariables = emptyMap()) } - genFun(getFactoryMethodName) { + genFun(initCachesFromMethodName) { + codeBlocks.initCachesFromMethodName.collect(declaredVariables = emptyMap()) + } + genFun(bindMethodName) { + codeBlocks.bindMethodName.collect(declaredVariables = emptyMap()) } genFun(switchRefMethodName) { - + codeBlocks.switchRefMethodName.collect(declaredVariables = emptyMap()) } genFun(updateBindInstancesFrom) { - + codeBlocks.updateBindInstancesFrom.collect(declaredVariables = emptyMap()) } genFun(clearNullsMethodName) { - + codeBlocks.clearNullsMethodName.collect(declaredVariables = emptyMap()) } } + } \ No newline at end of file diff --git a/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/__hidden__/IModule.kt b/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/__hidden__/IModule.kt index fa45ba86..7dc5cd7e 100644 --- a/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/__hidden__/IModule.kt +++ b/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/__hidden__/IModule.kt @@ -4,6 +4,14 @@ package com.github.klee0kai.stone.__hidden__ * Stone Private class */ interface IModule { + + /** + * get component's factory + * + * @return + */ + val factory: Any? + /** * Init module * @@ -33,12 +41,6 @@ interface IModule { */ fun __bind(`object`: Any?): Boolean - /** - * get component's factory - * - * @return - */ - fun __getFactory(): Any? /** * TODO Switch cache type for scope From 3b4eaacb7217a351239e50c251960877f83b8ca3 Mon Sep 17 00:00:00 2001 From: klee0kai Date: Sun, 23 Nov 2025 16:50:00 +0100 Subject: [PATCH 029/122] migrate provide cached methods --- .../klee0kai/thekey/stone/ksp/Processor.kt | 28 +- .../exceptions/ClassNotFoundStoneException.kt | 13 + .../ksp/exceptions/ExceptionStringBuilder.kt | 499 ++++++++++++++++++ .../ImplementMethodStoneException.kt | 13 + .../exceptions/IncorrectSignatureException.kt | 13 + .../exceptions/ObjectNotProvidedException.kt | 13 + ...PrimitiveTypeNonSupportedStoneException.kt | 13 + .../ksp/exceptions/RecursiveProviding.kt | 13 + .../stone/ksp/exceptions/StoneException.kt | 21 + .../stone/ksp/helpers/StoneFileNamesExt.kt | 2 +- .../helpers/itemholder/ItemHolderHelper.kt | 12 +- .../itemholder/MultiKeyMapItemHolderHelper.kt | 33 ++ .../itemholder/SimpleMapItemHolderHelper.kt | 30 ++ .../itemholder/SingleItemHolderHelper.kt | 22 + .../stone/ksp/helpers/wrap/ClassNameUtils.kt | 79 +++ .../stone/ksp/helpers/wrap/FormatInList.kt | 8 +- .../stone/ksp/helpers/wrap/FormatSimple.kt | 6 +- .../stone/ksp/helpers/wrap/WrapHelper.kt | 275 ++++++++-- .../thekey/stone/ksp/poet/FunSpecDsl.kt | 4 +- .../ksp/poet/smartcode/CollectedSmartCode.kt | 44 -- .../ksp/poet/smartcode/SimpleCodeBuilder.kt | 12 - .../stone/ksp/poet/smartcode/SmartCode.kt | 56 ++ .../ksp/poet/smartcode/SmartCodeBlock.kt | 9 + .../stone/ksp/poet/smartcode/SmartCodeExt.kt | 77 ++- .../poet/smartcode/SmartCodeScopeBuilder.kt | 56 -- .../thekey/stone/ksp/property/Property.kt | 68 +++ .../stone/ksp/target/GenModuleProcessor.kt | 101 +++- .../__hidden__/types/holders/MapItemHolder.kt | 8 +- .../types/holders/SingleItemHolder.kt | 8 +- 29 files changed, 1280 insertions(+), 256 deletions(-) create mode 100644 stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/exceptions/ClassNotFoundStoneException.kt create mode 100644 stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/exceptions/ExceptionStringBuilder.kt create mode 100644 stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/exceptions/ImplementMethodStoneException.kt create mode 100644 stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/exceptions/IncorrectSignatureException.kt create mode 100644 stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/exceptions/ObjectNotProvidedException.kt create mode 100644 stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/exceptions/PrimitiveTypeNonSupportedStoneException.kt create mode 100644 stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/exceptions/RecursiveProviding.kt create mode 100644 stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/exceptions/StoneException.kt create mode 100644 stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/wrap/ClassNameUtils.kt delete mode 100644 stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/poet/smartcode/CollectedSmartCode.kt delete mode 100644 stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/poet/smartcode/SimpleCodeBuilder.kt create mode 100644 stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/poet/smartcode/SmartCode.kt create mode 100644 stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/poet/smartcode/SmartCodeBlock.kt delete mode 100644 stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/poet/smartcode/SmartCodeScopeBuilder.kt create mode 100644 stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/property/Property.kt diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/Processor.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/Processor.kt index 69b54ee8..5a8fab5c 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/Processor.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/Processor.kt @@ -1,6 +1,7 @@ package com.github.klee0kai.thekey.stone.ksp import com.github.klee0kai.thekey.stone.ksp.coroutines.LaunchConductor +import com.github.klee0kai.thekey.stone.ksp.exceptions.StoneException import com.github.klee0kai.thekey.stone.ksp.ksp.arch.GenSpec import com.github.klee0kai.thekey.stone.ksp.ksp.arch.filter import com.github.klee0kai.thekey.stone.ksp.ksp.arch.forceProcess @@ -111,17 +112,22 @@ class Processor( } globalSymbolsForReprocessing.addAll(symbols.symbolsForReprocessing) - genSpecs.addAll( - symbols.symbolsForProcessing - .mapNotNull { targetSymbol -> - processor.process( - validSymbol = targetSymbol, - resolver = resolver, - options = options, - logger = logger, - ) - } - ) + try { + genSpecs.addAll( + symbols.symbolsForProcessing + .mapNotNull { targetSymbol -> + processor.process( + validSymbol = targetSymbol, + resolver = resolver, + options = options, + logger = logger, + ) + } + ) + } catch (e: StoneException) { + logger.error(e.toString(), e.findErrorElement()) + } + } } } diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/exceptions/ClassNotFoundStoneException.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/exceptions/ClassNotFoundStoneException.kt new file mode 100644 index 00000000..61dd1371 --- /dev/null +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/exceptions/ClassNotFoundStoneException.kt @@ -0,0 +1,13 @@ +package com.github.klee0kai.thekey.stone.ksp.exceptions + +import com.google.devtools.ksp.symbol.KSNode + +class ClassNotFoundStoneException( + message: String? = null, + cause: Throwable? = null, + element: KSNode? = null, +) : StoneException( + message = message, + cause = cause, + element = element, +) diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/exceptions/ExceptionStringBuilder.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/exceptions/ExceptionStringBuilder.kt new file mode 100644 index 00000000..6fdf7db7 --- /dev/null +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/exceptions/ExceptionStringBuilder.kt @@ -0,0 +1,499 @@ +package com.github.klee0kai.thekey.stone.ksp.exceptions + +import com.squareup.kotlinpoet.TypeName +import java.lang.String +import java.util.* +import kotlin.Deprecated +import kotlin.Throwable +import kotlin.text.format + +/** + * Build error message by masks + * Pro-StringBuilder implementation for exceptions + */ +@Deprecated(message = "use kotlin string builder instead") +class ExceptionStringBuilder { + private val sb = StringBuilder() + + fun cannotCreateComponent(componentName: String?): ExceptionStringBuilder { + if (sb.length > 0) sb.append(" ") + sb.append("Cannot create component: ") + sb.append(componentName) + return this + } + + fun cannotCreateWrappersHelper(): ExceptionStringBuilder { + if (sb.length > 0) sb.append(" ") + sb.append("Cannot create wrappers helper ") + return this + } + + fun cannotCreateModule(moduleName: String?): ExceptionStringBuilder { + if (sb.length > 0) sb.append(" ") + sb.append("Cannot create component: ") + sb.append(moduleName) + return this + } + + fun componentsClass(className: String?): ExceptionStringBuilder { + if (sb.length > 0) sb.append(" ") + sb.append( + String.format( + Locale.ROOT, + "Component's class %s", + className + ) + ) + return this + } + + + fun moduleClass(className: String?): ExceptionStringBuilder { + if (sb.length > 0) sb.append(" ") + sb.append( + String.format( + Locale.ROOT, + "Module's class %s", + className + ) + ) + return this + } + + fun dependencyClass(className: String?): ExceptionStringBuilder { + if (sb.length > 0) sb.append(" ") + sb.append( + String.format( + Locale.ROOT, + "Dependency's class %s", + className + ) + ) + return this + } + + + fun wrappersCreatorClass(className: String?): ExceptionStringBuilder { + if (sb.length > 0) sb.append(" ") + sb.append( + String.format( + Locale.ROOT, + "WrappersCreator's class %s", + className + ) + ) + return this + } + + fun wrapperShouldBeGenericType1(className: TypeName): ExceptionStringBuilder { + if (sb.length > 0) sb.append(" ") + sb.append( + String.format( + Locale.ROOT, + "WrapperClass %s should be genericType with one type argument. Like SmthWrapper.class ", + className.toString() + ) + ) + return this + } + + fun method(methodName: kotlin.String?): ExceptionStringBuilder { + if (sb.length > 0) sb.append(" ") + sb.append( + kotlin.String.format( + Locale.ROOT, + "method '%s'", + methodName + ) + ) + return this + } + + + fun classNonFound(className: kotlin.String?): ExceptionStringBuilder { + if (sb.length > 0) sb.append(" ") + sb.append("Class not found: ") + sb.append(className) + sb.append(". Try import class directly.") + return this + } + + fun primitiveTypesNonSupported(typeName: kotlin.String?): ExceptionStringBuilder { + if (sb.length > 0) sb.append(" ") + sb.append("Primitive type non supported: ") + sb.append(typeName) + return this + } + + fun methodPurposeNonDetected(methodName: kotlin.String?, className: kotlin.String?): ExceptionStringBuilder { + if (sb.length > 0) sb.append(" ") + sb.append( + kotlin.String.format( + Locale.ROOT, + "What is purpose for Method '%s'. Declared in %s", + methodName, className + ) + ) + return this + } + + fun errorProvideModuleFactoryRequiredIn( + providingTypeName: kotlin.String?, + className: kotlin.String?, + method: kotlin.String? + ): ExceptionStringBuilder { + if (sb.length > 0) sb.append(" ") + sb.append( + kotlin.String.format( + Locale.ROOT, + "Error provide module %s. Required in %s.%s", + providingTypeName, className, method + ) + ) + return this + } + + fun errorProvideTypeRequiredIn( + providingTypeName: kotlin.String?, + className: kotlin.String?, + method: kotlin.String? + ): ExceptionStringBuilder { + if (sb.length > 0) sb.append(" ") + sb.append( + kotlin.String.format( + Locale.ROOT, + "Error provide type %s. Required in %s.%s", + providingTypeName, className, method + ) + ) + return this + } + + fun errorProvideType(providingTypeName: kotlin.String?): ExceptionStringBuilder { + if (sb.length > 0) sb.append(" ") + sb.append( + kotlin.String.format( + Locale.ROOT, + "Error provide type %s", + providingTypeName + ) + ) + return this + } + + fun shouldNoProvideIdentifierType(providingTypeName: kotlin.String?): ExceptionStringBuilder { + if (sb.length > 0) sb.append(" ") + sb.append( + kotlin.String.format( + Locale.ROOT, + "Should no provide identifier %s", + providingTypeName + ) + ) + return this + } + + fun errorImplementMethod(method: kotlin.String?): ExceptionStringBuilder { + if (sb.length > 0) sb.append(" ") + sb.append( + kotlin.String.format( + Locale.ROOT, + "Error to implement method: '%s'", + method + ) + ) + return this + } + + fun hasIncorrectSignature(): ExceptionStringBuilder { + if (sb.length > 0) sb.append(" ") + sb.append("has incorrect signature") + return this + } + + fun shouldNoHaveAnnotation(annotation: kotlin.String?): ExceptionStringBuilder { + if (sb.length > 0) sb.append(" ") + sb.append( + kotlin.String.format( + Locale.ROOT, + "should not have @%s annotation", + annotation + ) + ) + return this + } + + fun shouldHaveOnlyAnnotations(vararg annotations: kotlin.String?): ExceptionStringBuilder { + if (sb.length > 0) sb.append(" ") + val annList = String.join(", @", *annotations) + sb.append( + kotlin.String.format( + Locale.ROOT, + "should have only @%s annotation", + annList + ) + ) + return this + } + + fun shouldHaveAnnotations(vararg annotations: kotlin.String?): ExceptionStringBuilder { + if (sb.length > 0) sb.append(" ") + val annList = String.join(", @", *annotations) + sb.append( + kotlin.String.format( + Locale.ROOT, + "should have @%s annotation", + annList + ) + ) + return this + } + + + fun shouldNoHaveIdentifiers(identifier: kotlin.String?): ExceptionStringBuilder { + if (sb.length > 0) sb.append(" ") + sb.append( + kotlin.String.format( + Locale.ROOT, + "should not have %s identifiers", + identifier + ) + ) + return this + } + + fun shouldHaveOnlySingleModuleMethod(moduleType: kotlin.String?): ExceptionStringBuilder { + if (sb.length > 0) sb.append(" ") + sb.append( + kotlin.String.format( + Locale.ROOT, + "should have only one module or dependency method. %s has duplicate", + moduleType + ) + ) + return this + } + + fun shouldNoHaveFields(): ExceptionStringBuilder { + if (sb.length > 0) sb.append(" ") + sb.append("should not have fields") + return this + } + + + fun shouldImplementInterface(interfaceType: kotlin.String?): ExceptionStringBuilder { + if (sb.length > 0) sb.append(" ") + sb.append("should implement ") + sb.append(interfaceType) + return this + } + + fun shouldHaveConstructorWithoutArgs(): ExceptionStringBuilder { + if (sb.length > 0) sb.append(" ") + sb.append("should have public constructor without arguments") + return this + } + + fun shouldHaveInjectableClassAsParameter(): ExceptionStringBuilder { + if (sb.length > 0) sb.append(" ") + sb.append("should have an injection class as a parameter") + return this + } + + fun shouldProvideNonPrimitiveObjects(): ExceptionStringBuilder { + if (sb.length > 0) sb.append(" ") + sb.append("should provide non primitive objects") + return this + } + + + fun shouldNoHavePrimitiveArguments(): ExceptionStringBuilder { + if (sb.length > 0) sb.append(" ") + sb.append("should no have primitive arguments") + return this + } + + + fun recursiveProviding(): ExceptionStringBuilder { + if (sb.length > 0) sb.append(" ") + sb.append("Recursive providing detected") + return this + } + + fun constructorNonFound(className: kotlin.String?, argTypes: MutableList): ExceptionStringBuilder { + if (sb.length > 0) sb.append(" ") + sb.append( + kotlin.String.format( + Locale.ROOT, + "No found public constructor for class: %s with args: %s", + className, String.join(", ", argTypes) + ) + ) + return this + } + + + fun typeTransformNonSupport(or: TypeName, dest: TypeName): ExceptionStringBuilder { + if (sb.length > 0) sb.append(" ") + sb.append( + String.format( + Locale.ROOT, + "Type Transform non support %s -> %s", + or.toString(), dest.toString() + ) + ) + return this + } + + + fun componentInitMethodSignatureIncorrect( + className: kotlin.String?, + annotation: kotlin.String? + ): ExceptionStringBuilder { + if (sb.length > 0) sb.append(" ") + sb.append( + kotlin.String.format( + Locale.ROOT, + ("Component's init method have incorrect signature: '%s'. " + + "Method Should have only one %s annotation. " + + "Should have arguments of module or dependencies. " + + "Should be void."), + className, annotation + ) + ) + return this + } + + + fun componentExtOfMethodSignatureIncorrect( + className: kotlin.String?, + annotation: kotlin.String? + ): ExceptionStringBuilder { + if (sb.length > 0) sb.append(" ") + sb.append( + kotlin.String.format( + Locale.ROOT, + ("Component's bindInstance method have incorrect signature: '%s'. " + + "Method Should have only %s annotation and GC scope annotations. " + + "Should have only one argument of providing object. " + + "Providing object should not be primitive or boxed primitive. " + + "Can return only providing object or should be void. "), + className, annotation + ) + ) + return this + } + + fun componentBindInstanceMethodSignatureIncorrect( + className: kotlin.String?, + annotation: kotlin.String? + ): ExceptionStringBuilder { + if (sb.length > 0) sb.append(" ") + sb.append( + kotlin.String.format( + Locale.ROOT, + ("Component's bindInstance method have incorrect signature: '%s'. " + + "Method Should have only %s annotation and GC scope annotations. " + + "Should have only one argument of providing object. " + + "Providing object should not be primitive or boxed primitive. " + + "Can return only providing object or should be void. "), + className, annotation + ) + ) + return this + } + + fun componentGCMethodSignatureIncorrect( + className: kotlin.String?, + annotation: kotlin.String? + ): ExceptionStringBuilder { + if (sb.length > 0) sb.append(" ") + sb.append( + kotlin.String.format( + Locale.ROOT, + ("Component's gc method have incorrect signature: '%s'. " + + "Method Should have only %s annotation and GC scope annotations. " + + "Should no have arguments. " + + "Should be void."), + className, annotation + ) + ) + return this + } + + fun componentSwitchCacheMethodSignatureIncorrect( + className: kotlin.String?, + annotation: kotlin.String? + ): ExceptionStringBuilder { + if (sb.length > 0) sb.append(" ") + sb.append( + kotlin.String.format( + Locale.ROOT, + ("Component's SwitchCache method have incorrect signature: '%s'. " + + "Method Should have only %s annotation and GC scope annotations. " + + "Should no have arguments. " + + "Should be void."), + className, annotation + ) + ) + return this + } + + fun componentProtectInjectedMethodSignatureIncorrect( + className: kotlin.String?, + annotation: kotlin.String? + ): ExceptionStringBuilder { + if (sb.length > 0) sb.append(" ") + sb.append( + kotlin.String.format( + Locale.ROOT, + ("Component's ProtectInjected method have incorrect signature: '%s'. " + + "Method Should have only %s annotation. " + + "Should have only one argument (non primitive and non boxed primitive). " + + "Should be void."), + className, annotation + ) + ) + return this + } + + + fun componentMethodNameBusy(methodName: kotlin.String?): ExceptionStringBuilder { + if (sb.length > 0) sb.append(" ") + sb.append( + kotlin.String.format( + Locale.ROOT, + "Component's method name '%s' busy by lib's private interfaces", + methodName + ) + ) + return this + } + + fun add(mes: kotlin.String?): ExceptionStringBuilder { + if (sb.length > 0) sb.append(" ") + sb.append(mes) + return this + } + + + fun collectCauseMessages(cause: Throwable?): ExceptionStringBuilder { + var cause = cause + while (cause != null) { + if (sb.length > 0) sb.append("\nCaused by: ") + sb.append(cause.message) + cause = cause.cause + } + return this + } + + fun build(): kotlin.String { + return sb.toString() + } + + companion object { + fun createErrorMes(): ExceptionStringBuilder { + return ExceptionStringBuilder() + } + } +} diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/exceptions/ImplementMethodStoneException.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/exceptions/ImplementMethodStoneException.kt new file mode 100644 index 00000000..b93ba1ac --- /dev/null +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/exceptions/ImplementMethodStoneException.kt @@ -0,0 +1,13 @@ +package com.github.klee0kai.thekey.stone.ksp.exceptions + +import com.google.devtools.ksp.symbol.KSNode + +class ImplementMethodStoneException( + message: String? = null, + cause: Throwable? = null, + element: KSNode? = null, +) : StoneException( + message = message, + cause = cause, + element = element, +) diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/exceptions/IncorrectSignatureException.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/exceptions/IncorrectSignatureException.kt new file mode 100644 index 00000000..bf62e497 --- /dev/null +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/exceptions/IncorrectSignatureException.kt @@ -0,0 +1,13 @@ +package com.github.klee0kai.thekey.stone.ksp.exceptions + +import com.google.devtools.ksp.symbol.KSNode + +class IncorrectSignatureException( + message: String? = null, + cause: Throwable? = null, + element: KSNode? = null, +) : StoneException( + message = message, + cause = cause, + element = element, +) \ No newline at end of file diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/exceptions/ObjectNotProvidedException.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/exceptions/ObjectNotProvidedException.kt new file mode 100644 index 00000000..dd145aac --- /dev/null +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/exceptions/ObjectNotProvidedException.kt @@ -0,0 +1,13 @@ +package com.github.klee0kai.thekey.stone.ksp.exceptions + +import com.google.devtools.ksp.symbol.KSNode + +class ObjectNotProvidedException( + message: String? = null, + cause: Throwable? = null, + element: KSNode? = null, +) : StoneException( + message = message, + cause = cause, + element = element, +) diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/exceptions/PrimitiveTypeNonSupportedStoneException.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/exceptions/PrimitiveTypeNonSupportedStoneException.kt new file mode 100644 index 00000000..4ca8f6db --- /dev/null +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/exceptions/PrimitiveTypeNonSupportedStoneException.kt @@ -0,0 +1,13 @@ +package com.github.klee0kai.thekey.stone.ksp.exceptions + +import com.google.devtools.ksp.symbol.KSNode + +class PrimitiveTypeNonSupportedStoneException( + message: String? = null, + cause: Throwable? = null, + element: KSNode? = null, +) : StoneException( + message = message, + cause = cause, + element = element, +) \ No newline at end of file diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/exceptions/RecursiveProviding.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/exceptions/RecursiveProviding.kt new file mode 100644 index 00000000..47705b92 --- /dev/null +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/exceptions/RecursiveProviding.kt @@ -0,0 +1,13 @@ +package com.github.klee0kai.thekey.stone.ksp.exceptions + +import com.google.devtools.ksp.symbol.KSNode + +class RecursiveProviding( + message: String? = null, + cause: Throwable? = null, + element: KSNode? = null, +) : StoneException( + message = message, + cause = cause, + element = element, +) \ No newline at end of file diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/exceptions/StoneException.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/exceptions/StoneException.kt new file mode 100644 index 00000000..d804a74f --- /dev/null +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/exceptions/StoneException.kt @@ -0,0 +1,21 @@ +package com.github.klee0kai.thekey.stone.ksp.exceptions + +import com.google.devtools.ksp.symbol.KSNode + + +open class StoneException( + message: String? = null, + cause: Throwable? = null, + val element: KSNode? = null, +) : IllegalStateException(message, cause) { + + fun findErrorElement(): KSNode? { + var sourceElement: KSNode? = null + if (cause is StoneException) { + sourceElement = (cause as StoneException).findErrorElement() + } + if (sourceElement == null) sourceElement = element + return sourceElement + } + +} diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/StoneFileNamesExt.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/StoneFileNamesExt.kt index 7e3c3532..5ce194b4 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/StoneFileNamesExt.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/StoneFileNamesExt.kt @@ -16,7 +16,7 @@ val String.hiddenModuleClName: String get() = "${this}_HMStone" val String.wrapperClName: String get() = "${this}_TWStone" -val KSFunctionDeclaration.cacheControlMethodName get() = "__" + simpleName + "_cache" +val KSFunctionDeclaration.cacheControlMethodName get() = "__" + simpleName.asString() + "_cache" val KSClassDeclaration.componentStoneClName get() = ClassName( diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/itemholder/ItemHolderHelper.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/itemholder/ItemHolderHelper.kt index f04dae8a..b884095f 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/itemholder/ItemHolderHelper.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/itemholder/ItemHolderHelper.kt @@ -2,8 +2,10 @@ package com.github.klee0kai.thekey.stone.ksp.helpers.itemholder import com.github.klee0kai.thekey.stone.ksp.helpers.isListType import com.github.klee0kai.thekey.stone.ksp.helpers.noWrappedType +import com.github.klee0kai.thekey.stone.ksp.poet.smartcode.SmartCode import com.google.devtools.ksp.symbol.KSType import com.google.devtools.ksp.symbol.KSValueParameter +import com.squareup.kotlinpoet.CodeBlock import com.squareup.kotlinpoet.TypeSpec interface ItemHolderHelper { @@ -11,6 +13,14 @@ interface ItemHolderHelper { fun TypeSpec.Builder.genCacheField() + fun codeGetCachedValue(): SmartCode + + fun codeSetCachedValue( + value: CodeBlock, + onlyIfNull: Boolean, + ): CodeBlock + + } fun ItemHolderHelper.Companion.of( @@ -57,6 +67,6 @@ fun ItemHolderHelper.Companion.of( isListCaching = noWrappedReturnType.isListType(), defRefType = defRefType, keyArguments = idArguments, - ) + ) } } diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/itemholder/MultiKeyMapItemHolderHelper.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/itemholder/MultiKeyMapItemHolderHelper.kt index 8f7b0052..161351d9 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/itemholder/MultiKeyMapItemHolderHelper.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/itemholder/MultiKeyMapItemHolderHelper.kt @@ -4,8 +4,12 @@ import com.github.klee0kai.stone.__hidden__.types.MultiKey import com.github.klee0kai.stone.__hidden__.types.holders.MapItemHolder import com.github.klee0kai.stone.__hidden__.types.holders.StoneRefType import com.github.klee0kai.thekey.stone.ksp.poet.genProperty +import com.github.klee0kai.thekey.stone.ksp.poet.smartcode.SmartCode +import com.github.klee0kai.thekey.stone.ksp.poet.smartcode.add +import com.github.klee0kai.thekey.stone.ksp.poet.smartcode.smartCode import com.google.devtools.ksp.symbol.KSType import com.google.devtools.ksp.symbol.KSValueParameter +import com.squareup.kotlinpoet.CodeBlock import com.squareup.kotlinpoet.KModifier import com.squareup.kotlinpoet.ParameterizedTypeName.Companion.parameterizedBy import com.squareup.kotlinpoet.TypeSpec @@ -34,4 +38,33 @@ class MultiKeyMapItemHolderHelper( initializer("%T(%T.%L)", cacheType, StoneRefType::class, defRefType) } } + + + override fun codeGetCachedValue( + ): SmartCode = smartCode { + val getMethod = if (isListCaching) "getList" else "get" + add( + "%L.%L(key = %T(%L))", + fieldName, getMethod, + MultiKey::class.asClassName(), keyArguments.joinToString(",") { it.name!!.asString() }, + ) + providingType.value = returnType.toClassName() + } + + override fun codeSetCachedValue( + value: CodeBlock, + onlyIfNull: Boolean + ): CodeBlock = smartCode { + val setMethod = if (isListCaching) "setList" else "set" + add( + "%L.%L(key = %T(%L), onlyIfNull = %L ){ ", + fieldName, setMethod, + MultiKey::class.asClassName(), keyArguments.joinToString(",") { it.name!!.asString() }, + onlyIfNull + ) + add(value) + add("}") + providingType.value = returnType.toClassName() + }.collect() + } \ No newline at end of file diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/itemholder/SimpleMapItemHolderHelper.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/itemholder/SimpleMapItemHolderHelper.kt index 7163fea0..5fdfa460 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/itemholder/SimpleMapItemHolderHelper.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/itemholder/SimpleMapItemHolderHelper.kt @@ -3,8 +3,12 @@ package com.github.klee0kai.thekey.stone.ksp.helpers.itemholder import com.github.klee0kai.stone.__hidden__.types.holders.MapItemHolder import com.github.klee0kai.stone.__hidden__.types.holders.StoneRefType import com.github.klee0kai.thekey.stone.ksp.poet.genProperty +import com.github.klee0kai.thekey.stone.ksp.poet.smartcode.SmartCode +import com.github.klee0kai.thekey.stone.ksp.poet.smartcode.add +import com.github.klee0kai.thekey.stone.ksp.poet.smartcode.smartCode import com.google.devtools.ksp.symbol.KSType import com.google.devtools.ksp.symbol.KSValueParameter +import com.squareup.kotlinpoet.CodeBlock import com.squareup.kotlinpoet.KModifier import com.squareup.kotlinpoet.ParameterizedTypeName.Companion.parameterizedBy import com.squareup.kotlinpoet.TypeSpec @@ -33,4 +37,30 @@ class SimpleMapItemHolderHelper( initializer("%T(%T.%L)", cacheType, StoneRefType::class, defRefType) } } + + override fun codeGetCachedValue( + ): SmartCode = smartCode { + val getMethod = if (isListCaching) "getList" else "get" + add( + "%L.%L(key = %L)", + fieldName, getMethod, keyParam.name!!.asString() + ) + providingType.value = returnType.toClassName() + } + + override fun codeSetCachedValue( + value: CodeBlock, + onlyIfNull: Boolean + ): CodeBlock = smartCode { + val setMethod = if (isListCaching) "setList" else "set" + add( + "%L.%L(key = %L, onlyIfNull = %L ){ ", + fieldName, setMethod, keyParam.name!!.asString(), onlyIfNull + ) + add(value) + add("}") + providingType.value = returnType.toClassName() + }.collect() + + } \ No newline at end of file diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/itemholder/SingleItemHolderHelper.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/itemholder/SingleItemHolderHelper.kt index 55fea754..308d5663 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/itemholder/SingleItemHolderHelper.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/itemholder/SingleItemHolderHelper.kt @@ -3,7 +3,11 @@ package com.github.klee0kai.thekey.stone.ksp.helpers.itemholder import com.github.klee0kai.stone.__hidden__.types.holders.SingleItemHolder import com.github.klee0kai.stone.__hidden__.types.holders.StoneRefType import com.github.klee0kai.thekey.stone.ksp.poet.genProperty +import com.github.klee0kai.thekey.stone.ksp.poet.smartcode.SmartCode +import com.github.klee0kai.thekey.stone.ksp.poet.smartcode.add +import com.github.klee0kai.thekey.stone.ksp.poet.smartcode.smartCode import com.google.devtools.ksp.symbol.KSType +import com.squareup.kotlinpoet.CodeBlock import com.squareup.kotlinpoet.KModifier import com.squareup.kotlinpoet.ParameterizedTypeName.Companion.parameterizedBy import com.squareup.kotlinpoet.TypeSpec @@ -29,4 +33,22 @@ class SingleItemHolderHelper( } } + override fun codeGetCachedValue( + ): SmartCode = smartCode { + val getMethod = if (isListCaching) "getList" else "get" + add("%L.%L()", fieldName, getMethod) + providingType.value = returnType.toClassName() + } + + override fun codeSetCachedValue( + value: CodeBlock, + onlyIfNull: Boolean + ): CodeBlock = smartCode { + val setMethod = if (isListCaching) "setList" else "set" + add("%L.%L(onlyIfNull = %L ){ ", fieldName, setMethod, onlyIfNull) + add(value) + add("}") + providingType.value = returnType.toClassName() + }.collect() + } \ No newline at end of file diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/wrap/ClassNameUtils.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/wrap/ClassNameUtils.kt new file mode 100644 index 00000000..57069dd4 --- /dev/null +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/wrap/ClassNameUtils.kt @@ -0,0 +1,79 @@ +package com.github.klee0kai.thekey.stone.ksp.helpers.wrap + +import com.github.klee0kai.thekey.stone.ksp.exceptions.ClassNotFoundStoneException +import com.github.klee0kai.thekey.stone.ksp.exceptions.ExceptionStringBuilder +import com.github.klee0kai.thekey.stone.ksp.exceptions.PrimitiveTypeNonSupportedStoneException +import com.squareup.kotlinpoet.ClassName +import com.squareup.kotlinpoet.ParameterizedTypeName +import com.squareup.kotlinpoet.TypeName +import com.squareup.kotlinpoet.WildcardTypeName + +object ClassNameUtils { + + /** + * Get class name from full name. + * Primitives and boxed types are not support + * + * @param clFullName class full name like "com.github.klee0kai.stone.annotations.component.class" + * @return class name + * @throws PrimitiveTypeNonSupportedStoneException primitive types are not support + */ + fun classNameOf(clFullName: String): ClassName { + var clFullName = clFullName + try { + if (clFullName.endsWith(".class")) clFullName = clFullName.take(clFullName.lastIndexOf(".class")) + return ClassName.bestGuess(clFullName) + } catch (e: Exception) { + if (!clFullName.contains(".")) { + throw PrimitiveTypeNonSupportedStoneException( + ExceptionStringBuilder.createErrorMes() + .primitiveTypesNonSupported(clFullName) + .build(), + e + ) + } + throw ClassNotFoundStoneException( + ExceptionStringBuilder.createErrorMes() + .classNonFound(clFullName) + .build(), + e + ) + } + } + + fun rawTypeOf(typeName: TypeName): TypeName { + if (typeName is ParameterizedTypeName) { + return rawTypeOf((typeName).rawType) + } + if (typeName is WildcardTypeName) { + val upperBounds = typeName.outTypes + if (upperBounds.isNotEmpty()) { + return rawTypeOf(upperBounds.first()) + } + } + return typeName + } + + + fun noWildCardType(type: TypeName): TypeName { + if (type is WildcardTypeName) { + val upperBounds = type.outTypes + return if (!upperBounds.isEmpty()) { + noWildCardType(upperBounds.first()) + } else { + type + } + } + return type + } + + @Deprecated("use careful") + fun simpleName(typeName: TypeName): String? { + val raw = rawTypeOf(typeName) + if (raw is ClassName) { + return raw.simpleName + } + return null + } + +} \ No newline at end of file diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/wrap/FormatInList.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/wrap/FormatInList.kt index cafc921f..320d06ca 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/wrap/FormatInList.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/wrap/FormatInList.kt @@ -1,6 +1,6 @@ package com.github.klee0kai.thekey.stone.ksp.helpers.wrap -import com.github.klee0kai.thekey.stone.ksp.poet.smartcode.SmartCodeScopeBuilder +import com.github.klee0kai.thekey.stone.ksp.poet.smartcode.SmartCode fun interface FormatInList { @@ -8,5 +8,9 @@ fun interface FormatInList { * @param itemTransformFun format each type * @return */ - fun SmartCodeScopeBuilder.formatCode(itemTransformFun: FormatSimple) + fun formatCode( + or: SmartCode, + itemTransformFun: FormatSimple, + ): SmartCode + } diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/wrap/FormatSimple.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/wrap/FormatSimple.kt index 80516d81..f00ff287 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/wrap/FormatSimple.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/wrap/FormatSimple.kt @@ -1,6 +1,6 @@ package com.github.klee0kai.thekey.stone.ksp.helpers.wrap -import com.github.klee0kai.thekey.stone.ksp.poet.smartcode.SmartCodeScopeBuilder +import com.github.klee0kai.thekey.stone.ksp.poet.smartcode.SmartCode fun interface FormatSimple { @@ -9,5 +9,7 @@ fun interface FormatSimple { * @param code code witch return original type * @return code witch return wanna type */ - fun SmartCodeScopeBuilder.formatCode(or: SmartCodeScopeBuilder) + fun formatCode( + or: SmartCode, + ): SmartCode } diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/wrap/WrapHelper.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/wrap/WrapHelper.kt index a421fdc9..9c66624b 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/wrap/WrapHelper.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/wrap/WrapHelper.kt @@ -4,8 +4,17 @@ import com.github.klee0kai.stone.weakref.Ref import com.github.klee0kai.stone.wrappers.AsyncCoroutineProvide import com.github.klee0kai.stone.wrappers.LazyProvide import com.github.klee0kai.stone.wrappers.PhantomProvide +import com.github.klee0kai.thekey.stone.ksp.exceptions.ExceptionStringBuilder +import com.github.klee0kai.thekey.stone.ksp.exceptions.StoneException +import com.github.klee0kai.thekey.stone.ksp.helpers.wrap.ClassNameUtils.rawTypeOf +import com.github.klee0kai.thekey.stone.ksp.poet.smartcode.SmartCode +import com.github.klee0kai.thekey.stone.ksp.poet.smartcode.add +import com.github.klee0kai.thekey.stone.ksp.poet.smartcode.smartCode +import com.github.klee0kai.thekey.stone.ksp.property.map +import com.squareup.kotlinpoet.ParameterizedTypeName import com.squareup.kotlinpoet.ParameterizedTypeName.Companion.parameterizedBy import com.squareup.kotlinpoet.TypeName +import com.squareup.kotlinpoet.WildcardTypeName import com.squareup.kotlinpoet.asClassName import java.lang.ref.Reference import java.lang.ref.SoftReference @@ -14,12 +23,140 @@ import javax.inject.Provider class WrapHelper { - var wrapTypes = HashMap() + private var wrapTypes = HashMap() init { fillStdWrappers() } + fun isList(typeName: TypeName): Boolean = allParamTypes(typeName).any { + val wrapType = wrapTypes[rawTypeOf(it)] + wrapType != null && wrapType.isList + } + + + fun listWrapTypeIfNeed(typeName: TypeName): TypeName { + if (isList(typeName)) List::class + .asClassName() + .parameterizedBy(nonWrappedType(typeName)) + + return nonWrappedType(typeName); + } + + fun transform(code: SmartCode, wannaType: TypeName): SmartCode { + if (code.providingType.value == null || code.providingType.value == wannaType) { + return code + } + var smartCode = SmartCode().apply { add(code) } + + var wrapPathNames = allParamTypes(wannaType).reversed() + var unwrapPathNames = allParamTypes(code.providingType.value!!) + while ( + !wrapPathNames.isEmpty() && !unwrapPathNames.isEmpty() + && rawTypeOf(unwrapPathNames.last()) == rawTypeOf(wrapPathNames.first()) + ) { + unwrapPathNames = unwrapPathNames.dropLast(1) + wrapPathNames = wrapPathNames.drop(1) + } + + val wrapTypeFormat: (TypeName) -> WrapType = { + wrapTypes.getOrElse(rawTypeOf(it)) { + throw StoneException( + ExceptionStringBuilder.createErrorMes() + .typeTransformNonSupport( + ClassNameUtils.noWildCardType(code.providingType.value!!), + wannaType + ) + .classNonFound(it.toString()) + .build(), + ) + } + } + + var unwrapPath = unwrapPathNames.map(wrapTypeFormat) + var wrapPath = wrapPathNames.map(wrapTypeFormat) + + while (!unwrapPath.isEmpty()) { + val unwrapType = unwrapPath.first() + if (unwrapType.isList) { + val wrapListIndex = wrapPath.indexOfFirst { it.isList } + if (wrapListIndex >= 0) { + val unWrapItemType = paramType(unwrapPathNames.first()) + val wrapItemType = paramType(wrapPathNames[wrapListIndex]) + val wrapListType = wrapPath[wrapListIndex] + smartCode = wrapListType.inListFormat!!.formatCode( + smartCode, + FormatSimple { listItemCode -> + listItemCode.providingType.value = unWrapItemType + transform(listItemCode, wrapItemType) + }) + + for (i in 0..wrapListIndex) { + wrapPath = wrapPath.drop(1) + wrapPathNames.drop(1) + } + unwrapPath = emptyList() + unwrapPathNames = emptyList() + break + } + } + smartCode = unwrapType.unwrap.formatCode(smartCode) + unwrapPath = unwrapPath.drop(1) + unwrapPathNames = unwrapPathNames.drop(1) + } + + while (!wrapPath.isEmpty()) { + smartCode = wrapPath[0].wrap.formatCode(smartCode) + wrapPath = wrapPath.drop(1) + wrapPathNames = wrapPathNames.drop(1) + } + + smartCode.providingType.value = wannaType + return smartCode + } + + fun nonWrappedType(typeName: TypeName): TypeName { + if (typeName is ParameterizedTypeName) { + if (isSupport(typeName.rawType) && !typeName.typeArguments.isEmpty()) { + return nonWrappedType(typeName.typeArguments.first()) + } + } + if (typeName is WildcardTypeName) { + if (!typeName.outTypes.isEmpty()) { + return nonWrappedType(typeName.outTypes.first()) + } + } + return typeName + } + + fun allParamTypes(typeName: TypeName): List { + var typeName = typeName + typeName = ClassNameUtils.noWildCardType(typeName) + val allParams = mutableListOf() + while (true) { + allParams.add(typeName) + val paramType = typeName as? ParameterizedTypeName + if (paramType == null || paramType.typeArguments.isEmpty()) break + typeName = ClassNameUtils.noWildCardType(paramType.typeArguments.first()) + } + return allParams + } + + fun support(wrapType: WrapType) { + wrapTypes.putIfAbsent(wrapType.typeName, wrapType) + } + + fun isSupport(typeName: TypeName): Boolean = wrapTypes.containsKey(rawTypeOf(typeName)) + + fun paramType(typeName: TypeName): TypeName { + if (typeName is ParameterizedTypeName) { + if (isSupport(typeName.rawType) && !typeName.typeArguments.isEmpty()) { + return typeName.typeArguments.first() + } + } + return typeName + } + private fun fillStdWrappers() { for (cl in listOf( WeakReference::class, @@ -29,24 +166,32 @@ class WrapHelper { val wrapper = cl.asClassName() val creator = if (cl != Reference::class) wrapper else WeakReference::class.asClassName() - val wrapType = WrapType( - isNoCachingWrapper = false, - typeName = wrapper, - wrap = FormatSimple { or -> - providingType = or.providingType?.let { - wrapper.parameterizedBy(it) - } - TODO() - }, - unwrap = FormatSimple { or -> -// providingType = or.providingType?.let { -// -// } - TODO() - }, - ) - wrapTypes.putIfAbsent(wrapType.typeName, wrapType) + support( + WrapType( + isNoCachingWrapper = false, + typeName = wrapper, + wrap = FormatSimple { or -> + smartCode { + add(or) + add("?.let{ %T( it ) }", creator) + + providingType.source = or.providingType.map { orType -> + orType?.let { wrapper.parameterizedBy(it) } + } + } + }, + unwrap = FormatSimple { or -> + smartCode { + add("or") + add("?.get()") + providingType.source = or.providingType.map { orType -> + orType?.let { paramType(it) } + } + } + }, + ) + ) } for (cl in listOf( @@ -58,19 +203,35 @@ class WrapHelper { )) { val wrapper = cl.asClassName() - val wrapType = WrapType( - typeName = wrapper, - isNoCachingWrapper = cl != LazyProvide::class.java && cl != AsyncCoroutineProvide::class.java, - isAsyncProvider = true, - wrap = FormatSimple { or -> - TODO() - }, - unwrap = FormatSimple { or -> - TODO() - } - ) + val isNoCachingWrapper = cl !in listOf(LazyProvide::class, AsyncCoroutineProvide::class) + val creator = if (isNoCachingWrapper) PhantomProvide::class.asClassName() else wrapper + support( + WrapType( + typeName = wrapper, + isNoCachingWrapper = cl != LazyProvide::class && cl != AsyncCoroutineProvide::class, + isAsyncProvider = true, + wrap = FormatSimple { or -> + smartCode { + add("%S{", creator) + add(or) + add("} ") - wrapTypes.putIfAbsent(wrapType.typeName, wrapType) + providingType.source = or.providingType.map { orType -> + orType?.let { wrapper.parameterizedBy(it) } + } + } + }, + unwrap = FormatSimple { or -> + smartCode { + add("or") + add("?.get()") + providingType.source = or.providingType.map { orType -> + orType?.let { paramType(it) } + } + } + } + ) + ) } for (cl in listOf( @@ -79,22 +240,50 @@ class WrapHelper { MutableList::class, MutableCollection::class )) { - val wrapper = cl.asClassName() + val creatorFun = when (cl) { + List::class -> "listOf" + Array::class -> "arrayOf" + MutableList::class, + MutableCollection::class -> "mutableListOf" - val wrapType = WrapType( - typeName = wrapper, - wrap = FormatSimple { or -> - TODO() - }, - unwrap = FormatSimple { or -> - TODO() - }, - inListFormat = FormatInList { or -> - TODO() - } - ) + else -> "listOf" + } + + support( + WrapType( + typeName = wrapper, + wrap = FormatSimple { or -> + smartCode { + add("%L(", creatorFun) + add(or) + add(")") + providingType.source = or.providingType.map { orType -> + orType?.let { wrapper.parameterizedBy(it) } + } + } + }, + unwrap = FormatSimple { or -> + smartCode { + add("or") + add("?.firstOrNull()") + providingType.source = or.providingType.map { orType -> + orType?.let { paramType(it) } + } + } + }, + inListFormat = FormatInList { originalListCode, itemTransformFun -> + smartCode { + add(originalListCode) + add(".map { ") + with(itemTransformFun) { + formatCode(smartCode("it")) + } + add(" }") + } + } + )) } diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/poet/FunSpecDsl.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/poet/FunSpecDsl.kt index 25724522..09748508 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/poet/FunSpecDsl.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/poet/FunSpecDsl.kt @@ -8,7 +8,7 @@ fun CodeBlock.Builder.controlFlow( vararg args: Any, block: CodeBlock.Builder.() -> Unit, ) = apply { - beginControlFlow(controlFlow, args) + beginControlFlow(controlFlow, *args) .add(CodeBlock.builder().apply(block).build()) .endControlFlow() } @@ -18,7 +18,7 @@ fun FunSpec.Builder.controlFlow( vararg args: Any, block: CodeBlock.Builder.() -> Unit, ) = apply { - beginControlFlow(controlFlow, args) + beginControlFlow(controlFlow, *args) .addCode(CodeBlock.builder().apply(block).build()) .endControlFlow() } \ No newline at end of file diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/poet/smartcode/CollectedSmartCode.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/poet/smartcode/CollectedSmartCode.kt deleted file mode 100644 index 19fe5221..00000000 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/poet/smartcode/CollectedSmartCode.kt +++ /dev/null @@ -1,44 +0,0 @@ -package com.github.klee0kai.thekey.stone.ksp.poet.smartcode - -import com.squareup.kotlinpoet.ClassName -import com.squareup.kotlinpoet.CodeBlock -import com.squareup.kotlinpoet.TypeName - -class CollectedSmartCode( - val codeBlock: CodeBlock, - val declareLocalVariable: Pair? = null, - val usedVariables: Set = emptySet(), - val providingType: TypeName? = null, -) { - - class ScopedBuilder( - val declaredVariables: Map, - ) { - val codeBuilder = CodeBlock.Builder() - var declareLocalVariable: Pair? = null - val usedVariables = mutableSetOf() - var providingType: ClassName? = null - - fun build() = CollectedSmartCode( - codeBlock = codeBuilder.build(), - declareLocalVariable = declareLocalVariable, - usedVariables = usedVariables, - providingType = providingType, - ) - - } - -} - -fun CollectedSmartCode.ScopedBuilder.add( - string: String, -) { - codeBuilder.add(string) -} - -fun CollectedSmartCode.ScopedBuilder.add( - codeBlock: CodeBlock, -) { - codeBuilder.add(codeBlock) -} - diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/poet/smartcode/SimpleCodeBuilder.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/poet/smartcode/SimpleCodeBuilder.kt deleted file mode 100644 index 3cd28cd3..00000000 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/poet/smartcode/SimpleCodeBuilder.kt +++ /dev/null @@ -1,12 +0,0 @@ -package com.github.klee0kai.thekey.stone.ksp.poet.smartcode - -import com.squareup.kotlinpoet.ClassName - -fun interface SimpleCodeBuilder { - - fun collect( - declaredVariables: Map - ): CollectedSmartCode - -} - diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/poet/smartcode/SmartCode.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/poet/smartcode/SmartCode.kt new file mode 100644 index 00000000..11e71d25 --- /dev/null +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/poet/smartcode/SmartCode.kt @@ -0,0 +1,56 @@ +package com.github.klee0kai.thekey.stone.ksp.poet.smartcode + +import com.github.klee0kai.thekey.stone.ksp.property.Property +import com.squareup.kotlinpoet.CodeBlock +import com.squareup.kotlinpoet.TypeName + +class SmartCode( + val parent: SmartCode? = null, +) { + + private val codes = Property>(emptyList()) + + val declareLocalVariable = Property?>(null) + val providingType = Property(null) + + val availableVariables = Property>(emptyMap()) + val usedVariables = Property>(emptySet()) + + fun add(codeBlock: CodeBlock) { + codes.value += SmartCodeBlock(codeBlock = codeBlock) + parent?.providingType?.source = null + } + + fun add(codeBlock: SmartCode) { + codes.value += SmartCodeBlock(smartCode = codeBlock) + parent?.providingType?.source = codeBlock.providingType + } + + fun collect( + ): CodeBlock { + val allUsedVariables = usedVariables.value + codes.value + .flatMap { childCode -> childCode.smartCode?.usedVariables?.value ?: emptySet() } + + val optimizedCode = codes.value.filter { childCode -> + childCode.smartCode == null + || childCode.smartCode.declareLocalVariable.value == null + || childCode.smartCode.declareLocalVariable.value?.first in allUsedVariables + } + + val codeBlock = CodeBlock.Builder() + optimizedCode.forEach { childCode -> + when { + childCode.codeBlock != null -> codeBlock.add(childCode.codeBlock) + childCode.smartCode != null -> codeBlock.add(childCode.smartCode.collect()) + } + } + return codeBlock.build() + } + +} + + + + + + diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/poet/smartcode/SmartCodeBlock.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/poet/smartcode/SmartCodeBlock.kt new file mode 100644 index 00000000..359f6df8 --- /dev/null +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/poet/smartcode/SmartCodeBlock.kt @@ -0,0 +1,9 @@ +package com.github.klee0kai.thekey.stone.ksp.poet.smartcode + +import com.squareup.kotlinpoet.CodeBlock + +class SmartCodeBlock( + val smartCode: SmartCode? = null, + val codeBlock: CodeBlock? = null, +) + diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/poet/smartcode/SmartCodeExt.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/poet/smartcode/SmartCodeExt.kt index 4ac497ed..c1f1eaee 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/poet/smartcode/SmartCodeExt.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/poet/smartcode/SmartCodeExt.kt @@ -1,63 +1,50 @@ package com.github.klee0kai.thekey.stone.ksp.poet.smartcode import com.github.klee0kai.thekey.stone.ksp.poet.PoetDsl -import com.squareup.kotlinpoet.ClassName import com.squareup.kotlinpoet.CodeBlock - -@PoetDsl -fun SmartCodeScopeBuilder.add( - codeBlock: CodeBlock, - usedVariables: Set = emptySet(), - providingType: ClassName? = null, +fun SmartCode.add( + code: String, ) { - codes.add( - SimpleCodeBuilder { - CollectedSmartCode( - codeBlock = codeBlock, - usedVariables = usedVariables, - providingType = providingType, - ) - }) + add(CodeBlock.of(code)) } -@PoetDsl -fun SmartCodeScopeBuilder.add( - codeBlock: String, - usedVariables: Set = emptySet(), - providingType: ClassName? = null, +fun SmartCode.add( + code: String, + vararg arg: Any ) { - codes.add( - SimpleCodeBuilder { - CollectedSmartCode( - codeBlock = CodeBlock.Builder().apply { - add(codeBlock) - }.build(), - usedVariables = usedVariables, - providingType = providingType, - ) - }) + add(CodeBlock.of(code, *arg)) } + @PoetDsl -fun SmartCodeScopeBuilder.add( - codeBlock: CollectedSmartCode.ScopedBuilder.() -> Unit, -) { - codes.add( - SimpleCodeBuilder { - CollectedSmartCode.ScopedBuilder(it).apply(codeBlock).build() - } - ) -} +fun smartCode( + block: SmartCode.() -> Unit, +) = SmartCode() + .apply(block) + @PoetDsl -fun SmartCodeScopeBuilder.smartCode( - codeBlock: SmartCodeScopeBuilder.() -> Unit, +fun smartCode( + string: String, +) = SmartCode() + .apply { + add(string) + } + + +@PoetDsl +fun SmartCode.add( + block: SmartCode.() -> Unit, ) { - codes.add( - SmartCodeScopeBuilder() - .apply(codeBlock) - ) + val parentBlock = this + val builder = SmartCode(parentBlock) + availableVariables.source = parentBlock.availableVariables + builder.block() + parentBlock.add(builder) } + + + diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/poet/smartcode/SmartCodeScopeBuilder.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/poet/smartcode/SmartCodeScopeBuilder.kt deleted file mode 100644 index 3c129e1c..00000000 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/poet/smartcode/SmartCodeScopeBuilder.kt +++ /dev/null @@ -1,56 +0,0 @@ -package com.github.klee0kai.thekey.stone.ksp.poet.smartcode - -import com.github.klee0kai.thekey.stone.ksp.poet.PoetDsl -import com.squareup.kotlinpoet.ClassName -import com.squareup.kotlinpoet.CodeBlock -import com.squareup.kotlinpoet.TypeName - -open class SmartCodeScopeBuilder() : SimpleCodeBuilder { - - val codes = mutableListOf() - - var declareLocalVariable: Pair? = null - var providingType: TypeName? = null - - override fun collect( - declaredVariables: Map, - ): CollectedSmartCode { - val declaredVariables = declaredVariables.toMutableMap() - val usedVariables = mutableSetOf() - val collectedList = mutableListOf() - for (code in codes) { - val collected = code.collect(declaredVariables) - if (collected.declareLocalVariable != null) { - declaredVariables += collected.declareLocalVariable - } - - usedVariables += collected.usedVariables - collectedList += collected - } - - val optimized = collectedList.filter { - it.declareLocalVariable == null - || it.declareLocalVariable.first in usedVariables - } - - return CollectedSmartCode( - codeBlock = CodeBlock.builder().also { builder -> - optimized.forEach { - builder.add(it.codeBlock) - } - }.build(), - declareLocalVariable = declareLocalVariable, - usedVariables = usedVariables, - providingType = providingType, - ) - } - -} - -@PoetDsl -fun smartCode( - block: SmartCodeScopeBuilder.() -> Unit, -) = SmartCodeScopeBuilder() - .apply(block) - .collect(declaredVariables = emptyMap()) - .codeBlock \ No newline at end of file diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/property/Property.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/property/Property.kt new file mode 100644 index 00000000..3175b5be --- /dev/null +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/property/Property.kt @@ -0,0 +1,68 @@ +package com.github.klee0kai.thekey.stone.ksp.property + +import kotlin.reflect.KProperty + +class Property( + initValue: T +) { + companion object; + + private val subscriptions = mutableListOf<(T) -> Unit>() + + var value: T = initValue + set(value) { + field = value + subscriptions.forEach { it.invoke(value) } + } + + private val updateThisValueSubscription: (T) -> Unit = { value = it } + + var source: Property? = null + set(value) { + field?.unsubscribeChanges(updateThisValueSubscription) + field = value + field?.subscribeChanges(updateThisValueSubscription) + } + + fun subscribeChanges( + block: (T) -> Unit, + ) { + subscriptions += block + block(value) + } + + fun unsubscribeChanges(block: (T) -> Unit) { + subscriptions -= block + } + + operator fun getValue( + thisRef: Any?, + property: KProperty<*>, + ): T = value + + operator fun setValue( + thisRef: Any?, + property: KProperty<*>, + newValue: T, + ) { + value = newValue + } + + operator fun setValue( + thisRef: Any?, + property: KProperty<*>, + newValue: Property, + ) { + source = newValue + } + +} + +fun Property.map( + transform: (T) -> R, +): Property { + val prop = Property(transform(value)) + subscribeChanges { prop.value = transform(it) } + return prop +} + diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/GenModuleProcessor.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/GenModuleProcessor.kt index def0ef0d..9d31b9f3 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/GenModuleProcessor.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/GenModuleProcessor.kt @@ -8,16 +8,20 @@ import com.github.klee0kai.stone.__hidden__.types.holders.StoneRefType import com.github.klee0kai.stone.annotations.module.BindInstance import com.github.klee0kai.stone.annotations.module.Module import com.github.klee0kai.stone.annotations.module.Provide +import com.github.klee0kai.stone.weakref.Ref import com.github.klee0kai.thekey.stone.ksp.helpers.* import com.github.klee0kai.thekey.stone.ksp.helpers.itemholder.ItemHolderHelper import com.github.klee0kai.thekey.stone.ksp.helpers.itemholder.of import com.github.klee0kai.thekey.stone.ksp.helpers.itemholder.toItemCacheType +import com.github.klee0kai.thekey.stone.ksp.helpers.wrap.WrapHelper import com.github.klee0kai.thekey.stone.ksp.ksp.arch.GenSpec import com.github.klee0kai.thekey.stone.ksp.ksp.arch.SymbolsToProcess import com.github.klee0kai.thekey.stone.ksp.ksp.arch.TargetFileProcessor import com.github.klee0kai.thekey.stone.ksp.ksp.getAllMethods import com.github.klee0kai.thekey.stone.ksp.poet.* -import com.github.klee0kai.thekey.stone.ksp.poet.smartcode.SmartCodeScopeBuilder +import com.github.klee0kai.thekey.stone.ksp.poet.smartcode.SmartCode +import com.github.klee0kai.thekey.stone.ksp.poet.smartcode.add +import com.github.klee0kai.thekey.stone.ksp.poet.smartcode.smartCode import com.google.devtools.ksp.KspExperimental import com.google.devtools.ksp.containingFile import com.google.devtools.ksp.getAnnotationsByType @@ -46,13 +50,13 @@ class GenModuleProcessor : TargetFileProcessor { } class DelayedCodeBlocks( - val initMethodCode: SmartCodeScopeBuilder = SmartCodeScopeBuilder(), - val initCachesFromMethodName: SmartCodeScopeBuilder = SmartCodeScopeBuilder(), - val bindMethodName: SmartCodeScopeBuilder = SmartCodeScopeBuilder(), - val getFactoryMethodName: SmartCodeScopeBuilder = SmartCodeScopeBuilder(), - val switchRefMethodName: SmartCodeScopeBuilder = SmartCodeScopeBuilder(), - val updateBindInstancesFrom: SmartCodeScopeBuilder = SmartCodeScopeBuilder(), - val clearNullsMethodName: SmartCodeScopeBuilder = SmartCodeScopeBuilder(), + val initMethodCode: SmartCode = SmartCode(), + val initCachesFromMethodName: SmartCode = SmartCode(), + val bindMethodName: SmartCode = SmartCode(), + val getFactoryMethodName: SmartCode = SmartCode(), + val switchRefMethodName: SmartCode = SmartCode(), + val updateBindInstancesFrom: SmartCode = SmartCode(), + val clearNullsMethodName: SmartCode = SmartCode(), ) @@ -90,6 +94,7 @@ class GenModuleProcessor : TargetFileProcessor { val genModuleClassName = moduleCl.moduleStoneClName + val wrapperHelper = WrapHelper() val fileSpec = genFileSpec(genModuleClassName.packageName, genModuleClassName.simpleName) { genLibComment() @@ -133,11 +138,9 @@ class GenModuleProcessor : TargetFileProcessor { } provideAnn == null || provideAnn.cache == Provide.CacheType.Factory -> { - genProvideCachedFun( - function, - idArguments, - wrapperTypes, - ) + genOverrideFun(function) { + + } } else -> { @@ -149,11 +152,14 @@ class GenModuleProcessor : TargetFileProcessor { ) with(itemHolderHelper) { genCacheField() - - genOverrideFun(function) { - - } } + genProvideCachedFun( + function, + idArguments, + itemHolderHelper, + wrapperTypes, + wrapperHelper, + ) } } @@ -174,20 +180,63 @@ class GenModuleProcessor : TargetFileProcessor { private fun TypeSpec.Builder.genProvideCachedFun( function: KSFunctionDeclaration, idArguments: List, + itemHolderHelper: ItemHolderHelper, wrapperTypes: List, + wrapperHelper: WrapHelper, ) { + val returnType = function.returnType?.resolve()?.toClassName() ?: return genOverrideFun(function) { controlFlow("if (%L.get() != null )", overridedModuleFieldName) { addStatement( - "%T cached = %L.get().%L( null %L ) ", - function.returnType!!.resolve().listWrapTypeIfNeed(wrapperTypes), - overridedModuleFieldName, function.cacheControlMethodName, - idArguments.joinToString { ", ${it.name}" }, + "val cached = %L.get().%L( null %L ) ", + overridedModuleFieldName, + function.cacheControlMethodName, + idArguments.joinToString { ", ${it.name!!.asString()}" }, ) add("if (cached != null ) return ") - TODO() - + add( + wrapperHelper.transform( + code = smartCode { + providingType.value = wrapperHelper.listWrapTypeIfNeed(returnType) + add("cached") + }, + wannaType = returnType, + ).collect() + ) + addStatement("") } + // set value if null + val argStrList = function.parameters.joinToString(", ") { it.name!!.asString() } + addCode("val creator = %T{ ", Ref::class.asClassName().parameterizedBy(returnType)) + addCode("if ( %L.get() != null ) ", overridedModuleFieldName) + addCode( + " %L.get().%L( %L ) ", + overridedModuleFieldName, + function.simpleName.asString(), + argStrList, + ) + addCode(" else ") + addCode(" %L.%L(%L)", factoryFieldName, function.simpleName.asString(), argStrList) + addCode("}\n") + addCode( + itemHolderHelper.codeSetCachedValue( + value = wrapperHelper.transform( + code = smartCode { + providingType.value = returnType + add("creator.get()") + }, + wannaType = wrapperHelper.listWrapTypeIfNeed(returnType) + ).collect(), + onlyIfNull = true, + ) + ) + addCode("return ") + addCode( + wrapperHelper.transform( + code = itemHolderHelper.codeGetCachedValue(), + wannaType = returnType, + ).collect() + ) } } @@ -216,27 +265,21 @@ class GenModuleProcessor : TargetFileProcessor { } genFun(initMethodName) { - codeBlocks.initMethodCode.collect(declaredVariables = emptyMap()) } genFun(initCachesFromMethodName) { - codeBlocks.initCachesFromMethodName.collect(declaredVariables = emptyMap()) } genFun(bindMethodName) { - codeBlocks.bindMethodName.collect(declaredVariables = emptyMap()) } genFun(switchRefMethodName) { - codeBlocks.switchRefMethodName.collect(declaredVariables = emptyMap()) } genFun(updateBindInstancesFrom) { - codeBlocks.updateBindInstancesFrom.collect(declaredVariables = emptyMap()) } genFun(clearNullsMethodName) { - codeBlocks.clearNullsMethodName.collect(declaredVariables = emptyMap()) } } diff --git a/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/__hidden__/types/holders/MapItemHolder.kt b/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/__hidden__/types/holders/MapItemHolder.kt index 3dc081af..438a0a01 100644 --- a/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/__hidden__/types/holders/MapItemHolder.kt +++ b/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/__hidden__/types/holders/MapItemHolder.kt @@ -48,8 +48,8 @@ class MapItemHolder( fun set( key: Key?, - creator: Ref, onlyIfNull: Boolean, + creator: Ref, ) { val refHolder = refMap[key] if (curRefType == StoneRefType.StrongObject) { @@ -72,8 +72,8 @@ class MapItemHolder( fun setList( key: Key?, - creator: Ref?>, onlyIfNull: Boolean, + creator: Ref?>, ) { val refHolder = refMap[key] if (curRefType == StoneRefType.ListObject) { @@ -118,12 +118,12 @@ class MapItemHolder( val listMap: HashMap?> = HashMap() for (key in refMap.keys) listMap[key] = getList(key) curRefType = refType.forList() - for (key in listMap.keys) setList(key, Ref { listMap[key] }, false) + for (key in listMap.keys) setList(key, onlyIfNull = false) { listMap[key] } } else { val itemMap: HashMap = HashMap() for (key in refMap.keys) itemMap[key] = get(key) curRefType = refType.forSingle() - for (key in itemMap.keys) set(key, Ref { itemMap[key] }, false) + for (key in itemMap.keys) set(key, onlyIfNull = false) { itemMap[key] } } } diff --git a/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/__hidden__/types/holders/SingleItemHolder.kt b/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/__hidden__/types/holders/SingleItemHolder.kt index a87fc3fb..0096b174 100644 --- a/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/__hidden__/types/holders/SingleItemHolder.kt +++ b/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/__hidden__/types/holders/SingleItemHolder.kt @@ -36,8 +36,8 @@ class SingleItemHolder( fun set( - creator: Ref, onlyIfNull: Boolean, + creator: Ref, ) { if (curRefType == StoneRefType.StrongObject) { if (refHolder != null && onlyIfNull) return @@ -58,8 +58,8 @@ class SingleItemHolder( } fun setList( - creator: Ref?>, onlyIfNull: Boolean, + creator: Ref?>, ) { if (curRefType == StoneRefType.ListObject) { if (!onlyIfNull || refHolder == null) { @@ -103,11 +103,11 @@ class SingleItemHolder( if (defType.isList) { val ob = this.getList() curRefType = refType.forList() - setList(creator = Ref { ob }, false) + setList(onlyIfNull = false) { ob } } else { val ob = get() curRefType = refType.forSingle() - set(creator = Ref { ob }, false) + set(onlyIfNull = false) { ob } } } From 18479297b32db4f5f01334b30c26c809e7a94eb3 Mon Sep 17 00:00:00 2001 From: klee0kai Date: Sun, 23 Nov 2025 18:21:58 +0100 Subject: [PATCH 030/122] Gen cache control class --- .../klee0kai/thekey/stone/ksp/Processor.kt | 2 + .../target/GenModuleCacheControlProcessor.kt | 113 ++++++++++++++++++ 2 files changed, 115 insertions(+) create mode 100644 stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/GenModuleCacheControlProcessor.kt diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/Processor.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/Processor.kt index 5a8fab5c..34915393 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/Processor.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/Processor.kt @@ -6,6 +6,7 @@ import com.github.klee0kai.thekey.stone.ksp.ksp.arch.GenSpec import com.github.klee0kai.thekey.stone.ksp.ksp.arch.filter import com.github.klee0kai.thekey.stone.ksp.ksp.arch.forceProcess import com.github.klee0kai.thekey.stone.ksp.ksp.arch.nowTakeOnly +import com.github.klee0kai.thekey.stone.ksp.target.GenModuleCacheControlProcessor import com.github.klee0kai.thekey.stone.ksp.target.GenModuleFactoryProcessor import com.github.klee0kai.thekey.stone.ksp.target.GenModuleProcessor import com.google.devtools.ksp.containingFile @@ -65,6 +66,7 @@ class Processor( val dispatcher by lazy { if (multithread) Dispatchers.Default else Dispatchers.Unconfined } val targetProcessors = arrayOf( GenModuleFactoryProcessor(), + GenModuleCacheControlProcessor(), GenModuleProcessor(), ) diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/GenModuleCacheControlProcessor.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/GenModuleCacheControlProcessor.kt new file mode 100644 index 00000000..a09e75b2 --- /dev/null +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/GenModuleCacheControlProcessor.kt @@ -0,0 +1,113 @@ +@file:OptIn(KspExperimental::class) + +package com.github.klee0kai.thekey.stone.ksp.target + +import com.github.klee0kai.stone.__hidden__.CacheAction +import com.github.klee0kai.stone.__hidden__.SwitchCacheParam +import com.github.klee0kai.stone.annotations.module.Module +import com.github.klee0kai.thekey.stone.ksp.helpers.allIdentifierTypes +import com.github.klee0kai.thekey.stone.ksp.helpers.cacheControlMethodName +import com.github.klee0kai.thekey.stone.ksp.helpers.cacheControlStoneClName +import com.github.klee0kai.thekey.stone.ksp.helpers.findComponentForModuleOrDep +import com.github.klee0kai.thekey.stone.ksp.ksp.arch.GenSpec +import com.github.klee0kai.thekey.stone.ksp.ksp.arch.SymbolsToProcess +import com.github.klee0kai.thekey.stone.ksp.ksp.arch.TargetFileProcessor +import com.github.klee0kai.thekey.stone.ksp.ksp.getAllMethods +import com.github.klee0kai.thekey.stone.ksp.poet.* +import com.google.devtools.ksp.KspExperimental +import com.google.devtools.ksp.containingFile +import com.google.devtools.ksp.processing.Dependencies +import com.google.devtools.ksp.processing.KSPLogger +import com.google.devtools.ksp.processing.Resolver +import com.google.devtools.ksp.symbol.KSAnnotated +import com.google.devtools.ksp.symbol.KSClassDeclaration +import com.squareup.kotlinpoet.KModifier +import com.squareup.kotlinpoet.ParameterizedTypeName.Companion.parameterizedBy +import com.squareup.kotlinpoet.STAR +import com.squareup.kotlinpoet.asClassName +import com.squareup.kotlinpoet.ksp.toClassName +import kotlin.reflect.KClass + +class GenModuleCacheControlProcessor : TargetFileProcessor { + + override suspend fun findSymbolsToProcess( + resolver: Resolver, + ) = SymbolsToProcess( + symbolsForProcessing = resolver + .getSymbolsWithAnnotation(Module::class.asClassName().canonicalName) + .toList(), + symbolsForReprocessing = emptyList(), + ) + + override suspend fun process( + validSymbol: KSAnnotated, + resolver: Resolver, + options: Map, + logger: KSPLogger + ): GenSpec? { + val fileOwner = validSymbol.containingFile ?: return null + val moduleCl = validSymbol as? KSClassDeclaration ?: return null + + val componentCl = resolver.findComponentForModuleOrDep(moduleCl.toClassName()) + .firstOrNull() + + val identifierTypes = componentCl + ?.allIdentifierTypes?.toList() + ?: emptyList() + + val genCacheControlClassName = moduleCl.cacheControlStoneClName + val fileSpec = genFileSpec( + packageName = genCacheControlClassName.packageName, + fileName = genCacheControlClassName.simpleName + ) { + genLibComment() + + genInterface(genCacheControlClassName) { + + genFun(GenModuleProcessor.bindMethodName) { + modifiers.add(KModifier.ABSTRACT) + addParameter("or", Any::class) + returns(Boolean::class) + } + + genFun(GenModuleProcessor.switchRefMethodName) { + modifiers.add(KModifier.ABSTRACT) + addParameter( + "scopes", + Set::class.asClassName() + .parameterizedBy( + KClass::class.asClassName() + .parameterizedBy(STAR) + ) + ) + addParameter("__params", SwitchCacheParam::class) + } + + + validSymbol.getAllMethods(false, false, "") + .forEach { function -> + val idArguments = function.parameters + .filter { it.type.resolve() in identifierTypes } + + genOverrideFun(function) { + modifiers.remove(KModifier.OVERRIDE) + modifiers.add(KModifier.ABSTRACT) + } + genFun(function.cacheControlMethodName) { + modifiers.add(KModifier.ABSTRACT) + addParameter("__action", CacheAction::class) + idArguments.forEach { + addParameter(it.name!!.asString(), it.type.resolve().toClassName()) + } + } + } + } + } + + return GenSpec( + fileSpec = fileSpec, + // https://kotlinlang.org/docs/ksp-incremental.html + dependencies = Dependencies(aggregating = false, fileOwner), + ) + } +} \ No newline at end of file From 446c62d1ff8d720b51ef78f508f42782356b6af7 Mon Sep 17 00:00:00 2001 From: klee0kai Date: Sun, 23 Nov 2025 18:54:01 +0100 Subject: [PATCH 031/122] correct provide cached method --- .../target/GenModuleCacheControlProcessor.kt | 2 +- .../stone/ksp/target/GenModuleProcessor.kt | 52 +++++++++---------- .../klee0kai/stone/__hidden__/CacheAction.kt | 3 +- 3 files changed, 28 insertions(+), 29 deletions(-) diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/GenModuleCacheControlProcessor.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/GenModuleCacheControlProcessor.kt index a09e75b2..863fbdea 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/GenModuleCacheControlProcessor.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/GenModuleCacheControlProcessor.kt @@ -83,7 +83,6 @@ class GenModuleCacheControlProcessor : TargetFileProcessor { addParameter("__params", SwitchCacheParam::class) } - validSymbol.getAllMethods(false, false, "") .forEach { function -> val idArguments = function.parameters @@ -95,6 +94,7 @@ class GenModuleCacheControlProcessor : TargetFileProcessor { } genFun(function.cacheControlMethodName) { modifiers.add(KModifier.ABSTRACT) + returns(function.returnType!!.resolve().toClassName()) addParameter("__action", CacheAction::class) idArguments.forEach { addParameter(it.name!!.asString(), it.type.resolve().toClassName()) diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/GenModuleProcessor.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/GenModuleProcessor.kt index 9d31b9f3..9a5fc9ef 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/GenModuleProcessor.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/GenModuleProcessor.kt @@ -2,6 +2,7 @@ package com.github.klee0kai.thekey.stone.ksp.target +import com.github.klee0kai.stone.__hidden__.CacheAction import com.github.klee0kai.stone.__hidden__.IModule import com.github.klee0kai.stone.__hidden__.types.holders.SingleItemHolder import com.github.klee0kai.stone.__hidden__.types.holders.StoneRefType @@ -186,37 +187,34 @@ class GenModuleProcessor : TargetFileProcessor { ) { val returnType = function.returnType?.resolve()?.toClassName() ?: return genOverrideFun(function) { - controlFlow("if (%L.get() != null )", overridedModuleFieldName) { - addStatement( - "val cached = %L.get().%L( null %L ) ", - overridedModuleFieldName, - function.cacheControlMethodName, - idArguments.joinToString { ", ${it.name!!.asString()}" }, - ) - add("if (cached != null ) return ") - add( - wrapperHelper.transform( - code = smartCode { - providingType.value = wrapperHelper.listWrapTypeIfNeed(returnType) - add("cached") - }, - wannaType = returnType, - ).collect() - ) - addStatement("") - } + addStatement( + "val cached = %L.get()?.%L( %T.getValueAction, %L ) ", + overridedModuleFieldName, + function.cacheControlMethodName, + CacheAction::class.asClassName(), + idArguments.joinToString(", ") { it.name!!.asString() }, + ) + addCode("if (cached != null ) return ") + addCode( + wrapperHelper.transform( + code = smartCode { + providingType.value = wrapperHelper.listWrapTypeIfNeed(returnType) + add("cached") + }, + wannaType = returnType, + ).collect() + ) + addStatement("") + // set value if null val argStrList = function.parameters.joinToString(", ") { it.name!!.asString() } addCode("val creator = %T{ ", Ref::class.asClassName().parameterizedBy(returnType)) - addCode("if ( %L.get() != null ) ", overridedModuleFieldName) addCode( - " %L.get().%L( %L ) ", - overridedModuleFieldName, - function.simpleName.asString(), - argStrList, + "%L.get()?.%L(%L)", + overridedModuleFieldName, function.simpleName.asString(), argStrList, ) - addCode(" else ") - addCode(" %L.%L(%L)", factoryFieldName, function.simpleName.asString(), argStrList) + addCode(" ?: ") + addCode("%L.%L(%L)", factoryFieldName, function.simpleName.asString(), argStrList) addCode("}\n") addCode( itemHolderHelper.codeSetCachedValue( @@ -230,6 +228,7 @@ class GenModuleProcessor : TargetFileProcessor { onlyIfNull = true, ) ) + addCode("\n") addCode("return ") addCode( wrapperHelper.transform( @@ -237,6 +236,7 @@ class GenModuleProcessor : TargetFileProcessor { wannaType = returnType, ).collect() ) + addCode(" as %T", returnType) } } diff --git a/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/__hidden__/CacheAction.kt b/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/__hidden__/CacheAction.kt index 40240e81..6de62fde 100644 --- a/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/__hidden__/CacheAction.kt +++ b/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/__hidden__/CacheAction.kt @@ -1,6 +1,5 @@ package com.github.klee0kai.stone.__hidden__ -import com.github.klee0kai.stone.__hidden__.SwitchCacheParam import com.github.klee0kai.stone.annotations.component.SwitchCache /** @@ -28,7 +27,7 @@ class CacheAction( val isSwitchCacheAction: Boolean get() = type == ActionType.SWITCH_CACHE companion object { - val valueAction: CacheAction get() = CacheAction(ActionType.GET_VALUE) + val getValueAction: CacheAction get() = CacheAction(ActionType.GET_VALUE) fun setValueAction(value: Any?) = CacheAction(ActionType.SET_VALUE, value = value) From 0fe335395687532d372ac9c7452e1092b94ba3fb Mon Sep 17 00:00:00 2001 From: klee0kai Date: Sun, 23 Nov 2025 18:55:21 +0100 Subject: [PATCH 032/122] impl cache control interface --- .../klee0kai/thekey/stone/ksp/target/GenModuleProcessor.kt | 1 + 1 file changed, 1 insertion(+) diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/GenModuleProcessor.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/GenModuleProcessor.kt index 9a5fc9ef..dbd2704c 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/GenModuleProcessor.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/GenModuleProcessor.kt @@ -107,6 +107,7 @@ class GenModuleProcessor : TargetFileProcessor { superclass(moduleCl.toClassName()) } addSuperinterface(IModule::class) + addSuperinterface(moduleCl.cacheControlStoneClName) addModifiers(KModifier.OPEN) val codeBlocks = DelayedCodeBlocks() From a95b199e4818ec58462380e6110881d6f200e9c7 Mon Sep 17 00:00:00 2001 From: klee0kai Date: Mon, 24 Nov 2025 22:34:36 +0100 Subject: [PATCH 033/122] cache control methods --- .../helpers/itemholder/ItemHolderHelper.kt | 5 + .../itemholder/MultiKeyMapItemHolderHelper.kt | 12 ++ .../itemholder/SimpleMapItemHolderHelper.kt | 10 ++ .../itemholder/SingleItemHolderHelper.kt | 8 ++ .../target/GenModuleCacheControlProcessor.kt | 7 +- .../stone/ksp/target/GenModuleProcessor.kt | 116 +++++++++++++++--- .../klee0kai/stone/__hidden__/IModule.kt | 12 +- 7 files changed, 148 insertions(+), 22 deletions(-) diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/itemholder/ItemHolderHelper.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/itemholder/ItemHolderHelper.kt index b884095f..a3a500c5 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/itemholder/ItemHolderHelper.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/itemholder/ItemHolderHelper.kt @@ -20,6 +20,11 @@ interface ItemHolderHelper { onlyIfNull: Boolean, ): CodeBlock + fun statementSwitchRef( + paramsCode: CodeBlock, + ): CodeBlock + + fun clearNullsStatement(): CodeBlock } diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/itemholder/MultiKeyMapItemHolderHelper.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/itemholder/MultiKeyMapItemHolderHelper.kt index 161351d9..a4e24cbe 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/itemholder/MultiKeyMapItemHolderHelper.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/itemholder/MultiKeyMapItemHolderHelper.kt @@ -67,4 +67,16 @@ class MultiKeyMapItemHolderHelper( providingType.value = returnType.toClassName() }.collect() + override fun statementSwitchRef( + paramsCode: CodeBlock, + ): CodeBlock = CodeBlock.builder() + .addStatement("%L.switchCache(%L)", fieldName, paramsCode) + .build() + + + override fun clearNullsStatement(): CodeBlock = CodeBlock.Builder() + .addStatement("%L.clearNulls()", fieldName) + .build() + + } \ No newline at end of file diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/itemholder/SimpleMapItemHolderHelper.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/itemholder/SimpleMapItemHolderHelper.kt index 5fdfa460..20bdfa55 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/itemholder/SimpleMapItemHolderHelper.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/itemholder/SimpleMapItemHolderHelper.kt @@ -62,5 +62,15 @@ class SimpleMapItemHolderHelper( providingType.value = returnType.toClassName() }.collect() + override fun statementSwitchRef( + paramsCode: CodeBlock, + ): CodeBlock = CodeBlock.builder() + .addStatement("%L.switchCache(%L)", fieldName, paramsCode) + .build() + + override fun clearNullsStatement(): CodeBlock = CodeBlock.Builder() + .addStatement("%L.clearNulls()", fieldName) + .build() + } \ No newline at end of file diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/itemholder/SingleItemHolderHelper.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/itemholder/SingleItemHolderHelper.kt index 308d5663..1eb14d12 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/itemholder/SingleItemHolderHelper.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/itemholder/SingleItemHolderHelper.kt @@ -51,4 +51,12 @@ class SingleItemHolderHelper( providingType.value = returnType.toClassName() }.collect() + override fun statementSwitchRef( + paramsCode: CodeBlock, + ): CodeBlock = CodeBlock.builder() + .addStatement("%L.switchCache(%L)", fieldName, paramsCode) + .build() + + override fun clearNullsStatement(): CodeBlock = CodeBlock.of("") + } \ No newline at end of file diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/GenModuleCacheControlProcessor.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/GenModuleCacheControlProcessor.kt index 863fbdea..b16a1ea4 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/GenModuleCacheControlProcessor.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/GenModuleCacheControlProcessor.kt @@ -94,7 +94,12 @@ class GenModuleCacheControlProcessor : TargetFileProcessor { } genFun(function.cacheControlMethodName) { modifiers.add(KModifier.ABSTRACT) - returns(function.returnType!!.resolve().toClassName()) + returns( + returnType = function.returnType!! + .resolve() + .toClassName() + .copy(nullable = true) + ) addParameter("__action", CacheAction::class) idArguments.forEach { addParameter(it.name!!.asString(), it.type.resolve().toClassName()) diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/GenModuleProcessor.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/GenModuleProcessor.kt index dbd2704c..e5a2c743 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/GenModuleProcessor.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/GenModuleProcessor.kt @@ -4,6 +4,7 @@ package com.github.klee0kai.thekey.stone.ksp.target import com.github.klee0kai.stone.__hidden__.CacheAction import com.github.klee0kai.stone.__hidden__.IModule +import com.github.klee0kai.stone.__hidden__.SwitchCacheParam import com.github.klee0kai.stone.__hidden__.types.holders.SingleItemHolder import com.github.klee0kai.stone.__hidden__.types.holders.StoneRefType import com.github.klee0kai.stone.annotations.module.BindInstance @@ -14,6 +15,7 @@ import com.github.klee0kai.thekey.stone.ksp.helpers.* import com.github.klee0kai.thekey.stone.ksp.helpers.itemholder.ItemHolderHelper import com.github.klee0kai.thekey.stone.ksp.helpers.itemholder.of import com.github.klee0kai.thekey.stone.ksp.helpers.itemholder.toItemCacheType +import com.github.klee0kai.thekey.stone.ksp.helpers.wrap.ClassNameUtils.rawTypeOf import com.github.klee0kai.thekey.stone.ksp.helpers.wrap.WrapHelper import com.github.klee0kai.thekey.stone.ksp.ksp.arch.GenSpec import com.github.klee0kai.thekey.stone.ksp.ksp.arch.SymbolsToProcess @@ -30,11 +32,10 @@ import com.google.devtools.ksp.processing.Dependencies import com.google.devtools.ksp.processing.KSPLogger import com.google.devtools.ksp.processing.Resolver import com.google.devtools.ksp.symbol.* -import com.squareup.kotlinpoet.KModifier +import com.squareup.kotlinpoet.* import com.squareup.kotlinpoet.ParameterizedTypeName.Companion.parameterizedBy -import com.squareup.kotlinpoet.TypeSpec -import com.squareup.kotlinpoet.asClassName import com.squareup.kotlinpoet.ksp.toClassName +import kotlin.reflect.KClass class GenModuleProcessor : TargetFileProcessor { @@ -51,13 +52,13 @@ class GenModuleProcessor : TargetFileProcessor { } class DelayedCodeBlocks( - val initMethodCode: SmartCode = SmartCode(), - val initCachesFromMethodName: SmartCode = SmartCode(), - val bindMethodName: SmartCode = SmartCode(), - val getFactoryMethodName: SmartCode = SmartCode(), - val switchRefMethodName: SmartCode = SmartCode(), - val updateBindInstancesFrom: SmartCode = SmartCode(), - val clearNullsMethodName: SmartCode = SmartCode(), + val initMethodBody: SmartCode = SmartCode(), + val initCachesFromMethodBody: SmartCode = SmartCode(), + val bindMethodBody: SmartCode = SmartCode(), + val getFactoryMethodBody: SmartCode = SmartCode(), + val switchRefMethodBody: SmartCode = SmartCode(), + val updateBindInstancesFromBody: SmartCode = SmartCode(), + val clearNullsMethodBody: SmartCode = SmartCode(), ) @@ -130,6 +131,7 @@ class GenModuleProcessor : TargetFileProcessor { idArguments = idArguments, cacheType = bindAnn.cache.toItemCacheType(), ) + codeBlocks.clearNullsMethodBody.add(itemHolderHelper.clearNullsStatement()) with(itemHolderHelper) { genCacheField() @@ -152,15 +154,21 @@ class GenModuleProcessor : TargetFileProcessor { idArguments = idArguments, cacheType = provideAnn.cache.toItemCacheType() ?: return@forEachIndexed, ) + codeBlocks.clearNullsMethodBody.add(itemHolderHelper.clearNullsStatement()) with(itemHolderHelper) { genCacheField() } genProvideCachedFun( - function, - idArguments, - itemHolderHelper, - wrapperTypes, - wrapperHelper, + function = function, + idArguments = idArguments, + itemHolderHelper = itemHolderHelper, + wrapperHelper = wrapperHelper, + ) + genCacheControlFun( + function = function, + idArguments = idArguments, + itemHolderHelper = itemHolderHelper, + wrapperHelper = wrapperHelper, ) } } @@ -183,7 +191,6 @@ class GenModuleProcessor : TargetFileProcessor { function: KSFunctionDeclaration, idArguments: List, itemHolderHelper: ItemHolderHelper, - wrapperTypes: List, wrapperHelper: WrapHelper, ) { val returnType = function.returnType?.resolve()?.toClassName() ?: return @@ -241,6 +248,54 @@ class GenModuleProcessor : TargetFileProcessor { } } + private fun TypeSpec.Builder.genCacheControlFun( + function: KSFunctionDeclaration, + idArguments: List, + itemHolderHelper: ItemHolderHelper, + wrapperHelper: WrapHelper, + ) { + val returnType = function.returnType?.resolve()?.toClassName() ?: return + genFun(function.cacheControlMethodName) { + modifiers.add(KModifier.OVERRIDE) + returns(returnType.copy(nullable = true)) + addParameter("__action", CacheAction::class) + idArguments.forEach { + addParameter(it.name!!.asString(), it.type.resolve().toClassName()) + } + + addStatement( + "%L.get()?.%L( __action, %L ) ", + overridedModuleFieldName, + function.cacheControlMethodName, + idArguments.joinToString(", ") { it.name!!.asString() }, + ) + beginControlFlow("when (__action.type) {") + addStatement("%T.GET_VALUE -> Unit", CacheAction.ActionType::class) + //set value + beginControlFlow("%T.SET_VALUE ->", CacheAction.ActionType::class) + addCode("(__action.value as? %T)?.let { ", rawTypeOf(returnType)) + addCode(codeBlock = itemHolderHelper.codeSetCachedValue(CodeBlock.of("it"), onlyIfNull = false)) + addCode("}") + endControlFlow() + //set if null value + beginControlFlow("%T.SET_IF_NULL ->", CacheAction.ActionType::class) + addCode("(__action.value as? %T)?.let { ", rawTypeOf(returnType)) + addCode(codeBlock = itemHolderHelper.codeSetCachedValue(CodeBlock.of("it"), onlyIfNull = true)) + addCode("}") + endControlFlow() + // switch cache type + beginControlFlow("%T.SWITCH_CACHE ->", CacheAction.ActionType::class) + addCode(codeBlock = itemHolderHelper.statementSwitchRef(CodeBlock.of("__action.swCacheParams!!"))) + endControlFlow() + + addStatement("null -> Unit") + endControlFlow() + + addCode("return ") + addCode(codeBlock = itemHolderHelper.codeGetCachedValue().collect()) + } + } + private fun TypeSpec.Builder.genIModelMethods( moduleCl: KSClassDeclaration, codeBlocks: DelayedCodeBlocks, @@ -266,21 +321,50 @@ class GenModuleProcessor : TargetFileProcessor { } genFun(initMethodName) { + addModifiers(KModifier.OVERRIDE) + returns(BOOLEAN) + addParameter("or", Any::class) + //TODO } genFun(initCachesFromMethodName) { + addModifiers(KModifier.OVERRIDE) + addParameter("m", IModule::class) + //TODO } genFun(bindMethodName) { + addModifiers(KModifier.OVERRIDE) + addParameter("or", Any::class) + returns(BOOLEAN) + + addStatement("var %L = false", appliedLocalFieldName) } genFun(switchRefMethodName) { + addModifiers(KModifier.OVERRIDE) + addParameter( + "scopes", + Set::class.asClassName() + .parameterizedBy( + KClass::class.asClassName() + .parameterizedBy(STAR) + ) + ) + addParameter("__params", SwitchCacheParam::class) } genFun(updateBindInstancesFrom) { + addModifiers(KModifier.OVERRIDE) + addParameter("m", IModule::class) + addStatement("if (m == this) return") + + } genFun(clearNullsMethodName) { + addModifiers(KModifier.OVERRIDE) + addCode(codeBlocks.clearNullsMethodBody.collect()) } } diff --git a/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/__hidden__/IModule.kt b/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/__hidden__/IModule.kt index 7dc5cd7e..5911793e 100644 --- a/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/__hidden__/IModule.kt +++ b/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/__hidden__/IModule.kt @@ -1,5 +1,7 @@ package com.github.klee0kai.stone.__hidden__ +import kotlin.reflect.KClass + /** * Stone Private class */ @@ -19,20 +21,20 @@ interface IModule { * - a factory instance * - a factory class */ - fun __init(ob: Any?): Boolean + fun __init(ob: Any): Boolean /** * Init caches from module prototype. * using in extOf method */ - fun __initCachesFrom(module: com.github.klee0kai.stone.__hidden__.IModule?) + fun __initCachesFrom(module: IModule) /** * Update values of bindInstance variables * * @param module related module, source to update */ - fun __updateBindInstancesFrom(module: com.github.klee0kai.stone.__hidden__.IModule?) + fun __updateBindInstancesFrom(module: IModule) /** * bind instance objects @@ -43,9 +45,9 @@ interface IModule { /** - * TODO Switch cache type for scope + * Switch cache type for scope */ -// fun __switchRef(scopes: MutableSet?>?, param: SwitchCacheParam?) + public fun __switchRef(scopes: Set>, __params: SwitchCacheParam) /** * Clear null refs. From 0c1783ef384d4d4b83188475aa76e76be85df59b Mon Sep 17 00:00:00 2001 From: klee0kai Date: Mon, 24 Nov 2025 22:58:12 +0100 Subject: [PATCH 034/122] switch cache method --- .../ksp/helpers/itemholder/ItemCacheType.kt | 6 ++-- .../stone/ksp/target/GenModuleProcessor.kt | 28 ++++++++++++++++--- 2 files changed, 27 insertions(+), 7 deletions(-) diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/itemholder/ItemCacheType.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/itemholder/ItemCacheType.kt index cc418be2..9e63fb5b 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/itemholder/ItemCacheType.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/itemholder/ItemCacheType.kt @@ -6,17 +6,17 @@ import com.github.klee0kai.stone.annotations.component.GcStrongScope import com.github.klee0kai.stone.annotations.component.GcWeakScope import com.github.klee0kai.stone.annotations.module.BindInstance import com.github.klee0kai.stone.annotations.module.Provide -import kotlin.reflect.KClass +import com.squareup.kotlinpoet.asClassName enum class ItemCacheType { Strong, Soft, Weak; - val gcScopeClassName: KClass + val gcScopeClassName get() = when (this) { Weak -> GcWeakScope::class Strong -> GcStrongScope::class Soft -> GcSoftScope::class - } + }.asClassName() } fun ItemCacheType.toRefTypeSingle( diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/GenModuleProcessor.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/GenModuleProcessor.kt index e5a2c743..a67fd4fe 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/GenModuleProcessor.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/GenModuleProcessor.kt @@ -7,6 +7,7 @@ import com.github.klee0kai.stone.__hidden__.IModule import com.github.klee0kai.stone.__hidden__.SwitchCacheParam import com.github.klee0kai.stone.__hidden__.types.holders.SingleItemHolder import com.github.klee0kai.stone.__hidden__.types.holders.StoneRefType +import com.github.klee0kai.stone.annotations.component.GcAllScope import com.github.klee0kai.stone.annotations.module.BindInstance import com.github.klee0kai.stone.annotations.module.Module import com.github.klee0kai.stone.annotations.module.Provide @@ -59,6 +60,7 @@ class GenModuleProcessor : TargetFileProcessor { val switchRefMethodBody: SmartCode = SmartCode(), val updateBindInstancesFromBody: SmartCode = SmartCode(), val clearNullsMethodBody: SmartCode = SmartCode(), + val switchRefStatementBuilders: MutableMap, CodeBlock.Builder> = mutableMapOf() ) @@ -122,6 +124,10 @@ class GenModuleProcessor : TargetFileProcessor { val returnType = function.returnType?.resolve() ?: return@forEachIndexed val nonWrappedType = returnType.noWrappedType(wrapperTypes) val isListReturnType = nonWrappedType.isListType() + val gcScopes = (function.scopeAnnotations + .map { it.annotationType.resolve().toClassName() } + .toSet() + GcAllScope::class.asClassName()).toMutableSet() + when { bindAnn != null -> { @@ -131,6 +137,10 @@ class GenModuleProcessor : TargetFileProcessor { idArguments = idArguments, cacheType = bindAnn.cache.toItemCacheType(), ) + gcScopes += bindAnn.cache.toItemCacheType().gcScopeClassName + codeBlocks.switchRefStatementBuilders.getOrPut(gcScopes) { CodeBlock.builder() } + .add(itemHolderHelper.statementSwitchRef(CodeBlock.of("__params"))) + codeBlocks.clearNullsMethodBody.add(itemHolderHelper.clearNullsStatement()) with(itemHolderHelper) { @@ -154,6 +164,9 @@ class GenModuleProcessor : TargetFileProcessor { idArguments = idArguments, cacheType = provideAnn.cache.toItemCacheType() ?: return@forEachIndexed, ) + gcScopes += provideAnn.cache.toItemCacheType()!!.gcScopeClassName + codeBlocks.switchRefStatementBuilders.getOrPut(gcScopes) { CodeBlock.builder() } + .add(itemHolderHelper.statementSwitchRef(CodeBlock.of("__params"))) codeBlocks.clearNullsMethodBody.add(itemHolderHelper.clearNullsStatement()) with(itemHolderHelper) { genCacheField() @@ -168,7 +181,6 @@ class GenModuleProcessor : TargetFileProcessor { function = function, idArguments = idArguments, itemHolderHelper = itemHolderHelper, - wrapperHelper = wrapperHelper, ) } } @@ -252,7 +264,6 @@ class GenModuleProcessor : TargetFileProcessor { function: KSFunctionDeclaration, idArguments: List, itemHolderHelper: ItemHolderHelper, - wrapperHelper: WrapHelper, ) { val returnType = function.returnType?.resolve()?.toClassName() ?: return genFun(function.cacheControlMethodName) { @@ -352,14 +363,23 @@ class GenModuleProcessor : TargetFileProcessor { ) ) addParameter("__params", SwitchCacheParam::class) + + codeBlocks.switchRefStatementBuilders.forEach { (key, value) -> + addCode("if (listOf(") + key.forEachIndexed { idx,scope-> + if (idx >0) addCode(", ") + addCode("%T::class", scope) + } + beginControlFlow(").containsAll(scopes))") + addCode(value.build()) + endControlFlow() + } } genFun(updateBindInstancesFrom) { addModifiers(KModifier.OVERRIDE) addParameter("m", IModule::class) addStatement("if (m == this) return") - - } genFun(clearNullsMethodName) { From 9ed7835e6324ee0e1e6056789727f6f5e048d212 Mon Sep 17 00:00:00 2001 From: klee0kai Date: Thu, 27 Nov 2025 23:34:49 +0100 Subject: [PATCH 035/122] implement init cached from method --- .../helpers/annotations/ComponentAnnMirror.kt | 14 ++++++ .../stone/ksp/ksp/KSClassDeclarationExt.kt | 1 - .../stone/ksp/ksp/KSFunctionDeclarationExt.kt | 27 ++++++++++- .../stone/ksp/target/GenModuleProcessor.kt | 46 +++++++++++++++++-- .../klee0kai/stone/__hidden__/IModule.kt | 4 +- 5 files changed, 83 insertions(+), 9 deletions(-) diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/annotations/ComponentAnnMirror.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/annotations/ComponentAnnMirror.kt index 64f2ca72..0f7687ea 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/annotations/ComponentAnnMirror.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/annotations/ComponentAnnMirror.kt @@ -2,7 +2,9 @@ package com.github.klee0kai.thekey.stone.ksp.helpers.annotations import com.github.klee0kai.stone.annotations.component.Component import com.google.devtools.ksp.symbol.KSAnnotated +import com.google.devtools.ksp.symbol.KSAnnotation import com.google.devtools.ksp.symbol.KSType +import com.squareup.kotlinpoet.ClassName import com.squareup.kotlinpoet.asClassName import com.squareup.kotlinpoet.ksp.toClassName @@ -11,6 +13,18 @@ class ComponentAnnMirror( val wrapperProviders: List, ) + +fun KSAnnotated.annotations( + className: ClassName, +): Sequence = annotations + .filter { it.annotationType.resolve().toClassName() == className } + +fun KSType.annotations( + className: ClassName, +): Sequence = annotations + .filter { it.annotationType.resolve().toClassName() == className } + + @Suppress("UNCHECKED_CAST") fun KSAnnotated.findComponentAnnotation( ): Sequence = annotations diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/ksp/KSClassDeclarationExt.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/ksp/KSClassDeclarationExt.kt index 1fd78c7a..bcf1ab9b 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/ksp/KSClassDeclarationExt.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/ksp/KSClassDeclarationExt.kt @@ -21,7 +21,6 @@ fun KSDeclaration.isAnyType( vararg cl: KClass<*>, ) = cl.any { isType(it) } - fun KSDeclaration.isType(cl: KClass<*>): Boolean = qualifiedName?.asString() == cl.qualifiedName.toString() fun KSDeclaration.isType(cl: ClassName): Boolean = qualifiedName?.asString() == cl.toString() diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/ksp/KSFunctionDeclarationExt.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/ksp/KSFunctionDeclarationExt.kt index 421ae687..b19005e6 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/ksp/KSFunctionDeclarationExt.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/ksp/KSFunctionDeclarationExt.kt @@ -1,5 +1,6 @@ package com.github.klee0kai.thekey.stone.ksp.ksp +import com.google.devtools.ksp.symbol.KSClassDeclaration import com.google.devtools.ksp.symbol.KSFunctionDeclaration import com.google.devtools.ksp.symbol.KSValueParameter @@ -31,4 +32,28 @@ fun KSFunctionDeclaration.joinInvokeArguments( null } }.joinToString(", ") -} \ No newline at end of file +} + +fun KSFunctionDeclaration.isClassReturn( +): Boolean = returnType?.resolve()?.let { ret -> + val declaration = ret.declaration as? KSClassDeclaration ?: return@let false + declaration.qualifiedName?.asString() !in setOf( + "java.lang.Boolean", + "java.lang.Byte", + "java.lang.Short", + "java.lang.Integer", + "java.lang.Long", + "java.lang.Character", + "java.lang.Float", + "java.lang.Double", + "kotlin.Boolean", + "kotlin.Byte", + "kotlin.Short", + "kotlin.Int", + "kotlin.Long", + "kotlin.Char", + "kotlin.Float", + "kotlin.Double", + "kotlin.Unit", + ) +} ?: false diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/GenModuleProcessor.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/GenModuleProcessor.kt index a67fd4fe..fffc88fe 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/GenModuleProcessor.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/GenModuleProcessor.kt @@ -13,6 +13,7 @@ import com.github.klee0kai.stone.annotations.module.Module import com.github.klee0kai.stone.annotations.module.Provide import com.github.klee0kai.stone.weakref.Ref import com.github.klee0kai.thekey.stone.ksp.helpers.* +import com.github.klee0kai.thekey.stone.ksp.helpers.annotations.annotations import com.github.klee0kai.thekey.stone.ksp.helpers.itemholder.ItemHolderHelper import com.github.klee0kai.thekey.stone.ksp.helpers.itemholder.of import com.github.klee0kai.thekey.stone.ksp.helpers.itemholder.toItemCacheType @@ -28,6 +29,7 @@ import com.github.klee0kai.thekey.stone.ksp.poet.smartcode.add import com.github.klee0kai.thekey.stone.ksp.poet.smartcode.smartCode import com.google.devtools.ksp.KspExperimental import com.google.devtools.ksp.containingFile +import com.google.devtools.ksp.getAllSuperTypes import com.google.devtools.ksp.getAnnotationsByType import com.google.devtools.ksp.processing.Dependencies import com.google.devtools.ksp.processing.KSPLogger @@ -188,7 +190,11 @@ class GenModuleProcessor : TargetFileProcessor { } - genIModelMethods(moduleCl, codeBlocks) + genIModelMethods( + moduleCl = moduleCl, + identifierTypes = identifierTypes, + codeBlocks = codeBlocks, + ) } } @@ -309,9 +315,10 @@ class GenModuleProcessor : TargetFileProcessor { private fun TypeSpec.Builder.genIModelMethods( moduleCl: KSClassDeclaration, + identifierTypes: List, codeBlocks: DelayedCodeBlocks, + ) { - ) { genProperty( name = factoryFieldName, type = moduleCl.toClassName(), @@ -341,7 +348,36 @@ class GenModuleProcessor : TargetFileProcessor { genFun(initCachesFromMethodName) { addModifiers(KModifier.OVERRIDE) addParameter("m", IModule::class) - //TODO + addStatement("if (m == this) return") + (sequenceOf(moduleCl) + moduleCl.getAllSuperTypes().map { it.declaration }) + .filter { it.annotations(Module::class.asClassName()).any() } + .mapNotNull { it as? KSClassDeclaration } + .forEach { cl -> + val cacheControlCl = cl.cacheControlStoneClName + beginControlFlow("if ( m is %T )", cacheControlCl) + addStatement("val module = m as %T", cacheControlCl) + + cl.getAllMethods( + includeObjectMethods = false, + allowDoubles = false, + exceptNames = arrayOf(""), + ).forEach { protoProvideMethod -> + val cacheControlMethod = protoProvideMethod.cacheControlMethodName + val idArguments = protoProvideMethod.parameters + .filter { it.type.resolve() in identifierTypes } + if (!idArguments.isEmpty()) { + // TODO https://github.com/klee0kai/stone/issues/42 + return@forEach + } + + addStatement( + "%L( %T.setIfNullValueAction( module.%L( %T.getValueAction ) ) )", + cacheControlMethod, CacheAction::class, + protoProvideMethod, CacheAction::class, + ); + } + endControlFlow() + } } genFun(bindMethodName) { @@ -366,8 +402,8 @@ class GenModuleProcessor : TargetFileProcessor { codeBlocks.switchRefStatementBuilders.forEach { (key, value) -> addCode("if (listOf(") - key.forEachIndexed { idx,scope-> - if (idx >0) addCode(", ") + key.forEachIndexed { idx, scope -> + if (idx > 0) addCode(", ") addCode("%T::class", scope) } beginControlFlow(").containsAll(scopes))") diff --git a/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/__hidden__/IModule.kt b/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/__hidden__/IModule.kt index 5911793e..ed839571 100644 --- a/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/__hidden__/IModule.kt +++ b/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/__hidden__/IModule.kt @@ -39,9 +39,9 @@ interface IModule { /** * bind instance objects * - * @param object - An instance of bindable objects + * @param or - An instance of bindable objects */ - fun __bind(`object`: Any?): Boolean + fun __bind(or: Any): Boolean /** From a17408470f31189d98b771c3b7217567d64a7a1a Mon Sep 17 00:00:00 2001 From: klee0kai Date: Fri, 28 Nov 2025 20:56:23 +0100 Subject: [PATCH 036/122] module init method --- .../stone/ksp/target/GenModuleProcessor.kt | 43 ++++++++++++++++++- 1 file changed, 42 insertions(+), 1 deletion(-) diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/GenModuleProcessor.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/GenModuleProcessor.kt index fffc88fe..dc6d784f 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/GenModuleProcessor.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/GenModuleProcessor.kt @@ -150,6 +150,13 @@ class GenModuleProcessor : TargetFileProcessor { genOverrideFun(function) { } + + codeBlocks.bindMethodBody.add { + add("if (or::class == %T::class) {\n", nonWrappedType) + add(codeSetCachedValue(CodeBlock.of("or"), false)) + add("%L = true", appliedLocalFieldName) + add("}") + } } } @@ -342,7 +349,38 @@ class GenModuleProcessor : TargetFileProcessor { addModifiers(KModifier.OVERRIDE) returns(BOOLEAN) addParameter("or", Any::class) - //TODO + addStatement("if (or === this) return false") + addStatement("var %L = false", appliedLocalFieldName) + + // check module class + beginControlFlow( + "if ( (or is %T) ) ", + moduleCl.cacheControlStoneClName, + ) + addStatement( + "%L.set(onlyIfNull = false) { or }", + overridedModuleFieldName, + ) + addStatement( + "%L = (or as %T).%L as %T", + factoryFieldName, + IModule::class.asClassName(), + factoryFieldName, + moduleCl.toClassName(), + ) + addStatement("%L = true", appliedLocalFieldName) + endControlFlow() // check factory class + beginControlFlow("else if (or is %T) ", moduleCl.toClassName()) + addStatement( + "%L = or as %T", + factoryFieldName, + moduleCl.toClassName(), + + ) + addStatement("%L = true", appliedLocalFieldName) + endControlFlow() // get module factory by module class + + addStatement("return %L", appliedLocalFieldName) } genFun(initCachesFromMethodName) { @@ -384,8 +422,11 @@ class GenModuleProcessor : TargetFileProcessor { addModifiers(KModifier.OVERRIDE) addParameter("or", Any::class) returns(BOOLEAN) + addStatement("%L.get()?.%L(or)", overridedModuleFieldName, bindMethodName) addStatement("var %L = false", appliedLocalFieldName) + addCode(codeBlocks.bindMethodBody.collect()) + addStatement("return %L", appliedLocalFieldName) } genFun(switchRefMethodName) { From 1a919184d91d1dc794db334c5154101d04540729 Mon Sep 17 00:00:00 2001 From: klee0kai Date: Fri, 28 Nov 2025 22:00:17 +0100 Subject: [PATCH 037/122] bind instance --- .../itemholder/SingleItemHolderHelper.kt | 2 +- .../thekey/stone/ksp/property/Property.kt | 3 + .../ksp/target/GenModuleFactoryProcessor.kt | 6 +- .../stone/ksp/target/GenModuleProcessor.kt | 101 +++++++++++++++--- 4 files changed, 96 insertions(+), 16 deletions(-) diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/itemholder/SingleItemHolderHelper.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/itemholder/SingleItemHolderHelper.kt index 1eb14d12..65884739 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/itemholder/SingleItemHolderHelper.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/itemholder/SingleItemHolderHelper.kt @@ -47,7 +47,7 @@ class SingleItemHolderHelper( val setMethod = if (isListCaching) "setList" else "set" add("%L.%L(onlyIfNull = %L ){ ", fieldName, setMethod, onlyIfNull) add(value) - add("}") + add(" }") providingType.value = returnType.toClassName() }.collect() diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/property/Property.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/property/Property.kt index 3175b5be..ab53b2e6 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/property/Property.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/property/Property.kt @@ -27,6 +27,9 @@ class Property( fun subscribeChanges( block: (T) -> Unit, ) { + if (block === updateThisValueSubscription) { + return + } subscriptions += block block(value) } diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/GenModuleFactoryProcessor.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/GenModuleFactoryProcessor.kt index 2dd8280c..af641657 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/GenModuleFactoryProcessor.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/GenModuleFactoryProcessor.kt @@ -84,7 +84,11 @@ class GenModuleFactoryProcessor : TargetFileProcessor { genOverrideFun(function) { when { bindInstanceAnn != null -> { - addStatement("return null") + addStatement( + "throw %T(%S)", + NotImplementedError::class.asClassName(), + "Object generation is not available for bind instance methods" + ) } constructorFun != null -> { diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/GenModuleProcessor.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/GenModuleProcessor.kt index dc6d784f..9ca00d9b 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/GenModuleProcessor.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/GenModuleProcessor.kt @@ -55,17 +55,11 @@ class GenModuleProcessor : TargetFileProcessor { } class DelayedCodeBlocks( - val initMethodBody: SmartCode = SmartCode(), - val initCachesFromMethodBody: SmartCode = SmartCode(), val bindMethodBody: SmartCode = SmartCode(), - val getFactoryMethodBody: SmartCode = SmartCode(), - val switchRefMethodBody: SmartCode = SmartCode(), - val updateBindInstancesFromBody: SmartCode = SmartCode(), val clearNullsMethodBody: SmartCode = SmartCode(), val switchRefStatementBuilders: MutableMap, CodeBlock.Builder> = mutableMapOf() ) - override suspend fun findSymbolsToProcess( resolver: Resolver, ) = SymbolsToProcess( @@ -147,22 +141,48 @@ class GenModuleProcessor : TargetFileProcessor { with(itemHolderHelper) { genCacheField() - genOverrideFun(function) { - - } codeBlocks.bindMethodBody.add { - add("if (or::class == %T::class) {\n", nonWrappedType) + add( + "if (or is %T && or::class == %T::class) {\n", + nonWrappedType.toClassName().copy(nullable = false), + nonWrappedType.toClassName().copy(nullable = false), + ) add(codeSetCachedValue(CodeBlock.of("or"), false)) - add("%L = true", appliedLocalFieldName) - add("}") + add("\n") + add("%L = true\n", appliedLocalFieldName) + add("}\n") } } + + genBindInstance( + function = function, + idArguments = idArguments, + itemHolderHelper = itemHolderHelper, + wrapperHelper = wrapperHelper, + ) + genCacheControlFun( + function = function, + idArguments = idArguments, + itemHolderHelper = itemHolderHelper, + ) + + } provideAnn == null || provideAnn.cache == Provide.CacheType.Factory -> { genOverrideFun(function) { - + addStatement( + "return %L.%L(%L)", factoryFieldName, + function.simpleName.asString(), + function.parameters.joinToString(", ") { it.name!!.asString() }) + } + genFun(function.cacheControlMethodName) { + modifiers.add(KModifier.OVERRIDE) + val returnType = function.returnType?.resolve()?.toClassName() + returnType?.let { returns(returnType.copy(nullable = true)) } + addParameter("__action", CacheAction::class) + addStatement("return null") } } @@ -212,6 +232,59 @@ class GenModuleProcessor : TargetFileProcessor { ) } + + private fun TypeSpec.Builder.genBindInstance( + function: KSFunctionDeclaration, + idArguments: List, + itemHolderHelper: ItemHolderHelper, + wrapperHelper: WrapHelper, + ) { + val returnType = function.returnType?.resolve() ?: return + val setValueArg = function.parameters.firstOrNull { it.type.resolve() == returnType } + + genOverrideFun(function) { + addStatement( + "val cached = %L.get()?.%L( %T.getValueAction, %L ) ", + overridedModuleFieldName, + function.cacheControlMethodName, + CacheAction::class.asClassName(), + idArguments.joinToString(", ") { it.name!!.asString() }, + ) + addCode("if (cached != null ) return ") + addCode( + wrapperHelper.transform( + code = smartCode { + providingType.value = wrapperHelper.listWrapTypeIfNeed(returnType.toClassName()) + add("cached") + }, + wannaType = returnType.toClassName(), + ).collect() + ) + addStatement("") + + if (setValueArg != null) { + beginControlFlow("if (%L != null)", setValueArg.name!!.asString()) + addCode( + itemHolderHelper.codeSetCachedValue( + value = CodeBlock.of("%L", setValueArg.name!!.asString()), + onlyIfNull = false + ) + ) + endControlFlow(); + } + + + addCode("return ") + addCode( + wrapperHelper.transform( + code = itemHolderHelper.codeGetCachedValue(), + wannaType = returnType.toClassName(), + ).collect() + ) + addCode(" as %T", returnType.toClassName()) + } + } + private fun TypeSpec.Builder.genProvideCachedFun( function: KSFunctionDeclaration, idArguments: List, @@ -411,7 +484,7 @@ class GenModuleProcessor : TargetFileProcessor { addStatement( "%L( %T.setIfNullValueAction( module.%L( %T.getValueAction ) ) )", cacheControlMethod, CacheAction::class, - protoProvideMethod, CacheAction::class, + cacheControlMethod, CacheAction::class, ); } endControlFlow() From ddce0da357e1b19393488347c2efe5be5fe36da1 Mon Sep 17 00:00:00 2001 From: klee0kai Date: Sun, 30 Nov 2025 09:19:33 +0100 Subject: [PATCH 038/122] component methods checks --- .../klee0kai/thekey/stone/ksp/Processor.kt | 2 + .../helpers/annotations/ComponentAnnMirror.kt | 14 ++ .../stone/ksp/ksp/KSClassDeclarationExt.kt | 28 ++- .../stone/ksp/ksp/KSFunctionDeclarationExt.kt | 24 +- .../stone/ksp/target/GenModuleProcessor.kt | 9 + .../target/component/ComponentsMethodsExt.kt | 232 ++++++++++++++++++ .../target/component/GenComponentProcessor.kt | 66 +++++ 7 files changed, 352 insertions(+), 23 deletions(-) create mode 100644 stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/component/ComponentsMethodsExt.kt create mode 100644 stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/component/GenComponentProcessor.kt diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/Processor.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/Processor.kt index 34915393..e2cefbac 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/Processor.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/Processor.kt @@ -6,6 +6,7 @@ import com.github.klee0kai.thekey.stone.ksp.ksp.arch.GenSpec import com.github.klee0kai.thekey.stone.ksp.ksp.arch.filter import com.github.klee0kai.thekey.stone.ksp.ksp.arch.forceProcess import com.github.klee0kai.thekey.stone.ksp.ksp.arch.nowTakeOnly +import com.github.klee0kai.thekey.stone.ksp.target.component.GenComponentProcessor import com.github.klee0kai.thekey.stone.ksp.target.GenModuleCacheControlProcessor import com.github.klee0kai.thekey.stone.ksp.target.GenModuleFactoryProcessor import com.github.klee0kai.thekey.stone.ksp.target.GenModuleProcessor @@ -68,6 +69,7 @@ class Processor( GenModuleFactoryProcessor(), GenModuleCacheControlProcessor(), GenModuleProcessor(), + GenComponentProcessor(), ) override fun process( diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/annotations/ComponentAnnMirror.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/annotations/ComponentAnnMirror.kt index 0f7687ea..ff736429 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/annotations/ComponentAnnMirror.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/annotations/ComponentAnnMirror.kt @@ -19,6 +19,20 @@ fun KSAnnotated.annotations( ): Sequence = annotations .filter { it.annotationType.resolve().toClassName() == className } + +fun KSAnnotated.anyAnnotation( + vararg classNames: ClassName, +): Sequence = annotations + .filter { it.annotationType.resolve().toClassName() in classNames } + + +fun KSAnnotated.hasOnlyAnnotation( + className: ClassName, +): Boolean { + if (annotations.count() != 1) return false + return annotations.first().annotationType.resolve().toClassName() == className +} + fun KSType.annotations( className: ClassName, ): Sequence = annotations diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/ksp/KSClassDeclarationExt.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/ksp/KSClassDeclarationExt.kt index bcf1ab9b..987db3dc 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/ksp/KSClassDeclarationExt.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/ksp/KSClassDeclarationExt.kt @@ -61,4 +61,30 @@ fun KSClassDeclaration.getAllMethods( it1.isSameMethods(it2) } ) -} \ No newline at end of file +} + + +val KSType.isUnit: Boolean get() = declaration.qualifiedName?.asString() == "kotlin.Unit" + +val KSType.isNotPrimitive: Boolean + get() { + return declaration.qualifiedName?.asString() !in setOf( + "java.lang.Boolean", + "java.lang.Byte", + "java.lang.Short", + "java.lang.Integer", + "java.lang.Long", + "java.lang.Character", + "java.lang.Float", + "java.lang.Double", + "kotlin.Boolean", + "kotlin.Byte", + "kotlin.Short", + "kotlin.Int", + "kotlin.Long", + "kotlin.Char", + "kotlin.Float", + "kotlin.Double", + "kotlin.Unit", + ) + } diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/ksp/KSFunctionDeclarationExt.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/ksp/KSFunctionDeclarationExt.kt index b19005e6..d3c51d4b 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/ksp/KSFunctionDeclarationExt.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/ksp/KSFunctionDeclarationExt.kt @@ -2,6 +2,7 @@ package com.github.klee0kai.thekey.stone.ksp.ksp import com.google.devtools.ksp.symbol.KSClassDeclaration import com.google.devtools.ksp.symbol.KSFunctionDeclaration +import com.google.devtools.ksp.symbol.KSType import com.google.devtools.ksp.symbol.KSValueParameter fun KSFunctionDeclaration.isSameMethods( @@ -35,25 +36,4 @@ fun KSFunctionDeclaration.joinInvokeArguments( } fun KSFunctionDeclaration.isClassReturn( -): Boolean = returnType?.resolve()?.let { ret -> - val declaration = ret.declaration as? KSClassDeclaration ?: return@let false - declaration.qualifiedName?.asString() !in setOf( - "java.lang.Boolean", - "java.lang.Byte", - "java.lang.Short", - "java.lang.Integer", - "java.lang.Long", - "java.lang.Character", - "java.lang.Float", - "java.lang.Double", - "kotlin.Boolean", - "kotlin.Byte", - "kotlin.Short", - "kotlin.Int", - "kotlin.Long", - "kotlin.Char", - "kotlin.Float", - "kotlin.Double", - "kotlin.Unit", - ) -} ?: false +): Boolean = returnType?.resolve()?.isNotPrimitive ?: false diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/GenModuleProcessor.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/GenModuleProcessor.kt index 9ca00d9b..611a78ab 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/GenModuleProcessor.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/GenModuleProcessor.kt @@ -52,6 +52,15 @@ class GenModuleProcessor : TargetFileProcessor { const val bindMethodName: String = "__bind" const val switchRefMethodName: String = "__switchRef" const val clearNullsMethodName: String = "__clearNulls" + + val allReserveMethodNames = listOf( + initMethodName, + initCachesFromMethodName, + updateBindInstancesFrom, + bindMethodName, + switchRefMethodName, + clearNullsMethodName, + ) } class DelayedCodeBlocks( diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/component/ComponentsMethodsExt.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/component/ComponentsMethodsExt.kt new file mode 100644 index 00000000..d3035486 --- /dev/null +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/component/ComponentsMethodsExt.kt @@ -0,0 +1,232 @@ +package com.github.klee0kai.thekey.stone.ksp.target.component + +import com.github.klee0kai.stone.annotations.component.* +import com.github.klee0kai.stone.annotations.dependencies.Dependencies +import com.github.klee0kai.stone.annotations.module.BindInstance +import com.github.klee0kai.stone.annotations.module.Module +import com.github.klee0kai.thekey.stone.ksp.exceptions.IncorrectSignatureException +import com.github.klee0kai.thekey.stone.ksp.helpers.annotations.annotations +import com.github.klee0kai.thekey.stone.ksp.helpers.annotations.anyAnnotation +import com.github.klee0kai.thekey.stone.ksp.helpers.annotations.hasOnlyAnnotation +import com.github.klee0kai.thekey.stone.ksp.helpers.scopeAnnotations +import com.github.klee0kai.thekey.stone.ksp.ksp.isClassReturn +import com.github.klee0kai.thekey.stone.ksp.ksp.isNotPrimitive +import com.github.klee0kai.thekey.stone.ksp.ksp.isUnit +import com.github.klee0kai.thekey.stone.ksp.target.GenModuleProcessor +import com.google.devtools.ksp.getAllSuperTypes +import com.google.devtools.ksp.symbol.KSClassDeclaration +import com.google.devtools.ksp.symbol.KSFunctionDeclaration +import com.squareup.kotlinpoet.asClassName +import com.squareup.kotlinpoet.ksp.toClassName + +enum class BindInstanceType { + BindInstance, + BindInstanceAndProvide +} + +val KSFunctionDeclaration.isModuleFactoryProvideMethod: Boolean + get() { + if (!isProvideMethodSimple) return false + val moduleCl = returnType?.resolve()?.declaration as? KSClassDeclaration ?: return false + if (!moduleCl.annotations(Module::class.asClassName()).any()) return false + if (!annotations(ModuleOriginFactory::class.asClassName()).any()) return false + + if (parameters.isNotEmpty()) { + throw IncorrectSignatureException("${simpleName.asString()} must no have arguments") + } + if (!hasOnlyAnnotation(ModuleOriginFactory::class.asClassName())) { + throw IncorrectSignatureException("${simpleName.asString()} must have only one annotation ${ModuleOriginFactory::class.simpleName}") + } + checkMethodNameBusy() + + return true + } + +val KSFunctionDeclaration.isModuleProvideMethod: Boolean + get() { + if (!isProvideMethodSimple) return false + val moduleCl = returnType?.resolve()?.declaration as? KSClassDeclaration ?: return false + if (!moduleCl.annotations(Module::class.asClassName()).any()) return false + if (annotations(ModuleOriginFactory::class.asClassName()).any()) return false + + if (parameters.isNotEmpty()) { + throw IncorrectSignatureException("${simpleName.asString()} must no have arguments") + } + if (annotations.any()) { + throw IncorrectSignatureException("${simpleName.asString()} must no have annotations") + } + checkMethodNameBusy() + + return true + } + +val KSFunctionDeclaration.isDepsProvideMethod: Boolean + get() { + if (!isProvideMethodSimple) return false + val depCl = returnType?.resolve()?.declaration as? KSClassDeclaration ?: return false + if (!depCl.annotations(Dependencies::class.asClassName()).any()) return false + if (parameters.isNotEmpty()) { + throw IncorrectSignatureException("${simpleName.asString()} must no have arguments") + } + if (annotations.any()) { + throw IncorrectSignatureException("${simpleName.asString()} must no have annotations") + } + checkMethodNameBusy() + return true + } + +val KSFunctionDeclaration.isObjectProvideMethod: Boolean + get() = isProvideMethodSimple && !isModuleProvideMethod && !isDepsProvideMethod && !isModuleFactoryProvideMethod + +val KSFunctionDeclaration.isModuleInitMethod: Boolean + get() { + if (!annotations(Init::class.asClassName()).any()) return false + + if (!hasOnlyAnnotation(Init::class.asClassName())) { + throw IncorrectSignatureException("${simpleName.asString()} must have only one annotation ${Init::class.simpleName}") + } + if (parameters.size != 1) { + throw IncorrectSignatureException("${simpleName.asString()} must have only one parameter of Dependency or Module instance") + } + if (returnType?.resolve()?.isUnit == false) { + throw IncorrectSignatureException("${simpleName.asString()} must return unit") + } + + parameters.forEach { + val clDeclaration = it.type + .resolve() + .declaration as? KSClassDeclaration + ?: throw IncorrectSignatureException("${simpleName.asString()} must have only one parameter of Dependency or Module instance") + + if (!clDeclaration.anyAnnotation(Module::class.asClassName(), Dependencies::class.asClassName()).any()) { + throw IncorrectSignatureException("${simpleName.asString()} must have only one parameter of Dependency or Module instance") + } + } + checkMethodNameBusy() + return true + } + +fun KSFunctionDeclaration.isExtOfMethod( + clOwner: KSClassDeclaration, +): Boolean { + if (!annotations(ExtendOf::class.asClassName()).any()) return false + + if (!hasOnlyAnnotation(ExtendOf::class.asClassName())) { + throw IncorrectSignatureException("${simpleName.asString()} must have only one annotation ${ExtendOf::class.simpleName}") + } + if (parameters.size != 1) { + throw IncorrectSignatureException("${simpleName.asString()} must have only one parameter of Component instance") + } + if (returnType?.resolve()?.isUnit == false) { + throw IncorrectSignatureException("${simpleName.asString()} must return unit") + } + val argumentType = parameters.firstOrNull()?.type + ?.resolve() as? KSClassDeclaration + ?: throw IncorrectSignatureException("${simpleName.asString()} must have only one parameter of Component instance") + + if (!argumentType.annotations(Component::class.asClassName()).any()) { + throw IncorrectSignatureException("${argumentType.simpleName.asString()} must have @Component annotation") + } + if (!clOwner.getAllSuperTypes().any { parent -> parent.toClassName() == argumentType.toClassName() }) { + throw IncorrectSignatureException( + message = "The argument for the method ${simpleName.asString()} must be the parent class of the class ${clOwner.toClassName()}. " + + "The class ${argumentType.toClassName()} is not a parent to the class ${clOwner.toClassName()}." + ) + } + + checkMethodNameBusy() + return true +} + + +val KSFunctionDeclaration.isBindInstanceMethod: BindInstanceType? + get() { + if (!annotations(BindInstance::class.asClassName()).any()) return null + + if (!hasOnlyAnnotation(BindInstance::class.asClassName())) { + throw IncorrectSignatureException("${simpleName.asString()} must have only one annotation ${BindInstance::class.simpleName}") + } + if (parameters.size != 1) { + throw IncorrectSignatureException("${simpleName.asString()} must have only one parameter of binding type") + } + checkMethodNameBusy() + + when { + returnType?.resolve()?.isNotPrimitive == true -> { + return BindInstanceType.BindInstance + } + + returnType?.resolve()?.toClassName() == parameters.first().type.resolve().toClassName() -> { + return BindInstanceType.BindInstanceAndProvide + } + } + + throw IncorrectSignatureException("${simpleName.asString()} has incorrect signature") + } + +val KSFunctionDeclaration.isGcMethod: Boolean + get() { + if (!annotations(RunGc::class.asClassName()).any()) return false + if (!scopeAnnotations.any()) { + throw IncorrectSignatureException("${simpleName.asString()} must use GC scope annotation") + } + + if (returnType?.resolve()?.isUnit == false) { + throw IncorrectSignatureException("${simpleName.asString()} must have return type is Unit") + } + + checkMethodNameBusy() + return true + } + + +val KSFunctionDeclaration.isSwitchCacheMethod: Boolean + get() { + if (!annotations(SwitchCache::class.asClassName()).any()) return false + + if (!hasOnlyAnnotation(SwitchCache::class.asClassName())) { + throw IncorrectSignatureException("${simpleName.asString()} must use only ${SwitchCache::class.simpleName} annotation") + } + if (parameters.isNotEmpty()) { + throw IncorrectSignatureException("${simpleName.asString()} must no have arguments") + } + if (returnType?.resolve()?.isUnit == false) { + throw IncorrectSignatureException("${simpleName.asString()} must have return type is Unit") + } + checkMethodNameBusy() + return true + } + +val KSFunctionDeclaration.isInjectMethod: Boolean + get() { + if (annotations.any()) return false + if (returnType?.resolve()?.isUnit == false) return false + if (parameters.size != 1) return false + checkMethodNameBusy() + return true + } + +val KSFunctionDeclaration.isProtectInjectedMethod: Boolean + get() { + if (!annotations(ProtectInjected::class.asClassName()).any()) return false + if (returnType?.resolve()?.isUnit == false) { + throw IncorrectSignatureException("${simpleName.asString()} must have return type is Unit") + } + if (parameters.size != 1) { + throw IncorrectSignatureException("${simpleName.asString()} must have only one parameter") + } + checkMethodNameBusy() + return true + } + + +fun KSFunctionDeclaration.checkMethodNameBusy() { + val reserved = + simpleName.asString() in GenModuleProcessor.allReserveMethodNames + GenComponentProcessor.allReserveMethodNames + if (reserved) throw IncorrectSignatureException("Function name ${simpleName.asString()} is reserved by stone library") +} + + +private val KSFunctionDeclaration.isProvideMethodSimple get() = isClassReturn() + + diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/component/GenComponentProcessor.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/component/GenComponentProcessor.kt new file mode 100644 index 00000000..d4dcedcd --- /dev/null +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/component/GenComponentProcessor.kt @@ -0,0 +1,66 @@ +package com.github.klee0kai.thekey.stone.ksp.target.component + +import com.github.klee0kai.stone.annotations.component.Component +import com.github.klee0kai.thekey.stone.ksp.helpers.allIdentifierTypes +import com.github.klee0kai.thekey.stone.ksp.helpers.componentStoneClName +import com.github.klee0kai.thekey.stone.ksp.helpers.wrapperProviders +import com.github.klee0kai.thekey.stone.ksp.ksp.arch.GenSpec +import com.github.klee0kai.thekey.stone.ksp.ksp.arch.SymbolsToProcess +import com.github.klee0kai.thekey.stone.ksp.ksp.arch.TargetFileProcessor +import com.github.klee0kai.thekey.stone.ksp.poet.genClass +import com.github.klee0kai.thekey.stone.ksp.poet.genFileSpec +import com.github.klee0kai.thekey.stone.ksp.poet.genLibComment +import com.google.devtools.ksp.containingFile +import com.google.devtools.ksp.processing.Dependencies +import com.google.devtools.ksp.processing.KSPLogger +import com.google.devtools.ksp.processing.Resolver +import com.google.devtools.ksp.symbol.KSAnnotated +import com.google.devtools.ksp.symbol.KSClassDeclaration +import com.squareup.kotlinpoet.asClassName + +class GenComponentProcessor : TargetFileProcessor { + + companion object { + val allReserveMethodNames = listOf() + } + + override suspend fun findSymbolsToProcess( + resolver: Resolver, + ) = SymbolsToProcess( + symbolsForProcessing = resolver + .getSymbolsWithAnnotation(Component::class.asClassName().canonicalName) + .toList(), + symbolsForReprocessing = emptyList(), + ) + + override suspend fun process( + validSymbol: KSAnnotated, + resolver: Resolver, + options: Map, + logger: KSPLogger + ): GenSpec? { + + val fileOwner = validSymbol.containingFile ?: return null + val componentCl = validSymbol as? KSClassDeclaration ?: return null + + val identifierTypes = componentCl.allIdentifierTypes.toList() + val wrapperTypes = componentCl.wrapperProviders.toList() + + + val genComponentClassName = componentCl.componentStoneClName + + val fileSpec = genFileSpec(genComponentClassName.packageName, genComponentClassName.simpleName) { + genLibComment() + + genClass(genComponentClassName) { + + } + } + + return GenSpec( + fileSpec = fileSpec, + // https://kotlinlang.org/docs/ksp-incremental.html + dependencies = Dependencies(aggregating = false, fileOwner), + ) + } +} \ No newline at end of file From eda1fddeb182ecf96d7435412c4066b86b6b640a Mon Sep 17 00:00:00 2001 From: klee0kai Date: Sun, 30 Nov 2025 09:57:39 +0100 Subject: [PATCH 039/122] component: gen init method --- .../target/component/ComponentsMethodsExt.kt | 137 ++++++++++++---- .../target/component/GenComponentProcessor.kt | 150 +++++++++++++++++- .../stone/__hidden__/IPrivateComponent.kt | 2 +- 3 files changed, 256 insertions(+), 33 deletions(-) diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/component/ComponentsMethodsExt.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/component/ComponentsMethodsExt.kt index d3035486..fff5ab0c 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/component/ComponentsMethodsExt.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/component/ComponentsMethodsExt.kt @@ -32,10 +32,16 @@ val KSFunctionDeclaration.isModuleFactoryProvideMethod: Boolean if (!annotations(ModuleOriginFactory::class.asClassName()).any()) return false if (parameters.isNotEmpty()) { - throw IncorrectSignatureException("${simpleName.asString()} must no have arguments") + throw IncorrectSignatureException( + message = "${simpleName.asString()} must no have arguments", + element = this, + ) } if (!hasOnlyAnnotation(ModuleOriginFactory::class.asClassName())) { - throw IncorrectSignatureException("${simpleName.asString()} must have only one annotation ${ModuleOriginFactory::class.simpleName}") + throw IncorrectSignatureException( + message = "${simpleName.asString()} must have only one annotation ${ModuleOriginFactory::class.simpleName}", + element = this, + ) } checkMethodNameBusy() @@ -50,10 +56,16 @@ val KSFunctionDeclaration.isModuleProvideMethod: Boolean if (annotations(ModuleOriginFactory::class.asClassName()).any()) return false if (parameters.isNotEmpty()) { - throw IncorrectSignatureException("${simpleName.asString()} must no have arguments") + throw IncorrectSignatureException( + message = "${simpleName.asString()} must no have arguments", + element = this, + ) } if (annotations.any()) { - throw IncorrectSignatureException("${simpleName.asString()} must no have annotations") + throw IncorrectSignatureException( + message = "${simpleName.asString()} must no have annotations", + element = this, + ) } checkMethodNameBusy() @@ -66,10 +78,16 @@ val KSFunctionDeclaration.isDepsProvideMethod: Boolean val depCl = returnType?.resolve()?.declaration as? KSClassDeclaration ?: return false if (!depCl.annotations(Dependencies::class.asClassName()).any()) return false if (parameters.isNotEmpty()) { - throw IncorrectSignatureException("${simpleName.asString()} must no have arguments") + throw IncorrectSignatureException( + message = "${simpleName.asString()} must no have arguments", + element = this, + ) } if (annotations.any()) { - throw IncorrectSignatureException("${simpleName.asString()} must no have annotations") + throw IncorrectSignatureException( + message = "${simpleName.asString()} must no have annotations", + element = this, + ) } checkMethodNameBusy() return true @@ -83,23 +101,38 @@ val KSFunctionDeclaration.isModuleInitMethod: Boolean if (!annotations(Init::class.asClassName()).any()) return false if (!hasOnlyAnnotation(Init::class.asClassName())) { - throw IncorrectSignatureException("${simpleName.asString()} must have only one annotation ${Init::class.simpleName}") + throw IncorrectSignatureException( + message = "${simpleName.asString()} must have only one annotation ${Init::class.simpleName}", + element = this, + ) } if (parameters.size != 1) { - throw IncorrectSignatureException("${simpleName.asString()} must have only one parameter of Dependency or Module instance") + throw IncorrectSignatureException( + message = "${simpleName.asString()} must have only one parameter of Dependency or Module instance", + element = this, + ) } if (returnType?.resolve()?.isUnit == false) { - throw IncorrectSignatureException("${simpleName.asString()} must return unit") + throw IncorrectSignatureException( + message = "${simpleName.asString()} must return unit", + element = this, + ) } parameters.forEach { val clDeclaration = it.type .resolve() .declaration as? KSClassDeclaration - ?: throw IncorrectSignatureException("${simpleName.asString()} must have only one parameter of Dependency or Module instance") + ?: throw IncorrectSignatureException( + message = "${simpleName.asString()} must have only one parameter of Dependency or Module instance", + element = this, + ) if (!clDeclaration.anyAnnotation(Module::class.asClassName(), Dependencies::class.asClassName()).any()) { - throw IncorrectSignatureException("${simpleName.asString()} must have only one parameter of Dependency or Module instance") + throw IncorrectSignatureException( + message = "${simpleName.asString()} must have only one parameter of Dependency or Module instance", + element = this, + ) } } checkMethodNameBusy() @@ -112,25 +145,41 @@ fun KSFunctionDeclaration.isExtOfMethod( if (!annotations(ExtendOf::class.asClassName()).any()) return false if (!hasOnlyAnnotation(ExtendOf::class.asClassName())) { - throw IncorrectSignatureException("${simpleName.asString()} must have only one annotation ${ExtendOf::class.simpleName}") + throw IncorrectSignatureException( + message = "${simpleName.asString()} must have only one annotation ${ExtendOf::class.simpleName}", + element = this, + ) } if (parameters.size != 1) { - throw IncorrectSignatureException("${simpleName.asString()} must have only one parameter of Component instance") + throw IncorrectSignatureException( + message = "${simpleName.asString()} must have only one parameter of Component instance", + element = this, + ) } if (returnType?.resolve()?.isUnit == false) { - throw IncorrectSignatureException("${simpleName.asString()} must return unit") + throw IncorrectSignatureException( + message = "${simpleName.asString()} must return unit", + element = this, + ) } val argumentType = parameters.firstOrNull()?.type ?.resolve() as? KSClassDeclaration - ?: throw IncorrectSignatureException("${simpleName.asString()} must have only one parameter of Component instance") + ?: throw IncorrectSignatureException( + message = "${simpleName.asString()} must have only one parameter of Component instance", + element = this, + ) if (!argumentType.annotations(Component::class.asClassName()).any()) { - throw IncorrectSignatureException("${argumentType.simpleName.asString()} must have @Component annotation") + throw IncorrectSignatureException( + message = "${argumentType.simpleName.asString()} must have @Component annotation", + element = this, + ) } if (!clOwner.getAllSuperTypes().any { parent -> parent.toClassName() == argumentType.toClassName() }) { throw IncorrectSignatureException( message = "The argument for the method ${simpleName.asString()} must be the parent class of the class ${clOwner.toClassName()}. " + - "The class ${argumentType.toClassName()} is not a parent to the class ${clOwner.toClassName()}." + "The class ${argumentType.toClassName()} is not a parent to the class ${clOwner.toClassName()}.", + element = this, ) } @@ -144,10 +193,16 @@ val KSFunctionDeclaration.isBindInstanceMethod: BindInstanceType? if (!annotations(BindInstance::class.asClassName()).any()) return null if (!hasOnlyAnnotation(BindInstance::class.asClassName())) { - throw IncorrectSignatureException("${simpleName.asString()} must have only one annotation ${BindInstance::class.simpleName}") + throw IncorrectSignatureException( + message = "${simpleName.asString()} must have only one annotation ${BindInstance::class.simpleName}", + element = this, + ) } if (parameters.size != 1) { - throw IncorrectSignatureException("${simpleName.asString()} must have only one parameter of binding type") + throw IncorrectSignatureException( + message = "${simpleName.asString()} must have only one parameter of binding type", + element = this, + ) } checkMethodNameBusy() @@ -168,11 +223,17 @@ val KSFunctionDeclaration.isGcMethod: Boolean get() { if (!annotations(RunGc::class.asClassName()).any()) return false if (!scopeAnnotations.any()) { - throw IncorrectSignatureException("${simpleName.asString()} must use GC scope annotation") + throw IncorrectSignatureException( + message = "${simpleName.asString()} must use GC scope annotation", + element = this, + ) } if (returnType?.resolve()?.isUnit == false) { - throw IncorrectSignatureException("${simpleName.asString()} must have return type is Unit") + throw IncorrectSignatureException( + message = "${simpleName.asString()} must have return type is Unit", + element = this, + ) } checkMethodNameBusy() @@ -185,13 +246,22 @@ val KSFunctionDeclaration.isSwitchCacheMethod: Boolean if (!annotations(SwitchCache::class.asClassName()).any()) return false if (!hasOnlyAnnotation(SwitchCache::class.asClassName())) { - throw IncorrectSignatureException("${simpleName.asString()} must use only ${SwitchCache::class.simpleName} annotation") + throw IncorrectSignatureException( + message = "${simpleName.asString()} must use only ${SwitchCache::class.simpleName} annotation", + element = this, + ) } if (parameters.isNotEmpty()) { - throw IncorrectSignatureException("${simpleName.asString()} must no have arguments") + throw IncorrectSignatureException( + message = "${simpleName.asString()} must no have arguments", + element = this, + ) } if (returnType?.resolve()?.isUnit == false) { - throw IncorrectSignatureException("${simpleName.asString()} must have return type is Unit") + throw IncorrectSignatureException( + message = "${simpleName.asString()} must have return type is Unit", + element = this, + ) } checkMethodNameBusy() return true @@ -201,7 +271,7 @@ val KSFunctionDeclaration.isInjectMethod: Boolean get() { if (annotations.any()) return false if (returnType?.resolve()?.isUnit == false) return false - if (parameters.size != 1) return false + if (parameters.isEmpty()) return false checkMethodNameBusy() return true } @@ -210,10 +280,16 @@ val KSFunctionDeclaration.isProtectInjectedMethod: Boolean get() { if (!annotations(ProtectInjected::class.asClassName()).any()) return false if (returnType?.resolve()?.isUnit == false) { - throw IncorrectSignatureException("${simpleName.asString()} must have return type is Unit") + throw IncorrectSignatureException( + message = "${simpleName.asString()} must have return type is Unit", + element = this, + ) } if (parameters.size != 1) { - throw IncorrectSignatureException("${simpleName.asString()} must have only one parameter") + throw IncorrectSignatureException( + message = "${simpleName.asString()} must have only one parameter", + element = this, + ) } checkMethodNameBusy() return true @@ -223,7 +299,12 @@ val KSFunctionDeclaration.isProtectInjectedMethod: Boolean fun KSFunctionDeclaration.checkMethodNameBusy() { val reserved = simpleName.asString() in GenModuleProcessor.allReserveMethodNames + GenComponentProcessor.allReserveMethodNames - if (reserved) throw IncorrectSignatureException("Function name ${simpleName.asString()} is reserved by stone library") + if (reserved) { + throw IncorrectSignatureException( + message = "Function name ${simpleName.asString()} is reserved by stone library", + element = this, + ) + } } diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/component/GenComponentProcessor.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/component/GenComponentProcessor.kt index d4dcedcd..1ea1b847 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/component/GenComponentProcessor.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/component/GenComponentProcessor.kt @@ -1,27 +1,60 @@ package com.github.klee0kai.thekey.stone.ksp.target.component +import com.github.klee0kai.stone.__hidden__.IPrivateComponent +import com.github.klee0kai.stone.__hidden__.types.WeakList import com.github.klee0kai.stone.annotations.component.Component +import com.github.klee0kai.thekey.stone.ksp.exceptions.IncorrectSignatureException import com.github.klee0kai.thekey.stone.ksp.helpers.allIdentifierTypes import com.github.klee0kai.thekey.stone.ksp.helpers.componentStoneClName import com.github.klee0kai.thekey.stone.ksp.helpers.wrapperProviders import com.github.klee0kai.thekey.stone.ksp.ksp.arch.GenSpec import com.github.klee0kai.thekey.stone.ksp.ksp.arch.SymbolsToProcess import com.github.klee0kai.thekey.stone.ksp.ksp.arch.TargetFileProcessor -import com.github.klee0kai.thekey.stone.ksp.poet.genClass -import com.github.klee0kai.thekey.stone.ksp.poet.genFileSpec -import com.github.klee0kai.thekey.stone.ksp.poet.genLibComment +import com.github.klee0kai.thekey.stone.ksp.ksp.getAllMethods +import com.github.klee0kai.thekey.stone.ksp.poet.* +import com.github.klee0kai.thekey.stone.ksp.target.GenModuleProcessor import com.google.devtools.ksp.containingFile import com.google.devtools.ksp.processing.Dependencies import com.google.devtools.ksp.processing.KSPLogger import com.google.devtools.ksp.processing.Resolver +import com.google.devtools.ksp.symbol.ClassKind import com.google.devtools.ksp.symbol.KSAnnotated import com.google.devtools.ksp.symbol.KSClassDeclaration +import com.squareup.kotlinpoet.BOOLEAN +import com.squareup.kotlinpoet.KModifier +import com.squareup.kotlinpoet.ParameterizedTypeName.Companion.parameterizedBy +import com.squareup.kotlinpoet.TypeSpec import com.squareup.kotlinpoet.asClassName +import com.squareup.kotlinpoet.ksp.toClassName class GenComponentProcessor : TargetFileProcessor { companion object { - val allReserveMethodNames = listOf() + val refCollectionGlFieldName = "__refCollection" + val scheduleGlFieldName = "__scheduler" + val hiddenModuleFieldName = "__hiddenModule" + val relatedComponentsListFieldName = "__related" + val protectRecursiveField = "__protectRecursive" + val hiddenModuleMethodName = "__hidden" + val eachModuleMethodName = "__eachModule" + val initMethodName = "__init" + val initDepsMethodName = "__initDependencies" + val bindMethodName = "__bind" + val extOfMethodName = "__extOf" + + val allReserveMethodNames = listOf( + refCollectionGlFieldName, + scheduleGlFieldName, + hiddenModuleFieldName, + relatedComponentsListFieldName, + protectRecursiveField, + hiddenModuleMethodName, + eachModuleMethodName, + initMethodName, + initDepsMethodName, + bindMethodName, + extOfMethodName, + ) } override suspend fun findSymbolsToProcess( @@ -53,7 +86,76 @@ class GenComponentProcessor : TargetFileProcessor { genLibComment() genClass(genComponentClassName) { + if (componentCl.classKind == ClassKind.INTERFACE) { + addSuperinterface(componentCl.toClassName()) + } else { + superclass(componentCl.toClassName()) + } + addSuperinterface(IPrivateComponent::class.asClassName()) + + val componentsAllMethods = componentCl + .getAllMethods(includeObjectMethods = false, allowDoubles = false, "") + + componentsAllMethods.forEach { m -> + when { + m.isModuleProvideMethod -> { + + } + + m.isModuleFactoryProvideMethod -> { + + } + + m.isDepsProvideMethod -> { + + } + + m.isModuleInitMethod -> { + + } + + m.isExtOfMethod(componentCl) -> { + + } + + m.isObjectProvideMethod -> { + + } + + m.isBindInstanceMethod != null -> { + + } + + m.isGcMethod -> { + + } + m.isSwitchCacheMethod -> { + + } + + m.isInjectMethod -> { + + } + + m.isProtectInjectedMethod -> { + + } + + m.isAbstract -> { + throw IncorrectSignatureException( + message = "What is purpose for Method ${m.simpleName.asString()}. " + + "Declared in ${componentCl.simpleName.asString()} ", + element = m, + ) + } + } + } + + genIComponentMethods( + componentCl = componentCl, + + ) } } @@ -63,4 +165,44 @@ class GenComponentProcessor : TargetFileProcessor { dependencies = Dependencies(aggregating = false, fileOwner), ) } + + + private fun TypeSpec.Builder.genIComponentMethods( + componentCl: KSClassDeclaration, + ) { + val relatedListType = WeakList::class.asClassName().parameterizedBy(IPrivateComponent::class.asClassName()) + genProperty( + name = relatedComponentsListFieldName, + type = relatedListType, + ) { + initializer("%T()", relatedListType) + } + genProperty( + name = protectRecursiveField, + type = BOOLEAN, + ) { + initializer("false") + } + + genFun(initMethodName) { + addModifiers(KModifier.OVERRIDE) + addParameter("modules", Any::class, KModifier.VARARG) + + beginControlFlow("for (m in modules)") + beginControlFlow("if (m is %T)", IPrivateComponent::class.asClassName()) + addComment("related component") + addStatement("%L.add(m)", relatedComponentsListFieldName) + endControlFlow() + beginControlFlow("else") + addComment("init modules") + addStatement( + "%L{ module -> module.%L(m) } ", + eachModuleMethodName, GenModuleProcessor.initMethodName + ) + endControlFlow() + endControlFlow() + } + + } + } \ No newline at end of file diff --git a/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/__hidden__/IPrivateComponent.kt b/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/__hidden__/IPrivateComponent.kt index 8206f3b6..ff8cbd4d 100644 --- a/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/__hidden__/IPrivateComponent.kt +++ b/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/__hidden__/IPrivateComponent.kt @@ -14,7 +14,7 @@ interface IPrivateComponent { * - a factory class */ @Deprecated("Create init method with module type as argument") - fun __init(vararg modules: Any?) + fun __init(vararg modules: Any) /** * init dependencies From 1881aa915f2364fed0bef06e121862cb61c99e42 Mon Sep 17 00:00:00 2001 From: klee0kai Date: Sun, 30 Nov 2025 17:43:48 +0100 Subject: [PATCH 040/122] component: interface methods --- .../klee0kai/thekey/stone/ksp/Processor.kt | 4 +- .../stone/ksp/target/GenModuleProcessor.kt | 2 +- .../target/component/GenComponentProcessor.kt | 124 +++++++++++++++++- .../hiddenmodule/GenHiddenModuleProcessor.kt | 58 ++++++++ .../stone/__hidden__/IPrivateComponent.kt | 18 +-- 5 files changed, 190 insertions(+), 16 deletions(-) create mode 100644 stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/hiddenmodule/GenHiddenModuleProcessor.kt diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/Processor.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/Processor.kt index e2cefbac..0534838e 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/Processor.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/Processor.kt @@ -6,10 +6,11 @@ import com.github.klee0kai.thekey.stone.ksp.ksp.arch.GenSpec import com.github.klee0kai.thekey.stone.ksp.ksp.arch.filter import com.github.klee0kai.thekey.stone.ksp.ksp.arch.forceProcess import com.github.klee0kai.thekey.stone.ksp.ksp.arch.nowTakeOnly -import com.github.klee0kai.thekey.stone.ksp.target.component.GenComponentProcessor import com.github.klee0kai.thekey.stone.ksp.target.GenModuleCacheControlProcessor import com.github.klee0kai.thekey.stone.ksp.target.GenModuleFactoryProcessor import com.github.klee0kai.thekey.stone.ksp.target.GenModuleProcessor +import com.github.klee0kai.thekey.stone.ksp.target.component.GenComponentProcessor +import com.github.klee0kai.thekey.stone.ksp.target.hiddenmodule.GenHiddenModuleProcessor import com.google.devtools.ksp.containingFile import com.google.devtools.ksp.processing.CodeGenerator import com.google.devtools.ksp.processing.KSPLogger @@ -69,6 +70,7 @@ class Processor( GenModuleFactoryProcessor(), GenModuleCacheControlProcessor(), GenModuleProcessor(), + GenHiddenModuleProcessor(), GenComponentProcessor(), ) diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/GenModuleProcessor.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/GenModuleProcessor.kt index 611a78ab..0c5e56f0 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/GenModuleProcessor.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/GenModuleProcessor.kt @@ -63,7 +63,7 @@ class GenModuleProcessor : TargetFileProcessor { ) } - class DelayedCodeBlocks( + private class DelayedCodeBlocks( val bindMethodBody: SmartCode = SmartCode(), val clearNullsMethodBody: SmartCode = SmartCode(), val switchRefStatementBuilders: MutableMap, CodeBlock.Builder> = mutableMapOf() diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/component/GenComponentProcessor.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/component/GenComponentProcessor.kt index 1ea1b847..0664ef43 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/component/GenComponentProcessor.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/component/GenComponentProcessor.kt @@ -1,11 +1,13 @@ package com.github.klee0kai.thekey.stone.ksp.target.component +import com.github.klee0kai.stone.__hidden__.IModule import com.github.klee0kai.stone.__hidden__.IPrivateComponent import com.github.klee0kai.stone.__hidden__.types.WeakList import com.github.klee0kai.stone.annotations.component.Component import com.github.klee0kai.thekey.stone.ksp.exceptions.IncorrectSignatureException import com.github.klee0kai.thekey.stone.ksp.helpers.allIdentifierTypes import com.github.klee0kai.thekey.stone.ksp.helpers.componentStoneClName +import com.github.klee0kai.thekey.stone.ksp.helpers.hiddenModuleStoneClName import com.github.klee0kai.thekey.stone.ksp.helpers.wrapperProviders import com.github.klee0kai.thekey.stone.ksp.ksp.arch.GenSpec import com.github.klee0kai.thekey.stone.ksp.ksp.arch.SymbolsToProcess @@ -14,17 +16,15 @@ import com.github.klee0kai.thekey.stone.ksp.ksp.getAllMethods import com.github.klee0kai.thekey.stone.ksp.poet.* import com.github.klee0kai.thekey.stone.ksp.target.GenModuleProcessor import com.google.devtools.ksp.containingFile +import com.google.devtools.ksp.getAllSuperTypes import com.google.devtools.ksp.processing.Dependencies import com.google.devtools.ksp.processing.KSPLogger import com.google.devtools.ksp.processing.Resolver import com.google.devtools.ksp.symbol.ClassKind import com.google.devtools.ksp.symbol.KSAnnotated import com.google.devtools.ksp.symbol.KSClassDeclaration -import com.squareup.kotlinpoet.BOOLEAN -import com.squareup.kotlinpoet.KModifier +import com.squareup.kotlinpoet.* import com.squareup.kotlinpoet.ParameterizedTypeName.Companion.parameterizedBy -import com.squareup.kotlinpoet.TypeSpec -import com.squareup.kotlinpoet.asClassName import com.squareup.kotlinpoet.ksp.toClassName class GenComponentProcessor : TargetFileProcessor { @@ -35,7 +35,6 @@ class GenComponentProcessor : TargetFileProcessor { val hiddenModuleFieldName = "__hiddenModule" val relatedComponentsListFieldName = "__related" val protectRecursiveField = "__protectRecursive" - val hiddenModuleMethodName = "__hidden" val eachModuleMethodName = "__eachModule" val initMethodName = "__init" val initDepsMethodName = "__initDependencies" @@ -48,7 +47,6 @@ class GenComponentProcessor : TargetFileProcessor { hiddenModuleFieldName, relatedComponentsListFieldName, protectRecursiveField, - hiddenModuleMethodName, eachModuleMethodName, initMethodName, initDepsMethodName, @@ -57,6 +55,10 @@ class GenComponentProcessor : TargetFileProcessor { ) } + private class DelayedCodeBlocks( + val initDepsMethodBody: CodeBlock.Builder = CodeBlock.builder(), + ) + override suspend fun findSymbolsToProcess( resolver: Resolver, ) = SymbolsToProcess( @@ -78,6 +80,7 @@ class GenComponentProcessor : TargetFileProcessor { val identifierTypes = componentCl.allIdentifierTypes.toList() val wrapperTypes = componentCl.wrapperProviders.toList() + val delayedCodeBlocks = DelayedCodeBlocks() val genComponentClassName = componentCl.componentStoneClName @@ -154,6 +157,7 @@ class GenComponentProcessor : TargetFileProcessor { genIComponentMethods( componentCl = componentCl, + delayedCodeBlocks = delayedCodeBlocks, ) } @@ -169,6 +173,7 @@ class GenComponentProcessor : TargetFileProcessor { private fun TypeSpec.Builder.genIComponentMethods( componentCl: KSClassDeclaration, + delayedCodeBlocks: DelayedCodeBlocks, ) { val relatedListType = WeakList::class.asClassName().parameterizedBy(IPrivateComponent::class.asClassName()) genProperty( @@ -181,9 +186,18 @@ class GenComponentProcessor : TargetFileProcessor { name = protectRecursiveField, type = BOOLEAN, ) { + mutable(true) initializer("false") } + genProperty( + name = hiddenModuleFieldName, + type = componentCl.hiddenModuleStoneClName, + ) { + addModifiers(KModifier.OVERRIDE) + initializer("%T()", componentCl.hiddenModuleStoneClName) + } + genFun(initMethodName) { addModifiers(KModifier.OVERRIDE) addParameter("modules", Any::class, KModifier.VARARG) @@ -203,6 +217,104 @@ class GenComponentProcessor : TargetFileProcessor { endControlFlow() } + genFun(initDepsMethodName) { + addModifiers(KModifier.OVERRIDE) + addParameter("deps", Any::class, KModifier.VARARG) + beginControlFlow("for (m in deps)") + addComment("init dependencies") + addCode(delayedCodeBlocks.initDepsMethodBody.build()) + endControlFlow() + } + + genFun(bindMethodName) { + addModifiers(KModifier.OVERRIDE) + addParameter("objects", Any::class, KModifier.VARARG) + beginControlFlow("for (ob in objects)") + addStatement( + "%L{ m -> m.%L(ob) }", + eachModuleMethodName, GenModuleProcessor.bindMethodName + ) + endControlFlow() + } + + genFun(extOfMethodName) { + addModifiers(KModifier.OVERRIDE) + addParameter("c", IPrivateComponent::class) + + for (proto in componentCl.getAllSuperTypes().mapNotNull { it.declaration as? KSClassDeclaration }) { + if (proto.toClassName() == IPrivateComponent::class.asClassName()) continue + val provideModuleMethods = proto + .getAllMethods(includeObjectMethods = false, allowDoubles = false) + .filter { it.isModuleProvideMethod } + .toList() + + val bindInstanceAndProvideMethods = proto + .getAllMethods(includeObjectMethods = false, allowDoubles = false) + .filter { it.isBindInstanceMethod == BindInstanceType.BindInstanceAndProvide } + .toList() + + if (provideModuleMethods.isEmpty() && bindInstanceAndProvideMethods.isEmpty()) continue + + beginControlFlow("if (c is %T)", proto.toClassName()) + addStatement("val protoComponent = c as %T", proto.toClassName()) + + for (provideModule in provideModuleMethods) { + addStatement( + "%L().%L( protoComponent.%L() as %T )", + provideModule.simpleName.asString(), + GenModuleProcessor.initCachesFromMethodName, + provideModule.simpleName.asString(), IModule::class.asClassName(), + ) + } + + for (bindInstMethod in bindInstanceAndProvideMethods) { + addStatement( + "%L(protoComponent.%L(null))", + bindInstMethod.simpleName.asString(), bindInstMethod.simpleName.asString(), + ) + } + addStatement( + "c.%L( %L ) ", + initMethodName, + provideModuleMethods.joinToString { "${it.simpleName.asString()}()" }, + ) + addStatement("c.%L(this)", initMethodName) + endControlFlow() + } + + addStatement("%L.add(c)", relatedComponentsListFieldName) + } + + genFun(eachModuleMethodName) { + addModifiers(KModifier.OVERRIDE) + addParameter( + "callback", LambdaTypeName.get( + receiver = null, + parameters = listOf(ParameterSpec.builder("it", IModule::class.asClassName()).build()), + returnType = UNIT, + ) + ) + addStatement("if (%L) return ", protectRecursiveField) + addStatement("%L = true", protectRecursiveField) + + val provideModuleMethods = componentCl + .getAllMethods(includeObjectMethods = false, allowDoubles = false) + .filter { it.isModuleProvideMethod } + .toList() + + for (module in provideModuleMethods) { + addStatement("callback(%L())", module.simpleName.asString()) + } + addStatement("callback(%L)", hiddenModuleFieldName); + + beginControlFlow("for (c in %L.toList())", relatedComponentsListFieldName) + addStatement("c.%L(callback)", eachModuleMethodName) + endControlFlow(); + + addStatement("%L = false", protectRecursiveField); + } + + } } \ No newline at end of file diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/hiddenmodule/GenHiddenModuleProcessor.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/hiddenmodule/GenHiddenModuleProcessor.kt new file mode 100644 index 00000000..af4e28a0 --- /dev/null +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/hiddenmodule/GenHiddenModuleProcessor.kt @@ -0,0 +1,58 @@ +package com.github.klee0kai.thekey.stone.ksp.target.hiddenmodule + +import com.github.klee0kai.stone.__hidden__.IModule +import com.github.klee0kai.stone.annotations.component.Component +import com.github.klee0kai.thekey.stone.ksp.helpers.hiddenModuleStoneClName +import com.github.klee0kai.thekey.stone.ksp.ksp.arch.GenSpec +import com.github.klee0kai.thekey.stone.ksp.ksp.arch.SymbolsToProcess +import com.github.klee0kai.thekey.stone.ksp.ksp.arch.TargetFileProcessor +import com.github.klee0kai.thekey.stone.ksp.poet.genClass +import com.github.klee0kai.thekey.stone.ksp.poet.genFileSpec +import com.github.klee0kai.thekey.stone.ksp.poet.genLibComment +import com.google.devtools.ksp.containingFile +import com.google.devtools.ksp.processing.Dependencies +import com.google.devtools.ksp.processing.KSPLogger +import com.google.devtools.ksp.processing.Resolver +import com.google.devtools.ksp.symbol.KSAnnotated +import com.google.devtools.ksp.symbol.KSClassDeclaration +import com.squareup.kotlinpoet.asClassName + +class GenHiddenModuleProcessor : TargetFileProcessor { + override suspend fun findSymbolsToProcess( + resolver: Resolver, + ) = SymbolsToProcess( + symbolsForProcessing = resolver + .getSymbolsWithAnnotation(Component::class.asClassName().canonicalName) + .toList(), + symbolsForReprocessing = emptyList(), + ) + + + override suspend fun process( + validSymbol: KSAnnotated, + resolver: Resolver, + options: Map, + logger: KSPLogger + ): GenSpec? { + val fileOwner = validSymbol.containingFile ?: return null + val componentCl = validSymbol as? KSClassDeclaration ?: return null + + val genHiddenModuleCl = componentCl.hiddenModuleStoneClName + + val fileSpec = genFileSpec(genHiddenModuleCl.packageName, genHiddenModuleCl.simpleName) { + genLibComment() + + genClass(genHiddenModuleCl) { + addSuperinterface(IModule::class) + + } + + } + + return GenSpec( + fileSpec = fileSpec, + // https://kotlinlang.org/docs/ksp-incremental.html + dependencies = Dependencies(aggregating = false, fileOwner), + ) + } +} diff --git a/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/__hidden__/IPrivateComponent.kt b/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/__hidden__/IPrivateComponent.kt index ff8cbd4d..69d020e4 100644 --- a/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/__hidden__/IPrivateComponent.kt +++ b/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/__hidden__/IPrivateComponent.kt @@ -6,6 +6,12 @@ package com.github.klee0kai.stone.__hidden__ * Each Stone component implement this interface. */ interface IPrivateComponent { + + /** + * hidden module + */ + val __hiddenModule: IModule + /** * init modules. * @@ -22,28 +28,24 @@ interface IPrivateComponent { * @param dependencies - An instance of dependencies */ @Deprecated("Create init method with dependency type as argument") - fun __initDependencies(vararg dependencies: Any?) + fun __initDependencies(vararg dependencies: Any) /** * bind instance objects * * @param objects - An instance of bindable objects */ - fun __bind(vararg objects: Any?) + fun __bind(vararg objects: Any) /** * this component extends of other */ - fun __extOf(components: com.github.klee0kai.stone.__hidden__.IPrivateComponent?) + fun __extOf(components: IPrivateComponent) - /** - * hidden module - */ - fun __hidden(): com.github.klee0kai.stone.__hidden__.IModule? /** * * @param callback */ - fun __eachModule(callback: (com.github.klee0kai.stone.__hidden__.IModule) -> Unit) + fun __eachModule(callback: (IModule) -> Unit) } From 77b2f8c5b6ff2c98c34e5ebbcbdee0ae560d9ae2 Mon Sep 17 00:00:00 2001 From: klee0kai Date: Sun, 30 Nov 2025 18:18:43 +0100 Subject: [PATCH 041/122] component init module method --- .../target/component/GenComponentProcessor.kt | 80 ++++++++++++++++--- .../test_kotlin/di/base_comp/CompComponent.kt | 4 + 2 files changed, 74 insertions(+), 10 deletions(-) diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/component/GenComponentProcessor.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/component/GenComponentProcessor.kt index 0664ef43..a656657f 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/component/GenComponentProcessor.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/component/GenComponentProcessor.kt @@ -4,11 +4,11 @@ import com.github.klee0kai.stone.__hidden__.IModule import com.github.klee0kai.stone.__hidden__.IPrivateComponent import com.github.klee0kai.stone.__hidden__.types.WeakList import com.github.klee0kai.stone.annotations.component.Component +import com.github.klee0kai.stone.annotations.dependencies.Dependencies +import com.github.klee0kai.stone.annotations.module.Module import com.github.klee0kai.thekey.stone.ksp.exceptions.IncorrectSignatureException -import com.github.klee0kai.thekey.stone.ksp.helpers.allIdentifierTypes -import com.github.klee0kai.thekey.stone.ksp.helpers.componentStoneClName -import com.github.klee0kai.thekey.stone.ksp.helpers.hiddenModuleStoneClName -import com.github.klee0kai.thekey.stone.ksp.helpers.wrapperProviders +import com.github.klee0kai.thekey.stone.ksp.helpers.* +import com.github.klee0kai.thekey.stone.ksp.helpers.annotations.anyAnnotation import com.github.klee0kai.thekey.stone.ksp.ksp.arch.GenSpec import com.github.klee0kai.thekey.stone.ksp.ksp.arch.SymbolsToProcess import com.github.klee0kai.thekey.stone.ksp.ksp.arch.TargetFileProcessor @@ -17,7 +17,6 @@ import com.github.klee0kai.thekey.stone.ksp.poet.* import com.github.klee0kai.thekey.stone.ksp.target.GenModuleProcessor import com.google.devtools.ksp.containingFile import com.google.devtools.ksp.getAllSuperTypes -import com.google.devtools.ksp.processing.Dependencies import com.google.devtools.ksp.processing.KSPLogger import com.google.devtools.ksp.processing.Resolver import com.google.devtools.ksp.symbol.ClassKind @@ -26,6 +25,7 @@ import com.google.devtools.ksp.symbol.KSClassDeclaration import com.squareup.kotlinpoet.* import com.squareup.kotlinpoet.ParameterizedTypeName.Companion.parameterizedBy import com.squareup.kotlinpoet.ksp.toClassName +import com.google.devtools.ksp.processing.Dependencies as KspDependencies class GenComponentProcessor : TargetFileProcessor { @@ -102,19 +102,77 @@ class GenComponentProcessor : TargetFileProcessor { componentsAllMethods.forEach { m -> when { m.isModuleProvideMethod -> { - + val moduleCl = m.returnType?.resolve()?.declaration as? KSClassDeclaration + ?: throw IncorrectSignatureException( + message = "wrong return type. Must by Module type", + element = m + ) + genProperty(m.simpleName.asString(), moduleCl.moduleStoneClName) { + addModifiers(KModifier.PRIVATE) + initializer("%T()", moduleCl.moduleStoneClName) + } + genOverrideFun(m) { + returns(moduleCl.moduleStoneClName) + addStatement("return %L", m.simpleName.asString()) + } } m.isModuleFactoryProvideMethod -> { - + val providingModuleFun = componentsAllMethods + .filter { it.isModuleProvideMethod } + .firstOrNull { + it.returnType?.resolve()?.toClassName() == m.returnType?.resolve()?.toClassName() + } + ?: throw IncorrectSignatureException( + message = "Component must also have providing module simple method with same type", + element = m.returnType, + ) + genOverrideFun(m) { + addStatement( + "return %L.%L", + providingModuleFun.simpleName.asString(), + GenModuleProcessor.factoryFieldName + ) + } } m.isDepsProvideMethod -> { - + //TODO } m.isModuleInitMethod -> { - + genOverrideFun(m) { + m.parameters.forEach { param -> + val paramType = param.type.resolve() + .declaration as? KSClassDeclaration + ?: throw IncorrectSignatureException( + message = "wrong return type. Must by Module type", + element = param, + ) + when { + paramType.anyAnnotation( + Module::class.asClassName(), + Component::class.asClassName() + ).any() -> { + addStatement("%L( %L )", initMethodName, param.name!!.asString()); + } + + paramType.anyAnnotation( + Dependencies::class.asClassName(), + ).any() -> { + addStatement("%L( %L )", initDepsMethodName, param.name!!.asString()); + } + + else -> { + throw IncorrectSignatureException( + message = "wrong return type. Must by Module type", + element = param, + ) + } + } + + } + } } m.isExtOfMethod(componentCl) -> { @@ -166,7 +224,7 @@ class GenComponentProcessor : TargetFileProcessor { return GenSpec( fileSpec = fileSpec, // https://kotlinlang.org/docs/ksp-incremental.html - dependencies = Dependencies(aggregating = false, fileOwner), + dependencies = KspDependencies(aggregating = false, fileOwner), ) } @@ -180,12 +238,14 @@ class GenComponentProcessor : TargetFileProcessor { name = relatedComponentsListFieldName, type = relatedListType, ) { + addModifiers(KModifier.PRIVATE) initializer("%T()", relatedListType) } genProperty( name = protectRecursiveField, type = BOOLEAN, ) { + addModifiers(KModifier.PRIVATE) mutable(true) initializer("false") } diff --git a/tests_kotlin/src/main/kotlin/com/github/klee0kai/test_kotlin/di/base_comp/CompComponent.kt b/tests_kotlin/src/main/kotlin/com/github/klee0kai/test_kotlin/di/base_comp/CompComponent.kt index cadf7538..48c70254 100644 --- a/tests_kotlin/src/main/kotlin/com/github/klee0kai/test_kotlin/di/base_comp/CompComponent.kt +++ b/tests_kotlin/src/main/kotlin/com/github/klee0kai/test_kotlin/di/base_comp/CompComponent.kt @@ -1,6 +1,7 @@ package com.github.klee0kai.test_kotlin.di.base_comp import com.github.klee0kai.stone.annotations.component.Component +import com.github.klee0kai.stone.annotations.component.Init import com.github.klee0kai.stone.lifecycle.StoneLifeCycleOwner import com.github.klee0kai.test_kotlin.di.base_comp.identifiers.Company import com.github.klee0kai.test_kotlin.di.base_comp.identifiers.KConnectType @@ -15,6 +16,9 @@ interface CompComponent { fun techModule(): TechModule + @Init + fun initTechModule(module: TechModule) + fun inject( comp: DesktopComp, monitorSize: MonitorSize, From aadd92a2a0cf146af9f8eb6e34d4e9da01d657c7 Mon Sep 17 00:00:00 2001 From: klee0kai Date: Sun, 30 Nov 2025 20:25:42 +0100 Subject: [PATCH 042/122] restore build tests --- settings.gradle.kts | 39 ++- tests_kotlin/build.gradle.kts | 4 +- .../di/compfactory/CompFactoryComponent.kt | 3 +- .../test_kotlin/tech/ComputerStore.kt | 5 +- .../simple/GodFirstWorkDayTest.kt | 83 ------ .../bindinstance/simple/GodTouchTest.kt | 78 ----- .../simple_inject/SevenPlanetTests.kt | 32 -- .../singlemethod/PlanetProvideTests.kt | 59 ---- .../singlemethod/StarProvideTests.kt | 41 --- .../singlemethod_gc/PlanetRollingTests.kt | 217 -------------- .../MoonSkyPotectInjectedTests.kt | 60 ---- .../singlemethod_inject/MoonSkyTests.kt | 36 --- .../java_models/cache/EarthCacheTests.kt | 140 --------- .../cache/EarthSwitchCacheTests.kt | 78 ----- .../tests/java_models/gc/EarthLastDayTests.kt | 276 ------------------ .../java_models/gc/GodLastWorkDayTests.kt | 153 ---------- .../identifiers/GoodPhoneInjectTests.kt | 40 --- .../identifiers/MultiIdentifiersTests.kt | 63 ---- .../identifiers/TechComponentsTests.kt | 65 ----- .../identifiers/TechFactoryComponentTests.kt | 90 ------ .../identifiers/TechFactoryTests.kt | 38 --- .../identifiers/TechFactoryWrappersTests.kt | 95 ------ .../java_models/inject/HorseInjectTests.kt | 76 ----- .../inject/HorseProtectInjectTests.kt | 56 ---- .../inject/MowgliInjectWrappersTests.kt | 79 ----- .../SchoolProtectInjectWrappersTests.kt | 47 --- .../interfaceprovide/DeepCaveTest.kt | 30 -- .../interfaceprovide/EarthWayTest.kt | 19 -- .../lifecycle/GoodPhoneRepairTests.kt | 124 -------- .../lifecycle/OnePhoneRepairTests.kt | 122 -------- .../moduleinit/BeginOfBegins2Tests.kt | 72 ----- .../moduleinit/BeginOfBeginsTests.kt | 58 ---- .../definterface/DefInterfaceTest.kt | 8 +- .../MonitorFactoryWrappersTests.kt | 84 +++--- .../inject/GorillaInjectTests.kt | 8 +- .../inject/GorillaInjectWrappersTests.kt | 12 +- .../inject/GorillaProtectInjectTests.kt | 5 +- .../GorillaProtectInjectWrappersTests.kt | 5 +- .../InterfaceDelegatesTest.kt | 7 +- 39 files changed, 85 insertions(+), 2422 deletions(-) delete mode 100644 tests_kotlin/src/test/kotlin/com/github/klee0kai/tests/java_models/bindinstance/simple/GodFirstWorkDayTest.kt delete mode 100644 tests_kotlin/src/test/kotlin/com/github/klee0kai/tests/java_models/bindinstance/simple/GodTouchTest.kt delete mode 100644 tests_kotlin/src/test/kotlin/com/github/klee0kai/tests/java_models/bindinstance/simple_inject/SevenPlanetTests.kt delete mode 100644 tests_kotlin/src/test/kotlin/com/github/klee0kai/tests/java_models/bindinstance/singlemethod/PlanetProvideTests.kt delete mode 100644 tests_kotlin/src/test/kotlin/com/github/klee0kai/tests/java_models/bindinstance/singlemethod/StarProvideTests.kt delete mode 100644 tests_kotlin/src/test/kotlin/com/github/klee0kai/tests/java_models/bindinstance/singlemethod_gc/PlanetRollingTests.kt delete mode 100644 tests_kotlin/src/test/kotlin/com/github/klee0kai/tests/java_models/bindinstance/singlemethod_inject/MoonSkyPotectInjectedTests.kt delete mode 100644 tests_kotlin/src/test/kotlin/com/github/klee0kai/tests/java_models/bindinstance/singlemethod_inject/MoonSkyTests.kt delete mode 100644 tests_kotlin/src/test/kotlin/com/github/klee0kai/tests/java_models/cache/EarthCacheTests.kt delete mode 100644 tests_kotlin/src/test/kotlin/com/github/klee0kai/tests/java_models/cache/EarthSwitchCacheTests.kt delete mode 100644 tests_kotlin/src/test/kotlin/com/github/klee0kai/tests/java_models/gc/EarthLastDayTests.kt delete mode 100644 tests_kotlin/src/test/kotlin/com/github/klee0kai/tests/java_models/gc/GodLastWorkDayTests.kt delete mode 100644 tests_kotlin/src/test/kotlin/com/github/klee0kai/tests/java_models/identifiers/GoodPhoneInjectTests.kt delete mode 100644 tests_kotlin/src/test/kotlin/com/github/klee0kai/tests/java_models/identifiers/MultiIdentifiersTests.kt delete mode 100644 tests_kotlin/src/test/kotlin/com/github/klee0kai/tests/java_models/identifiers/TechComponentsTests.kt delete mode 100644 tests_kotlin/src/test/kotlin/com/github/klee0kai/tests/java_models/identifiers/TechFactoryComponentTests.kt delete mode 100644 tests_kotlin/src/test/kotlin/com/github/klee0kai/tests/java_models/identifiers/TechFactoryTests.kt delete mode 100644 tests_kotlin/src/test/kotlin/com/github/klee0kai/tests/java_models/identifiers/TechFactoryWrappersTests.kt delete mode 100644 tests_kotlin/src/test/kotlin/com/github/klee0kai/tests/java_models/inject/HorseInjectTests.kt delete mode 100644 tests_kotlin/src/test/kotlin/com/github/klee0kai/tests/java_models/inject/HorseProtectInjectTests.kt delete mode 100644 tests_kotlin/src/test/kotlin/com/github/klee0kai/tests/java_models/inject/MowgliInjectWrappersTests.kt delete mode 100644 tests_kotlin/src/test/kotlin/com/github/klee0kai/tests/java_models/inject/SchoolProtectInjectWrappersTests.kt delete mode 100644 tests_kotlin/src/test/kotlin/com/github/klee0kai/tests/java_models/interfaceprovide/DeepCaveTest.kt delete mode 100644 tests_kotlin/src/test/kotlin/com/github/klee0kai/tests/java_models/interfaceprovide/EarthWayTest.kt delete mode 100644 tests_kotlin/src/test/kotlin/com/github/klee0kai/tests/java_models/lifecycle/GoodPhoneRepairTests.kt delete mode 100644 tests_kotlin/src/test/kotlin/com/github/klee0kai/tests/java_models/lifecycle/OnePhoneRepairTests.kt delete mode 100644 tests_kotlin/src/test/kotlin/com/github/klee0kai/tests/java_models/moduleinit/BeginOfBegins2Tests.kt delete mode 100644 tests_kotlin/src/test/kotlin/com/github/klee0kai/tests/java_models/moduleinit/BeginOfBeginsTests.kt diff --git a/settings.gradle.kts b/settings.gradle.kts index 5ff52cbd..52f10e35 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -19,31 +19,30 @@ dependencyResolutionManagement { } rootProject.name = "Stone" -//includeBuild("plugin_publish") +includeBuild("plugin_publish") include("weakref_multiplatform") include("inject_multiplatform") include(":stone_lib") include(":stone_multiplatform") include(":stone_processor") -//include(":android_lib") -//include(":kotlin_lib") -// -//include(":wiki_java") -//include(":wiki_kotlin") -//include(":tests") -//include(":tests_ext") -include(":tests_kotlin") -//include(":tests_wraps") -//include(":tests_wraps_kotlin") -//include(":tests_compile") -//include(":test_feature:companies:consulting") -//include(":test_feature:hr:api") -//include(":test_feature:hr:impl") -//include(":test_feature:planning:api") -//include(":test_feature:planning:impl") -//include(":test_feature:finance:api") -//include(":test_feature:finance:impl") -//include(":test_feature_core_deps") +include(":android_lib") +include(":kotlin_lib") +include(":wiki_java") +include(":wiki_kotlin") +include(":tests") +include(":tests_ext") +include(":tests_kotlin") +include(":tests_wraps") +include(":tests_wraps_kotlin") +include(":tests_compile") +include(":test_feature:companies:consulting") +include(":test_feature:hr:api") +include(":test_feature:hr:impl") +include(":test_feature:planning:api") +include(":test_feature:planning:impl") +include(":test_feature:finance:api") +include(":test_feature:finance:impl") +include(":test_feature_core_deps") include("stone_ksp") \ No newline at end of file diff --git a/tests_kotlin/build.gradle.kts b/tests_kotlin/build.gradle.kts index 8d1e60d2..dff60205 100644 --- a/tests_kotlin/build.gradle.kts +++ b/tests_kotlin/build.gradle.kts @@ -8,8 +8,10 @@ tasks.test { } dependencies { + implementation(project(":tests")) + implementation(project(":stone_multiplatform")) - ksp(project(":stone_ksp")) +// ksp(project(":stone_ksp")) testImplementation(libs.bundles.junit) diff --git a/tests_kotlin/src/main/kotlin/com/github/klee0kai/test_kotlin/di/compfactory/CompFactoryComponent.kt b/tests_kotlin/src/main/kotlin/com/github/klee0kai/test_kotlin/di/compfactory/CompFactoryComponent.kt index c4683c23..29777a38 100644 --- a/tests_kotlin/src/main/kotlin/com/github/klee0kai/test_kotlin/di/compfactory/CompFactoryComponent.kt +++ b/tests_kotlin/src/main/kotlin/com/github/klee0kai/test_kotlin/di/compfactory/CompFactoryComponent.kt @@ -1,6 +1,5 @@ package com.github.klee0kai.test_kotlin.di.compfactory -import com.github.klee0kai.stone.KotlinWrappersStone import com.github.klee0kai.stone.annotations.component.Component import com.github.klee0kai.test.di.base_phone.identifiers.PhoneOsType import com.github.klee0kai.test.di.base_phone.identifiers.PhoneOsVersion @@ -11,7 +10,7 @@ import com.github.klee0kai.test.di.base_phone.identifiers.RamSize RamSize::class, PhoneOsType::class, PhoneOsVersion::class ], - wrapperProviders = [KotlinWrappersStone::class] + wrapperProviders = [] ) interface CompFactoryComponent : ICompFactoryWrappersComponent { diff --git a/tests_kotlin/src/main/kotlin/com/github/klee0kai/test_kotlin/tech/ComputerStore.kt b/tests_kotlin/src/main/kotlin/com/github/klee0kai/test_kotlin/tech/ComputerStore.kt index b48f39f9..20c42a87 100644 --- a/tests_kotlin/src/main/kotlin/com/github/klee0kai/test_kotlin/tech/ComputerStore.kt +++ b/tests_kotlin/src/main/kotlin/com/github/klee0kai/test_kotlin/tech/ComputerStore.kt @@ -1,12 +1,11 @@ package com.github.klee0kai.test_kotlin.tech -import com.github.klee0kai.stone.Stone import com.github.klee0kai.test_kotlin.di.base_comp.CompComponent object ComputerStore { - var DI = Stone.createComponent(CompComponent::class.java) + var DI: CompComponent = TODO("Stone.createComponent(CompComponent::class.java)") fun recreate() { - DI = Stone.createComponent(CompComponent::class.java) + DI = TODO("Stone.createComponent(CompComponent::class.java)") } } \ No newline at end of file diff --git a/tests_kotlin/src/test/kotlin/com/github/klee0kai/tests/java_models/bindinstance/simple/GodFirstWorkDayTest.kt b/tests_kotlin/src/test/kotlin/com/github/klee0kai/tests/java_models/bindinstance/simple/GodFirstWorkDayTest.kt deleted file mode 100644 index f593e89f..00000000 --- a/tests_kotlin/src/test/kotlin/com/github/klee0kai/tests/java_models/bindinstance/simple/GodFirstWorkDayTest.kt +++ /dev/null @@ -1,83 +0,0 @@ -package com.github.klee0kai.tests.java_models.bindinstance.simple - -import com.github.klee0kai.stone.Stone -import com.github.klee0kai.test.di.bindinstance.simple.GodWorkspaceComponent -import com.github.klee0kai.test.mowgli.galaxy.Earth -import com.github.klee0kai.test.mowgli.galaxy.Saturn -import com.github.klee0kai.test.mowgli.galaxy.Sun -import org.junit.jupiter.api.Assertions.assertEquals -import org.junit.jupiter.api.Assertions.assertNull -import org.junit.jupiter.api.Test - -class GodFirstWorkDayTest { - @Test - fun firstCreateSunTest() { - //Given - val DI = Stone.createComponent(GodWorkspaceComponent::class.java) - val sun = Sun() - - //When - DI.bindSun(sun) - - //Then - assertEquals(sun.uuid, DI.sunSystem().sun().uuid) - assertNull(DI.sunSystem().earth()) - } - - @Test - fun createSunAndEarthTest() { - //Given - val DI = Stone.createComponent(GodWorkspaceComponent::class.java) - val sun = Sun() - val earth = Earth() - - //When - DI.bindSun(sun) - DI.bindEarth(earth) - - //Then - assertEquals(sun.uuid, DI.sunSystem().sun().uuid) - assertEquals(earth.uuid, DI.sunSystem().earth().uuid) - assertNull(DI.sunSystem().planet()) - } - - @Test - fun createSunEarthSaturnTest() { - //Given - val DI = Stone.createComponent(GodWorkspaceComponent::class.java) - val sun = Sun() - val earth = Earth() - val saturn = Saturn() - - //When - DI.bindSun(sun) - DI.bindEarth(earth) - DI.bindSaturn(saturn) - - //Then - assertEquals(sun.uuid, DI.sunSystem().sun().uuid) - assertEquals(earth.uuid, DI.sunSystem().earth().uuid) - assertEquals(saturn.uuid, DI.sunSystem().saturn().uuid) - assertNull(DI.sunSystem().planet()) - } - - @Test - fun createSaturnEarthSunTest() { - //Given - val DI = Stone.createComponent(GodWorkspaceComponent::class.java) - val sun = Sun() - val earth = Earth() - val saturn = Saturn() - - //When - DI.bindSaturn(saturn) - DI.bindEarth(earth) - DI.bindSun(sun) - - //Then - assertEquals(sun.uuid, DI.sunSystem().sun().uuid) - assertEquals(earth.uuid, DI.sunSystem().earth().uuid) - assertEquals(saturn.uuid, DI.sunSystem().saturn().uuid) - assertNull(DI.sunSystem().planet()) - } -} \ No newline at end of file diff --git a/tests_kotlin/src/test/kotlin/com/github/klee0kai/tests/java_models/bindinstance/simple/GodTouchTest.kt b/tests_kotlin/src/test/kotlin/com/github/klee0kai/tests/java_models/bindinstance/simple/GodTouchTest.kt deleted file mode 100644 index 144daf6d..00000000 --- a/tests_kotlin/src/test/kotlin/com/github/klee0kai/tests/java_models/bindinstance/simple/GodTouchTest.kt +++ /dev/null @@ -1,78 +0,0 @@ -package com.github.klee0kai.tests.java_models.bindinstance.simple - -import com.github.klee0kai.stone.Stone -import com.github.klee0kai.test.di.bindinstance.simple.GodWorkspaceComponent -import com.github.klee0kai.test.mowgli.galaxy.Earth -import com.github.klee0kai.test.mowgli.galaxy.Saturn -import com.github.klee0kai.test.mowgli.galaxy.Sun -import org.junit.jupiter.api.Assertions.assertEquals -import org.junit.jupiter.api.Assertions.assertNull -import org.junit.jupiter.api.Test - -class GodTouchTest { - @Test - fun firstCreateSunTest() { - //Given - val DI = Stone.createComponent(GodWorkspaceComponent::class.java) - val sun = Sun() - - //When - DI.bindSun(sun) - - //Then - assertEquals(sun.uuid, DI.sunSystem().sun().uuid) - assertNull(DI.sunSystem().earth()) - } - - @Test - fun createSunAndEarthTest() { - //Given - val DI = Stone.createComponent(GodWorkspaceComponent::class.java) - val sun = Sun() - val earth = Earth() - - //When - DI.bindSun(sun) - DI.bindEarth(earth) - - //Then - assertEquals(sun.uuid, DI.sunSystem().sun().uuid) - assertEquals(earth.uuid, DI.sunSystem().earth().uuid) - assertNull(DI.sunSystem().planet()) - } - - @Test - fun createSaturnEarthSunTest() { - //Given - val DI = Stone.createComponent(GodWorkspaceComponent::class.java) - val sun = Sun() - val earth = Earth() - val saturn = Saturn() - - //When - DI.bindEarth(earth) - DI.bindSun(sun) - DI.bindPlanet(saturn) - - //Then - assertEquals(sun.uuid, DI.sunSystem().sun().uuid) - assertEquals(earth.uuid, DI.sunSystem().earth().uuid) - assertEquals(saturn, DI.sunSystem().planet()) - assertNull(DI.sunSystem().saturn()) - } - - @Test - fun planetIsPlanetTest() { - //Given - val DI = Stone.createComponent(GodWorkspaceComponent::class.java) - val earth = Earth() - - //When - DI.planet(earth) - DI.planet(null) - - //Then - assertEquals(earth, DI.planet(null)) - assertEquals(earth, DI.providePlanet()) - } -} \ No newline at end of file diff --git a/tests_kotlin/src/test/kotlin/com/github/klee0kai/tests/java_models/bindinstance/simple_inject/SevenPlanetTests.kt b/tests_kotlin/src/test/kotlin/com/github/klee0kai/tests/java_models/bindinstance/simple_inject/SevenPlanetTests.kt deleted file mode 100644 index 3e140854..00000000 --- a/tests_kotlin/src/test/kotlin/com/github/klee0kai/tests/java_models/bindinstance/simple_inject/SevenPlanetTests.kt +++ /dev/null @@ -1,32 +0,0 @@ -package com.github.klee0kai.tests.java_models.bindinstance.simple_inject - -import com.github.klee0kai.stone.Stone -import com.github.klee0kai.test.di.bindinstance.simple_inject.SevenPlanetComponent -import com.github.klee0kai.test.mowgli.MoonSky -import com.github.klee0kai.test.mowgli.galaxy.Earth -import com.github.klee0kai.test.mowgli.galaxy.Mercury -import org.junit.jupiter.api.Assertions.assertEquals -import org.junit.jupiter.api.Test - -class SevenPlanetTests { - @Test - fun moonSkyTest() { - //Given - val component = Stone.createComponent(SevenPlanetComponent::class.java) - val earth = Earth() - val mercury = Mercury() - val planet = Earth() - component.bind(earth) - component.bind(mercury) - component.bindPlanet(planet) - - //When - val moonSky = MoonSky() - component.inject(moonSky); - - //Then - assertEquals(earth, moonSky.earth) - assertEquals(mercury, moonSky.mercury) - assertEquals(planet, moonSky.planet) - } -} \ No newline at end of file diff --git a/tests_kotlin/src/test/kotlin/com/github/klee0kai/tests/java_models/bindinstance/singlemethod/PlanetProvideTests.kt b/tests_kotlin/src/test/kotlin/com/github/klee0kai/tests/java_models/bindinstance/singlemethod/PlanetProvideTests.kt deleted file mode 100644 index f481b1e2..00000000 --- a/tests_kotlin/src/test/kotlin/com/github/klee0kai/tests/java_models/bindinstance/singlemethod/PlanetProvideTests.kt +++ /dev/null @@ -1,59 +0,0 @@ -package com.github.klee0kai.tests.java_models.bindinstance.singlemethod - -import com.github.klee0kai.stone.Stone -import com.github.klee0kai.test.di.bindinstance.singlemethod.PlanetComponent -import com.github.klee0kai.test.mowgli.galaxy.Earth -import org.junit.jupiter.api.Assertions.assertEquals -import org.junit.jupiter.api.Assertions.assertNull -import org.junit.jupiter.api.Test - -class PlanetProvideTests { - @Test - fun bindPlanetTest() { - //Given - val DI = Stone.createComponent(PlanetComponent::class.java) - val earth = Earth() - - //When - DI.planet(earth) - - //Then - assertEquals(earth, DI.planet(null)) - assertEquals(earth, DI.planet(null)) - assertEquals(earth, DI.providePlanet()) - assertEquals(earth, DI.providePlanet()) - assertNull(DI.earth(null)) - } - - @Test - fun bindEarthTest() { - //Given - val DI = Stone.createComponent(PlanetComponent::class.java) - val earth = Earth() - - //When - DI.earth(earth) - - //Then - assertEquals(earth, DI.earth(null)) - assertEquals(earth, DI.earth(null)) - assertNull(DI.planet(null)) - assertNull(DI.providePlanet()) - } - - @Test - fun bindEarthCommonTest() { - //Given - val DI = Stone.createComponent(PlanetComponent::class.java) - val earth = Earth() - - //When - DI.earth(earth) - - //Then - assertEquals(earth, DI.earth(null)) - assertEquals(earth, DI.earth(null)) - assertNull(DI.planet(null)) - assertNull(DI.providePlanet()) - } -} \ No newline at end of file diff --git a/tests_kotlin/src/test/kotlin/com/github/klee0kai/tests/java_models/bindinstance/singlemethod/StarProvideTests.kt b/tests_kotlin/src/test/kotlin/com/github/klee0kai/tests/java_models/bindinstance/singlemethod/StarProvideTests.kt deleted file mode 100644 index fb1ce73d..00000000 --- a/tests_kotlin/src/test/kotlin/com/github/klee0kai/tests/java_models/bindinstance/singlemethod/StarProvideTests.kt +++ /dev/null @@ -1,41 +0,0 @@ -package com.github.klee0kai.tests.java_models.bindinstance.singlemethod - -import com.github.klee0kai.stone.Stone -import com.github.klee0kai.test.di.bindinstance.singlemethod.PlanetComponent -import com.github.klee0kai.test.mowgli.galaxy.Sun -import org.junit.jupiter.api.Assertions.assertEquals -import org.junit.jupiter.api.Assertions.assertNull -import org.junit.jupiter.api.Test - -class StarProvideTests { - @Test - fun bindSunTest() { - //Given - val DI = Stone.createComponent(PlanetComponent::class.java) - val sun = Sun() - - //When - DI.sunModule().sun(sun) - - //Then - assertEquals(sun, DI.sunModule().sun(null)) - assertEquals(sun, DI.sunModule().sun(null)) - assertNull(DI.sunModule().star(null)) - } - - @Test - fun bindStarTest() { - //Given - val DI = Stone.createComponent(PlanetComponent::class.java) - val sun = Sun() - - //When - DI.sunModule().star(sun) - - //Then - assertEquals(sun, DI.sunModule().star(null)) - assertEquals(sun, DI.sunModule().star(null)) - assertNull(DI.sunModule().sun(null)) - } - -} \ No newline at end of file diff --git a/tests_kotlin/src/test/kotlin/com/github/klee0kai/tests/java_models/bindinstance/singlemethod_gc/PlanetRollingTests.kt b/tests_kotlin/src/test/kotlin/com/github/klee0kai/tests/java_models/bindinstance/singlemethod_gc/PlanetRollingTests.kt deleted file mode 100644 index 04d59006..00000000 --- a/tests_kotlin/src/test/kotlin/com/github/klee0kai/tests/java_models/bindinstance/singlemethod_gc/PlanetRollingTests.kt +++ /dev/null @@ -1,217 +0,0 @@ -package com.github.klee0kai.tests.java_models.bindinstance.singlemethod_gc - -import com.github.klee0kai.stone.Stone -import com.github.klee0kai.test.di.bindinstance.singlemethod_gc.PlanetRollingComponent -import com.github.klee0kai.test.mowgli.galaxy.Earth -import com.github.klee0kai.test.mowgli.galaxy.Sun -import org.junit.jupiter.api.Assertions.assertNotNull -import org.junit.jupiter.api.Assertions.assertNull -import org.junit.jupiter.api.Test -import java.lang.ref.WeakReference -import java.util.* - -class PlanetRollingTests { - @Test - fun gcAllTest() { - //Given - val DI = Stone.createComponent(PlanetRollingComponent::class.java) - val earthStrong = WeakReference(Earth()) - val earthSoft = WeakReference(Earth()) - val planetWeak = WeakReference(Earth()) - val sunStrong = WeakReference(Sun()) - val sunSoft = WeakReference(Sun()) - val starWeak = WeakReference(Sun()) - DI.earthStrong(earthStrong.get()) - DI.earthSoft(earthSoft.get()) - DI.planet(planetWeak.get()) - DI.sunModule().sunStrong(sunStrong.get()) - DI.sunModule().sunSoft(sunSoft.get()) - DI.sunModule().star(starWeak.get()) - - //When - DI.gcAll() - - //Then - for (ref in Arrays.asList( - earthStrong, earthSoft, planetWeak, - sunStrong, sunSoft, starWeak - )) { - assertNull(ref.get()) - } - } - - @Test - fun gcStrongTest() { - //Given - val DI = Stone.createComponent(PlanetRollingComponent::class.java) - val earthStrong = WeakReference(Earth()) - val earthSoft = WeakReference(Earth()) - val planetWeak = WeakReference(Earth()) - val sunStrong = WeakReference(Sun()) - val sunSoft = WeakReference(Sun()) - val starWeak = WeakReference(Sun()) - DI.earthStrong(earthStrong.get()) - DI.earthSoft(earthSoft.get()) - DI.planet(planetWeak.get()) - DI.sunModule().sunStrong(sunStrong.get()) - DI.sunModule().sunSoft(sunSoft.get()) - DI.sunModule().star(starWeak.get()) - - //When - DI.gcStrong() - - //Then - for (ref in Arrays.asList( - earthStrong, planetWeak, - sunStrong, starWeak - )) { - assertNull(ref.get()) - } - for (ref in Arrays.asList( - earthSoft, - sunSoft - )) { - assertNotNull(ref.get()) - } - } - - @Test - fun gcSoftTest() { - //Given - val DI = Stone.createComponent(PlanetRollingComponent::class.java) - val earthStrong = WeakReference(Earth()) - val earthSoft = WeakReference(Earth()) - val planetWeak = WeakReference(Earth()) - val sunStrong = WeakReference(Sun()) - val sunSoft = WeakReference(Sun()) - val starWeak = WeakReference(Sun()) - DI.earthStrong(earthStrong.get()) - DI.earthSoft(earthSoft.get()) - DI.planet(planetWeak.get()) - DI.sunModule().sunStrong(sunStrong.get()) - DI.sunModule().sunSoft(sunSoft.get()) - DI.sunModule().star(starWeak.get()) - - //When - DI.gcSoft() - - //Then - for (ref in Arrays.asList( - earthSoft, planetWeak, - sunSoft, starWeak - )) { - assertNull(ref.get()) - } - for (ref in Arrays.asList( - earthStrong, - sunStrong - )) { - assertNotNull(ref.get()) - } - } - - @Test - fun gcWeakTest() { - //Given - val DI = Stone.createComponent(PlanetRollingComponent::class.java) - val earthStrong = WeakReference(Earth()) - val earthSoft = WeakReference(Earth()) - val planetWeak = WeakReference(Earth()) - val sunStrong = WeakReference(Sun()) - val sunSoft = WeakReference(Sun()) - val starWeak = WeakReference(Sun()) - DI.earthStrong(earthStrong.get()) - DI.earthSoft(earthSoft.get()) - DI.planet(planetWeak.get()) - DI.sunModule().sunStrong(sunStrong.get()) - DI.sunModule().sunSoft(sunSoft.get()) - DI.sunModule().star(starWeak.get()) - - //When - DI.gcWeak() - - //Then - for (ref in Arrays.asList( - planetWeak, - starWeak - )) { - assertNull(ref.get()) - } - for (ref in Arrays.asList( - earthStrong, earthSoft, - sunStrong, sunSoft - )) { - assertNotNull(ref.get()) - } - } - - @Test - fun gcSoftSunTest() { - //Given - val DI = Stone.createComponent(PlanetRollingComponent::class.java) - val earthStrong = WeakReference(Earth()) - val earthSoft = WeakReference(Earth()) - val planetWeak = WeakReference(Earth()) - val sunStrong = WeakReference(Sun()) - val sunSoft = WeakReference(Sun()) - val starWeak = WeakReference(Sun()) - DI.earthStrong(earthStrong.get()) - DI.earthSoft(earthSoft.get()) - DI.planet(planetWeak.get()) - DI.sunModule().sunStrong(sunStrong.get()) - DI.sunModule().sunSoft(sunSoft.get()) - DI.sunModule().star(starWeak.get()) - - //When - DI.gcSoftSun() - - //Then - for (ref in Arrays.asList( - planetWeak, - sunSoft, starWeak - )) { - assertNull(ref.get()) - } - for (ref in Arrays.asList( - earthStrong, earthSoft, - sunStrong - )) { - assertNotNull(ref.get()) - } - } - - @Test - fun gcSoftPlanetsTest() { - //Given - val DI = Stone.createComponent(PlanetRollingComponent::class.java) - val earthStrong = WeakReference(Earth()) - val earthSoft = WeakReference(Earth()) - val planetWeak = WeakReference(Earth()) - val sunStrong = WeakReference(Sun()) - val sunSoft = WeakReference(Sun()) - val starWeak = WeakReference(Sun()) - DI.earthStrong(earthStrong.get()) - DI.earthSoft(earthSoft.get()) - DI.planet(planetWeak.get()) - DI.sunModule().sunStrong(sunStrong.get()) - DI.sunModule().sunSoft(sunSoft.get()) - DI.sunModule().star(starWeak.get()) - - //When - DI.gcSoftPlanets() - - //Then - for (ref in Arrays.asList( - earthSoft, planetWeak, - starWeak - )) { - assertNull(ref.get()) - } - for (ref in Arrays.asList( - earthStrong, - sunStrong, sunSoft - )) { - assertNotNull(ref.get()) - } - } -} \ No newline at end of file diff --git a/tests_kotlin/src/test/kotlin/com/github/klee0kai/tests/java_models/bindinstance/singlemethod_inject/MoonSkyPotectInjectedTests.kt b/tests_kotlin/src/test/kotlin/com/github/klee0kai/tests/java_models/bindinstance/singlemethod_inject/MoonSkyPotectInjectedTests.kt deleted file mode 100644 index aceb58ea..00000000 --- a/tests_kotlin/src/test/kotlin/com/github/klee0kai/tests/java_models/bindinstance/singlemethod_inject/MoonSkyPotectInjectedTests.kt +++ /dev/null @@ -1,60 +0,0 @@ -package com.github.klee0kai.tests.java_models.bindinstance.singlemethod_inject - -import com.github.klee0kai.stone.Stone -import com.github.klee0kai.test.di.bindinstance.singlemethod_inject.StarSkyComponent -import com.github.klee0kai.test.mowgli.MoonSky -import com.github.klee0kai.test.mowgli.galaxy.Mercury -import com.github.klee0kai.test.mowgli.galaxy.Sun -import org.junit.jupiter.api.Assertions.assertNotNull -import org.junit.jupiter.api.Assertions.assertNull -import org.junit.jupiter.api.Test -import java.lang.ref.WeakReference - -class MoonSkyPotectInjectedTests { - @Test - fun withoutProtectInjectedTest() { - //Given - val component = Stone.createComponent(StarSkyComponent::class.java) - val mercury = WeakReference(Mercury()) - val star = WeakReference(Sun()) - component.starModule().star(star.get()) - component.mercury(mercury.get()) - - //When - var moonSky: MoonSky? = MoonSky() - component.inject(moonSky) - moonSky = null - component.gcAll() - - - //Then - assertNull(mercury.get()) - assertNull(star.get()) - } - - @Test - @Throws(InterruptedException::class) - fun withProtectInjectedTest() { - //Given - val component = Stone.createComponent(StarSkyComponent::class.java) - val mercury = WeakReference(Mercury()) - val star = WeakReference(Sun()) - component.starModule().star(star.get()) - component.mercury(mercury.get()) - - //When - var moonSky: MoonSky? = MoonSky() - component.inject(moonSky) - component.protectInjected(moonSky) - moonSky = null - component.gcAll() - assertNotNull(mercury.get()) - assertNotNull(star.get()) - - //Then after protect finished - Thread.sleep(50) - System.gc() - assertNull(mercury.get()) - assertNull(star.get()) - } -} \ No newline at end of file diff --git a/tests_kotlin/src/test/kotlin/com/github/klee0kai/tests/java_models/bindinstance/singlemethod_inject/MoonSkyTests.kt b/tests_kotlin/src/test/kotlin/com/github/klee0kai/tests/java_models/bindinstance/singlemethod_inject/MoonSkyTests.kt deleted file mode 100644 index bc59562c..00000000 --- a/tests_kotlin/src/test/kotlin/com/github/klee0kai/tests/java_models/bindinstance/singlemethod_inject/MoonSkyTests.kt +++ /dev/null @@ -1,36 +0,0 @@ -package com.github.klee0kai.tests.java_models.bindinstance.singlemethod_inject - -import com.github.klee0kai.stone.Stone -import com.github.klee0kai.test.di.bindinstance.singlemethod_inject.StarSkyComponent -import com.github.klee0kai.test.mowgli.MoonSky -import com.github.klee0kai.test.mowgli.galaxy.Earth -import com.github.klee0kai.test.mowgli.galaxy.Mercury -import com.github.klee0kai.test.mowgli.galaxy.Sun -import org.junit.jupiter.api.Assertions.assertEquals -import org.junit.jupiter.api.Test - -class MoonSkyTests { - @Test - fun moonSkyTest() { - //Given - val component = Stone.createComponent(StarSkyComponent::class.java) - val sun = Sun() - val star = Sun() - val earth = Earth() - val planet = Mercury() - component.starModule().sun(sun) - component.starModule().star(star) - component.earth(earth) - component.planet(planet) - - //When - val moonSky = MoonSky() - component.inject(moonSky); - - //Then - assertEquals(sun, moonSky.sun) - assertEquals(star, moonSky.star) - assertEquals(earth, moonSky.earth) - assertEquals(planet, moonSky.planet) - } -} \ No newline at end of file diff --git a/tests_kotlin/src/test/kotlin/com/github/klee0kai/tests/java_models/cache/EarthCacheTests.kt b/tests_kotlin/src/test/kotlin/com/github/klee0kai/tests/java_models/cache/EarthCacheTests.kt deleted file mode 100644 index f8a597b9..00000000 --- a/tests_kotlin/src/test/kotlin/com/github/klee0kai/tests/java_models/cache/EarthCacheTests.kt +++ /dev/null @@ -1,140 +0,0 @@ -package com.github.klee0kai.tests.java_models.cache - -import com.github.klee0kai.stone.Stone -import com.github.klee0kai.test.di.gcforest.GcGodComponent -import org.junit.jupiter.api.Assertions.assertEquals -import org.junit.jupiter.api.Assertions.assertNotEquals -import org.junit.jupiter.api.Test - -class EarthCacheTests { - @Test - fun strongCacheTest() { - //Given - val di = Stone.createComponent(GcGodComponent::class.java) - - //When - val mountain1 = di.earth().mountainStrong() - val mountain2 = di.earth().mountainStrong() - - //Then - assertEquals( - mountain1.uuid, - mountain2.uuid - ) - } - - @Test - fun softCacheTest() { - //Given - val di = Stone.createComponent(GcGodComponent::class.java) - - //When - val mountain1 = di.earth().mountainSoft() - val mountain2 = di.earth().mountainSoft() - - //Then - assertEquals( - mountain1.uuid, - mountain2.uuid - ) - } - - @Test - fun weakCacheTest() { - //Given - val di = Stone.createComponent(GcGodComponent::class.java) - - //When - val mountain1 = di.earth().mountainWeak() - val mountain2 = di.earth().mountainWeak() - - //Then - assertEquals( - mountain1.uuid, - mountain2.uuid - ) - } - - @Test - fun defCacheTest() { - //Given - val di = Stone.createComponent(GcGodComponent::class.java) - - //When - val mountain1 = di.earth().mountainDefaultFactory() - val mountain2 = di.earth().mountainDefaultFactory() - - //Then - assertNotEquals( - mountain1.uuid, - mountain2.uuid, - "Factory creating" - ) - } - - @Test - fun defCache2Test() { - //Given - val di = Stone.createComponent(GcGodComponent::class.java) - - //When - val mountain1 = di.earth().mountainDefault2Factory() - val mountain2 = di.earth().mountainDefault2Factory() - - //Then - assertNotEquals( - mountain1.uuid, - mountain2.uuid, - "Factory creating" - ) - } - - @Test - fun differentMethodDifferentCacheTest() { - //Given - val di = Stone.createComponent(GcGodComponent::class.java) - - //When - val mountainStrong = di.earth().mountainStrong() - val mountainSoft = di.earth().mountainSoft() - - //Then - assertNotEquals( - mountainStrong.uuid, - mountainSoft.uuid - ) - } - - @Test - fun factoryNotCacheTest() { - //Given - val di = Stone.createComponent(GcGodComponent::class.java) - - //When - val mountain1 = di.earth().mountainFactory() - val mountain2 = di.earth().mountainFactory() - - //Then - assertNotEquals( - mountain1.uuid, - mountain2.uuid - ) - } - - @Test - fun differentDIDifferentCacheTest() { - //Given - val di1 = Stone.createComponent(GcGodComponent::class.java) - val di2 = Stone.createComponent(GcGodComponent::class.java) - - //When - val mountain1 = di1.earth().mountainStrong() - val mountain2 = di2.earth().mountainStrong() - - //Then - assertNotEquals( - mountain1.uuid, - mountain2.uuid - ) - } -} \ No newline at end of file diff --git a/tests_kotlin/src/test/kotlin/com/github/klee0kai/tests/java_models/cache/EarthSwitchCacheTests.kt b/tests_kotlin/src/test/kotlin/com/github/klee0kai/tests/java_models/cache/EarthSwitchCacheTests.kt deleted file mode 100644 index d012a2f5..00000000 --- a/tests_kotlin/src/test/kotlin/com/github/klee0kai/tests/java_models/cache/EarthSwitchCacheTests.kt +++ /dev/null @@ -1,78 +0,0 @@ -package com.github.klee0kai.tests.java_models.cache - -import com.github.klee0kai.stone.Stone -import com.github.klee0kai.test.di.swcache.SwitchCacheComponent -import org.junit.jupiter.api.Assertions.assertNotNull -import org.junit.jupiter.api.Assertions.assertNull -import org.junit.jupiter.api.Test -import java.lang.ref.WeakReference - -class EarthSwitchCacheTests { - @Test - fun allToWeakTest() { - //Given - val di = Stone.createComponent(SwitchCacheComponent::class.java) - val mountain = WeakReference(di.earth().mountainStrong()) - - //When - di.allWeak() - System.gc() - - //Then - assertNull(mountain.get()) - } - - @Test - fun strongToWeakTest() { - //Given - val di = Stone.createComponent(SwitchCacheComponent::class.java) - val mountainStrong = WeakReference(di.earth().mountainStrong()) - val mountainSoft = WeakReference(di.earth().mountainSoft()) - - //When - di.strongToWeak() - System.gc() - - //Then - assertNull(mountainStrong.get()) - assertNotNull(mountainSoft.get()) - } - - @Test - @Throws(InterruptedException::class) - fun weakToStrongFewMillisTest() { - //Given - val di = Stone.createComponent(SwitchCacheComponent::class.java) - val mountainWeak = WeakReference(di.earth().mountainWeak()) - - //When - di.allStrongFewMillis() - System.gc() - - //Then: can't GC - assertNotNull(mountainWeak.get()) - - //When: after few millis - Thread.sleep(110) - System.gc() - - //Then: can GC - assertNull(mountainWeak.get()) - } - - @Test - fun mountainToWeakTest() { - //Given - val di = Stone.createComponent(SwitchCacheComponent::class.java) - val mountain = WeakReference(di.earth().mountainStrong()) - val river = WeakReference(di.earth().riverSoft()) - - //When - di.mountainToWeak() - System.gc() - - //Then - assertNull(mountain.get()) - assertNotNull(river.get()) - } -} \ No newline at end of file diff --git a/tests_kotlin/src/test/kotlin/com/github/klee0kai/tests/java_models/gc/EarthLastDayTests.kt b/tests_kotlin/src/test/kotlin/com/github/klee0kai/tests/java_models/gc/EarthLastDayTests.kt deleted file mode 100644 index 21599e3b..00000000 --- a/tests_kotlin/src/test/kotlin/com/github/klee0kai/tests/java_models/gc/EarthLastDayTests.kt +++ /dev/null @@ -1,276 +0,0 @@ -package com.github.klee0kai.tests.java_models.gc - -import com.github.klee0kai.stone.Stone -import com.github.klee0kai.test.di.gcforest.GcGodComponent -import org.junit.jupiter.api.Assertions.assertNotNull -import org.junit.jupiter.api.Assertions.assertNull -import org.junit.jupiter.api.Test -import java.lang.ref.WeakReference -import java.util.* - -class EarthLastDayTests { - @Test - fun gcAllTest() { - //Given - val di = Stone.createComponent(GcGodComponent::class.java) - val mountainStrong = WeakReference(di.earth().mountainStrong()) - val mountainSoft = WeakReference(di.earth().mountainSoft()) - val mountainWeak = WeakReference(di.earth().mountainWeak()) - val mountainDef = WeakReference(di.earth().mountainDefaultFactory()) - val riverStrong = WeakReference(di.earth().riverStrong()) - val riverSoft = WeakReference(di.earth().riverSoft()) - val riverWeak = WeakReference(di.earth().riverWeak()) - val riverDef = WeakReference(di.earth().riverDefaultSoft()) - - //When - di.gcAll() - - //Then - for (ref in Arrays.asList( - mountainStrong, mountainSoft, mountainWeak, mountainDef, - riverStrong, riverSoft, riverWeak, riverDef - )) { - assertNull(ref.get()) - } - } - - @Test - fun gcStrongTest() { - //Given - val di = Stone.createComponent(GcGodComponent::class.java) - val mountainStrong = WeakReference(di.earth().mountainStrong()) - val mountainSoft = WeakReference(di.earth().mountainSoft()) - val mountainWeak = WeakReference(di.earth().mountainWeak()) - val mountainDef = WeakReference(di.earth().mountainDefaultFactory()) - val riverStrong = WeakReference(di.earth().riverStrong()) - val riverSoft = WeakReference(di.earth().riverSoft()) - val riverWeak = WeakReference(di.earth().riverWeak()) - val riverDef = WeakReference(di.earth().riverDefaultSoft()) - - //When - di.gcStrong() - - //Then - for (ref in listOf( - mountainStrong, mountainWeak, mountainDef, - riverStrong, riverWeak, riverDef - )) { - assertNull(ref.get()) - } - for (ref in listOf( - mountainSoft, - riverSoft, - )) { - assertNotNull(ref.get()) - } - } - - @Test - fun gcSoftTest() { - //Given - val di = Stone.createComponent(GcGodComponent::class.java) - val mountainStrong = WeakReference(di.earth().mountainStrong()) - val mountainSoft = WeakReference(di.earth().mountainSoft()) - val mountainWeak = WeakReference(di.earth().mountainWeak()) - val mountainDef = WeakReference(di.earth().mountainDefaultFactory()) - val riverStrong = WeakReference(di.earth().riverStrong()) - val riverSoft = WeakReference(di.earth().riverSoft()) - val riverWeak = WeakReference(di.earth().riverWeak()) - val riverDef = WeakReference(di.earth().riverDefaultSoft()) - - //When - di.gcSoft() - - //Then - for (ref in listOf( - mountainSoft, mountainWeak, mountainDef, - riverSoft, riverWeak, riverDef - )) { - assertNull(ref.get()) - } - for (ref in listOf( - mountainStrong, - riverStrong - )) { - assertNotNull(ref.get()) - } - } - - @Test - fun gcWeakTest() { - //Given - val di = Stone.createComponent(GcGodComponent::class.java) - val mountainStrong = WeakReference(di.earth().mountainStrong()) - val mountainSoft = WeakReference(di.earth().mountainSoft()) - val mountainWeak = WeakReference(di.earth().mountainWeak()) - val mountainDef = WeakReference(di.earth().mountainDefaultFactory()) - val riverStrong = WeakReference(di.earth().riverStrong()) - val riverSoft = WeakReference(di.earth().riverSoft()) - val riverWeak = WeakReference(di.earth().riverWeak()) - val riverDef = WeakReference(di.earth().riverDefaultSoft()) - - //When - di.gcWeak() - - //Then - for (ref in listOf( - mountainWeak, mountainDef, - riverWeak, riverDef - )) { - assertNull(ref.get()) - } - for (ref in listOf( - mountainStrong, mountainSoft, - riverStrong, riverSoft - )) { - assertNotNull(ref.get()) - } - } - - @Test - fun gcMountainTest() { - //Given - val di = Stone.createComponent(GcGodComponent::class.java) - val mountainStrong = WeakReference(di.earth().mountainStrong()) - val mountainSoft = WeakReference(di.earth().mountainSoft()) - val mountainWeak = WeakReference(di.earth().mountainWeak()) - val mountainDef = WeakReference(di.earth().mountainDefaultFactory()) - val riverStrong = WeakReference(di.earth().riverStrong()) - val riverSoft = WeakReference(di.earth().riverSoft()) - val riverWeak = WeakReference(di.earth().riverWeak()) - val riverDef = WeakReference(di.earth().riverDefaultSoft()) - - //When - di.gcMountains() - - //Then - for (ref in listOf( - mountainStrong, mountainSoft, mountainWeak, mountainDef, - riverWeak, riverDef - )) { - assertNull(ref.get()) - } - for (ref in listOf( - riverStrong, riverSoft, - )) { - assertNotNull(ref.get()) - } - } - - @Test - fun gcRiverTest() { - //Given - val di = Stone.createComponent(GcGodComponent::class.java) - val mountainStrong = WeakReference(di.earth().mountainStrong()) - val mountainSoft = WeakReference(di.earth().mountainSoft()) - val mountainWeak = WeakReference(di.earth().mountainWeak()) - val mountainDef = WeakReference(di.earth().mountainDefaultFactory()) - val riverStrong = WeakReference(di.earth().riverStrong()) - val riverSoft = WeakReference(di.earth().riverSoft()) - val riverWeak = WeakReference(di.earth().riverWeak()) - val riverDef = WeakReference(di.earth().riverDefaultSoft()) - - //When - di.gcRivers() - - //Then - for (ref in listOf( - mountainWeak, mountainDef, - riverStrong, riverSoft, riverWeak, riverDef - )) { - assertNull(ref.get()) - } - for (ref in listOf( - mountainStrong, mountainSoft, - )) { - assertNotNull(ref.get()) - } - } - - @Test - fun gcMountainAndRiverTest() { - //Given - val di = Stone.createComponent(GcGodComponent::class.java) - val mountainStrong = WeakReference(di.earth().mountainStrong()) - val mountainSoft = WeakReference(di.earth().mountainSoft()) - val mountainWeak = WeakReference(di.earth().mountainWeak()) - val mountainDef = WeakReference(di.earth().mountainDefaultFactory()) - val riverStrong = WeakReference(di.earth().riverStrong()) - val riverSoft = WeakReference(di.earth().riverSoft()) - val riverWeak = WeakReference(di.earth().riverWeak()) - val riverDef = WeakReference(di.earth().riverDefaultSoft()) - - //When - di.gcMountainsAndRivers() - - //Then - for (ref in listOf( - mountainStrong, mountainSoft, mountainWeak, mountainDef, - riverStrong, riverSoft, riverWeak, riverDef - )) { - assertNull(ref.get()) - } - } - - @Test - fun gcSoftMountainTest() { - //Given - val di = Stone.createComponent(GcGodComponent::class.java) - val mountainStrong = WeakReference(di.earth().mountainStrong()) - val mountainSoft = WeakReference(di.earth().mountainSoft()) - val mountainWeak = WeakReference(di.earth().mountainWeak()) - val mountainDef = WeakReference(di.earth().mountainDefaultFactory()) - val riverStrong = WeakReference(di.earth().riverStrong()) - val riverSoft = WeakReference(di.earth().riverSoft()) - val riverWeak = WeakReference(di.earth().riverWeak()) - val riverDef = WeakReference(di.earth().riverDefaultSoft()) - - //When - di.gcSoftMountains() - - //Then - for (ref in listOf( - mountainSoft, mountainWeak, mountainDef, - riverWeak, riverDef - )) { - assertNull(ref.get()) - } - for (ref in listOf( - mountainStrong, - riverStrong, riverSoft, - )) { - assertNotNull(ref.get()) - } - } - - @Test - fun gcStrongMountainTest() { - //Given - val di = Stone.createComponent(GcGodComponent::class.java) - val mountainStrong = WeakReference(di.earth().mountainStrong()) - val mountainSoft = WeakReference(di.earth().mountainSoft()) - val mountainWeak = WeakReference(di.earth().mountainWeak()) - val mountainDef = WeakReference(di.earth().mountainDefaultFactory()) - val riverStrong = WeakReference(di.earth().riverStrong()) - val riverSoft = WeakReference(di.earth().riverSoft()) - val riverWeak = WeakReference(di.earth().riverWeak()) - val riverDef = WeakReference(di.earth().riverDefaultSoft()) - - //When - di.gcStrongMountains() - - //Then - for (ref in listOf( - mountainStrong, mountainWeak, mountainDef, - riverWeak, riverDef - )) { - assertNull(ref.get()) - } - for (ref in listOf( - mountainSoft, - riverStrong, riverSoft, - )) { - assertNotNull(ref.get()) - } - } -} \ No newline at end of file diff --git a/tests_kotlin/src/test/kotlin/com/github/klee0kai/tests/java_models/gc/GodLastWorkDayTests.kt b/tests_kotlin/src/test/kotlin/com/github/klee0kai/tests/java_models/gc/GodLastWorkDayTests.kt deleted file mode 100644 index 0cd91a51..00000000 --- a/tests_kotlin/src/test/kotlin/com/github/klee0kai/tests/java_models/gc/GodLastWorkDayTests.kt +++ /dev/null @@ -1,153 +0,0 @@ -package com.github.klee0kai.tests.java_models.gc - -import com.github.klee0kai.stone.Stone -import com.github.klee0kai.test.di.gcforest.GcGodComponent -import com.github.klee0kai.test.mowgli.galaxy.Earth -import com.github.klee0kai.test.mowgli.galaxy.Saturn -import com.github.klee0kai.test.mowgli.galaxy.Sun -import org.junit.jupiter.api.Assertions.assertNotNull -import org.junit.jupiter.api.Assertions.assertNull -import org.junit.jupiter.api.Test -import java.lang.ref.WeakReference - -class GodLastWorkDayTests { - @Test - fun gcAllTest() { - //Given - val di = Stone.createComponent(GcGodComponent::class.java) - val sunRef = WeakReference(Sun()) - val earthRef = WeakReference(Earth()) - val saturnRef = WeakReference(Saturn()) - di.bind(sunRef.get()) - di.bind(earthRef.get()) - di.bind(saturnRef.get()) - - //When - di.gcAll() - - //Then - assertNull(sunRef.get()) - assertNull(earthRef.get()) - assertNull(saturnRef.get()) - } - - @Test - fun gcWeakTest() { - //Given - val di = Stone.createComponent(GcGodComponent::class.java) - val sunRef = WeakReference(Sun()) - val earthRef = WeakReference(Earth()) - val saturnRef = WeakReference(Saturn()) - di.bind(sunRef.get()) - di.bind(earthRef.get()) - di.bind(saturnRef.get()) - - //When - di.gcWeak() - - //Then - assertNotNull(sunRef.get()) - assertNotNull(earthRef.get()) - assertNull(saturnRef.get()) - } - - @Test - fun gcSoftTest() { - //Given - val di = Stone.createComponent(GcGodComponent::class.java) - val sunRef = WeakReference(Sun()) - val earthRef = WeakReference(Earth()) - val saturnRef = WeakReference(Saturn()) - di.bind(sunRef.get()) - di.bind(earthRef.get()) - di.bind(saturnRef.get()) - - //When - di.gcSoft() - - //Then - assertNotNull(sunRef.get()) - assertNull(earthRef.get()) - assertNull(saturnRef.get()) - } - - @Test - fun gcStrongTest() { - //Given - val di = Stone.createComponent(GcGodComponent::class.java) - val sunRef = WeakReference(Sun()) - val earthRef = WeakReference(Earth()) - val saturnRef = WeakReference(Saturn()) - di.bind(sunRef.get()) - di.bind(earthRef.get()) - di.bind(saturnRef.get()) - - //When - di.gcStrong() - - //Then - assertNull(sunRef.get()) - assertNotNull(earthRef.get()) - assertNull(saturnRef.get()) - } - - @Test - fun gcSunTest() { - //Given - val di = Stone.createComponent(GcGodComponent::class.java) - val sunRef = WeakReference(Sun()) - val earthRef = WeakReference(Earth()) - val saturnRef = WeakReference(Saturn()) - di.bind(sunRef.get()) - di.bind(earthRef.get()) - di.bind(saturnRef.get()) - - //When - di.gcSun() - - //Then - assertNull(sunRef.get()) - assertNotNull(earthRef.get()) - assertNull(saturnRef.get()) - } - - @Test - fun gcPlanetsTest() { - //Given - val di = Stone.createComponent(GcGodComponent::class.java) - val sunRef = WeakReference(Sun()) - val earthRef = WeakReference(Earth()) - val saturnRef = WeakReference(Saturn()) - di.bind(sunRef.get()) - di.bind(earthRef.get()) - di.bind(saturnRef.get()) - - //When - di.gcPlanets() - - //Then - assertNotNull(sunRef.get()) - assertNull(earthRef.get()) - assertNull(saturnRef.get()) - } - - @Test - fun gcSunAndPlanetsTest() { - //Given - val di = Stone.createComponent(GcGodComponent::class.java) - val sunRef = WeakReference(Sun()) - val earthRef = WeakReference(Earth()) - val saturnRef = WeakReference(Saturn()) - di.bind(sunRef.get()) - di.bind(earthRef.get()) - di.bind(saturnRef.get()) - - //When - di.gcSunAndPlanets() - - //Then - assertNull(sunRef.get()) - assertNull(earthRef.get()) - assertNull(saturnRef.get()) - } -} diff --git a/tests_kotlin/src/test/kotlin/com/github/klee0kai/tests/java_models/identifiers/GoodPhoneInjectTests.kt b/tests_kotlin/src/test/kotlin/com/github/klee0kai/tests/java_models/identifiers/GoodPhoneInjectTests.kt deleted file mode 100644 index 0b6fe0be..00000000 --- a/tests_kotlin/src/test/kotlin/com/github/klee0kai/tests/java_models/identifiers/GoodPhoneInjectTests.kt +++ /dev/null @@ -1,40 +0,0 @@ -package com.github.klee0kai.tests.java_models.identifiers - -import com.github.klee0kai.stone.Stone -import com.github.klee0kai.test.di.base_phone.PhoneComponent -import com.github.klee0kai.test.di.base_phone.identifiers.DataStorageSize -import com.github.klee0kai.test.di.base_phone.identifiers.RamSize -import com.github.klee0kai.test.tech.phone.GoodPhone -import org.junit.jupiter.api.Assertions.assertEquals -import org.junit.jupiter.api.Test - -class GoodPhoneInjectTests { - @Test - fun createGoodPhoneTest() { - //Given - val DI = Stone.createComponent(PhoneComponent::class.java) - val goodPhone = GoodPhone() - - //When - DI.inject(goodPhone, goodPhone.lifeCycleOwner, DataStorageSize("120GB"), RamSize("8GB")) - - //Then - assertEquals("120GB", goodPhone.dataStorage.size) - assertEquals("8GB", goodPhone.ram.size) - } - - @Test - fun cacheInjectedPhoneTest() { - //Given - val DI = Stone.createComponent(PhoneComponent::class.java) - val goodPhone1 = GoodPhone() - val goodPhone2 = GoodPhone() - - //When - DI.inject(goodPhone1, goodPhone1.lifeCycleOwner, DataStorageSize("120GB"), RamSize("8GB")) - DI.inject(goodPhone2, goodPhone2.lifeCycleOwner, DataStorageSize("120GB"), RamSize("8GB")) - - //Then - assertEquals(goodPhone1.ram.uuid, goodPhone2.ram.uuid) - } -} \ No newline at end of file diff --git a/tests_kotlin/src/test/kotlin/com/github/klee0kai/tests/java_models/identifiers/MultiIdentifiersTests.kt b/tests_kotlin/src/test/kotlin/com/github/klee0kai/tests/java_models/identifiers/MultiIdentifiersTests.kt deleted file mode 100644 index 935a4842..00000000 --- a/tests_kotlin/src/test/kotlin/com/github/klee0kai/tests/java_models/identifiers/MultiIdentifiersTests.kt +++ /dev/null @@ -1,63 +0,0 @@ -package com.github.klee0kai.tests.java_models.identifiers - -import com.github.klee0kai.stone.Stone -import com.github.klee0kai.test.di.base_phone.PhoneComponent -import com.github.klee0kai.test.di.base_phone.identifiers.PhoneOsType -import com.github.klee0kai.test.di.base_phone.identifiers.PhoneOsVersion -import org.junit.jupiter.api.Assertions.assertEquals -import org.junit.jupiter.api.Assertions.assertNotEquals -import org.junit.jupiter.api.Test - -class MultiIdentifiersTests { - @Test - fun differentCreatePhoneTest() { - //Given - val DI = Stone.createComponent(PhoneComponent::class.java) - - //When - val androidDemo = DI.components().phoneOs(PhoneOsType.Android, null) - val android11 = DI.components().phoneOs(PhoneOsType.Android, PhoneOsVersion("11")) - - //Then - assertNotEquals(androidDemo.uuid, android11.uuid) - } - - @Test - fun differentMethodDifferentCacheTest() { - //Given - val DI = Stone.createComponent(PhoneComponent::class.java) - - //When - val android11 = DI.components().phoneOs(PhoneOsType.Android, PhoneOsVersion("11")) - val androidSimple = DI.components().phoneOs(PhoneOsType.Android) - - //Then - assertNotEquals(androidSimple.uuid, android11.uuid) - } - - @Test - fun cacheByIdentifiersTest() { - //Given - val DI = Stone.createComponent(PhoneComponent::class.java) - - //When - val android11 = DI.components().phoneOs(PhoneOsType.Android, PhoneOsVersion("11")) - val android11_2 = DI.components().phoneOs(PhoneOsType.Android, PhoneOsVersion("11")) - - //Then - assertEquals(android11.uuid, android11_2.uuid) - } - - @Test - fun sepCacheByIdentifiersTest() { - //Given - val DI = Stone.createComponent(PhoneComponent::class.java) - - //When - val android11 = DI.components().phoneOs(PhoneOsType.Android, PhoneOsVersion("11")) - val android12 = DI.components().phoneOs(PhoneOsType.Android, PhoneOsVersion("12")) - - //Then - assertNotEquals(android11.uuid, android12.uuid) - } -} \ No newline at end of file diff --git a/tests_kotlin/src/test/kotlin/com/github/klee0kai/tests/java_models/identifiers/TechComponentsTests.kt b/tests_kotlin/src/test/kotlin/com/github/klee0kai/tests/java_models/identifiers/TechComponentsTests.kt deleted file mode 100644 index 9cd1659d..00000000 --- a/tests_kotlin/src/test/kotlin/com/github/klee0kai/tests/java_models/identifiers/TechComponentsTests.kt +++ /dev/null @@ -1,65 +0,0 @@ -package com.github.klee0kai.tests.java_models.identifiers - -import com.github.klee0kai.stone.Stone -import com.github.klee0kai.test.di.base_phone.PhoneComponent -import com.github.klee0kai.test.di.base_phone.identifiers.PhoneOsType -import com.github.klee0kai.test.di.base_phone.identifiers.RamSize -import org.junit.jupiter.api.Assertions.assertEquals -import org.junit.jupiter.api.Assertions.assertNotEquals -import org.junit.jupiter.api.Test - -class TechComponentsTests { - @Test - fun differentCreateTest() { - //Given - val DI = Stone.createComponent(PhoneComponent::class.java) - - //When - val ram8Gb = DI.components().ram(RamSize("8GB")) - val ram9Gb = DI.components().ram(RamSize("9GB")) - - //Then: created components are different - assertNotEquals(ram8Gb.uuid, ram9Gb.uuid) - } - - @Test - fun singleCacheTest() { - //Given - val DI = Stone.createComponent(PhoneComponent::class.java) - - //When - val ram1 = DI.components().ram(RamSize("8GB")) - val ram2 = DI.components().ram(RamSize("8GB")) - - //Then: cached ram - assertEquals(ram1.uuid, ram2.uuid) - } - - @Test - fun enumDifferentTest() { - //Given - val DI = Stone.createComponent(PhoneComponent::class.java) - - //When - val android = DI.components().phoneOs(PhoneOsType.Android) - val osNull = DI.components().phoneOs(null) - val ios = DI.components().phoneOs(PhoneOsType.Ios) - - //Then: created components are different - assertNotEquals(android.uuid, osNull.uuid) - assertNotEquals(android.uuid, ios.uuid) - } - - @Test - fun enumCachedTest() { - //Given - val DI = Stone.createComponent(PhoneComponent::class.java) - - //When - val android = DI.components().phoneOs(PhoneOsType.Android) - val android2 = DI.components().phoneOs(PhoneOsType.Android) - - //Then: created components are different - assertEquals(android.uuid, android2.uuid) - } -} \ No newline at end of file diff --git a/tests_kotlin/src/test/kotlin/com/github/klee0kai/tests/java_models/identifiers/TechFactoryComponentTests.kt b/tests_kotlin/src/test/kotlin/com/github/klee0kai/tests/java_models/identifiers/TechFactoryComponentTests.kt deleted file mode 100644 index 00a4fb50..00000000 --- a/tests_kotlin/src/test/kotlin/com/github/klee0kai/tests/java_models/identifiers/TechFactoryComponentTests.kt +++ /dev/null @@ -1,90 +0,0 @@ -package com.github.klee0kai.tests.java_models.identifiers - -import com.github.klee0kai.stone.Stone -import com.github.klee0kai.test.di.base_phone.identifiers.PhoneOsType -import com.github.klee0kai.test.di.base_phone.identifiers.PhoneOsVersion -import com.github.klee0kai.test.di.base_phone.identifiers.RamSize -import com.github.klee0kai.test.di.techfactory.TechFactoryComponent -import org.junit.jupiter.api.Assertions.* -import org.junit.jupiter.api.Test - -class TechFactoryComponentTests { - @Test - fun nonArgProvideTest() { - //Given - val DI = Stone.createComponent(TechFactoryComponent::class.java) - - //When - val ram = DI.ram() - - //Then - assertEquals("default", ram.size) - } - - @Test - fun singleArgProvideTest() { - //Given - val DI = Stone.createComponent(TechFactoryComponent::class.java) - - //When - val ram = DI.ram(RamSize("4G")) - - //Then - assertEquals("4G", ram.size) - } - - @Test - fun nullGenerateArgProvideTest() { - //Given - val DI = Stone.createComponent(TechFactoryComponent::class.java) - - //When - val os = DI.phoneOs() - - //Then: should pass null missing args - assertNull(os.phoneOsType) // missing args - assertEquals("default", os.version.version) // default from constructor - } - - @Test - fun coupleArgsProvideTest() { - //Given - val DI = Stone.createComponent(TechFactoryComponent::class.java) - - //When - val os = DI.phoneOs(PhoneOsType.Ios, PhoneOsVersion("11")) - - //Then - assertEquals(PhoneOsType.Ios, os.phoneOsType) - assertEquals("11", os.version.version) - } - - @Test - fun differentCreateTest() { - //Given - val DI = Stone.createComponent(TechFactoryComponent::class.java) - - //When - val ram8Gb = DI.ram(RamSize("8GB")) - val ram8Gb2 = DI.ram(RamSize("8GB")) - - //Then: created components are different - assertEquals("8GB", ram8Gb.size) - assertNotEquals(ram8Gb.uuid, ram8Gb2.uuid) - } - - @Test - fun enumDifferentTest() { - //Given - val DI = Stone.createComponent(TechFactoryComponent::class.java) - - //When - val android = DI.phoneOs(PhoneOsType.Android) - val android2 = DI.phoneOs(PhoneOsType.Android) - val osNull = DI.phoneOs(null) - - //Then: created components are different - assertNotEquals(android.uuid, osNull.uuid) - assertNotEquals(android.uuid, android2.uuid) - } -} \ No newline at end of file diff --git a/tests_kotlin/src/test/kotlin/com/github/klee0kai/tests/java_models/identifiers/TechFactoryTests.kt b/tests_kotlin/src/test/kotlin/com/github/klee0kai/tests/java_models/identifiers/TechFactoryTests.kt deleted file mode 100644 index 8c4e1620..00000000 --- a/tests_kotlin/src/test/kotlin/com/github/klee0kai/tests/java_models/identifiers/TechFactoryTests.kt +++ /dev/null @@ -1,38 +0,0 @@ -package com.github.klee0kai.tests.java_models.identifiers - -import com.github.klee0kai.stone.Stone -import com.github.klee0kai.test.di.base_phone.identifiers.PhoneOsType -import com.github.klee0kai.test.di.base_phone.identifiers.RamSize -import com.github.klee0kai.test.di.techfactory.TechFactoryComponent -import org.junit.jupiter.api.Assertions.assertNotEquals -import org.junit.jupiter.api.Test - -class TechFactoryTests { - @Test - fun differentCreateTest() { - //Given - val DI = Stone.createComponent(TechFactoryComponent::class.java) - - //When - val ram8Gb = DI.factory().ram(RamSize("8GB")) - val ram8Gb2 = DI.factory().ram(RamSize("8GB")) - - //Then: created components are different - assertNotEquals(ram8Gb.uuid, ram8Gb2.uuid) - } - - @Test - fun enumDifferentTest() { - //Given - val DI = Stone.createComponent(TechFactoryComponent::class.java) - - //When - val android = DI.factory().phoneOs(PhoneOsType.Android) - val android2 = DI.factory().phoneOs(PhoneOsType.Android) - val osNull = DI.factory().phoneOs(null) - - //Then: created components are different - assertNotEquals(android.uuid, osNull.uuid) - assertNotEquals(android.uuid, android2.uuid) - } -} \ No newline at end of file diff --git a/tests_kotlin/src/test/kotlin/com/github/klee0kai/tests/java_models/identifiers/TechFactoryWrappersTests.kt b/tests_kotlin/src/test/kotlin/com/github/klee0kai/tests/java_models/identifiers/TechFactoryWrappersTests.kt deleted file mode 100644 index 683c4fda..00000000 --- a/tests_kotlin/src/test/kotlin/com/github/klee0kai/tests/java_models/identifiers/TechFactoryWrappersTests.kt +++ /dev/null @@ -1,95 +0,0 @@ -package com.github.klee0kai.tests.java_models.identifiers - -import com.github.klee0kai.stone.Stone -import com.github.klee0kai.stone.weakref.Ref -import com.github.klee0kai.test.di.techfactory.TechFactoryComponent -import com.github.klee0kai.test.tech.components.Battery -import org.junit.jupiter.api.Assertions.* -import org.junit.jupiter.api.Test -import java.lang.ref.Reference - -class TechFactoryWrappersTests { - @Test - fun lazyProvideTest() { - //Given - val DI = Stone.createComponent(TechFactoryComponent::class.java) - - //When - val battery: Ref = DI.batteryLazy() - - //Then - assertEquals( - battery.get().uuid, - battery.get().uuid - ) - } - - @Test - fun softRefProvideTest() { - //Given - val DI = Stone.createComponent(TechFactoryComponent::class.java) - - //When - val battery: Reference = DI.batterySoft() - - //Then - assertNotNull(battery.get()) - } - - @Test - fun weakRefProvideTest() { - //Given - val DI = Stone.createComponent(TechFactoryComponent::class.java) - - //When - val battery: Reference = DI.batteryWeak() - - //Then - assertNotNull(battery.get()) - } - - @Test - fun phantom1ProvideTest() { - //Given - val DI = Stone.createComponent(TechFactoryComponent::class.java) - - //When - val battery: Ref = DI.batteryPhantomProvider() - - //Then - assertNotEquals( - battery.get().uuid, - battery.get().uuid - ) - } - - @Test - fun phantom2ProvideTest() { - //Given - val DI = Stone.createComponent(TechFactoryComponent::class.java) - - //When - val battery = DI.batteryProvider() - - //Then - assertNotEquals( - battery.get().uuid, - battery.get().uuid - ) - } - - @Test - fun phantom3ProvideTest() { - //Given - val DI = Stone.createComponent(TechFactoryComponent::class.java) - - //When - val battery = DI.batteryProviderIRef() - - //Then - assertNotEquals( - battery.get().uuid, - battery.get().uuid - ) - } -} \ No newline at end of file diff --git a/tests_kotlin/src/test/kotlin/com/github/klee0kai/tests/java_models/inject/HorseInjectTests.kt b/tests_kotlin/src/test/kotlin/com/github/klee0kai/tests/java_models/inject/HorseInjectTests.kt deleted file mode 100644 index 08483792..00000000 --- a/tests_kotlin/src/test/kotlin/com/github/klee0kai/tests/java_models/inject/HorseInjectTests.kt +++ /dev/null @@ -1,76 +0,0 @@ -package com.github.klee0kai.tests.java_models.inject - -import com.github.klee0kai.stone.Stone -import com.github.klee0kai.stone.lifecycle.StoneLifeCycleListener -import com.github.klee0kai.test.di.base_forest.ForestComponent -import com.github.klee0kai.test.mowgli.animal.Horse -import com.github.klee0kai.test.mowgli.animal.Mowgli -import com.github.klee0kai.test.mowgli.animal.Snake -import org.junit.jupiter.api.Assertions.* -import org.junit.jupiter.api.Test - -class HorseInjectTests { - @Test - fun horseBornTest() { - //Given - val DI = Stone.createComponent(ForestComponent::class.java) - val horse = Horse() - - - //When - DI.inject(horse) { listener: StoneLifeCycleListener? -> } - - //Then - assertNotNull(horse.blood) - assertNotNull(horse.knowledge) - assertNotNull(horse.conscience) - } - - @Test - fun mowgliBornTest() { - //Given - val DI = Stone.createComponent(ForestComponent::class.java) - val mowgli = Mowgli() - - - //When - DI.inject(mowgli) - - //Then - assertNotNull(mowgli.blood) - assertNotNull(mowgli.knowledge) - assertNotNull(mowgli.conscience) - } - - @Test - fun oneBloodTest() { - //Given - val DI = Stone.createComponent(ForestComponent::class.java) - val mowgli = Mowgli() - val snake = Snake() - - - //When - DI.inject(mowgli) - DI.inject(snake) - - //Then - assertEquals(mowgli.blood.uuid, snake.blood.uuid) - } - - @Test - fun personalityTest() { - //Given - val DI = Stone.createComponent(ForestComponent::class.java) - val mowgli = Mowgli() - val snake = Snake() - - - //When - DI.inject(mowgli) - DI.inject(snake) - - //Then - assertNotEquals(mowgli.conscience.uuid, snake.conscience.uuid) - } -} \ No newline at end of file diff --git a/tests_kotlin/src/test/kotlin/com/github/klee0kai/tests/java_models/inject/HorseProtectInjectTests.kt b/tests_kotlin/src/test/kotlin/com/github/klee0kai/tests/java_models/inject/HorseProtectInjectTests.kt deleted file mode 100644 index 4c301d63..00000000 --- a/tests_kotlin/src/test/kotlin/com/github/klee0kai/tests/java_models/inject/HorseProtectInjectTests.kt +++ /dev/null @@ -1,56 +0,0 @@ -package com.github.klee0kai.tests.java_models.inject - -import com.github.klee0kai.stone.Stone -import com.github.klee0kai.stone.lifecycle.StoneLifeCycleListener -import com.github.klee0kai.test.di.base_forest.ForestComponent -import com.github.klee0kai.test.mowgli.animal.Horse -import org.junit.jupiter.api.Assertions.assertNotNull -import org.junit.jupiter.api.Assertions.assertNull -import org.junit.jupiter.api.Test -import java.lang.ref.WeakReference - -class HorseProtectInjectTests { - @Test - fun withoutProtectInjectTest() { - // Given - val DI = Stone.createComponent(ForestComponent::class.java) - var horse: Horse? = Horse() - - - //When - DI.inject(horse) { listener: StoneLifeCycleListener? -> } - val historyWeakReference = WeakReference( - horse!!.history - ) - horse = null - DI.gcAll() - - //Then: without protect all not uses should be garbage collected - assertNull(historyWeakReference.get()) - } - - @Test - @Throws(InterruptedException::class) - fun withProtectInjectTest() { - // Given - val DI = Stone.createComponent(ForestComponent::class.java) - var horse: Horse? = Horse() - - //When - DI.inject(horse) { listener: StoneLifeCycleListener? -> } - val historyWeakReference = WeakReference( - horse!!.history - ) - DI.protectInjected(horse) - horse = null - DI.gcAll() - - //Then - assertNotNull(historyWeakReference.get()) - - //after protect finished - Thread.sleep(50) - DI.gcAll() - assertNull(historyWeakReference.get()) - } -} \ No newline at end of file diff --git a/tests_kotlin/src/test/kotlin/com/github/klee0kai/tests/java_models/inject/MowgliInjectWrappersTests.kt b/tests_kotlin/src/test/kotlin/com/github/klee0kai/tests/java_models/inject/MowgliInjectWrappersTests.kt deleted file mode 100644 index bd94acdb..00000000 --- a/tests_kotlin/src/test/kotlin/com/github/klee0kai/tests/java_models/inject/MowgliInjectWrappersTests.kt +++ /dev/null @@ -1,79 +0,0 @@ -package com.github.klee0kai.tests.java_models.inject - -import com.github.klee0kai.stone.Stone -import com.github.klee0kai.test.di.base_forest.ForestComponent -import com.github.klee0kai.test.mowgli.animal.Mowgli -import org.junit.jupiter.api.Assertions.* -import org.junit.jupiter.api.Test - -class MowgliInjectWrappersTests { - @Test - fun supportWrappersTest() { - //Given - val DI = Stone.createComponent(ForestComponent::class.java) - val mowgli = Mowgli() - - - //When - DI.inject(mowgli) - - //Then - assertNotNull(mowgli.knowledge) - assertNotNull(mowgli.knowledgeWeakRef.get()) - assertNotNull(mowgli.knowledgeSoftRef.get()) - assertNotNull(mowgli.knowledgeLazyProvide.get()) - assertNotNull(mowgli.knowledgePhantomProvide.get()) - assertNotNull(mowgli.knowledgePhantomProvide2.get()) - assertNotNull(mowgli.knowledgePhantomProvide3.get()) - } - - @Test - fun refWrapperTest() { - //Given - val DI = Stone.createComponent(ForestComponent::class.java) - val mowgli = Mowgli() - - //When - DI.inject(mowgli) - - - //Then - assertEquals( - mowgli.knowledgeWeakRef.get()!!.uuid, - mowgli.knowledgeWeakRef.get()!!.uuid - ) - assertEquals( - mowgli.knowledgeSoftRef.get()!!.uuid, - mowgli.knowledgeSoftRef.get()!!.uuid - ) - assertEquals( - mowgli.knowledgeLazyProvide.get()!!.uuid, - mowgli.knowledgeLazyProvide.get()!!.uuid - ) - } - - @Test - fun genWrapperTest() { - //Given - val DI = Stone.createComponent(ForestComponent::class.java) - val mowgli = Mowgli() - - //When - DI.inject(mowgli) - - - //Then - assertNotEquals( - mowgli.knowledgePhantomProvide.get().uuid, - mowgli.knowledgePhantomProvide.get().uuid - ) - assertNotEquals( - mowgli.knowledgePhantomProvide2.get().uuid, - mowgli.knowledgePhantomProvide2.get().uuid - ) - assertNotEquals( - mowgli.knowledgePhantomProvide3.get().uuid, - mowgli.knowledgePhantomProvide3.get().uuid - ) - } -} \ No newline at end of file diff --git a/tests_kotlin/src/test/kotlin/com/github/klee0kai/tests/java_models/inject/SchoolProtectInjectWrappersTests.kt b/tests_kotlin/src/test/kotlin/com/github/klee0kai/tests/java_models/inject/SchoolProtectInjectWrappersTests.kt deleted file mode 100644 index 4cef61aa..00000000 --- a/tests_kotlin/src/test/kotlin/com/github/klee0kai/tests/java_models/inject/SchoolProtectInjectWrappersTests.kt +++ /dev/null @@ -1,47 +0,0 @@ -package com.github.klee0kai.tests.java_models.inject - -import com.github.klee0kai.stone.Stone -import com.github.klee0kai.test.di.base_forest.ForestComponent -import com.github.klee0kai.test.mowgli.School -import org.junit.jupiter.api.Assertions.assertNotNull -import org.junit.jupiter.api.Assertions.assertNull -import org.junit.jupiter.api.Test -import java.lang.ref.WeakReference - -class SchoolProtectInjectWrappersTests { - @Test - fun lazyWrapperProtectTest() { - // Given - val DI = Stone.createComponent(ForestComponent::class.java) - val school = School() - - //When - DI.inject(school) - val history = WeakReference(school.historyLazyProvide.get()) - DI.protectInjected(school) - DI.gcAll() - - //Then - assertNotNull(history.get()) - } - - @Test - fun ignoreProvideWrapperProtectTest() { - // Given - val DI = Stone.createComponent(ForestComponent::class.java) - val school = School() - - //When - DI.inject(school) - val knowledge1 = WeakReference(school.knowledgePhantomProvide.get()) - val knowledge2 = WeakReference(school.knowledgePhantomProvide2.get()) - val knowledge3 = WeakReference(school.knowledgePhantomProvide3.get()) - DI.protectInjected(school) - DI.gcAll() - - //Then - assertNull(knowledge1.get()) - assertNull(knowledge2.get()) - assertNull(knowledge3.get()) - } -} \ No newline at end of file diff --git a/tests_kotlin/src/test/kotlin/com/github/klee0kai/tests/java_models/interfaceprovide/DeepCaveTest.kt b/tests_kotlin/src/test/kotlin/com/github/klee0kai/tests/java_models/interfaceprovide/DeepCaveTest.kt deleted file mode 100644 index 15a635f4..00000000 --- a/tests_kotlin/src/test/kotlin/com/github/klee0kai/tests/java_models/interfaceprovide/DeepCaveTest.kt +++ /dev/null @@ -1,30 +0,0 @@ -package com.github.klee0kai.tests.java_models.interfaceprovide - -import com.github.klee0kai.stone.Stone -import com.github.klee0kai.test.di.earthmirror.EarthComponent -import com.github.klee0kai.test.mowgli.earth.Cave -import org.junit.jupiter.api.Assertions.assertNotNull -import org.junit.jupiter.api.Test - -class DeepCaveTest { - @Test - fun justCaveTest() { - //When - val di = Stone.createComponent(EarthComponent::class.java) - - //Then: Cave simple constructor is available - assertNotNull(di.east().cave()) - assertNotNull(di.west().cave()) - } - - @Test - fun theCaveTest() { - //When - val di = Stone.createComponent(EarthComponent::class.java) - - //Then: Cave 2 params constructor is available - assertNotNull(di.east().cave(Cave.CaveType.Glacier, 2)) - assertNotNull(di.west().cave(Cave.CaveType.Fracture, 6)) - } - -} \ No newline at end of file diff --git a/tests_kotlin/src/test/kotlin/com/github/klee0kai/tests/java_models/interfaceprovide/EarthWayTest.kt b/tests_kotlin/src/test/kotlin/com/github/klee0kai/tests/java_models/interfaceprovide/EarthWayTest.kt deleted file mode 100644 index 6d5b445e..00000000 --- a/tests_kotlin/src/test/kotlin/com/github/klee0kai/tests/java_models/interfaceprovide/EarthWayTest.kt +++ /dev/null @@ -1,19 +0,0 @@ -package com.github.klee0kai.tests.java_models.interfaceprovide - -import com.github.klee0kai.stone.Stone -import com.github.klee0kai.test.di.earthmirror.EarthComponent -import org.junit.jupiter.api.Assertions.assertNotNull -import org.junit.jupiter.api.Test - -class EarthWayTest { - - @Test - fun ChristopherColumbusTest() { - //When - val di = Stone.createComponent(EarthComponent::class.java) - - //Then - assertNotNull(di.west().mountainImp()) - assertNotNull(di.west().riverImpl()) - } -} \ No newline at end of file diff --git a/tests_kotlin/src/test/kotlin/com/github/klee0kai/tests/java_models/lifecycle/GoodPhoneRepairTests.kt b/tests_kotlin/src/test/kotlin/com/github/klee0kai/tests/java_models/lifecycle/GoodPhoneRepairTests.kt deleted file mode 100644 index 2c0a2082..00000000 --- a/tests_kotlin/src/test/kotlin/com/github/klee0kai/tests/java_models/lifecycle/GoodPhoneRepairTests.kt +++ /dev/null @@ -1,124 +0,0 @@ -package com.github.klee0kai.tests.java_models.lifecycle - -import com.github.klee0kai.stone.Stone -import com.github.klee0kai.test.di.base_phone.PhoneComponent -import com.github.klee0kai.test.di.base_phone.identifiers.DataStorageSize -import com.github.klee0kai.test.di.base_phone.identifiers.RamSize -import com.github.klee0kai.test.tech.phone.GoodPhone -import org.junit.jupiter.api.Assertions.* -import org.junit.jupiter.api.Test -import java.lang.ref.WeakReference - -/** - * Test lifecycle owner over LifecycleUtils - */ -class GoodPhoneRepairTests { - @Test - fun goodPhoneInjectTest() { - //Given - val DI = Stone.createComponent(PhoneComponent::class.java) - - //When buy - val goodPhone = GoodPhone() - DI.inject(goodPhone, goodPhone.lifeCycleOwner, DataStorageSize("64G"), RamSize("4G")) - - //Then - assertNotNull(goodPhone.battery) - assertNotNull(goodPhone.dataStorage) - assertNotNull(goodPhone.ram) - } - - @Test - fun goodPhoneBrokeTest() { - //Given - val DI = Stone.createComponent(PhoneComponent::class.java) - val goodPhone = GoodPhone() - DI.inject(goodPhone, goodPhone.lifeCycleOwner, DataStorageSize("64G"), RamSize("4G")) - val batteryRef = WeakReference(goodPhone.battery) - val dataStorageRef = WeakReference(goodPhone.dataStorage) - val ramRef = WeakReference(goodPhone.ram) - - //When broke and repair - goodPhone.broke() - System.gc() - DI.inject(goodPhone, DataStorageSize("64G"), RamSize("4G")) - - //Then: Need new details for repair phone. Old components collected by GC - assertNull(batteryRef.get()) - assertNull(dataStorageRef.get()) - assertNull(ramRef.get()) - } - - @Test - @Throws(InterruptedException::class) - fun goodPhoneDropWatterTest() { - //Given - val DI = Stone.createComponent(PhoneComponent::class.java) - val goodPhone = GoodPhone() - DI.inject(goodPhone, goodPhone.lifeCycleOwner, DataStorageSize("64G"), RamSize("4G")) - val batteryRef = WeakReference(goodPhone.battery) - val dataStorageRef = WeakReference(goodPhone.dataStorage) - val ramRef = WeakReference(goodPhone.ram) - - //When - goodPhone.dropToWater() - System.gc() - - //Then: Phone not link with his components - assertNull(goodPhone.battery) - assertNull(goodPhone.dataStorage) - assertNull(goodPhone.ram) - - //Then: Phone components is alive little time. - assertNotNull(batteryRef.get()) - assertNotNull(dataStorageRef.get()) - assertNotNull(ramRef.get()) - - //When: After little time - Thread.sleep(120) - System.gc() - - //Then: Phone can not be repaired, components lost - assertNull(batteryRef.get()) - assertNull(dataStorageRef.get()) - assertNull(ramRef.get()) - } - - @Test - @Throws(InterruptedException::class) - fun goodPhoneDrownedRepairTest() { - //Given - val DI = Stone.createComponent(PhoneComponent::class.java) - val goodPhone = GoodPhone() - DI.inject(goodPhone, goodPhone.lifeCycleOwner, DataStorageSize("64G"), RamSize("4G")) - val ramUuid = goodPhone.dataStorage.uuid - - //When - goodPhone.dropToWater() - Thread.sleep(10) - System.gc() - DI.inject(goodPhone, goodPhone.lifeCycleOwner, DataStorageSize("64G"), RamSize("4G")) - - //Then: Can be repair after little time - assertEquals(ramUuid, goodPhone.dataStorage.uuid) - } - - @Test - @Throws(InterruptedException::class) - fun goodPhoneDeepDrownedRepairTest() { - //Given - val DI = Stone.createComponent(PhoneComponent::class.java) - val goodPhone = GoodPhone() - DI.inject(goodPhone, goodPhone.lifeCycleOwner, DataStorageSize("64G"), RamSize("4G")) - val ramUuid = goodPhone.dataStorage.uuid - - //When - goodPhone.dropToWater() - Thread.sleep(120) - System.gc() - DI.inject(goodPhone, goodPhone.lifeCycleOwner, DataStorageSize("64G"), RamSize("4G")) - - //Then: Can not be repair without new details - assertNotEquals(ramUuid, goodPhone.dataStorage.uuid) - } -} \ No newline at end of file diff --git a/tests_kotlin/src/test/kotlin/com/github/klee0kai/tests/java_models/lifecycle/OnePhoneRepairTests.kt b/tests_kotlin/src/test/kotlin/com/github/klee0kai/tests/java_models/lifecycle/OnePhoneRepairTests.kt deleted file mode 100644 index 809b7706..00000000 --- a/tests_kotlin/src/test/kotlin/com/github/klee0kai/tests/java_models/lifecycle/OnePhoneRepairTests.kt +++ /dev/null @@ -1,122 +0,0 @@ -package com.github.klee0kai.tests.java_models.lifecycle - -import com.github.klee0kai.stone.Stone -import com.github.klee0kai.test.di.base_phone.PhoneComponent -import com.github.klee0kai.test.tech.phone.OnePhone -import org.junit.jupiter.api.Assertions.* -import org.junit.jupiter.api.Test -import java.lang.ref.WeakReference - -/** - * Test lifecycle owner implemented in providing model - */ -class OnePhoneRepairTests { - @Test - fun onePhoneInjectTest() { - //Given - val DI = Stone.createComponent(PhoneComponent::class.java) - - //When - val onePhone = OnePhone() - DI.inject(onePhone) - - //Then - assertNotNull(onePhone.battery) - assertNotNull(onePhone.dataStorage) - assertNotNull(onePhone.ram) - } - - @Test - fun onePhoneBrokeTest() { - //Given - val DI = Stone.createComponent(PhoneComponent::class.java) - val onePhone = OnePhone() - DI.inject(onePhone) - val batteryRef = WeakReference(onePhone.battery) - val dataStorageRef = WeakReference(onePhone.dataStorage) - val ramRef = WeakReference(onePhone.ram) - - //When - onePhone.broke() - System.gc() - DI.inject(onePhone) - - //Then: Need new details for repair phone. Old components collected by GC - assertNull(batteryRef.get()) - assertNull(dataStorageRef.get()) - assertNull(ramRef.get()) - } - - @Test - @Throws(InterruptedException::class) - fun onePhoneDropWatterTest() { - //Given - val DI = Stone.createComponent(PhoneComponent::class.java) - val onePhone = OnePhone() - DI.inject(onePhone) - val batteryRef = WeakReference(onePhone.battery) - val dataStorageRef = WeakReference(onePhone.dataStorage) - val ramRef = WeakReference(onePhone.ram) - - //When - onePhone.dropToWatter() - System.gc() - - //Then: Phone not link with his components - assertNull(onePhone.battery) - assertNull(onePhone.dataStorage) - assertNull(onePhone.ram) - - //Then: Phone components is alive little time. - assertNotNull(batteryRef.get()) - assertNotNull(dataStorageRef.get()) - assertNotNull(ramRef.get()) - - //When: After little time - Thread.sleep(120) - System.gc() - - //Then: Phone can not be repaired, components lost - assertNull(batteryRef.get()) - assertNull(dataStorageRef.get()) - assertNull(ramRef.get()) - } - - @Test - @Throws(InterruptedException::class) - fun onePhoneDrownedRepairTest() { - //Given - val DI = Stone.createComponent(PhoneComponent::class.java) - val onePhone = OnePhone() - DI.inject(onePhone) - val ramUuid = onePhone.dataStorage.uuid - - //When - onePhone.dropToWatter() - Thread.sleep(10) - System.gc() - DI.inject(onePhone) - - //Then: Can be repair after little time - assertEquals(ramUuid, onePhone.dataStorage.uuid) - } - - @Test - @Throws(InterruptedException::class) - fun onePhoneDeepDrownedRepairTest() { - //Given - val DI = Stone.createComponent(PhoneComponent::class.java) - val onePhone = OnePhone() - DI.inject(onePhone) - val ramUuid = onePhone.dataStorage.uuid - - //When - onePhone.dropToWatter() - Thread.sleep(120) - System.gc() - DI.inject(onePhone) - - //Then: Can not be repair without new details - assertNotEquals(ramUuid, onePhone.dataStorage.uuid) - } -} \ No newline at end of file diff --git a/tests_kotlin/src/test/kotlin/com/github/klee0kai/tests/java_models/moduleinit/BeginOfBegins2Tests.kt b/tests_kotlin/src/test/kotlin/com/github/klee0kai/tests/java_models/moduleinit/BeginOfBegins2Tests.kt deleted file mode 100644 index 0d2909cc..00000000 --- a/tests_kotlin/src/test/kotlin/com/github/klee0kai/tests/java_models/moduleinit/BeginOfBegins2Tests.kt +++ /dev/null @@ -1,72 +0,0 @@ -package com.github.klee0kai.tests.java_models.moduleinit - -import com.github.klee0kai.stone.Stone -import com.github.klee0kai.test.di.base_forest.ForestComponent -import com.github.klee0kai.test.di.base_forest.UnitedBlueModule -import com.github.klee0kai.test.di.base_forest.UnitedModule -import com.github.klee0kai.test.mowgli.community.History -import com.github.klee0kai.test.mowgli.galaxy.Earth -import org.junit.jupiter.api.Assertions.assertEquals -import org.junit.jupiter.api.Test -import java.awt.Color - -class BeginOfBegins2Tests { - @Test - fun initByFactory() { - //Given - val module: UnitedModule = object : UnitedModule() { - override fun earth(): Earth { - return earth - } - - override fun history(): History? { - return null - } - } - val DI = Stone.createComponent(ForestComponent::class.java) - - //When - DI.initUnitedModule(module) - - //Then - assertEquals(earth, DI.united().earth()) - } - - @Test - fun initByFactoryClass() { - //Given - val DI = Stone.createComponent(ForestComponent::class.java) - - //When - DI.initUnitedModule(UnitedModuleFactory::class.java) - - //Then - assertEquals(earth, DI.united().earth()) - } - - @Test - fun initByAbstractFactoryClass() { - //Given - val DI = Stone.createComponent(ForestComponent::class.java) - - //When - DI.initUnitedModule(UnitedBlueModule::class.java) - - //Then - assertEquals(Color.BLUE, DI.united().blood().color) - } - - class UnitedModuleFactory : UnitedModule() { - override fun earth(): Earth { - return earth - } - - override fun history(): History? { - return null - } - } - - companion object { - private val earth = Earth() - } -} \ No newline at end of file diff --git a/tests_kotlin/src/test/kotlin/com/github/klee0kai/tests/java_models/moduleinit/BeginOfBeginsTests.kt b/tests_kotlin/src/test/kotlin/com/github/klee0kai/tests/java_models/moduleinit/BeginOfBeginsTests.kt deleted file mode 100644 index e6944652..00000000 --- a/tests_kotlin/src/test/kotlin/com/github/klee0kai/tests/java_models/moduleinit/BeginOfBeginsTests.kt +++ /dev/null @@ -1,58 +0,0 @@ -package com.github.klee0kai.tests.java_models.moduleinit - -import com.github.klee0kai.stone.Stone -import com.github.klee0kai.test.di.base_forest.ForestComponent -import com.github.klee0kai.test.di.base_forest.UnitedModule -import com.github.klee0kai.test.mowgli.community.History -import com.github.klee0kai.test.mowgli.galaxy.Earth -import org.junit.jupiter.api.Assertions.assertEquals -import org.junit.jupiter.api.Test - -class BeginOfBeginsTests { - @Test - fun initByFactory() { - //Given - val module: UnitedModule = object : UnitedModule() { - override fun earth(): Earth { - return earth - } - - override fun history(): History? { - return null - } - } - val DI = Stone.createComponent(ForestComponent::class.java) - - //When - DI.initUnitedModule(module) - - //Then - assertEquals(earth, DI.united().earth()) - } - - @Test - fun initByFactoryClass() { - //Given - val DI = Stone.createComponent(ForestComponent::class.java) - - //When - DI.initUnitedModule(UnitedModuleFactory::class.java) - - //Then - assertEquals(earth, DI.united().earth()) - } - - class UnitedModuleFactory : UnitedModule() { - override fun earth(): Earth? { - return earth - } - - override fun history(): History? { - return null - } - } - - companion object { - private val earth = Earth() - } -} \ No newline at end of file diff --git a/tests_kotlin/src/test/kotlin/com/github/klee0kai/tests/kotlin_models/definterface/DefInterfaceTest.kt b/tests_kotlin/src/test/kotlin/com/github/klee0kai/tests/kotlin_models/definterface/DefInterfaceTest.kt index 24d77567..1c93d7bb 100644 --- a/tests_kotlin/src/test/kotlin/com/github/klee0kai/tests/kotlin_models/definterface/DefInterfaceTest.kt +++ b/tests_kotlin/src/test/kotlin/com/github/klee0kai/tests/kotlin_models/definterface/DefInterfaceTest.kt @@ -1,6 +1,5 @@ package com.github.klee0kai.tests.kotlin_models.definterface -import com.github.klee0kai.stone.Stone import com.github.klee0kai.test_kotlin.di.base_comp.identifiers.KConnectType import com.github.klee0kai.test_kotlin.di.base_comp.identifiers.MonitorSize import com.github.klee0kai.test_kotlin.di.definterface.DefInterfaceComponent @@ -12,7 +11,7 @@ class DefInterfaceTest { @Test fun provideKeyboardTest() { //Given - val DI = Stone.createComponent(DefInterfaceComponent::class.java) + val DI: DefInterfaceComponent = TODO() //When val keyboard1 = DI.factory().keyboard() @@ -33,7 +32,8 @@ class DefInterfaceTest { @Test fun provideMonitorTest() { //Given - val DI = Stone.createComponent(DefInterfaceComponent::class.java) + val DI: DefInterfaceComponent = TODO() + //When val monitor = DI.factory().monitor(MonitorSize("2")) @@ -47,7 +47,7 @@ class DefInterfaceTest { @Test fun provideMouseTest() { //Given - val DI = Stone.createComponent(DefInterfaceComponent::class.java) + val DI: DefInterfaceComponent = TODO() //When val mouse1 = DI.factory().mouse() diff --git a/tests_kotlin/src/test/kotlin/com/github/klee0kai/tests/kotlin_models/identifiers/MonitorFactoryWrappersTests.kt b/tests_kotlin/src/test/kotlin/com/github/klee0kai/tests/kotlin_models/identifiers/MonitorFactoryWrappersTests.kt index ffc54609..1dea6ad1 100644 --- a/tests_kotlin/src/test/kotlin/com/github/klee0kai/tests/kotlin_models/identifiers/MonitorFactoryWrappersTests.kt +++ b/tests_kotlin/src/test/kotlin/com/github/klee0kai/tests/kotlin_models/identifiers/MonitorFactoryWrappersTests.kt @@ -1,8 +1,5 @@ package com.github.klee0kai.tests.kotlin_models.identifiers -import com.github.klee0kai.stone.Stone -import com.github.klee0kai.stone.type.wrappers.getValue -import com.github.klee0kai.stone.weakref.Ref import com.github.klee0kai.test_kotlin.di.compfactory.CompFactoryComponent import com.github.klee0kai.test_kotlin.tech.components.Monitor import org.junit.jupiter.api.Assertions.* @@ -14,15 +11,15 @@ class MonitorFactoryWrappersTests { @Test fun lazyProvideTest() { //Given - val DI = Stone.createComponent(CompFactoryComponent::class.java) + val DI: CompFactoryComponent = TODO() //When - val monitor: Ref = DI.monitorLazy() + val monitor = DI.monitorLazy() //Then assertEquals( - monitor.get().uuid, - monitor.get().uuid + monitor.get()!!.uuid, + monitor.get()!!.uuid ) } @@ -30,7 +27,7 @@ class MonitorFactoryWrappersTests { @Test fun softRefProvideTest() { //Given - val DI = Stone.createComponent(CompFactoryComponent::class.java) + val DI: CompFactoryComponent = TODO() //When val monitor: Reference = DI.monitorSoft() @@ -42,7 +39,7 @@ class MonitorFactoryWrappersTests { @Test fun weakRefProvideTest() { //Given - val DI = Stone.createComponent(CompFactoryComponent::class.java) + val DI: CompFactoryComponent = TODO() //When val monitor: Reference = DI.monitorWeak() @@ -54,37 +51,37 @@ class MonitorFactoryWrappersTests { @Test fun phantom1ProvideTest() { //Given - val DI = Stone.createComponent(CompFactoryComponent::class.java) + val DI: CompFactoryComponent = TODO() //When - val monitor: Ref = DI.monitorPhantomProvide() + val monitor = DI.monitorPhantomProvide() //Then assertNotEquals( - monitor.get().uuid, - monitor.get().uuid + monitor.get()!!.uuid, + monitor.get()!!.uuid ) } @Test fun phantomProvideTest() { //Given - val DI = Stone.createComponent(CompFactoryComponent::class.java) + val DI: CompFactoryComponent = TODO() //When - val monitor: Ref = DI.monitorPhantomProvide() + val monitor = DI.monitorPhantomProvide() //Then assertNotEquals( - monitor.get().uuid, - monitor.get().uuid + monitor.get()!!.uuid, + monitor.get()!!.uuid ) } @Test fun phantom3ProvideTest() { //Given - val DI = Stone.createComponent(CompFactoryComponent::class.java) + val DI: CompFactoryComponent = TODO() //When val monitor = DI.monitorProviderIRef() @@ -100,7 +97,7 @@ class MonitorFactoryWrappersTests { @Test fun kotlinLazyProvideTest() { //Given - val DI = Stone.createComponent(CompFactoryComponent::class.java) + val DI: CompFactoryComponent = TODO() //When val monitor = DI.monitorLazyDelegate() @@ -113,19 +110,18 @@ class MonitorFactoryWrappersTests { } - @Test fun lazyDelegateTest() { //Given - val DI = Stone.createComponent(CompFactoryComponent::class.java) + val DI: CompFactoryComponent = TODO() //When - val monitor by DI.monitorLazy() + val monitor = DI.monitorLazy() //Then assertEquals( - monitor.uuid, - monitor.uuid + monitor.get()!!.uuid, + monitor.get()!!.uuid ) } @@ -133,69 +129,69 @@ class MonitorFactoryWrappersTests { @Test fun softRefDelegateTest() { //Given - val DI = Stone.createComponent(CompFactoryComponent::class.java) + val DI: CompFactoryComponent = TODO() //When - val monitor by DI.monitorSoft() + val monitor = DI.monitorSoft() //Then - assertNotNull(monitor) + assertNotNull(monitor.get()) } @Test fun weakRefDelegateTest() { //Given - val DI = Stone.createComponent(CompFactoryComponent::class.java) + val DI: CompFactoryComponent = TODO() //When - val monitor by DI.monitorWeak() + val monitor = DI.monitorWeak() //Then - assertNotNull(monitor) + assertNotNull(monitor.get()) } @Test fun phantom1DelegateTest() { //Given - val DI = Stone.createComponent(CompFactoryComponent::class.java) + val DI: CompFactoryComponent = TODO() //When - val monitor by DI.monitorPhantomProvide() + val monitor = DI.monitorPhantomProvide() //Then assertNotEquals( - monitor.uuid, - monitor.uuid + monitor.get()!!.uuid, + monitor.get()!!.uuid ) } @Test fun phantom2DelegateTest() { //Given - val DI = Stone.createComponent(CompFactoryComponent::class.java) + val DI: CompFactoryComponent = TODO() //When - val monitor by DI.monitorPhantomProvide() + val monitor = DI.monitorPhantomProvide() //Then assertNotEquals( - monitor.uuid, - monitor.uuid + monitor.get()!!.uuid, + monitor.get()!!.uuid ) } @Test fun phantom3DelegateTest() { //Given - val DI = Stone.createComponent(CompFactoryComponent::class.java) + val DI: CompFactoryComponent = TODO() //When - val monitor by DI.monitorProviderIRef() + val monitor = DI.monitorProviderIRef() //Then assertNotEquals( - monitor.uuid, - monitor.uuid + monitor.get()!!.uuid, + monitor.get()!!.uuid ) } @@ -203,7 +199,7 @@ class MonitorFactoryWrappersTests { @Test fun kotlinLazyDelegateTest() { //Given - val DI = Stone.createComponent(CompFactoryComponent::class.java) + val DI: CompFactoryComponent = TODO() //When val monitor by DI.monitorLazyDelegate() @@ -216,8 +212,6 @@ class MonitorFactoryWrappersTests { } - - } diff --git a/tests_kotlin/src/test/kotlin/com/github/klee0kai/tests/kotlin_models/inject/GorillaInjectTests.kt b/tests_kotlin/src/test/kotlin/com/github/klee0kai/tests/kotlin_models/inject/GorillaInjectTests.kt index cf864513..b3dffade 100644 --- a/tests_kotlin/src/test/kotlin/com/github/klee0kai/tests/kotlin_models/inject/GorillaInjectTests.kt +++ b/tests_kotlin/src/test/kotlin/com/github/klee0kai/tests/kotlin_models/inject/GorillaInjectTests.kt @@ -1,6 +1,5 @@ package com.github.klee0kai.tests.kotlin_models.inject -import com.github.klee0kai.stone.Stone import com.github.klee0kai.test_kotlin.di.base_forest.RainForestComponent import com.github.klee0kai.test_kotlin.mowgli.animal.Cougar import com.github.klee0kai.test_kotlin.mowgli.animal.Gorilla @@ -12,7 +11,7 @@ class GorillaInjectTests { @Test fun gorillaBornTest() { //Given - val DI = Stone.createComponent(RainForestComponent::class.java) + val DI: RainForestComponent = TODO() val gorilla = Gorilla() @@ -28,7 +27,8 @@ class GorillaInjectTests { @Test fun oneBloodTest() { //Given - val DI = Stone.createComponent(RainForestComponent::class.java) + val DI: RainForestComponent = TODO() + val gorilla = Gorilla() val cougar = Cougar() @@ -48,7 +48,7 @@ class GorillaInjectTests { @Test fun personalityTest() { //Given - val DI = Stone.createComponent(RainForestComponent::class.java) + val DI: RainForestComponent = TODO() val gorilla = Gorilla() val cougar = Cougar() diff --git a/tests_kotlin/src/test/kotlin/com/github/klee0kai/tests/kotlin_models/inject/GorillaInjectWrappersTests.kt b/tests_kotlin/src/test/kotlin/com/github/klee0kai/tests/kotlin_models/inject/GorillaInjectWrappersTests.kt index 41656089..ca3026ad 100644 --- a/tests_kotlin/src/test/kotlin/com/github/klee0kai/tests/kotlin_models/inject/GorillaInjectWrappersTests.kt +++ b/tests_kotlin/src/test/kotlin/com/github/klee0kai/tests/kotlin_models/inject/GorillaInjectWrappersTests.kt @@ -1,6 +1,5 @@ package com.github.klee0kai.tests.kotlin_models.inject -import com.github.klee0kai.stone.Stone import com.github.klee0kai.test_kotlin.di.base_forest.RainForestComponent import com.github.klee0kai.test_kotlin.mowgli.animal.Gorilla import org.junit.jupiter.api.Assertions.* @@ -11,7 +10,7 @@ class GorillaInjectWrappersTests { @Test fun supportWrappersTest() { //Given - val DI = Stone.createComponent(RainForestComponent::class.java) + val DI: RainForestComponent = TODO() val gorilla = Gorilla() //When @@ -31,7 +30,8 @@ class GorillaInjectWrappersTests { @Test fun refWrapperTest() { //Given - val DI = Stone.createComponent(RainForestComponent::class.java) + val DI: RainForestComponent = TODO() + val gorilla = Gorilla() //When @@ -56,7 +56,7 @@ class GorillaInjectWrappersTests { @Test fun genWrapperTest() { //Given - val DI = Stone.createComponent(RainForestComponent::class.java) + val DI: RainForestComponent = TODO() var gorilla = Gorilla() //When @@ -64,8 +64,8 @@ class GorillaInjectWrappersTests { //Then assertNotEquals( - gorilla.knowledgePhantomProvide!!.get().uuid, - gorilla.knowledgePhantomProvide!!.get().uuid + gorilla.knowledgePhantomProvide!!.get()!!.uuid, + gorilla.knowledgePhantomProvide!!.get()!!.uuid ) assertNotEquals( gorilla.knowledgePhantomProvide2!!.get().uuid, diff --git a/tests_kotlin/src/test/kotlin/com/github/klee0kai/tests/kotlin_models/inject/GorillaProtectInjectTests.kt b/tests_kotlin/src/test/kotlin/com/github/klee0kai/tests/kotlin_models/inject/GorillaProtectInjectTests.kt index 59538b92..7f680d81 100644 --- a/tests_kotlin/src/test/kotlin/com/github/klee0kai/tests/kotlin_models/inject/GorillaProtectInjectTests.kt +++ b/tests_kotlin/src/test/kotlin/com/github/klee0kai/tests/kotlin_models/inject/GorillaProtectInjectTests.kt @@ -1,6 +1,5 @@ package com.github.klee0kai.tests.kotlin_models.inject -import com.github.klee0kai.stone.Stone import com.github.klee0kai.test_kotlin.di.base_forest.RainForestComponent import com.github.klee0kai.test_kotlin.mowgli.animal.Gorilla import org.junit.jupiter.api.Assertions.assertNotNull @@ -13,7 +12,7 @@ class GorillaProtectInjectTests { @Test fun withoutProtectInjectTest() { // Given - val DI = Stone.createComponent(RainForestComponent::class.java) + val DI: RainForestComponent = TODO() var gorilla: Gorilla? = Gorilla() @@ -32,7 +31,7 @@ class GorillaProtectInjectTests { @Throws(InterruptedException::class) fun withProtectInjectTest() { // Given - val DI = Stone.createComponent(RainForestComponent::class.java) + val DI: RainForestComponent = TODO() var gorrila: Gorilla? = Gorilla() diff --git a/tests_kotlin/src/test/kotlin/com/github/klee0kai/tests/kotlin_models/inject/GorillaProtectInjectWrappersTests.kt b/tests_kotlin/src/test/kotlin/com/github/klee0kai/tests/kotlin_models/inject/GorillaProtectInjectWrappersTests.kt index 552d3f14..089d09c2 100644 --- a/tests_kotlin/src/test/kotlin/com/github/klee0kai/tests/kotlin_models/inject/GorillaProtectInjectWrappersTests.kt +++ b/tests_kotlin/src/test/kotlin/com/github/klee0kai/tests/kotlin_models/inject/GorillaProtectInjectWrappersTests.kt @@ -1,6 +1,5 @@ package com.github.klee0kai.tests.kotlin_models.inject -import com.github.klee0kai.stone.Stone import com.github.klee0kai.test_kotlin.di.base_forest.RainForestComponent import com.github.klee0kai.test_kotlin.mowgli.University import com.github.klee0kai.test_kotlin.mowgli.animal.Gorilla @@ -14,7 +13,7 @@ class GorillaProtectInjectWrappersTests { @Test fun lazyWrapperProtectTest() { // Given - val DI = Stone.createComponent(RainForestComponent::class.java) + val DI: RainForestComponent = TODO() val university = University() @@ -33,7 +32,7 @@ class GorillaProtectInjectWrappersTests { @Throws(InterruptedException::class) fun withProtectInjectTest() { // Given - val DI = Stone.createComponent(RainForestComponent::class.java) + val DI: RainForestComponent = TODO() var gorilla: Gorilla? = Gorilla() //When diff --git a/tests_kotlin/src/test/kotlin/com/github/klee0kai/tests/kotlin_models/interface_delegates/InterfaceDelegatesTest.kt b/tests_kotlin/src/test/kotlin/com/github/klee0kai/tests/kotlin_models/interface_delegates/InterfaceDelegatesTest.kt index 83d9126e..644461af 100644 --- a/tests_kotlin/src/test/kotlin/com/github/klee0kai/tests/kotlin_models/interface_delegates/InterfaceDelegatesTest.kt +++ b/tests_kotlin/src/test/kotlin/com/github/klee0kai/tests/kotlin_models/interface_delegates/InterfaceDelegatesTest.kt @@ -1,6 +1,5 @@ package com.github.klee0kai.tests.kotlin_models.interface_delegates -import com.github.klee0kai.stone.Stone import com.github.klee0kai.test_kotlin.di.base_comp.identifiers.KConnectType import com.github.klee0kai.test_kotlin.di.base_comp.identifiers.MonitorSize import com.github.klee0kai.test_kotlin.di.interface_delegates.InterfaceDelegatesComponent @@ -12,7 +11,7 @@ class InterfaceDelegatesTest { @Test fun provideKeyboardTest() { //Given - val DI = Stone.createComponent(InterfaceDelegatesComponent::class.java) + val DI: InterfaceDelegatesComponent = TODO() //When val keyboard1 = DI.factory().keyboard() @@ -33,7 +32,7 @@ class InterfaceDelegatesTest { @Test fun provideMonitorTest() { //Given - val DI = Stone.createComponent(InterfaceDelegatesComponent::class.java) + val DI: InterfaceDelegatesComponent = TODO() //When val monitor = DI.factory().monitor(MonitorSize("2")) @@ -47,7 +46,7 @@ class InterfaceDelegatesTest { @Test fun provideMouseTest() { //Given - val DI = Stone.createComponent(InterfaceDelegatesComponent::class.java) + val DI: InterfaceDelegatesComponent = TODO() //When val mouse1 = DI.factory().mouse() From 151ac34de7f5d4b4b5628b5b959d1a5c842bd7fe Mon Sep 17 00:00:00 2001 From: klee0kai Date: Mon, 1 Dec 2025 21:58:03 +0100 Subject: [PATCH 043/122] try to migrate inject method --- .../klee0kai/thekey/stone/ksp/Processor.kt | 4 +- .../ksp/helpers/ComponentDeclarationExt.kt | 33 +- .../stone/ksp/helpers/TypeHelpersExt.kt | 2 +- .../helpers/annotations/ComponentAnnMirror.kt | 1 - .../invokecall/GenArgumentFunctions.kt | 46 +++ .../ksp/helpers/invokecall/InvokeCall.kt | 269 ++++++++++++++ .../helpers/invokecall/InvokeProvideFlags.kt | 14 + .../ksp/helpers/invokecall/ModulesGraph.kt | 341 ++++++++++++++++++ .../ksp/helpers/invokecall/ProvideDep.kt | 12 + .../stone/ksp/ksp/KSClassDeclarationExt.kt | 12 + .../stone/ksp/ksp/KSFunctionDeclarationExt.kt | 2 - .../poet/smartcode/DeclareLocalVariable.kt | 10 + .../stone/ksp/poet/smartcode/SmartCode.kt | 4 +- .../stone/ksp/poet/smartcode/SmartCodeExt.kt | 21 ++ .../target/component/GenComponentProcessor.kt | 49 ++- .../thekey/stone/ksp/utils/LocalFieldName.kt | 6 + .../__hidden__/provide/ProvideBuilder.kt | 23 ++ .../__hidden__/provide/ProvideConsumer.kt | 22 ++ tests_kotlin/build.gradle.kts | 2 +- .../definterface/DefInterfaceTest.kt | 8 +- .../MonitorFactoryWrappersTests.kt | 84 +++-- .../inject/GorillaInjectTests.kt | 8 +- .../inject/GorillaInjectWrappersTests.kt | 12 +- .../inject/GorillaProtectInjectTests.kt | 5 +- .../GorillaProtectInjectWrappersTests.kt | 5 +- .../InterfaceDelegatesTest.kt | 7 +- .../lifecycle/DeskCompRepairTest.kt | 1 - .../lifecycle/GameCompRepairTest.kt | 1 - 28 files changed, 930 insertions(+), 74 deletions(-) create mode 100644 stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/invokecall/GenArgumentFunctions.kt create mode 100644 stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/invokecall/InvokeCall.kt create mode 100644 stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/invokecall/InvokeProvideFlags.kt create mode 100644 stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/invokecall/ModulesGraph.kt create mode 100644 stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/invokecall/ProvideDep.kt create mode 100644 stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/poet/smartcode/DeclareLocalVariable.kt create mode 100644 stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/utils/LocalFieldName.kt create mode 100644 stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/__hidden__/provide/ProvideBuilder.kt create mode 100644 stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/__hidden__/provide/ProvideConsumer.kt diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/Processor.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/Processor.kt index 0534838e..fb3bf72e 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/Processor.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/Processor.kt @@ -60,8 +60,8 @@ class Processor( debugPkgFilter = options["debugPkgFilter"] // force changes - debug = true - debugPkgFilter = "com.github.klee0kai.test_kotlin.di.base_comp" +// debug = true +// debugPkgFilter = "com.github.klee0kai.test_kotlin.di.base_comp" } diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/ComponentDeclarationExt.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/ComponentDeclarationExt.kt index 498e6f8d..6ee50ea3 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/ComponentDeclarationExt.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/ComponentDeclarationExt.kt @@ -3,16 +3,20 @@ package com.github.klee0kai.thekey.stone.ksp.helpers import com.github.klee0kai.stone.annotations.component.* +import com.github.klee0kai.stone.weakref.Named +import com.github.klee0kai.stone.weakref.Qualifier import com.github.klee0kai.thekey.stone.ksp.helpers.annotations.findComponentAnnotation import com.github.klee0kai.thekey.stone.ksp.ksp.isType import com.google.devtools.ksp.KspExperimental import com.google.devtools.ksp.processing.Resolver +import com.google.devtools.ksp.symbol.KSAnnotated import com.google.devtools.ksp.symbol.KSAnnotation import com.google.devtools.ksp.symbol.KSClassDeclaration import com.google.devtools.ksp.symbol.KSFunctionDeclaration import com.google.devtools.ksp.symbol.KSType import com.squareup.kotlinpoet.ClassName import com.squareup.kotlinpoet.asClassName +import com.squareup.kotlinpoet.ksp.toClassName fun Resolver.findComponentForModuleOrDep( moduleCl: ClassName, @@ -44,7 +48,7 @@ val KSClassDeclaration.wrapperProviders: Sequence .flatMap { it.wrapperProviders } } -val KSFunctionDeclaration.scopeAnnotations: Sequence +val KSAnnotated.scopeAnnotations: Sequence get() { val standardScopeAnnotations = listOf( GcAllScope::class, GcWeakScope::class, @@ -57,4 +61,29 @@ val KSFunctionDeclaration.scopeAnnotations: Sequence annotationOfAnnotation.annotationType.resolve().declaration.isType(GcScopeAnnotation::class) } } - } \ No newline at end of file + } + +val KSAnnotated.qualifierAnnotations: Sequence + get() { + val standardQualifierAnnotations = listOf( + Named::class + ) + + return annotations.filter { funAnnotation -> + standardQualifierAnnotations.any { funAnnotation.annotationType.resolve().declaration.isType(it) } + || funAnnotation.annotationType.resolve().annotations.any { annotationOfAnnotation -> + annotationOfAnnotation.annotationType.resolve().declaration.isType(Qualifier::class) + } + } + } + + +fun KSAnnotation.isSameAsQualifier( + ann: KSAnnotation +): Boolean { + if (annotationType.resolve().toClassName() != ann.annotationType.resolve().toClassName()) return false + val annArguments1 = arguments.map { it.name?.asString() to it.value }.sortedBy { it.first } + val annArguments2 = ann.arguments.map { it.name?.asString() to it.value }.sortedBy { it.first } + return annArguments1 == annArguments2 +} + diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/TypeHelpersExt.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/TypeHelpersExt.kt index 7a5f79d4..f2a2b5a4 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/TypeHelpersExt.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/TypeHelpersExt.kt @@ -3,6 +3,7 @@ package com.github.klee0kai.thekey.stone.ksp.helpers import com.github.klee0kai.thekey.stone.ksp.ksp.isAnyType import com.google.devtools.ksp.symbol.KSClassDeclaration import com.google.devtools.ksp.symbol.KSType +import com.squareup.kotlinpoet.ClassName import com.squareup.kotlinpoet.ParameterizedTypeName.Companion.parameterizedBy import com.squareup.kotlinpoet.TypeName import com.squareup.kotlinpoet.asClassName @@ -27,7 +28,6 @@ fun KSType.isListType( ?.any { it.resolve().isListType() } == true } - fun KSType.noWrappedType( wrappedTypes: List, ): KSType { diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/annotations/ComponentAnnMirror.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/annotations/ComponentAnnMirror.kt index ff736429..f1183fbf 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/annotations/ComponentAnnMirror.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/annotations/ComponentAnnMirror.kt @@ -13,7 +13,6 @@ class ComponentAnnMirror( val wrapperProviders: List, ) - fun KSAnnotated.annotations( className: ClassName, ): Sequence = annotations diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/invokecall/GenArgumentFunctions.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/invokecall/GenArgumentFunctions.kt new file mode 100644 index 00000000..216a59e4 --- /dev/null +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/invokecall/GenArgumentFunctions.kt @@ -0,0 +1,46 @@ +package com.github.klee0kai.thekey.stone.ksp.helpers.invokecall + +import com.google.devtools.ksp.symbol.KSValueParameter +import com.squareup.kotlinpoet.CodeBlock +import com.squareup.kotlinpoet.TypeName + +object GenArgumentFunctions { + /** + * Simple unwrap argument from wrapped type (WeakReference and other). + * If you have arguments like

+ * `Provide someVariable;`

+ * unwrapArgument support to unwrap SomeClass type on invoke method, like

+ * `doSmth(someVariable.provide()) ` + * + * @param envFields available fields + * @return unwrapped field get code, or null + */ + fun unwrapArgument( + envFields: List, + ): (TypeName) -> CodeBlock { + envFields.map { + it.type.resolve().arguments + + + } + TODO() +// val provideFields: MutableList> = ListUtils.format(envFields, { it -> +// if (it.type is ParameterizedTypeName) { +// val type: ParameterizedTypeName = it.type as ParameterizedTypeName +// val orType: TypeName? = type.typeArguments.get(type.typeArguments.size() - 1) +// if (type.rawType == ClassName.get(PhantomProvide::class.java)) return@format Pair( +// orType, +// it.name + ".get()" +// ) +// } +// Pair(it.type, it.name) +// }) +// +// return Function { wannaType: TypeName? -> +// for (provideField in provideFields) { +// if (wannaType == provideField.first) return@Function CodeBlock.of(provideField.second) +// } +// null +// } + } +} diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/invokecall/InvokeCall.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/invokecall/InvokeCall.kt new file mode 100644 index 00000000..64e4f455 --- /dev/null +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/invokecall/InvokeCall.kt @@ -0,0 +1,269 @@ +package com.github.klee0kai.thekey.stone.ksp.helpers.invokecall + +import com.github.klee0kai.thekey.stone.ksp.helpers.invokecall.GenArgumentFunctions.unwrapArgument +import com.github.klee0kai.thekey.stone.ksp.helpers.qualifierAnnotations +import com.github.klee0kai.thekey.stone.ksp.helpers.wrap.ClassNameUtils +import com.github.klee0kai.thekey.stone.ksp.poet.smartcode.SmartCode +import com.github.klee0kai.thekey.stone.ksp.poet.smartcode.smartCode +import com.google.devtools.ksp.symbol.KSAnnotation +import com.google.devtools.ksp.symbol.KSFunctionDeclaration +import com.google.devtools.ksp.symbol.KSValueParameter +import com.squareup.kotlinpoet.CodeBlock +import com.squareup.kotlinpoet.TypeName +import com.squareup.kotlinpoet.ksp.toClassName +import java.util.* + +/** + * Invoke sequence or call sequence. + * Like someMethod1(arg1,arg2).someMethod2(arg3).someMethod3() + * + * + * Describe method names and using arguments for code generation. + * Arguments for chaining are reused by type. + */ +class InvokeCall( + val invokeSequenceVariants: List>, + val flags: InvokeProvideFlags = InvokeProvideFlags(), +) { + + /** + * Create new invoke sequence + * + * @param callSequence ordered methods in invoke sequence + */ + constructor( + vararg callSequence: KSFunctionDeclaration, + flags: InvokeProvideFlags = InvokeProvideFlags() + ) : this( + invokeSequenceVariants = listOf(callSequence.toList()), + flags = flags, + ) + + /** + * Merge variants. All should return same type + * + * @param variants all variants from best to worse + */ + constructor(variants: MutableCollection) : this( + invokeSequenceVariants = variants.flatMap { it.invokeSequenceVariants }, + flags = variants.fold(InvokeProvideFlags()) { acc, value -> acc.merge(value.flags) } + ) + + fun bestSequence(): List = invokeSequenceVariants[0] + + + fun qualifierAnnotations( + crossing: Boolean, + ): Set { + val allQualifiersLists = LinkedList>() + for (variant in invokeSequenceVariants) { + val qualifiers = HashSet() + for (m in variant) qualifiers.addAll(m.qualifierAnnotations) + allQualifiersLists.add(qualifiers) + } + if (allQualifiersLists.isEmpty()) return mutableSetOf() + + val allQualifiers = allQualifiersLists[0] + if (crossing) { + for (q in allQualifiersLists) allQualifiers.retainAll(q) + } else { + for (q in allQualifiersLists) allQualifiers.addAll(q) + } + return allQualifiers + } + + /** + * Using arguments in invoke sequence + * + * @return collection of all argument's types + */ + fun argDeps(): Set { + val argsTypes = HashSet() + for (invokeSequence in invokeSequenceVariants) { + for (m in invokeSequence) { + argsTypes.addAll( + m.parameters.map { + ProvideDep( + type = it.type.resolve(), + qualifiers = m.qualifierAnnotations.toList(), + ) + }) + } + } + return argsTypes + } + + /** + * Providing type in this invoke sequence + * + * @return return type + */ + fun resultType(): TypeName { + return ClassNameUtils.rawTypeOf(rawReturnType()) + } + + fun rawReturnType(): TypeName { + val invokeSequence = bestSequence() + return invokeSequence[invokeSequence.size - 1].returnType?.resolve()!!.toClassName() + } + + /** + * Generate invoke code bloke + * + * @param envFields predefined arguments in generated code + * @param argGen argument generator, if non found in envFields + * @return new code block without semicolon + */ + fun invokeCode( + envFields: List, + vararg argGen: (TypeName) -> CodeBlock, + ): CodeBlock { + val argGens = LinkedList<(TypeName) -> CodeBlock>() + argGens.add(unwrapArgument(envFields)) + argGens.addAll(argGen) + + val invokeBuilder = CodeBlock.builder() + var invokeCount = 0 + for (m in bestSequence()) { + var argCount = 0 + val argsCodeBuilder: CodeBlock.Builder = CodeBlock.builder() + for (arg in m.parameters) { + if (argCount++ > 0) argsCodeBuilder.add(",") + val argCode = argGens.firstNotNullOf { it.invoke(arg.type.resolve().toClassName()) } + argsCodeBuilder.add(argCode) + } + + if (invokeCount++ > 0) invokeBuilder.add(".") + invokeBuilder.add("%L(%L)", m.simpleName.asString(), argsCodeBuilder.build()) + } + return invokeBuilder.build() + } + + fun invokeBest(): SmartCode = smartCode { + providingType.value = resultType() +// TODO transform(invokeSequence(bestSequence()), resultType()) + } + +// return SmartCode +// .builder() +// .providingType(resultType()) +// .withLocals({ builder -}) +// } + + fun invokeAllToList() = smartCode { +// TODO +// val provType: TypeName? = ParameterizedTypeName.get(ClassName.get(MutableList::class.java), resultType()) +// return SmartCode +// .builder() +// .providingType(provType) +// .withLocals({ builder -> +// val listFieldName: String? = genLocalFieldName() +// builder.add( +// CodeBlock.of( +// "new \$T( ( \$L ) -> { \n", +// ParameterizedTypeName.get(ClassName.get(ProvideBuilder::class.java), resultType()), +// listFieldName +// ) +// ) +// for (sequence in invokeSequenceVariants) { +// val seqCode: SmartCode = invokeSequence(sequence) +// if (WrapHelper.isList(seqCode.providingType)) { +// builder.add(listFieldName) +// .add(".addAll(") +// .add(transform(seqCode, provType)) +// .add(");\n") +// } else { +// builder.add(listFieldName) +// .add(".add(") +// .add(transform(seqCode, resultType())) +// .add(");\n") +// } +// } +// builder.add(" }).all() ") +// builder +// }) + } + + + private fun invokeSequence( + sequence: List, + ): SmartCode { + TODO() +// return SmartCode.builder().withLocals({ builder -> +// var invokeCount = 0 +// for (m in sequence) { +// if (invokeCount++ > 0) builder.add(".") +// builder.add(m.methodName) +// .add("(") +// +// var argCount = 0 +// for (arg in m.args) { +// if (argCount++ > 0) builder.add(", ") +// val isList: Boolean = isList(arg.type) +// val typeFields: MutableList? = ListUtils.filter( +// builder.getDeclaredFields(), +// { i, f -> nonWrappedType(f.type) == nonWrappedType(arg.type) }) +// +// var field: FieldDetail? = if (isList) ListUtils.first( +// typeFields, +// { i, f -> isList(f.type) && f.qualifierAnns == arg.qualifierAnns } +// ) else null +// if (field == null) { +// //non list +// field = ListUtils.first(typeFields, { i, f -> f.qualifierAnns == arg.qualifierAnns }) +// } +// +// if (field == null) { +// builder.add("null", null) +// } else { +// // unwrap type +// builder.add( +// transform( +// SmartCode.of(field.name, mutableSetOf(field.name)) +// .providingType(field.type), +// arg.type +// ) +// ) +// } +// } +// +// builder.add(")") +// } +// builder +// }) +// .providingType(sequence.get(sequence.size - 1).returnType) + } + + override fun toString(): String { + val builder = StringBuilder() + if (invokeSequenceVariants.size <= 1) for (qualifierAnn in qualifierAnnotations(false)) { + builder.append(qualifierAnn.toString()) + .append(" ") + } + var variantIndx = 0 + for (variant in invokeSequenceVariants) { + if (variantIndx++ > 0) builder.append(";\n") + var secIndx = 0 + for (m in variant) { + if (secIndx++ > 0) builder.append(".") + builder.append(m.simpleName.asString()) + .append("(") + .append(m.parameters.joinToString(", ") { it.type.resolve().toClassName().simpleName }) + .append(")") + } + } + return builder.toString() + } + + + override fun equals(o: Any?): Boolean { + if (this === o) return true + if (o == null || javaClass != o.javaClass) return false + val that = o as InvokeCall + return invokeSequenceVariants == that.invokeSequenceVariants + } + + override fun hashCode(): Int { + return Objects.hash(invokeSequenceVariants) + } +} diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/invokecall/InvokeProvideFlags.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/invokecall/InvokeProvideFlags.kt new file mode 100644 index 00000000..ce9eefd2 --- /dev/null +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/invokecall/InvokeProvideFlags.kt @@ -0,0 +1,14 @@ +package com.github.klee0kai.thekey.stone.ksp.helpers.invokecall + +data class InvokeProvideFlags( + val provideObjectCached: Boolean = false, + val provideBindInstance: Boolean = false, +) + + +fun InvokeProvideFlags.merge( + invokeProvideFlags: InvokeProvideFlags, +) = InvokeProvideFlags( + provideObjectCached = provideObjectCached || invokeProvideFlags.provideObjectCached, + provideBindInstance = provideBindInstance || invokeProvideFlags.provideBindInstance, +) diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/invokecall/ModulesGraph.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/invokecall/ModulesGraph.kt new file mode 100644 index 00000000..84f58efd --- /dev/null +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/invokecall/ModulesGraph.kt @@ -0,0 +1,341 @@ +package com.github.klee0kai.thekey.stone.ksp.helpers.invokecall + +import com.github.klee0kai.stone.__hidden__.provide.ProvideBuilder +import com.github.klee0kai.thekey.stone.ksp.helpers.isListType +import com.github.klee0kai.thekey.stone.ksp.helpers.wrap.WrapHelper +import com.github.klee0kai.thekey.stone.ksp.poet.smartcode.add +import com.github.klee0kai.thekey.stone.ksp.poet.smartcode.declareLocalVariable +import com.github.klee0kai.thekey.stone.ksp.poet.smartcode.smartCode +import com.github.klee0kai.thekey.stone.ksp.utils.LocalFieldName.genLocalFieldName +import com.google.devtools.ksp.symbol.KSAnnotation +import com.google.devtools.ksp.symbol.KSType +import com.squareup.kotlinpoet.ParameterizedTypeName.Companion.parameterizedBy +import com.squareup.kotlinpoet.TypeName +import com.squareup.kotlinpoet.asClassName +import com.squareup.kotlinpoet.ksp.toClassName + +class ModulesGraph { + private val provideTypeCodes = HashMap>() + private val cacheControlTypeCodes = HashMap>() + private val wrapHelper = WrapHelper() + + /** + * Methods graph build. + * + * @param provideModuleMethod module's provide method + * @param module module's class + */ + fun collectFromModule( +// provideModuleMethod: MethodDetail?, +// module: ClassDetail, + ) { +// val iModuleInterface: ClassDetail = AnnotationProcessor.allClassesHelper.iModule +// for (m in module.getAllMethods(false, true, "")) { +// val provTypeName: TypeName = nonWrappedType(m.returnType) +// if (provTypeName.isPrimitive() || provTypeName === TypeName.VOID) continue +// if (iModuleInterface.findMethod(m, false) != null) continue +// val isCached = +// !m.hasAnnotations(ProvideAnn::class.java) || m.ann(ProvideAnn::class.java).isCachingProvideType() +// val isBindInstance: Boolean = m.hasAnnotations(BindInstanceAnn::class.java) +// var invokeProvideFlags = if (isCached) INVOKE_PROVIDE_OBJECT_CACHED else 0 +// invokeProvideFlags = invokeProvideFlags or if (isBindInstance) INVOKE_PROVIDE_BIND_INSTANCE else 0 +// +// provideTypeCodes.putIfAbsent(provTypeName, HashSet()) +// provideTypeCodes.get(provTypeName)!!.add(InvokeCall(invokeProvideFlags, provideModuleMethod, m)) +// +// val cacheControlMethod: MethodDetail = MethodDetail() +// cacheControlMethod.methodName = cacheControlMethodName(m.methodName) +// cacheControlMethod.args.add(FieldDetail.simple("__action", ClassName.get(CacheAction::class.java))) +// for (it in m.args) { +// if (!((it.type is ClassName) && allClassesHelper.allIdentifiers.contains(it.type))) continue +// cacheControlMethod.args.add(it) +// } +// cacheControlMethod.returnType = listWrapTypeIfNeed(m.returnType) +// cacheControlMethod.qualifierAnns = m.qualifierAnns +// +// cacheControlTypeCodes.putIfAbsent(provTypeName, HashSet()) +// cacheControlTypeCodes.get(provTypeName)!!.add(InvokeCall(provideModuleMethod, cacheControlMethod)) +// } + } + + fun codeProvideType( + methodName: String, + returnType: KSType, + qualifierAnns: List = emptyList(), + ) = smartCode { + val isWrappedReturn = wrapHelper.isSupport(returnType.toClassName()) + val isListReturn = returnType.isListType() + val providingType = if (isWrappedReturn) { + wrapHelper.nonWrappedType(returnType.toClassName()) + } else { + returnType.toClassName() + } + this.providingType.value = providingType + + val provideTypeInvokes = provideInvokesWithDeps(ProvideDep(methodName, returnType, qualifierAnns)) + if (provideTypeInvokes.isEmpty()) { + // TODO throw error + return@smartCode + } + + if (SIMPLE_PROVIDE_OPTIMIZING && provideTypeInvokes.size == 1 && !isListReturn) { + val invokeCall = provideTypeInvokes.first() + add( + wrapHelper.transform( + code = smartCode { + add(invokeCall.invokeBest()) + this.providingType.value = invokeCall.resultType() + }, + wannaType = returnType.toClassName(), + ) + ) + return@smartCode + } + + + val provideBuilder = ProvideBuilder::class.asClassName().parameterizedBy(providingType) + val provideBuilderList = Collection::class.asClassName().parameterizedBy(providingType) + val listFieldName = genLocalFieldName() + add("%T( ( %L ) -> { \n", provideBuilder, listFieldName) + + + for (inv in provideTypeInvokes) { + val depFieldName = genLocalFieldName() +// val isCacheProvide = (inv.flags and INVOKE_PROVIDE_OBJECT_CACHED) !== 0 +// val singleDepField: FieldDetail = FieldDetail.simple(genLocalFieldName(), null) +// val listDepField: FieldDetail = FieldDetail.simple(genLocalFieldName(), null) +// val isListInv = inv.invokeSequenceVariants.size() > 1 + + add { + if (inv.flags.provideObjectCached) { +// declareLocalVariable() + } else { + + } + + + } + +// +// builder.withLocals({ localBuilder -> +// // provide single objects +// if (isCacheProvide) { +// localBuilder.localVariable(singleDepField.name, inv.qualifierAnnotations(true), inv.invokeBest()) +// singleDepField.type = inv.resultType() +// } else { +// singleDepField.type = ParameterizedTypeName.get(ClassName.get(Ref::class.java), inv.resultType()) +// localBuilder.localVariable( +// singleDepField.name, inv.qualifierAnnotations(true), SmartCode.builder() +// .add("() -> ") +// .add(inv.invokeBest()) +// .providingType(singleDepField.type) +// ) +// } +// localBuilder +// }) +// +// builder.withLocals({ localBuilder -> +// // provide list objects +// listDepField.type = ParameterizedTypeName.get( +// ClassName.get(Ref::class.java), +// ParameterizedTypeName.get( +// ClassName.get(MutableList::class.java), +// inv.resultType() +// ) +// ) +// localBuilder.localVariable( +// listDepField.name, inv.qualifierAnnotations(true), SmartCode.builder() +// .add("() -> ") +// .add(inv.invokeAllToList()) +// .providingType(listDepField.type) +// ) +// localBuilder +// }) +// +// if (inv.resultType() == providingType) { +// builder.withLocals({ localBuilder -> +// if (isListReturn) { +// localBuilder +// .add(listFieldName) +// .add(".addAll( ") +// .add( +// transform( +// SmartCode.of( +// listDepField.name, +// mutableSetOf(listDepField.name) +// ) +// .providingType(listDepField.type), +// provideBuilderList +// ) +// ).add(");\n") +// } else { +// localBuilder +// .add(listFieldName) +// .add(".add( ") +// .add( +// transform( +// SmartCode.of( +// singleDepField.name, +// mutableSetOf(singleDepField.name) +// ) +// .providingType(singleDepField.type), +// providingType +// ) +// ).add(");\n") +// } +// localBuilder +// }) +// if (!isListReturn) break +// } + } +// +// +// builder.add("\n })") +// if (WrapHelper.isList(returnType)) { +// builder.add(".all() ") +// .providingType( +// ParameterizedTypeName.get( +// ClassName.get(MutableList::class.java), +// providingType +// ) +// ) +// } else { +// builder.add(".first() ") +// .providingType(providingType) +// } +// return WrapHelper.transform(builder, returnType) + } + + + fun provideInvokesWithDeps( + provideDep: ProvideDep, + ): List { + TODO() +// var provideTypeInvokes: LinkedList = LinkedList() +// var needProvideDeps: LinkedList = LinkedList() +// val needProvideDepsRecursiveDetector: RecursiveDetector = RecursiveDetector() +// needProvideDeps.add(provideDep) +// var loopCount = 0 +// +// // provide dependencies while not provide all +// while (!needProvideDeps.isEmpty()) { +// val rawDep: ProvideDep = needProvideDeps.pollFirst() +// val dep: TypeName = nonWrappedType(rawDep.typeName) +// val invokeCall: InvokeCall? = provideTypeInvokeCall( +// provideTypeCodes, +// dep, +// rawDep.qualifierAnns, +// rawDep.methodName, +// isList(rawDep.typeName) +// ) +// if (invokeCall == null) { +// if (provideDep == rawDep) { +// return null +// } +// +// throw ObjectNotProvidedException( +// createErrorMes() +// .errorProvideType(dep.toString()) +// .build() +// ) +// } +// +// val isBindInstanceInvoke = (invokeCall.flags and INVOKE_PROVIDE_BIND_INSTANCE) !== 0 +// val newDeps: MutableList = ListUtils.filter(invokeCall.argDeps(), { i, it -> +// if (isBindInstanceInvoke && rawDep.typeName == it.typeName) { +// // bind instance case. Argument and return type are equals +// return@filter false +// } +// // qualifies not need to provide +// val argNonWrapped: TypeName? = nonWrappedType(it.typeName) +// argNonWrapped is ClassName && !allClassesHelper.allIdentifiers.contains(argNonWrapped) +// }) +// +// needProvideDeps.addAll(newDeps) +// needProvideDeps = ListUtils.removeDoublesRight(needProvideDeps, Objects::equals) +// val recursiveDetected = +// !newDeps.isEmpty() && needProvideDepsRecursiveDetector.next(needProvideDeps.hashCode()) +// if (recursiveDetected) { +// throw RecursiveProviding( +// createErrorMes() +// .errorProvideType(provideDep.typeName.toString()) +// .recursiveProviding() +// .build() +// ) +// } +// if (loopCount++ > MAX_PROVIDE_RESOLVE_COUNT) { +// throw StoneException( +// createErrorMes() +// .errorProvideType(provideDep.typeName.toString()) +// .add("long providing loop for type. Stone library Error.") +// .build(), +// null +// ) +// } +// +// provideTypeInvokes.add(invokeCall) +// provideTypeInvokes = ListUtils.removeDoublesRight(provideTypeInvokes, { it1, it2 -> +// it1.resultType() == it2.resultType() +// && it1.qualifierAnnotations(true) == it2.qualifierAnnotations(true) +// }) +// } +// Collections.reverse(provideTypeInvokes) +// return provideTypeInvokes + } + + /** + * Generate cache control method invoke. Clean refs, change ref type and other + * + * @param provideMethodName predefined method name + * @param typeName the name of the type whose cache needs to be changed + * @return cache control invoke call + */ + fun invokeControlCacheForType( + provideMethodName: String?, + typeName: TypeName, + qualifierAnns: Set + ): InvokeCall? { + TODO() +// val cacheControlMethodName: String? = cacheControlMethodName(provideMethodName) +// return provideTypeInvokeCall(cacheControlTypeCodes, typeName, qualifierAnns, cacheControlMethodName, false) + } + + private fun provideTypeInvokeCall( + provideTypeCodes: Map>, + typeName: TypeName, + qualifierAnns: Set, + provideMethodName: String?, + listVariants: Boolean + ): InvokeCall? { + TODO() +// val invokeCalls: MutableSet? = provideTypeCodes.getOrDefault(typeName, null) +// if (invokeCalls == null || invokeCalls.isEmpty()) return null +// var filtered: MutableList = +// if (!listVariants || qualifierAnns != null && !qualifierAnns.isEmpty()) +// ListUtils.filter(invokeCalls, { i, it -> it.qualifierAnnotations(false) == qualifierAnns }) +// else +// LinkedList(invokeCalls) +// +// filtered = if (provideMethodName != null) ListUtils.filter(filtered, { i, it -> +// val len: Int = it.bestSequence().size() +// val mName: String? = it.bestSequence().get(len - 1).methodName +// provideMethodName == mName +// }) else filtered +// +// if (!listVariants && filtered.size > 1) { +// throw IncorrectSignatureException( +// createErrorMes() +// .errorProvideType(typeName.toString()) +// .add(": is bound multi times.\n") +// .add(java.lang.String.join(" and \n", ListUtils.format(filtered, InvokeCall::toString))) +// .build() +// ) +// } +// return if (!filtered.isEmpty()) InvokeCall(filtered) else null + } + + companion object { + var SIMPLE_PROVIDE_OPTIMIZING: Boolean = true + var MAX_PROVIDE_RESOLVE_COUNT: Int = 10000 + } +} diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/invokecall/ProvideDep.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/invokecall/ProvideDep.kt new file mode 100644 index 00000000..c77eacc4 --- /dev/null +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/invokecall/ProvideDep.kt @@ -0,0 +1,12 @@ +package com.github.klee0kai.thekey.stone.ksp.helpers.invokecall + +import com.google.devtools.ksp.symbol.KSAnnotation +import com.google.devtools.ksp.symbol.KSType + + +data class ProvideDep( + val methodName: String, + val type: KSType, + val qualifiers: List, +) + diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/ksp/KSClassDeclarationExt.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/ksp/KSClassDeclarationExt.kt index 987db3dc..e999e1d0 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/ksp/KSClassDeclarationExt.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/ksp/KSClassDeclarationExt.kt @@ -8,6 +8,7 @@ import com.google.devtools.ksp.symbol.KSDeclaration import com.google.devtools.ksp.symbol.KSFunctionDeclaration import com.google.devtools.ksp.symbol.KSType import com.squareup.kotlinpoet.ClassName +import com.squareup.kotlinpoet.ksp.toClassName import kotlin.reflect.KClass fun KSClassDeclaration.findConstructor( @@ -64,6 +65,17 @@ fun KSClassDeclaration.getAllMethods( } +fun KSClassDeclaration.isChildOf( + parentType: ClassName, +): Boolean { + if (toClassName() == parentType) return true + superTypes.forEach { type -> + if (type.resolve().toClassName() == type) return true + if ((type.resolve().declaration as? KSClassDeclaration)?.isChildOf(parentType) == true) return true + } + return false +} + val KSType.isUnit: Boolean get() = declaration.qualifiedName?.asString() == "kotlin.Unit" val KSType.isNotPrimitive: Boolean diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/ksp/KSFunctionDeclarationExt.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/ksp/KSFunctionDeclarationExt.kt index d3c51d4b..a9bc744b 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/ksp/KSFunctionDeclarationExt.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/ksp/KSFunctionDeclarationExt.kt @@ -1,8 +1,6 @@ package com.github.klee0kai.thekey.stone.ksp.ksp -import com.google.devtools.ksp.symbol.KSClassDeclaration import com.google.devtools.ksp.symbol.KSFunctionDeclaration -import com.google.devtools.ksp.symbol.KSType import com.google.devtools.ksp.symbol.KSValueParameter fun KSFunctionDeclaration.isSameMethods( diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/poet/smartcode/DeclareLocalVariable.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/poet/smartcode/DeclareLocalVariable.kt new file mode 100644 index 00000000..cd53cc70 --- /dev/null +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/poet/smartcode/DeclareLocalVariable.kt @@ -0,0 +1,10 @@ +package com.github.klee0kai.thekey.stone.ksp.poet.smartcode + +import com.google.devtools.ksp.symbol.KSAnnotation +import com.squareup.kotlinpoet.TypeName + +data class DeclareLocalVariable( + val variableName: String, + val type: TypeName, + val qualifierAnnotations: List = emptyList(), +) diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/poet/smartcode/SmartCode.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/poet/smartcode/SmartCode.kt index 11e71d25..0bbba70d 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/poet/smartcode/SmartCode.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/poet/smartcode/SmartCode.kt @@ -10,7 +10,7 @@ class SmartCode( private val codes = Property>(emptyList()) - val declareLocalVariable = Property?>(null) + val declareLocalVariable = Property(null) val providingType = Property(null) val availableVariables = Property>(emptyMap()) @@ -34,7 +34,7 @@ class SmartCode( val optimizedCode = codes.value.filter { childCode -> childCode.smartCode == null || childCode.smartCode.declareLocalVariable.value == null - || childCode.smartCode.declareLocalVariable.value?.first in allUsedVariables + || childCode.smartCode.declareLocalVariable.value?.variableName in allUsedVariables } val codeBlock = CodeBlock.Builder() diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/poet/smartcode/SmartCodeExt.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/poet/smartcode/SmartCodeExt.kt index c1f1eaee..a8d9be26 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/poet/smartcode/SmartCodeExt.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/poet/smartcode/SmartCodeExt.kt @@ -1,7 +1,10 @@ package com.github.klee0kai.thekey.stone.ksp.poet.smartcode import com.github.klee0kai.thekey.stone.ksp.poet.PoetDsl +import com.github.klee0kai.thekey.stone.ksp.property.map +import com.google.devtools.ksp.symbol.KSAnnotation import com.squareup.kotlinpoet.CodeBlock +import com.squareup.kotlinpoet.asTypeName fun SmartCode.add( code: String, @@ -16,6 +19,24 @@ fun SmartCode.add( add(CodeBlock.of(code, *arg)) } +fun SmartCode.declareLocalVariable( + variableName: String, + qualifiers: List, + initVariable: SmartCode, +) = add { + initVariable.providingType.map { type -> + DeclareLocalVariable( + variableName = variableName, + type = type ?: Unit::class.asTypeName(), + qualifierAnnotations = qualifiers, + ) + } + + add("val %L = ", variableName) + add(initVariable) + add("\n") +} + @PoetDsl fun smartCode( diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/component/GenComponentProcessor.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/component/GenComponentProcessor.kt index a656657f..fdb242e4 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/component/GenComponentProcessor.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/component/GenComponentProcessor.kt @@ -6,13 +6,16 @@ import com.github.klee0kai.stone.__hidden__.types.WeakList import com.github.klee0kai.stone.annotations.component.Component import com.github.klee0kai.stone.annotations.dependencies.Dependencies import com.github.klee0kai.stone.annotations.module.Module +import com.github.klee0kai.stone.lifecycle.StoneLifeCycleOwner import com.github.klee0kai.thekey.stone.ksp.exceptions.IncorrectSignatureException import com.github.klee0kai.thekey.stone.ksp.helpers.* import com.github.klee0kai.thekey.stone.ksp.helpers.annotations.anyAnnotation +import com.github.klee0kai.thekey.stone.ksp.helpers.invokecall.ModulesGraph import com.github.klee0kai.thekey.stone.ksp.ksp.arch.GenSpec import com.github.klee0kai.thekey.stone.ksp.ksp.arch.SymbolsToProcess import com.github.klee0kai.thekey.stone.ksp.ksp.arch.TargetFileProcessor import com.github.klee0kai.thekey.stone.ksp.ksp.getAllMethods +import com.github.klee0kai.thekey.stone.ksp.ksp.isChildOf import com.github.klee0kai.thekey.stone.ksp.poet.* import com.github.klee0kai.thekey.stone.ksp.target.GenModuleProcessor import com.google.devtools.ksp.containingFile @@ -22,6 +25,7 @@ import com.google.devtools.ksp.processing.Resolver import com.google.devtools.ksp.symbol.ClassKind import com.google.devtools.ksp.symbol.KSAnnotated import com.google.devtools.ksp.symbol.KSClassDeclaration +import com.google.devtools.ksp.symbol.KSFunctionDeclaration import com.squareup.kotlinpoet.* import com.squareup.kotlinpoet.ParameterizedTypeName.Companion.parameterizedBy import com.squareup.kotlinpoet.ksp.toClassName @@ -196,7 +200,10 @@ class GenComponentProcessor : TargetFileProcessor { } m.isInjectMethod -> { - + genInjectMethod( + componentCl = componentCl, + method = m, + ) } m.isProtectInjectedMethod -> { @@ -229,6 +236,46 @@ class GenComponentProcessor : TargetFileProcessor { } + private fun TypeSpec.Builder.genInjectMethod( + componentCl: KSClassDeclaration, + method: KSFunctionDeclaration, + modulesGraph: ModulesGraph, + ) { + val identifierTypes = componentCl.allIdentifierTypes.toList() + val idArguments = method.parameters.filter { it.type.resolve() in identifierTypes } + val lifeCycleOwnerArg = method.parameters.firstOrNull { + (it.type.resolve().declaration as? KSClassDeclaration) + ?.isChildOf(StoneLifeCycleOwner::class.asClassName()) == true + } + val injectableArguments = method.parameters.filter { it.type.resolve() !in identifierTypes } + if (originatingElements.isEmpty()) { + throw IncorrectSignatureException( + message = "No injectable parameter at ${method.simpleName.asString()}", + element = method, + ) + } + + genOverrideFun(method) { + for (injectableArgument in injectableArguments) { + val injectableCl = injectableArgument.type.resolve().declaration as? KSClassDeclaration + ?: throw IncorrectSignatureException( + message = "parameter must be a class", + element = injectableArgument, + ) + + for (injectField in injectableCl.getAllProperties()) { + val provideCode = modulesGraph.codeProvideType( + methodName = null, + returnType = injectField.type.resolve().toClassName(), + qualifierAnns = injectField.qualifierAnnotations.toList(), + ) + // TODO + } + } + + } + } + private fun TypeSpec.Builder.genIComponentMethods( componentCl: KSClassDeclaration, delayedCodeBlocks: DelayedCodeBlocks, diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/utils/LocalFieldName.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/utils/LocalFieldName.kt new file mode 100644 index 00000000..bf02f63e --- /dev/null +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/utils/LocalFieldName.kt @@ -0,0 +1,6 @@ +package com.github.klee0kai.thekey.stone.ksp.utils + +object LocalFieldName { + private var localVariableIndx: Long = 0 + fun genLocalFieldName() = "_lc" + localVariableIndx++ +} \ No newline at end of file diff --git a/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/__hidden__/provide/ProvideBuilder.kt b/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/__hidden__/provide/ProvideBuilder.kt new file mode 100644 index 00000000..6a62bd30 --- /dev/null +++ b/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/__hidden__/provide/ProvideBuilder.kt @@ -0,0 +1,23 @@ +package com.github.klee0kai.stone.__hidden__.provide + +class ProvideBuilder( + private val provideBody: ProvideBody +) { + + interface ProvideBody { + fun provide(consumer: ProvideConsumer) + } + + fun first(): T? { + val consumer = ProvideConsumer() + provideBody.provide(consumer) + return consumer.first + } + + fun all(): List { + val consumer = ProvideConsumer() + provideBody.provide(consumer) + return consumer.list + } + +} diff --git a/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/__hidden__/provide/ProvideConsumer.kt b/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/__hidden__/provide/ProvideConsumer.kt new file mode 100644 index 00000000..7534d696 --- /dev/null +++ b/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/__hidden__/provide/ProvideConsumer.kt @@ -0,0 +1,22 @@ +package com.github.klee0kai.stone.__hidden__.provide + +class ProvideConsumer { + private val _list = mutableListOf() + + val list get() = _list.toList() + + val first: T? get() = _list.firstOrNull() + + fun addAll( + collection: Collection + ) { + _list.addAll(collection.filterNotNull()) + } + + fun add(element: T?) { + if (element != null) { + _list.add(element) + } + } + +} diff --git a/tests_kotlin/build.gradle.kts b/tests_kotlin/build.gradle.kts index dff60205..180f5166 100644 --- a/tests_kotlin/build.gradle.kts +++ b/tests_kotlin/build.gradle.kts @@ -11,7 +11,7 @@ dependencies { implementation(project(":tests")) implementation(project(":stone_multiplatform")) -// ksp(project(":stone_ksp")) + ksp(project(":stone_ksp")) testImplementation(libs.bundles.junit) diff --git a/tests_kotlin/src/test/kotlin/com/github/klee0kai/tests/kotlin_models/definterface/DefInterfaceTest.kt b/tests_kotlin/src/test/kotlin/com/github/klee0kai/tests/kotlin_models/definterface/DefInterfaceTest.kt index 1c93d7bb..24d77567 100644 --- a/tests_kotlin/src/test/kotlin/com/github/klee0kai/tests/kotlin_models/definterface/DefInterfaceTest.kt +++ b/tests_kotlin/src/test/kotlin/com/github/klee0kai/tests/kotlin_models/definterface/DefInterfaceTest.kt @@ -1,5 +1,6 @@ package com.github.klee0kai.tests.kotlin_models.definterface +import com.github.klee0kai.stone.Stone import com.github.klee0kai.test_kotlin.di.base_comp.identifiers.KConnectType import com.github.klee0kai.test_kotlin.di.base_comp.identifiers.MonitorSize import com.github.klee0kai.test_kotlin.di.definterface.DefInterfaceComponent @@ -11,7 +12,7 @@ class DefInterfaceTest { @Test fun provideKeyboardTest() { //Given - val DI: DefInterfaceComponent = TODO() + val DI = Stone.createComponent(DefInterfaceComponent::class.java) //When val keyboard1 = DI.factory().keyboard() @@ -32,8 +33,7 @@ class DefInterfaceTest { @Test fun provideMonitorTest() { //Given - val DI: DefInterfaceComponent = TODO() - + val DI = Stone.createComponent(DefInterfaceComponent::class.java) //When val monitor = DI.factory().monitor(MonitorSize("2")) @@ -47,7 +47,7 @@ class DefInterfaceTest { @Test fun provideMouseTest() { //Given - val DI: DefInterfaceComponent = TODO() + val DI = Stone.createComponent(DefInterfaceComponent::class.java) //When val mouse1 = DI.factory().mouse() diff --git a/tests_kotlin/src/test/kotlin/com/github/klee0kai/tests/kotlin_models/identifiers/MonitorFactoryWrappersTests.kt b/tests_kotlin/src/test/kotlin/com/github/klee0kai/tests/kotlin_models/identifiers/MonitorFactoryWrappersTests.kt index 1dea6ad1..ffc54609 100644 --- a/tests_kotlin/src/test/kotlin/com/github/klee0kai/tests/kotlin_models/identifiers/MonitorFactoryWrappersTests.kt +++ b/tests_kotlin/src/test/kotlin/com/github/klee0kai/tests/kotlin_models/identifiers/MonitorFactoryWrappersTests.kt @@ -1,5 +1,8 @@ package com.github.klee0kai.tests.kotlin_models.identifiers +import com.github.klee0kai.stone.Stone +import com.github.klee0kai.stone.type.wrappers.getValue +import com.github.klee0kai.stone.weakref.Ref import com.github.klee0kai.test_kotlin.di.compfactory.CompFactoryComponent import com.github.klee0kai.test_kotlin.tech.components.Monitor import org.junit.jupiter.api.Assertions.* @@ -11,15 +14,15 @@ class MonitorFactoryWrappersTests { @Test fun lazyProvideTest() { //Given - val DI: CompFactoryComponent = TODO() + val DI = Stone.createComponent(CompFactoryComponent::class.java) //When - val monitor = DI.monitorLazy() + val monitor: Ref = DI.monitorLazy() //Then assertEquals( - monitor.get()!!.uuid, - monitor.get()!!.uuid + monitor.get().uuid, + monitor.get().uuid ) } @@ -27,7 +30,7 @@ class MonitorFactoryWrappersTests { @Test fun softRefProvideTest() { //Given - val DI: CompFactoryComponent = TODO() + val DI = Stone.createComponent(CompFactoryComponent::class.java) //When val monitor: Reference = DI.monitorSoft() @@ -39,7 +42,7 @@ class MonitorFactoryWrappersTests { @Test fun weakRefProvideTest() { //Given - val DI: CompFactoryComponent = TODO() + val DI = Stone.createComponent(CompFactoryComponent::class.java) //When val monitor: Reference = DI.monitorWeak() @@ -51,37 +54,37 @@ class MonitorFactoryWrappersTests { @Test fun phantom1ProvideTest() { //Given - val DI: CompFactoryComponent = TODO() + val DI = Stone.createComponent(CompFactoryComponent::class.java) //When - val monitor = DI.monitorPhantomProvide() + val monitor: Ref = DI.monitorPhantomProvide() //Then assertNotEquals( - monitor.get()!!.uuid, - monitor.get()!!.uuid + monitor.get().uuid, + monitor.get().uuid ) } @Test fun phantomProvideTest() { //Given - val DI: CompFactoryComponent = TODO() + val DI = Stone.createComponent(CompFactoryComponent::class.java) //When - val monitor = DI.monitorPhantomProvide() + val monitor: Ref = DI.monitorPhantomProvide() //Then assertNotEquals( - monitor.get()!!.uuid, - monitor.get()!!.uuid + monitor.get().uuid, + monitor.get().uuid ) } @Test fun phantom3ProvideTest() { //Given - val DI: CompFactoryComponent = TODO() + val DI = Stone.createComponent(CompFactoryComponent::class.java) //When val monitor = DI.monitorProviderIRef() @@ -97,7 +100,7 @@ class MonitorFactoryWrappersTests { @Test fun kotlinLazyProvideTest() { //Given - val DI: CompFactoryComponent = TODO() + val DI = Stone.createComponent(CompFactoryComponent::class.java) //When val monitor = DI.monitorLazyDelegate() @@ -110,18 +113,19 @@ class MonitorFactoryWrappersTests { } + @Test fun lazyDelegateTest() { //Given - val DI: CompFactoryComponent = TODO() + val DI = Stone.createComponent(CompFactoryComponent::class.java) //When - val monitor = DI.monitorLazy() + val monitor by DI.monitorLazy() //Then assertEquals( - monitor.get()!!.uuid, - monitor.get()!!.uuid + monitor.uuid, + monitor.uuid ) } @@ -129,69 +133,69 @@ class MonitorFactoryWrappersTests { @Test fun softRefDelegateTest() { //Given - val DI: CompFactoryComponent = TODO() + val DI = Stone.createComponent(CompFactoryComponent::class.java) //When - val monitor = DI.monitorSoft() + val monitor by DI.monitorSoft() //Then - assertNotNull(monitor.get()) + assertNotNull(monitor) } @Test fun weakRefDelegateTest() { //Given - val DI: CompFactoryComponent = TODO() + val DI = Stone.createComponent(CompFactoryComponent::class.java) //When - val monitor = DI.monitorWeak() + val monitor by DI.monitorWeak() //Then - assertNotNull(monitor.get()) + assertNotNull(monitor) } @Test fun phantom1DelegateTest() { //Given - val DI: CompFactoryComponent = TODO() + val DI = Stone.createComponent(CompFactoryComponent::class.java) //When - val monitor = DI.monitorPhantomProvide() + val monitor by DI.monitorPhantomProvide() //Then assertNotEquals( - monitor.get()!!.uuid, - monitor.get()!!.uuid + monitor.uuid, + monitor.uuid ) } @Test fun phantom2DelegateTest() { //Given - val DI: CompFactoryComponent = TODO() + val DI = Stone.createComponent(CompFactoryComponent::class.java) //When - val monitor = DI.monitorPhantomProvide() + val monitor by DI.monitorPhantomProvide() //Then assertNotEquals( - monitor.get()!!.uuid, - monitor.get()!!.uuid + monitor.uuid, + monitor.uuid ) } @Test fun phantom3DelegateTest() { //Given - val DI: CompFactoryComponent = TODO() + val DI = Stone.createComponent(CompFactoryComponent::class.java) //When - val monitor = DI.monitorProviderIRef() + val monitor by DI.monitorProviderIRef() //Then assertNotEquals( - monitor.get()!!.uuid, - monitor.get()!!.uuid + monitor.uuid, + monitor.uuid ) } @@ -199,7 +203,7 @@ class MonitorFactoryWrappersTests { @Test fun kotlinLazyDelegateTest() { //Given - val DI: CompFactoryComponent = TODO() + val DI = Stone.createComponent(CompFactoryComponent::class.java) //When val monitor by DI.monitorLazyDelegate() @@ -212,6 +216,8 @@ class MonitorFactoryWrappersTests { } + + } diff --git a/tests_kotlin/src/test/kotlin/com/github/klee0kai/tests/kotlin_models/inject/GorillaInjectTests.kt b/tests_kotlin/src/test/kotlin/com/github/klee0kai/tests/kotlin_models/inject/GorillaInjectTests.kt index b3dffade..cf864513 100644 --- a/tests_kotlin/src/test/kotlin/com/github/klee0kai/tests/kotlin_models/inject/GorillaInjectTests.kt +++ b/tests_kotlin/src/test/kotlin/com/github/klee0kai/tests/kotlin_models/inject/GorillaInjectTests.kt @@ -1,5 +1,6 @@ package com.github.klee0kai.tests.kotlin_models.inject +import com.github.klee0kai.stone.Stone import com.github.klee0kai.test_kotlin.di.base_forest.RainForestComponent import com.github.klee0kai.test_kotlin.mowgli.animal.Cougar import com.github.klee0kai.test_kotlin.mowgli.animal.Gorilla @@ -11,7 +12,7 @@ class GorillaInjectTests { @Test fun gorillaBornTest() { //Given - val DI: RainForestComponent = TODO() + val DI = Stone.createComponent(RainForestComponent::class.java) val gorilla = Gorilla() @@ -27,8 +28,7 @@ class GorillaInjectTests { @Test fun oneBloodTest() { //Given - val DI: RainForestComponent = TODO() - + val DI = Stone.createComponent(RainForestComponent::class.java) val gorilla = Gorilla() val cougar = Cougar() @@ -48,7 +48,7 @@ class GorillaInjectTests { @Test fun personalityTest() { //Given - val DI: RainForestComponent = TODO() + val DI = Stone.createComponent(RainForestComponent::class.java) val gorilla = Gorilla() val cougar = Cougar() diff --git a/tests_kotlin/src/test/kotlin/com/github/klee0kai/tests/kotlin_models/inject/GorillaInjectWrappersTests.kt b/tests_kotlin/src/test/kotlin/com/github/klee0kai/tests/kotlin_models/inject/GorillaInjectWrappersTests.kt index ca3026ad..41656089 100644 --- a/tests_kotlin/src/test/kotlin/com/github/klee0kai/tests/kotlin_models/inject/GorillaInjectWrappersTests.kt +++ b/tests_kotlin/src/test/kotlin/com/github/klee0kai/tests/kotlin_models/inject/GorillaInjectWrappersTests.kt @@ -1,5 +1,6 @@ package com.github.klee0kai.tests.kotlin_models.inject +import com.github.klee0kai.stone.Stone import com.github.klee0kai.test_kotlin.di.base_forest.RainForestComponent import com.github.klee0kai.test_kotlin.mowgli.animal.Gorilla import org.junit.jupiter.api.Assertions.* @@ -10,7 +11,7 @@ class GorillaInjectWrappersTests { @Test fun supportWrappersTest() { //Given - val DI: RainForestComponent = TODO() + val DI = Stone.createComponent(RainForestComponent::class.java) val gorilla = Gorilla() //When @@ -30,8 +31,7 @@ class GorillaInjectWrappersTests { @Test fun refWrapperTest() { //Given - val DI: RainForestComponent = TODO() - + val DI = Stone.createComponent(RainForestComponent::class.java) val gorilla = Gorilla() //When @@ -56,7 +56,7 @@ class GorillaInjectWrappersTests { @Test fun genWrapperTest() { //Given - val DI: RainForestComponent = TODO() + val DI = Stone.createComponent(RainForestComponent::class.java) var gorilla = Gorilla() //When @@ -64,8 +64,8 @@ class GorillaInjectWrappersTests { //Then assertNotEquals( - gorilla.knowledgePhantomProvide!!.get()!!.uuid, - gorilla.knowledgePhantomProvide!!.get()!!.uuid + gorilla.knowledgePhantomProvide!!.get().uuid, + gorilla.knowledgePhantomProvide!!.get().uuid ) assertNotEquals( gorilla.knowledgePhantomProvide2!!.get().uuid, diff --git a/tests_kotlin/src/test/kotlin/com/github/klee0kai/tests/kotlin_models/inject/GorillaProtectInjectTests.kt b/tests_kotlin/src/test/kotlin/com/github/klee0kai/tests/kotlin_models/inject/GorillaProtectInjectTests.kt index 7f680d81..59538b92 100644 --- a/tests_kotlin/src/test/kotlin/com/github/klee0kai/tests/kotlin_models/inject/GorillaProtectInjectTests.kt +++ b/tests_kotlin/src/test/kotlin/com/github/klee0kai/tests/kotlin_models/inject/GorillaProtectInjectTests.kt @@ -1,5 +1,6 @@ package com.github.klee0kai.tests.kotlin_models.inject +import com.github.klee0kai.stone.Stone import com.github.klee0kai.test_kotlin.di.base_forest.RainForestComponent import com.github.klee0kai.test_kotlin.mowgli.animal.Gorilla import org.junit.jupiter.api.Assertions.assertNotNull @@ -12,7 +13,7 @@ class GorillaProtectInjectTests { @Test fun withoutProtectInjectTest() { // Given - val DI: RainForestComponent = TODO() + val DI = Stone.createComponent(RainForestComponent::class.java) var gorilla: Gorilla? = Gorilla() @@ -31,7 +32,7 @@ class GorillaProtectInjectTests { @Throws(InterruptedException::class) fun withProtectInjectTest() { // Given - val DI: RainForestComponent = TODO() + val DI = Stone.createComponent(RainForestComponent::class.java) var gorrila: Gorilla? = Gorilla() diff --git a/tests_kotlin/src/test/kotlin/com/github/klee0kai/tests/kotlin_models/inject/GorillaProtectInjectWrappersTests.kt b/tests_kotlin/src/test/kotlin/com/github/klee0kai/tests/kotlin_models/inject/GorillaProtectInjectWrappersTests.kt index 089d09c2..552d3f14 100644 --- a/tests_kotlin/src/test/kotlin/com/github/klee0kai/tests/kotlin_models/inject/GorillaProtectInjectWrappersTests.kt +++ b/tests_kotlin/src/test/kotlin/com/github/klee0kai/tests/kotlin_models/inject/GorillaProtectInjectWrappersTests.kt @@ -1,5 +1,6 @@ package com.github.klee0kai.tests.kotlin_models.inject +import com.github.klee0kai.stone.Stone import com.github.klee0kai.test_kotlin.di.base_forest.RainForestComponent import com.github.klee0kai.test_kotlin.mowgli.University import com.github.klee0kai.test_kotlin.mowgli.animal.Gorilla @@ -13,7 +14,7 @@ class GorillaProtectInjectWrappersTests { @Test fun lazyWrapperProtectTest() { // Given - val DI: RainForestComponent = TODO() + val DI = Stone.createComponent(RainForestComponent::class.java) val university = University() @@ -32,7 +33,7 @@ class GorillaProtectInjectWrappersTests { @Throws(InterruptedException::class) fun withProtectInjectTest() { // Given - val DI: RainForestComponent = TODO() + val DI = Stone.createComponent(RainForestComponent::class.java) var gorilla: Gorilla? = Gorilla() //When diff --git a/tests_kotlin/src/test/kotlin/com/github/klee0kai/tests/kotlin_models/interface_delegates/InterfaceDelegatesTest.kt b/tests_kotlin/src/test/kotlin/com/github/klee0kai/tests/kotlin_models/interface_delegates/InterfaceDelegatesTest.kt index 644461af..83d9126e 100644 --- a/tests_kotlin/src/test/kotlin/com/github/klee0kai/tests/kotlin_models/interface_delegates/InterfaceDelegatesTest.kt +++ b/tests_kotlin/src/test/kotlin/com/github/klee0kai/tests/kotlin_models/interface_delegates/InterfaceDelegatesTest.kt @@ -1,5 +1,6 @@ package com.github.klee0kai.tests.kotlin_models.interface_delegates +import com.github.klee0kai.stone.Stone import com.github.klee0kai.test_kotlin.di.base_comp.identifiers.KConnectType import com.github.klee0kai.test_kotlin.di.base_comp.identifiers.MonitorSize import com.github.klee0kai.test_kotlin.di.interface_delegates.InterfaceDelegatesComponent @@ -11,7 +12,7 @@ class InterfaceDelegatesTest { @Test fun provideKeyboardTest() { //Given - val DI: InterfaceDelegatesComponent = TODO() + val DI = Stone.createComponent(InterfaceDelegatesComponent::class.java) //When val keyboard1 = DI.factory().keyboard() @@ -32,7 +33,7 @@ class InterfaceDelegatesTest { @Test fun provideMonitorTest() { //Given - val DI: InterfaceDelegatesComponent = TODO() + val DI = Stone.createComponent(InterfaceDelegatesComponent::class.java) //When val monitor = DI.factory().monitor(MonitorSize("2")) @@ -46,7 +47,7 @@ class InterfaceDelegatesTest { @Test fun provideMouseTest() { //Given - val DI: InterfaceDelegatesComponent = TODO() + val DI = Stone.createComponent(InterfaceDelegatesComponent::class.java) //When val mouse1 = DI.factory().mouse() diff --git a/tests_kotlin/src/test/kotlin/com/github/klee0kai/tests/kotlin_models/lifecycle/DeskCompRepairTest.kt b/tests_kotlin/src/test/kotlin/com/github/klee0kai/tests/kotlin_models/lifecycle/DeskCompRepairTest.kt index c389efa0..40e93531 100644 --- a/tests_kotlin/src/test/kotlin/com/github/klee0kai/tests/kotlin_models/lifecycle/DeskCompRepairTest.kt +++ b/tests_kotlin/src/test/kotlin/com/github/klee0kai/tests/kotlin_models/lifecycle/DeskCompRepairTest.kt @@ -1,6 +1,5 @@ package com.github.klee0kai.tests.kotlin_models.lifecycle -import com.github.klee0kai.test_kotlin.tech.ComputerStore import com.github.klee0kai.test_kotlin.tech.comp.DesktopComp import org.junit.jupiter.api.Assertions.* import org.junit.jupiter.api.Test diff --git a/tests_kotlin/src/test/kotlin/com/github/klee0kai/tests/kotlin_models/lifecycle/GameCompRepairTest.kt b/tests_kotlin/src/test/kotlin/com/github/klee0kai/tests/kotlin_models/lifecycle/GameCompRepairTest.kt index 5acf6ad9..d07a57ce 100644 --- a/tests_kotlin/src/test/kotlin/com/github/klee0kai/tests/kotlin_models/lifecycle/GameCompRepairTest.kt +++ b/tests_kotlin/src/test/kotlin/com/github/klee0kai/tests/kotlin_models/lifecycle/GameCompRepairTest.kt @@ -1,6 +1,5 @@ package com.github.klee0kai.tests.kotlin_models.lifecycle -import com.github.klee0kai.test_kotlin.tech.ComputerStore import com.github.klee0kai.test_kotlin.tech.comp.GameComp import org.junit.jupiter.api.Assertions.* import org.junit.jupiter.api.Test From 33b7d9f34d580714d7cf335929a27662c0d29e31 Mon Sep 17 00:00:00 2001 From: klee0kai Date: Sun, 7 Dec 2025 22:30:14 +0100 Subject: [PATCH 044/122] migrate wrap helper --- .../stone/ksp/helpers/wrap/ClassNameUtils.kt | 8 - .../stone/ksp/helpers/wrap/FormatInList.kt | 8 +- .../stone/ksp/helpers/wrap/FormatSimple.kt | 6 +- .../stone/ksp/helpers/wrap/WrapHelper.kt | 389 ++++++++---------- .../poet/smartcode/DeclareLocalVariable.kt | 10 - .../stone/ksp/poet/smartcode/SmartCode.kt | 56 --- .../ksp/poet/smartcode/SmartCodeBlock.kt | 9 - .../stone/ksp/poet/smartcode/SmartCodeExt.kt | 71 ---- 8 files changed, 189 insertions(+), 368 deletions(-) delete mode 100644 stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/poet/smartcode/DeclareLocalVariable.kt delete mode 100644 stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/poet/smartcode/SmartCode.kt delete mode 100644 stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/poet/smartcode/SmartCodeBlock.kt delete mode 100644 stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/poet/smartcode/SmartCodeExt.kt diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/wrap/ClassNameUtils.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/wrap/ClassNameUtils.kt index 57069dd4..75074f48 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/wrap/ClassNameUtils.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/wrap/ClassNameUtils.kt @@ -67,13 +67,5 @@ object ClassNameUtils { return type } - @Deprecated("use careful") - fun simpleName(typeName: TypeName): String? { - val raw = rawTypeOf(typeName) - if (raw is ClassName) { - return raw.simpleName - } - return null - } } \ No newline at end of file diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/wrap/FormatInList.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/wrap/FormatInList.kt index 320d06ca..13ee5573 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/wrap/FormatInList.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/wrap/FormatInList.kt @@ -1,6 +1,7 @@ package com.github.klee0kai.thekey.stone.ksp.helpers.wrap -import com.github.klee0kai.thekey.stone.ksp.poet.smartcode.SmartCode +import com.squareup.kotlinpoet.CodeBlock +import com.squareup.kotlinpoet.TypeName fun interface FormatInList { @@ -9,8 +10,9 @@ fun interface FormatInList { * @return */ fun formatCode( - or: SmartCode, + originalListType: TypeName, + or: CodeBlock, itemTransformFun: FormatSimple, - ): SmartCode + ): CodeBlock } diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/wrap/FormatSimple.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/wrap/FormatSimple.kt index f00ff287..71ae517a 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/wrap/FormatSimple.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/wrap/FormatSimple.kt @@ -1,6 +1,6 @@ package com.github.klee0kai.thekey.stone.ksp.helpers.wrap -import com.github.klee0kai.thekey.stone.ksp.poet.smartcode.SmartCode +import com.squareup.kotlinpoet.CodeBlock fun interface FormatSimple { @@ -10,6 +10,6 @@ fun interface FormatSimple { * @return code witch return wanna type */ fun formatCode( - or: SmartCode, - ): SmartCode + or: CodeBlock, + ): CodeBlock } diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/wrap/WrapHelper.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/wrap/WrapHelper.kt index 9c66624b..87694a9d 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/wrap/WrapHelper.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/wrap/WrapHelper.kt @@ -4,117 +4,66 @@ import com.github.klee0kai.stone.weakref.Ref import com.github.klee0kai.stone.wrappers.AsyncCoroutineProvide import com.github.klee0kai.stone.wrappers.LazyProvide import com.github.klee0kai.stone.wrappers.PhantomProvide -import com.github.klee0kai.thekey.stone.ksp.exceptions.ExceptionStringBuilder import com.github.klee0kai.thekey.stone.ksp.exceptions.StoneException +import com.github.klee0kai.thekey.stone.ksp.helpers.wrap.ClassNameUtils.noWildCardType import com.github.klee0kai.thekey.stone.ksp.helpers.wrap.ClassNameUtils.rawTypeOf -import com.github.klee0kai.thekey.stone.ksp.poet.smartcode.SmartCode -import com.github.klee0kai.thekey.stone.ksp.poet.smartcode.add -import com.github.klee0kai.thekey.stone.ksp.poet.smartcode.smartCode -import com.github.klee0kai.thekey.stone.ksp.property.map -import com.squareup.kotlinpoet.ParameterizedTypeName +import com.squareup.kotlinpoet.* import com.squareup.kotlinpoet.ParameterizedTypeName.Companion.parameterizedBy -import com.squareup.kotlinpoet.TypeName -import com.squareup.kotlinpoet.WildcardTypeName -import com.squareup.kotlinpoet.asClassName import java.lang.ref.Reference import java.lang.ref.SoftReference import java.lang.ref.WeakReference +import java.util.* import javax.inject.Provider + class WrapHelper { private var wrapTypes = HashMap() init { - fillStdWrappers() + std() } - fun isList(typeName: TypeName): Boolean = allParamTypes(typeName).any { - val wrapType = wrapTypes[rawTypeOf(it)] - wrapType != null && wrapType.isList + fun support(wrapType: WrapType) { + wrapTypes.putIfAbsent(wrapType.typeName, wrapType) } + fun isSupport(typeName: TypeName): Boolean = wrapTypes.containsKey(rawTypeOf(typeName)) - fun listWrapTypeIfNeed(typeName: TypeName): TypeName { - if (isList(typeName)) List::class - .asClassName() - .parameterizedBy(nonWrappedType(typeName)) - - return nonWrappedType(typeName); - } - - fun transform(code: SmartCode, wannaType: TypeName): SmartCode { - if (code.providingType.value == null || code.providingType.value == wannaType) { - return code - } - var smartCode = SmartCode().apply { add(code) } - - var wrapPathNames = allParamTypes(wannaType).reversed() - var unwrapPathNames = allParamTypes(code.providingType.value!!) - while ( - !wrapPathNames.isEmpty() && !unwrapPathNames.isEmpty() - && rawTypeOf(unwrapPathNames.last()) == rawTypeOf(wrapPathNames.first()) - ) { - unwrapPathNames = unwrapPathNames.dropLast(1) - wrapPathNames = wrapPathNames.drop(1) + fun isNonCachingWrapper(typeName: TypeName): Boolean { + for (t in allParamTypes(typeName)) { + val wrapType = wrapTypes.get(rawTypeOf(t)) + if (wrapType != null && wrapType.isNoCachingWrapper) return true } + return false + } - val wrapTypeFormat: (TypeName) -> WrapType = { - wrapTypes.getOrElse(rawTypeOf(it)) { - throw StoneException( - ExceptionStringBuilder.createErrorMes() - .typeTransformNonSupport( - ClassNameUtils.noWildCardType(code.providingType.value!!), - wannaType - ) - .classNonFound(it.toString()) - .build(), - ) - } + fun isAsyncProvider(typeName: TypeName): Boolean { + for (t in allParamTypes(typeName)) { + val wrapType = wrapTypes.get(rawTypeOf(t)) + if (wrapType != null && wrapType.isAsyncProvider) return true } + return false + } - var unwrapPath = unwrapPathNames.map(wrapTypeFormat) - var wrapPath = wrapPathNames.map(wrapTypeFormat) - - while (!unwrapPath.isEmpty()) { - val unwrapType = unwrapPath.first() - if (unwrapType.isList) { - val wrapListIndex = wrapPath.indexOfFirst { it.isList } - if (wrapListIndex >= 0) { - val unWrapItemType = paramType(unwrapPathNames.first()) - val wrapItemType = paramType(wrapPathNames[wrapListIndex]) - val wrapListType = wrapPath[wrapListIndex] - smartCode = wrapListType.inListFormat!!.formatCode( - smartCode, - FormatSimple { listItemCode -> - listItemCode.providingType.value = unWrapItemType - transform(listItemCode, wrapItemType) - }) + fun isList(typeName: TypeName): Boolean = allParamTypes(typeName).any { + val wrapType = wrapTypes.get(rawTypeOf(it)) + wrapType != null && wrapType.isList + } - for (i in 0..wrapListIndex) { - wrapPath = wrapPath.drop(1) - wrapPathNames.drop(1) - } - unwrapPath = emptyList() - unwrapPathNames = emptyList() - break - } + fun paramType(typeName: TypeName): TypeName { + if (typeName is ParameterizedTypeName) { + if (isSupport(typeName.rawType) && !typeName.typeArguments.isEmpty()) { + return typeName.typeArguments.first() } - smartCode = unwrapType.unwrap.formatCode(smartCode) - unwrapPath = unwrapPath.drop(1) - unwrapPathNames = unwrapPathNames.drop(1) - } - - while (!wrapPath.isEmpty()) { - smartCode = wrapPath[0].wrap.formatCode(smartCode) - wrapPath = wrapPath.drop(1) - wrapPathNames = wrapPathNames.drop(1) } - - smartCode.providingType.value = wannaType - return smartCode + return typeName } + /** + * com.github.klee0kai.stone.wrappers.LazyProvide -> com.github.klee0kai.test.tech.components.Battery + * ? extends java.lang.ref.WeakReference -> com.github.klee0kai.test.car.model.Window + */ fun nonWrappedType(typeName: TypeName): TypeName { if (typeName is ParameterizedTypeName) { if (isSupport(typeName.rawType) && !typeName.typeArguments.isEmpty()) { @@ -122,76 +71,129 @@ class WrapHelper { } } if (typeName is WildcardTypeName) { - if (!typeName.outTypes.isEmpty()) { - return nonWrappedType(typeName.outTypes.first()) - } + if (!typeName.outTypes.isEmpty()) return nonWrappedType(typeName.outTypes.first()) } return typeName } + /** + * java.util.List>> -> + * java.util.List> + */ + fun listWrapTypeIfNeed(typeName: TypeName): TypeName { + if (isList(typeName)) return List::class.asClassName().parameterizedBy(nonWrappedType(typeName)) + return nonWrappedType(typeName) + } + fun allParamTypes(typeName: TypeName): List { - var typeName = typeName - typeName = ClassNameUtils.noWildCardType(typeName) - val allParams = mutableListOf() + var typeName = noWildCardType(typeName) + val allParams = LinkedList() while (true) { allParams.add(typeName) val paramType = typeName as? ParameterizedTypeName if (paramType == null || paramType.typeArguments.isEmpty()) break - typeName = ClassNameUtils.noWildCardType(paramType.typeArguments.first()) + typeName = noWildCardType(paramType.typeArguments[0]) } return allParams } - fun support(wrapType: WrapType) { - wrapTypes.putIfAbsent(wrapType.typeName, wrapType) - } - fun isSupport(typeName: TypeName): Boolean = wrapTypes.containsKey(rawTypeOf(typeName)) + fun transform( + providingType: TypeName, + wannaType: TypeName, + code: CodeBlock - fun paramType(typeName: TypeName): TypeName { - if (typeName is ParameterizedTypeName) { - if (isSupport(typeName.rawType) && !typeName.typeArguments.isEmpty()) { - return typeName.typeArguments.first() + ): CodeBlock { + if (providingType == wannaType) return code + + var codeBuilder = CodeBlock.builder().add(code) + val wrapPathNames = LinkedList(allParamTypes(wannaType)) + val unwrapPathNames = LinkedList(allParamTypes(providingType)) + wrapPathNames.reverse() + + while (!wrapPathNames.isEmpty() && !unwrapPathNames.isEmpty() + && rawTypeOf(unwrapPathNames.last()) == rawTypeOf(wrapPathNames.first()) + ) { + unwrapPathNames.pollLast() + wrapPathNames.pollFirst() + } + + val wrapTypeFormat: (TypeName) -> WrapType = { it: TypeName -> + wrapTypes[rawTypeOf(it)] + ?: throw StoneException(message = "Type Transform non support $providingType -> $wannaType") + } + + val unwrapPath = LinkedList(unwrapPathNames.map(wrapTypeFormat)) + val wrapPath = LinkedList(wrapPathNames.map(wrapTypeFormat)) + + while (!unwrapPath.isEmpty()) { + val unwrapType = unwrapPath[0] + if (unwrapType.isList) { + val wrapListIndex = wrapPath.indexOfFirst { it.isList } + if (wrapListIndex >= 0) { + val unWrapItemType = paramType(unwrapPathNames[0]) + val wrapItemType = paramType(wrapPathNames[wrapListIndex]) + val wrapListType = wrapPath[wrapListIndex] + + codeBuilder = wrapListType.inListFormat!!.formatCode( + originalListType = unwrapType.typeName, + or = codeBuilder.build(), + itemTransformFun = { listItemCode -> + transform(unWrapItemType, wrapItemType, listItemCode) + } + ).toBuilder() + + for (i in 0..wrapListIndex) { + wrapPath.pollFirst() + wrapPathNames.pollFirst() + } + unwrapPath.clear() + unwrapPathNames.clear() + break + } } + codeBuilder = unwrapType.unwrap.formatCode(codeBuilder.build()) + .toBuilder() + + unwrapPath.pollFirst() + unwrapPathNames.pollFirst() } - return typeName + + while (!wrapPath.isEmpty()) { + codeBuilder = wrapPath[0].wrap.formatCode(codeBuilder.build()) + .toBuilder() + + wrapPath.pollFirst() + wrapPathNames.pollFirst() + } + + return codeBuilder.build() } - private fun fillStdWrappers() { + private fun std() { for (cl in listOf( WeakReference::class, SoftReference::class, - Reference::class + Reference::class, )) { val wrapper = cl.asClassName() - val creator = if (cl != Reference::class) wrapper else WeakReference::class.asClassName() - - support( - WrapType( - isNoCachingWrapper = false, - typeName = wrapper, - wrap = FormatSimple { or -> - smartCode { - add(or) - add("?.let{ %T( it ) }", creator) - - providingType.source = or.providingType.map { orType -> - orType?.let { wrapper.parameterizedBy(it) } - } - } - }, - unwrap = FormatSimple { or -> - smartCode { - add("or") - add("?.get()") - - providingType.source = or.providingType.map { orType -> - orType?.let { paramType(it) } - } - } - }, - ) + val creator = if (cl != Reference::class.java) wrapper else WeakReference::class.asClassName() + + val wrapType = WrapType( + typeName = wrapper, + isNoCachingWrapper = false, + wrap = { or -> + CodeBlock.builder() + .add("%L?.let{ %T(it) }", or, creator) + .build() + }, + unwrap = { or -> + CodeBlock.builder() + .add("%L?.get()", or) + .build() + } ) + support(wrapType) } for (cl in listOf( @@ -199,93 +201,64 @@ class WrapHelper { Ref::class, Provider::class, LazyProvide::class, - AsyncCoroutineProvide::class, + AsyncCoroutineProvide::class )) { val wrapper = cl.asClassName() - - val isNoCachingWrapper = cl !in listOf(LazyProvide::class, AsyncCoroutineProvide::class) - val creator = if (isNoCachingWrapper) PhantomProvide::class.asClassName() else wrapper - support( - WrapType( - typeName = wrapper, - isNoCachingWrapper = cl != LazyProvide::class && cl != AsyncCoroutineProvide::class, - isAsyncProvider = true, - wrap = FormatSimple { or -> - smartCode { - add("%S{", creator) - add(or) - add("} ") - - providingType.source = or.providingType.map { orType -> - orType?.let { wrapper.parameterizedBy(it) } - } - } - }, - unwrap = FormatSimple { or -> - smartCode { - add("or") - add("?.get()") - providingType.source = or.providingType.map { orType -> - orType?.let { paramType(it) } - } - } - } - ) + val isNoCachingWrapper = cl != LazyProvide::class.java && cl != AsyncCoroutineProvide::class + val wrapType = WrapType( + typeName = wrapper, + isNoCachingWrapper = isNoCachingWrapper, + isAsyncProvider = true, + wrap = { or -> + CodeBlock.of( + "%T{ %L } ", + if (isNoCachingWrapper) PhantomProvide::class.asClassName() else wrapper, + or, + ) + }, + unwrap = { or -> CodeBlock.of("%L?.get()", or) }, ) + support(wrapType) } - for (cl in listOf( - List::class, - Array::class, - MutableList::class, - MutableCollection::class - )) { + var index = 0 + for (cl in listOf(LinkedList::class, ArrayList::class, MutableList::class, MutableCollection::class)) { val wrapper = cl.asClassName() - val creatorFun = when (cl) { - List::class -> "listOf" - Array::class -> "arrayOf" - MutableList::class, - MutableCollection::class -> "mutableListOf" - - else -> "listOf" - } - - support( - WrapType( - typeName = wrapper, - wrap = FormatSimple { or -> - smartCode { - add("%L(", creatorFun) - add(or) - add(")") - - providingType.source = or.providingType.map { orType -> - orType?.let { wrapper.parameterizedBy(it) } - } - } - }, - unwrap = FormatSimple { or -> - smartCode { - add("or") - add("?.firstOrNull()") - providingType.source = or.providingType.map { orType -> - orType?.let { paramType(it) } - } - } - }, - inListFormat = FormatInList { originalListCode, itemTransformFun -> - smartCode { - add(originalListCode) - add(".map { ") - with(itemTransformFun) { - formatCode(smartCode("it")) - } - add(" }") - } + val needConstructor = listOf(LinkedList::class, ArrayList::class).contains(cl) + val createType = if (index++ <= 0) wrapper else ArrayList::class.asClassName() + + val wrapType = WrapType( + typeName = wrapper, + wrap = { or -> + val builder = CodeBlock.builder() + builder.add("listOfNotNull( %L ) ", or) + if (needConstructor) builder.add(".let { %T(it) }", createType) + builder.build() + }, + unwrap = { or -> + CodeBlock.builder() + .add("%L.first( %L )", or) + .build() + }, + inListFormat = { originalListType, originalListCode, itemTransformFun -> + val builder = CodeBlock.builder() + val isListNeedConstructor = + needConstructor && rawTypeOf(wrapper) != rawTypeOf(originalListType) + + val itemTransform = itemTransformFun.formatCode(CodeBlock.of("it")) + if (itemTransform.toString() == "it") { + //no transforms + builder.add(originalListCode) + } else { + builder.add("%L.map{ it -> %L }", originalListCode, itemTransform) } - )) - } + if (isListNeedConstructor) builder.add(".let { %T(it) }", createType) + builder.build() + }, + ) + support(wrapType) + } } } \ No newline at end of file diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/poet/smartcode/DeclareLocalVariable.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/poet/smartcode/DeclareLocalVariable.kt deleted file mode 100644 index cd53cc70..00000000 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/poet/smartcode/DeclareLocalVariable.kt +++ /dev/null @@ -1,10 +0,0 @@ -package com.github.klee0kai.thekey.stone.ksp.poet.smartcode - -import com.google.devtools.ksp.symbol.KSAnnotation -import com.squareup.kotlinpoet.TypeName - -data class DeclareLocalVariable( - val variableName: String, - val type: TypeName, - val qualifierAnnotations: List = emptyList(), -) diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/poet/smartcode/SmartCode.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/poet/smartcode/SmartCode.kt deleted file mode 100644 index 0bbba70d..00000000 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/poet/smartcode/SmartCode.kt +++ /dev/null @@ -1,56 +0,0 @@ -package com.github.klee0kai.thekey.stone.ksp.poet.smartcode - -import com.github.klee0kai.thekey.stone.ksp.property.Property -import com.squareup.kotlinpoet.CodeBlock -import com.squareup.kotlinpoet.TypeName - -class SmartCode( - val parent: SmartCode? = null, -) { - - private val codes = Property>(emptyList()) - - val declareLocalVariable = Property(null) - val providingType = Property(null) - - val availableVariables = Property>(emptyMap()) - val usedVariables = Property>(emptySet()) - - fun add(codeBlock: CodeBlock) { - codes.value += SmartCodeBlock(codeBlock = codeBlock) - parent?.providingType?.source = null - } - - fun add(codeBlock: SmartCode) { - codes.value += SmartCodeBlock(smartCode = codeBlock) - parent?.providingType?.source = codeBlock.providingType - } - - fun collect( - ): CodeBlock { - val allUsedVariables = usedVariables.value + codes.value - .flatMap { childCode -> childCode.smartCode?.usedVariables?.value ?: emptySet() } - - val optimizedCode = codes.value.filter { childCode -> - childCode.smartCode == null - || childCode.smartCode.declareLocalVariable.value == null - || childCode.smartCode.declareLocalVariable.value?.variableName in allUsedVariables - } - - val codeBlock = CodeBlock.Builder() - optimizedCode.forEach { childCode -> - when { - childCode.codeBlock != null -> codeBlock.add(childCode.codeBlock) - childCode.smartCode != null -> codeBlock.add(childCode.smartCode.collect()) - } - } - return codeBlock.build() - } - -} - - - - - - diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/poet/smartcode/SmartCodeBlock.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/poet/smartcode/SmartCodeBlock.kt deleted file mode 100644 index 359f6df8..00000000 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/poet/smartcode/SmartCodeBlock.kt +++ /dev/null @@ -1,9 +0,0 @@ -package com.github.klee0kai.thekey.stone.ksp.poet.smartcode - -import com.squareup.kotlinpoet.CodeBlock - -class SmartCodeBlock( - val smartCode: SmartCode? = null, - val codeBlock: CodeBlock? = null, -) - diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/poet/smartcode/SmartCodeExt.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/poet/smartcode/SmartCodeExt.kt deleted file mode 100644 index a8d9be26..00000000 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/poet/smartcode/SmartCodeExt.kt +++ /dev/null @@ -1,71 +0,0 @@ -package com.github.klee0kai.thekey.stone.ksp.poet.smartcode - -import com.github.klee0kai.thekey.stone.ksp.poet.PoetDsl -import com.github.klee0kai.thekey.stone.ksp.property.map -import com.google.devtools.ksp.symbol.KSAnnotation -import com.squareup.kotlinpoet.CodeBlock -import com.squareup.kotlinpoet.asTypeName - -fun SmartCode.add( - code: String, -) { - add(CodeBlock.of(code)) -} - -fun SmartCode.add( - code: String, - vararg arg: Any -) { - add(CodeBlock.of(code, *arg)) -} - -fun SmartCode.declareLocalVariable( - variableName: String, - qualifiers: List, - initVariable: SmartCode, -) = add { - initVariable.providingType.map { type -> - DeclareLocalVariable( - variableName = variableName, - type = type ?: Unit::class.asTypeName(), - qualifierAnnotations = qualifiers, - ) - } - - add("val %L = ", variableName) - add(initVariable) - add("\n") -} - - -@PoetDsl -fun smartCode( - block: SmartCode.() -> Unit, -) = SmartCode() - .apply(block) - - -@PoetDsl -fun smartCode( - string: String, -) = SmartCode() - .apply { - add(string) - } - - -@PoetDsl -fun SmartCode.add( - block: SmartCode.() -> Unit, -) { - val parentBlock = this - val builder = SmartCode(parentBlock) - availableVariables.source = parentBlock.availableVariables - builder.block() - parentBlock.add(builder) -} - - - - - From e1c75e8176d1a62b6a01ca2952dac70b02718495 Mon Sep 17 00:00:00 2001 From: klee0kai Date: Mon, 8 Dec 2025 12:41:56 +0100 Subject: [PATCH 045/122] module graph arch --- .../ksp/helpers/ComponentDeclarationExt.kt | 11 +- .../stone/ksp/helpers/StoneFileNamesExt.kt | 3 +- .../ksp/helpers/invokecall/InvokeCall.kt | 235 ++++--- .../ksp/helpers/invokecall/ModulesGraph.kt | 572 +++++++++--------- .../ksp/helpers/invokecall/ProvideDep.kt | 32 +- .../helpers/invokecall/model/FieldDetail.kt | 50 ++ .../helpers/invokecall/model/MethodDetail.kt | 51 ++ .../stone/ksp/target/GenModuleProcessor.kt | 3 +- .../thekey/stone/ksp/utils/CollectionExt.kt | 4 +- .../stone/ksp/utils/RecursiveDetector.kt | 35 ++ .../__hidden__/provide/ProvideBuilder.kt | 4 +- 11 files changed, 588 insertions(+), 412 deletions(-) create mode 100644 stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/invokecall/model/FieldDetail.kt create mode 100644 stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/invokecall/model/MethodDetail.kt create mode 100644 stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/utils/RecursiveDetector.kt diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/ComponentDeclarationExt.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/ComponentDeclarationExt.kt index 6ee50ea3..a9492557 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/ComponentDeclarationExt.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/ComponentDeclarationExt.kt @@ -9,11 +9,7 @@ import com.github.klee0kai.thekey.stone.ksp.helpers.annotations.findComponentAnn import com.github.klee0kai.thekey.stone.ksp.ksp.isType import com.google.devtools.ksp.KspExperimental import com.google.devtools.ksp.processing.Resolver -import com.google.devtools.ksp.symbol.KSAnnotated -import com.google.devtools.ksp.symbol.KSAnnotation -import com.google.devtools.ksp.symbol.KSClassDeclaration -import com.google.devtools.ksp.symbol.KSFunctionDeclaration -import com.google.devtools.ksp.symbol.KSType +import com.google.devtools.ksp.symbol.* import com.squareup.kotlinpoet.ClassName import com.squareup.kotlinpoet.asClassName import com.squareup.kotlinpoet.ksp.toClassName @@ -39,6 +35,11 @@ val KSClassDeclaration.allIdentifierTypes: Sequence .flatMap { it.identifiers } } +fun KSFunctionDeclaration.identifierParameters( + allIdentifierTypes: List, +) = parameters.filter { it.type.resolve() in allIdentifierTypes } + + val KSClassDeclaration.wrapperProviders: Sequence get() { val componentCl = this@wrapperProviders diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/StoneFileNamesExt.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/StoneFileNamesExt.kt index 5ce194b4..f155161d 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/StoneFileNamesExt.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/StoneFileNamesExt.kt @@ -16,7 +16,8 @@ val String.hiddenModuleClName: String get() = "${this}_HMStone" val String.wrapperClName: String get() = "${this}_TWStone" -val KSFunctionDeclaration.cacheControlMethodName get() = "__" + simpleName.asString() + "_cache" +val KSFunctionDeclaration.cacheControlMethodName get() = simpleName.asString().cacheControlMethodName +val String.cacheControlMethodName get() = "__" + this + "_cache" val KSClassDeclaration.componentStoneClName get() = ClassName( diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/invokecall/InvokeCall.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/invokecall/InvokeCall.kt index 64e4f455..837e0b8c 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/invokecall/InvokeCall.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/invokecall/InvokeCall.kt @@ -1,16 +1,15 @@ package com.github.klee0kai.thekey.stone.ksp.helpers.invokecall -import com.github.klee0kai.thekey.stone.ksp.helpers.invokecall.GenArgumentFunctions.unwrapArgument -import com.github.klee0kai.thekey.stone.ksp.helpers.qualifierAnnotations -import com.github.klee0kai.thekey.stone.ksp.helpers.wrap.ClassNameUtils -import com.github.klee0kai.thekey.stone.ksp.poet.smartcode.SmartCode -import com.github.klee0kai.thekey.stone.ksp.poet.smartcode.smartCode +import com.github.klee0kai.stone.__hidden__.provide.ProvideBuilder +import com.github.klee0kai.thekey.stone.ksp.helpers.invokecall.model.FieldDetail +import com.github.klee0kai.thekey.stone.ksp.helpers.invokecall.model.MethodDetail +import com.github.klee0kai.thekey.stone.ksp.helpers.wrap.WrapHelper +import com.github.klee0kai.thekey.stone.ksp.utils.LocalFieldName import com.google.devtools.ksp.symbol.KSAnnotation -import com.google.devtools.ksp.symbol.KSFunctionDeclaration -import com.google.devtools.ksp.symbol.KSValueParameter import com.squareup.kotlinpoet.CodeBlock +import com.squareup.kotlinpoet.ParameterizedTypeName.Companion.parameterizedBy import com.squareup.kotlinpoet.TypeName -import com.squareup.kotlinpoet.ksp.toClassName +import com.squareup.kotlinpoet.asClassName import java.util.* /** @@ -22,7 +21,8 @@ import java.util.* * Arguments for chaining are reused by type. */ class InvokeCall( - val invokeSequenceVariants: List>, + var wrapHelper: WrapHelper, + val invokeSequenceVariants: List>, val flags: InvokeProvideFlags = InvokeProvideFlags(), ) { @@ -32,10 +32,12 @@ class InvokeCall( * @param callSequence ordered methods in invoke sequence */ constructor( - vararg callSequence: KSFunctionDeclaration, + wrapHelper: WrapHelper, + callSequence: List, flags: InvokeProvideFlags = InvokeProvideFlags() ) : this( - invokeSequenceVariants = listOf(callSequence.toList()), + wrapHelper = wrapHelper, + invokeSequenceVariants = listOf(callSequence), flags = flags, ) @@ -44,13 +46,16 @@ class InvokeCall( * * @param variants all variants from best to worse */ - constructor(variants: MutableCollection) : this( + constructor( + wrapHelper: WrapHelper, + variants: List, + ) : this( + wrapHelper = wrapHelper, invokeSequenceVariants = variants.flatMap { it.invokeSequenceVariants }, flags = variants.fold(InvokeProvideFlags()) { acc, value -> acc.merge(value.flags) } ) - fun bestSequence(): List = invokeSequenceVariants[0] - + fun bestSequence(): List = invokeSequenceVariants[0] fun qualifierAnnotations( crossing: Boolean, @@ -58,7 +63,7 @@ class InvokeCall( val allQualifiersLists = LinkedList>() for (variant in invokeSequenceVariants) { val qualifiers = HashSet() - for (m in variant) qualifiers.addAll(m.qualifierAnnotations) + for (m in variant) qualifiers.addAll(m.qualifierAnns) allQualifiersLists.add(qualifiers) } if (allQualifiersLists.isEmpty()) return mutableSetOf() @@ -82,10 +87,11 @@ class InvokeCall( for (invokeSequence in invokeSequenceVariants) { for (m in invokeSequence) { argsTypes.addAll( - m.parameters.map { + m.args.map { ProvideDep( - type = it.type.resolve(), - qualifiers = m.qualifierAnnotations.toList(), + methodName = null, + typeName = wrapHelper.listWrapTypeIfNeed(it.type), + qualifierAnns = m.qualifierAnns.toSet(), ) }) } @@ -98,15 +104,15 @@ class InvokeCall( * * @return return type */ - fun resultType(): TypeName { - return ClassNameUtils.rawTypeOf(rawReturnType()) - } + fun resultType(): TypeName = wrapHelper.nonWrappedType(rawReturnType()) fun rawReturnType(): TypeName { val invokeSequence = bestSequence() - return invokeSequence[invokeSequence.size - 1].returnType?.resolve()!!.toClassName() + return invokeSequence[invokeSequence.size - 1].returnType } + fun best() = InvokeCall(wrapHelper, bestSequence()) + /** * Generate invoke code bloke * @@ -115,10 +121,10 @@ class InvokeCall( * @return new code block without semicolon */ fun invokeCode( - envFields: List, - vararg argGen: (TypeName) -> CodeBlock, + envFields: List, + vararg argGen: (FieldDetail) -> CodeBlock?, ): CodeBlock { - val argGens = LinkedList<(TypeName) -> CodeBlock>() + val argGens = LinkedList<(FieldDetail) -> CodeBlock?>() argGens.add(unwrapArgument(envFields)) argGens.addAll(argGen) @@ -126,119 +132,102 @@ class InvokeCall( var invokeCount = 0 for (m in bestSequence()) { var argCount = 0 - val argsCodeBuilder: CodeBlock.Builder = CodeBlock.builder() - for (arg in m.parameters) { + val argsCodeBuilder = CodeBlock.builder() + for (arg in m.args) { if (argCount++ > 0) argsCodeBuilder.add(",") - val argCode = argGens.firstNotNullOf { it.invoke(arg.type.resolve().toClassName()) } - argsCodeBuilder.add(argCode) + val argCode = argGens.firstNotNullOfOrNull { it.invoke(arg) } + argsCodeBuilder.add(argCode ?: CodeBlock.of("null")) } if (invokeCount++ > 0) invokeBuilder.add(".") - invokeBuilder.add("%L(%L)", m.simpleName.asString(), argsCodeBuilder.build()) + invokeBuilder.add("%L(%L)", m.methodName, argsCodeBuilder.build()) } + return invokeBuilder.build() } - fun invokeBest(): SmartCode = smartCode { - providingType.value = resultType() -// TODO transform(invokeSequence(bestSequence()), resultType()) - } + fun invokeAllToList( + declaredFields: List, + ): CodeBlock { + val provType = List::class.asClassName().parameterizedBy(resultType()) + val listFieldName: String = LocalFieldName.genLocalFieldName() + + val builder = CodeBlock.builder() -// return SmartCode -// .builder() -// .providingType(resultType()) -// .withLocals({ builder -}) -// } + builder.add( + "%T{ %L -> \n", + ProvideBuilder::class.asClassName().parameterizedBy(resultType()), + listFieldName, + ) - fun invokeAllToList() = smartCode { -// TODO -// val provType: TypeName? = ParameterizedTypeName.get(ClassName.get(MutableList::class.java), resultType()) -// return SmartCode -// .builder() -// .providingType(provType) -// .withLocals({ builder -> -// val listFieldName: String? = genLocalFieldName() -// builder.add( -// CodeBlock.of( -// "new \$T( ( \$L ) -> { \n", -// ParameterizedTypeName.get(ClassName.get(ProvideBuilder::class.java), resultType()), -// listFieldName -// ) -// ) -// for (sequence in invokeSequenceVariants) { -// val seqCode: SmartCode = invokeSequence(sequence) -// if (WrapHelper.isList(seqCode.providingType)) { -// builder.add(listFieldName) -// .add(".addAll(") -// .add(transform(seqCode, provType)) -// .add(");\n") -// } else { -// builder.add(listFieldName) -// .add(".add(") -// .add(transform(seqCode, resultType())) -// .add(");\n") -// } -// } -// builder.add(" }).all() ") -// builder -// }) + builder.add(CodeBlock.of("buildList<%T>{ \n", resultType())) + for (sequence in invokeSequenceVariants) { + val invokeCall = InvokeCall(wrapHelper, sequence) + val seqCodeBlock = invokeCall.invokeCode(declaredFields) + + if (wrapHelper.isList(invokeCall.rawReturnType())) { + builder + .add(listFieldName) + .add(".addAll(") + .add( + wrapHelper.transform( + invokeCall.rawReturnType(), + provType, + seqCodeBlock + ) + ) + .add(");\n") + } else { + builder + .add(listFieldName) + .add(".add(") + .add( + wrapHelper.transform( + invokeCall.rawReturnType(), + resultType(), + seqCodeBlock + ) + ) + .add(");\n") + } + } + builder.add(" }.all() ") + return builder.build() } - private fun invokeSequence( - sequence: List, - ): SmartCode { - TODO() -// return SmartCode.builder().withLocals({ builder -> -// var invokeCount = 0 -// for (m in sequence) { -// if (invokeCount++ > 0) builder.add(".") -// builder.add(m.methodName) -// .add("(") -// -// var argCount = 0 -// for (arg in m.args) { -// if (argCount++ > 0) builder.add(", ") -// val isList: Boolean = isList(arg.type) -// val typeFields: MutableList? = ListUtils.filter( -// builder.getDeclaredFields(), -// { i, f -> nonWrappedType(f.type) == nonWrappedType(arg.type) }) -// -// var field: FieldDetail? = if (isList) ListUtils.first( -// typeFields, -// { i, f -> isList(f.type) && f.qualifierAnns == arg.qualifierAnns } -// ) else null -// if (field == null) { -// //non list -// field = ListUtils.first(typeFields, { i, f -> f.qualifierAnns == arg.qualifierAnns }) -// } -// -// if (field == null) { -// builder.add("null", null) -// } else { -// // unwrap type -// builder.add( -// transform( -// SmartCode.of(field.name, mutableSetOf(field.name)) -// .providingType(field.type), -// arg.type -// ) -// ) -// } -// } -// -// builder.add(")") -// } -// builder -// }) -// .providingType(sequence.get(sequence.size - 1).returnType) + private fun unwrapArgument( + envFields: List, + ): (FieldDetail) -> CodeBlock? { + return { arg -> + val isWannaList = wrapHelper.isList(arg.type) + val typeFields = envFields.filter { f -> + wrapHelper.nonWrappedType(f.type) == wrapHelper.nonWrappedType(arg.type) + } + var field = if (isWannaList) typeFields.firstOrNull { f -> + wrapHelper.isList(f.type) && f.qualifierAnns == arg.qualifierAnns + } else null + + if (field == null) { + //non list + field = typeFields.firstOrNull { f -> f.qualifierAnns == arg.qualifierAnns } + } + + if (field != null) { + wrapHelper.transform(field.type, arg.type, CodeBlock.of(field.name)) + } else { + null + } + } } override fun toString(): String { val builder = StringBuilder() - if (invokeSequenceVariants.size <= 1) for (qualifierAnn in qualifierAnnotations(false)) { - builder.append(qualifierAnn.toString()) - .append(" ") + if (invokeSequenceVariants.size <= 1) { + for (qualifierAnn in qualifierAnnotations(false)) { + builder.append(qualifierAnn.toString()) + .append(" ") + } } var variantIndx = 0 for (variant in invokeSequenceVariants) { @@ -246,9 +235,9 @@ class InvokeCall( var secIndx = 0 for (m in variant) { if (secIndx++ > 0) builder.append(".") - builder.append(m.simpleName.asString()) + builder.append(m.methodName) .append("(") - .append(m.parameters.joinToString(", ") { it.type.resolve().toClassName().simpleName }) + .append(m.args.joinToString(", ") { it.type.toString() }) .append(")") } } diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/invokecall/ModulesGraph.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/invokecall/ModulesGraph.kt index 84f58efd..04b31e3a 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/invokecall/ModulesGraph.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/invokecall/ModulesGraph.kt @@ -1,23 +1,47 @@ +@file:OptIn(KspExperimental::class) + package com.github.klee0kai.thekey.stone.ksp.helpers.invokecall +import com.github.klee0kai.stone.__hidden__.CacheAction import com.github.klee0kai.stone.__hidden__.provide.ProvideBuilder -import com.github.klee0kai.thekey.stone.ksp.helpers.isListType +import com.github.klee0kai.stone.annotations.module.BindInstance +import com.github.klee0kai.stone.annotations.module.Provide +import com.github.klee0kai.stone.weakref.Ref +import com.github.klee0kai.thekey.stone.ksp.exceptions.IncorrectSignatureException +import com.github.klee0kai.thekey.stone.ksp.exceptions.ObjectNotProvidedException +import com.github.klee0kai.thekey.stone.ksp.exceptions.RecursiveProviding +import com.github.klee0kai.thekey.stone.ksp.exceptions.StoneException +import com.github.klee0kai.thekey.stone.ksp.helpers.cacheControlMethodName +import com.github.klee0kai.thekey.stone.ksp.helpers.identifierParameters +import com.github.klee0kai.thekey.stone.ksp.helpers.invokecall.model.* +import com.github.klee0kai.thekey.stone.ksp.helpers.qualifierAnnotations import com.github.klee0kai.thekey.stone.ksp.helpers.wrap.WrapHelper -import com.github.klee0kai.thekey.stone.ksp.poet.smartcode.add -import com.github.klee0kai.thekey.stone.ksp.poet.smartcode.declareLocalVariable -import com.github.klee0kai.thekey.stone.ksp.poet.smartcode.smartCode +import com.github.klee0kai.thekey.stone.ksp.ksp.getAllMethods +import com.github.klee0kai.thekey.stone.ksp.ksp.isNotPrimitive import com.github.klee0kai.thekey.stone.ksp.utils.LocalFieldName.genLocalFieldName +import com.github.klee0kai.thekey.stone.ksp.utils.RecursiveDetector +import com.github.klee0kai.thekey.stone.ksp.utils.removeDoubles +import com.google.devtools.ksp.KspExperimental +import com.google.devtools.ksp.getAnnotationsByType import com.google.devtools.ksp.symbol.KSAnnotation +import com.google.devtools.ksp.symbol.KSClassDeclaration +import com.google.devtools.ksp.symbol.KSFunctionDeclaration import com.google.devtools.ksp.symbol.KSType +import com.squareup.kotlinpoet.ClassName +import com.squareup.kotlinpoet.CodeBlock import com.squareup.kotlinpoet.ParameterizedTypeName.Companion.parameterizedBy import com.squareup.kotlinpoet.TypeName import com.squareup.kotlinpoet.asClassName import com.squareup.kotlinpoet.ksp.toClassName +import java.util.* + +class ModulesGraph( + val wrapHelper: WrapHelper, + val identifierTypes: List, +) { -class ModulesGraph { - private val provideTypeCodes = HashMap>() - private val cacheControlTypeCodes = HashMap>() - private val wrapHelper = WrapHelper() + private val provideTypeCodes = HashMap>() + private val cacheControlTypeCodes = HashMap>() /** * Methods graph build. @@ -26,261 +50,265 @@ class ModulesGraph { * @param module module's class */ fun collectFromModule( -// provideModuleMethod: MethodDetail?, -// module: ClassDetail, + provideModuleMethod: KSFunctionDeclaration?, ) { -// val iModuleInterface: ClassDetail = AnnotationProcessor.allClassesHelper.iModule -// for (m in module.getAllMethods(false, true, "")) { -// val provTypeName: TypeName = nonWrappedType(m.returnType) -// if (provTypeName.isPrimitive() || provTypeName === TypeName.VOID) continue -// if (iModuleInterface.findMethod(m, false) != null) continue -// val isCached = -// !m.hasAnnotations(ProvideAnn::class.java) || m.ann(ProvideAnn::class.java).isCachingProvideType() -// val isBindInstance: Boolean = m.hasAnnotations(BindInstanceAnn::class.java) -// var invokeProvideFlags = if (isCached) INVOKE_PROVIDE_OBJECT_CACHED else 0 -// invokeProvideFlags = invokeProvideFlags or if (isBindInstance) INVOKE_PROVIDE_BIND_INSTANCE else 0 -// -// provideTypeCodes.putIfAbsent(provTypeName, HashSet()) -// provideTypeCodes.get(provTypeName)!!.add(InvokeCall(invokeProvideFlags, provideModuleMethod, m)) -// -// val cacheControlMethod: MethodDetail = MethodDetail() -// cacheControlMethod.methodName = cacheControlMethodName(m.methodName) -// cacheControlMethod.args.add(FieldDetail.simple("__action", ClassName.get(CacheAction::class.java))) -// for (it in m.args) { -// if (!((it.type is ClassName) && allClassesHelper.allIdentifiers.contains(it.type))) continue -// cacheControlMethod.args.add(it) -// } -// cacheControlMethod.returnType = listWrapTypeIfNeed(m.returnType) -// cacheControlMethod.qualifierAnns = m.qualifierAnns -// -// cacheControlTypeCodes.putIfAbsent(provTypeName, HashSet()) -// cacheControlTypeCodes.get(provTypeName)!!.add(InvokeCall(provideModuleMethod, cacheControlMethod)) -// } - } + val module = provideModuleMethod?.returnType?.resolve()?.declaration as? KSClassDeclaration ?: return + for (m in module.getAllMethods(false, true, "")) { + if (m.returnType?.resolve()?.isNotPrimitive == false) continue + val returnType = m.returnType?.resolve()?.toClassName() ?: continue + val provTypeName = wrapHelper.nonWrappedType(returnType) + val isCached = m.getAnnotationsByType(Provide::class) + .firstOrNull()?.cache !in listOf(Provide.CacheType.Factory, null) + val isBindInstance = m.getAnnotationsByType(BindInstance::class).firstOrNull() != null - fun codeProvideType( - methodName: String, - returnType: KSType, - qualifierAnns: List = emptyList(), - ) = smartCode { - val isWrappedReturn = wrapHelper.isSupport(returnType.toClassName()) - val isListReturn = returnType.isListType() - val providingType = if (isWrappedReturn) { - wrapHelper.nonWrappedType(returnType.toClassName()) - } else { - returnType.toClassName() - } - this.providingType.value = providingType + provideTypeCodes.putIfAbsent(provTypeName, HashSet()) + provideTypeCodes[provTypeName]?.add( + InvokeCall( + wrapHelper = wrapHelper, + callSequence = listOf(provideModuleMethod.toMethodDetail(), m.toMethodDetail()), + flags = InvokeProvideFlags( + provideObjectCached = isCached, + provideBindInstance = isBindInstance, + ), + ) + ) - val provideTypeInvokes = provideInvokesWithDeps(ProvideDep(methodName, returnType, qualifierAnns)) - if (provideTypeInvokes.isEmpty()) { - // TODO throw error - return@smartCode - } + val cacheControlMethod = MethodDetail( + methodName = m.cacheControlMethodName, + returnType = wrapHelper.listWrapTypeIfNeed(returnType), + qualifierAnns = m.qualifierAnnotations.toList(), + args = buildList { + add(FieldDetail.simple("__action", CacheAction::class.asClassName())) + addAll(m.identifierParameters(identifierTypes).map { it.toFieldDetail() }) + }, + ) - if (SIMPLE_PROVIDE_OPTIMIZING && provideTypeInvokes.size == 1 && !isListReturn) { - val invokeCall = provideTypeInvokes.first() - add( - wrapHelper.transform( - code = smartCode { - add(invokeCall.invokeBest()) - this.providingType.value = invokeCall.resultType() - }, - wannaType = returnType.toClassName(), + cacheControlTypeCodes.putIfAbsent(provTypeName, HashSet()) + cacheControlTypeCodes.get(provTypeName) + ?.add( + InvokeCall( + wrapHelper = wrapHelper, + callSequence = listOf(provideModuleMethod.toMethodDetail(), cacheControlMethod) + ) ) - ) - return@smartCode } + } + fun codeProvideType( + methodName: String?, + returnType: TypeName, + qualifierAnns: Set, + declaredFields: List + ): CodeBlock? { + val isWrappedReturn = wrapHelper.isSupport(returnType) + val providingType = if (isWrappedReturn) wrapHelper.nonWrappedType(returnType) else returnType + val provideDeps = HashSet() + provideDeps.add( + ProvideDep( + methodName = methodName, + typeName = wrapHelper.listWrapTypeIfNeed(returnType), + qualifierAnns = qualifierAnns, + ) + ) + val provideTypeInvokes = provideInvokesWithDeps(provideDeps.iterator().next()) + if (provideTypeInvokes == null || provideTypeInvokes.isEmpty()) { + return null + } + for (provideTypeInvoke in provideTypeInvokes) provideDeps.addAll(provideTypeInvoke.argDeps()) + if (provideTypeInvokes.size == 1 && !wrapHelper.isList(returnType)) { + val invokeCall = provideTypeInvokes.first().best() + return wrapHelper.transform( + invokeCall.rawReturnType(), + returnType, + invokeCall.invokeCode(declaredFields) + ) + } val provideBuilder = ProvideBuilder::class.asClassName().parameterizedBy(providingType) val provideBuilderList = Collection::class.asClassName().parameterizedBy(providingType) + val listFieldName = genLocalFieldName() - add("%T( ( %L ) -> { \n", provideBuilder, listFieldName) + val localVariables = LinkedList(declaredFields) + val codeBlock = CodeBlock.builder() + codeBlock.add("%T{ %L -> \n", provideBuilder, listFieldName) for (inv in provideTypeInvokes) { - val depFieldName = genLocalFieldName() -// val isCacheProvide = (inv.flags and INVOKE_PROVIDE_OBJECT_CACHED) !== 0 -// val singleDepField: FieldDetail = FieldDetail.simple(genLocalFieldName(), null) -// val listDepField: FieldDetail = FieldDetail.simple(genLocalFieldName(), null) -// val isListInv = inv.invokeSequenceVariants.size() > 1 - - add { - if (inv.flags.provideObjectCached) { -// declareLocalVariable() + val isCacheProvide = inv.flags.provideObjectCached + val isSingleDepRequired = provideDeps.any { + wrapHelper.nonWrappedType(it.typeName) == wrapHelper.nonWrappedType(inv.resultType()) + && !wrapHelper.isList(it.typeName) + } + val isListDepRequired = provideDeps.any { + wrapHelper.nonWrappedType(it.typeName) == wrapHelper.nonWrappedType(inv.resultType()) + && wrapHelper.isList(it.typeName) + } + var singleDepField = FieldDetail( + name = genLocalFieldName(), + type = inv.resultType(), + qualifierAnns = inv.qualifierAnnotations(true) + ) + val listDepField = FieldDetail( + name = genLocalFieldName(), + type = Ref::class.asClassName().parameterizedBy( + List::class.asClassName().parameterizedBy( + inv.resultType() + ) + ), + qualifierAnns = inv.qualifierAnnotations(true) + ) + + if (isSingleDepRequired) { + if (isCacheProvide) { + codeBlock.add("val %L : %T = ", singleDepField.name, inv.resultType()) + .add( + wrapHelper.transform( + inv.best().rawReturnType(), + inv.resultType(), + inv.best().invokeCode(localVariables) + ) + ) + .addStatement("") + + + localVariables.add(singleDepField) } else { + singleDepField = singleDepField + .copy( + type = Ref::class.asClassName().parameterizedBy(inv.resultType()), + ) + codeBlock.add("val %L: %T = { ", singleDepField.name, singleDepField.type) + .add( + wrapHelper.transform( + inv.best().rawReturnType(), + inv.resultType(), + inv.best().invokeCode(localVariables), + ) + ) + .addStatement(" } ") + + localVariables.add(singleDepField) } + } + + if (isListDepRequired) { + codeBlock.add("val %L : %T = { ", listDepField.name, listDepField.type) + .add(inv.invokeAllToList(localVariables)) + .addStatement(" } ") + + localVariables.add(listDepField) + } + if (inv.resultType() == providingType) { + if (wrapHelper.isList(returnType)) { + codeBlock.add( + "%L.addAll( %L )\n", + listFieldName, + wrapHelper.transform( + listDepField.type, + provideBuilderList, + CodeBlock.of(listDepField.name) + ) + ) + } else { + codeBlock.add( + "%L.add( %L );\n", + listFieldName, + wrapHelper.transform( + singleDepField.type, + providingType, + CodeBlock.of(singleDepField.name) + ) + ) + } + if (!wrapHelper.isList(returnType)) break } + } -// -// builder.withLocals({ localBuilder -> -// // provide single objects -// if (isCacheProvide) { -// localBuilder.localVariable(singleDepField.name, inv.qualifierAnnotations(true), inv.invokeBest()) -// singleDepField.type = inv.resultType() -// } else { -// singleDepField.type = ParameterizedTypeName.get(ClassName.get(Ref::class.java), inv.resultType()) -// localBuilder.localVariable( -// singleDepField.name, inv.qualifierAnnotations(true), SmartCode.builder() -// .add("() -> ") -// .add(inv.invokeBest()) -// .providingType(singleDepField.type) -// ) -// } -// localBuilder -// }) -// -// builder.withLocals({ localBuilder -> -// // provide list objects -// listDepField.type = ParameterizedTypeName.get( -// ClassName.get(Ref::class.java), -// ParameterizedTypeName.get( -// ClassName.get(MutableList::class.java), -// inv.resultType() -// ) -// ) -// localBuilder.localVariable( -// listDepField.name, inv.qualifierAnnotations(true), SmartCode.builder() -// .add("() -> ") -// .add(inv.invokeAllToList()) -// .providingType(listDepField.type) -// ) -// localBuilder -// }) -// -// if (inv.resultType() == providingType) { -// builder.withLocals({ localBuilder -> -// if (isListReturn) { -// localBuilder -// .add(listFieldName) -// .add(".addAll( ") -// .add( -// transform( -// SmartCode.of( -// listDepField.name, -// mutableSetOf(listDepField.name) -// ) -// .providingType(listDepField.type), -// provideBuilderList -// ) -// ).add(");\n") -// } else { -// localBuilder -// .add(listFieldName) -// .add(".add( ") -// .add( -// transform( -// SmartCode.of( -// singleDepField.name, -// mutableSetOf(singleDepField.name) -// ) -// .providingType(singleDepField.type), -// providingType -// ) -// ).add(");\n") -// } -// localBuilder -// }) -// if (!isListReturn) break -// } + codeBlock.add("\n })") + if (wrapHelper.isList(returnType)) { + codeBlock.add(".all() ") + + return wrapHelper.transform( + List::class.asClassName().parameterizedBy(providingType), + returnType, + codeBlock.build() + ) + + } else { + codeBlock.add(".first() ") + + return wrapHelper.transform( + providingType, + returnType, + codeBlock.build() + ) } -// -// -// builder.add("\n })") -// if (WrapHelper.isList(returnType)) { -// builder.add(".all() ") -// .providingType( -// ParameterizedTypeName.get( -// ClassName.get(MutableList::class.java), -// providingType -// ) -// ) -// } else { -// builder.add(".first() ") -// .providingType(providingType) -// } -// return WrapHelper.transform(builder, returnType) } - fun provideInvokesWithDeps( - provideDep: ProvideDep, - ): List { - TODO() -// var provideTypeInvokes: LinkedList = LinkedList() -// var needProvideDeps: LinkedList = LinkedList() -// val needProvideDepsRecursiveDetector: RecursiveDetector = RecursiveDetector() -// needProvideDeps.add(provideDep) -// var loopCount = 0 -// -// // provide dependencies while not provide all -// while (!needProvideDeps.isEmpty()) { -// val rawDep: ProvideDep = needProvideDeps.pollFirst() -// val dep: TypeName = nonWrappedType(rawDep.typeName) -// val invokeCall: InvokeCall? = provideTypeInvokeCall( -// provideTypeCodes, -// dep, -// rawDep.qualifierAnns, -// rawDep.methodName, -// isList(rawDep.typeName) -// ) -// if (invokeCall == null) { -// if (provideDep == rawDep) { -// return null -// } -// -// throw ObjectNotProvidedException( -// createErrorMes() -// .errorProvideType(dep.toString()) -// .build() -// ) -// } -// -// val isBindInstanceInvoke = (invokeCall.flags and INVOKE_PROVIDE_BIND_INSTANCE) !== 0 -// val newDeps: MutableList = ListUtils.filter(invokeCall.argDeps(), { i, it -> -// if (isBindInstanceInvoke && rawDep.typeName == it.typeName) { -// // bind instance case. Argument and return type are equals -// return@filter false -// } -// // qualifies not need to provide -// val argNonWrapped: TypeName? = nonWrappedType(it.typeName) -// argNonWrapped is ClassName && !allClassesHelper.allIdentifiers.contains(argNonWrapped) -// }) -// -// needProvideDeps.addAll(newDeps) -// needProvideDeps = ListUtils.removeDoublesRight(needProvideDeps, Objects::equals) -// val recursiveDetected = -// !newDeps.isEmpty() && needProvideDepsRecursiveDetector.next(needProvideDeps.hashCode()) -// if (recursiveDetected) { -// throw RecursiveProviding( -// createErrorMes() -// .errorProvideType(provideDep.typeName.toString()) -// .recursiveProviding() -// .build() -// ) -// } -// if (loopCount++ > MAX_PROVIDE_RESOLVE_COUNT) { -// throw StoneException( -// createErrorMes() -// .errorProvideType(provideDep.typeName.toString()) -// .add("long providing loop for type. Stone library Error.") -// .build(), -// null -// ) -// } -// -// provideTypeInvokes.add(invokeCall) -// provideTypeInvokes = ListUtils.removeDoublesRight(provideTypeInvokes, { it1, it2 -> -// it1.resultType() == it2.resultType() -// && it1.qualifierAnnotations(true) == it2.qualifierAnnotations(true) -// }) -// } -// Collections.reverse(provideTypeInvokes) -// return provideTypeInvokes + fun provideInvokesWithDeps(provideDep: ProvideDep): List? { + var provideTypeInvokes = LinkedList() + var needProvideDeps = LinkedList() + val needProvideDepsRecursiveDetector = RecursiveDetector() + needProvideDeps.add(provideDep) + var loopCount = 0 + + // provide dependencies while not provide all + while (!needProvideDeps.isEmpty()) { + val rawDep = needProvideDeps.pollFirst() + val dep = wrapHelper.nonWrappedType(rawDep.typeName) + val invokeCall = provideTypeInvokeCall( + provideTypeCodes, + dep, + rawDep.qualifierAnns, + rawDep.methodName, + wrapHelper.isList(rawDep.typeName) + ) + if (invokeCall == null) { + if (provideDep == rawDep) return null + throw ObjectNotProvidedException("Error provide type ${rawDep.typeName}") + } + + val isBindInstanceInvoke = invokeCall.flags.provideBindInstance + val newDeps = invokeCall.argDeps().filter { + if (isBindInstanceInvoke && rawDep.typeName == it.typeName) { + // bind instance case. Argument and return type are equals + return@filter false + } + // qualifies not need to provide + val argNonWrapped = wrapHelper.nonWrappedType(it.typeName) + argNonWrapped is ClassName && !identifierTypes.any { it.toClassName() == argNonWrapped } + } + needProvideDeps.addAll(newDeps) + + needProvideDeps = LinkedList(needProvideDeps.removeDoubles { a, b -> a == b }) + + val recursiveDetected = !newDeps.isEmpty() + && needProvideDepsRecursiveDetector.next(needProvideDeps.hashCode()) + if (recursiveDetected) { + throw RecursiveProviding("Error provide type ${provideDep.typeName}. Recursive providing detected.") + } + + if (loopCount++ > MAX_PROVIDE_RESOLVE_COUNT) { + throw StoneException( + "Error provide type ${provideDep.typeName}. " + + "Long providing loop for type. Stone library Error. " + ) + } + + provideTypeInvokes.add(invokeCall) + provideTypeInvokes = LinkedList( + provideTypeInvokes.removeDoubles { it1, it2 -> + it1.resultType() == it2.resultType() + && it1.qualifierAnnotations(true) == it2.qualifierAnnotations(true) + } + ) + } + provideTypeInvokes.reverse() + return provideTypeInvokes } /** @@ -291,51 +319,51 @@ class ModulesGraph { * @return cache control invoke call */ fun invokeControlCacheForType( - provideMethodName: String?, + provideMethodName: String, typeName: TypeName, qualifierAnns: Set - ): InvokeCall? { - TODO() -// val cacheControlMethodName: String? = cacheControlMethodName(provideMethodName) -// return provideTypeInvokeCall(cacheControlTypeCodes, typeName, qualifierAnns, cacheControlMethodName, false) - } + ): InvokeCall? = provideTypeInvokeCall( + cacheControlTypeCodes, + typeName, + qualifierAnns, + provideMethodName.cacheControlMethodName, + false + ) + private fun provideTypeInvokeCall( provideTypeCodes: Map>, typeName: TypeName, qualifierAnns: Set, provideMethodName: String?, - listVariants: Boolean + listVariants: Boolean, ): InvokeCall? { - TODO() -// val invokeCalls: MutableSet? = provideTypeCodes.getOrDefault(typeName, null) -// if (invokeCalls == null || invokeCalls.isEmpty()) return null -// var filtered: MutableList = -// if (!listVariants || qualifierAnns != null && !qualifierAnns.isEmpty()) -// ListUtils.filter(invokeCalls, { i, it -> it.qualifierAnnotations(false) == qualifierAnns }) -// else -// LinkedList(invokeCalls) -// -// filtered = if (provideMethodName != null) ListUtils.filter(filtered, { i, it -> -// val len: Int = it.bestSequence().size() -// val mName: String? = it.bestSequence().get(len - 1).methodName -// provideMethodName == mName -// }) else filtered -// -// if (!listVariants && filtered.size > 1) { -// throw IncorrectSignatureException( -// createErrorMes() -// .errorProvideType(typeName.toString()) -// .add(": is bound multi times.\n") -// .add(java.lang.String.join(" and \n", ListUtils.format(filtered, InvokeCall::toString))) -// .build() -// ) -// } -// return if (!filtered.isEmpty()) InvokeCall(filtered) else null + val invokeCalls = provideTypeCodes.getOrDefault(typeName, null) + if (invokeCalls == null || invokeCalls.isEmpty()) return null + + var filtered = if (!listVariants || !qualifierAnns.isEmpty()) { + invokeCalls.filter { it.qualifierAnnotations(false) == qualifierAnns } + } else { + invokeCalls + } + + filtered = if (provideMethodName != null) { + filtered.filter { provideMethodName == it.bestSequence().last().methodName } + } else filtered + + if (!listVariants && filtered.size > 1) { + throw IncorrectSignatureException( + "Error provide type $typeName " + + ": is bound multi times.\n " + + filtered.joinToString(" and ") + ) + } + return if (!filtered.isEmpty()) InvokeCall(wrapHelper, variants = filtered.toList()) else null } companion object { - var SIMPLE_PROVIDE_OPTIMIZING: Boolean = true - var MAX_PROVIDE_RESOLVE_COUNT: Int = 10000 + const val SIMPLE_PROVIDE_OPTIMIZING: Boolean = true + const val MAX_PROVIDE_RESOLVE_COUNT: Int = 10000 } + } diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/invokecall/ProvideDep.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/invokecall/ProvideDep.kt index c77eacc4..ca2adb47 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/invokecall/ProvideDep.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/invokecall/ProvideDep.kt @@ -1,12 +1,32 @@ package com.github.klee0kai.thekey.stone.ksp.helpers.invokecall import com.google.devtools.ksp.symbol.KSAnnotation -import com.google.devtools.ksp.symbol.KSType - +import com.squareup.kotlinpoet.TypeName data class ProvideDep( - val methodName: String, - val type: KSType, - val qualifiers: List, -) + val methodName: String?, + val typeName: TypeName, + val qualifierAnns: Set, +) { + + override fun equals(other: Any?): Boolean { + if (this === other) return true + if (javaClass != other?.javaClass) return false + + other as ProvideDep + + if (methodName != other.methodName) return false + if (typeName != other.typeName) return false + if (qualifierAnns != other.qualifierAnns) return false + + return true + } + + override fun hashCode(): Int { + var result = methodName?.hashCode() ?: 0 + result = 31 * result + typeName.hashCode() + result = 31 * result + qualifierAnns.hashCode() + return result + } +} diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/invokecall/model/FieldDetail.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/invokecall/model/FieldDetail.kt new file mode 100644 index 00000000..a70aebc3 --- /dev/null +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/invokecall/model/FieldDetail.kt @@ -0,0 +1,50 @@ +package com.github.klee0kai.thekey.stone.ksp.helpers.invokecall.model + +import com.github.klee0kai.thekey.stone.ksp.helpers.qualifierAnnotations +import com.google.devtools.ksp.symbol.KSAnnotation +import com.google.devtools.ksp.symbol.KSValueParameter +import com.squareup.kotlinpoet.TypeName +import com.squareup.kotlinpoet.ksp.toClassName + +data class FieldDetail( + val name: String, + val type: TypeName, + val qualifierAnns: Set = emptySet(), + val kSValueParameter: KSValueParameter? = null, +) { + companion object; + + override fun equals(other: Any?): Boolean { + if (this === other) return true + if (javaClass != other?.javaClass) return false + + other as FieldDetail + + if (name != other.name) return false + if (type != other.type) return false + if (qualifierAnns != other.qualifierAnns) return false + if (kSValueParameter != other.kSValueParameter) return false + + return true + } + + override fun hashCode(): Int { + var result = name.hashCode() + result = 31 * result + type.hashCode() + result = 31 * result + qualifierAnns.hashCode() + result = 31 * result + (kSValueParameter?.hashCode() ?: 0) + return result + } + +} + +fun FieldDetail.Companion.simple(name: String, type: TypeName) = FieldDetail(name, type) + + +fun KSValueParameter.toFieldDetail() = FieldDetail( + name = name?.asString() ?: "it", + type = type.resolve().toClassName(), + qualifierAnns = qualifierAnnotations.toSet(), + kSValueParameter = this, +) + diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/invokecall/model/MethodDetail.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/invokecall/model/MethodDetail.kt new file mode 100644 index 00000000..12289d5c --- /dev/null +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/invokecall/model/MethodDetail.kt @@ -0,0 +1,51 @@ +package com.github.klee0kai.thekey.stone.ksp.helpers.invokecall.model + +import com.github.klee0kai.thekey.stone.ksp.helpers.qualifierAnnotations +import com.google.devtools.ksp.symbol.KSAnnotation +import com.google.devtools.ksp.symbol.KSFunctionDeclaration +import com.squareup.kotlinpoet.TypeName +import com.squareup.kotlinpoet.asClassName +import com.squareup.kotlinpoet.ksp.toClassName + +class MethodDetail( + val methodName: String, + val returnType: TypeName, + val args: List = emptyList(), + val qualifierAnns: List = emptyList(), + val kSValueParameter: KSFunctionDeclaration? = null, +) { + companion object + + override + + fun equals(other: Any?): Boolean { + if (this === other) return true + if (javaClass != other?.javaClass) return false + + other as MethodDetail + + if (methodName != other.methodName) return false + if (returnType != other.returnType) return false + if (args != other.args) return false + + return true + } + + override fun hashCode(): Int { + var result = methodName.hashCode() + result = 31 * result + returnType.hashCode() + result = 31 * result + args.hashCode() + return result + }; + + +} + +fun KSFunctionDeclaration.toMethodDetail() = MethodDetail( + methodName = simpleName.asString(), + returnType = returnType?.resolve()?.toClassName() ?: Unit::class.asClassName(), + args = parameters.map { it.toFieldDetail() }, + qualifierAnns = qualifierAnnotations.toList(), + kSValueParameter = this, +) + diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/GenModuleProcessor.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/GenModuleProcessor.kt index 0c5e56f0..57fed800 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/GenModuleProcessor.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/GenModuleProcessor.kt @@ -123,8 +123,7 @@ class GenModuleProcessor : TargetFileProcessor { .forEachIndexed { funIdx, function -> val bindAnn = function.getAnnotationsByType(BindInstance::class).firstOrNull() val provideAnn = function.getAnnotationsByType(Provide::class).firstOrNull() - val idArguments = function.parameters - .filter { it.type.resolve() in identifierTypes } + val idArguments = function.identifierParameters(identifierTypes) val returnType = function.returnType?.resolve() ?: return@forEachIndexed val nonWrappedType = returnType.noWrappedType(wrapperTypes) diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/utils/CollectionExt.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/utils/CollectionExt.kt index bc7f7a68..c74c1b83 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/utils/CollectionExt.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/utils/CollectionExt.kt @@ -5,11 +5,11 @@ import java.util.* fun List.removeDoubles( compare: (T, T) -> Boolean, -): LinkedList { +): List { val out = LinkedList() for (item in this) { val contains = out.any { compare.invoke(item, it) } if (!contains) out.add(item) } - return out + return out.toList() } \ No newline at end of file diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/utils/RecursiveDetector.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/utils/RecursiveDetector.kt new file mode 100644 index 00000000..850111af --- /dev/null +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/utils/RecursiveDetector.kt @@ -0,0 +1,35 @@ +package com.github.klee0kai.thekey.stone.ksp.utils + +import java.util.* + +/** + * A tortoise is chasing the hare. + * If the sequence is looped, then the hare will meet the tortoise on the next circle + * + * @param sequence type + */ +class RecursiveDetector { + + private val race = LinkedList() + private var hareStep: Long = 0 + + + /** + * Do next step. + * + * @param next next item in sequence + * @return true if sequence is cycled + */ + fun next(next: T?): Boolean { + race.add(next) + if (hareStep++ % 2 == 0L) { + race.pollFirst() + } + if (race.size <= 2) return false + + val hare = next + val turtle = race.first() + return hare == turtle + } + +} diff --git a/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/__hidden__/provide/ProvideBuilder.kt b/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/__hidden__/provide/ProvideBuilder.kt index 6a62bd30..1aca2adc 100644 --- a/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/__hidden__/provide/ProvideBuilder.kt +++ b/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/__hidden__/provide/ProvideBuilder.kt @@ -4,7 +4,7 @@ class ProvideBuilder( private val provideBody: ProvideBody ) { - interface ProvideBody { + fun interface ProvideBody { fun provide(consumer: ProvideConsumer) } @@ -21,3 +21,5 @@ class ProvideBuilder( } } + + From 5c77124290126023ba60a1a4291c51d69d9df6c2 Mon Sep 17 00:00:00 2001 From: klee0kai Date: Mon, 8 Dec 2025 16:27:22 +0100 Subject: [PATCH 046/122] gen inject method --- .../ksp/helpers/ComponentDeclarationExt.kt | 18 +- .../stone/ksp/helpers/TypeHelpersExt.kt | 13 +- .../helpers/annotations/ComponentAnnMirror.kt | 11 +- .../ksp/helpers/invokecall/InvokeCall.kt | 61 ++++--- .../ksp/helpers/invokecall/ModulesGraph.kt | 26 +-- .../ksp/helpers/invokecall/ProvideDep.kt | 25 +-- .../helpers/invokecall/model/FieldDetail.kt | 34 +--- .../helpers/invokecall/model/MethodDetail.kt | 39 +---- .../helpers/invokecall/model/QualifierAnn.kt | 16 ++ ...olderHelper.kt => ItemHolderCodeHelper.kt} | 15 +- ....kt => MultiKeyMapItemHolderCodeHelper.kt} | 19 +-- ...er.kt => SimpleMapItemHolderCodeHelper.kt} | 21 +-- ...elper.kt => SingleItemHolderCodeHelper.kt} | 19 +-- .../stone/ksp/helpers/wrap/ClassNameUtils.kt | 2 +- .../stone/ksp/helpers/wrap/WrapHelper.kt | 2 +- .../stone/ksp/ksp/KSClassDeclarationExt.kt | 3 +- .../thekey/stone/ksp/poet/CodeBlockExt.kt | 8 + .../thekey/stone/ksp/poet/FunSpecDsl.kt | 2 + .../thekey/stone/ksp/poet/TypeSpecDsl.kt | 3 +- .../poet/member/CoroutinesMemberFunctions.kt | 9 + .../thekey/stone/ksp/target/CommonPoetExt.kt | 6 +- .../target/GenModuleCacheControlProcessor.kt | 3 +- .../stone/ksp/target/GenModuleProcessor.kt | 142 ++++++++-------- .../ksp/target/component/ComponentGraphExt.kt | 35 ++++ .../target/component/ComponentsMethodsExt.kt | 5 +- .../target/component/GenComponentProcessor.kt | 156 +++++++++++++++--- .../hiddenmodule/GenHiddenModuleProcessor.kt | 2 + .../__hidden__/types/holders/TimeHolder.kt | 45 +++++ .../stone/lifecycle/StoneLifeCycleListener.kt | 2 +- .../stone/lifecycle/StoneLifeCycleOwner.kt | 4 +- .../di/base_forest/RainForestComponent.kt | 2 + 31 files changed, 449 insertions(+), 299 deletions(-) create mode 100644 stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/invokecall/model/QualifierAnn.kt rename stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/itemholder/{ItemHolderHelper.kt => ItemHolderCodeHelper.kt} (84%) rename stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/itemholder/{MultiKeyMapItemHolderHelper.kt => MultiKeyMapItemHolderCodeHelper.kt} (82%) rename stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/itemholder/{SimpleMapItemHolderHelper.kt => SimpleMapItemHolderCodeHelper.kt} (79%) rename stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/itemholder/{SingleItemHolderHelper.kt => SingleItemHolderCodeHelper.kt} (77%) create mode 100644 stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/poet/CodeBlockExt.kt create mode 100644 stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/poet/member/CoroutinesMemberFunctions.kt create mode 100644 stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/component/ComponentGraphExt.kt create mode 100644 stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/__hidden__/types/holders/TimeHolder.kt diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/ComponentDeclarationExt.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/ComponentDeclarationExt.kt index a9492557..6b7f16d6 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/ComponentDeclarationExt.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/ComponentDeclarationExt.kt @@ -3,9 +3,11 @@ package com.github.klee0kai.thekey.stone.ksp.helpers import com.github.klee0kai.stone.annotations.component.* +import com.github.klee0kai.stone.lifecycle.StoneLifeCycleOwner import com.github.klee0kai.stone.weakref.Named import com.github.klee0kai.stone.weakref.Qualifier import com.github.klee0kai.thekey.stone.ksp.helpers.annotations.findComponentAnnotation +import com.github.klee0kai.thekey.stone.ksp.ksp.isChildOf import com.github.klee0kai.thekey.stone.ksp.ksp.isType import com.google.devtools.ksp.KspExperimental import com.google.devtools.ksp.processing.Resolver @@ -13,6 +15,7 @@ import com.google.devtools.ksp.symbol.* import com.squareup.kotlinpoet.ClassName import com.squareup.kotlinpoet.asClassName import com.squareup.kotlinpoet.ksp.toClassName +import com.squareup.kotlinpoet.ksp.toTypeName fun Resolver.findComponentForModuleOrDep( moduleCl: ClassName, @@ -35,9 +38,18 @@ val KSClassDeclaration.allIdentifierTypes: Sequence .flatMap { it.identifiers } } -fun KSFunctionDeclaration.identifierParameters( +fun List.identifierParameters( allIdentifierTypes: List, -) = parameters.filter { it.type.resolve() in allIdentifierTypes } +) = filter { it.type.resolve() in allIdentifierTypes } + +fun List.notIdentifierParameters( + allIdentifierTypes: List, +) = filter { it.type.resolve() !in allIdentifierTypes } + +fun List.lifeCycleParameter() = firstOrNull { + (it.type.resolve().declaration as? KSClassDeclaration) + ?.isChildOf(StoneLifeCycleOwner::class.asClassName()) == true +} val KSClassDeclaration.wrapperProviders: Sequence @@ -82,7 +94,7 @@ val KSAnnotated.qualifierAnnotations: Sequence fun KSAnnotation.isSameAsQualifier( ann: KSAnnotation ): Boolean { - if (annotationType.resolve().toClassName() != ann.annotationType.resolve().toClassName()) return false + if (annotationType.resolve().toClassName() != ann.annotationType.resolve().toTypeName()) return false val annArguments1 = arguments.map { it.name?.asString() to it.value }.sortedBy { it.first } val annArguments2 = ann.arguments.map { it.name?.asString() to it.value }.sortedBy { it.first } return annArguments1 == annArguments2 diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/TypeHelpersExt.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/TypeHelpersExt.kt index f2a2b5a4..1b9ca4f2 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/TypeHelpersExt.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/TypeHelpersExt.kt @@ -3,11 +3,6 @@ package com.github.klee0kai.thekey.stone.ksp.helpers import com.github.klee0kai.thekey.stone.ksp.ksp.isAnyType import com.google.devtools.ksp.symbol.KSClassDeclaration import com.google.devtools.ksp.symbol.KSType -import com.squareup.kotlinpoet.ClassName -import com.squareup.kotlinpoet.ParameterizedTypeName.Companion.parameterizedBy -import com.squareup.kotlinpoet.TypeName -import com.squareup.kotlinpoet.asClassName -import com.squareup.kotlinpoet.ksp.toClassName fun KSType.isListType( ): Boolean { @@ -28,6 +23,7 @@ fun KSType.isListType( ?.any { it.resolve().isListType() } == true } +@Deprecated("ue wrap helper ") fun KSType.noWrappedType( wrappedTypes: List, ): KSType { @@ -40,10 +36,3 @@ fun KSType.noWrappedType( } return this } - -fun KSType.listWrapTypeIfNeed( - wrappedTypes: List, -): TypeName { - if (!isListType()) return noWrappedType(wrappedTypes).toClassName() - return List::class.asClassName().parameterizedBy(noWrappedType(wrappedTypes).toClassName()) -} diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/annotations/ComponentAnnMirror.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/annotations/ComponentAnnMirror.kt index f1183fbf..eea074cc 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/annotations/ComponentAnnMirror.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/annotations/ComponentAnnMirror.kt @@ -7,6 +7,7 @@ import com.google.devtools.ksp.symbol.KSType import com.squareup.kotlinpoet.ClassName import com.squareup.kotlinpoet.asClassName import com.squareup.kotlinpoet.ksp.toClassName +import com.squareup.kotlinpoet.ksp.toTypeName class ComponentAnnMirror( val identifiers: List, @@ -16,32 +17,32 @@ class ComponentAnnMirror( fun KSAnnotated.annotations( className: ClassName, ): Sequence = annotations - .filter { it.annotationType.resolve().toClassName() == className } + .filter { it.annotationType.resolve().toTypeName() == className } fun KSAnnotated.anyAnnotation( vararg classNames: ClassName, ): Sequence = annotations - .filter { it.annotationType.resolve().toClassName() in classNames } + .filter { it.annotationType.resolve().toTypeName() in classNames } fun KSAnnotated.hasOnlyAnnotation( className: ClassName, ): Boolean { if (annotations.count() != 1) return false - return annotations.first().annotationType.resolve().toClassName() == className + return annotations.first().annotationType.resolve().toTypeName() == className } fun KSType.annotations( className: ClassName, ): Sequence = annotations - .filter { it.annotationType.resolve().toClassName() == className } + .filter { it.annotationType.resolve().toTypeName() == className } @Suppress("UNCHECKED_CAST") fun KSAnnotated.findComponentAnnotation( ): Sequence = annotations - .filter { it.annotationType.resolve().toClassName() == Component::class.asClassName() } + .filter { it.annotationType.resolve().toTypeName() == Component::class.asClassName() } .map { compAnn -> val identifiers = compAnn.arguments .firstOrNull { it.name?.asString() == "identifiers" } diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/invokecall/InvokeCall.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/invokecall/InvokeCall.kt index 837e0b8c..df6f25c2 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/invokecall/InvokeCall.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/invokecall/InvokeCall.kt @@ -3,6 +3,7 @@ package com.github.klee0kai.thekey.stone.ksp.helpers.invokecall import com.github.klee0kai.stone.__hidden__.provide.ProvideBuilder import com.github.klee0kai.thekey.stone.ksp.helpers.invokecall.model.FieldDetail import com.github.klee0kai.thekey.stone.ksp.helpers.invokecall.model.MethodDetail +import com.github.klee0kai.thekey.stone.ksp.helpers.invokecall.model.QualifierAnn import com.github.klee0kai.thekey.stone.ksp.helpers.wrap.WrapHelper import com.github.klee0kai.thekey.stone.ksp.utils.LocalFieldName import com.google.devtools.ksp.symbol.KSAnnotation @@ -26,43 +27,16 @@ class InvokeCall( val flags: InvokeProvideFlags = InvokeProvideFlags(), ) { - /** - * Create new invoke sequence - * - * @param callSequence ordered methods in invoke sequence - */ - constructor( - wrapHelper: WrapHelper, - callSequence: List, - flags: InvokeProvideFlags = InvokeProvideFlags() - ) : this( - wrapHelper = wrapHelper, - invokeSequenceVariants = listOf(callSequence), - flags = flags, - ) - - /** - * Merge variants. All should return same type - * - * @param variants all variants from best to worse - */ - constructor( - wrapHelper: WrapHelper, - variants: List, - ) : this( - wrapHelper = wrapHelper, - invokeSequenceVariants = variants.flatMap { it.invokeSequenceVariants }, - flags = variants.fold(InvokeProvideFlags()) { acc, value -> acc.merge(value.flags) } - ) + companion object; fun bestSequence(): List = invokeSequenceVariants[0] fun qualifierAnnotations( crossing: Boolean, - ): Set { - val allQualifiersLists = LinkedList>() + ): Set { + val allQualifiersLists = LinkedList>() for (variant in invokeSequenceVariants) { - val qualifiers = HashSet() + val qualifiers = HashSet() for (m in variant) qualifiers.addAll(m.qualifierAnns) allQualifiersLists.add(qualifiers) } @@ -111,7 +85,7 @@ class InvokeCall( return invokeSequence[invokeSequence.size - 1].returnType } - fun best() = InvokeCall(wrapHelper, bestSequence()) + fun best() = InvokeCall.fromSequence(wrapHelper, bestSequence()) /** * Generate invoke code bloke @@ -162,7 +136,7 @@ class InvokeCall( builder.add(CodeBlock.of("buildList<%T>{ \n", resultType())) for (sequence in invokeSequenceVariants) { - val invokeCall = InvokeCall(wrapHelper, sequence) + val invokeCall = InvokeCall.fromSequence(wrapHelper, sequence) val seqCodeBlock = invokeCall.invokeCode(declaredFields) if (wrapHelper.isList(invokeCall.rawReturnType())) { @@ -256,3 +230,24 @@ class InvokeCall( return Objects.hash(invokeSequenceVariants) } } + + +fun InvokeCall.Companion.fromSequence( + wrapHelper: WrapHelper, + callSequence: List, + flags: InvokeProvideFlags = InvokeProvideFlags(), +) = InvokeCall( + wrapHelper = wrapHelper, + invokeSequenceVariants = listOf(callSequence), + flags = flags, +) + + +fun InvokeCall.Companion.fromVariants( + wrapHelper: WrapHelper, + variants: List, +) = InvokeCall( + wrapHelper = wrapHelper, + invokeSequenceVariants = variants.flatMap { it.invokeSequenceVariants }, + flags = variants.fold(InvokeProvideFlags()) { acc, value -> acc.merge(value.flags) } +) \ No newline at end of file diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/invokecall/ModulesGraph.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/invokecall/ModulesGraph.kt index 04b31e3a..ed11843d 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/invokecall/ModulesGraph.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/invokecall/ModulesGraph.kt @@ -32,7 +32,7 @@ import com.squareup.kotlinpoet.CodeBlock import com.squareup.kotlinpoet.ParameterizedTypeName.Companion.parameterizedBy import com.squareup.kotlinpoet.TypeName import com.squareup.kotlinpoet.asClassName -import com.squareup.kotlinpoet.ksp.toClassName +import com.squareup.kotlinpoet.ksp.toTypeName import java.util.* class ModulesGraph( @@ -55,7 +55,7 @@ class ModulesGraph( val module = provideModuleMethod?.returnType?.resolve()?.declaration as? KSClassDeclaration ?: return for (m in module.getAllMethods(false, true, "")) { if (m.returnType?.resolve()?.isNotPrimitive == false) continue - val returnType = m.returnType?.resolve()?.toClassName() ?: continue + val returnType = m.returnType?.resolve()?.toTypeName() ?: continue val provTypeName = wrapHelper.nonWrappedType(returnType) val isCached = m.getAnnotationsByType(Provide::class) .firstOrNull()?.cache !in listOf(Provide.CacheType.Factory, null) @@ -63,7 +63,7 @@ class ModulesGraph( provideTypeCodes.putIfAbsent(provTypeName, HashSet()) provideTypeCodes[provTypeName]?.add( - InvokeCall( + InvokeCall.fromSequence( wrapHelper = wrapHelper, callSequence = listOf(provideModuleMethod.toMethodDetail(), m.toMethodDetail()), flags = InvokeProvideFlags( @@ -76,17 +76,17 @@ class ModulesGraph( val cacheControlMethod = MethodDetail( methodName = m.cacheControlMethodName, returnType = wrapHelper.listWrapTypeIfNeed(returnType), - qualifierAnns = m.qualifierAnnotations.toList(), + qualifierAnns = m.qualifierAnnotations.map { it.toQualifierAnn() }.toSet(), args = buildList { add(FieldDetail.simple("__action", CacheAction::class.asClassName())) - addAll(m.identifierParameters(identifierTypes).map { it.toFieldDetail() }) + addAll(m.parameters.identifierParameters(identifierTypes).map { it.toFieldDetail() }) }, ) cacheControlTypeCodes.putIfAbsent(provTypeName, HashSet()) cacheControlTypeCodes.get(provTypeName) ?.add( - InvokeCall( + InvokeCall.fromSequence( wrapHelper = wrapHelper, callSequence = listOf(provideModuleMethod.toMethodDetail(), cacheControlMethod) ) @@ -97,7 +97,7 @@ class ModulesGraph( fun codeProvideType( methodName: String?, returnType: TypeName, - qualifierAnns: Set, + qualifierAnns: Set, declaredFields: List ): CodeBlock? { val isWrappedReturn = wrapHelper.isSupport(returnType) @@ -280,7 +280,7 @@ class ModulesGraph( } // qualifies not need to provide val argNonWrapped = wrapHelper.nonWrappedType(it.typeName) - argNonWrapped is ClassName && !identifierTypes.any { it.toClassName() == argNonWrapped } + argNonWrapped is ClassName && !identifierTypes.any { it.toTypeName() == argNonWrapped } } needProvideDeps.addAll(newDeps) @@ -321,7 +321,7 @@ class ModulesGraph( fun invokeControlCacheForType( provideMethodName: String, typeName: TypeName, - qualifierAnns: Set + qualifierAnns: Set ): InvokeCall? = provideTypeInvokeCall( cacheControlTypeCodes, typeName, @@ -334,7 +334,7 @@ class ModulesGraph( private fun provideTypeInvokeCall( provideTypeCodes: Map>, typeName: TypeName, - qualifierAnns: Set, + qualifierAnns: Set, provideMethodName: String?, listVariants: Boolean, ): InvokeCall? { @@ -342,7 +342,9 @@ class ModulesGraph( if (invokeCalls == null || invokeCalls.isEmpty()) return null var filtered = if (!listVariants || !qualifierAnns.isEmpty()) { - invokeCalls.filter { it.qualifierAnnotations(false) == qualifierAnns } + invokeCalls.filter { + it.qualifierAnnotations(false) == qualifierAnns + } } else { invokeCalls } @@ -358,7 +360,7 @@ class ModulesGraph( filtered.joinToString(" and ") ) } - return if (!filtered.isEmpty()) InvokeCall(wrapHelper, variants = filtered.toList()) else null + return if (!filtered.isEmpty()) InvokeCall.fromVariants(wrapHelper, variants = filtered.toList()) else null } companion object { diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/invokecall/ProvideDep.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/invokecall/ProvideDep.kt index ca2adb47..c23719eb 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/invokecall/ProvideDep.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/invokecall/ProvideDep.kt @@ -1,32 +1,13 @@ package com.github.klee0kai.thekey.stone.ksp.helpers.invokecall -import com.google.devtools.ksp.symbol.KSAnnotation +import com.github.klee0kai.thekey.stone.ksp.helpers.invokecall.model.QualifierAnn import com.squareup.kotlinpoet.TypeName data class ProvideDep( val methodName: String?, val typeName: TypeName, - val qualifierAnns: Set, + val qualifierAnns: Set, ) { - - override fun equals(other: Any?): Boolean { - if (this === other) return true - if (javaClass != other?.javaClass) return false - - other as ProvideDep - - if (methodName != other.methodName) return false - if (typeName != other.typeName) return false - if (qualifierAnns != other.qualifierAnns) return false - - return true - } - - override fun hashCode(): Int { - var result = methodName?.hashCode() ?: 0 - result = 31 * result + typeName.hashCode() - result = 31 * result + qualifierAnns.hashCode() - return result - } + companion object; } diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/invokecall/model/FieldDetail.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/invokecall/model/FieldDetail.kt index a70aebc3..8645e891 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/invokecall/model/FieldDetail.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/invokecall/model/FieldDetail.kt @@ -1,50 +1,26 @@ package com.github.klee0kai.thekey.stone.ksp.helpers.invokecall.model import com.github.klee0kai.thekey.stone.ksp.helpers.qualifierAnnotations -import com.google.devtools.ksp.symbol.KSAnnotation import com.google.devtools.ksp.symbol.KSValueParameter import com.squareup.kotlinpoet.TypeName -import com.squareup.kotlinpoet.ksp.toClassName +import com.squareup.kotlinpoet.ksp.toTypeName data class FieldDetail( val name: String, val type: TypeName, - val qualifierAnns: Set = emptySet(), - val kSValueParameter: KSValueParameter? = null, + val qualifierAnns: Set = emptySet(), ) { companion object; - override fun equals(other: Any?): Boolean { - if (this === other) return true - if (javaClass != other?.javaClass) return false - - other as FieldDetail - - if (name != other.name) return false - if (type != other.type) return false - if (qualifierAnns != other.qualifierAnns) return false - if (kSValueParameter != other.kSValueParameter) return false - - return true - } - - override fun hashCode(): Int { - var result = name.hashCode() - result = 31 * result + type.hashCode() - result = 31 * result + qualifierAnns.hashCode() - result = 31 * result + (kSValueParameter?.hashCode() ?: 0) - return result - } } fun FieldDetail.Companion.simple(name: String, type: TypeName) = FieldDetail(name, type) - fun KSValueParameter.toFieldDetail() = FieldDetail( name = name?.asString() ?: "it", - type = type.resolve().toClassName(), - qualifierAnns = qualifierAnnotations.toSet(), - kSValueParameter = this, + type = type.resolve().toTypeName(), + qualifierAnns = qualifierAnnotations.map { it.toQualifierAnn() }.toSet(), ) + diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/invokecall/model/MethodDetail.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/invokecall/model/MethodDetail.kt index 12289d5c..32489b8b 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/invokecall/model/MethodDetail.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/invokecall/model/MethodDetail.kt @@ -1,51 +1,24 @@ package com.github.klee0kai.thekey.stone.ksp.helpers.invokecall.model import com.github.klee0kai.thekey.stone.ksp.helpers.qualifierAnnotations -import com.google.devtools.ksp.symbol.KSAnnotation import com.google.devtools.ksp.symbol.KSFunctionDeclaration import com.squareup.kotlinpoet.TypeName import com.squareup.kotlinpoet.asClassName -import com.squareup.kotlinpoet.ksp.toClassName +import com.squareup.kotlinpoet.ksp.toTypeName -class MethodDetail( +data class MethodDetail( val methodName: String, val returnType: TypeName, val args: List = emptyList(), - val qualifierAnns: List = emptyList(), - val kSValueParameter: KSFunctionDeclaration? = null, + val qualifierAnns: Set = emptySet(), ) { - companion object - - override - - fun equals(other: Any?): Boolean { - if (this === other) return true - if (javaClass != other?.javaClass) return false - - other as MethodDetail - - if (methodName != other.methodName) return false - if (returnType != other.returnType) return false - if (args != other.args) return false - - return true - } - - override fun hashCode(): Int { - var result = methodName.hashCode() - result = 31 * result + returnType.hashCode() - result = 31 * result + args.hashCode() - return result - }; - - + companion object; } fun KSFunctionDeclaration.toMethodDetail() = MethodDetail( methodName = simpleName.asString(), - returnType = returnType?.resolve()?.toClassName() ?: Unit::class.asClassName(), + returnType = returnType?.resolve()?.toTypeName() ?: Unit::class.asClassName(), args = parameters.map { it.toFieldDetail() }, - qualifierAnns = qualifierAnnotations.toList(), - kSValueParameter = this, + qualifierAnns = qualifierAnnotations.map { it.toQualifierAnn() }.toSet(), ) diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/invokecall/model/QualifierAnn.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/invokecall/model/QualifierAnn.kt new file mode 100644 index 00000000..5eda056b --- /dev/null +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/invokecall/model/QualifierAnn.kt @@ -0,0 +1,16 @@ +package com.github.klee0kai.thekey.stone.ksp.helpers.invokecall.model + +import com.google.devtools.ksp.symbol.KSAnnotation +import com.squareup.kotlinpoet.TypeName +import com.squareup.kotlinpoet.ksp.toClassName + +data class QualifierAnn( + var qualifierClStr: TypeName, + var values: Map = mapOf(), +) + +fun KSAnnotation.toQualifierAnn( +) = QualifierAnn( + qualifierClStr = annotationType.resolve().toClassName(), + values = arguments.map { it.name?.asString()!! to it.value }.groupBy { it.first }, +) diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/itemholder/ItemHolderHelper.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/itemholder/ItemHolderCodeHelper.kt similarity index 84% rename from stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/itemholder/ItemHolderHelper.kt rename to stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/itemholder/ItemHolderCodeHelper.kt index a3a500c5..76daea29 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/itemholder/ItemHolderHelper.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/itemholder/ItemHolderCodeHelper.kt @@ -2,18 +2,17 @@ package com.github.klee0kai.thekey.stone.ksp.helpers.itemholder import com.github.klee0kai.thekey.stone.ksp.helpers.isListType import com.github.klee0kai.thekey.stone.ksp.helpers.noWrappedType -import com.github.klee0kai.thekey.stone.ksp.poet.smartcode.SmartCode import com.google.devtools.ksp.symbol.KSType import com.google.devtools.ksp.symbol.KSValueParameter import com.squareup.kotlinpoet.CodeBlock import com.squareup.kotlinpoet.TypeSpec -interface ItemHolderHelper { +interface ItemHolderCodeHelper { companion object; fun TypeSpec.Builder.genCacheField() - fun codeGetCachedValue(): SmartCode + fun codeGetCachedValue(): CodeBlock fun codeSetCachedValue( value: CodeBlock, @@ -28,12 +27,12 @@ interface ItemHolderHelper { } -fun ItemHolderHelper.Companion.of( +fun ItemHolderCodeHelper.Companion.of( fieldName: String, returnType: KSType, idArguments: List, cacheType: ItemCacheType, -): ItemHolderHelper { +): ItemHolderCodeHelper { val noWrappedReturnType = returnType .noWrappedType( wrappedTypes = idArguments.map { it.type.resolve() } @@ -45,7 +44,7 @@ fun ItemHolderHelper.Companion.of( } return when { - idArguments.isEmpty() -> SingleItemHolderHelper( + idArguments.isEmpty() -> SingleItemHolderCodeHelper( fieldName = fieldName, returnType = returnType, nonWrappedReturnType = noWrappedReturnType, @@ -54,7 +53,7 @@ fun ItemHolderHelper.Companion.of( defRefType = defRefType, ) - idArguments.size == 1 -> SimpleMapItemHolderHelper( + idArguments.size == 1 -> SimpleMapItemHolderCodeHelper( fieldName = fieldName, returnType = returnType, nonWrappedReturnType = noWrappedReturnType, @@ -64,7 +63,7 @@ fun ItemHolderHelper.Companion.of( keyParam = idArguments.first(), ) - else -> MultiKeyMapItemHolderHelper( + else -> MultiKeyMapItemHolderCodeHelper( fieldName = fieldName, returnType = returnType, nonWrappedReturnType = noWrappedReturnType, diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/itemholder/MultiKeyMapItemHolderHelper.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/itemholder/MultiKeyMapItemHolderCodeHelper.kt similarity index 82% rename from stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/itemholder/MultiKeyMapItemHolderHelper.kt rename to stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/itemholder/MultiKeyMapItemHolderCodeHelper.kt index a4e24cbe..a5399c22 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/itemholder/MultiKeyMapItemHolderHelper.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/itemholder/MultiKeyMapItemHolderCodeHelper.kt @@ -3,10 +3,8 @@ package com.github.klee0kai.thekey.stone.ksp.helpers.itemholder import com.github.klee0kai.stone.__hidden__.types.MultiKey import com.github.klee0kai.stone.__hidden__.types.holders.MapItemHolder import com.github.klee0kai.stone.__hidden__.types.holders.StoneRefType +import com.github.klee0kai.thekey.stone.ksp.poet.codeBlock import com.github.klee0kai.thekey.stone.ksp.poet.genProperty -import com.github.klee0kai.thekey.stone.ksp.poet.smartcode.SmartCode -import com.github.klee0kai.thekey.stone.ksp.poet.smartcode.add -import com.github.klee0kai.thekey.stone.ksp.poet.smartcode.smartCode import com.google.devtools.ksp.symbol.KSType import com.google.devtools.ksp.symbol.KSValueParameter import com.squareup.kotlinpoet.CodeBlock @@ -15,8 +13,9 @@ import com.squareup.kotlinpoet.ParameterizedTypeName.Companion.parameterizedBy import com.squareup.kotlinpoet.TypeSpec import com.squareup.kotlinpoet.asClassName import com.squareup.kotlinpoet.ksp.toClassName +import com.squareup.kotlinpoet.ksp.toTypeName -class MultiKeyMapItemHolderHelper( +class MultiKeyMapItemHolderCodeHelper( val fieldName: String, val returnType: KSType, val nonWrappedReturnType: KSType, @@ -24,13 +23,13 @@ class MultiKeyMapItemHolderHelper( val isListCaching: Boolean, val defRefType: StoneRefType, val keyArguments: List, -) : ItemHolderHelper { +) : ItemHolderCodeHelper { override fun TypeSpec.Builder.genCacheField() { val cacheType = MapItemHolder::class.asClassName() .parameterizedBy( MultiKey::class.asClassName(), - nonWrappedReturnType.toClassName(), + nonWrappedReturnType.toTypeName(), ) genProperty(fieldName, cacheType) { @@ -41,20 +40,19 @@ class MultiKeyMapItemHolderHelper( override fun codeGetCachedValue( - ): SmartCode = smartCode { + ) = codeBlock { val getMethod = if (isListCaching) "getList" else "get" add( "%L.%L(key = %T(%L))", fieldName, getMethod, MultiKey::class.asClassName(), keyArguments.joinToString(",") { it.name!!.asString() }, ) - providingType.value = returnType.toClassName() } override fun codeSetCachedValue( value: CodeBlock, onlyIfNull: Boolean - ): CodeBlock = smartCode { + ) = codeBlock { val setMethod = if (isListCaching) "setList" else "set" add( "%L.%L(key = %T(%L), onlyIfNull = %L ){ ", @@ -64,8 +62,7 @@ class MultiKeyMapItemHolderHelper( ) add(value) add("}") - providingType.value = returnType.toClassName() - }.collect() + } override fun statementSwitchRef( paramsCode: CodeBlock, diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/itemholder/SimpleMapItemHolderHelper.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/itemholder/SimpleMapItemHolderCodeHelper.kt similarity index 79% rename from stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/itemholder/SimpleMapItemHolderHelper.kt rename to stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/itemholder/SimpleMapItemHolderCodeHelper.kt index 20bdfa55..7af74c65 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/itemholder/SimpleMapItemHolderHelper.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/itemholder/SimpleMapItemHolderCodeHelper.kt @@ -2,10 +2,8 @@ package com.github.klee0kai.thekey.stone.ksp.helpers.itemholder import com.github.klee0kai.stone.__hidden__.types.holders.MapItemHolder import com.github.klee0kai.stone.__hidden__.types.holders.StoneRefType +import com.github.klee0kai.thekey.stone.ksp.poet.codeBlock import com.github.klee0kai.thekey.stone.ksp.poet.genProperty -import com.github.klee0kai.thekey.stone.ksp.poet.smartcode.SmartCode -import com.github.klee0kai.thekey.stone.ksp.poet.smartcode.add -import com.github.klee0kai.thekey.stone.ksp.poet.smartcode.smartCode import com.google.devtools.ksp.symbol.KSType import com.google.devtools.ksp.symbol.KSValueParameter import com.squareup.kotlinpoet.CodeBlock @@ -14,8 +12,9 @@ import com.squareup.kotlinpoet.ParameterizedTypeName.Companion.parameterizedBy import com.squareup.kotlinpoet.TypeSpec import com.squareup.kotlinpoet.asClassName import com.squareup.kotlinpoet.ksp.toClassName +import com.squareup.kotlinpoet.ksp.toTypeName -class SimpleMapItemHolderHelper( +class SimpleMapItemHolderCodeHelper( val fieldName: String, val returnType: KSType, val nonWrappedReturnType: KSType, @@ -23,13 +22,13 @@ class SimpleMapItemHolderHelper( val isListCaching: Boolean, val defRefType: StoneRefType, val keyParam: KSValueParameter, -) : ItemHolderHelper { +) : ItemHolderCodeHelper { override fun TypeSpec.Builder.genCacheField() { val cacheType = MapItemHolder::class.asClassName() .parameterizedBy( - keyParam.type.resolve().toClassName(), - nonWrappedReturnType.toClassName(), + keyParam.type.resolve().toTypeName(), + nonWrappedReturnType.toTypeName(), ) genProperty(fieldName, cacheType) { @@ -39,19 +38,18 @@ class SimpleMapItemHolderHelper( } override fun codeGetCachedValue( - ): SmartCode = smartCode { + ) = codeBlock { val getMethod = if (isListCaching) "getList" else "get" add( "%L.%L(key = %L)", fieldName, getMethod, keyParam.name!!.asString() ) - providingType.value = returnType.toClassName() } override fun codeSetCachedValue( value: CodeBlock, onlyIfNull: Boolean - ): CodeBlock = smartCode { + ) = codeBlock { val setMethod = if (isListCaching) "setList" else "set" add( "%L.%L(key = %L, onlyIfNull = %L ){ ", @@ -59,8 +57,7 @@ class SimpleMapItemHolderHelper( ) add(value) add("}") - providingType.value = returnType.toClassName() - }.collect() + } override fun statementSwitchRef( paramsCode: CodeBlock, diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/itemholder/SingleItemHolderHelper.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/itemholder/SingleItemHolderCodeHelper.kt similarity index 77% rename from stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/itemholder/SingleItemHolderHelper.kt rename to stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/itemholder/SingleItemHolderCodeHelper.kt index 65884739..db10c8f5 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/itemholder/SingleItemHolderHelper.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/itemholder/SingleItemHolderCodeHelper.kt @@ -2,10 +2,8 @@ package com.github.klee0kai.thekey.stone.ksp.helpers.itemholder import com.github.klee0kai.stone.__hidden__.types.holders.SingleItemHolder import com.github.klee0kai.stone.__hidden__.types.holders.StoneRefType +import com.github.klee0kai.thekey.stone.ksp.poet.codeBlock import com.github.klee0kai.thekey.stone.ksp.poet.genProperty -import com.github.klee0kai.thekey.stone.ksp.poet.smartcode.SmartCode -import com.github.klee0kai.thekey.stone.ksp.poet.smartcode.add -import com.github.klee0kai.thekey.stone.ksp.poet.smartcode.smartCode import com.google.devtools.ksp.symbol.KSType import com.squareup.kotlinpoet.CodeBlock import com.squareup.kotlinpoet.KModifier @@ -13,19 +11,20 @@ import com.squareup.kotlinpoet.ParameterizedTypeName.Companion.parameterizedBy import com.squareup.kotlinpoet.TypeSpec import com.squareup.kotlinpoet.asClassName import com.squareup.kotlinpoet.ksp.toClassName +import com.squareup.kotlinpoet.ksp.toTypeName -class SingleItemHolderHelper( +class SingleItemHolderCodeHelper( val fieldName: String, val returnType: KSType, val nonWrappedReturnType: KSType, val itemCacheType: ItemCacheType, val isListCaching: Boolean, val defRefType: StoneRefType, -) : ItemHolderHelper { +) : ItemHolderCodeHelper { override fun TypeSpec.Builder.genCacheField() { val cacheType = SingleItemHolder::class.asClassName() - .parameterizedBy(nonWrappedReturnType.toClassName()) + .parameterizedBy(nonWrappedReturnType.toTypeName()) genProperty(fieldName, cacheType) { addModifiers(KModifier.PRIVATE) @@ -34,22 +33,20 @@ class SingleItemHolderHelper( } override fun codeGetCachedValue( - ): SmartCode = smartCode { + ) = codeBlock { val getMethod = if (isListCaching) "getList" else "get" add("%L.%L()", fieldName, getMethod) - providingType.value = returnType.toClassName() } override fun codeSetCachedValue( value: CodeBlock, onlyIfNull: Boolean - ): CodeBlock = smartCode { + ) = codeBlock { val setMethod = if (isListCaching) "setList" else "set" add("%L.%L(onlyIfNull = %L ){ ", fieldName, setMethod, onlyIfNull) add(value) add(" }") - providingType.value = returnType.toClassName() - }.collect() + } override fun statementSwitchRef( paramsCode: CodeBlock, diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/wrap/ClassNameUtils.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/wrap/ClassNameUtils.kt index 75074f48..9b0184fd 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/wrap/ClassNameUtils.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/wrap/ClassNameUtils.kt @@ -51,7 +51,7 @@ object ClassNameUtils { return rawTypeOf(upperBounds.first()) } } - return typeName + return typeName.copy(nullable = false) } diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/wrap/WrapHelper.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/wrap/WrapHelper.kt index 87694a9d..1ca0d7da 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/wrap/WrapHelper.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/wrap/WrapHelper.kt @@ -73,7 +73,7 @@ class WrapHelper { if (typeName is WildcardTypeName) { if (!typeName.outTypes.isEmpty()) return nonWrappedType(typeName.outTypes.first()) } - return typeName + return typeName.copy(nullable = false) } /** diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/ksp/KSClassDeclarationExt.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/ksp/KSClassDeclarationExt.kt index e999e1d0..37ef8471 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/ksp/KSClassDeclarationExt.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/ksp/KSClassDeclarationExt.kt @@ -9,6 +9,7 @@ import com.google.devtools.ksp.symbol.KSFunctionDeclaration import com.google.devtools.ksp.symbol.KSType import com.squareup.kotlinpoet.ClassName import com.squareup.kotlinpoet.ksp.toClassName +import com.squareup.kotlinpoet.ksp.toTypeName import kotlin.reflect.KClass fun KSClassDeclaration.findConstructor( @@ -70,7 +71,7 @@ fun KSClassDeclaration.isChildOf( ): Boolean { if (toClassName() == parentType) return true superTypes.forEach { type -> - if (type.resolve().toClassName() == type) return true + if (type.resolve().toTypeName() == type) return true if ((type.resolve().declaration as? KSClassDeclaration)?.isChildOf(parentType) == true) return true } return false diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/poet/CodeBlockExt.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/poet/CodeBlockExt.kt new file mode 100644 index 00000000..86487e21 --- /dev/null +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/poet/CodeBlockExt.kt @@ -0,0 +1,8 @@ +package com.github.klee0kai.thekey.stone.ksp.poet + +import com.squareup.kotlinpoet.CodeBlock + +@PoetDsl +fun codeBlock( + block: CodeBlock.Builder.() -> Unit, +) = CodeBlock.builder().apply(block).build() \ No newline at end of file diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/poet/FunSpecDsl.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/poet/FunSpecDsl.kt index 09748508..0d75e132 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/poet/FunSpecDsl.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/poet/FunSpecDsl.kt @@ -3,6 +3,7 @@ package com.github.klee0kai.thekey.stone.ksp.poet import com.squareup.kotlinpoet.CodeBlock import com.squareup.kotlinpoet.FunSpec +@PoetDsl fun CodeBlock.Builder.controlFlow( controlFlow: String, vararg args: Any, @@ -13,6 +14,7 @@ fun CodeBlock.Builder.controlFlow( .endControlFlow() } +@PoetDsl fun FunSpec.Builder.controlFlow( controlFlow: String, vararg args: Any, diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/poet/TypeSpecDsl.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/poet/TypeSpecDsl.kt index 64040afb..7b37e8ca 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/poet/TypeSpecDsl.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/poet/TypeSpecDsl.kt @@ -5,6 +5,7 @@ import com.github.klee0kai.thekey.stone.ksp.target.isSuspend import com.google.devtools.ksp.symbol.KSFunctionDeclaration import com.squareup.kotlinpoet.* import com.squareup.kotlinpoet.ksp.toClassName +import com.squareup.kotlinpoet.ksp.toTypeName @PoetDsl fun TypeSpec.Builder.genProperty( @@ -78,7 +79,7 @@ fun TypeSpec.Builder.genOverrideFun( addModifiers(KModifier.OVERRIDE) if (func.isSuspend) addModifiers(KModifier.SUSPEND) declareSameParameters(func) - func.returnType?.resolve()?.toClassName()?.let { returns(it) } + func.returnType?.resolve()?.toTypeName()?.let { returns(it) } block() } diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/poet/member/CoroutinesMemberFunctions.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/poet/member/CoroutinesMemberFunctions.kt new file mode 100644 index 00000000..f2944d56 --- /dev/null +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/poet/member/CoroutinesMemberFunctions.kt @@ -0,0 +1,9 @@ +package com.github.klee0kai.thekey.stone.ksp.poet.member + +import com.squareup.kotlinpoet.MemberName + +object CoroutinesMemberFunctions { + + val SupervisorJob = MemberName("kotlinx.coroutines", "SupervisorJob") + +} \ No newline at end of file diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/CommonPoetExt.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/CommonPoetExt.kt index b1b32ab2..d31d9bcc 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/CommonPoetExt.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/CommonPoetExt.kt @@ -17,7 +17,7 @@ val KSFunctionDeclaration.isSuspend: Boolean get() = modifiers.contains(Modifier val KSFunctionDeclaration.asyncReturnType: TypeName? get() { - val returnType = returnType?.resolve()?.toClassName() + val returnType = returnType?.resolve()?.toTypeName() return when { returnType != null && !isSuspend -> returnType returnType != null && returnType != Unit::class.asClassName() -> @@ -31,8 +31,8 @@ val KSFunctionDeclaration.asyncReturnType: TypeName? fun FunSpec.Builder.declareSameParameters( function: KSFunctionDeclaration, ) = apply { - function.returnType?.resolve()?.toClassName()?.let { returns(it) } - function.extensionReceiver?.resolve()?.toClassName()?.let { receiver(it) } + function.returnType?.resolve()?.toTypeName()?.let { returns(it) } + function.extensionReceiver?.resolve()?.toTypeName()?.let { receiver(it) } function.parameters.forEach { param -> addParameter( diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/GenModuleCacheControlProcessor.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/GenModuleCacheControlProcessor.kt index b16a1ea4..aff7bff5 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/GenModuleCacheControlProcessor.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/GenModuleCacheControlProcessor.kt @@ -26,6 +26,7 @@ import com.squareup.kotlinpoet.ParameterizedTypeName.Companion.parameterizedBy import com.squareup.kotlinpoet.STAR import com.squareup.kotlinpoet.asClassName import com.squareup.kotlinpoet.ksp.toClassName +import com.squareup.kotlinpoet.ksp.toTypeName import kotlin.reflect.KClass class GenModuleCacheControlProcessor : TargetFileProcessor { @@ -102,7 +103,7 @@ class GenModuleCacheControlProcessor : TargetFileProcessor { ) addParameter("__action", CacheAction::class) idArguments.forEach { - addParameter(it.name!!.asString(), it.type.resolve().toClassName()) + addParameter(it.name!!.asString(), it.type.resolve().toTypeName()) } } } diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/GenModuleProcessor.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/GenModuleProcessor.kt index 57fed800..11f0205e 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/GenModuleProcessor.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/GenModuleProcessor.kt @@ -14,7 +14,7 @@ import com.github.klee0kai.stone.annotations.module.Provide import com.github.klee0kai.stone.weakref.Ref import com.github.klee0kai.thekey.stone.ksp.helpers.* import com.github.klee0kai.thekey.stone.ksp.helpers.annotations.annotations -import com.github.klee0kai.thekey.stone.ksp.helpers.itemholder.ItemHolderHelper +import com.github.klee0kai.thekey.stone.ksp.helpers.itemholder.ItemHolderCodeHelper import com.github.klee0kai.thekey.stone.ksp.helpers.itemholder.of import com.github.klee0kai.thekey.stone.ksp.helpers.itemholder.toItemCacheType import com.github.klee0kai.thekey.stone.ksp.helpers.wrap.ClassNameUtils.rawTypeOf @@ -24,9 +24,6 @@ import com.github.klee0kai.thekey.stone.ksp.ksp.arch.SymbolsToProcess import com.github.klee0kai.thekey.stone.ksp.ksp.arch.TargetFileProcessor import com.github.klee0kai.thekey.stone.ksp.ksp.getAllMethods import com.github.klee0kai.thekey.stone.ksp.poet.* -import com.github.klee0kai.thekey.stone.ksp.poet.smartcode.SmartCode -import com.github.klee0kai.thekey.stone.ksp.poet.smartcode.add -import com.github.klee0kai.thekey.stone.ksp.poet.smartcode.smartCode import com.google.devtools.ksp.KspExperimental import com.google.devtools.ksp.containingFile import com.google.devtools.ksp.getAllSuperTypes @@ -38,6 +35,7 @@ import com.google.devtools.ksp.symbol.* import com.squareup.kotlinpoet.* import com.squareup.kotlinpoet.ParameterizedTypeName.Companion.parameterizedBy import com.squareup.kotlinpoet.ksp.toClassName +import com.squareup.kotlinpoet.ksp.toTypeName import kotlin.reflect.KClass class GenModuleProcessor : TargetFileProcessor { @@ -64,8 +62,8 @@ class GenModuleProcessor : TargetFileProcessor { } private class DelayedCodeBlocks( - val bindMethodBody: SmartCode = SmartCode(), - val clearNullsMethodBody: SmartCode = SmartCode(), + val bindMethodBody: CodeBlock.Builder = CodeBlock.builder(), + val clearNullsMethodBody: CodeBlock.Builder = CodeBlock.builder(), val switchRefStatementBuilders: MutableMap, CodeBlock.Builder> = mutableMapOf() ) @@ -123,19 +121,19 @@ class GenModuleProcessor : TargetFileProcessor { .forEachIndexed { funIdx, function -> val bindAnn = function.getAnnotationsByType(BindInstance::class).firstOrNull() val provideAnn = function.getAnnotationsByType(Provide::class).firstOrNull() - val idArguments = function.identifierParameters(identifierTypes) + val idArguments = function.parameters.identifierParameters(identifierTypes) val returnType = function.returnType?.resolve() ?: return@forEachIndexed val nonWrappedType = returnType.noWrappedType(wrapperTypes) val isListReturnType = nonWrappedType.isListType() val gcScopes = (function.scopeAnnotations - .map { it.annotationType.resolve().toClassName() } + .map { it.annotationType.resolve().toTypeName() } .toSet() + GcAllScope::class.asClassName()).toMutableSet() when { bindAnn != null -> { - val itemHolderHelper = ItemHolderHelper.of( + val itemHolderCodeHelper = ItemHolderCodeHelper.of( fieldName = "${function.simpleName.asString()}$funIdx", returnType = returnType, idArguments = idArguments, @@ -143,18 +141,18 @@ class GenModuleProcessor : TargetFileProcessor { ) gcScopes += bindAnn.cache.toItemCacheType().gcScopeClassName codeBlocks.switchRefStatementBuilders.getOrPut(gcScopes) { CodeBlock.builder() } - .add(itemHolderHelper.statementSwitchRef(CodeBlock.of("__params"))) + .add(itemHolderCodeHelper.statementSwitchRef(CodeBlock.of("__params"))) - codeBlocks.clearNullsMethodBody.add(itemHolderHelper.clearNullsStatement()) + codeBlocks.clearNullsMethodBody.add(itemHolderCodeHelper.clearNullsStatement()) - with(itemHolderHelper) { + with(itemHolderCodeHelper) { genCacheField() - codeBlocks.bindMethodBody.add { + codeBlocks.bindMethodBody.apply { add( "if (or is %T && or::class == %T::class) {\n", - nonWrappedType.toClassName().copy(nullable = false), - nonWrappedType.toClassName().copy(nullable = false), + nonWrappedType.toTypeName().copy(nullable = false), + nonWrappedType.toTypeName().copy(nullable = false), ) add(codeSetCachedValue(CodeBlock.of("or"), false)) add("\n") @@ -166,13 +164,13 @@ class GenModuleProcessor : TargetFileProcessor { genBindInstance( function = function, idArguments = idArguments, - itemHolderHelper = itemHolderHelper, - wrapperHelper = wrapperHelper, + itemHolderCodeHelper = itemHolderCodeHelper, + wrapHelper = wrapperHelper, ) genCacheControlFun( function = function, idArguments = idArguments, - itemHolderHelper = itemHolderHelper, + itemHolderCodeHelper = itemHolderCodeHelper, ) @@ -187,7 +185,7 @@ class GenModuleProcessor : TargetFileProcessor { } genFun(function.cacheControlMethodName) { modifiers.add(KModifier.OVERRIDE) - val returnType = function.returnType?.resolve()?.toClassName() + val returnType = function.returnType?.resolve()?.toTypeName() returnType?.let { returns(returnType.copy(nullable = true)) } addParameter("__action", CacheAction::class) addStatement("return null") @@ -195,7 +193,7 @@ class GenModuleProcessor : TargetFileProcessor { } else -> { - val itemHolderHelper = ItemHolderHelper.of( + val itemHolderCodeHelper = ItemHolderCodeHelper.of( fieldName = "${function.simpleName.asString()}$funIdx", returnType = returnType, idArguments = idArguments, @@ -203,21 +201,21 @@ class GenModuleProcessor : TargetFileProcessor { ) gcScopes += provideAnn.cache.toItemCacheType()!!.gcScopeClassName codeBlocks.switchRefStatementBuilders.getOrPut(gcScopes) { CodeBlock.builder() } - .add(itemHolderHelper.statementSwitchRef(CodeBlock.of("__params"))) - codeBlocks.clearNullsMethodBody.add(itemHolderHelper.clearNullsStatement()) - with(itemHolderHelper) { + .add(itemHolderCodeHelper.statementSwitchRef(CodeBlock.of("__params"))) + codeBlocks.clearNullsMethodBody.add(itemHolderCodeHelper.clearNullsStatement()) + with(itemHolderCodeHelper) { genCacheField() } genProvideCachedFun( function = function, idArguments = idArguments, - itemHolderHelper = itemHolderHelper, - wrapperHelper = wrapperHelper, + itemHolderCodeHelper = itemHolderCodeHelper, + wrapHelper = wrapperHelper, ) genCacheControlFun( function = function, idArguments = idArguments, - itemHolderHelper = itemHolderHelper, + itemHolderCodeHelper = itemHolderCodeHelper, ) } } @@ -244,10 +242,10 @@ class GenModuleProcessor : TargetFileProcessor { private fun TypeSpec.Builder.genBindInstance( function: KSFunctionDeclaration, idArguments: List, - itemHolderHelper: ItemHolderHelper, - wrapperHelper: WrapHelper, + itemHolderCodeHelper: ItemHolderCodeHelper, + wrapHelper: WrapHelper, ) { - val returnType = function.returnType?.resolve() ?: return + val returnType = function.returnType?.resolve()?.toTypeName() ?: return val setValueArg = function.parameters.firstOrNull { it.type.resolve() == returnType } genOverrideFun(function) { @@ -258,22 +256,20 @@ class GenModuleProcessor : TargetFileProcessor { CacheAction::class.asClassName(), idArguments.joinToString(", ") { it.name!!.asString() }, ) - addCode("if (cached != null ) return ") + addCode("if ( cached != null ) return ") addCode( - wrapperHelper.transform( - code = smartCode { - providingType.value = wrapperHelper.listWrapTypeIfNeed(returnType.toClassName()) - add("cached") - }, - wannaType = returnType.toClassName(), - ).collect() + wrapHelper.transform( + providingType = wrapHelper.listWrapTypeIfNeed(returnType), + wannaType = returnType, + code = codeBlock { add("cached") }, + ) ) addStatement("") if (setValueArg != null) { beginControlFlow("if (%L != null)", setValueArg.name!!.asString()) addCode( - itemHolderHelper.codeSetCachedValue( + itemHolderCodeHelper.codeSetCachedValue( value = CodeBlock.of("%L", setValueArg.name!!.asString()), onlyIfNull = false ) @@ -284,22 +280,23 @@ class GenModuleProcessor : TargetFileProcessor { addCode("return ") addCode( - wrapperHelper.transform( - code = itemHolderHelper.codeGetCachedValue(), - wannaType = returnType.toClassName(), - ).collect() + wrapHelper.transform( + wrapHelper.listWrapTypeIfNeed(returnType), + returnType, + CodeBlock.of("cached"), + ) ) - addCode(" as %T", returnType.toClassName()) + addStatement(" as %T", returnType) } } private fun TypeSpec.Builder.genProvideCachedFun( function: KSFunctionDeclaration, idArguments: List, - itemHolderHelper: ItemHolderHelper, - wrapperHelper: WrapHelper, + itemHolderCodeHelper: ItemHolderCodeHelper, + wrapHelper: WrapHelper, ) { - val returnType = function.returnType?.resolve()?.toClassName() ?: return + val returnType = function.returnType?.resolve()?.toTypeName() ?: return genOverrideFun(function) { addStatement( "val cached = %L.get()?.%L( %T.getValueAction, %L ) ", @@ -310,13 +307,11 @@ class GenModuleProcessor : TargetFileProcessor { ) addCode("if (cached != null ) return ") addCode( - wrapperHelper.transform( - code = smartCode { - providingType.value = wrapperHelper.listWrapTypeIfNeed(returnType) - add("cached") - }, - wannaType = returnType, - ).collect() + wrapHelper.transform( + wrapHelper.listWrapTypeIfNeed(returnType), + returnType, + CodeBlock.of("cached"), + ) ) addStatement("") @@ -331,24 +326,23 @@ class GenModuleProcessor : TargetFileProcessor { addCode("%L.%L(%L)", factoryFieldName, function.simpleName.asString(), argStrList) addCode("}\n") addCode( - itemHolderHelper.codeSetCachedValue( - value = wrapperHelper.transform( - code = smartCode { - providingType.value = returnType - add("creator.get()") - }, - wannaType = wrapperHelper.listWrapTypeIfNeed(returnType) - ).collect(), + itemHolderCodeHelper.codeSetCachedValue( + wrapHelper.transform( + returnType, + wrapHelper.listWrapTypeIfNeed(returnType), + CodeBlock.of("creator.get()"), + ), onlyIfNull = true, ) ) addCode("\n") addCode("return ") addCode( - wrapperHelper.transform( - code = itemHolderHelper.codeGetCachedValue(), - wannaType = returnType, - ).collect() + wrapHelper.transform( + wrapHelper.listWrapTypeIfNeed(returnType), + returnType, + itemHolderCodeHelper.codeGetCachedValue(), + ) ) addCode(" as %T", returnType) } @@ -357,15 +351,15 @@ class GenModuleProcessor : TargetFileProcessor { private fun TypeSpec.Builder.genCacheControlFun( function: KSFunctionDeclaration, idArguments: List, - itemHolderHelper: ItemHolderHelper, + itemHolderCodeHelper: ItemHolderCodeHelper, ) { - val returnType = function.returnType?.resolve()?.toClassName() ?: return + val returnType = function.returnType?.resolve()?.toTypeName() ?: return genFun(function.cacheControlMethodName) { modifiers.add(KModifier.OVERRIDE) returns(returnType.copy(nullable = true)) addParameter("__action", CacheAction::class) idArguments.forEach { - addParameter(it.name!!.asString(), it.type.resolve().toClassName()) + addParameter(it.name!!.asString(), it.type.resolve().toTypeName()) } addStatement( @@ -379,25 +373,25 @@ class GenModuleProcessor : TargetFileProcessor { //set value beginControlFlow("%T.SET_VALUE ->", CacheAction.ActionType::class) addCode("(__action.value as? %T)?.let { ", rawTypeOf(returnType)) - addCode(codeBlock = itemHolderHelper.codeSetCachedValue(CodeBlock.of("it"), onlyIfNull = false)) + addCode(codeBlock = itemHolderCodeHelper.codeSetCachedValue(CodeBlock.of("it"), onlyIfNull = false)) addCode("}") endControlFlow() //set if null value beginControlFlow("%T.SET_IF_NULL ->", CacheAction.ActionType::class) addCode("(__action.value as? %T)?.let { ", rawTypeOf(returnType)) - addCode(codeBlock = itemHolderHelper.codeSetCachedValue(CodeBlock.of("it"), onlyIfNull = true)) + addCode(codeBlock = itemHolderCodeHelper.codeSetCachedValue(CodeBlock.of("it"), onlyIfNull = true)) addCode("}") endControlFlow() // switch cache type beginControlFlow("%T.SWITCH_CACHE ->", CacheAction.ActionType::class) - addCode(codeBlock = itemHolderHelper.statementSwitchRef(CodeBlock.of("__action.swCacheParams!!"))) + addCode(codeBlock = itemHolderCodeHelper.statementSwitchRef(CodeBlock.of("__action.swCacheParams!!"))) endControlFlow() addStatement("null -> Unit") endControlFlow() addCode("return ") - addCode(codeBlock = itemHolderHelper.codeGetCachedValue().collect()) + addCode(codeBlock = itemHolderCodeHelper.codeGetCachedValue()) } } @@ -506,7 +500,7 @@ class GenModuleProcessor : TargetFileProcessor { addStatement("%L.get()?.%L(or)", overridedModuleFieldName, bindMethodName) addStatement("var %L = false", appliedLocalFieldName) - addCode(codeBlocks.bindMethodBody.collect()) + addCode(codeBlocks.bindMethodBody.build()) addStatement("return %L", appliedLocalFieldName) } @@ -542,7 +536,7 @@ class GenModuleProcessor : TargetFileProcessor { genFun(clearNullsMethodName) { addModifiers(KModifier.OVERRIDE) - addCode(codeBlocks.clearNullsMethodBody.collect()) + addCode(codeBlocks.clearNullsMethodBody.build()) } } diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/component/ComponentGraphExt.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/component/ComponentGraphExt.kt new file mode 100644 index 00000000..65c42a57 --- /dev/null +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/component/ComponentGraphExt.kt @@ -0,0 +1,35 @@ +package com.github.klee0kai.thekey.stone.ksp.target.component + +import com.github.klee0kai.thekey.stone.ksp.helpers.allIdentifierTypes +import com.github.klee0kai.thekey.stone.ksp.helpers.annotations.findComponentAnnotation +import com.github.klee0kai.thekey.stone.ksp.helpers.invokecall.ModulesGraph +import com.github.klee0kai.thekey.stone.ksp.helpers.wrap.WrapHelper +import com.github.klee0kai.thekey.stone.ksp.ksp.getAllMethods +import com.google.devtools.ksp.symbol.KSClassDeclaration + +fun KSClassDeclaration.collectWrapHelper( +): WrapHelper { + val wrapHelper = WrapHelper() + val wrapperProviders = findComponentAnnotation().flatMap { it.wrapperProviders } + // TODO + + return wrapHelper +} + + +fun KSClassDeclaration.collectComponentGraph( + +): ModulesGraph { + val modulesGraph = ModulesGraph( + wrapHelper = collectWrapHelper(), + identifierTypes = allIdentifierTypes.toList(), + ) + for (m in getAllMethods(false, false, "")) { + if (m.isModuleProvideMethod) { + modulesGraph.collectFromModule(m) + } else if (m.isDepsProvideMethod) { + modulesGraph.collectFromModule(m) + } + } + return modulesGraph +} \ No newline at end of file diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/component/ComponentsMethodsExt.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/component/ComponentsMethodsExt.kt index fff5ab0c..28305fe1 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/component/ComponentsMethodsExt.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/component/ComponentsMethodsExt.kt @@ -18,6 +18,7 @@ import com.google.devtools.ksp.symbol.KSClassDeclaration import com.google.devtools.ksp.symbol.KSFunctionDeclaration import com.squareup.kotlinpoet.asClassName import com.squareup.kotlinpoet.ksp.toClassName +import com.squareup.kotlinpoet.ksp.toTypeName enum class BindInstanceType { BindInstance, @@ -175,7 +176,7 @@ fun KSFunctionDeclaration.isExtOfMethod( element = this, ) } - if (!clOwner.getAllSuperTypes().any { parent -> parent.toClassName() == argumentType.toClassName() }) { + if (!clOwner.getAllSuperTypes().any { parent -> parent.toTypeName() == argumentType.toClassName() }) { throw IncorrectSignatureException( message = "The argument for the method ${simpleName.asString()} must be the parent class of the class ${clOwner.toClassName()}. " + "The class ${argumentType.toClassName()} is not a parent to the class ${clOwner.toClassName()}.", @@ -211,7 +212,7 @@ val KSFunctionDeclaration.isBindInstanceMethod: BindInstanceType? return BindInstanceType.BindInstance } - returnType?.resolve()?.toClassName() == parameters.first().type.resolve().toClassName() -> { + returnType?.resolve()?.toTypeName() == parameters.first().type.resolve().toTypeName() -> { return BindInstanceType.BindInstanceAndProvide } } diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/component/GenComponentProcessor.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/component/GenComponentProcessor.kt index fdb242e4..49a9882b 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/component/GenComponentProcessor.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/component/GenComponentProcessor.kt @@ -2,21 +2,27 @@ package com.github.klee0kai.thekey.stone.ksp.target.component import com.github.klee0kai.stone.__hidden__.IModule import com.github.klee0kai.stone.__hidden__.IPrivateComponent +import com.github.klee0kai.stone.__hidden__.collections.RefCollection import com.github.klee0kai.stone.__hidden__.types.WeakList +import com.github.klee0kai.stone.__hidden__.types.holders.TimeHolder import com.github.klee0kai.stone.annotations.component.Component import com.github.klee0kai.stone.annotations.dependencies.Dependencies import com.github.klee0kai.stone.annotations.module.Module -import com.github.klee0kai.stone.lifecycle.StoneLifeCycleOwner +import com.github.klee0kai.stone.weakref.Inject import com.github.klee0kai.thekey.stone.ksp.exceptions.IncorrectSignatureException +import com.github.klee0kai.thekey.stone.ksp.exceptions.ObjectNotProvidedException import com.github.klee0kai.thekey.stone.ksp.helpers.* import com.github.klee0kai.thekey.stone.ksp.helpers.annotations.anyAnnotation import com.github.klee0kai.thekey.stone.ksp.helpers.invokecall.ModulesGraph +import com.github.klee0kai.thekey.stone.ksp.helpers.invokecall.model.toFieldDetail +import com.github.klee0kai.thekey.stone.ksp.helpers.invokecall.model.toQualifierAnn +import com.github.klee0kai.thekey.stone.ksp.helpers.wrap.WrapHelper import com.github.klee0kai.thekey.stone.ksp.ksp.arch.GenSpec import com.github.klee0kai.thekey.stone.ksp.ksp.arch.SymbolsToProcess import com.github.klee0kai.thekey.stone.ksp.ksp.arch.TargetFileProcessor import com.github.klee0kai.thekey.stone.ksp.ksp.getAllMethods -import com.github.klee0kai.thekey.stone.ksp.ksp.isChildOf import com.github.klee0kai.thekey.stone.ksp.poet.* +import com.github.klee0kai.thekey.stone.ksp.poet.member.CoroutinesMemberFunctions.SupervisorJob import com.github.klee0kai.thekey.stone.ksp.target.GenModuleProcessor import com.google.devtools.ksp.containingFile import com.google.devtools.ksp.getAllSuperTypes @@ -29,13 +35,15 @@ import com.google.devtools.ksp.symbol.KSFunctionDeclaration import com.squareup.kotlinpoet.* import com.squareup.kotlinpoet.ParameterizedTypeName.Companion.parameterizedBy import com.squareup.kotlinpoet.ksp.toClassName +import com.squareup.kotlinpoet.ksp.toTypeName +import kotlinx.coroutines.CoroutineScope import com.google.devtools.ksp.processing.Dependencies as KspDependencies class GenComponentProcessor : TargetFileProcessor { companion object { val refCollectionGlFieldName = "__refCollection" - val scheduleGlFieldName = "__scheduler" + val scopeFieldName = "__scope" val hiddenModuleFieldName = "__hiddenModule" val relatedComponentsListFieldName = "__related" val protectRecursiveField = "__protectRecursive" @@ -47,7 +55,7 @@ class GenComponentProcessor : TargetFileProcessor { val allReserveMethodNames = listOf( refCollectionGlFieldName, - scheduleGlFieldName, + scopeFieldName, hiddenModuleFieldName, relatedComponentsListFieldName, protectRecursiveField, @@ -83,10 +91,10 @@ class GenComponentProcessor : TargetFileProcessor { val componentCl = validSymbol as? KSClassDeclaration ?: return null val identifierTypes = componentCl.allIdentifierTypes.toList() - val wrapperTypes = componentCl.wrapperProviders.toList() + val wrapHelper = componentCl.collectWrapHelper() + val modulesGraph = componentCl.collectComponentGraph() val delayedCodeBlocks = DelayedCodeBlocks() - val genComponentClassName = componentCl.componentStoneClName val fileSpec = genFileSpec(genComponentClassName.packageName, genComponentClassName.simpleName) { @@ -109,7 +117,7 @@ class GenComponentProcessor : TargetFileProcessor { val moduleCl = m.returnType?.resolve()?.declaration as? KSClassDeclaration ?: throw IncorrectSignatureException( message = "wrong return type. Must by Module type", - element = m + element = m, ) genProperty(m.simpleName.asString(), moduleCl.moduleStoneClName) { addModifiers(KModifier.PRIVATE) @@ -125,7 +133,7 @@ class GenComponentProcessor : TargetFileProcessor { val providingModuleFun = componentsAllMethods .filter { it.isModuleProvideMethod } .firstOrNull { - it.returnType?.resolve()?.toClassName() == m.returnType?.resolve()?.toClassName() + it.returnType?.resolve()?.toTypeName() == m.returnType?.resolve()?.toTypeName() } ?: throw IncorrectSignatureException( message = "Component must also have providing module simple method with same type", @@ -203,6 +211,8 @@ class GenComponentProcessor : TargetFileProcessor { genInjectMethod( componentCl = componentCl, method = m, + wrapHelper = wrapHelper, + modulesGraph = modulesGraph, ) } @@ -239,16 +249,14 @@ class GenComponentProcessor : TargetFileProcessor { private fun TypeSpec.Builder.genInjectMethod( componentCl: KSClassDeclaration, method: KSFunctionDeclaration, + wrapHelper: WrapHelper, modulesGraph: ModulesGraph, ) { val identifierTypes = componentCl.allIdentifierTypes.toList() - val idArguments = method.parameters.filter { it.type.resolve() in identifierTypes } - val lifeCycleOwnerArg = method.parameters.firstOrNull { - (it.type.resolve().declaration as? KSClassDeclaration) - ?.isChildOf(StoneLifeCycleOwner::class.asClassName()) == true - } - val injectableArguments = method.parameters.filter { it.type.resolve() !in identifierTypes } - if (originatingElements.isEmpty()) { + val idArguments = method.parameters.identifierParameters(identifierTypes) + val lifeCycleOwnerArg = method.parameters.lifeCycleParameter() + val injectableArguments = method.parameters.notIdentifierParameters(identifierTypes) + if (injectableArguments.isEmpty()) { throw IncorrectSignatureException( message = "No injectable parameter at ${method.simpleName.asString()}", element = method, @@ -256,23 +264,112 @@ class GenComponentProcessor : TargetFileProcessor { } genOverrideFun(method) { - for (injectableArgument in injectableArguments) { - val injectableCl = injectableArgument.type.resolve().declaration as? KSClassDeclaration + for (injectableField in injectableArguments) { + val injectableCl = injectableField.type.resolve().declaration as? KSClassDeclaration ?: throw IncorrectSignatureException( message = "parameter must be a class", - element = injectableArgument, + element = injectableField, ) + for (injectField in injectableCl.getAllProperties()) { + if (!injectField.anyAnnotation(Inject::class.asClassName()).any()) continue + val provideCode = modulesGraph.codeProvideType( methodName = null, - returnType = injectField.type.resolve().toClassName(), - qualifierAnns = injectField.qualifierAnnotations.toList(), + returnType = injectField.type.resolve().toTypeName(), + qualifierAnns = injectField.qualifierAnnotations.map { it.toQualifierAnn() }.toSet(), + declaredFields = method.parameters.map { it.toFieldDetail() }, + ) + + if (provideCode == null) { + throw ObjectNotProvidedException( + message = "Error provide type ${injectField.type.resolve().toTypeName()}. " + + "Required in ${injectableCl.toClassName()}.${injectField.simpleName.asString()}", + element = method, + ) + } + + addStatement( + "%L.%L = %L", + injectableField.name!!.asString(), + injectField.simpleName.asString(), + provideCode, ) - // TODO } + + for (injectMethod in injectableCl.getAllMethods(false, false, "")) { + if (!injectMethod.anyAnnotation(Inject::class.asClassName()).any()) continue + val providingArgsCode = CodeBlock.builder() + for (injectField in injectMethod.parameters) { + val provideCode = modulesGraph.codeProvideType( + null, + injectField.type.resolve().toTypeName(), + injectField.qualifierAnnotations.map { it.toQualifierAnn() }.toSet(), + method.parameters.map { it.toFieldDetail() }, + ) + + if (provideCode == null) { + throw ObjectNotProvidedException( + message = "Error provide type ${injectField.type.resolve().toTypeName()}. " + + "Required in ${injectableCl.toClassName()}.${injectMethod.simpleName.asString()}", + element = method, + ) + } + + if (!providingArgsCode.isEmpty()) providingArgsCode.add(", ") + providingArgsCode.add(provideCode) + } + + addCode("%L.%L( ", injectableField.name, injectMethod.simpleName.asString()) + .addCode(providingArgsCode.build()) + .addStatement(")"); + } + } + + //protect by lifecycle owner + for (injectableField in injectableArguments) { + val injectableCl = injectableField.type.resolve().declaration as? KSClassDeclaration + ?: throw IncorrectSignatureException( + message = "parameter must be a class", + element = injectableField, + ) + + + val subscrCode = CodeBlock.builder() + var emptyCode = true + if (lifeCycleOwnerArg != null) { + subscrCode.beginControlFlow( + "%L?.subscribe{ timeMillis -> ", + lifeCycleOwnerArg.name!!.asString(), + ) + for (injectField in injectableCl.getAllProperties()) { + if (!injectField.anyAnnotation(Inject::class.asClassName()).any()) continue + if (wrapHelper.isNonCachingWrapper( + injectField.type.resolve().toClassName() + ) + ) //nothing to protect + continue + + emptyCode = false + subscrCode.addStatement( + "%L.add( %T( %L, %L.%L , timeMillis) )", + refCollectionGlFieldName, + TimeHolder::class.asClassName(), + scopeFieldName, + injectableField.name!!.asString(), + injectField.simpleName.asString() + ) + } + + subscrCode + .endControlFlow() + + if (!emptyCode) addCode(subscrCode.build()) + } + } } } @@ -296,6 +393,23 @@ class GenComponentProcessor : TargetFileProcessor { mutable(true) initializer("false") } + genProperty( + name = refCollectionGlFieldName, + type = RefCollection::class.asClassName().parameterizedBy(ANY), + ) { + addModifiers(KModifier.PRIVATE) + mutable(true) + initializer("%T()", RefCollection::class.asClassName().parameterizedBy(ANY)) + } + + genProperty( + name = scopeFieldName, + type = CoroutineScope::class.asClassName(), + ) { + addModifiers(KModifier.PRIVATE) + mutable(true) + initializer("%T(%M())", CoroutineScope::class.asClassName(),SupervisorJob) + } genProperty( name = hiddenModuleFieldName, diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/hiddenmodule/GenHiddenModuleProcessor.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/hiddenmodule/GenHiddenModuleProcessor.kt index af4e28a0..4f943db6 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/hiddenmodule/GenHiddenModuleProcessor.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/hiddenmodule/GenHiddenModuleProcessor.kt @@ -15,6 +15,7 @@ import com.google.devtools.ksp.processing.KSPLogger import com.google.devtools.ksp.processing.Resolver import com.google.devtools.ksp.symbol.KSAnnotated import com.google.devtools.ksp.symbol.KSClassDeclaration +import com.squareup.kotlinpoet.KModifier import com.squareup.kotlinpoet.asClassName class GenHiddenModuleProcessor : TargetFileProcessor { @@ -44,6 +45,7 @@ class GenHiddenModuleProcessor : TargetFileProcessor { genClass(genHiddenModuleCl) { addSuperinterface(IModule::class) + addModifiers(KModifier.ABSTRACT) } diff --git a/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/__hidden__/types/holders/TimeHolder.kt b/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/__hidden__/types/holders/TimeHolder.kt new file mode 100644 index 00000000..4c9fde6f --- /dev/null +++ b/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/__hidden__/types/holders/TimeHolder.kt @@ -0,0 +1,45 @@ +package com.github.klee0kai.stone.__hidden__.types.holders + +import com.github.klee0kai.stone.weakref.Ref +import com.github.klee0kai.stone.weakref.SoftRef +import kotlinx.coroutines.* + +/** + * Stone Private class + */ +class TimeHolder( + private var scope: CoroutineScope = CoroutineScope(SupervisorJob()), + ob: T? = null, + holdTime: Long? = null, +) : Ref { + + var ref: Ref? = null + + init { + if (ob != null && holdTime != null) { + hold(ob, holdTime) + } + } + + private var holdJob: Job? = null + + fun hold(ob: T?, holdTime: Long): T? { + clearRef() + this.ref = SoftRef(ob) + holdJob?.cancel() + holdJob = scope.launch { + delay(holdTime) + clearRef() + } + return ob + } + + override fun get(): T? = ref?.get() + + private fun clearRef() { + ref = null + holdJob?.cancel() + holdJob = null + } + +} diff --git a/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/lifecycle/StoneLifeCycleListener.kt b/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/lifecycle/StoneLifeCycleListener.kt index 2acd3cf0..d785a86b 100644 --- a/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/lifecycle/StoneLifeCycleListener.kt +++ b/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/lifecycle/StoneLifeCycleListener.kt @@ -1,6 +1,6 @@ package com.github.klee0kai.stone.lifecycle -interface StoneLifeCycleListener { +fun interface StoneLifeCycleListener { fun protectForInjected(timeMillis: Long) diff --git a/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/lifecycle/StoneLifeCycleOwner.kt b/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/lifecycle/StoneLifeCycleOwner.kt index dbd443c3..15998e94 100644 --- a/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/lifecycle/StoneLifeCycleOwner.kt +++ b/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/lifecycle/StoneLifeCycleOwner.kt @@ -49,8 +49,8 @@ package com.github.klee0kai.stone.lifecycle * } ` * */ -interface StoneLifeCycleOwner { +fun interface StoneLifeCycleOwner { - fun subscribe(listener: StoneLifeCycleListener?) + fun subscribe(listener: StoneLifeCycleListener) } diff --git a/tests_kotlin/src/main/kotlin/com/github/klee0kai/test_kotlin/di/base_forest/RainForestComponent.kt b/tests_kotlin/src/main/kotlin/com/github/klee0kai/test_kotlin/di/base_forest/RainForestComponent.kt index 6f85f9c9..431c668c 100644 --- a/tests_kotlin/src/main/kotlin/com/github/klee0kai/test_kotlin/di/base_forest/RainForestComponent.kt +++ b/tests_kotlin/src/main/kotlin/com/github/klee0kai/test_kotlin/di/base_forest/RainForestComponent.kt @@ -22,7 +22,9 @@ interface RainForestComponent { fun gcAll() fun inject(university: University) + fun inject(gorilla: Gorilla) + fun inject(cougar: Cougar) @ProtectInjected(timeMillis = 50) From 65e40610041703966806a1046a7bf9f240f0eeb1 Mon Sep 17 00:00:00 2001 From: klee0kai Date: Mon, 8 Dec 2025 20:19:20 +0100 Subject: [PATCH 047/122] gen hidden module --- .../hiddenmodule/GenHiddenModuleProcessor.kt | 113 ++++++++++++++++-- 1 file changed, 106 insertions(+), 7 deletions(-) diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/hiddenmodule/GenHiddenModuleProcessor.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/hiddenmodule/GenHiddenModuleProcessor.kt index 4f943db6..a28cba7e 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/hiddenmodule/GenHiddenModuleProcessor.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/hiddenmodule/GenHiddenModuleProcessor.kt @@ -1,24 +1,43 @@ package com.github.klee0kai.thekey.stone.ksp.target.hiddenmodule import com.github.klee0kai.stone.__hidden__.IModule +import com.github.klee0kai.stone.__hidden__.SwitchCacheParam import com.github.klee0kai.stone.annotations.component.Component +import com.github.klee0kai.thekey.stone.ksp.helpers.allIdentifierTypes import com.github.klee0kai.thekey.stone.ksp.helpers.hiddenModuleStoneClName import com.github.klee0kai.thekey.stone.ksp.ksp.arch.GenSpec import com.github.klee0kai.thekey.stone.ksp.ksp.arch.SymbolsToProcess import com.github.klee0kai.thekey.stone.ksp.ksp.arch.TargetFileProcessor -import com.github.klee0kai.thekey.stone.ksp.poet.genClass -import com.github.klee0kai.thekey.stone.ksp.poet.genFileSpec -import com.github.klee0kai.thekey.stone.ksp.poet.genLibComment +import com.github.klee0kai.thekey.stone.ksp.poet.* +import com.github.klee0kai.thekey.stone.ksp.target.GenModuleProcessor.Companion.appliedLocalFieldName +import com.github.klee0kai.thekey.stone.ksp.target.GenModuleProcessor.Companion.bindMethodName +import com.github.klee0kai.thekey.stone.ksp.target.GenModuleProcessor.Companion.clearNullsMethodName +import com.github.klee0kai.thekey.stone.ksp.target.GenModuleProcessor.Companion.factoryFieldName +import com.github.klee0kai.thekey.stone.ksp.target.GenModuleProcessor.Companion.initCachesFromMethodName +import com.github.klee0kai.thekey.stone.ksp.target.GenModuleProcessor.Companion.initMethodName +import com.github.klee0kai.thekey.stone.ksp.target.GenModuleProcessor.Companion.switchRefMethodName +import com.github.klee0kai.thekey.stone.ksp.target.GenModuleProcessor.Companion.updateBindInstancesFrom +import com.github.klee0kai.thekey.stone.ksp.target.component.collectComponentGraph +import com.github.klee0kai.thekey.stone.ksp.target.component.collectWrapHelper import com.google.devtools.ksp.containingFile import com.google.devtools.ksp.processing.Dependencies import com.google.devtools.ksp.processing.KSPLogger import com.google.devtools.ksp.processing.Resolver import com.google.devtools.ksp.symbol.KSAnnotated import com.google.devtools.ksp.symbol.KSClassDeclaration -import com.squareup.kotlinpoet.KModifier -import com.squareup.kotlinpoet.asClassName +import com.squareup.kotlinpoet.* +import com.squareup.kotlinpoet.ParameterizedTypeName.Companion.parameterizedBy +import kotlin.reflect.KClass class GenHiddenModuleProcessor : TargetFileProcessor { + + + private class DelayedCodeBlocks( + val bindMethodBody: CodeBlock.Builder = CodeBlock.builder(), + val clearNullsMethodBody: CodeBlock.Builder = CodeBlock.builder(), + val switchRefStatementBuilders: MutableMap, CodeBlock.Builder> = mutableMapOf() + ) + override suspend fun findSymbolsToProcess( resolver: Resolver, ) = SymbolsToProcess( @@ -39,14 +58,19 @@ class GenHiddenModuleProcessor : TargetFileProcessor { val componentCl = validSymbol as? KSClassDeclaration ?: return null val genHiddenModuleCl = componentCl.hiddenModuleStoneClName + val identifierTypes = componentCl.allIdentifierTypes.toList() + val wrapHelper = componentCl.collectWrapHelper() + val modulesGraph = componentCl.collectComponentGraph() + val delayedCodeBlocks = DelayedCodeBlocks() val fileSpec = genFileSpec(genHiddenModuleCl.packageName, genHiddenModuleCl.simpleName) { genLibComment() genClass(genHiddenModuleCl) { addSuperinterface(IModule::class) - addModifiers(KModifier.ABSTRACT) - + genIModelMethods( + codeBlocks = delayedCodeBlocks, + ) } } @@ -57,4 +81,79 @@ class GenHiddenModuleProcessor : TargetFileProcessor { dependencies = Dependencies(aggregating = false, fileOwner), ) } + + private fun TypeSpec.Builder.genIModelMethods( + codeBlocks: DelayedCodeBlocks, + ) { + genProperty( + name = factoryFieldName, + type = ANY.copy(nullable = true), + ) { + addModifiers(KModifier.OVERRIDE) + initializer("null") + } + + genFun(initMethodName) { + addModifiers(KModifier.OVERRIDE) + returns(BOOLEAN) + addParameter("or", Any::class) + addStatement("if (or === this) return false") + addStatement("var %L = false", appliedLocalFieldName) + + addStatement("return %L", appliedLocalFieldName) + } + + genFun(initCachesFromMethodName) { + addModifiers(KModifier.OVERRIDE) + addParameter("m", IModule::class) + addStatement("if (m == this) return") + } + + genFun(bindMethodName) { + addModifiers(KModifier.OVERRIDE) + addParameter("or", Any::class) + returns(BOOLEAN) + addStatement("var %L = false", appliedLocalFieldName) + addCode(codeBlocks.bindMethodBody.build()) + addStatement("return %L", appliedLocalFieldName) + } + + genFun(switchRefMethodName) { + addModifiers(KModifier.OVERRIDE) + addParameter( + "scopes", + Set::class.asClassName() + .parameterizedBy( + KClass::class.asClassName() + .parameterizedBy(STAR) + ) + ) + addParameter("__params", SwitchCacheParam::class) + + codeBlocks.switchRefStatementBuilders.forEach { (key, value) -> + addCode("if (listOf(") + key.forEachIndexed { idx, scope -> + if (idx > 0) addCode(", ") + addCode("%T::class", scope) + } + beginControlFlow(").containsAll(scopes))") + addCode(value.build()) + endControlFlow() + } + } + + genFun(updateBindInstancesFrom) { + addModifiers(KModifier.OVERRIDE) + addParameter("m", IModule::class) + addStatement("if (m == this) return") + } + + genFun(clearNullsMethodName) { + addModifiers(KModifier.OVERRIDE) + addCode(codeBlocks.clearNullsMethodBody.build()) + } + + } + + } From 6d25d4a8b0c89fce845b5db99ba23542b390f4fe Mon Sep 17 00:00:00 2001 From: klee0kai Date: Mon, 8 Dec 2025 21:21:45 +0100 Subject: [PATCH 048/122] Rename .java to .kt --- .../di/base_forest/{ForestComponent.java => ForestComponent.kt} | 0 .../di/base_forest/{IdentityModule.java => IdentityModule.kt} | 0 .../di/base_forest/{UnitedBlueModule.java => UnitedBlueModule.kt} | 0 .../test/di/base_forest/{UnitedModule.java => UnitedModule.kt} | 0 .../test/di/base_phone/{PhoneComponent.java => PhoneComponent.kt} | 0 .../test/di/base_phone/{TechModule.java => TechModule.kt} | 0 .../identifiers/{DataStorageSize.java => DataStorageSize.kt} | 0 .../base_phone/identifiers/{PhoneOsType.java => PhoneOsType.kt} | 0 .../identifiers/{PhoneOsVersion.java => PhoneOsVersion.kt} | 0 .../test/di/base_phone/identifiers/{RamSize.java => RamSize.kt} | 0 .../{GodWorkspaceComponent.java => GodWorkspaceComponent.kt} | 0 .../simple/{SunSystemModule.java => SunSystemModule.kt} | 0 .../{SevenPlanetComponent.java => SevenPlanetComponent.kt} | 0 .../{SevenPlanetModule.java => SevenPlanetModule.kt} | 0 .../simple_inject/{StarsModule.java => StarsModule.kt} | 0 .../singlemethod/{PlanetComponent.java => PlanetComponent.kt} | 0 .../di/bindinstance/singlemethod/{SunModule.java => SunModule.kt} | 0 .../{PlanetRollingComponent.java => PlanetRollingComponent.kt} | 0 .../{StarSkyComponent.java => StarSkyComponent.kt} | 0 .../singlemethod_inject/{StarSkyModule.java => StarSkyModule.kt} | 0 .../solarsystem/{PlanetModule.java => PlanetModule.kt} | 0 .../{SolarSystemComponent.java => SolarSystemComponent.kt} | 0 .../{SolarSystemDependencies.java => SolarSystemDependencies.kt} | 0 .../di/earthmirror/{EarthComponent.java => EarthComponent.kt} | 0 .../test/di/earthmirror/{EastModule.java => EastModule.kt} | 0 .../test/di/earthmirror/{WestModule.java => WestModule.kt} | 0 .../di/gcforest/{GcEarthComponent.java => GcEarthComponent.kt} | 0 .../test/di/gcforest/{GcEarthModule.java => GcEarthModule.kt} | 0 .../test/di/gcforest/{GcGodComponent.java => GcGodComponent.kt} | 0 .../di/gcforest/{GcSunSystemModule.java => GcSunSystemModule.kt} | 0 .../gcforest/scopes/{GcMountainScope.java => GcMountainScope.kt} | 0 .../di/gcforest/scopes/{GcPlanetScope.java => GcPlanetScope.kt} | 0 .../di/gcforest/scopes/{GcRiverScope.java => GcRiverScope.kt} | 0 .../test/di/gcforest/scopes/{GcSunScope.java => GcSunScope.kt} | 0 .../nulls/{HouseNullsComponent.java => HouseNullsComponent.kt} | 0 .../di/house/nulls/{HouseNullsModule.java => HouseNullsModule.kt} | 0 .../test/di/house/simple/{AreasModule.java => AreasModule.kt} | 0 .../di/house/simple/{HouseComponent.java => HouseComponent.kt} | 0 .../test/di/house/simple/{HouseModule.java => HouseModule.kt} | 0 .../test/di/house/simple/{RoomsModule.java => RoomsModule.kt} | 0 .../test/di/house/simple/{ToolsModule.java => ToolsModule.kt} | 0 .../{SwitchCacheComponent.java => SwitchCacheComponent.kt} | 0 .../{ITechProviderComponent.java => ITechProviderComponent.kt} | 0 .../{TechFactoryComponent.java => TechFactoryComponent.kt} | 0 .../techfactory/{TechFactoryModule.java => TechFactoryModule.kt} | 0 .../test/di/wire/{WireComponent.java => WireComponent.kt} | 0 .../klee0kai/test/di/wire/{WireModule.java => WireModule.kt} | 0 .../java/com/github/klee0kai/test/house/{House.java => House.kt} | 0 .../com/github/klee0kai/test/house/{InHouse.java => InHouse.kt} | 0 .../house/identifiers/{StoreAreaType.java => StoreAreaType.kt} | 0 .../github/klee0kai/test/house/kitchen/{Kichen.java => Kichen.kt} | 0 .../kitchen/cookingarea/{CookingArea.java => CookingArea.kt} | 0 .../test/house/kitchen/sinkarea/{SinkArea.java => SinkArea.kt} | 0 .../test/house/kitchen/storagearea/{Clothes.java => Clothes.kt} | 0 .../test/house/kitchen/storagearea/{Cookware.java => Cookware.kt} | 0 .../kitchen/storagearea/{GarageStore.java => GarageStore.kt} | 0 .../house/kitchen/storagearea/{Sanitizers.java => Sanitizers.kt} | 0 .../house/kitchen/storagearea/{StoreArea.java => StoreArea.kt} | 0 .../klee0kai/test/house/rooms/{BathRoom.java => BathRoom.kt} | 0 .../github/klee0kai/test/house/rooms/{BedRoom.java => BedRoom.kt} | 0 .../github/klee0kai/test/house/rooms/{Garage.java => Garage.kt} | 0 .../com/github/klee0kai/test/mowgli/{MoonSky.java => MoonSky.kt} | 0 .../com/github/klee0kai/test/mowgli/{School.java => School.kt} | 0 .../github/klee0kai/test/mowgli/animal/{Horse.java => Horse.kt} | 0 .../klee0kai/test/mowgli/animal/{IAnimal.java => IAnimal.kt} | 0 .../github/klee0kai/test/mowgli/animal/{Mowgli.java => Mowgli.kt} | 0 .../github/klee0kai/test/mowgli/animal/{Snake.java => Snake.kt} | 0 .../com/github/klee0kai/test/mowgli/body/{Blood.java => Blood.kt} | 0 .../klee0kai/test/mowgli/community/{History.java => History.kt} | 0 .../com/github/klee0kai/test/mowgli/earth/{Cave.java => Cave.kt} | 0 .../klee0kai/test/mowgli/earth/{IMountain.java => IMountain.kt} | 0 .../github/klee0kai/test/mowgli/earth/{IRiver.java => IRiver.kt} | 0 .../klee0kai/test/mowgli/earth/{Mountain.java => Mountain.kt} | 0 .../github/klee0kai/test/mowgli/earth/{River.java => River.kt} | 0 .../github/klee0kai/test/mowgli/galaxy/{Earth.java => Earth.kt} | 0 .../klee0kai/test/mowgli/galaxy/{IPlanet.java => IPlanet.kt} | 0 .../github/klee0kai/test/mowgli/galaxy/{IStar.java => IStar.kt} | 0 .../klee0kai/test/mowgli/galaxy/{Mercury.java => Mercury.kt} | 0 .../github/klee0kai/test/mowgli/galaxy/{Saturn.java => Saturn.kt} | 0 .../test/mowgli/galaxy/{SolarSystem.java => SolarSystem.kt} | 0 .../com/github/klee0kai/test/mowgli/galaxy/{Sun.java => Sun.kt} | 0 .../test/mowgli/identity/{Conscience.java => Conscience.kt} | 0 .../klee0kai/test/mowgli/identity/{Ideology.java => Ideology.kt} | 0 .../test/mowgli/identity/{Knowledge.java => Knowledge.kt} | 0 .../klee0kai/test/tech/components/{Battery.java => Battery.kt} | 0 .../test/tech/components/{DataStorage.java => DataStorage.kt} | 0 .../tech/components/{OperationSystem.java => OperationSystem.kt} | 0 .../com/github/klee0kai/test/tech/components/{Ram.java => Ram.kt} | 0 .../klee0kai/test/tech/phone/{GoodPhone.java => GoodPhone.kt} | 0 .../klee0kai/test/tech/phone/{OnePhone.java => OnePhone.kt} | 0 .../github/klee0kai/test/tech/phone/base/{ATech.java => ATech.kt} | 0 .../tech/phone/base/{ATechLifecycle.java => ATechLifecycle.kt} | 0 .../tech/phone/base/{LifecycleUtils.java => LifecycleUtils.kt} | 0 .../java/com/github/klee0kai/test/wire/{Wire.java => Wire.kt} | 0 .../com/github/klee0kai/test/wire/types/{Hdmi.java => Hdmi.kt} | 0 .../github/klee0kai/test/wire/types/{MiniUsb.java => MiniUsb.kt} | 0 .../java/com/github/klee0kai/test/wire/types/{Usb.java => Usb.kt} | 0 97 files changed, 0 insertions(+), 0 deletions(-) rename tests/src/main/java/com/github/klee0kai/test/di/base_forest/{ForestComponent.java => ForestComponent.kt} (100%) rename tests/src/main/java/com/github/klee0kai/test/di/base_forest/{IdentityModule.java => IdentityModule.kt} (100%) rename tests/src/main/java/com/github/klee0kai/test/di/base_forest/{UnitedBlueModule.java => UnitedBlueModule.kt} (100%) rename tests/src/main/java/com/github/klee0kai/test/di/base_forest/{UnitedModule.java => UnitedModule.kt} (100%) rename tests/src/main/java/com/github/klee0kai/test/di/base_phone/{PhoneComponent.java => PhoneComponent.kt} (100%) rename tests/src/main/java/com/github/klee0kai/test/di/base_phone/{TechModule.java => TechModule.kt} (100%) rename tests/src/main/java/com/github/klee0kai/test/di/base_phone/identifiers/{DataStorageSize.java => DataStorageSize.kt} (100%) rename tests/src/main/java/com/github/klee0kai/test/di/base_phone/identifiers/{PhoneOsType.java => PhoneOsType.kt} (100%) rename tests/src/main/java/com/github/klee0kai/test/di/base_phone/identifiers/{PhoneOsVersion.java => PhoneOsVersion.kt} (100%) rename tests/src/main/java/com/github/klee0kai/test/di/base_phone/identifiers/{RamSize.java => RamSize.kt} (100%) rename tests/src/main/java/com/github/klee0kai/test/di/bindinstance/simple/{GodWorkspaceComponent.java => GodWorkspaceComponent.kt} (100%) rename tests/src/main/java/com/github/klee0kai/test/di/bindinstance/simple/{SunSystemModule.java => SunSystemModule.kt} (100%) rename tests/src/main/java/com/github/klee0kai/test/di/bindinstance/simple_inject/{SevenPlanetComponent.java => SevenPlanetComponent.kt} (100%) rename tests/src/main/java/com/github/klee0kai/test/di/bindinstance/simple_inject/{SevenPlanetModule.java => SevenPlanetModule.kt} (100%) rename tests/src/main/java/com/github/klee0kai/test/di/bindinstance/simple_inject/{StarsModule.java => StarsModule.kt} (100%) rename tests/src/main/java/com/github/klee0kai/test/di/bindinstance/singlemethod/{PlanetComponent.java => PlanetComponent.kt} (100%) rename tests/src/main/java/com/github/klee0kai/test/di/bindinstance/singlemethod/{SunModule.java => SunModule.kt} (100%) rename tests/src/main/java/com/github/klee0kai/test/di/bindinstance/singlemethod_gc/{PlanetRollingComponent.java => PlanetRollingComponent.kt} (100%) rename tests/src/main/java/com/github/klee0kai/test/di/bindinstance/singlemethod_inject/{StarSkyComponent.java => StarSkyComponent.kt} (100%) rename tests/src/main/java/com/github/klee0kai/test/di/bindinstance/singlemethod_inject/{StarSkyModule.java => StarSkyModule.kt} (100%) rename tests/src/main/java/com/github/klee0kai/test/di/bindinstance/solarsystem/{PlanetModule.java => PlanetModule.kt} (100%) rename tests/src/main/java/com/github/klee0kai/test/di/bindinstance/solarsystem/{SolarSystemComponent.java => SolarSystemComponent.kt} (100%) rename tests/src/main/java/com/github/klee0kai/test/di/bindinstance/solarsystem/{SolarSystemDependencies.java => SolarSystemDependencies.kt} (100%) rename tests/src/main/java/com/github/klee0kai/test/di/earthmirror/{EarthComponent.java => EarthComponent.kt} (100%) rename tests/src/main/java/com/github/klee0kai/test/di/earthmirror/{EastModule.java => EastModule.kt} (100%) rename tests/src/main/java/com/github/klee0kai/test/di/earthmirror/{WestModule.java => WestModule.kt} (100%) rename tests/src/main/java/com/github/klee0kai/test/di/gcforest/{GcEarthComponent.java => GcEarthComponent.kt} (100%) rename tests/src/main/java/com/github/klee0kai/test/di/gcforest/{GcEarthModule.java => GcEarthModule.kt} (100%) rename tests/src/main/java/com/github/klee0kai/test/di/gcforest/{GcGodComponent.java => GcGodComponent.kt} (100%) rename tests/src/main/java/com/github/klee0kai/test/di/gcforest/{GcSunSystemModule.java => GcSunSystemModule.kt} (100%) rename tests/src/main/java/com/github/klee0kai/test/di/gcforest/scopes/{GcMountainScope.java => GcMountainScope.kt} (100%) rename tests/src/main/java/com/github/klee0kai/test/di/gcforest/scopes/{GcPlanetScope.java => GcPlanetScope.kt} (100%) rename tests/src/main/java/com/github/klee0kai/test/di/gcforest/scopes/{GcRiverScope.java => GcRiverScope.kt} (100%) rename tests/src/main/java/com/github/klee0kai/test/di/gcforest/scopes/{GcSunScope.java => GcSunScope.kt} (100%) rename tests/src/main/java/com/github/klee0kai/test/di/house/nulls/{HouseNullsComponent.java => HouseNullsComponent.kt} (100%) rename tests/src/main/java/com/github/klee0kai/test/di/house/nulls/{HouseNullsModule.java => HouseNullsModule.kt} (100%) rename tests/src/main/java/com/github/klee0kai/test/di/house/simple/{AreasModule.java => AreasModule.kt} (100%) rename tests/src/main/java/com/github/klee0kai/test/di/house/simple/{HouseComponent.java => HouseComponent.kt} (100%) rename tests/src/main/java/com/github/klee0kai/test/di/house/simple/{HouseModule.java => HouseModule.kt} (100%) rename tests/src/main/java/com/github/klee0kai/test/di/house/simple/{RoomsModule.java => RoomsModule.kt} (100%) rename tests/src/main/java/com/github/klee0kai/test/di/house/simple/{ToolsModule.java => ToolsModule.kt} (100%) rename tests/src/main/java/com/github/klee0kai/test/di/swcache/{SwitchCacheComponent.java => SwitchCacheComponent.kt} (100%) rename tests/src/main/java/com/github/klee0kai/test/di/techfactory/{ITechProviderComponent.java => ITechProviderComponent.kt} (100%) rename tests/src/main/java/com/github/klee0kai/test/di/techfactory/{TechFactoryComponent.java => TechFactoryComponent.kt} (100%) rename tests/src/main/java/com/github/klee0kai/test/di/techfactory/{TechFactoryModule.java => TechFactoryModule.kt} (100%) rename tests/src/main/java/com/github/klee0kai/test/di/wire/{WireComponent.java => WireComponent.kt} (100%) rename tests/src/main/java/com/github/klee0kai/test/di/wire/{WireModule.java => WireModule.kt} (100%) rename tests/src/main/java/com/github/klee0kai/test/house/{House.java => House.kt} (100%) rename tests/src/main/java/com/github/klee0kai/test/house/{InHouse.java => InHouse.kt} (100%) rename tests/src/main/java/com/github/klee0kai/test/house/identifiers/{StoreAreaType.java => StoreAreaType.kt} (100%) rename tests/src/main/java/com/github/klee0kai/test/house/kitchen/{Kichen.java => Kichen.kt} (100%) rename tests/src/main/java/com/github/klee0kai/test/house/kitchen/cookingarea/{CookingArea.java => CookingArea.kt} (100%) rename tests/src/main/java/com/github/klee0kai/test/house/kitchen/sinkarea/{SinkArea.java => SinkArea.kt} (100%) rename tests/src/main/java/com/github/klee0kai/test/house/kitchen/storagearea/{Clothes.java => Clothes.kt} (100%) rename tests/src/main/java/com/github/klee0kai/test/house/kitchen/storagearea/{Cookware.java => Cookware.kt} (100%) rename tests/src/main/java/com/github/klee0kai/test/house/kitchen/storagearea/{GarageStore.java => GarageStore.kt} (100%) rename tests/src/main/java/com/github/klee0kai/test/house/kitchen/storagearea/{Sanitizers.java => Sanitizers.kt} (100%) rename tests/src/main/java/com/github/klee0kai/test/house/kitchen/storagearea/{StoreArea.java => StoreArea.kt} (100%) rename tests/src/main/java/com/github/klee0kai/test/house/rooms/{BathRoom.java => BathRoom.kt} (100%) rename tests/src/main/java/com/github/klee0kai/test/house/rooms/{BedRoom.java => BedRoom.kt} (100%) rename tests/src/main/java/com/github/klee0kai/test/house/rooms/{Garage.java => Garage.kt} (100%) rename tests/src/main/java/com/github/klee0kai/test/mowgli/{MoonSky.java => MoonSky.kt} (100%) rename tests/src/main/java/com/github/klee0kai/test/mowgli/{School.java => School.kt} (100%) rename tests/src/main/java/com/github/klee0kai/test/mowgli/animal/{Horse.java => Horse.kt} (100%) rename tests/src/main/java/com/github/klee0kai/test/mowgli/animal/{IAnimal.java => IAnimal.kt} (100%) rename tests/src/main/java/com/github/klee0kai/test/mowgli/animal/{Mowgli.java => Mowgli.kt} (100%) rename tests/src/main/java/com/github/klee0kai/test/mowgli/animal/{Snake.java => Snake.kt} (100%) rename tests/src/main/java/com/github/klee0kai/test/mowgli/body/{Blood.java => Blood.kt} (100%) rename tests/src/main/java/com/github/klee0kai/test/mowgli/community/{History.java => History.kt} (100%) rename tests/src/main/java/com/github/klee0kai/test/mowgli/earth/{Cave.java => Cave.kt} (100%) rename tests/src/main/java/com/github/klee0kai/test/mowgli/earth/{IMountain.java => IMountain.kt} (100%) rename tests/src/main/java/com/github/klee0kai/test/mowgli/earth/{IRiver.java => IRiver.kt} (100%) rename tests/src/main/java/com/github/klee0kai/test/mowgli/earth/{Mountain.java => Mountain.kt} (100%) rename tests/src/main/java/com/github/klee0kai/test/mowgli/earth/{River.java => River.kt} (100%) rename tests/src/main/java/com/github/klee0kai/test/mowgli/galaxy/{Earth.java => Earth.kt} (100%) rename tests/src/main/java/com/github/klee0kai/test/mowgli/galaxy/{IPlanet.java => IPlanet.kt} (100%) rename tests/src/main/java/com/github/klee0kai/test/mowgli/galaxy/{IStar.java => IStar.kt} (100%) rename tests/src/main/java/com/github/klee0kai/test/mowgli/galaxy/{Mercury.java => Mercury.kt} (100%) rename tests/src/main/java/com/github/klee0kai/test/mowgli/galaxy/{Saturn.java => Saturn.kt} (100%) rename tests/src/main/java/com/github/klee0kai/test/mowgli/galaxy/{SolarSystem.java => SolarSystem.kt} (100%) rename tests/src/main/java/com/github/klee0kai/test/mowgli/galaxy/{Sun.java => Sun.kt} (100%) rename tests/src/main/java/com/github/klee0kai/test/mowgli/identity/{Conscience.java => Conscience.kt} (100%) rename tests/src/main/java/com/github/klee0kai/test/mowgli/identity/{Ideology.java => Ideology.kt} (100%) rename tests/src/main/java/com/github/klee0kai/test/mowgli/identity/{Knowledge.java => Knowledge.kt} (100%) rename tests/src/main/java/com/github/klee0kai/test/tech/components/{Battery.java => Battery.kt} (100%) rename tests/src/main/java/com/github/klee0kai/test/tech/components/{DataStorage.java => DataStorage.kt} (100%) rename tests/src/main/java/com/github/klee0kai/test/tech/components/{OperationSystem.java => OperationSystem.kt} (100%) rename tests/src/main/java/com/github/klee0kai/test/tech/components/{Ram.java => Ram.kt} (100%) rename tests/src/main/java/com/github/klee0kai/test/tech/phone/{GoodPhone.java => GoodPhone.kt} (100%) rename tests/src/main/java/com/github/klee0kai/test/tech/phone/{OnePhone.java => OnePhone.kt} (100%) rename tests/src/main/java/com/github/klee0kai/test/tech/phone/base/{ATech.java => ATech.kt} (100%) rename tests/src/main/java/com/github/klee0kai/test/tech/phone/base/{ATechLifecycle.java => ATechLifecycle.kt} (100%) rename tests/src/main/java/com/github/klee0kai/test/tech/phone/base/{LifecycleUtils.java => LifecycleUtils.kt} (100%) rename tests/src/main/java/com/github/klee0kai/test/wire/{Wire.java => Wire.kt} (100%) rename tests/src/main/java/com/github/klee0kai/test/wire/types/{Hdmi.java => Hdmi.kt} (100%) rename tests/src/main/java/com/github/klee0kai/test/wire/types/{MiniUsb.java => MiniUsb.kt} (100%) rename tests/src/main/java/com/github/klee0kai/test/wire/types/{Usb.java => Usb.kt} (100%) diff --git a/tests/src/main/java/com/github/klee0kai/test/di/base_forest/ForestComponent.java b/tests/src/main/java/com/github/klee0kai/test/di/base_forest/ForestComponent.kt similarity index 100% rename from tests/src/main/java/com/github/klee0kai/test/di/base_forest/ForestComponent.java rename to tests/src/main/java/com/github/klee0kai/test/di/base_forest/ForestComponent.kt diff --git a/tests/src/main/java/com/github/klee0kai/test/di/base_forest/IdentityModule.java b/tests/src/main/java/com/github/klee0kai/test/di/base_forest/IdentityModule.kt similarity index 100% rename from tests/src/main/java/com/github/klee0kai/test/di/base_forest/IdentityModule.java rename to tests/src/main/java/com/github/klee0kai/test/di/base_forest/IdentityModule.kt diff --git a/tests/src/main/java/com/github/klee0kai/test/di/base_forest/UnitedBlueModule.java b/tests/src/main/java/com/github/klee0kai/test/di/base_forest/UnitedBlueModule.kt similarity index 100% rename from tests/src/main/java/com/github/klee0kai/test/di/base_forest/UnitedBlueModule.java rename to tests/src/main/java/com/github/klee0kai/test/di/base_forest/UnitedBlueModule.kt diff --git a/tests/src/main/java/com/github/klee0kai/test/di/base_forest/UnitedModule.java b/tests/src/main/java/com/github/klee0kai/test/di/base_forest/UnitedModule.kt similarity index 100% rename from tests/src/main/java/com/github/klee0kai/test/di/base_forest/UnitedModule.java rename to tests/src/main/java/com/github/klee0kai/test/di/base_forest/UnitedModule.kt diff --git a/tests/src/main/java/com/github/klee0kai/test/di/base_phone/PhoneComponent.java b/tests/src/main/java/com/github/klee0kai/test/di/base_phone/PhoneComponent.kt similarity index 100% rename from tests/src/main/java/com/github/klee0kai/test/di/base_phone/PhoneComponent.java rename to tests/src/main/java/com/github/klee0kai/test/di/base_phone/PhoneComponent.kt diff --git a/tests/src/main/java/com/github/klee0kai/test/di/base_phone/TechModule.java b/tests/src/main/java/com/github/klee0kai/test/di/base_phone/TechModule.kt similarity index 100% rename from tests/src/main/java/com/github/klee0kai/test/di/base_phone/TechModule.java rename to tests/src/main/java/com/github/klee0kai/test/di/base_phone/TechModule.kt diff --git a/tests/src/main/java/com/github/klee0kai/test/di/base_phone/identifiers/DataStorageSize.java b/tests/src/main/java/com/github/klee0kai/test/di/base_phone/identifiers/DataStorageSize.kt similarity index 100% rename from tests/src/main/java/com/github/klee0kai/test/di/base_phone/identifiers/DataStorageSize.java rename to tests/src/main/java/com/github/klee0kai/test/di/base_phone/identifiers/DataStorageSize.kt diff --git a/tests/src/main/java/com/github/klee0kai/test/di/base_phone/identifiers/PhoneOsType.java b/tests/src/main/java/com/github/klee0kai/test/di/base_phone/identifiers/PhoneOsType.kt similarity index 100% rename from tests/src/main/java/com/github/klee0kai/test/di/base_phone/identifiers/PhoneOsType.java rename to tests/src/main/java/com/github/klee0kai/test/di/base_phone/identifiers/PhoneOsType.kt diff --git a/tests/src/main/java/com/github/klee0kai/test/di/base_phone/identifiers/PhoneOsVersion.java b/tests/src/main/java/com/github/klee0kai/test/di/base_phone/identifiers/PhoneOsVersion.kt similarity index 100% rename from tests/src/main/java/com/github/klee0kai/test/di/base_phone/identifiers/PhoneOsVersion.java rename to tests/src/main/java/com/github/klee0kai/test/di/base_phone/identifiers/PhoneOsVersion.kt diff --git a/tests/src/main/java/com/github/klee0kai/test/di/base_phone/identifiers/RamSize.java b/tests/src/main/java/com/github/klee0kai/test/di/base_phone/identifiers/RamSize.kt similarity index 100% rename from tests/src/main/java/com/github/klee0kai/test/di/base_phone/identifiers/RamSize.java rename to tests/src/main/java/com/github/klee0kai/test/di/base_phone/identifiers/RamSize.kt diff --git a/tests/src/main/java/com/github/klee0kai/test/di/bindinstance/simple/GodWorkspaceComponent.java b/tests/src/main/java/com/github/klee0kai/test/di/bindinstance/simple/GodWorkspaceComponent.kt similarity index 100% rename from tests/src/main/java/com/github/klee0kai/test/di/bindinstance/simple/GodWorkspaceComponent.java rename to tests/src/main/java/com/github/klee0kai/test/di/bindinstance/simple/GodWorkspaceComponent.kt diff --git a/tests/src/main/java/com/github/klee0kai/test/di/bindinstance/simple/SunSystemModule.java b/tests/src/main/java/com/github/klee0kai/test/di/bindinstance/simple/SunSystemModule.kt similarity index 100% rename from tests/src/main/java/com/github/klee0kai/test/di/bindinstance/simple/SunSystemModule.java rename to tests/src/main/java/com/github/klee0kai/test/di/bindinstance/simple/SunSystemModule.kt diff --git a/tests/src/main/java/com/github/klee0kai/test/di/bindinstance/simple_inject/SevenPlanetComponent.java b/tests/src/main/java/com/github/klee0kai/test/di/bindinstance/simple_inject/SevenPlanetComponent.kt similarity index 100% rename from tests/src/main/java/com/github/klee0kai/test/di/bindinstance/simple_inject/SevenPlanetComponent.java rename to tests/src/main/java/com/github/klee0kai/test/di/bindinstance/simple_inject/SevenPlanetComponent.kt diff --git a/tests/src/main/java/com/github/klee0kai/test/di/bindinstance/simple_inject/SevenPlanetModule.java b/tests/src/main/java/com/github/klee0kai/test/di/bindinstance/simple_inject/SevenPlanetModule.kt similarity index 100% rename from tests/src/main/java/com/github/klee0kai/test/di/bindinstance/simple_inject/SevenPlanetModule.java rename to tests/src/main/java/com/github/klee0kai/test/di/bindinstance/simple_inject/SevenPlanetModule.kt diff --git a/tests/src/main/java/com/github/klee0kai/test/di/bindinstance/simple_inject/StarsModule.java b/tests/src/main/java/com/github/klee0kai/test/di/bindinstance/simple_inject/StarsModule.kt similarity index 100% rename from tests/src/main/java/com/github/klee0kai/test/di/bindinstance/simple_inject/StarsModule.java rename to tests/src/main/java/com/github/klee0kai/test/di/bindinstance/simple_inject/StarsModule.kt diff --git a/tests/src/main/java/com/github/klee0kai/test/di/bindinstance/singlemethod/PlanetComponent.java b/tests/src/main/java/com/github/klee0kai/test/di/bindinstance/singlemethod/PlanetComponent.kt similarity index 100% rename from tests/src/main/java/com/github/klee0kai/test/di/bindinstance/singlemethod/PlanetComponent.java rename to tests/src/main/java/com/github/klee0kai/test/di/bindinstance/singlemethod/PlanetComponent.kt diff --git a/tests/src/main/java/com/github/klee0kai/test/di/bindinstance/singlemethod/SunModule.java b/tests/src/main/java/com/github/klee0kai/test/di/bindinstance/singlemethod/SunModule.kt similarity index 100% rename from tests/src/main/java/com/github/klee0kai/test/di/bindinstance/singlemethod/SunModule.java rename to tests/src/main/java/com/github/klee0kai/test/di/bindinstance/singlemethod/SunModule.kt diff --git a/tests/src/main/java/com/github/klee0kai/test/di/bindinstance/singlemethod_gc/PlanetRollingComponent.java b/tests/src/main/java/com/github/klee0kai/test/di/bindinstance/singlemethod_gc/PlanetRollingComponent.kt similarity index 100% rename from tests/src/main/java/com/github/klee0kai/test/di/bindinstance/singlemethod_gc/PlanetRollingComponent.java rename to tests/src/main/java/com/github/klee0kai/test/di/bindinstance/singlemethod_gc/PlanetRollingComponent.kt diff --git a/tests/src/main/java/com/github/klee0kai/test/di/bindinstance/singlemethod_inject/StarSkyComponent.java b/tests/src/main/java/com/github/klee0kai/test/di/bindinstance/singlemethod_inject/StarSkyComponent.kt similarity index 100% rename from tests/src/main/java/com/github/klee0kai/test/di/bindinstance/singlemethod_inject/StarSkyComponent.java rename to tests/src/main/java/com/github/klee0kai/test/di/bindinstance/singlemethod_inject/StarSkyComponent.kt diff --git a/tests/src/main/java/com/github/klee0kai/test/di/bindinstance/singlemethod_inject/StarSkyModule.java b/tests/src/main/java/com/github/klee0kai/test/di/bindinstance/singlemethod_inject/StarSkyModule.kt similarity index 100% rename from tests/src/main/java/com/github/klee0kai/test/di/bindinstance/singlemethod_inject/StarSkyModule.java rename to tests/src/main/java/com/github/klee0kai/test/di/bindinstance/singlemethod_inject/StarSkyModule.kt diff --git a/tests/src/main/java/com/github/klee0kai/test/di/bindinstance/solarsystem/PlanetModule.java b/tests/src/main/java/com/github/klee0kai/test/di/bindinstance/solarsystem/PlanetModule.kt similarity index 100% rename from tests/src/main/java/com/github/klee0kai/test/di/bindinstance/solarsystem/PlanetModule.java rename to tests/src/main/java/com/github/klee0kai/test/di/bindinstance/solarsystem/PlanetModule.kt diff --git a/tests/src/main/java/com/github/klee0kai/test/di/bindinstance/solarsystem/SolarSystemComponent.java b/tests/src/main/java/com/github/klee0kai/test/di/bindinstance/solarsystem/SolarSystemComponent.kt similarity index 100% rename from tests/src/main/java/com/github/klee0kai/test/di/bindinstance/solarsystem/SolarSystemComponent.java rename to tests/src/main/java/com/github/klee0kai/test/di/bindinstance/solarsystem/SolarSystemComponent.kt diff --git a/tests/src/main/java/com/github/klee0kai/test/di/bindinstance/solarsystem/SolarSystemDependencies.java b/tests/src/main/java/com/github/klee0kai/test/di/bindinstance/solarsystem/SolarSystemDependencies.kt similarity index 100% rename from tests/src/main/java/com/github/klee0kai/test/di/bindinstance/solarsystem/SolarSystemDependencies.java rename to tests/src/main/java/com/github/klee0kai/test/di/bindinstance/solarsystem/SolarSystemDependencies.kt diff --git a/tests/src/main/java/com/github/klee0kai/test/di/earthmirror/EarthComponent.java b/tests/src/main/java/com/github/klee0kai/test/di/earthmirror/EarthComponent.kt similarity index 100% rename from tests/src/main/java/com/github/klee0kai/test/di/earthmirror/EarthComponent.java rename to tests/src/main/java/com/github/klee0kai/test/di/earthmirror/EarthComponent.kt diff --git a/tests/src/main/java/com/github/klee0kai/test/di/earthmirror/EastModule.java b/tests/src/main/java/com/github/klee0kai/test/di/earthmirror/EastModule.kt similarity index 100% rename from tests/src/main/java/com/github/klee0kai/test/di/earthmirror/EastModule.java rename to tests/src/main/java/com/github/klee0kai/test/di/earthmirror/EastModule.kt diff --git a/tests/src/main/java/com/github/klee0kai/test/di/earthmirror/WestModule.java b/tests/src/main/java/com/github/klee0kai/test/di/earthmirror/WestModule.kt similarity index 100% rename from tests/src/main/java/com/github/klee0kai/test/di/earthmirror/WestModule.java rename to tests/src/main/java/com/github/klee0kai/test/di/earthmirror/WestModule.kt diff --git a/tests/src/main/java/com/github/klee0kai/test/di/gcforest/GcEarthComponent.java b/tests/src/main/java/com/github/klee0kai/test/di/gcforest/GcEarthComponent.kt similarity index 100% rename from tests/src/main/java/com/github/klee0kai/test/di/gcforest/GcEarthComponent.java rename to tests/src/main/java/com/github/klee0kai/test/di/gcforest/GcEarthComponent.kt diff --git a/tests/src/main/java/com/github/klee0kai/test/di/gcforest/GcEarthModule.java b/tests/src/main/java/com/github/klee0kai/test/di/gcforest/GcEarthModule.kt similarity index 100% rename from tests/src/main/java/com/github/klee0kai/test/di/gcforest/GcEarthModule.java rename to tests/src/main/java/com/github/klee0kai/test/di/gcforest/GcEarthModule.kt diff --git a/tests/src/main/java/com/github/klee0kai/test/di/gcforest/GcGodComponent.java b/tests/src/main/java/com/github/klee0kai/test/di/gcforest/GcGodComponent.kt similarity index 100% rename from tests/src/main/java/com/github/klee0kai/test/di/gcforest/GcGodComponent.java rename to tests/src/main/java/com/github/klee0kai/test/di/gcforest/GcGodComponent.kt diff --git a/tests/src/main/java/com/github/klee0kai/test/di/gcforest/GcSunSystemModule.java b/tests/src/main/java/com/github/klee0kai/test/di/gcforest/GcSunSystemModule.kt similarity index 100% rename from tests/src/main/java/com/github/klee0kai/test/di/gcforest/GcSunSystemModule.java rename to tests/src/main/java/com/github/klee0kai/test/di/gcforest/GcSunSystemModule.kt diff --git a/tests/src/main/java/com/github/klee0kai/test/di/gcforest/scopes/GcMountainScope.java b/tests/src/main/java/com/github/klee0kai/test/di/gcforest/scopes/GcMountainScope.kt similarity index 100% rename from tests/src/main/java/com/github/klee0kai/test/di/gcforest/scopes/GcMountainScope.java rename to tests/src/main/java/com/github/klee0kai/test/di/gcforest/scopes/GcMountainScope.kt diff --git a/tests/src/main/java/com/github/klee0kai/test/di/gcforest/scopes/GcPlanetScope.java b/tests/src/main/java/com/github/klee0kai/test/di/gcforest/scopes/GcPlanetScope.kt similarity index 100% rename from tests/src/main/java/com/github/klee0kai/test/di/gcforest/scopes/GcPlanetScope.java rename to tests/src/main/java/com/github/klee0kai/test/di/gcforest/scopes/GcPlanetScope.kt diff --git a/tests/src/main/java/com/github/klee0kai/test/di/gcforest/scopes/GcRiverScope.java b/tests/src/main/java/com/github/klee0kai/test/di/gcforest/scopes/GcRiverScope.kt similarity index 100% rename from tests/src/main/java/com/github/klee0kai/test/di/gcforest/scopes/GcRiverScope.java rename to tests/src/main/java/com/github/klee0kai/test/di/gcforest/scopes/GcRiverScope.kt diff --git a/tests/src/main/java/com/github/klee0kai/test/di/gcforest/scopes/GcSunScope.java b/tests/src/main/java/com/github/klee0kai/test/di/gcforest/scopes/GcSunScope.kt similarity index 100% rename from tests/src/main/java/com/github/klee0kai/test/di/gcforest/scopes/GcSunScope.java rename to tests/src/main/java/com/github/klee0kai/test/di/gcforest/scopes/GcSunScope.kt diff --git a/tests/src/main/java/com/github/klee0kai/test/di/house/nulls/HouseNullsComponent.java b/tests/src/main/java/com/github/klee0kai/test/di/house/nulls/HouseNullsComponent.kt similarity index 100% rename from tests/src/main/java/com/github/klee0kai/test/di/house/nulls/HouseNullsComponent.java rename to tests/src/main/java/com/github/klee0kai/test/di/house/nulls/HouseNullsComponent.kt diff --git a/tests/src/main/java/com/github/klee0kai/test/di/house/nulls/HouseNullsModule.java b/tests/src/main/java/com/github/klee0kai/test/di/house/nulls/HouseNullsModule.kt similarity index 100% rename from tests/src/main/java/com/github/klee0kai/test/di/house/nulls/HouseNullsModule.java rename to tests/src/main/java/com/github/klee0kai/test/di/house/nulls/HouseNullsModule.kt diff --git a/tests/src/main/java/com/github/klee0kai/test/di/house/simple/AreasModule.java b/tests/src/main/java/com/github/klee0kai/test/di/house/simple/AreasModule.kt similarity index 100% rename from tests/src/main/java/com/github/klee0kai/test/di/house/simple/AreasModule.java rename to tests/src/main/java/com/github/klee0kai/test/di/house/simple/AreasModule.kt diff --git a/tests/src/main/java/com/github/klee0kai/test/di/house/simple/HouseComponent.java b/tests/src/main/java/com/github/klee0kai/test/di/house/simple/HouseComponent.kt similarity index 100% rename from tests/src/main/java/com/github/klee0kai/test/di/house/simple/HouseComponent.java rename to tests/src/main/java/com/github/klee0kai/test/di/house/simple/HouseComponent.kt diff --git a/tests/src/main/java/com/github/klee0kai/test/di/house/simple/HouseModule.java b/tests/src/main/java/com/github/klee0kai/test/di/house/simple/HouseModule.kt similarity index 100% rename from tests/src/main/java/com/github/klee0kai/test/di/house/simple/HouseModule.java rename to tests/src/main/java/com/github/klee0kai/test/di/house/simple/HouseModule.kt diff --git a/tests/src/main/java/com/github/klee0kai/test/di/house/simple/RoomsModule.java b/tests/src/main/java/com/github/klee0kai/test/di/house/simple/RoomsModule.kt similarity index 100% rename from tests/src/main/java/com/github/klee0kai/test/di/house/simple/RoomsModule.java rename to tests/src/main/java/com/github/klee0kai/test/di/house/simple/RoomsModule.kt diff --git a/tests/src/main/java/com/github/klee0kai/test/di/house/simple/ToolsModule.java b/tests/src/main/java/com/github/klee0kai/test/di/house/simple/ToolsModule.kt similarity index 100% rename from tests/src/main/java/com/github/klee0kai/test/di/house/simple/ToolsModule.java rename to tests/src/main/java/com/github/klee0kai/test/di/house/simple/ToolsModule.kt diff --git a/tests/src/main/java/com/github/klee0kai/test/di/swcache/SwitchCacheComponent.java b/tests/src/main/java/com/github/klee0kai/test/di/swcache/SwitchCacheComponent.kt similarity index 100% rename from tests/src/main/java/com/github/klee0kai/test/di/swcache/SwitchCacheComponent.java rename to tests/src/main/java/com/github/klee0kai/test/di/swcache/SwitchCacheComponent.kt diff --git a/tests/src/main/java/com/github/klee0kai/test/di/techfactory/ITechProviderComponent.java b/tests/src/main/java/com/github/klee0kai/test/di/techfactory/ITechProviderComponent.kt similarity index 100% rename from tests/src/main/java/com/github/klee0kai/test/di/techfactory/ITechProviderComponent.java rename to tests/src/main/java/com/github/klee0kai/test/di/techfactory/ITechProviderComponent.kt diff --git a/tests/src/main/java/com/github/klee0kai/test/di/techfactory/TechFactoryComponent.java b/tests/src/main/java/com/github/klee0kai/test/di/techfactory/TechFactoryComponent.kt similarity index 100% rename from tests/src/main/java/com/github/klee0kai/test/di/techfactory/TechFactoryComponent.java rename to tests/src/main/java/com/github/klee0kai/test/di/techfactory/TechFactoryComponent.kt diff --git a/tests/src/main/java/com/github/klee0kai/test/di/techfactory/TechFactoryModule.java b/tests/src/main/java/com/github/klee0kai/test/di/techfactory/TechFactoryModule.kt similarity index 100% rename from tests/src/main/java/com/github/klee0kai/test/di/techfactory/TechFactoryModule.java rename to tests/src/main/java/com/github/klee0kai/test/di/techfactory/TechFactoryModule.kt diff --git a/tests/src/main/java/com/github/klee0kai/test/di/wire/WireComponent.java b/tests/src/main/java/com/github/klee0kai/test/di/wire/WireComponent.kt similarity index 100% rename from tests/src/main/java/com/github/klee0kai/test/di/wire/WireComponent.java rename to tests/src/main/java/com/github/klee0kai/test/di/wire/WireComponent.kt diff --git a/tests/src/main/java/com/github/klee0kai/test/di/wire/WireModule.java b/tests/src/main/java/com/github/klee0kai/test/di/wire/WireModule.kt similarity index 100% rename from tests/src/main/java/com/github/klee0kai/test/di/wire/WireModule.java rename to tests/src/main/java/com/github/klee0kai/test/di/wire/WireModule.kt diff --git a/tests/src/main/java/com/github/klee0kai/test/house/House.java b/tests/src/main/java/com/github/klee0kai/test/house/House.kt similarity index 100% rename from tests/src/main/java/com/github/klee0kai/test/house/House.java rename to tests/src/main/java/com/github/klee0kai/test/house/House.kt diff --git a/tests/src/main/java/com/github/klee0kai/test/house/InHouse.java b/tests/src/main/java/com/github/klee0kai/test/house/InHouse.kt similarity index 100% rename from tests/src/main/java/com/github/klee0kai/test/house/InHouse.java rename to tests/src/main/java/com/github/klee0kai/test/house/InHouse.kt diff --git a/tests/src/main/java/com/github/klee0kai/test/house/identifiers/StoreAreaType.java b/tests/src/main/java/com/github/klee0kai/test/house/identifiers/StoreAreaType.kt similarity index 100% rename from tests/src/main/java/com/github/klee0kai/test/house/identifiers/StoreAreaType.java rename to tests/src/main/java/com/github/klee0kai/test/house/identifiers/StoreAreaType.kt diff --git a/tests/src/main/java/com/github/klee0kai/test/house/kitchen/Kichen.java b/tests/src/main/java/com/github/klee0kai/test/house/kitchen/Kichen.kt similarity index 100% rename from tests/src/main/java/com/github/klee0kai/test/house/kitchen/Kichen.java rename to tests/src/main/java/com/github/klee0kai/test/house/kitchen/Kichen.kt diff --git a/tests/src/main/java/com/github/klee0kai/test/house/kitchen/cookingarea/CookingArea.java b/tests/src/main/java/com/github/klee0kai/test/house/kitchen/cookingarea/CookingArea.kt similarity index 100% rename from tests/src/main/java/com/github/klee0kai/test/house/kitchen/cookingarea/CookingArea.java rename to tests/src/main/java/com/github/klee0kai/test/house/kitchen/cookingarea/CookingArea.kt diff --git a/tests/src/main/java/com/github/klee0kai/test/house/kitchen/sinkarea/SinkArea.java b/tests/src/main/java/com/github/klee0kai/test/house/kitchen/sinkarea/SinkArea.kt similarity index 100% rename from tests/src/main/java/com/github/klee0kai/test/house/kitchen/sinkarea/SinkArea.java rename to tests/src/main/java/com/github/klee0kai/test/house/kitchen/sinkarea/SinkArea.kt diff --git a/tests/src/main/java/com/github/klee0kai/test/house/kitchen/storagearea/Clothes.java b/tests/src/main/java/com/github/klee0kai/test/house/kitchen/storagearea/Clothes.kt similarity index 100% rename from tests/src/main/java/com/github/klee0kai/test/house/kitchen/storagearea/Clothes.java rename to tests/src/main/java/com/github/klee0kai/test/house/kitchen/storagearea/Clothes.kt diff --git a/tests/src/main/java/com/github/klee0kai/test/house/kitchen/storagearea/Cookware.java b/tests/src/main/java/com/github/klee0kai/test/house/kitchen/storagearea/Cookware.kt similarity index 100% rename from tests/src/main/java/com/github/klee0kai/test/house/kitchen/storagearea/Cookware.java rename to tests/src/main/java/com/github/klee0kai/test/house/kitchen/storagearea/Cookware.kt diff --git a/tests/src/main/java/com/github/klee0kai/test/house/kitchen/storagearea/GarageStore.java b/tests/src/main/java/com/github/klee0kai/test/house/kitchen/storagearea/GarageStore.kt similarity index 100% rename from tests/src/main/java/com/github/klee0kai/test/house/kitchen/storagearea/GarageStore.java rename to tests/src/main/java/com/github/klee0kai/test/house/kitchen/storagearea/GarageStore.kt diff --git a/tests/src/main/java/com/github/klee0kai/test/house/kitchen/storagearea/Sanitizers.java b/tests/src/main/java/com/github/klee0kai/test/house/kitchen/storagearea/Sanitizers.kt similarity index 100% rename from tests/src/main/java/com/github/klee0kai/test/house/kitchen/storagearea/Sanitizers.java rename to tests/src/main/java/com/github/klee0kai/test/house/kitchen/storagearea/Sanitizers.kt diff --git a/tests/src/main/java/com/github/klee0kai/test/house/kitchen/storagearea/StoreArea.java b/tests/src/main/java/com/github/klee0kai/test/house/kitchen/storagearea/StoreArea.kt similarity index 100% rename from tests/src/main/java/com/github/klee0kai/test/house/kitchen/storagearea/StoreArea.java rename to tests/src/main/java/com/github/klee0kai/test/house/kitchen/storagearea/StoreArea.kt diff --git a/tests/src/main/java/com/github/klee0kai/test/house/rooms/BathRoom.java b/tests/src/main/java/com/github/klee0kai/test/house/rooms/BathRoom.kt similarity index 100% rename from tests/src/main/java/com/github/klee0kai/test/house/rooms/BathRoom.java rename to tests/src/main/java/com/github/klee0kai/test/house/rooms/BathRoom.kt diff --git a/tests/src/main/java/com/github/klee0kai/test/house/rooms/BedRoom.java b/tests/src/main/java/com/github/klee0kai/test/house/rooms/BedRoom.kt similarity index 100% rename from tests/src/main/java/com/github/klee0kai/test/house/rooms/BedRoom.java rename to tests/src/main/java/com/github/klee0kai/test/house/rooms/BedRoom.kt diff --git a/tests/src/main/java/com/github/klee0kai/test/house/rooms/Garage.java b/tests/src/main/java/com/github/klee0kai/test/house/rooms/Garage.kt similarity index 100% rename from tests/src/main/java/com/github/klee0kai/test/house/rooms/Garage.java rename to tests/src/main/java/com/github/klee0kai/test/house/rooms/Garage.kt diff --git a/tests/src/main/java/com/github/klee0kai/test/mowgli/MoonSky.java b/tests/src/main/java/com/github/klee0kai/test/mowgli/MoonSky.kt similarity index 100% rename from tests/src/main/java/com/github/klee0kai/test/mowgli/MoonSky.java rename to tests/src/main/java/com/github/klee0kai/test/mowgli/MoonSky.kt diff --git a/tests/src/main/java/com/github/klee0kai/test/mowgli/School.java b/tests/src/main/java/com/github/klee0kai/test/mowgli/School.kt similarity index 100% rename from tests/src/main/java/com/github/klee0kai/test/mowgli/School.java rename to tests/src/main/java/com/github/klee0kai/test/mowgli/School.kt diff --git a/tests/src/main/java/com/github/klee0kai/test/mowgli/animal/Horse.java b/tests/src/main/java/com/github/klee0kai/test/mowgli/animal/Horse.kt similarity index 100% rename from tests/src/main/java/com/github/klee0kai/test/mowgli/animal/Horse.java rename to tests/src/main/java/com/github/klee0kai/test/mowgli/animal/Horse.kt diff --git a/tests/src/main/java/com/github/klee0kai/test/mowgli/animal/IAnimal.java b/tests/src/main/java/com/github/klee0kai/test/mowgli/animal/IAnimal.kt similarity index 100% rename from tests/src/main/java/com/github/klee0kai/test/mowgli/animal/IAnimal.java rename to tests/src/main/java/com/github/klee0kai/test/mowgli/animal/IAnimal.kt diff --git a/tests/src/main/java/com/github/klee0kai/test/mowgli/animal/Mowgli.java b/tests/src/main/java/com/github/klee0kai/test/mowgli/animal/Mowgli.kt similarity index 100% rename from tests/src/main/java/com/github/klee0kai/test/mowgli/animal/Mowgli.java rename to tests/src/main/java/com/github/klee0kai/test/mowgli/animal/Mowgli.kt diff --git a/tests/src/main/java/com/github/klee0kai/test/mowgli/animal/Snake.java b/tests/src/main/java/com/github/klee0kai/test/mowgli/animal/Snake.kt similarity index 100% rename from tests/src/main/java/com/github/klee0kai/test/mowgli/animal/Snake.java rename to tests/src/main/java/com/github/klee0kai/test/mowgli/animal/Snake.kt diff --git a/tests/src/main/java/com/github/klee0kai/test/mowgli/body/Blood.java b/tests/src/main/java/com/github/klee0kai/test/mowgli/body/Blood.kt similarity index 100% rename from tests/src/main/java/com/github/klee0kai/test/mowgli/body/Blood.java rename to tests/src/main/java/com/github/klee0kai/test/mowgli/body/Blood.kt diff --git a/tests/src/main/java/com/github/klee0kai/test/mowgli/community/History.java b/tests/src/main/java/com/github/klee0kai/test/mowgli/community/History.kt similarity index 100% rename from tests/src/main/java/com/github/klee0kai/test/mowgli/community/History.java rename to tests/src/main/java/com/github/klee0kai/test/mowgli/community/History.kt diff --git a/tests/src/main/java/com/github/klee0kai/test/mowgli/earth/Cave.java b/tests/src/main/java/com/github/klee0kai/test/mowgli/earth/Cave.kt similarity index 100% rename from tests/src/main/java/com/github/klee0kai/test/mowgli/earth/Cave.java rename to tests/src/main/java/com/github/klee0kai/test/mowgli/earth/Cave.kt diff --git a/tests/src/main/java/com/github/klee0kai/test/mowgli/earth/IMountain.java b/tests/src/main/java/com/github/klee0kai/test/mowgli/earth/IMountain.kt similarity index 100% rename from tests/src/main/java/com/github/klee0kai/test/mowgli/earth/IMountain.java rename to tests/src/main/java/com/github/klee0kai/test/mowgli/earth/IMountain.kt diff --git a/tests/src/main/java/com/github/klee0kai/test/mowgli/earth/IRiver.java b/tests/src/main/java/com/github/klee0kai/test/mowgli/earth/IRiver.kt similarity index 100% rename from tests/src/main/java/com/github/klee0kai/test/mowgli/earth/IRiver.java rename to tests/src/main/java/com/github/klee0kai/test/mowgli/earth/IRiver.kt diff --git a/tests/src/main/java/com/github/klee0kai/test/mowgli/earth/Mountain.java b/tests/src/main/java/com/github/klee0kai/test/mowgli/earth/Mountain.kt similarity index 100% rename from tests/src/main/java/com/github/klee0kai/test/mowgli/earth/Mountain.java rename to tests/src/main/java/com/github/klee0kai/test/mowgli/earth/Mountain.kt diff --git a/tests/src/main/java/com/github/klee0kai/test/mowgli/earth/River.java b/tests/src/main/java/com/github/klee0kai/test/mowgli/earth/River.kt similarity index 100% rename from tests/src/main/java/com/github/klee0kai/test/mowgli/earth/River.java rename to tests/src/main/java/com/github/klee0kai/test/mowgli/earth/River.kt diff --git a/tests/src/main/java/com/github/klee0kai/test/mowgli/galaxy/Earth.java b/tests/src/main/java/com/github/klee0kai/test/mowgli/galaxy/Earth.kt similarity index 100% rename from tests/src/main/java/com/github/klee0kai/test/mowgli/galaxy/Earth.java rename to tests/src/main/java/com/github/klee0kai/test/mowgli/galaxy/Earth.kt diff --git a/tests/src/main/java/com/github/klee0kai/test/mowgli/galaxy/IPlanet.java b/tests/src/main/java/com/github/klee0kai/test/mowgli/galaxy/IPlanet.kt similarity index 100% rename from tests/src/main/java/com/github/klee0kai/test/mowgli/galaxy/IPlanet.java rename to tests/src/main/java/com/github/klee0kai/test/mowgli/galaxy/IPlanet.kt diff --git a/tests/src/main/java/com/github/klee0kai/test/mowgli/galaxy/IStar.java b/tests/src/main/java/com/github/klee0kai/test/mowgli/galaxy/IStar.kt similarity index 100% rename from tests/src/main/java/com/github/klee0kai/test/mowgli/galaxy/IStar.java rename to tests/src/main/java/com/github/klee0kai/test/mowgli/galaxy/IStar.kt diff --git a/tests/src/main/java/com/github/klee0kai/test/mowgli/galaxy/Mercury.java b/tests/src/main/java/com/github/klee0kai/test/mowgli/galaxy/Mercury.kt similarity index 100% rename from tests/src/main/java/com/github/klee0kai/test/mowgli/galaxy/Mercury.java rename to tests/src/main/java/com/github/klee0kai/test/mowgli/galaxy/Mercury.kt diff --git a/tests/src/main/java/com/github/klee0kai/test/mowgli/galaxy/Saturn.java b/tests/src/main/java/com/github/klee0kai/test/mowgli/galaxy/Saturn.kt similarity index 100% rename from tests/src/main/java/com/github/klee0kai/test/mowgli/galaxy/Saturn.java rename to tests/src/main/java/com/github/klee0kai/test/mowgli/galaxy/Saturn.kt diff --git a/tests/src/main/java/com/github/klee0kai/test/mowgli/galaxy/SolarSystem.java b/tests/src/main/java/com/github/klee0kai/test/mowgli/galaxy/SolarSystem.kt similarity index 100% rename from tests/src/main/java/com/github/klee0kai/test/mowgli/galaxy/SolarSystem.java rename to tests/src/main/java/com/github/klee0kai/test/mowgli/galaxy/SolarSystem.kt diff --git a/tests/src/main/java/com/github/klee0kai/test/mowgli/galaxy/Sun.java b/tests/src/main/java/com/github/klee0kai/test/mowgli/galaxy/Sun.kt similarity index 100% rename from tests/src/main/java/com/github/klee0kai/test/mowgli/galaxy/Sun.java rename to tests/src/main/java/com/github/klee0kai/test/mowgli/galaxy/Sun.kt diff --git a/tests/src/main/java/com/github/klee0kai/test/mowgli/identity/Conscience.java b/tests/src/main/java/com/github/klee0kai/test/mowgli/identity/Conscience.kt similarity index 100% rename from tests/src/main/java/com/github/klee0kai/test/mowgli/identity/Conscience.java rename to tests/src/main/java/com/github/klee0kai/test/mowgli/identity/Conscience.kt diff --git a/tests/src/main/java/com/github/klee0kai/test/mowgli/identity/Ideology.java b/tests/src/main/java/com/github/klee0kai/test/mowgli/identity/Ideology.kt similarity index 100% rename from tests/src/main/java/com/github/klee0kai/test/mowgli/identity/Ideology.java rename to tests/src/main/java/com/github/klee0kai/test/mowgli/identity/Ideology.kt diff --git a/tests/src/main/java/com/github/klee0kai/test/mowgli/identity/Knowledge.java b/tests/src/main/java/com/github/klee0kai/test/mowgli/identity/Knowledge.kt similarity index 100% rename from tests/src/main/java/com/github/klee0kai/test/mowgli/identity/Knowledge.java rename to tests/src/main/java/com/github/klee0kai/test/mowgli/identity/Knowledge.kt diff --git a/tests/src/main/java/com/github/klee0kai/test/tech/components/Battery.java b/tests/src/main/java/com/github/klee0kai/test/tech/components/Battery.kt similarity index 100% rename from tests/src/main/java/com/github/klee0kai/test/tech/components/Battery.java rename to tests/src/main/java/com/github/klee0kai/test/tech/components/Battery.kt diff --git a/tests/src/main/java/com/github/klee0kai/test/tech/components/DataStorage.java b/tests/src/main/java/com/github/klee0kai/test/tech/components/DataStorage.kt similarity index 100% rename from tests/src/main/java/com/github/klee0kai/test/tech/components/DataStorage.java rename to tests/src/main/java/com/github/klee0kai/test/tech/components/DataStorage.kt diff --git a/tests/src/main/java/com/github/klee0kai/test/tech/components/OperationSystem.java b/tests/src/main/java/com/github/klee0kai/test/tech/components/OperationSystem.kt similarity index 100% rename from tests/src/main/java/com/github/klee0kai/test/tech/components/OperationSystem.java rename to tests/src/main/java/com/github/klee0kai/test/tech/components/OperationSystem.kt diff --git a/tests/src/main/java/com/github/klee0kai/test/tech/components/Ram.java b/tests/src/main/java/com/github/klee0kai/test/tech/components/Ram.kt similarity index 100% rename from tests/src/main/java/com/github/klee0kai/test/tech/components/Ram.java rename to tests/src/main/java/com/github/klee0kai/test/tech/components/Ram.kt diff --git a/tests/src/main/java/com/github/klee0kai/test/tech/phone/GoodPhone.java b/tests/src/main/java/com/github/klee0kai/test/tech/phone/GoodPhone.kt similarity index 100% rename from tests/src/main/java/com/github/klee0kai/test/tech/phone/GoodPhone.java rename to tests/src/main/java/com/github/klee0kai/test/tech/phone/GoodPhone.kt diff --git a/tests/src/main/java/com/github/klee0kai/test/tech/phone/OnePhone.java b/tests/src/main/java/com/github/klee0kai/test/tech/phone/OnePhone.kt similarity index 100% rename from tests/src/main/java/com/github/klee0kai/test/tech/phone/OnePhone.java rename to tests/src/main/java/com/github/klee0kai/test/tech/phone/OnePhone.kt diff --git a/tests/src/main/java/com/github/klee0kai/test/tech/phone/base/ATech.java b/tests/src/main/java/com/github/klee0kai/test/tech/phone/base/ATech.kt similarity index 100% rename from tests/src/main/java/com/github/klee0kai/test/tech/phone/base/ATech.java rename to tests/src/main/java/com/github/klee0kai/test/tech/phone/base/ATech.kt diff --git a/tests/src/main/java/com/github/klee0kai/test/tech/phone/base/ATechLifecycle.java b/tests/src/main/java/com/github/klee0kai/test/tech/phone/base/ATechLifecycle.kt similarity index 100% rename from tests/src/main/java/com/github/klee0kai/test/tech/phone/base/ATechLifecycle.java rename to tests/src/main/java/com/github/klee0kai/test/tech/phone/base/ATechLifecycle.kt diff --git a/tests/src/main/java/com/github/klee0kai/test/tech/phone/base/LifecycleUtils.java b/tests/src/main/java/com/github/klee0kai/test/tech/phone/base/LifecycleUtils.kt similarity index 100% rename from tests/src/main/java/com/github/klee0kai/test/tech/phone/base/LifecycleUtils.java rename to tests/src/main/java/com/github/klee0kai/test/tech/phone/base/LifecycleUtils.kt diff --git a/tests/src/main/java/com/github/klee0kai/test/wire/Wire.java b/tests/src/main/java/com/github/klee0kai/test/wire/Wire.kt similarity index 100% rename from tests/src/main/java/com/github/klee0kai/test/wire/Wire.java rename to tests/src/main/java/com/github/klee0kai/test/wire/Wire.kt diff --git a/tests/src/main/java/com/github/klee0kai/test/wire/types/Hdmi.java b/tests/src/main/java/com/github/klee0kai/test/wire/types/Hdmi.kt similarity index 100% rename from tests/src/main/java/com/github/klee0kai/test/wire/types/Hdmi.java rename to tests/src/main/java/com/github/klee0kai/test/wire/types/Hdmi.kt diff --git a/tests/src/main/java/com/github/klee0kai/test/wire/types/MiniUsb.java b/tests/src/main/java/com/github/klee0kai/test/wire/types/MiniUsb.kt similarity index 100% rename from tests/src/main/java/com/github/klee0kai/test/wire/types/MiniUsb.java rename to tests/src/main/java/com/github/klee0kai/test/wire/types/MiniUsb.kt diff --git a/tests/src/main/java/com/github/klee0kai/test/wire/types/Usb.java b/tests/src/main/java/com/github/klee0kai/test/wire/types/Usb.kt similarity index 100% rename from tests/src/main/java/com/github/klee0kai/test/wire/types/Usb.java rename to tests/src/main/java/com/github/klee0kai/test/wire/types/Usb.kt From 2274d05f6315e14c5d52cc3e399a0e1d24b515e0 Mon Sep 17 00:00:00 2001 From: klee0kai Date: Mon, 8 Dec 2025 21:21:45 +0100 Subject: [PATCH 049/122] migrate tests gradle module to kotlin --- .../klee0kai/thekey/stone/ksp/Processor.kt | 2 +- .../stone/ksp/exceptions/StoneException.kt | 4 +- .../thekey/stone/ksp/exceptions/WrapExt.kt | 17 +++ .../ksp/helpers/ComponentDeclarationExt.kt | 13 ++- .../stone/ksp/ksp/KSClassDeclarationExt.kt | 22 +++- .../thekey/stone/ksp/poet/TypeSpecDsl.kt | 5 +- .../target/GenModuleCacheControlProcessor.kt | 7 +- .../target/component/ComponentsMethodsExt.kt | 16 +-- tests/build.gradle.kts | 7 +- .../test/di/base_forest/ForestComponent.kt | 47 ++++---- .../test/di/base_forest/IdentityModule.kt | 22 ++-- .../test/di/base_forest/UnitedBlueModule.kt | 20 ++-- .../test/di/base_forest/UnitedModule.kt | 29 ++--- .../test/di/base_phone/PhoneComponent.kt | 42 +++---- .../klee0kai/test/di/base_phone/TechModule.kt | 46 ++++---- .../base_phone/identifiers/DataStorageSize.kt | 29 ++--- .../di/base_phone/identifiers/PhoneOsType.kt | 4 +- .../base_phone/identifiers/PhoneOsVersion.kt | 28 ++--- .../test/di/base_phone/identifiers/RamSize.kt | 30 ++--- .../simple/GodWorkspaceComponent.kt | 32 +++-- .../di/bindinstance/simple/SunSystemModule.kt | 23 ++-- .../simple_inject/SevenPlanetComponent.kt | 30 +++-- .../simple_inject/SevenPlanetModule.kt | 23 ++-- .../bindinstance/simple_inject/StarsModule.kt | 19 ++- .../singlemethod/PlanetComponent.kt | 26 ++--- .../di/bindinstance/singlemethod/SunModule.kt | 28 ++--- .../singlemethod_gc/PlanetRollingComponent.kt | 45 ++++---- .../singlemethod_inject/StarSkyComponent.kt | 39 +++---- .../singlemethod_inject/StarSkyModule.kt | 21 ++-- .../bindinstance/solarsystem/PlanetModule.kt | 29 +++-- .../solarsystem/SolarSystemComponent.kt | 15 ++- .../solarsystem/SolarSystemDependencies.kt | 19 ++- .../test/di/earthmirror/EarthComponent.kt | 18 ++- .../test/di/earthmirror/EastModule.kt | 17 ++- .../test/di/earthmirror/WestModule.kt | 25 ++-- .../test/di/gcforest/GcEarthComponent.kt | 29 +++-- .../test/di/gcforest/GcEarthModule.kt | 45 ++++---- .../test/di/gcforest/GcGodComponent.kt | 48 ++++---- .../test/di/gcforest/GcSunSystemModule.kt | 31 +++-- .../di/gcforest/scopes/GcMountainScope.kt | 15 +-- .../test/di/gcforest/scopes/GcPlanetScope.kt | 17 +-- .../test/di/gcforest/scopes/GcRiverScope.kt | 16 +-- .../test/di/gcforest/scopes/GcSunScope.kt | 16 +-- .../di/house/nulls/HouseNullsComponent.kt | 14 +-- .../test/di/house/nulls/HouseNullsModule.kt | 20 ++-- .../test/di/house/simple/AreasModule.kt | 31 ++--- .../test/di/house/simple/HouseComponent.kt | 42 +++---- .../test/di/house/simple/HouseModule.kt | 22 ++-- .../test/di/house/simple/RoomsModule.kt | 34 +++--- .../test/di/house/simple/ToolsModule.kt | 22 ++-- .../test/di/swcache/SwitchCacheComponent.kt | 28 +++-- .../di/techfactory/ITechProviderComponent.kt | 56 +++++---- .../di/techfactory/TechFactoryComponent.kt | 29 +++-- .../test/di/techfactory/TechFactoryModule.kt | 46 ++++---- .../klee0kai/test/di/wire/WireComponent.kt | 31 +++-- .../klee0kai/test/di/wire/WireModule.kt | 31 +++-- .../com/github/klee0kai/test/house/House.kt | 31 ++--- .../com/github/klee0kai/test/house/InHouse.kt | 32 ++--- .../test/house/identifiers/StoreAreaType.kt | 4 +- .../klee0kai/test/house/kitchen/Kichen.kt | 36 +++--- .../house/kitchen/cookingarea/CookingArea.kt | 10 +- .../test/house/kitchen/sinkarea/SinkArea.kt | 10 +- .../test/house/kitchen/storagearea/Clothes.kt | 10 +- .../house/kitchen/storagearea/Cookware.kt | 10 +- .../house/kitchen/storagearea/GarageStore.kt | 16 +-- .../house/kitchen/storagearea/Sanitizers.kt | 19 +-- .../house/kitchen/storagearea/StoreArea.kt | 20 +--- .../klee0kai/test/house/rooms/BathRoom.kt | 19 +-- .../klee0kai/test/house/rooms/BedRoom.kt | 19 +-- .../klee0kai/test/house/rooms/Garage.kt | 19 +-- .../github/klee0kai/test/mowgli/MoonSky.kt | 27 ++--- .../com/github/klee0kai/test/mowgli/School.kt | 38 +++--- .../klee0kai/test/mowgli/animal/Horse.kt | 60 ++++++---- .../klee0kai/test/mowgli/animal/IAnimal.kt | 7 +- .../klee0kai/test/mowgli/animal/Mowgli.kt | 109 ++++++++++-------- .../klee0kai/test/mowgli/animal/Snake.kt | 38 +++--- .../github/klee0kai/test/mowgli/body/Blood.kt | 16 +-- .../klee0kai/test/mowgli/community/History.kt | 11 +- .../github/klee0kai/test/mowgli/earth/Cave.kt | 21 ++-- .../klee0kai/test/mowgli/earth/IMountain.kt | 5 +- .../klee0kai/test/mowgli/earth/IRiver.kt | 5 +- .../klee0kai/test/mowgli/earth/Mountain.kt | 11 +- .../klee0kai/test/mowgli/earth/River.kt | 10 +- .../klee0kai/test/mowgli/galaxy/Earth.kt | 12 +- .../klee0kai/test/mowgli/galaxy/IPlanet.kt | 5 +- .../klee0kai/test/mowgli/galaxy/IStar.kt | 5 +- .../klee0kai/test/mowgli/galaxy/Mercury.kt | 11 +- .../klee0kai/test/mowgli/galaxy/Saturn.kt | 12 +- .../test/mowgli/galaxy/SolarSystem.kt | 13 +-- .../github/klee0kai/test/mowgli/galaxy/Sun.kt | 11 +- .../test/mowgli/identity/Conscience.kt | 17 ++- .../klee0kai/test/mowgli/identity/Ideology.kt | 15 +-- .../test/mowgli/identity/Knowledge.kt | 16 ++- .../klee0kai/test/tech/components/Battery.kt | 11 +- .../test/tech/components/DataStorage.kt | 25 ++-- .../test/tech/components/OperationSystem.kt | 33 +++--- .../klee0kai/test/tech/components/Ram.kt | 24 ++-- .../klee0kai/test/tech/phone/GoodPhone.kt | 58 +++++----- .../klee0kai/test/tech/phone/OnePhone.kt | 78 ++++++------- .../klee0kai/test/tech/phone/base/ATech.kt | 30 ++--- .../test/tech/phone/base/ATechLifecycle.kt | 12 +- .../test/tech/phone/base/LifecycleUtils.kt | 33 +++--- .../com/github/klee0kai/test/wire/Wire.kt | 13 +-- .../github/klee0kai/test/wire/types/Hdmi.kt | 10 +- .../klee0kai/test/wire/types/MiniUsb.kt | 10 +- .../github/klee0kai/test/wire/types/Usb.kt | 10 +- 106 files changed, 1132 insertions(+), 1367 deletions(-) create mode 100644 stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/exceptions/WrapExt.kt diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/Processor.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/Processor.kt index fb3bf72e..9677d1f6 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/Processor.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/Processor.kt @@ -131,7 +131,7 @@ class Processor( } ) } catch (e: StoneException) { - logger.error(e.toString(), e.findErrorElement()) + logger.error(e.toString(), e.findLastErrorElement()) } } diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/exceptions/StoneException.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/exceptions/StoneException.kt index d804a74f..67249a60 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/exceptions/StoneException.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/exceptions/StoneException.kt @@ -9,10 +9,10 @@ open class StoneException( val element: KSNode? = null, ) : IllegalStateException(message, cause) { - fun findErrorElement(): KSNode? { + fun findLastErrorElement(): KSNode? { var sourceElement: KSNode? = null if (cause is StoneException) { - sourceElement = (cause as StoneException).findErrorElement() + sourceElement = (cause as StoneException).findLastErrorElement() } if (sourceElement == null) sourceElement = element return sourceElement diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/exceptions/WrapExt.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/exceptions/WrapExt.kt new file mode 100644 index 00000000..0b282d55 --- /dev/null +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/exceptions/WrapExt.kt @@ -0,0 +1,17 @@ +package com.github.klee0kai.thekey.stone.ksp.exceptions + +import com.google.devtools.ksp.symbol.KSNode + +fun T.wrapKsNoteInfo( + ksNode: KSNode, + block: T.() -> R, +): R { + return try { + block() + } catch (e: Throwable) { + throw StoneException( + message = e.message, + element = ksNode, + ) + } +} \ No newline at end of file diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/ComponentDeclarationExt.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/ComponentDeclarationExt.kt index 6b7f16d6..be298df0 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/ComponentDeclarationExt.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/ComponentDeclarationExt.kt @@ -6,9 +6,12 @@ import com.github.klee0kai.stone.annotations.component.* import com.github.klee0kai.stone.lifecycle.StoneLifeCycleOwner import com.github.klee0kai.stone.weakref.Named import com.github.klee0kai.stone.weakref.Qualifier +import com.github.klee0kai.stone.weakref.Scope import com.github.klee0kai.thekey.stone.ksp.helpers.annotations.findComponentAnnotation +import com.github.klee0kai.thekey.stone.ksp.ksp.isAnyType import com.github.klee0kai.thekey.stone.ksp.ksp.isChildOf import com.github.klee0kai.thekey.stone.ksp.ksp.isType +import com.github.klee0kai.thekey.stone.ksp.ksp.resolveAlias import com.google.devtools.ksp.KspExperimental import com.google.devtools.ksp.processing.Resolver import com.google.devtools.ksp.symbol.* @@ -69,9 +72,13 @@ val KSAnnotated.scopeAnnotations: Sequence ) return annotations.filter { funAnnotation -> - standardScopeAnnotations.any { funAnnotation.annotationType.resolve().declaration.isType(it) } - || funAnnotation.annotationType.resolve().annotations.any { annotationOfAnnotation -> - annotationOfAnnotation.annotationType.resolve().declaration.isType(GcScopeAnnotation::class) + standardScopeAnnotations.any { funAnnotation.annotationType.resolveAlias().declaration.isType(it) } + || funAnnotation.annotationType.resolveAlias().declaration.annotations.any { annotationOfAnnotation -> + annotationOfAnnotation.annotationType.resolveAlias().declaration.isAnyType( + GcScopeAnnotation::class, + Scope::class, + javax.inject.Scope::class + ) } } } diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/ksp/KSClassDeclarationExt.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/ksp/KSClassDeclarationExt.kt index 37ef8471..2973eae4 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/ksp/KSClassDeclarationExt.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/ksp/KSClassDeclarationExt.kt @@ -3,15 +3,25 @@ package com.github.klee0kai.thekey.stone.ksp.ksp import com.github.klee0kai.thekey.stone.ksp.utils.removeDoubles import com.google.devtools.ksp.getAllSuperTypes import com.google.devtools.ksp.getDeclaredFunctions -import com.google.devtools.ksp.symbol.KSClassDeclaration -import com.google.devtools.ksp.symbol.KSDeclaration -import com.google.devtools.ksp.symbol.KSFunctionDeclaration -import com.google.devtools.ksp.symbol.KSType +import com.google.devtools.ksp.symbol.* import com.squareup.kotlinpoet.ClassName import com.squareup.kotlinpoet.ksp.toClassName -import com.squareup.kotlinpoet.ksp.toTypeName +import com.squareup.kotlinpoet.ksp.toClassNameOrNull import kotlin.reflect.KClass + +fun KSTypeReference.resolveAlias(): KSType = resolve().unwrapAlias() + +fun KSType.unwrapAlias(): KSType { + var current: KSType = this + while (current.declaration is KSTypeAlias) { + val alias = current.declaration as KSTypeAlias + current = alias.type.resolve() + } + return current +} + + fun KSClassDeclaration.findConstructor( parameters: List, ): KSFunctionDeclaration? = getDeclaredFunctions().firstOrNull { function -> @@ -71,7 +81,7 @@ fun KSClassDeclaration.isChildOf( ): Boolean { if (toClassName() == parentType) return true superTypes.forEach { type -> - if (type.resolve().toTypeName() == type) return true + if (type.resolve().toClassNameOrNull() == type) return true if ((type.resolve().declaration as? KSClassDeclaration)?.isChildOf(parentType) == true) return true } return false diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/poet/TypeSpecDsl.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/poet/TypeSpecDsl.kt index 7b37e8ca..aec3c014 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/poet/TypeSpecDsl.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/poet/TypeSpecDsl.kt @@ -1,10 +1,10 @@ package com.github.klee0kai.thekey.stone.ksp.poet +import com.github.klee0kai.thekey.stone.ksp.exceptions.wrapKsNoteInfo import com.github.klee0kai.thekey.stone.ksp.target.declareSameParameters import com.github.klee0kai.thekey.stone.ksp.target.isSuspend import com.google.devtools.ksp.symbol.KSFunctionDeclaration import com.squareup.kotlinpoet.* -import com.squareup.kotlinpoet.ksp.toClassName import com.squareup.kotlinpoet.ksp.toTypeName @PoetDsl @@ -80,8 +80,7 @@ fun TypeSpec.Builder.genOverrideFun( if (func.isSuspend) addModifiers(KModifier.SUSPEND) declareSameParameters(func) func.returnType?.resolve()?.toTypeName()?.let { returns(it) } - - block() + wrapKsNoteInfo(func) { block() } } } diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/GenModuleCacheControlProcessor.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/GenModuleCacheControlProcessor.kt index aff7bff5..f4fc868b 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/GenModuleCacheControlProcessor.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/GenModuleCacheControlProcessor.kt @@ -95,12 +95,7 @@ class GenModuleCacheControlProcessor : TargetFileProcessor { } genFun(function.cacheControlMethodName) { modifiers.add(KModifier.ABSTRACT) - returns( - returnType = function.returnType!! - .resolve() - .toClassName() - .copy(nullable = true) - ) + returns(returnType = function.returnType!!.resolve().toTypeName().copy(nullable = true)) addParameter("__action", CacheAction::class) idArguments.forEach { addParameter(it.name!!.asString(), it.type.resolve().toTypeName()) diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/component/ComponentsMethodsExt.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/component/ComponentsMethodsExt.kt index 28305fe1..35e7158d 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/component/ComponentsMethodsExt.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/component/ComponentsMethodsExt.kt @@ -107,12 +107,6 @@ val KSFunctionDeclaration.isModuleInitMethod: Boolean element = this, ) } - if (parameters.size != 1) { - throw IncorrectSignatureException( - message = "${simpleName.asString()} must have only one parameter of Dependency or Module instance", - element = this, - ) - } if (returnType?.resolve()?.isUnit == false) { throw IncorrectSignatureException( message = "${simpleName.asString()} must return unit", @@ -124,10 +118,12 @@ val KSFunctionDeclaration.isModuleInitMethod: Boolean val clDeclaration = it.type .resolve() .declaration as? KSClassDeclaration - ?: throw IncorrectSignatureException( - message = "${simpleName.asString()} must have only one parameter of Dependency or Module instance", - element = this, - ) + ?: + throw IncorrectSignatureException( + message = "${simpleName.asString()} must have only one parameter of Dependency or Module instance", + element = this, + ) + if (!clDeclaration.anyAnnotation(Module::class.asClassName(), Dependencies::class.asClassName()).any()) { throw IncorrectSignatureException( diff --git a/tests/build.gradle.kts b/tests/build.gradle.kts index 10cbe8a0..06a16db4 100644 --- a/tests/build.gradle.kts +++ b/tests/build.gradle.kts @@ -1,5 +1,6 @@ plugins { - java + alias(libs.plugins.kotlin.jvm) + alias(libs.plugins.kotlin.ksp) } tasks.test { @@ -7,8 +8,8 @@ tasks.test { } dependencies { - implementation(project(":stone_lib")) - annotationProcessor(project(":stone_processor")) + implementation(project(":stone_multiplatform")) + ksp(project(":stone_ksp")) testImplementation(libs.bundles.junit) } diff --git a/tests/src/main/java/com/github/klee0kai/test/di/base_forest/ForestComponent.kt b/tests/src/main/java/com/github/klee0kai/test/di/base_forest/ForestComponent.kt index a61afb3a..7cf1cc83 100644 --- a/tests/src/main/java/com/github/klee0kai/test/di/base_forest/ForestComponent.kt +++ b/tests/src/main/java/com/github/klee0kai/test/di/base_forest/ForestComponent.kt @@ -1,51 +1,46 @@ -package com.github.klee0kai.test.di.base_forest; +package com.github.klee0kai.test.di.base_forest -import com.github.klee0kai.stone.annotations.component.*; -import com.github.klee0kai.stone.lifecycle.StoneLifeCycleOwner; -import com.github.klee0kai.test.mowgli.School; -import com.github.klee0kai.test.mowgli.animal.Horse; -import com.github.klee0kai.test.mowgli.animal.Mowgli; -import com.github.klee0kai.test.mowgli.animal.Snake; +import com.github.klee0kai.stone.annotations.component.* +import com.github.klee0kai.stone.lifecycle.StoneLifeCycleOwner +import com.github.klee0kai.test.mowgli.School +import com.github.klee0kai.test.mowgli.animal.Horse +import com.github.klee0kai.test.mowgli.animal.Mowgli +import com.github.klee0kai.test.mowgli.animal.Snake @Component -public interface ForestComponent { +interface ForestComponent { + fun united(): UnitedModule? - UnitedModule united(); + fun identity(): IdentityModule? - IdentityModule identity(); + fun inject(horse: Horse?, stoneLifeCycleOwner: StoneLifeCycleOwner?) - void inject(Horse horse, StoneLifeCycleOwner stoneLifeCycleOwner); + fun inject(horse: Horse?) - void inject(Horse horse); + fun inject(mowgli: Mowgli?) - void inject(Mowgli mowgli); + fun inject(snake: Snake?) - void inject(Snake snake); - - void inject(School school); - - @Init - void initUnitedModule(UnitedModule unitedModule); + fun inject(school: School?) @Init - void initUnitedModule(Class unitedModule); + fun initUnitedModule(unitedModule: UnitedModule?) @Init - void iniAllModules(UnitedModule unitedModule, IdentityModule identityModule); + fun iniAllModules(unitedModule: UnitedModule?, identityModule: IdentityModule?) @RunGc @GcAllScope - void gcAll(); + fun gcAll() @ProtectInjected(timeMillis = 30) - void protectInjected(Horse horse); + fun protectInjected(horse: Horse?) @ProtectInjected(timeMillis = 30) - void protectInjected(Mowgli horse); + fun protectInjected(horse: Mowgli?) @ProtectInjected(timeMillis = 30) - void protectInjected(School school); - + fun protectInjected(school: School?) } diff --git a/tests/src/main/java/com/github/klee0kai/test/di/base_forest/IdentityModule.kt b/tests/src/main/java/com/github/klee0kai/test/di/base_forest/IdentityModule.kt index 867ff812..e3c8b4e9 100644 --- a/tests/src/main/java/com/github/klee0kai/test/di/base_forest/IdentityModule.kt +++ b/tests/src/main/java/com/github/klee0kai/test/di/base_forest/IdentityModule.kt @@ -1,22 +1,20 @@ -package com.github.klee0kai.test.di.base_forest; +package com.github.klee0kai.test.di.base_forest +import com.github.klee0kai.stone.annotations.module.Module +import com.github.klee0kai.stone.annotations.module.Provide +import com.github.klee0kai.test.mowgli.identity.Conscience +import com.github.klee0kai.test.mowgli.identity.Ideology +import com.github.klee0kai.test.mowgli.identity.Knowledge -import com.github.klee0kai.stone.annotations.module.Module; -import com.github.klee0kai.stone.annotations.module.Provide; -import com.github.klee0kai.test.mowgli.identity.Conscience; -import com.github.klee0kai.test.mowgli.identity.Ideology; -import com.github.klee0kai.test.mowgli.identity.Knowledge; @Module -public interface IdentityModule { - +interface IdentityModule { @Provide(cache = Provide.CacheType.Factory) - Knowledge knowledge(); + fun knowledge(): Knowledge? @Provide(cache = Provide.CacheType.Factory) - Conscience conscience(); + fun conscience(): Conscience? @Provide(cache = Provide.CacheType.Soft) - Ideology ideology(); - + fun ideology(): Ideology? } diff --git a/tests/src/main/java/com/github/klee0kai/test/di/base_forest/UnitedBlueModule.kt b/tests/src/main/java/com/github/klee0kai/test/di/base_forest/UnitedBlueModule.kt index eb8f76e1..0335e267 100644 --- a/tests/src/main/java/com/github/klee0kai/test/di/base_forest/UnitedBlueModule.kt +++ b/tests/src/main/java/com/github/klee0kai/test/di/base_forest/UnitedBlueModule.kt @@ -1,18 +1,14 @@ -package com.github.klee0kai.test.di.base_forest; - -import com.github.klee0kai.stone.annotations.module.Module; -import com.github.klee0kai.stone.annotations.module.Provide; -import com.github.klee0kai.test.mowgli.body.Blood; - -import java.awt.*; +package com.github.klee0kai.test.di.base_forest +import com.github.klee0kai.stone.annotations.module.Module +import com.github.klee0kai.stone.annotations.module.Provide +import com.github.klee0kai.test.mowgli.body.Blood +import java.awt.Color @Module -public abstract class UnitedBlueModule extends UnitedModule { - +abstract class UnitedBlueModule : UnitedModule() { @Provide(cache = Provide.CacheType.Strong) - public Blood blood() { - return new Blood(Color.BLUE); + override fun blood(): Blood? { + return Blood(Color.BLUE) } - } diff --git a/tests/src/main/java/com/github/klee0kai/test/di/base_forest/UnitedModule.kt b/tests/src/main/java/com/github/klee0kai/test/di/base_forest/UnitedModule.kt index dd35cb87..4e459f81 100644 --- a/tests/src/main/java/com/github/klee0kai/test/di/base_forest/UnitedModule.kt +++ b/tests/src/main/java/com/github/klee0kai/test/di/base_forest/UnitedModule.kt @@ -1,27 +1,22 @@ -package com.github.klee0kai.test.di.base_forest; - -import com.github.klee0kai.stone.annotations.module.Module; -import com.github.klee0kai.stone.annotations.module.Provide; -import com.github.klee0kai.test.mowgli.body.Blood; -import com.github.klee0kai.test.mowgli.community.History; -import com.github.klee0kai.test.mowgli.galaxy.Earth; - -import java.awt.*; +package com.github.klee0kai.test.di.base_forest +import com.github.klee0kai.stone.annotations.module.Module +import com.github.klee0kai.stone.annotations.module.Provide +import com.github.klee0kai.test.mowgli.body.Blood +import com.github.klee0kai.test.mowgli.community.History +import com.github.klee0kai.test.mowgli.galaxy.Earth +import java.awt.Color @Module -public abstract class UnitedModule { - +abstract class UnitedModule { @Provide(cache = Provide.CacheType.Strong) - public Blood blood() { - return new Blood(Color.RED); + open fun blood(): Blood? { + return Blood(Color.RED) } @Provide(cache = Provide.CacheType.Soft) - public abstract Earth earth(); + abstract fun earth(): Earth? @Provide(cache = Provide.CacheType.Weak) - public abstract History history(); - - + abstract fun history(): History? } diff --git a/tests/src/main/java/com/github/klee0kai/test/di/base_phone/PhoneComponent.kt b/tests/src/main/java/com/github/klee0kai/test/di/base_phone/PhoneComponent.kt index 29b04a5c..39097466 100644 --- a/tests/src/main/java/com/github/klee0kai/test/di/base_phone/PhoneComponent.kt +++ b/tests/src/main/java/com/github/klee0kai/test/di/base_phone/PhoneComponent.kt @@ -1,29 +1,29 @@ -package com.github.klee0kai.test.di.base_phone; +package com.github.klee0kai.test.di.base_phone -import com.github.klee0kai.stone.annotations.component.Component; -import com.github.klee0kai.stone.lifecycle.StoneLifeCycleOwner; -import com.github.klee0kai.test.di.base_phone.identifiers.DataStorageSize; -import com.github.klee0kai.test.di.base_phone.identifiers.PhoneOsType; -import com.github.klee0kai.test.di.base_phone.identifiers.PhoneOsVersion; -import com.github.klee0kai.test.di.base_phone.identifiers.RamSize; -import com.github.klee0kai.test.tech.phone.GoodPhone; -import com.github.klee0kai.test.tech.phone.OnePhone; +import com.github.klee0kai.stone.annotations.component.Component +import com.github.klee0kai.stone.lifecycle.StoneLifeCycleOwner +import com.github.klee0kai.test.di.base_phone.identifiers.DataStorageSize +import com.github.klee0kai.test.di.base_phone.identifiers.PhoneOsType +import com.github.klee0kai.test.di.base_phone.identifiers.PhoneOsVersion +import com.github.klee0kai.test.di.base_phone.identifiers.RamSize +import com.github.klee0kai.test.tech.phone.GoodPhone +import com.github.klee0kai.test.tech.phone.OnePhone @Component( - identifiers = { - DataStorageSize.class, - RamSize.class, - PhoneOsType.class, - PhoneOsVersion.class - } + identifiers = [DataStorageSize::class, RamSize::class, PhoneOsType::class, PhoneOsVersion::class + ] ) -public interface PhoneComponent { +interface PhoneComponent { + fun components(): TechModule? - TechModule components(); + fun inject(onePhone: OnePhone?) - void inject(OnePhone onePhone); + fun inject(goodPhone: GoodPhone?, dataStorageSize: DataStorageSize?, ramSize: RamSize?) - void inject(GoodPhone goodPhone, DataStorageSize dataStorageSize, RamSize ramSize); - - void inject(GoodPhone goodPhone, StoneLifeCycleOwner lifeCycleOwner, DataStorageSize dataStorageSize, RamSize ramSize); + fun inject( + goodPhone: GoodPhone?, + lifeCycleOwner: StoneLifeCycleOwner?, + dataStorageSize: DataStorageSize?, + ramSize: RamSize? + ) } diff --git a/tests/src/main/java/com/github/klee0kai/test/di/base_phone/TechModule.kt b/tests/src/main/java/com/github/klee0kai/test/di/base_phone/TechModule.kt index 65cd6a55..34cd83aa 100644 --- a/tests/src/main/java/com/github/klee0kai/test/di/base_phone/TechModule.kt +++ b/tests/src/main/java/com/github/klee0kai/test/di/base_phone/TechModule.kt @@ -1,45 +1,41 @@ -package com.github.klee0kai.test.di.base_phone; - -import com.github.klee0kai.stone.annotations.module.Module; -import com.github.klee0kai.stone.annotations.module.Provide; -import com.github.klee0kai.test.di.base_phone.identifiers.DataStorageSize; -import com.github.klee0kai.test.di.base_phone.identifiers.PhoneOsType; -import com.github.klee0kai.test.di.base_phone.identifiers.PhoneOsVersion; -import com.github.klee0kai.test.di.base_phone.identifiers.RamSize; -import com.github.klee0kai.test.tech.components.Battery; -import com.github.klee0kai.test.tech.components.DataStorage; -import com.github.klee0kai.test.tech.components.OperationSystem; -import com.github.klee0kai.test.tech.components.Ram; - -import javax.inject.Named; - +package com.github.klee0kai.test.di.base_phone + +import com.github.klee0kai.stone.annotations.module.Module +import com.github.klee0kai.stone.annotations.module.Provide +import com.github.klee0kai.test.di.base_phone.identifiers.DataStorageSize +import com.github.klee0kai.test.di.base_phone.identifiers.PhoneOsType +import com.github.klee0kai.test.di.base_phone.identifiers.PhoneOsVersion +import com.github.klee0kai.test.di.base_phone.identifiers.RamSize +import com.github.klee0kai.test.tech.components.Battery +import com.github.klee0kai.test.tech.components.DataStorage +import com.github.klee0kai.test.tech.components.OperationSystem +import com.github.klee0kai.test.tech.components.Ram +import javax.inject.Named @Module -public interface TechModule { - +interface TechModule { @Provide(cache = Provide.CacheType.Weak) - Battery battery(); + fun battery(): Battery? @Named("null_args") @Provide(cache = Provide.CacheType.Weak) - DataStorage dataStorage(); + fun dataStorage(): DataStorage? @Provide(cache = Provide.CacheType.Weak) - DataStorage dataStorage(DataStorageSize size); + fun dataStorage(size: DataStorageSize?): DataStorage? @Provide(cache = Provide.CacheType.Weak) - Ram ram(RamSize ramSize); + fun ram(ramSize: RamSize?): Ram? @Named("null_args") @Provide(cache = Provide.CacheType.Weak) - Ram ram(); + fun ram(): Ram? @Named("null_args") @Provide(cache = Provide.CacheType.Weak) - OperationSystem phoneOs(PhoneOsType osType); + fun phoneOs(osType: PhoneOsType?): OperationSystem? @Provide(cache = Provide.CacheType.Weak) - OperationSystem phoneOs(PhoneOsType osType, PhoneOsVersion version); - + fun phoneOs(osType: PhoneOsType?, version: PhoneOsVersion?): OperationSystem? } diff --git a/tests/src/main/java/com/github/klee0kai/test/di/base_phone/identifiers/DataStorageSize.kt b/tests/src/main/java/com/github/klee0kai/test/di/base_phone/identifiers/DataStorageSize.kt index 20523d65..fbb3d298 100644 --- a/tests/src/main/java/com/github/klee0kai/test/di/base_phone/identifiers/DataStorageSize.kt +++ b/tests/src/main/java/com/github/klee0kai/test/di/base_phone/identifiers/DataStorageSize.kt @@ -1,25 +1,16 @@ -package com.github.klee0kai.test.di.base_phone.identifiers; +package com.github.klee0kai.test.di.base_phone.identifiers -import java.util.Objects; +import java.util.* -public class DataStorageSize { - - public String size; - - public DataStorageSize(String size) { - this.size = size; - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - DataStorageSize that = (DataStorageSize) o; - return Objects.equals(size, that.size); +class DataStorageSize(var size: String?) { + override fun equals(o: Any?): Boolean { + if (this === o) return true + if (o == null || javaClass != o.javaClass) return false + val that = o as DataStorageSize + return size == that.size } - @Override - public int hashCode() { - return Objects.hash(size); + override fun hashCode(): Int { + return Objects.hash(size) } } diff --git a/tests/src/main/java/com/github/klee0kai/test/di/base_phone/identifiers/PhoneOsType.kt b/tests/src/main/java/com/github/klee0kai/test/di/base_phone/identifiers/PhoneOsType.kt index cb9fbb95..d3acb5fd 100644 --- a/tests/src/main/java/com/github/klee0kai/test/di/base_phone/identifiers/PhoneOsType.kt +++ b/tests/src/main/java/com/github/klee0kai/test/di/base_phone/identifiers/PhoneOsType.kt @@ -1,6 +1,6 @@ -package com.github.klee0kai.test.di.base_phone.identifiers; +package com.github.klee0kai.test.di.base_phone.identifiers -public enum PhoneOsType { +enum class PhoneOsType { Android, Ios, UbuntuTouch, diff --git a/tests/src/main/java/com/github/klee0kai/test/di/base_phone/identifiers/PhoneOsVersion.kt b/tests/src/main/java/com/github/klee0kai/test/di/base_phone/identifiers/PhoneOsVersion.kt index 86f53638..136a3a64 100644 --- a/tests/src/main/java/com/github/klee0kai/test/di/base_phone/identifiers/PhoneOsVersion.kt +++ b/tests/src/main/java/com/github/klee0kai/test/di/base_phone/identifiers/PhoneOsVersion.kt @@ -1,24 +1,16 @@ -package com.github.klee0kai.test.di.base_phone.identifiers; +package com.github.klee0kai.test.di.base_phone.identifiers -import java.util.Objects; +import java.util.* -public class PhoneOsVersion { - public String version; - - public PhoneOsVersion(String version) { - this.version = version; - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - PhoneOsVersion that = (PhoneOsVersion) o; - return Objects.equals(version, that.version); +class PhoneOsVersion(@JvmField var version: String?) { + override fun equals(o: Any?): Boolean { + if (this === o) return true + if (o == null || javaClass != o.javaClass) return false + val that = o as PhoneOsVersion + return version == that.version } - @Override - public int hashCode() { - return Objects.hash(version); + override fun hashCode(): Int { + return Objects.hash(version) } } diff --git a/tests/src/main/java/com/github/klee0kai/test/di/base_phone/identifiers/RamSize.kt b/tests/src/main/java/com/github/klee0kai/test/di/base_phone/identifiers/RamSize.kt index 3cc35231..04db2791 100644 --- a/tests/src/main/java/com/github/klee0kai/test/di/base_phone/identifiers/RamSize.kt +++ b/tests/src/main/java/com/github/klee0kai/test/di/base_phone/identifiers/RamSize.kt @@ -1,26 +1,16 @@ -package com.github.klee0kai.test.di.base_phone.identifiers; +package com.github.klee0kai.test.di.base_phone.identifiers -import java.util.Objects; +import java.util.* -public class RamSize { - - public String size; - - public RamSize(String size) { - this.size = size; +class RamSize(var size: String?) { + override fun equals(o: Any?): Boolean { + if (this === o) return true + if (o == null || javaClass != o.javaClass) return false + val that = o as RamSize + return size == that.size } - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - RamSize that = (RamSize) o; - return Objects.equals(size, that.size); + override fun hashCode(): Int { + return Objects.hash(size) } - - @Override - public int hashCode() { - return Objects.hash(size); - } - } diff --git a/tests/src/main/java/com/github/klee0kai/test/di/bindinstance/simple/GodWorkspaceComponent.kt b/tests/src/main/java/com/github/klee0kai/test/di/bindinstance/simple/GodWorkspaceComponent.kt index 29c0b8f5..4f21930d 100644 --- a/tests/src/main/java/com/github/klee0kai/test/di/bindinstance/simple/GodWorkspaceComponent.kt +++ b/tests/src/main/java/com/github/klee0kai/test/di/bindinstance/simple/GodWorkspaceComponent.kt @@ -1,33 +1,31 @@ -package com.github.klee0kai.test.di.bindinstance.simple; +package com.github.klee0kai.test.di.bindinstance.simple -import com.github.klee0kai.stone.annotations.component.Component; -import com.github.klee0kai.stone.annotations.module.BindInstance; -import com.github.klee0kai.test.mowgli.galaxy.Earth; -import com.github.klee0kai.test.mowgli.galaxy.IPlanet; -import com.github.klee0kai.test.mowgli.galaxy.Saturn; -import com.github.klee0kai.test.mowgli.galaxy.Sun; +import com.github.klee0kai.stone.annotations.component.Component +import com.github.klee0kai.stone.annotations.module.BindInstance +import com.github.klee0kai.test.mowgli.galaxy.Earth +import com.github.klee0kai.test.mowgli.galaxy.IPlanet +import com.github.klee0kai.test.mowgli.galaxy.Saturn +import com.github.klee0kai.test.mowgli.galaxy.Sun @Component -public interface GodWorkspaceComponent { - - SunSystemModule sunSystem(); +interface GodWorkspaceComponent { + fun sunSystem(): SunSystemModule? @BindInstance - void bindPlanet(IPlanet planet); + fun bindPlanet(planet: IPlanet?) @BindInstance - IPlanet planet(IPlanet planet); + fun planet(planet: IPlanet?): IPlanet? @BindInstance - void bindSun(Sun sun); + fun bindSun(sun: Sun?) @BindInstance - void bindEarth(Earth earth); + fun bindEarth(earth: Earth?) @BindInstance - void bindSaturn(Saturn saturn); - + fun bindSaturn(saturn: Saturn?) - IPlanet providePlanet(); + fun providePlanet(): IPlanet? } diff --git a/tests/src/main/java/com/github/klee0kai/test/di/bindinstance/simple/SunSystemModule.kt b/tests/src/main/java/com/github/klee0kai/test/di/bindinstance/simple/SunSystemModule.kt index 2bc6f54b..704d2821 100644 --- a/tests/src/main/java/com/github/klee0kai/test/di/bindinstance/simple/SunSystemModule.kt +++ b/tests/src/main/java/com/github/klee0kai/test/di/bindinstance/simple/SunSystemModule.kt @@ -1,27 +1,24 @@ -package com.github.klee0kai.test.di.bindinstance.simple; +package com.github.klee0kai.test.di.bindinstance.simple +import com.github.klee0kai.stone.annotations.module.BindInstance +import com.github.klee0kai.stone.annotations.module.Module +import com.github.klee0kai.test.mowgli.galaxy.* -import com.github.klee0kai.stone.annotations.module.BindInstance; -import com.github.klee0kai.stone.annotations.module.Module; -import com.github.klee0kai.test.mowgli.galaxy.*; @Module -public interface SunSystemModule { - +interface SunSystemModule { @BindInstance - Sun sun(); + fun sun(): Sun? @BindInstance - IStar star(); + fun star(): IStar? @BindInstance - IPlanet planet(); + fun planet(): IPlanet? @BindInstance - Earth earth(); + fun earth(): Earth? @BindInstance - Saturn saturn(); - - + fun saturn(): Saturn? } diff --git a/tests/src/main/java/com/github/klee0kai/test/di/bindinstance/simple_inject/SevenPlanetComponent.kt b/tests/src/main/java/com/github/klee0kai/test/di/bindinstance/simple_inject/SevenPlanetComponent.kt index b3a54562..f2424b1d 100644 --- a/tests/src/main/java/com/github/klee0kai/test/di/bindinstance/simple_inject/SevenPlanetComponent.kt +++ b/tests/src/main/java/com/github/klee0kai/test/di/bindinstance/simple_inject/SevenPlanetComponent.kt @@ -1,28 +1,26 @@ -package com.github.klee0kai.test.di.bindinstance.simple_inject; +package com.github.klee0kai.test.di.bindinstance.simple_inject -import com.github.klee0kai.stone.annotations.component.Component; -import com.github.klee0kai.stone.annotations.module.BindInstance; -import com.github.klee0kai.test.mowgli.MoonSky; -import com.github.klee0kai.test.mowgli.galaxy.Earth; -import com.github.klee0kai.test.mowgli.galaxy.IPlanet; -import com.github.klee0kai.test.mowgli.galaxy.Mercury; +import com.github.klee0kai.stone.annotations.component.Component +import com.github.klee0kai.stone.annotations.module.BindInstance +import com.github.klee0kai.test.mowgli.MoonSky +import com.github.klee0kai.test.mowgli.galaxy.Earth +import com.github.klee0kai.test.mowgli.galaxy.IPlanet +import com.github.klee0kai.test.mowgli.galaxy.Mercury @Component -public interface SevenPlanetComponent { +interface SevenPlanetComponent { + fun planets(): SevenPlanetModule? - - SevenPlanetModule planets(); - - StarsModule stars(); + fun stars(): StarsModule? @BindInstance - void bind(Earth earth); + fun bind(earth: Earth?) @BindInstance - void bind(Mercury mercury); + fun bind(mercury: Mercury?) @BindInstance - void bindPlanet(IPlanet planet); + fun bindPlanet(planet: IPlanet?) - void inject(MoonSky moonSky); + fun inject(moonSky: MoonSky?) } diff --git a/tests/src/main/java/com/github/klee0kai/test/di/bindinstance/simple_inject/SevenPlanetModule.kt b/tests/src/main/java/com/github/klee0kai/test/di/bindinstance/simple_inject/SevenPlanetModule.kt index 6852b640..d18c690a 100644 --- a/tests/src/main/java/com/github/klee0kai/test/di/bindinstance/simple_inject/SevenPlanetModule.kt +++ b/tests/src/main/java/com/github/klee0kai/test/di/bindinstance/simple_inject/SevenPlanetModule.kt @@ -1,22 +1,19 @@ -package com.github.klee0kai.test.di.bindinstance.simple_inject; +package com.github.klee0kai.test.di.bindinstance.simple_inject -import com.github.klee0kai.stone.annotations.module.BindInstance; -import com.github.klee0kai.stone.annotations.module.Module; -import com.github.klee0kai.test.mowgli.galaxy.Earth; -import com.github.klee0kai.test.mowgli.galaxy.IPlanet; -import com.github.klee0kai.test.mowgli.galaxy.Mercury; +import com.github.klee0kai.stone.annotations.module.BindInstance +import com.github.klee0kai.stone.annotations.module.Module +import com.github.klee0kai.test.mowgli.galaxy.Earth +import com.github.klee0kai.test.mowgli.galaxy.IPlanet +import com.github.klee0kai.test.mowgli.galaxy.Mercury @Module -public interface SevenPlanetModule { - - +interface SevenPlanetModule { @BindInstance - Earth earth(); + fun earth(): Earth? @BindInstance - Mercury mercury(); + fun mercury(): Mercury? @BindInstance - IPlanet planet(); - + fun planet(): IPlanet? } diff --git a/tests/src/main/java/com/github/klee0kai/test/di/bindinstance/simple_inject/StarsModule.kt b/tests/src/main/java/com/github/klee0kai/test/di/bindinstance/simple_inject/StarsModule.kt index 853357f9..2c0f7bdd 100644 --- a/tests/src/main/java/com/github/klee0kai/test/di/bindinstance/simple_inject/StarsModule.kt +++ b/tests/src/main/java/com/github/klee0kai/test/di/bindinstance/simple_inject/StarsModule.kt @@ -1,18 +1,15 @@ -package com.github.klee0kai.test.di.bindinstance.simple_inject; +package com.github.klee0kai.test.di.bindinstance.simple_inject -import com.github.klee0kai.stone.annotations.module.BindInstance; -import com.github.klee0kai.stone.annotations.module.Module; -import com.github.klee0kai.test.mowgli.galaxy.IStar; -import com.github.klee0kai.test.mowgli.galaxy.Sun; +import com.github.klee0kai.stone.annotations.module.BindInstance +import com.github.klee0kai.stone.annotations.module.Module +import com.github.klee0kai.test.mowgli.galaxy.IStar +import com.github.klee0kai.test.mowgli.galaxy.Sun @Module -public interface StarsModule { - +interface StarsModule { @BindInstance - IStar star(); + fun star(): IStar? @BindInstance - Sun sun(); - - + fun sun(): Sun? } diff --git a/tests/src/main/java/com/github/klee0kai/test/di/bindinstance/singlemethod/PlanetComponent.kt b/tests/src/main/java/com/github/klee0kai/test/di/bindinstance/singlemethod/PlanetComponent.kt index fa5670ef..253e7790 100644 --- a/tests/src/main/java/com/github/klee0kai/test/di/bindinstance/singlemethod/PlanetComponent.kt +++ b/tests/src/main/java/com/github/klee0kai/test/di/bindinstance/singlemethod/PlanetComponent.kt @@ -1,25 +1,23 @@ -package com.github.klee0kai.test.di.bindinstance.singlemethod; +package com.github.klee0kai.test.di.bindinstance.singlemethod -import com.github.klee0kai.stone.annotations.component.Component; -import com.github.klee0kai.stone.annotations.module.BindInstance; -import com.github.klee0kai.test.mowgli.galaxy.Earth; -import com.github.klee0kai.test.mowgli.galaxy.IPlanet; -import com.github.klee0kai.test.mowgli.galaxy.Sun; +import com.github.klee0kai.stone.annotations.component.Component +import com.github.klee0kai.stone.annotations.module.BindInstance +import com.github.klee0kai.test.mowgli.galaxy.Earth +import com.github.klee0kai.test.mowgli.galaxy.IPlanet +import com.github.klee0kai.test.mowgli.galaxy.Sun @Component -public interface PlanetComponent { - - SunModule sunModule(); +interface PlanetComponent { + fun sunModule(): SunModule? @BindInstance - IPlanet planet(IPlanet planet); + fun planet(planet: IPlanet?): IPlanet? @BindInstance(cache = BindInstance.CacheType.Weak) - Earth earth(Earth earth); + fun earth(earth: Earth?): Earth? - IPlanet providePlanet(); + fun providePlanet(): IPlanet? @BindInstance - void bindSun(Sun sun); - + fun bindSun(sun: Sun?) } diff --git a/tests/src/main/java/com/github/klee0kai/test/di/bindinstance/singlemethod/SunModule.kt b/tests/src/main/java/com/github/klee0kai/test/di/bindinstance/singlemethod/SunModule.kt index 5c1ccef4..2698d7cd 100644 --- a/tests/src/main/java/com/github/klee0kai/test/di/bindinstance/singlemethod/SunModule.kt +++ b/tests/src/main/java/com/github/klee0kai/test/di/bindinstance/singlemethod/SunModule.kt @@ -1,36 +1,32 @@ -package com.github.klee0kai.test.di.bindinstance.singlemethod; +package com.github.klee0kai.test.di.bindinstance.singlemethod +import com.github.klee0kai.stone.annotations.module.BindInstance +import com.github.klee0kai.stone.annotations.module.Module +import com.github.klee0kai.test.di.gcforest.scopes.GcSunScope +import com.github.klee0kai.test.mowgli.galaxy.IStar +import com.github.klee0kai.test.mowgli.galaxy.Sun +import javax.inject.Named -import com.github.klee0kai.stone.annotations.module.BindInstance; -import com.github.klee0kai.stone.annotations.module.Module; -import com.github.klee0kai.test.di.gcforest.scopes.GcSunScope; -import com.github.klee0kai.test.mowgli.galaxy.IStar; -import com.github.klee0kai.test.mowgli.galaxy.Sun; - -import javax.inject.Named; @Module -public interface SunModule { - +interface SunModule { @GcSunScope @Named("strong") @BindInstance(cache = BindInstance.CacheType.Strong) - Sun sunStrong(Sun sun); + fun sunStrong(sun: Sun?): Sun? @GcSunScope @Named("soft") @BindInstance(cache = BindInstance.CacheType.Soft) - Sun sunSoft(Sun sun); + fun sunSoft(sun: Sun?): Sun? @GcSunScope @BindInstance - Sun sun(Sun sun); + fun sun(sun: Sun?): Sun? @GcSunScope @BindInstance(cache = BindInstance.CacheType.Weak) - IStar star(IStar star); - - + fun star(star: IStar?): IStar? } diff --git a/tests/src/main/java/com/github/klee0kai/test/di/bindinstance/singlemethod_gc/PlanetRollingComponent.kt b/tests/src/main/java/com/github/klee0kai/test/di/bindinstance/singlemethod_gc/PlanetRollingComponent.kt index 63ba5444..bbe1a6a0 100644 --- a/tests/src/main/java/com/github/klee0kai/test/di/bindinstance/singlemethod_gc/PlanetRollingComponent.kt +++ b/tests/src/main/java/com/github/klee0kai/test/di/bindinstance/singlemethod_gc/PlanetRollingComponent.kt @@ -1,62 +1,59 @@ -package com.github.klee0kai.test.di.bindinstance.singlemethod_gc; +package com.github.klee0kai.test.di.bindinstance.singlemethod_gc -import com.github.klee0kai.stone.annotations.component.*; -import com.github.klee0kai.stone.annotations.module.BindInstance; -import com.github.klee0kai.test.di.bindinstance.singlemethod.SunModule; -import com.github.klee0kai.test.di.gcforest.scopes.GcPlanetScope; -import com.github.klee0kai.test.di.gcforest.scopes.GcSunScope; -import com.github.klee0kai.test.mowgli.galaxy.Earth; -import com.github.klee0kai.test.mowgli.galaxy.IPlanet; +import com.github.klee0kai.stone.annotations.component.* +import com.github.klee0kai.stone.annotations.module.BindInstance +import com.github.klee0kai.test.di.bindinstance.singlemethod.SunModule +import com.github.klee0kai.test.di.gcforest.scopes.GcPlanetScope +import com.github.klee0kai.test.di.gcforest.scopes.GcSunScope +import com.github.klee0kai.test.mowgli.galaxy.Earth +import com.github.klee0kai.test.mowgli.galaxy.IPlanet @Component -public interface PlanetRollingComponent { - - SunModule sunModule(); +interface PlanetRollingComponent { + fun sunModule(): SunModule? @GcPlanetScope @BindInstance(cache = BindInstance.CacheType.Strong) - Earth earthStrong(Earth earth); + fun earthStrong(earth: Earth?): Earth? @GcPlanetScope @BindInstance(cache = BindInstance.CacheType.Soft) - Earth earthSoft(Earth earth); + fun earthSoft(earth: Earth?): Earth? @GcPlanetScope @BindInstance(cache = BindInstance.CacheType.Weak) - IPlanet planet(IPlanet planet); + fun planet(planet: IPlanet?): IPlanet? @GcPlanetScope @BindInstance(cache = BindInstance.CacheType.Weak) - Earth earth(Earth earth); + fun earth(earth: Earth?): Earth? - IPlanet providePlanet(); + fun providePlanet(): IPlanet? @RunGc @GcAllScope - void gcAll(); + fun gcAll() @RunGc @GcStrongScope - void gcStrong(); + fun gcStrong() @RunGc @GcSoftScope - void gcSoft(); + fun gcSoft() @RunGc @GcWeakScope - void gcWeak(); + fun gcWeak() @RunGc @GcSoftScope @GcSunScope - void gcSoftSun(); + fun gcSoftSun() @RunGc @GcSoftScope @GcPlanetScope - void gcSoftPlanets(); - - + fun gcSoftPlanets() } diff --git a/tests/src/main/java/com/github/klee0kai/test/di/bindinstance/singlemethod_inject/StarSkyComponent.kt b/tests/src/main/java/com/github/klee0kai/test/di/bindinstance/singlemethod_inject/StarSkyComponent.kt index cda2ae9e..25d52345 100644 --- a/tests/src/main/java/com/github/klee0kai/test/di/bindinstance/singlemethod_inject/StarSkyComponent.kt +++ b/tests/src/main/java/com/github/klee0kai/test/di/bindinstance/singlemethod_inject/StarSkyComponent.kt @@ -1,35 +1,34 @@ -package com.github.klee0kai.test.di.bindinstance.singlemethod_inject; - -import com.github.klee0kai.stone.annotations.component.Component; -import com.github.klee0kai.stone.annotations.component.GcAllScope; -import com.github.klee0kai.stone.annotations.component.ProtectInjected; -import com.github.klee0kai.stone.annotations.component.RunGc; -import com.github.klee0kai.stone.annotations.module.BindInstance; -import com.github.klee0kai.test.mowgli.MoonSky; -import com.github.klee0kai.test.mowgli.galaxy.Earth; -import com.github.klee0kai.test.mowgli.galaxy.IPlanet; -import com.github.klee0kai.test.mowgli.galaxy.Mercury; +package com.github.klee0kai.test.di.bindinstance.singlemethod_inject + +import com.github.klee0kai.stone.annotations.component.Component +import com.github.klee0kai.stone.annotations.component.GcAllScope +import com.github.klee0kai.stone.annotations.component.ProtectInjected +import com.github.klee0kai.stone.annotations.component.RunGc +import com.github.klee0kai.stone.annotations.module.BindInstance +import com.github.klee0kai.test.mowgli.MoonSky +import com.github.klee0kai.test.mowgli.galaxy.Earth +import com.github.klee0kai.test.mowgli.galaxy.IPlanet +import com.github.klee0kai.test.mowgli.galaxy.Mercury @Component -public interface StarSkyComponent { - - StarSkyModule starModule(); +interface StarSkyComponent { + fun starModule(): StarSkyModule? @BindInstance - IPlanet planet(IPlanet planet); + fun planet(planet: IPlanet?): IPlanet? @BindInstance - Earth earth(Earth earth); + fun earth(earth: Earth?): Earth? @BindInstance(cache = BindInstance.CacheType.Weak) - Mercury mercury(Mercury earth); + fun mercury(earth: Mercury?): Mercury? @RunGc @GcAllScope - void gcAll(); + fun gcAll() - void inject(MoonSky moonSky); + fun inject(moonSky: MoonSky?) @ProtectInjected(timeMillis = 50) - void protectInjected(MoonSky moonSky); + fun protectInjected(moonSky: MoonSky?) } diff --git a/tests/src/main/java/com/github/klee0kai/test/di/bindinstance/singlemethod_inject/StarSkyModule.kt b/tests/src/main/java/com/github/klee0kai/test/di/bindinstance/singlemethod_inject/StarSkyModule.kt index 34346bc2..a29441f5 100644 --- a/tests/src/main/java/com/github/klee0kai/test/di/bindinstance/singlemethod_inject/StarSkyModule.kt +++ b/tests/src/main/java/com/github/klee0kai/test/di/bindinstance/singlemethod_inject/StarSkyModule.kt @@ -1,23 +1,20 @@ -package com.github.klee0kai.test.di.bindinstance.singlemethod_inject; +package com.github.klee0kai.test.di.bindinstance.singlemethod_inject +import com.github.klee0kai.stone.annotations.module.BindInstance +import com.github.klee0kai.stone.annotations.module.Module +import com.github.klee0kai.test.di.gcforest.scopes.GcSunScope +import com.github.klee0kai.test.mowgli.galaxy.IStar +import com.github.klee0kai.test.mowgli.galaxy.Sun -import com.github.klee0kai.stone.annotations.module.BindInstance; -import com.github.klee0kai.stone.annotations.module.Module; -import com.github.klee0kai.test.di.gcforest.scopes.GcSunScope; -import com.github.klee0kai.test.mowgli.galaxy.IStar; -import com.github.klee0kai.test.mowgli.galaxy.Sun; @Module -public interface StarSkyModule { - +interface StarSkyModule { @GcSunScope @BindInstance - Sun sun(Sun sun); + fun sun(sun: Sun?): Sun? @GcSunScope @BindInstance(cache = BindInstance.CacheType.Weak) - IStar star(IStar star); - - + fun star(star: IStar?): IStar? } diff --git a/tests/src/main/java/com/github/klee0kai/test/di/bindinstance/solarsystem/PlanetModule.kt b/tests/src/main/java/com/github/klee0kai/test/di/bindinstance/solarsystem/PlanetModule.kt index 363448b7..d4eaebdb 100644 --- a/tests/src/main/java/com/github/klee0kai/test/di/bindinstance/solarsystem/PlanetModule.kt +++ b/tests/src/main/java/com/github/klee0kai/test/di/bindinstance/solarsystem/PlanetModule.kt @@ -1,31 +1,28 @@ -package com.github.klee0kai.test.di.bindinstance.solarsystem; +package com.github.klee0kai.test.di.bindinstance.solarsystem -import com.github.klee0kai.stone.annotations.module.Module; -import com.github.klee0kai.stone.annotations.module.Provide; -import com.github.klee0kai.test.mowgli.galaxy.*; +import com.github.klee0kai.stone.annotations.module.Module +import com.github.klee0kai.stone.annotations.module.Provide +import com.github.klee0kai.test.mowgli.galaxy.* @Module -public class PlanetModule { - +open class PlanetModule { @Provide(cache = Provide.CacheType.Strong) - Sun sun(SolarSystem solarSystem) { - return new Sun(); + open fun sun(solarSystem: SolarSystem?): Sun? { + return Sun() } @Provide(cache = Provide.CacheType.Soft) - Earth earth(Sun sun){ - return new Earth(); + open fun earth(sun: Sun?): Earth? { + return Earth() } @Provide(cache = Provide.CacheType.Soft) - Mercury mercury(Sun sun){ - return new Mercury(); + open fun mercury(sun: Sun?): Mercury? { + return Mercury() } @Provide(cache = Provide.CacheType.Soft) - Saturn saturn(Sun sun){ - return new Saturn(); + open fun saturn(sun: Sun?): Saturn? { + return Saturn() } - - } diff --git a/tests/src/main/java/com/github/klee0kai/test/di/bindinstance/solarsystem/SolarSystemComponent.kt b/tests/src/main/java/com/github/klee0kai/test/di/bindinstance/solarsystem/SolarSystemComponent.kt index d7bdfc93..a65abba1 100644 --- a/tests/src/main/java/com/github/klee0kai/test/di/bindinstance/solarsystem/SolarSystemComponent.kt +++ b/tests/src/main/java/com/github/klee0kai/test/di/bindinstance/solarsystem/SolarSystemComponent.kt @@ -1,15 +1,14 @@ -package com.github.klee0kai.test.di.bindinstance.solarsystem; +package com.github.klee0kai.test.di.bindinstance.solarsystem -import com.github.klee0kai.stone.annotations.component.Component; -import com.github.klee0kai.stone.annotations.module.BindInstance; -import com.github.klee0kai.test.mowgli.galaxy.SolarSystem; +import com.github.klee0kai.stone.annotations.component.Component +import com.github.klee0kai.stone.annotations.module.BindInstance +import com.github.klee0kai.test.mowgli.galaxy.SolarSystem @Component -public interface SolarSystemComponent extends SolarSystemDependencies { - - PlanetModule planets(); +interface SolarSystemComponent : SolarSystemDependencies { + fun planets(): PlanetModule? @BindInstance - SolarSystem bind(SolarSystem system); + fun bind(system: SolarSystem?): SolarSystem? } diff --git a/tests/src/main/java/com/github/klee0kai/test/di/bindinstance/solarsystem/SolarSystemDependencies.kt b/tests/src/main/java/com/github/klee0kai/test/di/bindinstance/solarsystem/SolarSystemDependencies.kt index 59e28e7a..ec2ee6c6 100644 --- a/tests/src/main/java/com/github/klee0kai/test/di/bindinstance/solarsystem/SolarSystemDependencies.kt +++ b/tests/src/main/java/com/github/klee0kai/test/di/bindinstance/solarsystem/SolarSystemDependencies.kt @@ -1,15 +1,14 @@ -package com.github.klee0kai.test.di.bindinstance.solarsystem; +package com.github.klee0kai.test.di.bindinstance.solarsystem -import com.github.klee0kai.stone.wrappers.LazyProvide; -import com.github.klee0kai.test.mowgli.galaxy.Earth; -import com.github.klee0kai.test.mowgli.galaxy.Mercury; -import com.github.klee0kai.test.mowgli.galaxy.Saturn; +import com.github.klee0kai.stone.wrappers.LazyProvide +import com.github.klee0kai.test.mowgli.galaxy.Earth +import com.github.klee0kai.test.mowgli.galaxy.Mercury +import com.github.klee0kai.test.mowgli.galaxy.Saturn -public interface SolarSystemDependencies { +interface SolarSystemDependencies { + fun earth(): LazyProvide? - LazyProvide earth(); + fun mercury(): LazyProvide? - LazyProvide mercury(); - - LazyProvide saturn(); + fun saturn(): LazyProvide? } diff --git a/tests/src/main/java/com/github/klee0kai/test/di/earthmirror/EarthComponent.kt b/tests/src/main/java/com/github/klee0kai/test/di/earthmirror/EarthComponent.kt index 645cc96e..afacaa9f 100644 --- a/tests/src/main/java/com/github/klee0kai/test/di/earthmirror/EarthComponent.kt +++ b/tests/src/main/java/com/github/klee0kai/test/di/earthmirror/EarthComponent.kt @@ -1,15 +1,11 @@ -package com.github.klee0kai.test.di.earthmirror; +package com.github.klee0kai.test.di.earthmirror -import com.github.klee0kai.stone.annotations.component.Component; -import com.github.klee0kai.test.mowgli.earth.Cave; +import com.github.klee0kai.stone.annotations.component.Component +import com.github.klee0kai.test.mowgli.earth.Cave.CaveType -@Component( - identifiers = {Cave.CaveType.class, Integer.class} -) -public interface EarthComponent { - - EastModule east(); - - WestModule west(); +@Component(identifiers = [CaveType::class, Int::class]) +interface EarthComponent { + fun east(): EastModule? + fun west(): WestModule? } diff --git a/tests/src/main/java/com/github/klee0kai/test/di/earthmirror/EastModule.kt b/tests/src/main/java/com/github/klee0kai/test/di/earthmirror/EastModule.kt index f5bc070b..edcf56d3 100644 --- a/tests/src/main/java/com/github/klee0kai/test/di/earthmirror/EastModule.kt +++ b/tests/src/main/java/com/github/klee0kai/test/di/earthmirror/EastModule.kt @@ -1,16 +1,15 @@ -package com.github.klee0kai.test.di.earthmirror; +package com.github.klee0kai.test.di.earthmirror -import com.github.klee0kai.stone.annotations.module.Module; -import com.github.klee0kai.stone.annotations.module.Provide; -import com.github.klee0kai.test.mowgli.earth.Cave; +import com.github.klee0kai.stone.annotations.module.Module +import com.github.klee0kai.stone.annotations.module.Provide +import com.github.klee0kai.test.mowgli.earth.Cave +import com.github.klee0kai.test.mowgli.earth.Cave.CaveType @Module -public interface EastModule { - +interface EastModule { @Provide(cache = Provide.CacheType.Soft) - Cave cave(); + fun cave(): Cave? @Provide(cache = Provide.CacheType.Soft) - Cave cave(Cave.CaveType type, Integer deep); - + fun cave(type: CaveType?, deep: Int?): Cave? } diff --git a/tests/src/main/java/com/github/klee0kai/test/di/earthmirror/WestModule.kt b/tests/src/main/java/com/github/klee0kai/test/di/earthmirror/WestModule.kt index 175345d3..9c705765 100644 --- a/tests/src/main/java/com/github/klee0kai/test/di/earthmirror/WestModule.kt +++ b/tests/src/main/java/com/github/klee0kai/test/di/earthmirror/WestModule.kt @@ -1,26 +1,25 @@ -package com.github.klee0kai.test.di.earthmirror; +package com.github.klee0kai.test.di.earthmirror -import com.github.klee0kai.stone.annotations.module.Module; -import com.github.klee0kai.stone.annotations.module.Provide; -import com.github.klee0kai.test.mowgli.earth.*; +import com.github.klee0kai.stone.annotations.module.Module +import com.github.klee0kai.stone.annotations.module.Provide +import com.github.klee0kai.test.mowgli.earth.* +import com.github.klee0kai.test.mowgli.earth.Cave.CaveType @Module -public abstract class WestModule { - +abstract class WestModule { @Provide(cache = Provide.CacheType.Factory) - public IRiver riverImpl() { - return new River(); + open fun riverImpl(): IRiver? { + return River() } @Provide(cache = Provide.CacheType.Soft) - public IMountain mountainImp() { - return new Mountain(); + open fun mountainImp(): IMountain? { + return Mountain() } @Provide(cache = Provide.CacheType.Soft) - public abstract Cave cave(); + abstract fun cave(): Cave? @Provide(cache = Provide.CacheType.Soft) - public abstract Cave cave(Cave.CaveType type, Integer deep); - + abstract fun cave(type: CaveType?, deep: Int?): Cave? } diff --git a/tests/src/main/java/com/github/klee0kai/test/di/gcforest/GcEarthComponent.kt b/tests/src/main/java/com/github/klee0kai/test/di/gcforest/GcEarthComponent.kt index 9f945659..149f3570 100644 --- a/tests/src/main/java/com/github/klee0kai/test/di/gcforest/GcEarthComponent.kt +++ b/tests/src/main/java/com/github/klee0kai/test/di/gcforest/GcEarthComponent.kt @@ -1,34 +1,33 @@ -package com.github.klee0kai.test.di.gcforest; +package com.github.klee0kai.test.di.gcforest -import com.github.klee0kai.stone.annotations.component.GcSoftScope; -import com.github.klee0kai.stone.annotations.component.GcStrongScope; -import com.github.klee0kai.stone.annotations.component.RunGc; -import com.github.klee0kai.test.di.gcforest.scopes.GcMountainScope; -import com.github.klee0kai.test.di.gcforest.scopes.GcRiverScope; - -public abstract class GcEarthComponent { +import com.github.klee0kai.stone.annotations.component.GcSoftScope +import com.github.klee0kai.stone.annotations.component.GcStrongScope +import com.github.klee0kai.stone.annotations.component.RunGc +import com.github.klee0kai.test.di.gcforest.scopes.GcMountainScope +import com.github.klee0kai.test.di.gcforest.scopes.GcRiverScope +abstract class GcEarthComponent { @RunGc @GcMountainScope - public abstract void gcMountains(); + abstract fun gcMountains() @RunGc @GcSoftScope @GcMountainScope - public abstract void gcSoftMountains(); + abstract fun gcSoftMountains() @RunGc @GcStrongScope @GcMountainScope - public abstract void gcStrongMountains(); + abstract fun gcStrongMountains() @RunGc @GcRiverScope - public abstract void gcRivers(); + abstract fun gcRivers() - public void gcMountainsAndRivers() { - gcMountains(); - gcRivers(); + fun gcMountainsAndRivers() { + gcMountains() + gcRivers() } } diff --git a/tests/src/main/java/com/github/klee0kai/test/di/gcforest/GcEarthModule.kt b/tests/src/main/java/com/github/klee0kai/test/di/gcforest/GcEarthModule.kt index cc9ce1c5..0c110c3f 100644 --- a/tests/src/main/java/com/github/klee0kai/test/di/gcforest/GcEarthModule.kt +++ b/tests/src/main/java/com/github/klee0kai/test/di/gcforest/GcEarthModule.kt @@ -1,61 +1,58 @@ -package com.github.klee0kai.test.di.gcforest; +package com.github.klee0kai.test.di.gcforest -import com.github.klee0kai.stone.annotations.module.Module; -import com.github.klee0kai.stone.annotations.module.Provide; -import com.github.klee0kai.test.di.gcforest.scopes.GcMountainScope; -import com.github.klee0kai.test.di.gcforest.scopes.GcRiverScope; -import com.github.klee0kai.test.mowgli.earth.Mountain; -import com.github.klee0kai.test.mowgli.earth.River; +import com.github.klee0kai.stone.annotations.module.Module +import com.github.klee0kai.stone.annotations.module.Provide +import com.github.klee0kai.test.di.gcforest.scopes.GcMountainScope +import com.github.klee0kai.test.di.gcforest.scopes.GcRiverScope +import com.github.klee0kai.test.mowgli.earth.Mountain +import com.github.klee0kai.test.mowgli.earth.River @Module -public abstract class GcEarthModule { - +abstract class GcEarthModule { @GcMountainScope @Provide(cache = Provide.CacheType.Strong) - abstract public Mountain mountainStrong(); + abstract fun mountainStrong(): Mountain? @GcMountainScope @Provide(cache = Provide.CacheType.Soft) - abstract public Mountain mountainSoft(); + abstract fun mountainSoft(): Mountain? @GcMountainScope @Provide(cache = Provide.CacheType.Weak) - abstract public Mountain mountainWeak(); + abstract fun mountainWeak(): Mountain? @GcMountainScope @Provide(cache = Provide.CacheType.Factory) - public Mountain mountainFactory() { - return new Mountain(); + open fun mountainFactory(): Mountain? { + return Mountain() } @GcMountainScope @Provide - abstract public Mountain mountainDefaultFactory(); + abstract fun mountainDefaultFactory(): Mountain? @GcMountainScope - abstract public Mountain mountainDefault2Factory(); + abstract fun mountainDefault2Factory(): Mountain? @GcRiverScope @Provide(cache = Provide.CacheType.Strong) - abstract public River riverStrong(); + abstract fun riverStrong(): River? @GcRiverScope @Provide(cache = Provide.CacheType.Soft) - abstract public River riverSoft(); + abstract fun riverSoft(): River? @GcRiverScope @Provide(cache = Provide.CacheType.Weak) - abstract public River riverWeak(); + abstract fun riverWeak(): River? @GcRiverScope @Provide(cache = Provide.CacheType.Factory) - abstract public River riverFactory(); + abstract fun riverFactory(): River? @GcRiverScope @Provide - public River riverDefaultSoft() { - return new River(); + open fun riverDefaultSoft(): River? { + return River() } - - } diff --git a/tests/src/main/java/com/github/klee0kai/test/di/gcforest/GcGodComponent.kt b/tests/src/main/java/com/github/klee0kai/test/di/gcforest/GcGodComponent.kt index d9f7de65..bc1203bb 100644 --- a/tests/src/main/java/com/github/klee0kai/test/di/gcforest/GcGodComponent.kt +++ b/tests/src/main/java/com/github/klee0kai/test/di/gcforest/GcGodComponent.kt @@ -1,57 +1,55 @@ -package com.github.klee0kai.test.di.gcforest; +package com.github.klee0kai.test.di.gcforest -import com.github.klee0kai.stone.annotations.component.*; -import com.github.klee0kai.stone.annotations.module.BindInstance; -import com.github.klee0kai.test.di.gcforest.scopes.GcPlanetScope; -import com.github.klee0kai.test.di.gcforest.scopes.GcSunScope; -import com.github.klee0kai.test.mowgli.galaxy.Earth; -import com.github.klee0kai.test.mowgli.galaxy.Saturn; -import com.github.klee0kai.test.mowgli.galaxy.Sun; +import com.github.klee0kai.stone.annotations.component.* +import com.github.klee0kai.stone.annotations.module.BindInstance +import com.github.klee0kai.test.di.gcforest.scopes.GcPlanetScope +import com.github.klee0kai.test.di.gcforest.scopes.GcSunScope +import com.github.klee0kai.test.mowgli.galaxy.Earth +import com.github.klee0kai.test.mowgli.galaxy.Saturn +import com.github.klee0kai.test.mowgli.galaxy.Sun @Component -public abstract class GcGodComponent extends GcEarthComponent { +abstract class GcGodComponent : GcEarthComponent() { + abstract fun sunSystem(): GcSunSystemModule? - public abstract GcSunSystemModule sunSystem(); - - public abstract GcEarthModule earth(); + abstract fun earth(): GcEarthModule? @BindInstance - public abstract void bind(Sun sun); + abstract fun bind(sun: Sun?) @BindInstance - public abstract void bind(Earth earth); + abstract fun bind(earth: Earth?) @BindInstance - public abstract void bind(Saturn saturn); + abstract fun bind(saturn: Saturn?) @RunGc @GcAllScope - public abstract void gcAll(); + abstract fun gcAll() @RunGc @GcStrongScope - public abstract void gcStrong(); + abstract fun gcStrong() @RunGc @GcSoftScope - public abstract void gcSoft(); + abstract fun gcSoft() @RunGc @GcWeakScope - public abstract void gcWeak(); + abstract fun gcWeak() @RunGc @GcSunScope - public abstract void gcSun(); + abstract fun gcSun() @RunGc @GcPlanetScope - public abstract void gcPlanets(); + abstract fun gcPlanets() - public void gcSunAndPlanets() { - gcSun(); - gcPlanets(); + fun gcSunAndPlanets() { + gcSun() + gcPlanets() } - } diff --git a/tests/src/main/java/com/github/klee0kai/test/di/gcforest/GcSunSystemModule.kt b/tests/src/main/java/com/github/klee0kai/test/di/gcforest/GcSunSystemModule.kt index 1397fe37..35b46681 100644 --- a/tests/src/main/java/com/github/klee0kai/test/di/gcforest/GcSunSystemModule.kt +++ b/tests/src/main/java/com/github/klee0kai/test/di/gcforest/GcSunSystemModule.kt @@ -1,33 +1,30 @@ -package com.github.klee0kai.test.di.gcforest; +package com.github.klee0kai.test.di.gcforest -import com.github.klee0kai.stone.annotations.module.BindInstance; -import com.github.klee0kai.stone.annotations.module.Module; -import com.github.klee0kai.test.di.gcforest.scopes.GcPlanetScope; -import com.github.klee0kai.test.di.gcforest.scopes.GcSunScope; -import com.github.klee0kai.test.mowgli.galaxy.Earth; -import com.github.klee0kai.test.mowgli.galaxy.IPlanet; -import com.github.klee0kai.test.mowgli.galaxy.Saturn; -import com.github.klee0kai.test.mowgli.galaxy.Sun; +import com.github.klee0kai.stone.annotations.module.BindInstance +import com.github.klee0kai.stone.annotations.module.Module +import com.github.klee0kai.test.di.gcforest.scopes.GcPlanetScope +import com.github.klee0kai.test.di.gcforest.scopes.GcSunScope +import com.github.klee0kai.test.mowgli.galaxy.Earth +import com.github.klee0kai.test.mowgli.galaxy.IPlanet +import com.github.klee0kai.test.mowgli.galaxy.Saturn +import com.github.klee0kai.test.mowgli.galaxy.Sun @Module -public interface GcSunSystemModule { - +interface GcSunSystemModule { @GcSunScope @BindInstance(cache = BindInstance.CacheType.Strong) - Sun sun(); + fun sun(): Sun? @GcPlanetScope @BindInstance(cache = BindInstance.CacheType.Strong) - IPlanet planet(); + fun planet(): IPlanet? @GcPlanetScope @BindInstance(cache = BindInstance.CacheType.Soft) - Earth earth(); + fun earth(): Earth? @GcPlanetScope @BindInstance(cache = BindInstance.CacheType.Weak) - Saturn saturn(); - - + fun saturn(): Saturn? } diff --git a/tests/src/main/java/com/github/klee0kai/test/di/gcforest/scopes/GcMountainScope.kt b/tests/src/main/java/com/github/klee0kai/test/di/gcforest/scopes/GcMountainScope.kt index d69d1b13..23220034 100644 --- a/tests/src/main/java/com/github/klee0kai/test/di/gcforest/scopes/GcMountainScope.kt +++ b/tests/src/main/java/com/github/klee0kai/test/di/gcforest/scopes/GcMountainScope.kt @@ -1,14 +1,9 @@ -package com.github.klee0kai.test.di.gcforest.scopes; +package com.github.klee0kai.test.di.gcforest.scopes -import javax.inject.Scope; -import java.lang.annotation.Retention; -import java.lang.annotation.Target; +import com.github.klee0kai.stone.weakref.Scope -import static java.lang.annotation.ElementType.METHOD; -import static java.lang.annotation.RetentionPolicy.RUNTIME; @Scope -@Retention(RUNTIME) -@Target(METHOD) -public @interface GcMountainScope { -} +@Retention(AnnotationRetention.RUNTIME) +@Target(AnnotationTarget.FUNCTION, AnnotationTarget.PROPERTY_GETTER, AnnotationTarget.PROPERTY_SETTER) +annotation class GcMountainScope diff --git a/tests/src/main/java/com/github/klee0kai/test/di/gcforest/scopes/GcPlanetScope.kt b/tests/src/main/java/com/github/klee0kai/test/di/gcforest/scopes/GcPlanetScope.kt index c4c8d2f4..3e36efbc 100644 --- a/tests/src/main/java/com/github/klee0kai/test/di/gcforest/scopes/GcPlanetScope.kt +++ b/tests/src/main/java/com/github/klee0kai/test/di/gcforest/scopes/GcPlanetScope.kt @@ -1,15 +1,8 @@ -package com.github.klee0kai.test.di.gcforest.scopes; +package com.github.klee0kai.test.di.gcforest.scopes -import com.github.klee0kai.stone.annotations.component.GcScopeAnnotation; - -import java.lang.annotation.Retention; -import java.lang.annotation.Target; - -import static java.lang.annotation.ElementType.METHOD; -import static java.lang.annotation.RetentionPolicy.RUNTIME; +import com.github.klee0kai.stone.annotations.component.GcScopeAnnotation @GcScopeAnnotation -@Retention(RUNTIME) -@Target(METHOD) -public @interface GcPlanetScope { -} +@Retention(AnnotationRetention.RUNTIME) +@Target(AnnotationTarget.FUNCTION, AnnotationTarget.PROPERTY_GETTER, AnnotationTarget.PROPERTY_SETTER) +annotation class GcPlanetScope diff --git a/tests/src/main/java/com/github/klee0kai/test/di/gcforest/scopes/GcRiverScope.kt b/tests/src/main/java/com/github/klee0kai/test/di/gcforest/scopes/GcRiverScope.kt index 211da4cf..ff6c5c85 100644 --- a/tests/src/main/java/com/github/klee0kai/test/di/gcforest/scopes/GcRiverScope.kt +++ b/tests/src/main/java/com/github/klee0kai/test/di/gcforest/scopes/GcRiverScope.kt @@ -1,14 +1,8 @@ -package com.github.klee0kai.test.di.gcforest.scopes; +package com.github.klee0kai.test.di.gcforest.scopes -import javax.inject.Scope; -import java.lang.annotation.Retention; -import java.lang.annotation.Target; - -import static java.lang.annotation.ElementType.METHOD; -import static java.lang.annotation.RetentionPolicy.RUNTIME; +import javax.inject.Scope @Scope -@Retention(RUNTIME) -@Target(METHOD) -public @interface GcRiverScope { -} +@Retention(AnnotationRetention.RUNTIME) +@Target(AnnotationTarget.FUNCTION, AnnotationTarget.PROPERTY_GETTER, AnnotationTarget.PROPERTY_SETTER) +annotation class GcRiverScope diff --git a/tests/src/main/java/com/github/klee0kai/test/di/gcforest/scopes/GcSunScope.kt b/tests/src/main/java/com/github/klee0kai/test/di/gcforest/scopes/GcSunScope.kt index aafc4459..80b7c97f 100644 --- a/tests/src/main/java/com/github/klee0kai/test/di/gcforest/scopes/GcSunScope.kt +++ b/tests/src/main/java/com/github/klee0kai/test/di/gcforest/scopes/GcSunScope.kt @@ -1,14 +1,8 @@ -package com.github.klee0kai.test.di.gcforest.scopes; +package com.github.klee0kai.test.di.gcforest.scopes -import javax.inject.Scope; -import java.lang.annotation.Retention; -import java.lang.annotation.Target; - -import static java.lang.annotation.ElementType.METHOD; -import static java.lang.annotation.RetentionPolicy.RUNTIME; +import javax.inject.Scope @Scope -@Retention(RUNTIME) -@Target(METHOD) -public @interface GcSunScope { -} +@Retention(AnnotationRetention.RUNTIME) +@Target(AnnotationTarget.FUNCTION, AnnotationTarget.PROPERTY_GETTER, AnnotationTarget.PROPERTY_SETTER) +annotation class GcSunScope diff --git a/tests/src/main/java/com/github/klee0kai/test/di/house/nulls/HouseNullsComponent.kt b/tests/src/main/java/com/github/klee0kai/test/di/house/nulls/HouseNullsComponent.kt index b6225d9d..6b362891 100644 --- a/tests/src/main/java/com/github/klee0kai/test/di/house/nulls/HouseNullsComponent.kt +++ b/tests/src/main/java/com/github/klee0kai/test/di/house/nulls/HouseNullsComponent.kt @@ -1,13 +1,11 @@ -package com.github.klee0kai.test.di.house.nulls; +package com.github.klee0kai.test.di.house.nulls -import com.github.klee0kai.stone.annotations.component.Component; -import com.github.klee0kai.test.house.House; +import com.github.klee0kai.stone.annotations.component.Component +import com.github.klee0kai.test.house.House @Component -public interface HouseNullsComponent { - - HouseNullsModule module(); - - House house(); +interface HouseNullsComponent { + fun module(): HouseNullsModule? + fun house(): House? } diff --git a/tests/src/main/java/com/github/klee0kai/test/di/house/nulls/HouseNullsModule.kt b/tests/src/main/java/com/github/klee0kai/test/di/house/nulls/HouseNullsModule.kt index dbb85d84..95e8229a 100644 --- a/tests/src/main/java/com/github/klee0kai/test/di/house/nulls/HouseNullsModule.kt +++ b/tests/src/main/java/com/github/klee0kai/test/di/house/nulls/HouseNullsModule.kt @@ -1,18 +1,16 @@ -package com.github.klee0kai.test.di.house.nulls; +package com.github.klee0kai.test.di.house.nulls -import com.github.klee0kai.stone.annotations.module.Module; -import com.github.klee0kai.test.house.House; -import com.github.klee0kai.test.house.kitchen.Kichen; +import com.github.klee0kai.stone.annotations.module.Module +import com.github.klee0kai.test.house.House +import com.github.klee0kai.test.house.kitchen.Kichen @Module -public class HouseNullsModule { - - public Kichen kichen() { - return new Kichen(null, null, null); +open class HouseNullsModule { + open fun kichen(): Kichen? { + return Kichen(null, null, null) } - public House house(Kichen kichen) { - return new House(kichen, null, null, null); + open fun house(kichen: Kichen?): House? { + return House(kichen, null, null, null) } - } diff --git a/tests/src/main/java/com/github/klee0kai/test/di/house/simple/AreasModule.kt b/tests/src/main/java/com/github/klee0kai/test/di/house/simple/AreasModule.kt index c843e935..5df859c4 100644 --- a/tests/src/main/java/com/github/klee0kai/test/di/house/simple/AreasModule.kt +++ b/tests/src/main/java/com/github/klee0kai/test/di/house/simple/AreasModule.kt @@ -1,25 +1,28 @@ -package com.github.klee0kai.test.di.house.simple; +package com.github.klee0kai.test.di.house.simple -import com.github.klee0kai.stone.annotations.module.Module; -import com.github.klee0kai.stone.annotations.module.Provide; -import com.github.klee0kai.test.house.identifiers.StoreAreaType; -import com.github.klee0kai.test.house.kitchen.cookingarea.CookingArea; -import com.github.klee0kai.test.house.kitchen.sinkarea.SinkArea; -import com.github.klee0kai.test.house.kitchen.storagearea.*; +import com.github.klee0kai.stone.annotations.module.Module +import com.github.klee0kai.stone.annotations.module.Provide +import com.github.klee0kai.test.house.identifiers.StoreAreaType +import com.github.klee0kai.test.house.kitchen.cookingarea.CookingArea +import com.github.klee0kai.test.house.kitchen.sinkarea.SinkArea +import com.github.klee0kai.test.house.kitchen.storagearea.* @Module -abstract class AreasModule { - +internal abstract class AreasModule { @Provide(cache = Provide.CacheType.Soft) - public abstract CookingArea cookingArea(); + abstract fun cookingArea(): CookingArea? @Provide(cache = Provide.CacheType.Soft) - public abstract SinkArea sinkArea(); + abstract fun sinkArea(): SinkArea? @Provide(cache = Provide.CacheType.Factory) - public abstract StoreArea storeArea(StoreAreaType type, Cookware cookware, Clothes clothes, Sanitizers sanitizers); + abstract fun storeArea( + type: StoreAreaType?, + cookware: Cookware?, + clothes: Clothes?, + sanitizers: Sanitizers? + ): StoreArea? @Provide(cache = Provide.CacheType.Soft) - abstract public GarageStore garageStore(Cookware cookware, Clothes clothes, Sanitizers sanitizers); - + abstract fun garageStore(cookware: Cookware?, clothes: Clothes?, sanitizers: Sanitizers?): GarageStore? } diff --git a/tests/src/main/java/com/github/klee0kai/test/di/house/simple/HouseComponent.kt b/tests/src/main/java/com/github/klee0kai/test/di/house/simple/HouseComponent.kt index fe27883b..50743dfb 100644 --- a/tests/src/main/java/com/github/klee0kai/test/di/house/simple/HouseComponent.kt +++ b/tests/src/main/java/com/github/klee0kai/test/di/house/simple/HouseComponent.kt @@ -1,36 +1,32 @@ -package com.github.klee0kai.test.di.house.simple; +package com.github.klee0kai.test.di.house.simple -import com.github.klee0kai.stone.annotations.component.Component; -import com.github.klee0kai.stone.annotations.component.ModuleOriginFactory; -import com.github.klee0kai.test.house.House; -import com.github.klee0kai.test.house.InHouse; -import com.github.klee0kai.test.house.identifiers.StoreAreaType; -import com.github.klee0kai.test.house.kitchen.storagearea.Sanitizers; +import com.github.klee0kai.stone.annotations.component.Component +import com.github.klee0kai.stone.annotations.component.ModuleOriginFactory +import com.github.klee0kai.test.house.House +import com.github.klee0kai.test.house.InHouse +import com.github.klee0kai.test.house.identifiers.StoreAreaType +import com.github.klee0kai.test.house.kitchen.storagearea.Sanitizers -@Component( - identifiers = {StoreAreaType.class} -) -public interface HouseComponent { - - HouseModule module(); +@Component(identifiers = [StoreAreaType::class]) +interface HouseComponent { + fun module(): HouseModule? @ModuleOriginFactory - HouseModule moduleFactory(); - - RoomsModule rooms(); + fun moduleFactory(): HouseModule? - AreasModule area(); + fun rooms(): RoomsModule? - ToolsModule tools(); + fun area(): AreasModule? - House house(); + fun tools(): ToolsModule? - Sanitizers sanitizers(); + fun house(): House? - House house(StoreAreaType type); + fun sanitizers(): Sanitizers? - void inject(StoreAreaType storeAreaType, InHouse inHouse); + fun house(type: StoreAreaType?): House? - void inject(InHouse inHouse); + fun inject(storeAreaType: StoreAreaType?, inHouse: InHouse?) + fun inject(inHouse: InHouse?) } diff --git a/tests/src/main/java/com/github/klee0kai/test/di/house/simple/HouseModule.kt b/tests/src/main/java/com/github/klee0kai/test/di/house/simple/HouseModule.kt index 0a9f83b7..cd3949fe 100644 --- a/tests/src/main/java/com/github/klee0kai/test/di/house/simple/HouseModule.kt +++ b/tests/src/main/java/com/github/klee0kai/test/di/house/simple/HouseModule.kt @@ -1,17 +1,15 @@ -package com.github.klee0kai.test.di.house.simple; +package com.github.klee0kai.test.di.house.simple -import com.github.klee0kai.stone.annotations.module.Module; -import com.github.klee0kai.stone.annotations.module.Provide; -import com.github.klee0kai.test.house.House; -import com.github.klee0kai.test.house.kitchen.Kichen; -import com.github.klee0kai.test.house.rooms.BathRoom; -import com.github.klee0kai.test.house.rooms.BedRoom; -import com.github.klee0kai.test.house.rooms.Garage; +import com.github.klee0kai.stone.annotations.module.Module +import com.github.klee0kai.stone.annotations.module.Provide +import com.github.klee0kai.test.house.House +import com.github.klee0kai.test.house.kitchen.Kichen +import com.github.klee0kai.test.house.rooms.BathRoom +import com.github.klee0kai.test.house.rooms.BedRoom +import com.github.klee0kai.test.house.rooms.Garage @Module -public interface HouseModule { - +interface HouseModule { @Provide(cache = Provide.CacheType.Soft) - House house(Kichen kichen, BathRoom bathRoom, BedRoom bedRoom, Garage garage); - + fun house(kichen: Kichen?, bathRoom: BathRoom?, bedRoom: BedRoom?, garage: Garage?): House? } diff --git a/tests/src/main/java/com/github/klee0kai/test/di/house/simple/RoomsModule.kt b/tests/src/main/java/com/github/klee0kai/test/di/house/simple/RoomsModule.kt index 82583dbb..5464827d 100644 --- a/tests/src/main/java/com/github/klee0kai/test/di/house/simple/RoomsModule.kt +++ b/tests/src/main/java/com/github/klee0kai/test/di/house/simple/RoomsModule.kt @@ -1,29 +1,27 @@ -package com.github.klee0kai.test.di.house.simple; +package com.github.klee0kai.test.di.house.simple -import com.github.klee0kai.stone.annotations.module.Module; -import com.github.klee0kai.stone.annotations.module.Provide; -import com.github.klee0kai.test.house.kitchen.Kichen; -import com.github.klee0kai.test.house.kitchen.cookingarea.CookingArea; -import com.github.klee0kai.test.house.kitchen.sinkarea.SinkArea; -import com.github.klee0kai.test.house.kitchen.storagearea.GarageStore; -import com.github.klee0kai.test.house.kitchen.storagearea.StoreArea; -import com.github.klee0kai.test.house.rooms.BathRoom; -import com.github.klee0kai.test.house.rooms.BedRoom; -import com.github.klee0kai.test.house.rooms.Garage; +import com.github.klee0kai.stone.annotations.module.Module +import com.github.klee0kai.stone.annotations.module.Provide +import com.github.klee0kai.test.house.kitchen.Kichen +import com.github.klee0kai.test.house.kitchen.cookingarea.CookingArea +import com.github.klee0kai.test.house.kitchen.sinkarea.SinkArea +import com.github.klee0kai.test.house.kitchen.storagearea.GarageStore +import com.github.klee0kai.test.house.kitchen.storagearea.StoreArea +import com.github.klee0kai.test.house.rooms.BathRoom +import com.github.klee0kai.test.house.rooms.BedRoom +import com.github.klee0kai.test.house.rooms.Garage @Module -public interface RoomsModule { - +interface RoomsModule { @Provide(cache = Provide.CacheType.Soft) - Kichen kitchen(CookingArea cookingArea, SinkArea sinkArea, StoreArea storeArea); + fun kitchen(cookingArea: CookingArea?, sinkArea: SinkArea?, storeArea: StoreArea?): Kichen? @Provide(cache = Provide.CacheType.Soft) - BathRoom bathRoom(StoreArea storeArea); + fun bathRoom(storeArea: StoreArea?): BathRoom? @Provide(cache = Provide.CacheType.Soft) - BedRoom bedRoom(StoreArea storeArea); + fun bedRoom(storeArea: StoreArea?): BedRoom? @Provide(cache = Provide.CacheType.Soft) - Garage garage(GarageStore garageStore); - + fun garage(garageStore: GarageStore?): Garage? } diff --git a/tests/src/main/java/com/github/klee0kai/test/di/house/simple/ToolsModule.kt b/tests/src/main/java/com/github/klee0kai/test/di/house/simple/ToolsModule.kt index 934535fb..b2cd63ce 100644 --- a/tests/src/main/java/com/github/klee0kai/test/di/house/simple/ToolsModule.kt +++ b/tests/src/main/java/com/github/klee0kai/test/di/house/simple/ToolsModule.kt @@ -1,21 +1,19 @@ -package com.github.klee0kai.test.di.house.simple; +package com.github.klee0kai.test.di.house.simple -import com.github.klee0kai.stone.annotations.module.Module; -import com.github.klee0kai.stone.annotations.module.Provide; -import com.github.klee0kai.test.house.kitchen.storagearea.Clothes; -import com.github.klee0kai.test.house.kitchen.storagearea.Cookware; -import com.github.klee0kai.test.house.kitchen.storagearea.Sanitizers; +import com.github.klee0kai.stone.annotations.module.Module +import com.github.klee0kai.stone.annotations.module.Provide +import com.github.klee0kai.test.house.kitchen.storagearea.Clothes +import com.github.klee0kai.test.house.kitchen.storagearea.Cookware +import com.github.klee0kai.test.house.kitchen.storagearea.Sanitizers @Module -public interface ToolsModule { - +interface ToolsModule { @Provide(cache = Provide.CacheType.Factory) - Cookware cookware(); + fun cookware(): Cookware? @Provide(cache = Provide.CacheType.Factory) - Clothes clothes(); + fun clothes(): Clothes? @Provide(cache = Provide.CacheType.Factory) - Sanitizers sanitizers(); - + fun sanitizers(): Sanitizers? } diff --git a/tests/src/main/java/com/github/klee0kai/test/di/swcache/SwitchCacheComponent.kt b/tests/src/main/java/com/github/klee0kai/test/di/swcache/SwitchCacheComponent.kt index 75f40714..ebe2ee9f 100644 --- a/tests/src/main/java/com/github/klee0kai/test/di/swcache/SwitchCacheComponent.kt +++ b/tests/src/main/java/com/github/klee0kai/test/di/swcache/SwitchCacheComponent.kt @@ -1,33 +1,31 @@ -package com.github.klee0kai.test.di.swcache; +package com.github.klee0kai.test.di.swcache -import com.github.klee0kai.stone.annotations.component.Component; -import com.github.klee0kai.stone.annotations.component.GcAllScope; -import com.github.klee0kai.stone.annotations.component.GcStrongScope; -import com.github.klee0kai.stone.annotations.component.SwitchCache; -import com.github.klee0kai.test.di.gcforest.GcEarthModule; -import com.github.klee0kai.test.di.gcforest.scopes.GcMountainScope; +import com.github.klee0kai.stone.annotations.component.Component +import com.github.klee0kai.stone.annotations.component.GcAllScope +import com.github.klee0kai.stone.annotations.component.GcStrongScope +import com.github.klee0kai.stone.annotations.component.SwitchCache +import com.github.klee0kai.test.di.gcforest.GcEarthModule +import com.github.klee0kai.test.di.gcforest.scopes.GcMountainScope @Component -public interface SwitchCacheComponent { - - GcEarthModule earth(); +interface SwitchCacheComponent { + fun earth(): GcEarthModule? @GcAllScope @SwitchCache(cache = SwitchCache.CacheType.Weak) - void allWeak(); + fun allWeak() @GcAllScope @SwitchCache(cache = SwitchCache.CacheType.Strong, timeMillis = 100) - void allStrongFewMillis(); + fun allStrongFewMillis() @GcStrongScope @SwitchCache(cache = SwitchCache.CacheType.Weak) - void strongToWeak(); + fun strongToWeak() @GcMountainScope @SwitchCache(cache = SwitchCache.CacheType.Weak) - void mountainToWeak(); - + fun mountainToWeak() } diff --git a/tests/src/main/java/com/github/klee0kai/test/di/techfactory/ITechProviderComponent.kt b/tests/src/main/java/com/github/klee0kai/test/di/techfactory/ITechProviderComponent.kt index e5c1ff49..e8ffc4d4 100644 --- a/tests/src/main/java/com/github/klee0kai/test/di/techfactory/ITechProviderComponent.kt +++ b/tests/src/main/java/com/github/klee0kai/test/di/techfactory/ITechProviderComponent.kt @@ -1,45 +1,41 @@ -package com.github.klee0kai.test.di.techfactory; +package com.github.klee0kai.test.di.techfactory -import com.github.klee0kai.stone.wrappers.LazyProvide; -import com.github.klee0kai.stone.wrappers.PhantomProvide; -import com.github.klee0kai.stone.wrappers.Ref; -import com.github.klee0kai.test.di.base_phone.identifiers.PhoneOsType; -import com.github.klee0kai.test.di.base_phone.identifiers.PhoneOsVersion; -import com.github.klee0kai.test.di.base_phone.identifiers.RamSize; -import com.github.klee0kai.test.tech.components.Battery; -import com.github.klee0kai.test.tech.components.OperationSystem; -import com.github.klee0kai.test.tech.components.Ram; +import com.github.klee0kai.stone.wrappers.LazyProvide +import com.github.klee0kai.stone.wrappers.PhantomProvide +import com.github.klee0kai.stone.wrappers.Ref +import com.github.klee0kai.test.di.base_phone.identifiers.PhoneOsType +import com.github.klee0kai.test.di.base_phone.identifiers.PhoneOsVersion +import com.github.klee0kai.test.di.base_phone.identifiers.RamSize +import com.github.klee0kai.test.tech.components.Battery +import com.github.klee0kai.test.tech.components.OperationSystem +import com.github.klee0kai.test.tech.components.Ram +import java.lang.ref.SoftReference +import java.lang.ref.WeakReference +import javax.inject.Named +import javax.inject.Provider -import javax.inject.Named; -import javax.inject.Provider; -import java.lang.ref.SoftReference; -import java.lang.ref.WeakReference; +interface ITechProviderComponent { + fun batteryLazy(): LazyProvide? -public interface ITechProviderComponent { + fun batteryProviderIRef(): Ref? - LazyProvide batteryLazy(); + fun batteryPhantomProvider(): PhantomProvide? - Ref batteryProviderIRef(); + fun batteryProvider(): Provider? - PhantomProvide batteryPhantomProvider(); + fun batterySoft(): SoftReference? - Provider batteryProvider(); - - SoftReference batterySoft(); - - WeakReference batteryWeak(); + fun batteryWeak(): WeakReference? @Named("null_args") - Ram ram(); + fun ram(): Ram? - Ram ram(RamSize ramSize); + fun ram(ramSize: RamSize?): Ram? @Named("null_args") - OperationSystem phoneOs(); - - OperationSystem phoneOs(PhoneOsType osType); - - OperationSystem phoneOs(PhoneOsType phoneOsType, PhoneOsVersion version); + fun phoneOs(): OperationSystem? + fun phoneOs(osType: PhoneOsType?): OperationSystem? + fun phoneOs(phoneOsType: PhoneOsType?, version: PhoneOsVersion?): OperationSystem? } diff --git a/tests/src/main/java/com/github/klee0kai/test/di/techfactory/TechFactoryComponent.kt b/tests/src/main/java/com/github/klee0kai/test/di/techfactory/TechFactoryComponent.kt index 39368ece..2a10e0f7 100644 --- a/tests/src/main/java/com/github/klee0kai/test/di/techfactory/TechFactoryComponent.kt +++ b/tests/src/main/java/com/github/klee0kai/test/di/techfactory/TechFactoryComponent.kt @@ -1,20 +1,19 @@ -package com.github.klee0kai.test.di.techfactory; +package com.github.klee0kai.test.di.techfactory -import com.github.klee0kai.stone.annotations.component.Component; -import com.github.klee0kai.test.di.base_phone.identifiers.DataStorageSize; -import com.github.klee0kai.test.di.base_phone.identifiers.PhoneOsType; -import com.github.klee0kai.test.di.base_phone.identifiers.PhoneOsVersion; -import com.github.klee0kai.test.di.base_phone.identifiers.RamSize; +import com.github.klee0kai.stone.annotations.component.Component +import com.github.klee0kai.test.di.base_phone.identifiers.DataStorageSize +import com.github.klee0kai.test.di.base_phone.identifiers.PhoneOsType +import com.github.klee0kai.test.di.base_phone.identifiers.PhoneOsVersion +import com.github.klee0kai.test.di.base_phone.identifiers.RamSize @Component( - identifiers = { - RamSize.class, DataStorageSize.class, - PhoneOsType.class, PhoneOsVersion.class - } + identifiers = [ + RamSize::class, + DataStorageSize::class, + PhoneOsType::class, + PhoneOsVersion::class, + ] ) -public interface TechFactoryComponent extends ITechProviderComponent { - - TechFactoryModule factory(); - - +interface TechFactoryComponent : ITechProviderComponent { + fun factory(): TechFactoryModule? } diff --git a/tests/src/main/java/com/github/klee0kai/test/di/techfactory/TechFactoryModule.kt b/tests/src/main/java/com/github/klee0kai/test/di/techfactory/TechFactoryModule.kt index 5308dfe7..87645488 100644 --- a/tests/src/main/java/com/github/klee0kai/test/di/techfactory/TechFactoryModule.kt +++ b/tests/src/main/java/com/github/klee0kai/test/di/techfactory/TechFactoryModule.kt @@ -1,46 +1,42 @@ -package com.github.klee0kai.test.di.techfactory; - -import com.github.klee0kai.stone.annotations.module.Module; -import com.github.klee0kai.stone.annotations.module.Provide; -import com.github.klee0kai.test.di.base_phone.identifiers.DataStorageSize; -import com.github.klee0kai.test.di.base_phone.identifiers.PhoneOsType; -import com.github.klee0kai.test.di.base_phone.identifiers.PhoneOsVersion; -import com.github.klee0kai.test.di.base_phone.identifiers.RamSize; -import com.github.klee0kai.test.tech.components.Battery; -import com.github.klee0kai.test.tech.components.DataStorage; -import com.github.klee0kai.test.tech.components.OperationSystem; -import com.github.klee0kai.test.tech.components.Ram; - -import javax.inject.Named; - +package com.github.klee0kai.test.di.techfactory + +import com.github.klee0kai.stone.annotations.module.Module +import com.github.klee0kai.stone.annotations.module.Provide +import com.github.klee0kai.test.di.base_phone.identifiers.DataStorageSize +import com.github.klee0kai.test.di.base_phone.identifiers.PhoneOsType +import com.github.klee0kai.test.di.base_phone.identifiers.PhoneOsVersion +import com.github.klee0kai.test.di.base_phone.identifiers.RamSize +import com.github.klee0kai.test.tech.components.Battery +import com.github.klee0kai.test.tech.components.DataStorage +import com.github.klee0kai.test.tech.components.OperationSystem +import com.github.klee0kai.test.tech.components.Ram +import javax.inject.Named @Module -public interface TechFactoryModule { - +interface TechFactoryModule { @Provide(cache = Provide.CacheType.Factory) - Battery battery(); + fun battery(): Battery? @Named("null_args") @Provide(cache = Provide.CacheType.Factory) - DataStorage dataStorage(); + fun dataStorage(): DataStorage? @Provide(cache = Provide.CacheType.Factory) - DataStorage dataStorage(DataStorageSize size); + fun dataStorage(size: DataStorageSize?): DataStorage? @Named("null_args") @Provide(cache = Provide.CacheType.Factory) - Ram ram(); + fun ram(): Ram? @Provide(cache = Provide.CacheType.Factory) - Ram ram(RamSize ramSize); + fun ram(ramSize: RamSize?): Ram? @Named("null_args") @Provide(cache = Provide.CacheType.Factory) - OperationSystem phoneOs(PhoneOsType osType); + fun phoneOs(osType: PhoneOsType?): OperationSystem? @Provide(cache = Provide.CacheType.Factory) - OperationSystem phoneOs(PhoneOsType phoneOsType, PhoneOsVersion version); - + fun phoneOs(phoneOsType: PhoneOsType?, version: PhoneOsVersion?): OperationSystem? } diff --git a/tests/src/main/java/com/github/klee0kai/test/di/wire/WireComponent.kt b/tests/src/main/java/com/github/klee0kai/test/di/wire/WireComponent.kt index c6aac113..868a81d9 100644 --- a/tests/src/main/java/com/github/klee0kai/test/di/wire/WireComponent.kt +++ b/tests/src/main/java/com/github/klee0kai/test/di/wire/WireComponent.kt @@ -1,26 +1,23 @@ -package com.github.klee0kai.test.di.wire; +package com.github.klee0kai.test.di.wire -import com.github.klee0kai.stone.annotations.component.Component; -import com.github.klee0kai.stone.annotations.module.BindInstance; -import com.github.klee0kai.test.wire.Wire; -import com.github.klee0kai.test.wire.types.Hdmi; -import com.github.klee0kai.test.wire.types.MiniUsb; -import com.github.klee0kai.test.wire.types.Usb; - -import java.lang.ref.WeakReference; +import com.github.klee0kai.stone.annotations.component.Component +import com.github.klee0kai.stone.annotations.module.BindInstance +import com.github.klee0kai.test.wire.Wire +import com.github.klee0kai.test.wire.types.Hdmi +import com.github.klee0kai.test.wire.types.MiniUsb +import com.github.klee0kai.test.wire.types.Usb +import java.lang.ref.WeakReference @Component -public abstract class WireComponent { - - public abstract WireModule module(); +abstract class WireComponent { + abstract fun module(): WireModule? - public abstract Wire usb_hdmi(); + abstract fun usb_hdmi(): Wire? - public abstract WeakReference> usb_usb(); + abstract fun usb_usb(): WeakReference?>? - public abstract Wire simple(); + abstract fun simple(): Wire<*, *>? @BindInstance - public abstract Wire miniusb_miniusb(Wire wire); - + abstract fun miniusb_miniusb(wire: Wire?): Wire? } diff --git a/tests/src/main/java/com/github/klee0kai/test/di/wire/WireModule.kt b/tests/src/main/java/com/github/klee0kai/test/di/wire/WireModule.kt index 3fead851..e605dced 100644 --- a/tests/src/main/java/com/github/klee0kai/test/di/wire/WireModule.kt +++ b/tests/src/main/java/com/github/klee0kai/test/di/wire/WireModule.kt @@ -1,30 +1,27 @@ -package com.github.klee0kai.test.di.wire; +package com.github.klee0kai.test.di.wire -import com.github.klee0kai.stone.annotations.module.Module; -import com.github.klee0kai.stone.annotations.module.Provide; -import com.github.klee0kai.test.wire.Wire; -import com.github.klee0kai.test.wire.types.Hdmi; -import com.github.klee0kai.test.wire.types.MiniUsb; -import com.github.klee0kai.test.wire.types.Usb; +import com.github.klee0kai.stone.annotations.module.Module +import com.github.klee0kai.stone.annotations.module.Provide +import com.github.klee0kai.test.wire.Wire +import com.github.klee0kai.test.wire.types.Hdmi +import com.github.klee0kai.test.wire.types.MiniUsb +import com.github.klee0kai.test.wire.types.Usb @Module -public abstract class WireModule { - +abstract class WireModule { @Provide(cache = Provide.CacheType.Soft) - public abstract Wire usb_miniusb(); + abstract fun usb_miniusb(): Wire? @Provide(cache = Provide.CacheType.Soft) - public abstract Wire usb_usb(); + abstract fun usb_usb(): Wire? @Provide(cache = Provide.CacheType.Soft) - public Wire usb_hdmi() { - return new Wire<>(); + open fun usb_hdmi(): Wire? { + return Wire() } @Provide(cache = Provide.CacheType.Soft) - public Wire simple() { - return new Wire(); + open fun simple(): Wire<*, *>? { + return Wire() } - - } diff --git a/tests/src/main/java/com/github/klee0kai/test/house/House.kt b/tests/src/main/java/com/github/klee0kai/test/house/House.kt index d7bbd8bb..89f96246 100644 --- a/tests/src/main/java/com/github/klee0kai/test/house/House.kt +++ b/tests/src/main/java/com/github/klee0kai/test/house/House.kt @@ -1,25 +1,12 @@ -package com.github.klee0kai.test.house; +package com.github.klee0kai.test.house -import com.github.klee0kai.test.house.kitchen.Kichen; -import com.github.klee0kai.test.house.rooms.BathRoom; -import com.github.klee0kai.test.house.rooms.BedRoom; -import com.github.klee0kai.test.house.rooms.Garage; +import com.github.klee0kai.test.house.kitchen.Kichen +import com.github.klee0kai.test.house.rooms.BathRoom +import com.github.klee0kai.test.house.rooms.BedRoom +import com.github.klee0kai.test.house.rooms.Garage +import java.util.* -import java.util.UUID; - -public class House { - - public UUID uuid = UUID.randomUUID(); - - public final Kichen kichen; - public final BathRoom bathRoom; - public final BedRoom bedRoom; - public final Garage garage; - - public House(Kichen kichen, BathRoom bathRoom, BedRoom bedRoom, Garage garage) { - this.kichen = kichen; - this.bathRoom = bathRoom; - this.bedRoom = bedRoom; - this.garage = garage; - } +class House(@JvmField val kichen: Kichen?, @JvmField val bathRoom: BathRoom?, @JvmField val bedRoom: BedRoom?, val garage: Garage?) { + @JvmField + var uuid: UUID = UUID.randomUUID() } diff --git a/tests/src/main/java/com/github/klee0kai/test/house/InHouse.kt b/tests/src/main/java/com/github/klee0kai/test/house/InHouse.kt index 599de537..a204117f 100644 --- a/tests/src/main/java/com/github/klee0kai/test/house/InHouse.kt +++ b/tests/src/main/java/com/github/klee0kai/test/house/InHouse.kt @@ -1,27 +1,29 @@ -package com.github.klee0kai.test.house; +package com.github.klee0kai.test.house -import com.github.klee0kai.test.house.kitchen.Kichen; -import com.github.klee0kai.test.house.kitchen.storagearea.StoreArea; -import com.github.klee0kai.test.house.rooms.BathRoom; -import com.github.klee0kai.test.house.rooms.Garage; - -import javax.inject.Inject; - -public class InHouse { +import com.github.klee0kai.test.house.kitchen.Kichen +import com.github.klee0kai.test.house.kitchen.storagearea.StoreArea +import com.github.klee0kai.test.house.rooms.BathRoom +import com.github.klee0kai.test.house.rooms.Garage +import javax.inject.Inject +class InHouse { + @JvmField @Inject - public Kichen kichen; + var kichen: Kichen? = null + @JvmField @Inject - public BathRoom bathRoom; + var bathRoom: BathRoom? = null + @JvmField @Inject - public BathRoom bedRoom; + var bedRoom: BathRoom? = null + @JvmField @Inject - public Garage garage; + var garage: Garage? = null + @JvmField @Inject - public StoreArea bedStoreArea; - + var bedStoreArea: StoreArea? = null } diff --git a/tests/src/main/java/com/github/klee0kai/test/house/identifiers/StoreAreaType.kt b/tests/src/main/java/com/github/klee0kai/test/house/identifiers/StoreAreaType.kt index 1b3b780c..a582791e 100644 --- a/tests/src/main/java/com/github/klee0kai/test/house/identifiers/StoreAreaType.kt +++ b/tests/src/main/java/com/github/klee0kai/test/house/identifiers/StoreAreaType.kt @@ -1,6 +1,6 @@ -package com.github.klee0kai.test.house.identifiers; +package com.github.klee0kai.test.house.identifiers -public enum StoreAreaType { +enum class StoreAreaType { CLOSED, LOCKER, CUPBOARD, diff --git a/tests/src/main/java/com/github/klee0kai/test/house/kitchen/Kichen.kt b/tests/src/main/java/com/github/klee0kai/test/house/kitchen/Kichen.kt index 292f5d6b..3543604a 100644 --- a/tests/src/main/java/com/github/klee0kai/test/house/kitchen/Kichen.kt +++ b/tests/src/main/java/com/github/klee0kai/test/house/kitchen/Kichen.kt @@ -1,23 +1,15 @@ -package com.github.klee0kai.test.house.kitchen; - -import com.github.klee0kai.test.house.kitchen.cookingarea.CookingArea; -import com.github.klee0kai.test.house.kitchen.sinkarea.SinkArea; -import com.github.klee0kai.test.house.kitchen.storagearea.StoreArea; - -import java.util.UUID; - -public class Kichen { - - public UUID uuid = UUID.randomUUID(); - - public final CookingArea cookingArea; - public final SinkArea sinkArea; - public final StoreArea storeArea; - - - public Kichen(CookingArea cookingArea, SinkArea sinkArea, StoreArea storeArea) { - this.cookingArea = cookingArea; - this.sinkArea = sinkArea; - this.storeArea = storeArea; - } +package com.github.klee0kai.test.house.kitchen + +import com.github.klee0kai.test.house.kitchen.cookingarea.CookingArea +import com.github.klee0kai.test.house.kitchen.sinkarea.SinkArea +import com.github.klee0kai.test.house.kitchen.storagearea.StoreArea +import java.util.* + +class Kichen( + @JvmField val cookingArea: CookingArea?, + @JvmField val sinkArea: SinkArea?, + @JvmField val storeArea: StoreArea? +) { + @JvmField + var uuid: UUID = UUID.randomUUID() } diff --git a/tests/src/main/java/com/github/klee0kai/test/house/kitchen/cookingarea/CookingArea.kt b/tests/src/main/java/com/github/klee0kai/test/house/kitchen/cookingarea/CookingArea.kt index 1f4f9351..10b450e0 100644 --- a/tests/src/main/java/com/github/klee0kai/test/house/kitchen/cookingarea/CookingArea.kt +++ b/tests/src/main/java/com/github/klee0kai/test/house/kitchen/cookingarea/CookingArea.kt @@ -1,9 +1,7 @@ -package com.github.klee0kai.test.house.kitchen.cookingarea; +package com.github.klee0kai.test.house.kitchen.cookingarea -import java.util.UUID; - -public class CookingArea { - - public UUID uuid = UUID.randomUUID(); +import java.util.* +class CookingArea { + var uuid: UUID = UUID.randomUUID() } diff --git a/tests/src/main/java/com/github/klee0kai/test/house/kitchen/sinkarea/SinkArea.kt b/tests/src/main/java/com/github/klee0kai/test/house/kitchen/sinkarea/SinkArea.kt index c4082cd7..9164d82c 100644 --- a/tests/src/main/java/com/github/klee0kai/test/house/kitchen/sinkarea/SinkArea.kt +++ b/tests/src/main/java/com/github/klee0kai/test/house/kitchen/sinkarea/SinkArea.kt @@ -1,9 +1,7 @@ -package com.github.klee0kai.test.house.kitchen.sinkarea; +package com.github.klee0kai.test.house.kitchen.sinkarea -import java.util.UUID; - -public class SinkArea { - - public UUID uuid = UUID.randomUUID(); +import java.util.* +class SinkArea { + var uuid: UUID = UUID.randomUUID() } diff --git a/tests/src/main/java/com/github/klee0kai/test/house/kitchen/storagearea/Clothes.kt b/tests/src/main/java/com/github/klee0kai/test/house/kitchen/storagearea/Clothes.kt index a58f5d02..42b4f571 100644 --- a/tests/src/main/java/com/github/klee0kai/test/house/kitchen/storagearea/Clothes.kt +++ b/tests/src/main/java/com/github/klee0kai/test/house/kitchen/storagearea/Clothes.kt @@ -1,9 +1,7 @@ -package com.github.klee0kai.test.house.kitchen.storagearea; +package com.github.klee0kai.test.house.kitchen.storagearea -import java.util.UUID; - -public class Clothes { - - public UUID uuid = UUID.randomUUID(); +import java.util.* +class Clothes { + var uuid: UUID = UUID.randomUUID() } diff --git a/tests/src/main/java/com/github/klee0kai/test/house/kitchen/storagearea/Cookware.kt b/tests/src/main/java/com/github/klee0kai/test/house/kitchen/storagearea/Cookware.kt index 11236c1e..78c5fc8a 100644 --- a/tests/src/main/java/com/github/klee0kai/test/house/kitchen/storagearea/Cookware.kt +++ b/tests/src/main/java/com/github/klee0kai/test/house/kitchen/storagearea/Cookware.kt @@ -1,9 +1,7 @@ -package com.github.klee0kai.test.house.kitchen.storagearea; +package com.github.klee0kai.test.house.kitchen.storagearea -import java.util.UUID; - -public class Cookware { - - public UUID uuid = UUID.randomUUID(); +import java.util.* +class Cookware { + var uuid: UUID = UUID.randomUUID() } diff --git a/tests/src/main/java/com/github/klee0kai/test/house/kitchen/storagearea/GarageStore.kt b/tests/src/main/java/com/github/klee0kai/test/house/kitchen/storagearea/GarageStore.kt index 6ae93877..dc62174c 100644 --- a/tests/src/main/java/com/github/klee0kai/test/house/kitchen/storagearea/GarageStore.kt +++ b/tests/src/main/java/com/github/klee0kai/test/house/kitchen/storagearea/GarageStore.kt @@ -1,15 +1,3 @@ -package com.github.klee0kai.test.house.kitchen.storagearea; +package com.github.klee0kai.test.house.kitchen.storagearea -public class GarageStore { - - public final Cookware cookware; - public final Clothes clothes; - public final Sanitizers sanitizers; - - public GarageStore(Cookware cookware, Clothes clothes, Sanitizers sanitizers) { - this.cookware = cookware; - this.clothes = clothes; - this.sanitizers = sanitizers; - } - -} +class GarageStore(val cookware: Cookware?, val clothes: Clothes?, val sanitizers: Sanitizers?) diff --git a/tests/src/main/java/com/github/klee0kai/test/house/kitchen/storagearea/Sanitizers.kt b/tests/src/main/java/com/github/klee0kai/test/house/kitchen/storagearea/Sanitizers.kt index 608afec9..781e353e 100644 --- a/tests/src/main/java/com/github/klee0kai/test/house/kitchen/storagearea/Sanitizers.kt +++ b/tests/src/main/java/com/github/klee0kai/test/house/kitchen/storagearea/Sanitizers.kt @@ -1,15 +1,16 @@ -package com.github.klee0kai.test.house.kitchen.storagearea; +package com.github.klee0kai.test.house.kitchen.storagearea -import java.util.UUID; +import java.util.* -public class Sanitizers { +class Sanitizers { + @JvmField + var uuid: UUID = UUID.randomUUID() - public static int createCount = 0; - - public UUID uuid = UUID.randomUUID(); - - public Sanitizers() { - createCount++; + init { + createCount++ } + companion object { + var createCount: Int = 0 + } } diff --git a/tests/src/main/java/com/github/klee0kai/test/house/kitchen/storagearea/StoreArea.kt b/tests/src/main/java/com/github/klee0kai/test/house/kitchen/storagearea/StoreArea.kt index 56c66e37..daf8eb43 100644 --- a/tests/src/main/java/com/github/klee0kai/test/house/kitchen/storagearea/StoreArea.kt +++ b/tests/src/main/java/com/github/klee0kai/test/house/kitchen/storagearea/StoreArea.kt @@ -1,19 +1,5 @@ -package com.github.klee0kai.test.house.kitchen.storagearea; +package com.github.klee0kai.test.house.kitchen.storagearea -import com.github.klee0kai.test.house.identifiers.StoreAreaType; +import com.github.klee0kai.test.house.identifiers.StoreAreaType -public class StoreArea { - - public final StoreAreaType type; - public final Cookware cookware; - public final Clothes clothes; - public final Sanitizers sanitizers; - - - public StoreArea(StoreAreaType type,Cookware cookware, Clothes clothes, Sanitizers sanitizers) { - this.type = type; - this.cookware = cookware; - this.clothes = clothes; - this.sanitizers = sanitizers; - } -} +class StoreArea(@JvmField val type: StoreAreaType?, val cookware: Cookware?, val clothes: Clothes?, @JvmField val sanitizers: Sanitizers?) diff --git a/tests/src/main/java/com/github/klee0kai/test/house/rooms/BathRoom.kt b/tests/src/main/java/com/github/klee0kai/test/house/rooms/BathRoom.kt index f760d1b9..c2559434 100644 --- a/tests/src/main/java/com/github/klee0kai/test/house/rooms/BathRoom.kt +++ b/tests/src/main/java/com/github/klee0kai/test/house/rooms/BathRoom.kt @@ -1,17 +1,8 @@ -package com.github.klee0kai.test.house.rooms; +package com.github.klee0kai.test.house.rooms -import com.github.klee0kai.test.house.kitchen.storagearea.StoreArea; +import com.github.klee0kai.test.house.kitchen.storagearea.StoreArea +import java.util.* -import java.util.UUID; - -public class BathRoom { - - public UUID uuid = UUID.randomUUID(); - - public final StoreArea storeArea; - - - public BathRoom(StoreArea storeArea) { - this.storeArea = storeArea; - } +class BathRoom(@JvmField val storeArea: StoreArea?) { + var uuid: UUID = UUID.randomUUID() } diff --git a/tests/src/main/java/com/github/klee0kai/test/house/rooms/BedRoom.kt b/tests/src/main/java/com/github/klee0kai/test/house/rooms/BedRoom.kt index 32f9c81b..f3f8ab38 100644 --- a/tests/src/main/java/com/github/klee0kai/test/house/rooms/BedRoom.kt +++ b/tests/src/main/java/com/github/klee0kai/test/house/rooms/BedRoom.kt @@ -1,17 +1,8 @@ -package com.github.klee0kai.test.house.rooms; +package com.github.klee0kai.test.house.rooms -import com.github.klee0kai.test.house.kitchen.storagearea.StoreArea; +import com.github.klee0kai.test.house.kitchen.storagearea.StoreArea +import java.util.* -import java.util.UUID; - -public class BedRoom { - - public UUID uuid = UUID.randomUUID(); - - public final StoreArea storeArea; - - - public BedRoom(StoreArea storeArea) { - this.storeArea = storeArea; - } +class BedRoom(@JvmField val storeArea: StoreArea?) { + var uuid: UUID = UUID.randomUUID() } diff --git a/tests/src/main/java/com/github/klee0kai/test/house/rooms/Garage.kt b/tests/src/main/java/com/github/klee0kai/test/house/rooms/Garage.kt index 84ab5d71..c85ee05c 100644 --- a/tests/src/main/java/com/github/klee0kai/test/house/rooms/Garage.kt +++ b/tests/src/main/java/com/github/klee0kai/test/house/rooms/Garage.kt @@ -1,17 +1,8 @@ -package com.github.klee0kai.test.house.rooms; +package com.github.klee0kai.test.house.rooms -import com.github.klee0kai.test.house.kitchen.storagearea.GarageStore; +import com.github.klee0kai.test.house.kitchen.storagearea.GarageStore +import java.util.* -import java.util.UUID; - -public class Garage { - - public UUID uuid = UUID.randomUUID(); - - public final GarageStore garageStore; - - - public Garage(GarageStore garageStore) { - this.garageStore = garageStore; - } +class Garage(val garageStore: GarageStore?) { + var uuid: UUID = UUID.randomUUID() } diff --git a/tests/src/main/java/com/github/klee0kai/test/mowgli/MoonSky.kt b/tests/src/main/java/com/github/klee0kai/test/mowgli/MoonSky.kt index ae304044..3216be01 100644 --- a/tests/src/main/java/com/github/klee0kai/test/mowgli/MoonSky.kt +++ b/tests/src/main/java/com/github/klee0kai/test/mowgli/MoonSky.kt @@ -1,26 +1,27 @@ -package com.github.klee0kai.test.mowgli; +package com.github.klee0kai.test.mowgli -import com.github.klee0kai.test.mowgli.galaxy.*; - -import javax.inject.Inject; - -public class MoonSky { +import com.github.klee0kai.test.mowgli.galaxy.* +import javax.inject.Inject +class MoonSky { + @JvmField @Inject - public IStar star; + var star: IStar? = null + @JvmField @Inject - public Sun sun; + var sun: Sun? = null + @JvmField @Inject - public IPlanet planet; + var planet: IPlanet? = null + @JvmField @Inject - public Mercury mercury; + var mercury: Mercury? = null + @JvmField @Inject - public Earth earth; - - + var earth: Earth? = null } diff --git a/tests/src/main/java/com/github/klee0kai/test/mowgli/School.kt b/tests/src/main/java/com/github/klee0kai/test/mowgli/School.kt index 3d1ef96a..2bfbfa97 100644 --- a/tests/src/main/java/com/github/klee0kai/test/mowgli/School.kt +++ b/tests/src/main/java/com/github/klee0kai/test/mowgli/School.kt @@ -1,27 +1,27 @@ -package com.github.klee0kai.test.mowgli; - -import com.github.klee0kai.stone.wrappers.LazyProvide; -import com.github.klee0kai.stone.wrappers.PhantomProvide; -import com.github.klee0kai.stone.wrappers.Ref; -import com.github.klee0kai.test.mowgli.community.History; -import com.github.klee0kai.test.mowgli.identity.Knowledge; - -import javax.inject.Inject; -import javax.inject.Provider; - -public class School { - +package com.github.klee0kai.test.mowgli + +import com.github.klee0kai.stone.weakref.Ref +import com.github.klee0kai.stone.wrappers.LazyProvide +import com.github.klee0kai.stone.wrappers.PhantomProvide +import com.github.klee0kai.test.mowgli.community.History +import com.github.klee0kai.test.mowgli.identity.Knowledge +import javax.inject.Inject +import javax.inject.Provider + +class School { + @JvmField @Inject - public LazyProvide historyLazyProvide; + var historyLazyProvide: LazyProvide? = null + @JvmField @Inject - public Ref knowledgePhantomProvide2; + var knowledgePhantomProvide2: Ref? = null + @JvmField @Inject - public Provider knowledgePhantomProvide3; + var knowledgePhantomProvide3: Provider? = null + @JvmField @Inject - public PhantomProvide knowledgePhantomProvide; - - + var knowledgePhantomProvide: PhantomProvide? = null } diff --git a/tests/src/main/java/com/github/klee0kai/test/mowgli/animal/Horse.kt b/tests/src/main/java/com/github/klee0kai/test/mowgli/animal/Horse.kt index 984d1a39..db1e006a 100644 --- a/tests/src/main/java/com/github/klee0kai/test/mowgli/animal/Horse.kt +++ b/tests/src/main/java/com/github/klee0kai/test/mowgli/animal/Horse.kt @@ -1,37 +1,47 @@ -package com.github.klee0kai.test.mowgli.animal; - -import com.github.klee0kai.test.mowgli.body.Blood; -import com.github.klee0kai.test.mowgli.community.History; -import com.github.klee0kai.test.mowgli.galaxy.Earth; -import com.github.klee0kai.test.mowgli.identity.Conscience; -import com.github.klee0kai.test.mowgli.identity.Ideology; -import com.github.klee0kai.test.mowgli.identity.Knowledge; - -import javax.inject.Inject; - -public class Horse implements IAnimal { - +package com.github.klee0kai.test.mowgli.animal + +import com.github.klee0kai.test.mowgli.body.Blood +import com.github.klee0kai.test.mowgli.community.History +import com.github.klee0kai.test.mowgli.galaxy.Earth +import com.github.klee0kai.test.mowgli.identity.Conscience +import com.github.klee0kai.test.mowgli.identity.Ideology +import com.github.klee0kai.test.mowgli.identity.Knowledge +import javax.inject.Inject + +open class Horse : IAnimal { + @JvmField @Inject - public Blood blood; + var blood: Blood? = null + + @JvmField @Inject - public Earth earth; + var earth: Earth? = null + + @JvmField @Inject - public History history; + var history: History? = null + + @JvmField @Inject - public Conscience conscience; + var conscience: Conscience? = null + + @JvmField @Inject - public Knowledge knowledge; + var knowledge: Knowledge? = null + + @JvmField @Inject - public Ideology ideology; + var ideology: Ideology? = null - public Conscience methodInjectedConscience; - public Knowledge methodInjectedKnowledge; + @JvmField + var methodInjectedConscience: Conscience? = null + @JvmField + var methodInjectedKnowledge: Knowledge? = null @Inject - public void initInject(Conscience conscience, Knowledge knowledge) { - methodInjectedConscience = conscience; - methodInjectedKnowledge = knowledge; + fun initInject(conscience: Conscience?, knowledge: Knowledge?) { + methodInjectedConscience = conscience + methodInjectedKnowledge = knowledge } - } diff --git a/tests/src/main/java/com/github/klee0kai/test/mowgli/animal/IAnimal.kt b/tests/src/main/java/com/github/klee0kai/test/mowgli/animal/IAnimal.kt index 92bc4fe1..77ef45ee 100644 --- a/tests/src/main/java/com/github/klee0kai/test/mowgli/animal/IAnimal.kt +++ b/tests/src/main/java/com/github/klee0kai/test/mowgli/animal/IAnimal.kt @@ -1,6 +1,3 @@ -package com.github.klee0kai.test.mowgli.animal; +package com.github.klee0kai.test.mowgli.animal -public interface IAnimal { - - -} +interface IAnimal diff --git a/tests/src/main/java/com/github/klee0kai/test/mowgli/animal/Mowgli.kt b/tests/src/main/java/com/github/klee0kai/test/mowgli/animal/Mowgli.kt index fc4f06e6..da2d4a7d 100644 --- a/tests/src/main/java/com/github/klee0kai/test/mowgli/animal/Mowgli.kt +++ b/tests/src/main/java/com/github/klee0kai/test/mowgli/animal/Mowgli.kt @@ -1,82 +1,95 @@ -package com.github.klee0kai.test.mowgli.animal; - -import com.github.klee0kai.stone.wrappers.LazyProvide; -import com.github.klee0kai.stone.wrappers.PhantomProvide; -import com.github.klee0kai.stone.wrappers.Ref; -import com.github.klee0kai.test.mowgli.body.Blood; -import com.github.klee0kai.test.mowgli.community.History; -import com.github.klee0kai.test.mowgli.galaxy.Earth; -import com.github.klee0kai.test.mowgli.identity.Conscience; -import com.github.klee0kai.test.mowgli.identity.Knowledge; - -import javax.inject.Inject; -import javax.inject.Provider; -import java.lang.ref.SoftReference; -import java.lang.ref.WeakReference; - -public class Mowgli implements IAnimal { +package com.github.klee0kai.test.mowgli.animal + +import com.github.klee0kai.stone.weakref.Ref +import com.github.klee0kai.stone.wrappers.LazyProvide +import com.github.klee0kai.stone.wrappers.PhantomProvide +import com.github.klee0kai.test.mowgli.body.Blood +import com.github.klee0kai.test.mowgli.community.History +import com.github.klee0kai.test.mowgli.galaxy.Earth +import com.github.klee0kai.test.mowgli.identity.Conscience +import com.github.klee0kai.test.mowgli.identity.Knowledge +import java.lang.ref.SoftReference +import java.lang.ref.WeakReference +import javax.inject.Inject +import javax.inject.Provider + +class Mowgli : IAnimal { @Inject - public Blood blood; + var blood: Blood? = null + @Inject - public Earth earth; + var earth: Earth? = null + @Inject - public History history; + var history: History? = null + @Inject - public Conscience conscience; + var conscience: Conscience? = null + + @JvmField @Inject - public Knowledge knowledge; + var knowledge: Knowledge? = null + @JvmField @Inject - public WeakReference knowledgeWeakRef; + var knowledgeWeakRef: WeakReference? = null + @JvmField @Inject - public SoftReference knowledgeSoftRef; + var knowledgeSoftRef: SoftReference? = null + @JvmField @Inject - public LazyProvide knowledgeLazyProvide; + var knowledgeLazyProvide: LazyProvide? = null + @JvmField @Inject - public Ref knowledgePhantomProvide2; + var knowledgePhantomProvide2: Ref? = null @Inject - public Provider knowledgePhantomProvide3; + var knowledgePhantomProvide3: Provider? = null + @JvmField @Inject - public PhantomProvide knowledgePhantomProvide; + var knowledgePhantomProvide: PhantomProvide? = null - public WeakReference methodKnowledgeWeakRef; + @JvmField + var methodKnowledgeWeakRef: WeakReference? = null - public SoftReference methodKnowledgeSoftRef; + @JvmField + var methodKnowledgeSoftRef: SoftReference? = null - public LazyProvide methodKnowledgeLazyProvide; + @JvmField + var methodKnowledgeLazyProvide: LazyProvide? = null - public Ref methodKnowledgePhantomProvide2; + @JvmField + var methodKnowledgePhantomProvide2: Ref? = null - public Provider methodKnowledgePhantomProvide3; + @JvmField + var methodKnowledgePhantomProvide3: Provider? = null - public PhantomProvide methodKnowledgePhantomProvide; + @JvmField + var methodKnowledgePhantomProvide: PhantomProvide? = null @Inject - public void refInject(WeakReference knowledgeWeakRef, SoftReference knowledgeSoftRef) { - methodKnowledgeWeakRef = knowledgeWeakRef; - methodKnowledgeSoftRef = knowledgeSoftRef; + fun refInject(knowledgeWeakRef: WeakReference?, knowledgeSoftRef: SoftReference?) { + methodKnowledgeWeakRef = knowledgeWeakRef + methodKnowledgeSoftRef = knowledgeSoftRef } @Inject - public void wrapperInject( - LazyProvide knowledgeLazyProvide, - Ref knowledgePhantomProvide2, - Provider knowledgePhantomProvide3, - PhantomProvide knowledgePhantomProvide + fun wrapperInject( + knowledgeLazyProvide: LazyProvide?, + knowledgePhantomProvide2: Ref?, + knowledgePhantomProvide3: Provider?, + knowledgePhantomProvide: PhantomProvide? ) { - methodKnowledgeLazyProvide = knowledgeLazyProvide; - methodKnowledgePhantomProvide2 = knowledgePhantomProvide2; - methodKnowledgePhantomProvide3 = knowledgePhantomProvide3; - methodKnowledgePhantomProvide = knowledgePhantomProvide; + methodKnowledgeLazyProvide = knowledgeLazyProvide + methodKnowledgePhantomProvide2 = knowledgePhantomProvide2 + methodKnowledgePhantomProvide3 = knowledgePhantomProvide3 + methodKnowledgePhantomProvide = knowledgePhantomProvide } - - } diff --git a/tests/src/main/java/com/github/klee0kai/test/mowgli/animal/Snake.kt b/tests/src/main/java/com/github/klee0kai/test/mowgli/animal/Snake.kt index 513fa258..f7464613 100644 --- a/tests/src/main/java/com/github/klee0kai/test/mowgli/animal/Snake.kt +++ b/tests/src/main/java/com/github/klee0kai/test/mowgli/animal/Snake.kt @@ -1,24 +1,30 @@ -package com.github.klee0kai.test.mowgli.animal; +package com.github.klee0kai.test.mowgli.animal -import com.github.klee0kai.test.mowgli.body.Blood; -import com.github.klee0kai.test.mowgli.community.History; -import com.github.klee0kai.test.mowgli.galaxy.Earth; -import com.github.klee0kai.test.mowgli.identity.Conscience; -import com.github.klee0kai.test.mowgli.identity.Knowledge; - -import javax.inject.Inject; - -public class Snake implements IAnimal { +import com.github.klee0kai.test.mowgli.body.Blood +import com.github.klee0kai.test.mowgli.community.History +import com.github.klee0kai.test.mowgli.galaxy.Earth +import com.github.klee0kai.test.mowgli.identity.Conscience +import com.github.klee0kai.test.mowgli.identity.Knowledge +import javax.inject.Inject +class Snake : IAnimal { + @JvmField @Inject - public Blood blood; - @Inject - public Earth earth; + var blood: Blood? = null + + @JvmField @Inject - public History history; + var earth: Earth? = null + + @JvmField @Inject - public Conscience conscience; + var history: History? = null + + @JvmField @Inject - public Knowledge knowledge; + var conscience: Conscience? = null + @JvmField + @Inject + var knowledge: Knowledge? = null } diff --git a/tests/src/main/java/com/github/klee0kai/test/mowgli/body/Blood.kt b/tests/src/main/java/com/github/klee0kai/test/mowgli/body/Blood.kt index 3f454145..6a2c11e5 100644 --- a/tests/src/main/java/com/github/klee0kai/test/mowgli/body/Blood.kt +++ b/tests/src/main/java/com/github/klee0kai/test/mowgli/body/Blood.kt @@ -1,15 +1,15 @@ -package com.github.klee0kai.test.mowgli.body; +package com.github.klee0kai.test.mowgli.body -import java.awt.*; -import java.util.UUID; +import java.awt.Color +import java.util.* -public class Blood { +class Blood(color: Color?) { - public UUID uuid = UUID.randomUUID(); + var uuid: UUID = UUID.randomUUID() - public Color color = null; + var color: Color? = null - public Blood(Color color) { - this.color = color; + init { + this.color = color } } diff --git a/tests/src/main/java/com/github/klee0kai/test/mowgli/community/History.kt b/tests/src/main/java/com/github/klee0kai/test/mowgli/community/History.kt index 42632864..91cbd250 100644 --- a/tests/src/main/java/com/github/klee0kai/test/mowgli/community/History.kt +++ b/tests/src/main/java/com/github/klee0kai/test/mowgli/community/History.kt @@ -1,10 +1,7 @@ -package com.github.klee0kai.test.mowgli.community; - -import java.util.UUID; - -public class History { - - public UUID uuid = UUID.randomUUID(); +package com.github.klee0kai.test.mowgli.community +import java.util.* +class History { + var uuid: UUID = UUID.randomUUID() } diff --git a/tests/src/main/java/com/github/klee0kai/test/mowgli/earth/Cave.kt b/tests/src/main/java/com/github/klee0kai/test/mowgli/earth/Cave.kt index 499b30f5..10b51378 100644 --- a/tests/src/main/java/com/github/klee0kai/test/mowgli/earth/Cave.kt +++ b/tests/src/main/java/com/github/klee0kai/test/mowgli/earth/Cave.kt @@ -1,22 +1,15 @@ -package com.github.klee0kai.test.mowgli.earth; +package com.github.klee0kai.test.mowgli.earth -import java.util.UUID; +import java.util.* +class Cave : IMountain { + var uuid: UUID = UUID.randomUUID() -public class Cave implements IMountain { + constructor() - public UUID uuid = UUID.randomUUID(); + constructor(type: CaveType?, deep: Int?) - public Cave() { - //nothing - } - - public Cave(CaveType type, Integer deep) { - //nothing - } - - public enum CaveType { + enum class CaveType { Solutional, Glacier, Fracture } - } diff --git a/tests/src/main/java/com/github/klee0kai/test/mowgli/earth/IMountain.kt b/tests/src/main/java/com/github/klee0kai/test/mowgli/earth/IMountain.kt index 910219eb..48c5dd37 100644 --- a/tests/src/main/java/com/github/klee0kai/test/mowgli/earth/IMountain.kt +++ b/tests/src/main/java/com/github/klee0kai/test/mowgli/earth/IMountain.kt @@ -1,4 +1,3 @@ -package com.github.klee0kai.test.mowgli.earth; +package com.github.klee0kai.test.mowgli.earth -public interface IMountain { -} +interface IMountain diff --git a/tests/src/main/java/com/github/klee0kai/test/mowgli/earth/IRiver.kt b/tests/src/main/java/com/github/klee0kai/test/mowgli/earth/IRiver.kt index 85f2e91f..4eee30db 100644 --- a/tests/src/main/java/com/github/klee0kai/test/mowgli/earth/IRiver.kt +++ b/tests/src/main/java/com/github/klee0kai/test/mowgli/earth/IRiver.kt @@ -1,4 +1,3 @@ -package com.github.klee0kai.test.mowgli.earth; +package com.github.klee0kai.test.mowgli.earth -public interface IRiver { -} +interface IRiver diff --git a/tests/src/main/java/com/github/klee0kai/test/mowgli/earth/Mountain.kt b/tests/src/main/java/com/github/klee0kai/test/mowgli/earth/Mountain.kt index b45d4c8d..caac4544 100644 --- a/tests/src/main/java/com/github/klee0kai/test/mowgli/earth/Mountain.kt +++ b/tests/src/main/java/com/github/klee0kai/test/mowgli/earth/Mountain.kt @@ -1,9 +1,8 @@ -package com.github.klee0kai.test.mowgli.earth; +package com.github.klee0kai.test.mowgli.earth -import java.util.UUID; - -public class Mountain implements IMountain{ - - public UUID uuid = UUID.randomUUID(); +import java.util.* +class Mountain : IMountain { + @JvmField + var uuid: UUID = UUID.randomUUID() } diff --git a/tests/src/main/java/com/github/klee0kai/test/mowgli/earth/River.kt b/tests/src/main/java/com/github/klee0kai/test/mowgli/earth/River.kt index 669e7d21..12f823da 100644 --- a/tests/src/main/java/com/github/klee0kai/test/mowgli/earth/River.kt +++ b/tests/src/main/java/com/github/klee0kai/test/mowgli/earth/River.kt @@ -1,9 +1,7 @@ -package com.github.klee0kai.test.mowgli.earth; +package com.github.klee0kai.test.mowgli.earth -import java.util.UUID; - -public class River implements IRiver { - - public UUID uuid = UUID.randomUUID(); +import java.util.* +open class River : IRiver { + var uuid: UUID = UUID.randomUUID() } diff --git a/tests/src/main/java/com/github/klee0kai/test/mowgli/galaxy/Earth.kt b/tests/src/main/java/com/github/klee0kai/test/mowgli/galaxy/Earth.kt index 76354546..67e485a5 100644 --- a/tests/src/main/java/com/github/klee0kai/test/mowgli/galaxy/Earth.kt +++ b/tests/src/main/java/com/github/klee0kai/test/mowgli/galaxy/Earth.kt @@ -1,10 +1,8 @@ -package com.github.klee0kai.test.mowgli.galaxy; - -import java.util.UUID; - -public class Earth implements IPlanet { - - public UUID uuid = UUID.randomUUID(); +package com.github.klee0kai.test.mowgli.galaxy +import java.util.* +class Earth : IPlanet { + @JvmField + var uuid: UUID = UUID.randomUUID() } diff --git a/tests/src/main/java/com/github/klee0kai/test/mowgli/galaxy/IPlanet.kt b/tests/src/main/java/com/github/klee0kai/test/mowgli/galaxy/IPlanet.kt index 8bc6fa39..2b78c169 100644 --- a/tests/src/main/java/com/github/klee0kai/test/mowgli/galaxy/IPlanet.kt +++ b/tests/src/main/java/com/github/klee0kai/test/mowgli/galaxy/IPlanet.kt @@ -1,4 +1,3 @@ -package com.github.klee0kai.test.mowgli.galaxy; +package com.github.klee0kai.test.mowgli.galaxy -public interface IPlanet { -} +interface IPlanet diff --git a/tests/src/main/java/com/github/klee0kai/test/mowgli/galaxy/IStar.kt b/tests/src/main/java/com/github/klee0kai/test/mowgli/galaxy/IStar.kt index 6839e573..17d6230d 100644 --- a/tests/src/main/java/com/github/klee0kai/test/mowgli/galaxy/IStar.kt +++ b/tests/src/main/java/com/github/klee0kai/test/mowgli/galaxy/IStar.kt @@ -1,4 +1,3 @@ -package com.github.klee0kai.test.mowgli.galaxy; +package com.github.klee0kai.test.mowgli.galaxy -public interface IStar { -} +interface IStar diff --git a/tests/src/main/java/com/github/klee0kai/test/mowgli/galaxy/Mercury.kt b/tests/src/main/java/com/github/klee0kai/test/mowgli/galaxy/Mercury.kt index 6cfe9e46..6785f9ea 100644 --- a/tests/src/main/java/com/github/klee0kai/test/mowgli/galaxy/Mercury.kt +++ b/tests/src/main/java/com/github/klee0kai/test/mowgli/galaxy/Mercury.kt @@ -1,10 +1,7 @@ -package com.github.klee0kai.test.mowgli.galaxy; - -import java.util.UUID; - -public class Mercury implements IPlanet { - - public UUID uuid = UUID.randomUUID(); +package com.github.klee0kai.test.mowgli.galaxy +import java.util.* +class Mercury : IPlanet { + var uuid: UUID = UUID.randomUUID() } diff --git a/tests/src/main/java/com/github/klee0kai/test/mowgli/galaxy/Saturn.kt b/tests/src/main/java/com/github/klee0kai/test/mowgli/galaxy/Saturn.kt index c9577da5..50035452 100644 --- a/tests/src/main/java/com/github/klee0kai/test/mowgli/galaxy/Saturn.kt +++ b/tests/src/main/java/com/github/klee0kai/test/mowgli/galaxy/Saturn.kt @@ -1,10 +1,8 @@ -package com.github.klee0kai.test.mowgli.galaxy; - -import java.util.UUID; - -public class Saturn implements IPlanet { - - public UUID uuid = UUID.randomUUID(); +package com.github.klee0kai.test.mowgli.galaxy +import java.util.* +class Saturn : IPlanet { + @JvmField + var uuid: UUID = UUID.randomUUID() } diff --git a/tests/src/main/java/com/github/klee0kai/test/mowgli/galaxy/SolarSystem.kt b/tests/src/main/java/com/github/klee0kai/test/mowgli/galaxy/SolarSystem.kt index acbe21a6..2150cf1f 100644 --- a/tests/src/main/java/com/github/klee0kai/test/mowgli/galaxy/SolarSystem.kt +++ b/tests/src/main/java/com/github/klee0kai/test/mowgli/galaxy/SolarSystem.kt @@ -1,12 +1,7 @@ -package com.github.klee0kai.test.mowgli.galaxy; +package com.github.klee0kai.test.mowgli.galaxy -public class SolarSystem { +class SolarSystem { + constructor() - - public SolarSystem() { - } - - public SolarSystem(Sun sun, Earth earth) { - - } + constructor(sun: Sun?, earth: Earth?) } diff --git a/tests/src/main/java/com/github/klee0kai/test/mowgli/galaxy/Sun.kt b/tests/src/main/java/com/github/klee0kai/test/mowgli/galaxy/Sun.kt index eda821ed..f5812947 100644 --- a/tests/src/main/java/com/github/klee0kai/test/mowgli/galaxy/Sun.kt +++ b/tests/src/main/java/com/github/klee0kai/test/mowgli/galaxy/Sun.kt @@ -1,9 +1,8 @@ -package com.github.klee0kai.test.mowgli.galaxy; +package com.github.klee0kai.test.mowgli.galaxy -import java.util.UUID; - -public class Sun implements IStar{ - - public UUID uuid = UUID.randomUUID(); +import java.util.* +class Sun : IStar { + @JvmField + var uuid: UUID = UUID.randomUUID() } diff --git a/tests/src/main/java/com/github/klee0kai/test/mowgli/identity/Conscience.kt b/tests/src/main/java/com/github/klee0kai/test/mowgli/identity/Conscience.kt index 8dd6401e..9a4c9a02 100644 --- a/tests/src/main/java/com/github/klee0kai/test/mowgli/identity/Conscience.kt +++ b/tests/src/main/java/com/github/klee0kai/test/mowgli/identity/Conscience.kt @@ -1,14 +1,11 @@ -package com.github.klee0kai.test.mowgli.identity; +package com.github.klee0kai.test.mowgli.identity -import java.util.UUID; - -public class Conscience { - - public UUID uuid = UUID.randomUUID(); - - public boolean isOldConscience() { - return false; - } +import java.util.* +class Conscience { + @JvmField + var uuid: UUID = UUID.randomUUID() + val isOldConscience: Boolean + get() = false } diff --git a/tests/src/main/java/com/github/klee0kai/test/mowgli/identity/Ideology.kt b/tests/src/main/java/com/github/klee0kai/test/mowgli/identity/Ideology.kt index a9d9370d..435a7825 100644 --- a/tests/src/main/java/com/github/klee0kai/test/mowgli/identity/Ideology.kt +++ b/tests/src/main/java/com/github/klee0kai/test/mowgli/identity/Ideology.kt @@ -1,14 +1,11 @@ -package com.github.klee0kai.test.mowgli.identity; +package com.github.klee0kai.test.mowgli.identity -import java.util.UUID; +import java.util.* -public class Ideology { +open class Ideology { + var uuid: UUID = UUID.randomUUID() - public UUID uuid = UUID.randomUUID(); - - - public boolean isFamilyIdeology(){ - return false; - } + open val isFamilyIdeology: Boolean + get() = false } diff --git a/tests/src/main/java/com/github/klee0kai/test/mowgli/identity/Knowledge.kt b/tests/src/main/java/com/github/klee0kai/test/mowgli/identity/Knowledge.kt index 2501ac1a..e8ff29df 100644 --- a/tests/src/main/java/com/github/klee0kai/test/mowgli/identity/Knowledge.kt +++ b/tests/src/main/java/com/github/klee0kai/test/mowgli/identity/Knowledge.kt @@ -1,14 +1,12 @@ -package com.github.klee0kai.test.mowgli.identity; +package com.github.klee0kai.test.mowgli.identity -import java.util.UUID; +import java.util.* -public class Knowledge { +open class Knowledge { + @JvmField + var uuid: UUID = UUID.randomUUID() - public UUID uuid = UUID.randomUUID(); - - - public boolean isOldKnowledge(){ - return false; - } + open val isOldKnowledge: Boolean + get() = false } diff --git a/tests/src/main/java/com/github/klee0kai/test/tech/components/Battery.kt b/tests/src/main/java/com/github/klee0kai/test/tech/components/Battery.kt index c06f839a..66a5a6ac 100644 --- a/tests/src/main/java/com/github/klee0kai/test/tech/components/Battery.kt +++ b/tests/src/main/java/com/github/klee0kai/test/tech/components/Battery.kt @@ -1,9 +1,8 @@ -package com.github.klee0kai.test.tech.components; +package com.github.klee0kai.test.tech.components -import java.util.UUID; - -public class Battery { - - public final UUID uuid = UUID.randomUUID(); +import java.util.* +class Battery { + @JvmField + val uuid: UUID = UUID.randomUUID() } diff --git a/tests/src/main/java/com/github/klee0kai/test/tech/components/DataStorage.kt b/tests/src/main/java/com/github/klee0kai/test/tech/components/DataStorage.kt index 632491a4..f5f64a94 100644 --- a/tests/src/main/java/com/github/klee0kai/test/tech/components/DataStorage.kt +++ b/tests/src/main/java/com/github/klee0kai/test/tech/components/DataStorage.kt @@ -1,21 +1,20 @@ -package com.github.klee0kai.test.tech.components; +package com.github.klee0kai.test.tech.components -import com.github.klee0kai.test.di.base_phone.identifiers.DataStorageSize; +import com.github.klee0kai.test.di.base_phone.identifiers.DataStorageSize +import java.util.* -import java.util.UUID; +class DataStorage { + @JvmField + val uuid: UUID = UUID.randomUUID() -public class DataStorage { + @JvmField + val size: String? - public final UUID uuid = UUID.randomUUID(); - - public final String size; - - public DataStorage() { - size = null; + constructor() { + size = null } - public DataStorage(DataStorageSize size) { - this.size = size.size; + constructor(size: DataStorageSize) { + this.size = size.size } - } diff --git a/tests/src/main/java/com/github/klee0kai/test/tech/components/OperationSystem.kt b/tests/src/main/java/com/github/klee0kai/test/tech/components/OperationSystem.kt index 7bd8ce88..a09d3fc2 100644 --- a/tests/src/main/java/com/github/klee0kai/test/tech/components/OperationSystem.kt +++ b/tests/src/main/java/com/github/klee0kai/test/tech/components/OperationSystem.kt @@ -1,24 +1,25 @@ -package com.github.klee0kai.test.tech.components; +package com.github.klee0kai.test.tech.components -import com.github.klee0kai.test.di.base_phone.identifiers.PhoneOsType; -import com.github.klee0kai.test.di.base_phone.identifiers.PhoneOsVersion; +import com.github.klee0kai.test.di.base_phone.identifiers.PhoneOsType +import com.github.klee0kai.test.di.base_phone.identifiers.PhoneOsVersion +import java.util.* -import java.util.UUID; +class OperationSystem { + @JvmField + val uuid: UUID = UUID.randomUUID() + @JvmField + val phoneOsType: PhoneOsType? + @JvmField + val version: PhoneOsVersion? -public class OperationSystem { - public final UUID uuid = UUID.randomUUID(); - public final PhoneOsType phoneOsType; - public final PhoneOsVersion version; - - - public OperationSystem(PhoneOsType phoneOsType) { - this.phoneOsType = phoneOsType; - this.version = new PhoneOsVersion("default"); + constructor(phoneOsType: PhoneOsType?) { + this.phoneOsType = phoneOsType + this.version = PhoneOsVersion("default") } - public OperationSystem(PhoneOsType phoneOsType, PhoneOsVersion version) { - this.phoneOsType = phoneOsType; - this.version = version; + constructor(phoneOsType: PhoneOsType?, version: PhoneOsVersion?) { + this.phoneOsType = phoneOsType + this.version = version } } diff --git a/tests/src/main/java/com/github/klee0kai/test/tech/components/Ram.kt b/tests/src/main/java/com/github/klee0kai/test/tech/components/Ram.kt index 3e6246d1..af9d56ab 100644 --- a/tests/src/main/java/com/github/klee0kai/test/tech/components/Ram.kt +++ b/tests/src/main/java/com/github/klee0kai/test/tech/components/Ram.kt @@ -1,20 +1,20 @@ -package com.github.klee0kai.test.tech.components; +package com.github.klee0kai.test.tech.components -import com.github.klee0kai.test.di.base_phone.identifiers.RamSize; +import com.github.klee0kai.test.di.base_phone.identifiers.RamSize +import java.util.* -import java.util.UUID; +open class Ram { + @JvmField + val uuid: UUID = UUID.randomUUID() -public class Ram { + @JvmField + val size: String? - public final UUID uuid = UUID.randomUUID(); - - public final String size; - - public Ram() { - size = "default"; + constructor() { + size = "default" } - public Ram(RamSize ramSize) { - this.size = ramSize.size; + constructor(ramSize: RamSize) { + this.size = ramSize.size } } diff --git a/tests/src/main/java/com/github/klee0kai/test/tech/phone/GoodPhone.kt b/tests/src/main/java/com/github/klee0kai/test/tech/phone/GoodPhone.kt index 16c07746..727c6bb8 100644 --- a/tests/src/main/java/com/github/klee0kai/test/tech/phone/GoodPhone.kt +++ b/tests/src/main/java/com/github/klee0kai/test/tech/phone/GoodPhone.kt @@ -1,45 +1,47 @@ -package com.github.klee0kai.test.tech.phone; +package com.github.klee0kai.test.tech.phone -import com.github.klee0kai.stone.lifecycle.StoneLifeCycleOwner; -import com.github.klee0kai.test.tech.components.Battery; -import com.github.klee0kai.test.tech.components.DataStorage; -import com.github.klee0kai.test.tech.components.OperationSystem; -import com.github.klee0kai.test.tech.components.Ram; -import com.github.klee0kai.test.tech.phone.base.ATech; -import com.github.klee0kai.test.tech.phone.base.LifecycleUtils; +import com.github.klee0kai.stone.lifecycle.StoneLifeCycleOwner +import com.github.klee0kai.test.tech.components.Battery +import com.github.klee0kai.test.tech.components.DataStorage +import com.github.klee0kai.test.tech.components.OperationSystem +import com.github.klee0kai.test.tech.components.Ram +import com.github.klee0kai.test.tech.phone.base.ATech +import com.github.klee0kai.test.tech.phone.base.LifecycleUtils +import javax.inject.Inject -import javax.inject.Inject; - -public class GoodPhone extends ATech { - - public StoneLifeCycleOwner lifeCycleOwner = LifecycleUtils.createFromATech(this); +class GoodPhone : ATech() { + @JvmField + var lifeCycleOwner: StoneLifeCycleOwner = LifecycleUtils.createFromATech(this) + @JvmField @Inject - public Battery battery; + var battery: Battery? = null + @JvmField @Inject - public DataStorage dataStorage; + var dataStorage: DataStorage? = null + @JvmField @Inject - public Ram ram; + var ram: Ram? = null + @JvmField @Inject - public OperationSystem os; + var os: OperationSystem? = null - public void dropToWater() { - onDrown(); - battery = null; - dataStorage = null; - ram = null; + fun dropToWater() { + onDrown() + battery = null + dataStorage = null + ram = null } - public void broke() { - onBroken(); - battery = null; - dataStorage = null; - ram = null; + fun broke() { + onBroken() + battery = null + dataStorage = null + ram = null } - } diff --git a/tests/src/main/java/com/github/klee0kai/test/tech/phone/OnePhone.kt b/tests/src/main/java/com/github/klee0kai/test/tech/phone/OnePhone.kt index 88fee4bb..0dfb631b 100644 --- a/tests/src/main/java/com/github/klee0kai/test/tech/phone/OnePhone.kt +++ b/tests/src/main/java/com/github/klee0kai/test/tech/phone/OnePhone.kt @@ -1,63 +1,57 @@ -package com.github.klee0kai.test.tech.phone; - -import com.github.klee0kai.stone.lifecycle.StoneLifeCycleListener; -import com.github.klee0kai.stone.lifecycle.StoneLifeCycleOwner; -import com.github.klee0kai.test.tech.components.Battery; -import com.github.klee0kai.test.tech.components.DataStorage; -import com.github.klee0kai.test.tech.components.Ram; -import com.github.klee0kai.test.tech.phone.base.ATech; -import com.github.klee0kai.test.tech.phone.base.ATechLifecycle; - -import javax.inject.Inject; -import javax.inject.Named; - -public class OnePhone extends ATech implements StoneLifeCycleOwner { - +package com.github.klee0kai.test.tech.phone + +import com.github.klee0kai.stone.lifecycle.StoneLifeCycleListener +import com.github.klee0kai.stone.lifecycle.StoneLifeCycleOwner +import com.github.klee0kai.test.tech.components.Battery +import com.github.klee0kai.test.tech.components.DataStorage +import com.github.klee0kai.test.tech.components.Ram +import com.github.klee0kai.test.tech.phone.base.ATech +import com.github.klee0kai.test.tech.phone.base.ATechLifecycle +import javax.inject.Inject +import javax.inject.Named + +class OnePhone : ATech(), StoneLifeCycleOwner { + @JvmField @Inject - public Battery battery; + var battery: Battery? = null + @JvmField @Inject @Named("null_args") - public DataStorage dataStorage; + var dataStorage: DataStorage? = null + @JvmField @Inject @Named("null_args") - public Ram ram; + var ram: Ram? = null - @Override - public void subscribe(StoneLifeCycleListener listener) { - super.subscribe(new ATechLifecycle() { - @Override - public void onBuy() { - + override fun subscribe(listener: StoneLifeCycleListener) { + super.subscribe(object : ATechLifecycle { + override fun onBuy() { } - @Override - public void onBroken() { - + override fun onBroken() { } - @Override - public void onDrown() { - listener.protectForInjected(100); + override fun onDrown() { + listener.protectForInjected(100) } - }); + }) } - public void dropToWatter() { - onDrown(); - battery = null; - dataStorage = null; - ram = null; + fun dropToWatter() { + onDrown() + battery = null + dataStorage = null + ram = null } - public void broke() { - onBroken(); - battery = null; - dataStorage = null; - ram = null; + fun broke() { + onBroken() + battery = null + dataStorage = null + ram = null } - } diff --git a/tests/src/main/java/com/github/klee0kai/test/tech/phone/base/ATech.kt b/tests/src/main/java/com/github/klee0kai/test/tech/phone/base/ATech.kt index 81f12fcf..c27486b7 100644 --- a/tests/src/main/java/com/github/klee0kai/test/tech/phone/base/ATech.kt +++ b/tests/src/main/java/com/github/klee0kai/test/tech/phone/base/ATech.kt @@ -1,29 +1,23 @@ -package com.github.klee0kai.test.tech.phone.base; +package com.github.klee0kai.test.tech.phone.base -import java.util.LinkedList; +import java.util.* -public abstract class ATech { +abstract class ATech { + private val listeners = LinkedList() - private LinkedList listeners = new LinkedList<>(); - - public void subscribe(ATechLifecycle listener) { - this.listeners.add(listener); + fun subscribe(listener: ATechLifecycle?) { + this.listeners.add(listener!!) } - public void onBuy() { - for (ATechLifecycle lis : listeners) - lis.onBuy(); + fun onBuy() { + for (lis in listeners) lis.onBuy() } - public void onBroken() { - for (ATechLifecycle lis : listeners) - lis.onBroken(); + fun onBroken() { + for (lis in listeners) lis.onBroken() } - public void onDrown() { - for (ATechLifecycle lis : listeners) - lis.onDrown(); + fun onDrown() { + for (lis in listeners) lis.onDrown() } - - } diff --git a/tests/src/main/java/com/github/klee0kai/test/tech/phone/base/ATechLifecycle.kt b/tests/src/main/java/com/github/klee0kai/test/tech/phone/base/ATechLifecycle.kt index 4fd81a7a..eecc256d 100644 --- a/tests/src/main/java/com/github/klee0kai/test/tech/phone/base/ATechLifecycle.kt +++ b/tests/src/main/java/com/github/klee0kai/test/tech/phone/base/ATechLifecycle.kt @@ -1,11 +1,9 @@ -package com.github.klee0kai.test.tech.phone.base; +package com.github.klee0kai.test.tech.phone.base -public interface ATechLifecycle { +interface ATechLifecycle { + fun onBuy() - void onBuy(); - - void onBroken(); - - void onDrown(); + fun onBroken() + fun onDrown() } diff --git a/tests/src/main/java/com/github/klee0kai/test/tech/phone/base/LifecycleUtils.kt b/tests/src/main/java/com/github/klee0kai/test/tech/phone/base/LifecycleUtils.kt index 5cdd8e36..a349018f 100644 --- a/tests/src/main/java/com/github/klee0kai/test/tech/phone/base/LifecycleUtils.kt +++ b/tests/src/main/java/com/github/klee0kai/test/tech/phone/base/LifecycleUtils.kt @@ -1,29 +1,24 @@ -package com.github.klee0kai.test.tech.phone.base; +package com.github.klee0kai.test.tech.phone.base -import com.github.klee0kai.stone.lifecycle.StoneLifeCycleOwner; - -public class LifecycleUtils { - - public static StoneLifeCycleOwner createFromATech(ATech phone){ - return listener -> phone.subscribe( - new ATechLifecycle() { - @Override - public void onBuy() { +import com.github.klee0kai.stone.lifecycle.StoneLifeCycleListener +import com.github.klee0kai.stone.lifecycle.StoneLifeCycleOwner +object LifecycleUtils { + fun createFromATech(phone: ATech): StoneLifeCycleOwner { + return StoneLifeCycleOwner { listener: StoneLifeCycleListener? -> + phone.subscribe( + object : ATechLifecycle { + override fun onBuy() { } - @Override - public void onBroken() { - + override fun onBroken() { } - @Override - public void onDrown() { - listener.protectForInjected(100); + override fun onDrown() { + listener!!.protectForInjected(100) } } - ); + ) + } } - - } diff --git a/tests/src/main/java/com/github/klee0kai/test/wire/Wire.kt b/tests/src/main/java/com/github/klee0kai/test/wire/Wire.kt index 28b96a73..838beec8 100644 --- a/tests/src/main/java/com/github/klee0kai/test/wire/Wire.kt +++ b/tests/src/main/java/com/github/klee0kai/test/wire/Wire.kt @@ -1,13 +1,12 @@ -package com.github.klee0kai.test.wire; +package com.github.klee0kai.test.wire -import java.util.UUID; +import java.util.* -public class Wire { +class Wire { - public final UUID uuid = UUID.randomUUID(); + val uuid: UUID = UUID.randomUUID() - public Input input; - - public Output output; + var input: Input? = null + var output: Output? = null } diff --git a/tests/src/main/java/com/github/klee0kai/test/wire/types/Hdmi.kt b/tests/src/main/java/com/github/klee0kai/test/wire/types/Hdmi.kt index e9537c9f..8652a362 100644 --- a/tests/src/main/java/com/github/klee0kai/test/wire/types/Hdmi.kt +++ b/tests/src/main/java/com/github/klee0kai/test/wire/types/Hdmi.kt @@ -1,9 +1,7 @@ -package com.github.klee0kai.test.wire.types; +package com.github.klee0kai.test.wire.types -import java.util.UUID; - -public class Hdmi { - - public final UUID uuid = UUID.randomUUID(); +import java.util.* +class Hdmi { + val uuid: UUID = UUID.randomUUID() } diff --git a/tests/src/main/java/com/github/klee0kai/test/wire/types/MiniUsb.kt b/tests/src/main/java/com/github/klee0kai/test/wire/types/MiniUsb.kt index 8b15f098..b20f8055 100644 --- a/tests/src/main/java/com/github/klee0kai/test/wire/types/MiniUsb.kt +++ b/tests/src/main/java/com/github/klee0kai/test/wire/types/MiniUsb.kt @@ -1,9 +1,7 @@ -package com.github.klee0kai.test.wire.types; +package com.github.klee0kai.test.wire.types -import java.util.UUID; - -public class MiniUsb { - - public final UUID uuid = UUID.randomUUID(); +import java.util.* +class MiniUsb { + val uuid: UUID = UUID.randomUUID() } diff --git a/tests/src/main/java/com/github/klee0kai/test/wire/types/Usb.kt b/tests/src/main/java/com/github/klee0kai/test/wire/types/Usb.kt index 7b5c8165..6da85181 100644 --- a/tests/src/main/java/com/github/klee0kai/test/wire/types/Usb.kt +++ b/tests/src/main/java/com/github/klee0kai/test/wire/types/Usb.kt @@ -1,9 +1,7 @@ -package com.github.klee0kai.test.wire.types; +package com.github.klee0kai.test.wire.types -import java.util.UUID; - -public class Usb { - - public final UUID uuid = UUID.randomUUID(); +import java.util.* +class Usb { + val uuid: UUID = UUID.randomUUID() } From eac965a59d683f537efae9e425aabfa0834ae176 Mon Sep 17 00:00:00 2001 From: klee0kai Date: Tue, 9 Dec 2025 23:05:51 +0100 Subject: [PATCH 050/122] gen hidden module --- .../klee0kai/thekey/stone/ksp/Processor.kt | 19 +- .../thekey/stone/ksp/exceptions/WrapExt.kt | 11 + .../stone/ksp/helpers/StoneFileNamesExt.kt | 6 +- .../itemholder/ItemHolderCodeHelper.kt | 35 ++- .../MultiKeyMapItemHolderCodeHelper.kt | 14 +- .../SimpleMapItemHolderCodeHelper.kt | 13 +- .../itemholder/SingleItemHolderCodeHelper.kt | 14 +- .../target/GenModuleCacheControlProcessor.kt | 13 +- .../ksp/target/GenModuleFactoryProcessor.kt | 7 +- .../stone/ksp/target/GenModuleProcessor.kt | 31 +-- .../target/component/ComponentsMethodsExt.kt | 39 ++-- .../target/component/GenComponentProcessor.kt | 5 +- .../GenHiddenModuleCacheControlProcessor.kt | 114 ++++++++++ .../hiddenmodule/GenHiddenModuleProcessor.kt | 201 +++++++++++++++++- .../di/techfactory/ITechProviderComponent.kt | 2 +- 15 files changed, 410 insertions(+), 114 deletions(-) create mode 100644 stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/hiddenmodule/GenHiddenModuleCacheControlProcessor.kt diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/Processor.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/Processor.kt index 9677d1f6..fb5b2b6b 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/Processor.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/Processor.kt @@ -10,6 +10,7 @@ import com.github.klee0kai.thekey.stone.ksp.target.GenModuleCacheControlProcesso import com.github.klee0kai.thekey.stone.ksp.target.GenModuleFactoryProcessor import com.github.klee0kai.thekey.stone.ksp.target.GenModuleProcessor import com.github.klee0kai.thekey.stone.ksp.target.component.GenComponentProcessor +import com.github.klee0kai.thekey.stone.ksp.target.hiddenmodule.GenHiddenModuleCacheControlProcessor import com.github.klee0kai.thekey.stone.ksp.target.hiddenmodule.GenHiddenModuleProcessor import com.google.devtools.ksp.containingFile import com.google.devtools.ksp.processing.CodeGenerator @@ -60,8 +61,8 @@ class Processor( debugPkgFilter = options["debugPkgFilter"] // force changes -// debug = true -// debugPkgFilter = "com.github.klee0kai.test_kotlin.di.base_comp" + debug = true + debugPkgFilter = "com.github.klee0kai.test.di.bindinstance.singlemethod_inject" } @@ -71,6 +72,7 @@ class Processor( GenModuleCacheControlProcessor(), GenModuleProcessor(), GenHiddenModuleProcessor(), + GenHiddenModuleCacheControlProcessor(), GenComponentProcessor(), ) @@ -102,6 +104,14 @@ class Processor( takeSymbolsCount = max(takeSymbolsCount, 0) totalCount + takeSymbolsCount } + + if (debug && debugPkgFilter != null) { + symbols = symbols + .filter { + it.containingFile?.packageName?.asString()?.startsWith(debugPkgFilter!!) ?: true + } + } + // skip to next run symbols = symbols.nowTakeOnly(takeSymbolsCount) @@ -112,10 +122,7 @@ class Processor( symbols = symbols.forceProcess { it in globalSymbolsForProcessing } - if (debug && debugPkgFilter != null) { - symbols = symbols - .filter { it.containingFile?.packageName?.asString()?.startsWith(debugPkgFilter!!) ?: true } - } + globalSymbolsForReprocessing.addAll(symbols.symbolsForReprocessing) try { diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/exceptions/WrapExt.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/exceptions/WrapExt.kt index 0b282d55..dee64aa5 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/exceptions/WrapExt.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/exceptions/WrapExt.kt @@ -1,5 +1,6 @@ package com.github.klee0kai.thekey.stone.ksp.exceptions +import com.google.devtools.ksp.symbol.KSFunctionDeclaration import com.google.devtools.ksp.symbol.KSNode fun T.wrapKsNoteInfo( @@ -14,4 +15,14 @@ fun T.wrapKsNoteInfo( element = ksNode, ) } +} + +fun Sequence.forEachFun( + action: (index: Int, KSFunctionDeclaration) -> Unit +) { + forEachIndexed { idx, func -> + wrapKsNoteInfo(func) { + action(idx, func) + } + } } \ No newline at end of file diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/StoneFileNamesExt.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/StoneFileNamesExt.kt index f155161d..8fabad5e 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/StoneFileNamesExt.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/StoneFileNamesExt.kt @@ -38,10 +38,10 @@ val KSClassDeclaration.moduleStoneClName ) -val KSClassDeclaration.cacheControlStoneClName +val ClassName.cacheControlStoneClName get() = ClassName( - packageName.asString(), - simpleName.getShortName().cacheControlClName, + packageName, + simpleName.cacheControlClName, ) diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/itemholder/ItemHolderCodeHelper.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/itemholder/ItemHolderCodeHelper.kt index 76daea29..5b750b52 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/itemholder/ItemHolderCodeHelper.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/itemholder/ItemHolderCodeHelper.kt @@ -1,10 +1,9 @@ package com.github.klee0kai.thekey.stone.ksp.helpers.itemholder -import com.github.klee0kai.thekey.stone.ksp.helpers.isListType -import com.github.klee0kai.thekey.stone.ksp.helpers.noWrappedType -import com.google.devtools.ksp.symbol.KSType +import com.github.klee0kai.thekey.stone.ksp.helpers.wrap.WrapHelper import com.google.devtools.ksp.symbol.KSValueParameter import com.squareup.kotlinpoet.CodeBlock +import com.squareup.kotlinpoet.TypeName import com.squareup.kotlinpoet.TypeSpec interface ItemHolderCodeHelper { @@ -29,47 +28,39 @@ interface ItemHolderCodeHelper { fun ItemHolderCodeHelper.Companion.of( fieldName: String, - returnType: KSType, + returnType: TypeName, idArguments: List, cacheType: ItemCacheType, + wrapHelper: WrapHelper, ): ItemHolderCodeHelper { - val noWrappedReturnType = returnType - .noWrappedType( - wrappedTypes = idArguments.map { it.type.resolve() } - ) - val defRefType = if (noWrappedReturnType.isListType()) { - cacheType.toRefTypeList() - } else { - cacheType.toRefTypeSingle() - } return when { idArguments.isEmpty() -> SingleItemHolderCodeHelper( fieldName = fieldName, returnType = returnType, - nonWrappedReturnType = noWrappedReturnType, + nonWrappedReturnType = wrapHelper.nonWrappedType(returnType), itemCacheType = cacheType, - isListCaching = noWrappedReturnType.isListType(), - defRefType = defRefType, + isListCaching = wrapHelper.isList(returnType), + defRefType = if (wrapHelper.isList(returnType)) cacheType.toRefTypeList() else cacheType.toRefTypeSingle(), ) idArguments.size == 1 -> SimpleMapItemHolderCodeHelper( fieldName = fieldName, returnType = returnType, - nonWrappedReturnType = noWrappedReturnType, + nonWrappedReturnType = wrapHelper.nonWrappedType(returnType), itemCacheType = cacheType, - isListCaching = noWrappedReturnType.isListType(), - defRefType = defRefType, + isListCaching = wrapHelper.isList(returnType), + defRefType = if (wrapHelper.isList(returnType)) cacheType.toRefTypeList() else cacheType.toRefTypeSingle(), keyParam = idArguments.first(), ) else -> MultiKeyMapItemHolderCodeHelper( fieldName = fieldName, returnType = returnType, - nonWrappedReturnType = noWrappedReturnType, + nonWrappedReturnType = wrapHelper.nonWrappedType(returnType), itemCacheType = cacheType, - isListCaching = noWrappedReturnType.isListType(), - defRefType = defRefType, + isListCaching = wrapHelper.isList(returnType), + defRefType = if (wrapHelper.isList(returnType)) cacheType.toRefTypeList() else cacheType.toRefTypeSingle(), keyArguments = idArguments, ) } diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/itemholder/MultiKeyMapItemHolderCodeHelper.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/itemholder/MultiKeyMapItemHolderCodeHelper.kt index a5399c22..683f8b36 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/itemholder/MultiKeyMapItemHolderCodeHelper.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/itemholder/MultiKeyMapItemHolderCodeHelper.kt @@ -5,20 +5,14 @@ import com.github.klee0kai.stone.__hidden__.types.holders.MapItemHolder import com.github.klee0kai.stone.__hidden__.types.holders.StoneRefType import com.github.klee0kai.thekey.stone.ksp.poet.codeBlock import com.github.klee0kai.thekey.stone.ksp.poet.genProperty -import com.google.devtools.ksp.symbol.KSType import com.google.devtools.ksp.symbol.KSValueParameter -import com.squareup.kotlinpoet.CodeBlock -import com.squareup.kotlinpoet.KModifier +import com.squareup.kotlinpoet.* import com.squareup.kotlinpoet.ParameterizedTypeName.Companion.parameterizedBy -import com.squareup.kotlinpoet.TypeSpec -import com.squareup.kotlinpoet.asClassName -import com.squareup.kotlinpoet.ksp.toClassName -import com.squareup.kotlinpoet.ksp.toTypeName class MultiKeyMapItemHolderCodeHelper( val fieldName: String, - val returnType: KSType, - val nonWrappedReturnType: KSType, + val returnType: TypeName, + val nonWrappedReturnType: TypeName, val itemCacheType: ItemCacheType, val isListCaching: Boolean, val defRefType: StoneRefType, @@ -29,7 +23,7 @@ class MultiKeyMapItemHolderCodeHelper( val cacheType = MapItemHolder::class.asClassName() .parameterizedBy( MultiKey::class.asClassName(), - nonWrappedReturnType.toTypeName(), + nonWrappedReturnType, ) genProperty(fieldName, cacheType) { diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/itemholder/SimpleMapItemHolderCodeHelper.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/itemholder/SimpleMapItemHolderCodeHelper.kt index 7af74c65..8cd75119 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/itemholder/SimpleMapItemHolderCodeHelper.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/itemholder/SimpleMapItemHolderCodeHelper.kt @@ -4,20 +4,15 @@ import com.github.klee0kai.stone.__hidden__.types.holders.MapItemHolder import com.github.klee0kai.stone.__hidden__.types.holders.StoneRefType import com.github.klee0kai.thekey.stone.ksp.poet.codeBlock import com.github.klee0kai.thekey.stone.ksp.poet.genProperty -import com.google.devtools.ksp.symbol.KSType import com.google.devtools.ksp.symbol.KSValueParameter -import com.squareup.kotlinpoet.CodeBlock -import com.squareup.kotlinpoet.KModifier +import com.squareup.kotlinpoet.* import com.squareup.kotlinpoet.ParameterizedTypeName.Companion.parameterizedBy -import com.squareup.kotlinpoet.TypeSpec -import com.squareup.kotlinpoet.asClassName -import com.squareup.kotlinpoet.ksp.toClassName import com.squareup.kotlinpoet.ksp.toTypeName class SimpleMapItemHolderCodeHelper( val fieldName: String, - val returnType: KSType, - val nonWrappedReturnType: KSType, + val returnType: TypeName, + val nonWrappedReturnType: TypeName, val itemCacheType: ItemCacheType, val isListCaching: Boolean, val defRefType: StoneRefType, @@ -28,7 +23,7 @@ class SimpleMapItemHolderCodeHelper( val cacheType = MapItemHolder::class.asClassName() .parameterizedBy( keyParam.type.resolve().toTypeName(), - nonWrappedReturnType.toTypeName(), + nonWrappedReturnType, ) genProperty(fieldName, cacheType) { diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/itemholder/SingleItemHolderCodeHelper.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/itemholder/SingleItemHolderCodeHelper.kt index db10c8f5..caf58951 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/itemholder/SingleItemHolderCodeHelper.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/itemholder/SingleItemHolderCodeHelper.kt @@ -4,19 +4,13 @@ import com.github.klee0kai.stone.__hidden__.types.holders.SingleItemHolder import com.github.klee0kai.stone.__hidden__.types.holders.StoneRefType import com.github.klee0kai.thekey.stone.ksp.poet.codeBlock import com.github.klee0kai.thekey.stone.ksp.poet.genProperty -import com.google.devtools.ksp.symbol.KSType -import com.squareup.kotlinpoet.CodeBlock -import com.squareup.kotlinpoet.KModifier +import com.squareup.kotlinpoet.* import com.squareup.kotlinpoet.ParameterizedTypeName.Companion.parameterizedBy -import com.squareup.kotlinpoet.TypeSpec -import com.squareup.kotlinpoet.asClassName -import com.squareup.kotlinpoet.ksp.toClassName -import com.squareup.kotlinpoet.ksp.toTypeName class SingleItemHolderCodeHelper( val fieldName: String, - val returnType: KSType, - val nonWrappedReturnType: KSType, + val returnType: TypeName, + val nonWrappedReturnType: TypeName, val itemCacheType: ItemCacheType, val isListCaching: Boolean, val defRefType: StoneRefType, @@ -24,7 +18,7 @@ class SingleItemHolderCodeHelper( override fun TypeSpec.Builder.genCacheField() { val cacheType = SingleItemHolder::class.asClassName() - .parameterizedBy(nonWrappedReturnType.toTypeName()) + .parameterizedBy(nonWrappedReturnType) genProperty(fieldName, cacheType) { addModifiers(KModifier.PRIVATE) diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/GenModuleCacheControlProcessor.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/GenModuleCacheControlProcessor.kt index f4fc868b..af4f5d95 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/GenModuleCacheControlProcessor.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/GenModuleCacheControlProcessor.kt @@ -5,10 +5,8 @@ package com.github.klee0kai.thekey.stone.ksp.target import com.github.klee0kai.stone.__hidden__.CacheAction import com.github.klee0kai.stone.__hidden__.SwitchCacheParam import com.github.klee0kai.stone.annotations.module.Module -import com.github.klee0kai.thekey.stone.ksp.helpers.allIdentifierTypes -import com.github.klee0kai.thekey.stone.ksp.helpers.cacheControlMethodName -import com.github.klee0kai.thekey.stone.ksp.helpers.cacheControlStoneClName -import com.github.klee0kai.thekey.stone.ksp.helpers.findComponentForModuleOrDep +import com.github.klee0kai.thekey.stone.ksp.exceptions.forEachFun +import com.github.klee0kai.thekey.stone.ksp.helpers.* import com.github.klee0kai.thekey.stone.ksp.ksp.arch.GenSpec import com.github.klee0kai.thekey.stone.ksp.ksp.arch.SymbolsToProcess import com.github.klee0kai.thekey.stone.ksp.ksp.arch.TargetFileProcessor @@ -56,7 +54,7 @@ class GenModuleCacheControlProcessor : TargetFileProcessor { ?.allIdentifierTypes?.toList() ?: emptyList() - val genCacheControlClassName = moduleCl.cacheControlStoneClName + val genCacheControlClassName = moduleCl.toClassName().cacheControlStoneClName val fileSpec = genFileSpec( packageName = genCacheControlClassName.packageName, fileName = genCacheControlClassName.simpleName @@ -85,9 +83,8 @@ class GenModuleCacheControlProcessor : TargetFileProcessor { } validSymbol.getAllMethods(false, false, "") - .forEach { function -> - val idArguments = function.parameters - .filter { it.type.resolve() in identifierTypes } + .forEachFun { _, function -> + val idArguments = function.parameters.identifierParameters(identifierTypes) genOverrideFun(function) { modifiers.remove(KModifier.OVERRIDE) diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/GenModuleFactoryProcessor.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/GenModuleFactoryProcessor.kt index af641657..bcb89f27 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/GenModuleFactoryProcessor.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/GenModuleFactoryProcessor.kt @@ -5,6 +5,7 @@ package com.github.klee0kai.thekey.stone.ksp.target import com.github.klee0kai.stone.__hidden__.IModuleFactory import com.github.klee0kai.stone.annotations.module.BindInstance import com.github.klee0kai.stone.annotations.module.Module +import com.github.klee0kai.thekey.stone.ksp.exceptions.forEachFun import com.github.klee0kai.thekey.stone.ksp.helpers.factoryStoneClName import com.github.klee0kai.thekey.stone.ksp.ksp.arch.GenSpec import com.github.klee0kai.thekey.stone.ksp.ksp.arch.SymbolsToProcess @@ -69,10 +70,10 @@ class GenModuleFactoryProcessor : TargetFileProcessor { addModifiers(KModifier.OPEN) validSymbol.getAllMethods(false, false, "") - .forEach { function -> - if (!function.modifiers.contains(Modifier.ABSTRACT) && moduleCl.classKind != ClassKind.INTERFACE) return@forEach + .forEachFun { _, function -> + if (!function.modifiers.contains(Modifier.ABSTRACT) && moduleCl.classKind != ClassKind.INTERFACE) return@forEachFun val returnCl = function.returnType?.resolve() - ?.declaration as? KSClassDeclaration ?: return@forEach + ?.declaration as? KSClassDeclaration ?: return@forEachFun val bindInstanceAnn = function.getAnnotationsByType(BindInstance::class) .firstOrNull() diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/GenModuleProcessor.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/GenModuleProcessor.kt index 11f0205e..af287214 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/GenModuleProcessor.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/GenModuleProcessor.kt @@ -12,6 +12,7 @@ import com.github.klee0kai.stone.annotations.module.BindInstance import com.github.klee0kai.stone.annotations.module.Module import com.github.klee0kai.stone.annotations.module.Provide import com.github.klee0kai.stone.weakref.Ref +import com.github.klee0kai.thekey.stone.ksp.exceptions.forEachFun import com.github.klee0kai.thekey.stone.ksp.helpers.* import com.github.klee0kai.thekey.stone.ksp.helpers.annotations.annotations import com.github.klee0kai.thekey.stone.ksp.helpers.itemholder.ItemHolderCodeHelper @@ -101,7 +102,7 @@ class GenModuleProcessor : TargetFileProcessor { val genModuleClassName = moduleCl.moduleStoneClName - val wrapperHelper = WrapHelper() + val wrapHelper = WrapHelper() val fileSpec = genFileSpec(genModuleClassName.packageName, genModuleClassName.simpleName) { genLibComment() @@ -113,19 +114,19 @@ class GenModuleProcessor : TargetFileProcessor { superclass(moduleCl.toClassName()) } addSuperinterface(IModule::class) - addSuperinterface(moduleCl.cacheControlStoneClName) + addSuperinterface(moduleCl.toClassName().cacheControlStoneClName) addModifiers(KModifier.OPEN) val codeBlocks = DelayedCodeBlocks() validSymbol.getAllMethods(false, false, "") - .forEachIndexed { funIdx, function -> + .forEachFun { funIdx, function -> val bindAnn = function.getAnnotationsByType(BindInstance::class).firstOrNull() val provideAnn = function.getAnnotationsByType(Provide::class).firstOrNull() val idArguments = function.parameters.identifierParameters(identifierTypes) - val returnType = function.returnType?.resolve() ?: return@forEachIndexed - val nonWrappedType = returnType.noWrappedType(wrapperTypes) - val isListReturnType = nonWrappedType.isListType() + val returnType = function.returnType?.resolve()?.toTypeName() ?: return@forEachFun + val nonWrappedType = wrapHelper.nonWrappedType(returnType) + val isListReturnType = wrapHelper.isList(returnType) val gcScopes = (function.scopeAnnotations .map { it.annotationType.resolve().toTypeName() } .toSet() + GcAllScope::class.asClassName()).toMutableSet() @@ -138,6 +139,7 @@ class GenModuleProcessor : TargetFileProcessor { returnType = returnType, idArguments = idArguments, cacheType = bindAnn.cache.toItemCacheType(), + wrapHelper = wrapHelper, ) gcScopes += bindAnn.cache.toItemCacheType().gcScopeClassName codeBlocks.switchRefStatementBuilders.getOrPut(gcScopes) { CodeBlock.builder() } @@ -151,8 +153,8 @@ class GenModuleProcessor : TargetFileProcessor { codeBlocks.bindMethodBody.apply { add( "if (or is %T && or::class == %T::class) {\n", - nonWrappedType.toTypeName().copy(nullable = false), - nonWrappedType.toTypeName().copy(nullable = false), + nonWrappedType, + nonWrappedType, ) add(codeSetCachedValue(CodeBlock.of("or"), false)) add("\n") @@ -165,7 +167,7 @@ class GenModuleProcessor : TargetFileProcessor { function = function, idArguments = idArguments, itemHolderCodeHelper = itemHolderCodeHelper, - wrapHelper = wrapperHelper, + wrapHelper = wrapHelper, ) genCacheControlFun( function = function, @@ -197,7 +199,8 @@ class GenModuleProcessor : TargetFileProcessor { fieldName = "${function.simpleName.asString()}$funIdx", returnType = returnType, idArguments = idArguments, - cacheType = provideAnn.cache.toItemCacheType() ?: return@forEachIndexed, + cacheType = provideAnn.cache.toItemCacheType() ?: return@forEachFun, + wrapHelper = wrapHelper, ) gcScopes += provideAnn.cache.toItemCacheType()!!.gcScopeClassName codeBlocks.switchRefStatementBuilders.getOrPut(gcScopes) { CodeBlock.builder() } @@ -210,7 +213,7 @@ class GenModuleProcessor : TargetFileProcessor { function = function, idArguments = idArguments, itemHolderCodeHelper = itemHolderCodeHelper, - wrapHelper = wrapperHelper, + wrapHelper = wrapHelper, ) genCacheControlFun( function = function, @@ -411,7 +414,7 @@ class GenModuleProcessor : TargetFileProcessor { } val cacheControlHolder = SingleItemHolder::class.asClassName() - .parameterizedBy(moduleCl.cacheControlStoneClName) + .parameterizedBy(moduleCl.toClassName().cacheControlStoneClName) genProperty( name = overridedModuleFieldName, type = cacheControlHolder, @@ -430,7 +433,7 @@ class GenModuleProcessor : TargetFileProcessor { // check module class beginControlFlow( "if ( (or is %T) ) ", - moduleCl.cacheControlStoneClName, + moduleCl.toClassName().cacheControlStoneClName, ) addStatement( "%L.set(onlyIfNull = false) { or }", @@ -466,7 +469,7 @@ class GenModuleProcessor : TargetFileProcessor { .filter { it.annotations(Module::class.asClassName()).any() } .mapNotNull { it as? KSClassDeclaration } .forEach { cl -> - val cacheControlCl = cl.cacheControlStoneClName + val cacheControlCl = cl.toClassName().cacheControlStoneClName beginControlFlow("if ( m is %T )", cacheControlCl) addStatement("val module = m as %T", cacheControlCl) diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/component/ComponentsMethodsExt.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/component/ComponentsMethodsExt.kt index 35e7158d..acab2b0d 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/component/ComponentsMethodsExt.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/component/ComponentsMethodsExt.kt @@ -12,6 +12,7 @@ import com.github.klee0kai.thekey.stone.ksp.helpers.scopeAnnotations import com.github.klee0kai.thekey.stone.ksp.ksp.isClassReturn import com.github.klee0kai.thekey.stone.ksp.ksp.isNotPrimitive import com.github.klee0kai.thekey.stone.ksp.ksp.isUnit +import com.github.klee0kai.thekey.stone.ksp.ksp.resolveAlias import com.github.klee0kai.thekey.stone.ksp.target.GenModuleProcessor import com.google.devtools.ksp.getAllSuperTypes import com.google.devtools.ksp.symbol.KSClassDeclaration @@ -118,11 +119,10 @@ val KSFunctionDeclaration.isModuleInitMethod: Boolean val clDeclaration = it.type .resolve() .declaration as? KSClassDeclaration - ?: - throw IncorrectSignatureException( - message = "${simpleName.asString()} must have only one parameter of Dependency or Module instance", - element = this, - ) + ?: throw IncorrectSignatureException( + message = "${simpleName.asString()} must have only one parameter of Dependency or Module instance", + element = this, + ) if (!clDeclaration.anyAnnotation(Module::class.asClassName(), Dependencies::class.asClassName()).any()) { @@ -189,12 +189,6 @@ val KSFunctionDeclaration.isBindInstanceMethod: BindInstanceType? get() { if (!annotations(BindInstance::class.asClassName()).any()) return null - if (!hasOnlyAnnotation(BindInstance::class.asClassName())) { - throw IncorrectSignatureException( - message = "${simpleName.asString()} must have only one annotation ${BindInstance::class.simpleName}", - element = this, - ) - } if (parameters.size != 1) { throw IncorrectSignatureException( message = "${simpleName.asString()} must have only one parameter of binding type", @@ -202,18 +196,25 @@ val KSFunctionDeclaration.isBindInstanceMethod: BindInstanceType? ) } checkMethodNameBusy() + val parameterIsNotPrimitive = parameters.first().type.resolveAlias().isNotPrimitive when { - returnType?.resolve()?.isNotPrimitive == true -> { - return BindInstanceType.BindInstance + parameterIsNotPrimitive + && returnType?.resolve()?.toTypeName() == parameters.first().type.resolve().toTypeName() -> { + return BindInstanceType.BindInstanceAndProvide } - returnType?.resolve()?.toTypeName() == parameters.first().type.resolve().toTypeName() -> { - return BindInstanceType.BindInstanceAndProvide + parameterIsNotPrimitive -> { + return BindInstanceType.BindInstance } + + } - throw IncorrectSignatureException("${simpleName.asString()} has incorrect signature") + throw IncorrectSignatureException( + message = "${simpleName.asString()} has incorrect signature", + element = this, + ) } val KSFunctionDeclaration.isGcMethod: Boolean @@ -242,12 +243,6 @@ val KSFunctionDeclaration.isSwitchCacheMethod: Boolean get() { if (!annotations(SwitchCache::class.asClassName()).any()) return false - if (!hasOnlyAnnotation(SwitchCache::class.asClassName())) { - throw IncorrectSignatureException( - message = "${simpleName.asString()} must use only ${SwitchCache::class.simpleName} annotation", - element = this, - ) - } if (parameters.isNotEmpty()) { throw IncorrectSignatureException( message = "${simpleName.asString()} must no have arguments", diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/component/GenComponentProcessor.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/component/GenComponentProcessor.kt index 49a9882b..08a43bd7 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/component/GenComponentProcessor.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/component/GenComponentProcessor.kt @@ -11,6 +11,7 @@ import com.github.klee0kai.stone.annotations.module.Module import com.github.klee0kai.stone.weakref.Inject import com.github.klee0kai.thekey.stone.ksp.exceptions.IncorrectSignatureException import com.github.klee0kai.thekey.stone.ksp.exceptions.ObjectNotProvidedException +import com.github.klee0kai.thekey.stone.ksp.exceptions.forEachFun import com.github.klee0kai.thekey.stone.ksp.helpers.* import com.github.klee0kai.thekey.stone.ksp.helpers.annotations.anyAnnotation import com.github.klee0kai.thekey.stone.ksp.helpers.invokecall.ModulesGraph @@ -111,7 +112,7 @@ class GenComponentProcessor : TargetFileProcessor { val componentsAllMethods = componentCl .getAllMethods(includeObjectMethods = false, allowDoubles = false, "") - componentsAllMethods.forEach { m -> + componentsAllMethods.forEachFun { _, m -> when { m.isModuleProvideMethod -> { val moduleCl = m.returnType?.resolve()?.declaration as? KSClassDeclaration @@ -408,7 +409,7 @@ class GenComponentProcessor : TargetFileProcessor { ) { addModifiers(KModifier.PRIVATE) mutable(true) - initializer("%T(%M())", CoroutineScope::class.asClassName(),SupervisorJob) + initializer("%T(%M())", CoroutineScope::class.asClassName(), SupervisorJob) } genProperty( diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/hiddenmodule/GenHiddenModuleCacheControlProcessor.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/hiddenmodule/GenHiddenModuleCacheControlProcessor.kt new file mode 100644 index 00000000..b0555934 --- /dev/null +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/hiddenmodule/GenHiddenModuleCacheControlProcessor.kt @@ -0,0 +1,114 @@ +@file:OptIn(KspExperimental::class) + +package com.github.klee0kai.thekey.stone.ksp.target.hiddenmodule + +import com.github.klee0kai.stone.__hidden__.CacheAction +import com.github.klee0kai.stone.__hidden__.SwitchCacheParam +import com.github.klee0kai.stone.annotations.component.Component +import com.github.klee0kai.stone.annotations.module.BindInstance +import com.github.klee0kai.thekey.stone.ksp.exceptions.forEachFun +import com.github.klee0kai.thekey.stone.ksp.helpers.* +import com.github.klee0kai.thekey.stone.ksp.ksp.arch.GenSpec +import com.github.klee0kai.thekey.stone.ksp.ksp.arch.SymbolsToProcess +import com.github.klee0kai.thekey.stone.ksp.ksp.arch.TargetFileProcessor +import com.github.klee0kai.thekey.stone.ksp.ksp.getAllMethods +import com.github.klee0kai.thekey.stone.ksp.poet.* +import com.github.klee0kai.thekey.stone.ksp.target.GenModuleProcessor +import com.github.klee0kai.thekey.stone.ksp.target.component.BindInstanceType +import com.github.klee0kai.thekey.stone.ksp.target.component.isBindInstanceMethod +import com.google.devtools.ksp.KspExperimental +import com.google.devtools.ksp.containingFile +import com.google.devtools.ksp.getAnnotationsByType +import com.google.devtools.ksp.processing.Dependencies +import com.google.devtools.ksp.processing.KSPLogger +import com.google.devtools.ksp.processing.Resolver +import com.google.devtools.ksp.symbol.KSAnnotated +import com.google.devtools.ksp.symbol.KSClassDeclaration +import com.squareup.kotlinpoet.KModifier +import com.squareup.kotlinpoet.ParameterizedTypeName.Companion.parameterizedBy +import com.squareup.kotlinpoet.STAR +import com.squareup.kotlinpoet.asClassName +import com.squareup.kotlinpoet.ksp.toTypeName +import kotlin.reflect.KClass + +class GenHiddenModuleCacheControlProcessor : TargetFileProcessor { + + override suspend fun findSymbolsToProcess( + resolver: Resolver, + ) = SymbolsToProcess( + symbolsForProcessing = resolver + .getSymbolsWithAnnotation(Component::class.asClassName().canonicalName) + .toList(), + symbolsForReprocessing = emptyList(), + ) + + + override suspend fun process( + validSymbol: KSAnnotated, + resolver: Resolver, + options: Map, + logger: KSPLogger + ): GenSpec? { + val fileOwner = validSymbol.containingFile ?: return null + val componentCl = validSymbol as? KSClassDeclaration ?: return null + + val genHiddenModuleCl = componentCl.hiddenModuleStoneClName + val identifierTypes = componentCl.allIdentifierTypes.toList() + + val genCacheControlClassName = genHiddenModuleCl.cacheControlStoneClName + val fileSpec = genFileSpec(genHiddenModuleCl.packageName, genCacheControlClassName.simpleName) { + genLibComment() + + genInterface(genCacheControlClassName) { + + genFun(GenModuleProcessor.bindMethodName) { + modifiers.add(KModifier.ABSTRACT) + addParameter("or", Any::class) + returns(Boolean::class) + } + + genFun(GenModuleProcessor.switchRefMethodName) { + modifiers.add(KModifier.ABSTRACT) + addParameter( + "scopes", + Set::class.asClassName() + .parameterizedBy( + KClass::class.asClassName() + .parameterizedBy(STAR) + ) + ) + addParameter("__params", SwitchCacheParam::class) + } + + val functions = validSymbol.getAllMethods(false, false, "") + functions.forEachFun { _, function -> + val idArguments = function.parameters.identifierParameters(identifierTypes) + val bindAnn = function.getAnnotationsByType(BindInstance::class).firstOrNull() + + if (bindAnn == null || function.isBindInstanceMethod != BindInstanceType.BindInstanceAndProvide) + return@forEachFun + + genOverrideFun(function) { + modifiers.remove(KModifier.OVERRIDE) + modifiers.add(KModifier.ABSTRACT) + } + genFun(function.cacheControlMethodName) { + modifiers.add(KModifier.ABSTRACT) + returns(returnType = function.returnType!!.resolve().toTypeName().copy(nullable = true)) + addParameter("__action", CacheAction::class) + idArguments.forEach { + addParameter(it.name!!.asString(), it.type.resolve().toTypeName()) + } + } + } + + } + } + + return GenSpec( + fileSpec = fileSpec, + // https://kotlinlang.org/docs/ksp-incremental.html + dependencies = Dependencies(aggregating = false, fileOwner), + ) + } +} \ No newline at end of file diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/hiddenmodule/GenHiddenModuleProcessor.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/hiddenmodule/GenHiddenModuleProcessor.kt index a28cba7e..95e42cbc 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/hiddenmodule/GenHiddenModuleProcessor.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/hiddenmodule/GenHiddenModuleProcessor.kt @@ -1,13 +1,26 @@ +@file:OptIn(KspExperimental::class) + package com.github.klee0kai.thekey.stone.ksp.target.hiddenmodule +import com.github.klee0kai.stone.__hidden__.CacheAction import com.github.klee0kai.stone.__hidden__.IModule import com.github.klee0kai.stone.__hidden__.SwitchCacheParam +import com.github.klee0kai.stone.__hidden__.types.holders.SingleItemHolder +import com.github.klee0kai.stone.__hidden__.types.holders.StoneRefType import com.github.klee0kai.stone.annotations.component.Component -import com.github.klee0kai.thekey.stone.ksp.helpers.allIdentifierTypes -import com.github.klee0kai.thekey.stone.ksp.helpers.hiddenModuleStoneClName +import com.github.klee0kai.stone.annotations.component.GcAllScope +import com.github.klee0kai.stone.annotations.module.BindInstance +import com.github.klee0kai.thekey.stone.ksp.exceptions.forEachFun +import com.github.klee0kai.thekey.stone.ksp.helpers.* +import com.github.klee0kai.thekey.stone.ksp.helpers.itemholder.ItemHolderCodeHelper +import com.github.klee0kai.thekey.stone.ksp.helpers.itemholder.of +import com.github.klee0kai.thekey.stone.ksp.helpers.itemholder.toItemCacheType +import com.github.klee0kai.thekey.stone.ksp.helpers.wrap.ClassNameUtils.rawTypeOf +import com.github.klee0kai.thekey.stone.ksp.helpers.wrap.WrapHelper import com.github.klee0kai.thekey.stone.ksp.ksp.arch.GenSpec import com.github.klee0kai.thekey.stone.ksp.ksp.arch.SymbolsToProcess import com.github.klee0kai.thekey.stone.ksp.ksp.arch.TargetFileProcessor +import com.github.klee0kai.thekey.stone.ksp.ksp.getAllMethods import com.github.klee0kai.thekey.stone.ksp.poet.* import com.github.klee0kai.thekey.stone.ksp.target.GenModuleProcessor.Companion.appliedLocalFieldName import com.github.klee0kai.thekey.stone.ksp.target.GenModuleProcessor.Companion.bindMethodName @@ -15,18 +28,26 @@ import com.github.klee0kai.thekey.stone.ksp.target.GenModuleProcessor.Companion. import com.github.klee0kai.thekey.stone.ksp.target.GenModuleProcessor.Companion.factoryFieldName import com.github.klee0kai.thekey.stone.ksp.target.GenModuleProcessor.Companion.initCachesFromMethodName import com.github.klee0kai.thekey.stone.ksp.target.GenModuleProcessor.Companion.initMethodName +import com.github.klee0kai.thekey.stone.ksp.target.GenModuleProcessor.Companion.overridedModuleFieldName import com.github.klee0kai.thekey.stone.ksp.target.GenModuleProcessor.Companion.switchRefMethodName import com.github.klee0kai.thekey.stone.ksp.target.GenModuleProcessor.Companion.updateBindInstancesFrom +import com.github.klee0kai.thekey.stone.ksp.target.component.BindInstanceType import com.github.klee0kai.thekey.stone.ksp.target.component.collectComponentGraph import com.github.klee0kai.thekey.stone.ksp.target.component.collectWrapHelper +import com.github.klee0kai.thekey.stone.ksp.target.component.isBindInstanceMethod +import com.google.devtools.ksp.KspExperimental import com.google.devtools.ksp.containingFile +import com.google.devtools.ksp.getAnnotationsByType import com.google.devtools.ksp.processing.Dependencies import com.google.devtools.ksp.processing.KSPLogger import com.google.devtools.ksp.processing.Resolver import com.google.devtools.ksp.symbol.KSAnnotated import com.google.devtools.ksp.symbol.KSClassDeclaration +import com.google.devtools.ksp.symbol.KSFunctionDeclaration +import com.google.devtools.ksp.symbol.KSValueParameter import com.squareup.kotlinpoet.* import com.squareup.kotlinpoet.ParameterizedTypeName.Companion.parameterizedBy +import com.squareup.kotlinpoet.ksp.toTypeName import kotlin.reflect.KClass class GenHiddenModuleProcessor : TargetFileProcessor { @@ -61,15 +82,77 @@ class GenHiddenModuleProcessor : TargetFileProcessor { val identifierTypes = componentCl.allIdentifierTypes.toList() val wrapHelper = componentCl.collectWrapHelper() val modulesGraph = componentCl.collectComponentGraph() - val delayedCodeBlocks = DelayedCodeBlocks() + val codeBlocks = DelayedCodeBlocks() + val genCacheControlClassName = genHiddenModuleCl.cacheControlStoneClName val fileSpec = genFileSpec(genHiddenModuleCl.packageName, genHiddenModuleCl.simpleName) { genLibComment() genClass(genHiddenModuleCl) { addSuperinterface(IModule::class) + addSuperinterface(genCacheControlClassName) + + val functions = validSymbol.getAllMethods(false, false, "") + functions.forEachFun { funIdx, function -> + + val bindAnn = function.getAnnotationsByType(BindInstance::class).firstOrNull() + val idArguments = function.parameters.identifierParameters(identifierTypes) + + val returnType = function.returnType?.resolve()?.toTypeName() ?: return@forEachFun + val nonWrappedType = wrapHelper.nonWrappedType(returnType) + val gcScopes = (function.scopeAnnotations + .map { it.annotationType.resolve().toTypeName() } + .toSet() + GcAllScope::class.asClassName()).toMutableSet() + + if (bindAnn == null || function.isBindInstanceMethod != BindInstanceType.BindInstanceAndProvide) + return@forEachFun + + val itemHolderCodeHelper = ItemHolderCodeHelper.of( + fieldName = "${function.simpleName.asString()}$funIdx", + returnType = returnType, + idArguments = idArguments, + cacheType = bindAnn.cache.toItemCacheType(), + wrapHelper = wrapHelper, + ) + gcScopes += bindAnn.cache.toItemCacheType().gcScopeClassName + codeBlocks.switchRefStatementBuilders.getOrPut(gcScopes) { CodeBlock.builder() } + .add(itemHolderCodeHelper.statementSwitchRef(CodeBlock.of("__params"))) + + codeBlocks.clearNullsMethodBody.add(itemHolderCodeHelper.clearNullsStatement()) + + + with(itemHolderCodeHelper) { + genCacheField() + + codeBlocks.bindMethodBody.apply { + add( + "if (or is %T && or::class == %T::class) {\n", + nonWrappedType, + nonWrappedType, + ) + add(codeSetCachedValue(CodeBlock.of("or"), false)) + add("\n") + add("%L = true\n", appliedLocalFieldName) + add("}\n") + } + } + + genBindInstance( + function = function, + idArguments = idArguments, + itemHolderCodeHelper = itemHolderCodeHelper, + wrapHelper = wrapHelper, + ) + genCacheControlFun( + function = function, + idArguments = idArguments, + itemHolderCodeHelper = itemHolderCodeHelper, + ) + } + genIModelMethods( - codeBlocks = delayedCodeBlocks, + genHiddenModuleCl = genHiddenModuleCl, + codeBlocks = codeBlocks, ) } @@ -82,7 +165,107 @@ class GenHiddenModuleProcessor : TargetFileProcessor { ) } + private fun TypeSpec.Builder.genBindInstance( + function: KSFunctionDeclaration, + idArguments: List, + itemHolderCodeHelper: ItemHolderCodeHelper, + wrapHelper: WrapHelper, + ) { + val returnType = function.returnType?.resolve()?.toTypeName() ?: return + val setValueArg = function.parameters.firstOrNull { it.type.resolve() == returnType } + + genOverrideFun(function) { + addStatement( + "val cached = %L.get()?.%L( %T.getValueAction, %L ) ", + overridedModuleFieldName, + function.cacheControlMethodName, + CacheAction::class.asClassName(), + idArguments.joinToString(", ") { it.name!!.asString() }, + ) + addCode("if ( cached != null ) return ") + addCode( + wrapHelper.transform( + providingType = wrapHelper.listWrapTypeIfNeed(returnType), + wannaType = returnType, + code = codeBlock { add("cached") }, + ) + ) + addStatement("") + + if (setValueArg != null) { + beginControlFlow("if (%L != null)", setValueArg.name!!.asString()) + addCode( + itemHolderCodeHelper.codeSetCachedValue( + value = CodeBlock.of("%L", setValueArg.name!!.asString()), + onlyIfNull = false + ) + ) + endControlFlow(); + } + + + addCode("return ") + addCode( + wrapHelper.transform( + wrapHelper.listWrapTypeIfNeed(returnType), + returnType, + CodeBlock.of("cached"), + ) + ) + addStatement(" as %T", returnType) + } + } + + + private fun TypeSpec.Builder.genCacheControlFun( + function: KSFunctionDeclaration, + idArguments: List, + itemHolderCodeHelper: ItemHolderCodeHelper, + ) { + val returnType = function.returnType?.resolve()?.toTypeName() ?: return + genFun(function.cacheControlMethodName) { + modifiers.add(KModifier.OVERRIDE) + returns(returnType.copy(nullable = true)) + addParameter("__action", CacheAction::class) + idArguments.forEach { + addParameter(it.name!!.asString(), it.type.resolve().toTypeName()) + } + + addStatement( + "%L.get()?.%L( __action, %L ) ", + overridedModuleFieldName, + function.cacheControlMethodName, + idArguments.joinToString(", ") { it.name!!.asString() }, + ) + beginControlFlow("when (__action.type) {") + addStatement("%T.GET_VALUE -> Unit", CacheAction.ActionType::class) + //set value + beginControlFlow("%T.SET_VALUE ->", CacheAction.ActionType::class) + addCode("(__action.value as? %T)?.let { ", rawTypeOf(returnType)) + addCode(codeBlock = itemHolderCodeHelper.codeSetCachedValue(CodeBlock.of("it"), onlyIfNull = false)) + addCode("}") + endControlFlow() + //set if null value + beginControlFlow("%T.SET_IF_NULL ->", CacheAction.ActionType::class) + addCode("(__action.value as? %T)?.let { ", rawTypeOf(returnType)) + addCode(codeBlock = itemHolderCodeHelper.codeSetCachedValue(CodeBlock.of("it"), onlyIfNull = true)) + addCode("}") + endControlFlow() + // switch cache type + beginControlFlow("%T.SWITCH_CACHE ->", CacheAction.ActionType::class) + addCode(codeBlock = itemHolderCodeHelper.statementSwitchRef(CodeBlock.of("__action.swCacheParams!!"))) + endControlFlow() + + addStatement("null -> Unit") + endControlFlow() + + addCode("return ") + addCode(codeBlock = itemHolderCodeHelper.codeGetCachedValue()) + } + } + private fun TypeSpec.Builder.genIModelMethods( + genHiddenModuleCl: ClassName, codeBlocks: DelayedCodeBlocks, ) { genProperty( @@ -93,6 +276,16 @@ class GenHiddenModuleProcessor : TargetFileProcessor { initializer("null") } + val cacheControlHolder = SingleItemHolder::class.asClassName() + .parameterizedBy(genHiddenModuleCl.cacheControlStoneClName) + genProperty( + name = overridedModuleFieldName, + type = cacheControlHolder, + ) { + mutable(true) + initializer("%T(%T.WeakObject)", cacheControlHolder, StoneRefType::class) + } + genFun(initMethodName) { addModifiers(KModifier.OVERRIDE) returns(BOOLEAN) diff --git a/tests/src/main/java/com/github/klee0kai/test/di/techfactory/ITechProviderComponent.kt b/tests/src/main/java/com/github/klee0kai/test/di/techfactory/ITechProviderComponent.kt index e8ffc4d4..5140859c 100644 --- a/tests/src/main/java/com/github/klee0kai/test/di/techfactory/ITechProviderComponent.kt +++ b/tests/src/main/java/com/github/klee0kai/test/di/techfactory/ITechProviderComponent.kt @@ -1,8 +1,8 @@ package com.github.klee0kai.test.di.techfactory +import com.github.klee0kai.stone.weakref.Ref import com.github.klee0kai.stone.wrappers.LazyProvide import com.github.klee0kai.stone.wrappers.PhantomProvide -import com.github.klee0kai.stone.wrappers.Ref import com.github.klee0kai.test.di.base_phone.identifiers.PhoneOsType import com.github.klee0kai.test.di.base_phone.identifiers.PhoneOsVersion import com.github.klee0kai.test.di.base_phone.identifiers.RamSize From 687b15f07ecc4aeb3318066dde9775f30d2fe256 Mon Sep 17 00:00:00 2001 From: klee0kai Date: Tue, 9 Dec 2025 23:29:10 +0100 Subject: [PATCH 051/122] module graph collect hidden module info --- .../ksp/helpers/invokecall/InvokeCall.kt | 7 +- .../ksp/helpers/invokecall/ModulesGraph.kt | 153 ++++++++++++------ .../helpers/invokecall/model/MethodDetail.kt | 1 + .../ksp/target/component/ComponentGraphExt.kt | 8 +- .../target/component/GenComponentProcessor.kt | 2 +- 5 files changed, 111 insertions(+), 60 deletions(-) diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/invokecall/InvokeCall.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/invokecall/InvokeCall.kt index df6f25c2..ef1a08be 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/invokecall/InvokeCall.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/invokecall/InvokeCall.kt @@ -6,7 +6,6 @@ import com.github.klee0kai.thekey.stone.ksp.helpers.invokecall.model.MethodDetai import com.github.klee0kai.thekey.stone.ksp.helpers.invokecall.model.QualifierAnn import com.github.klee0kai.thekey.stone.ksp.helpers.wrap.WrapHelper import com.github.klee0kai.thekey.stone.ksp.utils.LocalFieldName -import com.google.devtools.ksp.symbol.KSAnnotation import com.squareup.kotlinpoet.CodeBlock import com.squareup.kotlinpoet.ParameterizedTypeName.Companion.parameterizedBy import com.squareup.kotlinpoet.TypeName @@ -114,7 +113,11 @@ class InvokeCall( } if (invokeCount++ > 0) invokeBuilder.add(".") - invokeBuilder.add("%L(%L)", m.methodName, argsCodeBuilder.build()) + if (m.isProperty) { + invokeBuilder.add("%L", m.methodName) + } else { + invokeBuilder.add("%L(%L)", m.methodName, argsCodeBuilder.build()) + } } return invokeBuilder.build() diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/invokecall/ModulesGraph.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/invokecall/ModulesGraph.kt index ed11843d..8c7fdcaa 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/invokecall/ModulesGraph.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/invokecall/ModulesGraph.kt @@ -7,25 +7,22 @@ import com.github.klee0kai.stone.__hidden__.provide.ProvideBuilder import com.github.klee0kai.stone.annotations.module.BindInstance import com.github.klee0kai.stone.annotations.module.Provide import com.github.klee0kai.stone.weakref.Ref -import com.github.klee0kai.thekey.stone.ksp.exceptions.IncorrectSignatureException -import com.github.klee0kai.thekey.stone.ksp.exceptions.ObjectNotProvidedException -import com.github.klee0kai.thekey.stone.ksp.exceptions.RecursiveProviding -import com.github.klee0kai.thekey.stone.ksp.exceptions.StoneException +import com.github.klee0kai.thekey.stone.ksp.exceptions.* import com.github.klee0kai.thekey.stone.ksp.helpers.cacheControlMethodName +import com.github.klee0kai.thekey.stone.ksp.helpers.hiddenModuleStoneClName import com.github.klee0kai.thekey.stone.ksp.helpers.identifierParameters import com.github.klee0kai.thekey.stone.ksp.helpers.invokecall.model.* import com.github.klee0kai.thekey.stone.ksp.helpers.qualifierAnnotations import com.github.klee0kai.thekey.stone.ksp.helpers.wrap.WrapHelper import com.github.klee0kai.thekey.stone.ksp.ksp.getAllMethods import com.github.klee0kai.thekey.stone.ksp.ksp.isNotPrimitive +import com.github.klee0kai.thekey.stone.ksp.target.component.* import com.github.klee0kai.thekey.stone.ksp.utils.LocalFieldName.genLocalFieldName import com.github.klee0kai.thekey.stone.ksp.utils.RecursiveDetector import com.github.klee0kai.thekey.stone.ksp.utils.removeDoubles import com.google.devtools.ksp.KspExperimental import com.google.devtools.ksp.getAnnotationsByType -import com.google.devtools.ksp.symbol.KSAnnotation import com.google.devtools.ksp.symbol.KSClassDeclaration -import com.google.devtools.ksp.symbol.KSFunctionDeclaration import com.google.devtools.ksp.symbol.KSType import com.squareup.kotlinpoet.ClassName import com.squareup.kotlinpoet.CodeBlock @@ -43,57 +40,113 @@ class ModulesGraph( private val provideTypeCodes = HashMap>() private val cacheControlTypeCodes = HashMap>() - /** - * Methods graph build. - * - * @param provideModuleMethod module's provide method - * @param module module's class - */ - fun collectFromModule( - provideModuleMethod: KSFunctionDeclaration?, + + fun collectFromComponent( + componentCl: KSClassDeclaration, ) { - val module = provideModuleMethod?.returnType?.resolve()?.declaration as? KSClassDeclaration ?: return - for (m in module.getAllMethods(false, true, "")) { - if (m.returnType?.resolve()?.isNotPrimitive == false) continue - val returnType = m.returnType?.resolve()?.toTypeName() ?: continue - val provTypeName = wrapHelper.nonWrappedType(returnType) - val isCached = m.getAnnotationsByType(Provide::class) - .firstOrNull()?.cache !in listOf(Provide.CacheType.Factory, null) - val isBindInstance = m.getAnnotationsByType(BindInstance::class).firstOrNull() != null - - provideTypeCodes.putIfAbsent(provTypeName, HashSet()) - provideTypeCodes[provTypeName]?.add( - InvokeCall.fromSequence( - wrapHelper = wrapHelper, - callSequence = listOf(provideModuleMethod.toMethodDetail(), m.toMethodDetail()), - flags = InvokeProvideFlags( - provideObjectCached = isCached, - provideBindInstance = isBindInstance, - ), - ) - ) + val componentsAllMethods = componentCl + .getAllMethods(includeObjectMethods = false, allowDoubles = false, "") + val hiddenModuleProvideMethod = MethodDetail( + methodName = GenComponentProcessor.hiddenModuleFieldName, + returnType = componentCl.hiddenModuleStoneClName, + isProperty = true, + ) - val cacheControlMethod = MethodDetail( - methodName = m.cacheControlMethodName, - returnType = wrapHelper.listWrapTypeIfNeed(returnType), - qualifierAnns = m.qualifierAnnotations.map { it.toQualifierAnn() }.toSet(), - args = buildList { - add(FieldDetail.simple("__action", CacheAction::class.asClassName())) - addAll(m.parameters.identifierParameters(identifierTypes).map { it.toFieldDetail() }) - }, - ) + componentsAllMethods.forEachFun { _, componentMethod -> + when { + componentMethod.isModuleProvideMethod || componentMethod.isDepsProvideMethod -> { + val module = + componentMethod.returnType?.resolve()?.declaration as? KSClassDeclaration ?: return@forEachFun + for (m in module.getAllMethods(false, true, "")) { + if (m.returnType?.resolve()?.isNotPrimitive == false) continue + + val returnType = m.returnType?.resolve()?.toTypeName() ?: continue + val provTypeName = wrapHelper.nonWrappedType(returnType) + val isCached = m.getAnnotationsByType(Provide::class) + .firstOrNull()?.cache !in listOf(Provide.CacheType.Factory, null) + val isBindInstance = m.getAnnotationsByType(BindInstance::class).firstOrNull() != null + + provideTypeCodes.putIfAbsent(provTypeName, HashSet()) + provideTypeCodes[provTypeName]?.add( + InvokeCall.fromSequence( + wrapHelper = wrapHelper, + callSequence = listOf(componentMethod.toMethodDetail(), m.toMethodDetail()), + flags = InvokeProvideFlags( + provideObjectCached = isCached, + provideBindInstance = isBindInstance, + ), + ) + ) + + val cacheControlMethod = MethodDetail( + methodName = m.cacheControlMethodName, + returnType = wrapHelper.listWrapTypeIfNeed(returnType), + qualifierAnns = m.qualifierAnnotations.map { it.toQualifierAnn() }.toSet(), + args = buildList { + add(FieldDetail.simple("__action", CacheAction::class.asClassName())) + addAll(m.parameters.identifierParameters(identifierTypes).map { it.toFieldDetail() }) + }, + ) + + cacheControlTypeCodes.putIfAbsent(provTypeName, HashSet()) + cacheControlTypeCodes.get(provTypeName) + ?.add( + InvokeCall.fromSequence( + wrapHelper = wrapHelper, + callSequence = listOf(componentMethod.toMethodDetail(), cacheControlMethod) + ) + ) + } - cacheControlTypeCodes.putIfAbsent(provTypeName, HashSet()) - cacheControlTypeCodes.get(provTypeName) - ?.add( - InvokeCall.fromSequence( - wrapHelper = wrapHelper, - callSequence = listOf(provideModuleMethod.toMethodDetail(), cacheControlMethod) + } + + componentMethod.isBindInstanceMethod == BindInstanceType.BindInstanceAndProvide -> { + val returnType = componentMethod.returnType?.resolve()?.toTypeName() ?: return@forEachFun + val provTypeName = wrapHelper.nonWrappedType(returnType) + val isCached = componentMethod.getAnnotationsByType(Provide::class) + .firstOrNull()?.cache !in listOf(Provide.CacheType.Factory, null) + val isBindInstance = componentMethod.getAnnotationsByType(BindInstance::class).firstOrNull() != null + + provideTypeCodes.putIfAbsent(provTypeName, HashSet()) + provideTypeCodes[provTypeName]?.add( + InvokeCall.fromSequence( + wrapHelper = wrapHelper, + callSequence = listOf(hiddenModuleProvideMethod, componentMethod.toMethodDetail()), + flags = InvokeProvideFlags( + provideObjectCached = isCached, + provideBindInstance = isBindInstance, + ), + ) ) - ) + + val cacheControlMethod = MethodDetail( + methodName = componentMethod.cacheControlMethodName, + returnType = wrapHelper.listWrapTypeIfNeed(returnType), + qualifierAnns = componentMethod.qualifierAnnotations.map { it.toQualifierAnn() }.toSet(), + args = buildList { + add(FieldDetail.simple("__action", CacheAction::class.asClassName())) + addAll( + componentMethod.parameters.identifierParameters(identifierTypes) + .map { it.toFieldDetail() }) + }, + ) + + cacheControlTypeCodes.putIfAbsent(provTypeName, HashSet()) + cacheControlTypeCodes[provTypeName] + ?.add( + InvokeCall.fromSequence( + wrapHelper = wrapHelper, + callSequence = listOf(componentMethod.toMethodDetail(), cacheControlMethod) + ) + ) + } + } } + + } + fun codeProvideType( methodName: String?, returnType: TypeName, diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/invokecall/model/MethodDetail.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/invokecall/model/MethodDetail.kt index 32489b8b..7a66e1ef 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/invokecall/model/MethodDetail.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/invokecall/model/MethodDetail.kt @@ -11,6 +11,7 @@ data class MethodDetail( val returnType: TypeName, val args: List = emptyList(), val qualifierAnns: Set = emptySet(), + val isProperty: Boolean = false, ) { companion object; } diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/component/ComponentGraphExt.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/component/ComponentGraphExt.kt index 65c42a57..ccaabc76 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/component/ComponentGraphExt.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/component/ComponentGraphExt.kt @@ -24,12 +24,6 @@ fun KSClassDeclaration.collectComponentGraph( wrapHelper = collectWrapHelper(), identifierTypes = allIdentifierTypes.toList(), ) - for (m in getAllMethods(false, false, "")) { - if (m.isModuleProvideMethod) { - modulesGraph.collectFromModule(m) - } else if (m.isDepsProvideMethod) { - modulesGraph.collectFromModule(m) - } - } + modulesGraph.collectFromComponent(this) return modulesGraph } \ No newline at end of file diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/component/GenComponentProcessor.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/component/GenComponentProcessor.kt index 08a43bd7..23cddb34 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/component/GenComponentProcessor.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/component/GenComponentProcessor.kt @@ -292,7 +292,7 @@ class GenComponentProcessor : TargetFileProcessor { } addStatement( - "%L.%L = %L", + "%L?.%L = %L", injectableField.name!!.asString(), injectField.simpleName.asString(), provideCode, From 72b03317366be9c82d0e7764a7cb73ad9cdc778b Mon Sep 17 00:00:00 2001 From: klee0kai Date: Wed, 10 Dec 2025 00:03:56 +0100 Subject: [PATCH 052/122] module and hidden module methods --- .../stone/ksp/target/GenModuleProcessor.kt | 109 ++++++++++++------ .../hiddenmodule/GenHiddenModuleProcessor.kt | 67 +++++++++-- 2 files changed, 131 insertions(+), 45 deletions(-) diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/GenModuleProcessor.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/GenModuleProcessor.kt index af287214..5b24af71 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/GenModuleProcessor.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/GenModuleProcessor.kt @@ -15,6 +15,7 @@ import com.github.klee0kai.stone.weakref.Ref import com.github.klee0kai.thekey.stone.ksp.exceptions.forEachFun import com.github.klee0kai.thekey.stone.ksp.helpers.* import com.github.klee0kai.thekey.stone.ksp.helpers.annotations.annotations +import com.github.klee0kai.thekey.stone.ksp.helpers.annotations.anyAnnotation import com.github.klee0kai.thekey.stone.ksp.helpers.itemholder.ItemHolderCodeHelper import com.github.klee0kai.thekey.stone.ksp.helpers.itemholder.of import com.github.klee0kai.thekey.stone.ksp.helpers.itemholder.toItemCacheType @@ -249,7 +250,7 @@ class GenModuleProcessor : TargetFileProcessor { wrapHelper: WrapHelper, ) { val returnType = function.returnType?.resolve()?.toTypeName() ?: return - val setValueArg = function.parameters.firstOrNull { it.type.resolve() == returnType } + val setValueArg = function.parameters.firstOrNull { it.type.resolve().toTypeName() == returnType } genOverrideFun(function) { addStatement( @@ -286,7 +287,7 @@ class GenModuleProcessor : TargetFileProcessor { wrapHelper.transform( wrapHelper.listWrapTypeIfNeed(returnType), returnType, - CodeBlock.of("cached"), + itemHolderCodeHelper.codeGetCachedValue(), ) ) addStatement(" as %T", returnType) @@ -461,40 +462,7 @@ class GenModuleProcessor : TargetFileProcessor { addStatement("return %L", appliedLocalFieldName) } - genFun(initCachesFromMethodName) { - addModifiers(KModifier.OVERRIDE) - addParameter("m", IModule::class) - addStatement("if (m == this) return") - (sequenceOf(moduleCl) + moduleCl.getAllSuperTypes().map { it.declaration }) - .filter { it.annotations(Module::class.asClassName()).any() } - .mapNotNull { it as? KSClassDeclaration } - .forEach { cl -> - val cacheControlCl = cl.toClassName().cacheControlStoneClName - beginControlFlow("if ( m is %T )", cacheControlCl) - addStatement("val module = m as %T", cacheControlCl) - - cl.getAllMethods( - includeObjectMethods = false, - allowDoubles = false, - exceptNames = arrayOf(""), - ).forEach { protoProvideMethod -> - val cacheControlMethod = protoProvideMethod.cacheControlMethodName - val idArguments = protoProvideMethod.parameters - .filter { it.type.resolve() in identifierTypes } - if (!idArguments.isEmpty()) { - // TODO https://github.com/klee0kai/stone/issues/42 - return@forEach - } - addStatement( - "%L( %T.setIfNullValueAction( module.%L( %T.getValueAction ) ) )", - cacheControlMethod, CacheAction::class, - cacheControlMethod, CacheAction::class, - ); - } - endControlFlow() - } - } genFun(bindMethodName) { addModifiers(KModifier.OVERRIDE) @@ -531,10 +499,81 @@ class GenModuleProcessor : TargetFileProcessor { } } + + genFun(initCachesFromMethodName) { + addModifiers(KModifier.OVERRIDE) + addParameter("m", IModule::class) + addStatement("if (m == this) return") + (sequenceOf(moduleCl) + moduleCl.getAllSuperTypes().map { it.declaration }) + .filter { it.annotations(Module::class.asClassName()).any() } + .mapNotNull { it as? KSClassDeclaration } + .forEach { cl -> + val cacheControlCl = cl.toClassName().cacheControlStoneClName + beginControlFlow("if ( m is %T )", cacheControlCl) + addStatement("val module = m as %T", cacheControlCl) + + cl.getAllMethods( + includeObjectMethods = false, + allowDoubles = false, + exceptNames = arrayOf(""), + ).forEach { protoProvideMethod -> + val cacheControlMethod = protoProvideMethod.cacheControlMethodName + val idArguments = protoProvideMethod.parameters + .filter { it.type.resolve() in identifierTypes } + if (!idArguments.isEmpty()) { + // TODO https://github.com/klee0kai/stone/issues/42 + return@forEach + } + + addStatement( + "%L( %T.setIfNullValueAction( module.%L( %T.getValueAction ) ) )", + cacheControlMethod, CacheAction::class, + cacheControlMethod, CacheAction::class, + ); + } + endControlFlow() + } + } + genFun(updateBindInstancesFrom) { addModifiers(KModifier.OVERRIDE) addParameter("m", IModule::class) addStatement("if (m == this) return") + moduleCl.getAllSuperTypes() + + (sequenceOf(moduleCl) + moduleCl.getAllSuperTypes().map { it.declaration }) + .filter { it.annotations(Module::class.asClassName()).any() } + .mapNotNull { it as? KSClassDeclaration } + .forEach { cl -> + val cacheControlCl = cl.toClassName().cacheControlStoneClName + beginControlFlow("if ( m is %T )", cacheControlCl) + addStatement("val module = m as %T", cacheControlCl) + + cl.getAllMethods( + includeObjectMethods = false, + allowDoubles = false, + exceptNames = arrayOf(""), + ).forEach { protoProvideMethod -> + if (protoProvideMethod.anyAnnotation(BindInstance::class.asClassName()).none()) { + return@forEach + } + + val cacheControlMethod = protoProvideMethod.cacheControlMethodName + val idArguments = protoProvideMethod.parameters + .filter { it.type.resolve() in identifierTypes } + if (!idArguments.isEmpty()) { + // TODO https://github.com/klee0kai/stone/issues/42 + return@forEach + } + + addStatement( + "%L( %T.setValueAction( module.%L( %T.getValueAction ) ) )", + cacheControlMethod, CacheAction::class, + cacheControlMethod, CacheAction::class, + ); + } + endControlFlow() + } } genFun(clearNullsMethodName) { diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/hiddenmodule/GenHiddenModuleProcessor.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/hiddenmodule/GenHiddenModuleProcessor.kt index 95e42cbc..ce1d7b82 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/hiddenmodule/GenHiddenModuleProcessor.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/hiddenmodule/GenHiddenModuleProcessor.kt @@ -151,7 +151,7 @@ class GenHiddenModuleProcessor : TargetFileProcessor { } genIModelMethods( - genHiddenModuleCl = genHiddenModuleCl, + componentCl = componentCl, codeBlocks = codeBlocks, ) } @@ -172,7 +172,7 @@ class GenHiddenModuleProcessor : TargetFileProcessor { wrapHelper: WrapHelper, ) { val returnType = function.returnType?.resolve()?.toTypeName() ?: return - val setValueArg = function.parameters.firstOrNull { it.type.resolve() == returnType } + val setValueArg = function.parameters.firstOrNull { it.type.resolve().toTypeName() == returnType } genOverrideFun(function) { addStatement( @@ -209,7 +209,7 @@ class GenHiddenModuleProcessor : TargetFileProcessor { wrapHelper.transform( wrapHelper.listWrapTypeIfNeed(returnType), returnType, - CodeBlock.of("cached"), + itemHolderCodeHelper.codeGetCachedValue(), ) ) addStatement(" as %T", returnType) @@ -265,7 +265,8 @@ class GenHiddenModuleProcessor : TargetFileProcessor { } private fun TypeSpec.Builder.genIModelMethods( - genHiddenModuleCl: ClassName, + componentCl: KSClassDeclaration, + codeBlocks: DelayedCodeBlocks, ) { genProperty( @@ -277,7 +278,7 @@ class GenHiddenModuleProcessor : TargetFileProcessor { } val cacheControlHolder = SingleItemHolder::class.asClassName() - .parameterizedBy(genHiddenModuleCl.cacheControlStoneClName) + .parameterizedBy(componentCl.hiddenModuleStoneClName.cacheControlStoneClName) genProperty( name = overridedModuleFieldName, type = cacheControlHolder, @@ -296,11 +297,7 @@ class GenHiddenModuleProcessor : TargetFileProcessor { addStatement("return %L", appliedLocalFieldName) } - genFun(initCachesFromMethodName) { - addModifiers(KModifier.OVERRIDE) - addParameter("m", IModule::class) - addStatement("if (m == this) return") - } + genFun(bindMethodName) { addModifiers(KModifier.OVERRIDE) @@ -335,10 +332,60 @@ class GenHiddenModuleProcessor : TargetFileProcessor { } } + genFun(initCachesFromMethodName) { + addModifiers(KModifier.OVERRIDE) + addParameter("m", IModule::class) + addStatement("if (m == this) return") + + val cacheControlCl = componentCl.hiddenModuleStoneClName.cacheControlStoneClName + beginControlFlow("if ( m is %T )", cacheControlCl) + addStatement("val module = m as %T", cacheControlCl) + componentCl.getAllMethods( + includeObjectMethods = false, + allowDoubles = false, + exceptNames = arrayOf(""), + ).forEach { protoProvideMethod -> + if (protoProvideMethod.isBindInstanceMethod != BindInstanceType.BindInstanceAndProvide) { + return@forEach + } + + val cacheControlMethod = protoProvideMethod.cacheControlMethodName + + addStatement( + "%L( %T.setIfNullValueAction( module.%L( %T.getValueAction ) ) )", + cacheControlMethod, CacheAction::class, + cacheControlMethod, CacheAction::class, + ) + } + endControlFlow() + } + genFun(updateBindInstancesFrom) { addModifiers(KModifier.OVERRIDE) addParameter("m", IModule::class) addStatement("if (m == this) return") + + val cacheControlCl = componentCl.hiddenModuleStoneClName.cacheControlStoneClName + beginControlFlow("if ( m is %T )", cacheControlCl) + addStatement("val module = m as %T", cacheControlCl) + componentCl.getAllMethods( + includeObjectMethods = false, + allowDoubles = false, + exceptNames = arrayOf(""), + ).forEach { protoProvideMethod -> + if (protoProvideMethod.isBindInstanceMethod != BindInstanceType.BindInstanceAndProvide) { + return@forEach + } + + val cacheControlMethod = protoProvideMethod.cacheControlMethodName + + addStatement( + "%L( %T.setValueAction( module.%L( %T.getValueAction ) ) )", + cacheControlMethod, CacheAction::class, + cacheControlMethod, CacheAction::class, + ); + } + endControlFlow() } genFun(clearNullsMethodName) { From df151236abf562e6118cd5eff2b8a883b753f77a Mon Sep 17 00:00:00 2001 From: klee0kai Date: Wed, 10 Dec 2025 22:05:06 +0100 Subject: [PATCH 053/122] correct module generation based on old kapt generation --- .../stone/ksp/target/GenModuleProcessor.kt | 18 ++++++++++++------ .../hiddenmodule/GenHiddenModuleProcessor.kt | 18 ++++++++++++------ 2 files changed, 24 insertions(+), 12 deletions(-) diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/GenModuleProcessor.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/GenModuleProcessor.kt index 5b24af71..dc6a6a09 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/GenModuleProcessor.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/GenModuleProcessor.kt @@ -376,15 +376,21 @@ class GenModuleProcessor : TargetFileProcessor { addStatement("%T.GET_VALUE -> Unit", CacheAction.ActionType::class) //set value beginControlFlow("%T.SET_VALUE ->", CacheAction.ActionType::class) - addCode("(__action.value as? %T)?.let { ", rawTypeOf(returnType)) - addCode(codeBlock = itemHolderCodeHelper.codeSetCachedValue(CodeBlock.of("it"), onlyIfNull = false)) - addCode("}") + addCode( + codeBlock = itemHolderCodeHelper.codeSetCachedValue( + CodeBlock.of("__action.value as? %T", rawTypeOf(returnType)), + onlyIfNull = false + ) + ) endControlFlow() //set if null value beginControlFlow("%T.SET_IF_NULL ->", CacheAction.ActionType::class) - addCode("(__action.value as? %T)?.let { ", rawTypeOf(returnType)) - addCode(codeBlock = itemHolderCodeHelper.codeSetCachedValue(CodeBlock.of("it"), onlyIfNull = true)) - addCode("}") + addCode( + codeBlock = itemHolderCodeHelper.codeSetCachedValue( + CodeBlock.of("__action.value as? %T", rawTypeOf(returnType)), + onlyIfNull = true + ) + ) endControlFlow() // switch cache type beginControlFlow("%T.SWITCH_CACHE ->", CacheAction.ActionType::class) diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/hiddenmodule/GenHiddenModuleProcessor.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/hiddenmodule/GenHiddenModuleProcessor.kt index ce1d7b82..410e0a50 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/hiddenmodule/GenHiddenModuleProcessor.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/hiddenmodule/GenHiddenModuleProcessor.kt @@ -241,15 +241,21 @@ class GenHiddenModuleProcessor : TargetFileProcessor { addStatement("%T.GET_VALUE -> Unit", CacheAction.ActionType::class) //set value beginControlFlow("%T.SET_VALUE ->", CacheAction.ActionType::class) - addCode("(__action.value as? %T)?.let { ", rawTypeOf(returnType)) - addCode(codeBlock = itemHolderCodeHelper.codeSetCachedValue(CodeBlock.of("it"), onlyIfNull = false)) - addCode("}") + addCode( + codeBlock = itemHolderCodeHelper.codeSetCachedValue( + CodeBlock.of("__action.value as? %T", rawTypeOf(returnType)), + onlyIfNull = false, + ) + ) endControlFlow() //set if null value beginControlFlow("%T.SET_IF_NULL ->", CacheAction.ActionType::class) - addCode("(__action.value as? %T)?.let { ", rawTypeOf(returnType)) - addCode(codeBlock = itemHolderCodeHelper.codeSetCachedValue(CodeBlock.of("it"), onlyIfNull = true)) - addCode("}") + addCode( + codeBlock = itemHolderCodeHelper.codeSetCachedValue( + CodeBlock.of("__action.value as? %T", rawTypeOf(returnType)), + onlyIfNull = true, + ) + ) endControlFlow() // switch cache type beginControlFlow("%T.SWITCH_CACHE ->", CacheAction.ActionType::class) From a8bee5c596ea5586726a68e82a4405e9952153d4 Mon Sep 17 00:00:00 2001 From: klee0kai Date: Wed, 10 Dec 2025 22:15:28 +0100 Subject: [PATCH 054/122] object provide method --- .../target/component/GenComponentProcessor.kt | 34 ++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/component/GenComponentProcessor.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/component/GenComponentProcessor.kt index 23cddb34..8cfc8d85 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/component/GenComponentProcessor.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/component/GenComponentProcessor.kt @@ -193,7 +193,11 @@ class GenComponentProcessor : TargetFileProcessor { } m.isObjectProvideMethod -> { - + genProvideObjMethod( + componentCl = componentCl, + method = m, + modulesGraph = modulesGraph, + ) } m.isBindInstanceMethod != null -> { @@ -246,6 +250,34 @@ class GenComponentProcessor : TargetFileProcessor { ) } + private fun TypeSpec.Builder.genProvideObjMethod( + componentCl: KSClassDeclaration, + method: KSFunctionDeclaration, + modulesGraph: ModulesGraph, + ) { + val returnType = method.returnType?.resolve()?.toTypeName() ?: return + + val codeBlock = modulesGraph.codeProvideType( + methodName = null, + returnType = returnType, + qualifierAnns = method.qualifierAnnotations.map { it.toQualifierAnn() }.toSet(), + declaredFields = method.parameters.map { it.toFieldDetail() }, + ) + + if (codeBlock == null) { + throw ObjectNotProvidedException( + message = "Error provide type ${returnType}. " + + "Required in ${componentCl.toClassName()}.${method.simpleName.asString()}", + element = method, + ) + } + + genOverrideFun(method) { + addStatement("return %L", codeBlock) + } + + } + private fun TypeSpec.Builder.genInjectMethod( componentCl: KSClassDeclaration, From 1b4d1b980cfab01dd21ab43137995cb5547573d9 Mon Sep 17 00:00:00 2001 From: klee0kai Date: Wed, 10 Dec 2025 22:42:52 +0100 Subject: [PATCH 055/122] protect injected. gen gc method --- .../target/component/GenComponentProcessor.kt | 112 +++++++++++++++++- .../github/klee0kai/stone/weakref/Memory.kt | 7 ++ .../klee0kai/stone/weakref/Memory.jvm.kt | 9 ++ .../klee0kai/stone/weakref/Memory.native.kt | 15 +++ .../klee0kai/stone/weakref/Memory.web.kt | 11 ++ 5 files changed, 151 insertions(+), 3 deletions(-) create mode 100644 weakref_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/weakref/Memory.kt create mode 100644 weakref_multiplatform/src/jvmMain/java/com/github/klee0kai/stone/weakref/Memory.jvm.kt create mode 100644 weakref_multiplatform/src/nativeMain/kotlin/com/github/klee0kai/stone/weakref/Memory.native.kt create mode 100644 weakref_multiplatform/src/webMain/kotlin/com/github/klee0kai/stone/weakref/Memory.web.kt diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/component/GenComponentProcessor.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/component/GenComponentProcessor.kt index 8cfc8d85..5fbb9de9 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/component/GenComponentProcessor.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/component/GenComponentProcessor.kt @@ -1,14 +1,19 @@ +@file:OptIn(KspExperimental::class) + package com.github.klee0kai.thekey.stone.ksp.target.component import com.github.klee0kai.stone.__hidden__.IModule import com.github.klee0kai.stone.__hidden__.IPrivateComponent +import com.github.klee0kai.stone.__hidden__.SwitchCacheParam import com.github.klee0kai.stone.__hidden__.collections.RefCollection import com.github.klee0kai.stone.__hidden__.types.WeakList import com.github.klee0kai.stone.__hidden__.types.holders.TimeHolder import com.github.klee0kai.stone.annotations.component.Component +import com.github.klee0kai.stone.annotations.component.ProtectInjected import com.github.klee0kai.stone.annotations.dependencies.Dependencies import com.github.klee0kai.stone.annotations.module.Module import com.github.klee0kai.stone.weakref.Inject +import com.github.klee0kai.stone.weakref.Memory import com.github.klee0kai.thekey.stone.ksp.exceptions.IncorrectSignatureException import com.github.klee0kai.thekey.stone.ksp.exceptions.ObjectNotProvidedException import com.github.klee0kai.thekey.stone.ksp.exceptions.forEachFun @@ -25,8 +30,10 @@ import com.github.klee0kai.thekey.stone.ksp.ksp.getAllMethods import com.github.klee0kai.thekey.stone.ksp.poet.* import com.github.klee0kai.thekey.stone.ksp.poet.member.CoroutinesMemberFunctions.SupervisorJob import com.github.klee0kai.thekey.stone.ksp.target.GenModuleProcessor +import com.google.devtools.ksp.KspExperimental import com.google.devtools.ksp.containingFile import com.google.devtools.ksp.getAllSuperTypes +import com.google.devtools.ksp.getAnnotationsByType import com.google.devtools.ksp.processing.KSPLogger import com.google.devtools.ksp.processing.Resolver import com.google.devtools.ksp.symbol.ClassKind @@ -38,6 +45,7 @@ import com.squareup.kotlinpoet.ParameterizedTypeName.Companion.parameterizedBy import com.squareup.kotlinpoet.ksp.toClassName import com.squareup.kotlinpoet.ksp.toTypeName import kotlinx.coroutines.CoroutineScope +import kotlin.reflect.KClass import com.google.devtools.ksp.processing.Dependencies as KspDependencies class GenComponentProcessor : TargetFileProcessor { @@ -205,7 +213,11 @@ class GenComponentProcessor : TargetFileProcessor { } m.isGcMethod -> { - + genGcMthod( + componentCl = componentCl, + method = m, + wrapHelper = wrapHelper, + ) } m.isSwitchCacheMethod -> { @@ -222,7 +234,11 @@ class GenComponentProcessor : TargetFileProcessor { } m.isProtectInjectedMethod -> { - + genProtectInjected( + componentCl = componentCl, + method = m, + wrapHelper = wrapHelper, + ) } m.isAbstract -> { @@ -388,7 +404,7 @@ class GenComponentProcessor : TargetFileProcessor { emptyCode = false subscrCode.addStatement( - "%L.add( %T( %L, %L.%L , timeMillis) )", + "%L.add( %T( %L, %L?.%L , timeMillis) )", refCollectionGlFieldName, TimeHolder::class.asClassName(), scopeFieldName, @@ -406,6 +422,96 @@ class GenComponentProcessor : TargetFileProcessor { } } + private fun TypeSpec.Builder.genProtectInjected( + componentCl: KSClassDeclaration, + method: KSFunctionDeclaration, + wrapHelper: WrapHelper, + ) { + val protectTimeMillis = method.getAnnotationsByType(ProtectInjected::class) + .firstOrNull()?.timeMillis + ?: throw IncorrectSignatureException( + message = "Use ProtectInjected annotation at method ${componentCl.simpleName.asString()}.${method.simpleName.asString()}", + element = method, + ) + val identifierTypes = componentCl.allIdentifierTypes.toList() + val injectableArguments = method.parameters.notIdentifierParameters(identifierTypes) + if (injectableArguments.isEmpty()) { + throw IncorrectSignatureException( + message = "No injectable parameter at ${method.simpleName.asString()}", + element = method, + ) + } + + + genOverrideFun(method) { + for (injectableField in injectableArguments) { + val injectableCl = injectableField.type.resolve().declaration as? KSClassDeclaration + ?: throw IncorrectSignatureException( + message = "parameter must be a class", + element = injectableField, + ) + + + for (injectField in injectableCl.getAllProperties()) { + if (!injectField.anyAnnotation(Inject::class.asClassName()).any()) continue + if (wrapHelper.isNonCachingWrapper(injectField.type.resolve().toTypeName())) { //nothing to protect + continue + } + + addStatement( + "%L.add( %T( %L, %L?.%L , %L ) )", + refCollectionGlFieldName, + TimeHolder::class.asClassName(), + scopeFieldName, + injectableField.name!!.asString(), + injectField.simpleName.asString(), + protectTimeMillis, + ) + } + } + } + } + + private fun TypeSpec.Builder.genGcMthod( + componentCl: KSClassDeclaration, + method: KSFunctionDeclaration, + wrapHelper: WrapHelper, + ) { + + val scopesCode = codeBlock { + method.scopeAnnotations.forEachIndexed { index, annotation -> + if (index > 0) add(", ") + add("%T::class", annotation.annotationType.resolve().toTypeName()) + } + } + + + genOverrideFun(method) { + addStatement( + "val scopes = setOf<%T>( %L )", + KClass::class.asClassName().parameterizedBy(STAR), scopesCode + ) + addStatement("val toWeak = %T.toWeak()", SwitchCacheParam::class) + addStatement("val toDef = %T.toDef()", SwitchCacheParam::class) + + addStatement( + "%L{ m -> m.%L(scopes, toWeak) } ", + eachModuleMethodName, + GenModuleProcessor.switchRefMethodName, + ) + + addStatement("%T.gc()", Memory::class) + addStatement("%L.clearNulls()", relatedComponentsListFieldName) + addStatement( + + "%L{ m -> m.__clearNulls(); m.%L(scopes, toDef); }", + eachModuleMethodName, GenModuleProcessor.switchRefMethodName, + ) + + addStatement("%L.clearNulls()", refCollectionGlFieldName); + } + } + private fun TypeSpec.Builder.genIComponentMethods( componentCl: KSClassDeclaration, delayedCodeBlocks: DelayedCodeBlocks, diff --git a/weakref_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/weakref/Memory.kt b/weakref_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/weakref/Memory.kt new file mode 100644 index 00000000..e63fb404 --- /dev/null +++ b/weakref_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/weakref/Memory.kt @@ -0,0 +1,7 @@ +package com.github.klee0kai.stone.weakref + +expect object Memory { + + fun gc() + +} \ No newline at end of file diff --git a/weakref_multiplatform/src/jvmMain/java/com/github/klee0kai/stone/weakref/Memory.jvm.kt b/weakref_multiplatform/src/jvmMain/java/com/github/klee0kai/stone/weakref/Memory.jvm.kt new file mode 100644 index 00000000..de0e5b50 --- /dev/null +++ b/weakref_multiplatform/src/jvmMain/java/com/github/klee0kai/stone/weakref/Memory.jvm.kt @@ -0,0 +1,9 @@ +package com.github.klee0kai.stone.weakref + +actual object Memory { + + actual fun gc() { + System.gc() + } + +} \ No newline at end of file diff --git a/weakref_multiplatform/src/nativeMain/kotlin/com/github/klee0kai/stone/weakref/Memory.native.kt b/weakref_multiplatform/src/nativeMain/kotlin/com/github/klee0kai/stone/weakref/Memory.native.kt new file mode 100644 index 00000000..2e9a2e2e --- /dev/null +++ b/weakref_multiplatform/src/nativeMain/kotlin/com/github/klee0kai/stone/weakref/Memory.native.kt @@ -0,0 +1,15 @@ +@file:OptIn(NativeRuntimeApi::class) + +package com.github.klee0kai.stone.weakref + +import kotlin.native.runtime.NativeRuntimeApi + +actual object Memory { + + actual fun gc() { + runCatching { + kotlin.native.runtime.GC.collect() + } + } + +} \ No newline at end of file diff --git a/weakref_multiplatform/src/webMain/kotlin/com/github/klee0kai/stone/weakref/Memory.web.kt b/weakref_multiplatform/src/webMain/kotlin/com/github/klee0kai/stone/weakref/Memory.web.kt new file mode 100644 index 00000000..81d3f0d9 --- /dev/null +++ b/weakref_multiplatform/src/webMain/kotlin/com/github/klee0kai/stone/weakref/Memory.web.kt @@ -0,0 +1,11 @@ +package com.github.klee0kai.stone.weakref + +actual object Memory { + + actual fun gc() { + runCatching { + js("gc()") + } + } + +} \ No newline at end of file From ff944fa72d3898b183a1bd05654299362e00e5bd Mon Sep 17 00:00:00 2001 From: klee0kai Date: Wed, 10 Dec 2025 23:39:35 +0100 Subject: [PATCH 056/122] fix code provide cases --- .../klee0kai/thekey/stone/ksp/Processor.kt | 22 ++++++++----- .../thekey/stone/ksp/exceptions/WrapExt.kt | 2 +- .../helpers/annotations/ComponentAnnMirror.kt | 33 +++++++++++++++++-- .../ksp/helpers/invokecall/ModulesGraph.kt | 16 ++++----- .../target/component/ComponentsMethodsExt.kt | 7 +++- .../target/component/GenComponentProcessor.kt | 11 ++++--- .../simple/GodWorkspaceComponent.kt | 1 - .../singlemethod_gc/PlanetRollingComponent.kt | 1 + 8 files changed, 66 insertions(+), 27 deletions(-) diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/Processor.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/Processor.kt index fb5b2b6b..48a517ad 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/Processor.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/Processor.kt @@ -2,6 +2,7 @@ package com.github.klee0kai.thekey.stone.ksp import com.github.klee0kai.thekey.stone.ksp.coroutines.LaunchConductor import com.github.klee0kai.thekey.stone.ksp.exceptions.StoneException +import com.github.klee0kai.thekey.stone.ksp.exceptions.wrapKsNoteInfo import com.github.klee0kai.thekey.stone.ksp.ksp.arch.GenSpec import com.github.klee0kai.thekey.stone.ksp.ksp.arch.filter import com.github.klee0kai.thekey.stone.ksp.ksp.arch.forceProcess @@ -61,8 +62,8 @@ class Processor( debugPkgFilter = options["debugPkgFilter"] // force changes - debug = true - debugPkgFilter = "com.github.klee0kai.test.di.bindinstance.singlemethod_inject" +// debug = true +// debugPkgFilter = "com.github.klee0kai.test.di.house.simple" } @@ -150,13 +151,18 @@ class Processor( // with symbol resolution so that the processor can link the input and output of generation generateCodeJob.join() - genSpecs.forEach { genSpec -> - genSpec?.fileSpec?.writeTo( - codeGenerator = codeGenerator, - dependencies = genSpec.dependencies - ) + try { + genSpecs.forEach { genSpec -> + wrapKsNoteInfo(genSpec.dependencies.originatingFiles.firstOrNull()) { + genSpec?.fileSpec?.writeTo( + codeGenerator = codeGenerator, + dependencies = genSpec.dependencies + ) + } + } + } catch (e: StoneException) { + logger.error(e.toString(), e.findLastErrorElement()) } - globalSymbolsForReprocessing.toList() } diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/exceptions/WrapExt.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/exceptions/WrapExt.kt index dee64aa5..9caa9c52 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/exceptions/WrapExt.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/exceptions/WrapExt.kt @@ -4,7 +4,7 @@ import com.google.devtools.ksp.symbol.KSFunctionDeclaration import com.google.devtools.ksp.symbol.KSNode fun T.wrapKsNoteInfo( - ksNode: KSNode, + ksNode: KSNode?, block: T.() -> R, ): R { return try { diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/annotations/ComponentAnnMirror.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/annotations/ComponentAnnMirror.kt index eea074cc..445b16af 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/annotations/ComponentAnnMirror.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/annotations/ComponentAnnMirror.kt @@ -1,12 +1,16 @@ package com.github.klee0kai.thekey.stone.ksp.helpers.annotations -import com.github.klee0kai.stone.annotations.component.Component +import com.github.klee0kai.stone.annotations.component.* +import com.github.klee0kai.stone.annotations.dependencies.Dependencies +import com.github.klee0kai.stone.annotations.module.BindInstance +import com.github.klee0kai.stone.annotations.module.Module +import com.github.klee0kai.stone.annotations.module.Provide +import com.github.klee0kai.stone.annotations.wrappers.WrappersCreator import com.google.devtools.ksp.symbol.KSAnnotated import com.google.devtools.ksp.symbol.KSAnnotation import com.google.devtools.ksp.symbol.KSType import com.squareup.kotlinpoet.ClassName import com.squareup.kotlinpoet.asClassName -import com.squareup.kotlinpoet.ksp.toClassName import com.squareup.kotlinpoet.ksp.toTypeName class ComponentAnnMirror( @@ -26,6 +30,23 @@ fun KSAnnotated.anyAnnotation( .filter { it.annotationType.resolve().toTypeName() in classNames } +fun KSAnnotated.stoneControlAnnotations( +): Sequence = anyAnnotation( + Component::class.asClassName(), + ExtendOf::class.asClassName(), + ModuleOriginFactory::class.asClassName(), + ProtectInjected::class.asClassName(), + RunGc::class.asClassName(), + SwitchCache::class.asClassName(), + Init::class.asClassName(), + BindInstance::class.asClassName(), + Provide::class.asClassName(), + Module::class.asClassName(), + Dependencies::class.asClassName(), + WrappersCreator::class.asClassName(), +) + + fun KSAnnotated.hasOnlyAnnotation( className: ClassName, ): Boolean { @@ -33,6 +54,14 @@ fun KSAnnotated.hasOnlyAnnotation( return annotations.first().annotationType.resolve().toTypeName() == className } +fun KSAnnotated.hasOnlyStoneControlAnnotation( + vararg classNames: ClassName, +): Boolean { + if (stoneControlAnnotations().count() > classNames.size) return false + return stoneControlAnnotations().all { it.annotationType.resolve().toTypeName() in classNames } +} + + fun KSType.annotations( className: ClassName, ): Sequence = annotations diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/invokecall/ModulesGraph.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/invokecall/ModulesGraph.kt index 8c7fdcaa..20af550e 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/invokecall/ModulesGraph.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/invokecall/ModulesGraph.kt @@ -213,7 +213,7 @@ class ModulesGraph( if (isSingleDepRequired) { if (isCacheProvide) { - codeBlock.add("val %L : %T = ", singleDepField.name, inv.resultType()) + codeBlock.add("val %L = ", singleDepField.name) .add( wrapHelper.transform( inv.best().rawReturnType(), @@ -227,11 +227,9 @@ class ModulesGraph( localVariables.add(singleDepField) } else { singleDepField = singleDepField - .copy( - type = Ref::class.asClassName().parameterizedBy(inv.resultType()), - ) + .copy(type = Ref::class.asClassName().parameterizedBy(inv.resultType())) - codeBlock.add("val %L: %T = { ", singleDepField.name, singleDepField.type) + codeBlock.add("val %L = %T{ ", singleDepField.name, Ref::class) .add( wrapHelper.transform( inv.best().rawReturnType(), @@ -246,7 +244,7 @@ class ModulesGraph( } if (isListDepRequired) { - codeBlock.add("val %L : %T = { ", listDepField.name, listDepField.type) + codeBlock.add("val %L = %T{ ", listDepField.name, listDepField.type) .add(inv.invokeAllToList(localVariables)) .addStatement(" } ") @@ -254,7 +252,7 @@ class ModulesGraph( } - if (inv.resultType() == providingType) { + if (inv.resultType().copy(nullable = false) == providingType.copy(nullable = false)) { if (wrapHelper.isList(returnType)) { codeBlock.add( "%L.addAll( %L )\n", @@ -267,7 +265,7 @@ class ModulesGraph( ) } else { codeBlock.add( - "%L.add( %L );\n", + "%L.add( %L )\n", listFieldName, wrapHelper.transform( singleDepField.type, @@ -280,7 +278,7 @@ class ModulesGraph( } } - codeBlock.add("\n })") + codeBlock.add(" }") if (wrapHelper.isList(returnType)) { codeBlock.add(".all() ") diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/component/ComponentsMethodsExt.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/component/ComponentsMethodsExt.kt index acab2b0d..58f09c6b 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/component/ComponentsMethodsExt.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/component/ComponentsMethodsExt.kt @@ -8,6 +8,7 @@ import com.github.klee0kai.thekey.stone.ksp.exceptions.IncorrectSignatureExcepti import com.github.klee0kai.thekey.stone.ksp.helpers.annotations.annotations import com.github.klee0kai.thekey.stone.ksp.helpers.annotations.anyAnnotation import com.github.klee0kai.thekey.stone.ksp.helpers.annotations.hasOnlyAnnotation +import com.github.klee0kai.thekey.stone.ksp.helpers.annotations.stoneControlAnnotations import com.github.klee0kai.thekey.stone.ksp.helpers.scopeAnnotations import com.github.klee0kai.thekey.stone.ksp.ksp.isClassReturn import com.github.klee0kai.thekey.stone.ksp.ksp.isNotPrimitive @@ -96,7 +97,11 @@ val KSFunctionDeclaration.isDepsProvideMethod: Boolean } val KSFunctionDeclaration.isObjectProvideMethod: Boolean - get() = isProvideMethodSimple && !isModuleProvideMethod && !isDepsProvideMethod && !isModuleFactoryProvideMethod + get() = isProvideMethodSimple + && !isModuleProvideMethod + && !isDepsProvideMethod + && !isModuleFactoryProvideMethod + && stoneControlAnnotations().none() val KSFunctionDeclaration.isModuleInitMethod: Boolean get() { diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/component/GenComponentProcessor.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/component/GenComponentProcessor.kt index 5fbb9de9..0a48646c 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/component/GenComponentProcessor.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/component/GenComponentProcessor.kt @@ -339,12 +339,13 @@ class GenComponentProcessor : TargetFileProcessor { ) } - addStatement( - "%L?.%L = %L", + addCode( + "%L?.%L = ", injectableField.name!!.asString(), injectField.simpleName.asString(), - provideCode, ) + addCode(provideCode) + addStatement("") } for (injectMethod in injectableCl.getAllMethods(false, false, "")) { @@ -371,8 +372,8 @@ class GenComponentProcessor : TargetFileProcessor { } addCode("%L.%L( ", injectableField.name, injectMethod.simpleName.asString()) - .addCode(providingArgsCode.build()) - .addStatement(")"); + addCode(providingArgsCode.build()) + addStatement(")"); } } diff --git a/tests/src/main/java/com/github/klee0kai/test/di/bindinstance/simple/GodWorkspaceComponent.kt b/tests/src/main/java/com/github/klee0kai/test/di/bindinstance/simple/GodWorkspaceComponent.kt index 4f21930d..a8ffb6a3 100644 --- a/tests/src/main/java/com/github/klee0kai/test/di/bindinstance/simple/GodWorkspaceComponent.kt +++ b/tests/src/main/java/com/github/klee0kai/test/di/bindinstance/simple/GodWorkspaceComponent.kt @@ -26,6 +26,5 @@ interface GodWorkspaceComponent { @BindInstance fun bindSaturn(saturn: Saturn?) - fun providePlanet(): IPlanet? } diff --git a/tests/src/main/java/com/github/klee0kai/test/di/bindinstance/singlemethod_gc/PlanetRollingComponent.kt b/tests/src/main/java/com/github/klee0kai/test/di/bindinstance/singlemethod_gc/PlanetRollingComponent.kt index bbe1a6a0..394748a9 100644 --- a/tests/src/main/java/com/github/klee0kai/test/di/bindinstance/singlemethod_gc/PlanetRollingComponent.kt +++ b/tests/src/main/java/com/github/klee0kai/test/di/bindinstance/singlemethod_gc/PlanetRollingComponent.kt @@ -10,6 +10,7 @@ import com.github.klee0kai.test.mowgli.galaxy.IPlanet @Component interface PlanetRollingComponent { + fun sunModule(): SunModule? @GcPlanetScope From 45afb07fb9850dc988d5d6a0af84e150f68ff1e1 Mon Sep 17 00:00:00 2001 From: klee0kai Date: Fri, 12 Dec 2025 21:52:40 +0100 Subject: [PATCH 057/122] correct module graph from hidden module --- .../ksp/helpers/invokecall/ModulesGraph.kt | 125 ++++++++++-------- tests_ext/build.gradle.kts | 2 +- 2 files changed, 68 insertions(+), 59 deletions(-) diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/invokecall/ModulesGraph.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/invokecall/ModulesGraph.kt index 20af550e..da731fdc 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/invokecall/ModulesGraph.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/invokecall/ModulesGraph.kt @@ -52,66 +52,27 @@ class ModulesGraph( isProperty = true, ) - componentsAllMethods.forEachFun { _, componentMethod -> - when { - componentMethod.isModuleProvideMethod || componentMethod.isDepsProvideMethod -> { - val module = - componentMethod.returnType?.resolve()?.declaration as? KSClassDeclaration ?: return@forEachFun - for (m in module.getAllMethods(false, true, "")) { - if (m.returnType?.resolve()?.isNotPrimitive == false) continue - - val returnType = m.returnType?.resolve()?.toTypeName() ?: continue - val provTypeName = wrapHelper.nonWrappedType(returnType) - val isCached = m.getAnnotationsByType(Provide::class) - .firstOrNull()?.cache !in listOf(Provide.CacheType.Factory, null) - val isBindInstance = m.getAnnotationsByType(BindInstance::class).firstOrNull() != null - - provideTypeCodes.putIfAbsent(provTypeName, HashSet()) - provideTypeCodes[provTypeName]?.add( - InvokeCall.fromSequence( - wrapHelper = wrapHelper, - callSequence = listOf(componentMethod.toMethodDetail(), m.toMethodDetail()), - flags = InvokeProvideFlags( - provideObjectCached = isCached, - provideBindInstance = isBindInstance, - ), - ) - ) - - val cacheControlMethod = MethodDetail( - methodName = m.cacheControlMethodName, - returnType = wrapHelper.listWrapTypeIfNeed(returnType), - qualifierAnns = m.qualifierAnnotations.map { it.toQualifierAnn() }.toSet(), - args = buildList { - add(FieldDetail.simple("__action", CacheAction::class.asClassName())) - addAll(m.parameters.identifierParameters(identifierTypes).map { it.toFieldDetail() }) - }, - ) + componentsAllMethods + .filter { it.isModuleProvideMethod || it.isDepsProvideMethod } + .forEachFun { _, moduleProvideMethod -> - cacheControlTypeCodes.putIfAbsent(provTypeName, HashSet()) - cacheControlTypeCodes.get(provTypeName) - ?.add( - InvokeCall.fromSequence( - wrapHelper = wrapHelper, - callSequence = listOf(componentMethod.toMethodDetail(), cacheControlMethod) - ) - ) - } + val module = moduleProvideMethod.returnType?.resolve() + ?.declaration as? KSClassDeclaration ?: return@forEachFun - } + for (m in module.getAllMethods(false, true, "")) { + if (m.returnType?.resolve()?.isNotPrimitive == false) continue - componentMethod.isBindInstanceMethod == BindInstanceType.BindInstanceAndProvide -> { - val returnType = componentMethod.returnType?.resolve()?.toTypeName() ?: return@forEachFun + val returnType = m.returnType?.resolve()?.toTypeName() ?: continue val provTypeName = wrapHelper.nonWrappedType(returnType) - val isCached = componentMethod.getAnnotationsByType(Provide::class) + val isCached = m.getAnnotationsByType(Provide::class) .firstOrNull()?.cache !in listOf(Provide.CacheType.Factory, null) - val isBindInstance = componentMethod.getAnnotationsByType(BindInstance::class).firstOrNull() != null + val isBindInstance = m.getAnnotationsByType(BindInstance::class).firstOrNull() != null provideTypeCodes.putIfAbsent(provTypeName, HashSet()) provideTypeCodes[provTypeName]?.add( InvokeCall.fromSequence( wrapHelper = wrapHelper, - callSequence = listOf(hiddenModuleProvideMethod, componentMethod.toMethodDetail()), + callSequence = listOf(moduleProvideMethod.toMethodDetail(), m.toMethodDetail()), flags = InvokeProvideFlags( provideObjectCached = isCached, provideBindInstance = isBindInstance, @@ -120,30 +81,78 @@ class ModulesGraph( ) val cacheControlMethod = MethodDetail( - methodName = componentMethod.cacheControlMethodName, + methodName = m.cacheControlMethodName, returnType = wrapHelper.listWrapTypeIfNeed(returnType), - qualifierAnns = componentMethod.qualifierAnnotations.map { it.toQualifierAnn() }.toSet(), + qualifierAnns = m.qualifierAnnotations.map { it.toQualifierAnn() }.toSet(), args = buildList { add(FieldDetail.simple("__action", CacheAction::class.asClassName())) - addAll( - componentMethod.parameters.identifierParameters(identifierTypes) - .map { it.toFieldDetail() }) + addAll(m.parameters.identifierParameters(identifierTypes).map { it.toFieldDetail() }) }, ) cacheControlTypeCodes.putIfAbsent(provTypeName, HashSet()) - cacheControlTypeCodes[provTypeName] + cacheControlTypeCodes.get(provTypeName) ?.add( InvokeCall.fromSequence( wrapHelper = wrapHelper, - callSequence = listOf(componentMethod.toMethodDetail(), cacheControlMethod) + callSequence = listOf(moduleProvideMethod.toMethodDetail(), cacheControlMethod) ) ) } } - } + componentsAllMethods + .filter { it.isBindInstanceMethod == BindInstanceType.BindInstanceAndProvide } + .forEachFun { _, componentMethod -> + val returnType = componentMethod.returnType?.resolve()?.toTypeName() ?: return@forEachFun + val nonInModules = provideInvokesWithDeps( + ProvideDep( + componentMethod.simpleName.asString(), + wrapHelper.listWrapTypeIfNeed(returnType), + componentMethod.qualifierAnnotations.map { it.toQualifierAnn() }.toSet() + ) + ) == null + if (!nonInModules) return@forEachFun + + val provTypeName = wrapHelper.nonWrappedType(returnType) + val isCached = componentMethod.getAnnotationsByType(Provide::class) + .firstOrNull()?.cache !in listOf(Provide.CacheType.Factory, null) + val isBindInstance = componentMethod.getAnnotationsByType(BindInstance::class).firstOrNull() != null + + provideTypeCodes.putIfAbsent(provTypeName, HashSet()) + provideTypeCodes[provTypeName]?.add( + InvokeCall.fromSequence( + wrapHelper = wrapHelper, + callSequence = listOf(hiddenModuleProvideMethod, componentMethod.toMethodDetail()), + flags = InvokeProvideFlags( + provideObjectCached = isCached, + provideBindInstance = isBindInstance, + ), + ) + ) + + val cacheControlMethod = MethodDetail( + methodName = componentMethod.cacheControlMethodName, + returnType = wrapHelper.listWrapTypeIfNeed(returnType), + qualifierAnns = componentMethod.qualifierAnnotations.map { it.toQualifierAnn() }.toSet(), + args = buildList { + add(FieldDetail.simple("__action", CacheAction::class.asClassName())) + addAll( + componentMethod.parameters.identifierParameters(identifierTypes) + .map { it.toFieldDetail() }) + }, + ) + + cacheControlTypeCodes.putIfAbsent(provTypeName, HashSet()) + cacheControlTypeCodes[provTypeName] + ?.add( + InvokeCall.fromSequence( + wrapHelper = wrapHelper, + callSequence = listOf(componentMethod.toMethodDetail(), cacheControlMethod) + ) + ) + } } diff --git a/tests_ext/build.gradle.kts b/tests_ext/build.gradle.kts index 1da66512..e8333e6d 100644 --- a/tests_ext/build.gradle.kts +++ b/tests_ext/build.gradle.kts @@ -7,7 +7,7 @@ tasks.test { } dependencies { - implementation(project(":stone_lib")) + implementation(project(":stone_multiplatform")) annotationProcessor(project(":stone_processor")) implementation(project(":tests")) From 2e58cdaa3d9f5b4317d11be4c16c0cef5eddbf74 Mon Sep 17 00:00:00 2001 From: klee0kai Date: Fri, 12 Dec 2025 22:55:40 +0100 Subject: [PATCH 058/122] gen bind instance method at component --- .../ksp/helpers/invokecall/InvokeCall.kt | 4 +- .../ksp/helpers/invokecall/ModulesGraph.kt | 17 ++-- .../target/component/GenComponentProcessor.kt | 87 ++++++++++++++++++- .../test/di/house/simple/AreasModule.kt | 2 +- 4 files changed, 97 insertions(+), 13 deletions(-) diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/invokecall/InvokeCall.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/invokecall/InvokeCall.kt index ef1a08be..8165ad57 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/invokecall/InvokeCall.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/invokecall/InvokeCall.kt @@ -95,11 +95,11 @@ class InvokeCall( */ fun invokeCode( envFields: List, - vararg argGen: (FieldDetail) -> CodeBlock?, + argGen: (FieldDetail) -> CodeBlock? = { null }, ): CodeBlock { val argGens = LinkedList<(FieldDetail) -> CodeBlock?>() argGens.add(unwrapArgument(envFields)) - argGens.addAll(argGen) + argGens.add(argGen) val invokeBuilder = CodeBlock.builder() var invokeCount = 0 diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/invokecall/ModulesGraph.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/invokecall/ModulesGraph.kt index da731fdc..34721a6f 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/invokecall/ModulesGraph.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/invokecall/ModulesGraph.kt @@ -91,13 +91,12 @@ class ModulesGraph( ) cacheControlTypeCodes.putIfAbsent(provTypeName, HashSet()) - cacheControlTypeCodes.get(provTypeName) - ?.add( - InvokeCall.fromSequence( - wrapHelper = wrapHelper, - callSequence = listOf(moduleProvideMethod.toMethodDetail(), cacheControlMethod) - ) + cacheControlTypeCodes[provTypeName]?.add( + InvokeCall.fromSequence( + wrapHelper = wrapHelper, + callSequence = listOf(moduleProvideMethod.toMethodDetail(), cacheControlMethod) ) + ) } } @@ -149,7 +148,7 @@ class ModulesGraph( ?.add( InvokeCall.fromSequence( wrapHelper = wrapHelper, - callSequence = listOf(componentMethod.toMethodDetail(), cacheControlMethod) + callSequence = listOf(hiddenModuleProvideMethod, cacheControlMethod) ) ) } @@ -379,14 +378,14 @@ class ModulesGraph( * @return cache control invoke call */ fun invokeControlCacheForType( - provideMethodName: String, + provideMethodName: String?, typeName: TypeName, qualifierAnns: Set ): InvokeCall? = provideTypeInvokeCall( cacheControlTypeCodes, typeName, qualifierAnns, - provideMethodName.cacheControlMethodName, + provideMethodName?.cacheControlMethodName, false ) diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/component/GenComponentProcessor.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/component/GenComponentProcessor.kt index 0a48646c..3b4529b1 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/component/GenComponentProcessor.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/component/GenComponentProcessor.kt @@ -2,6 +2,7 @@ package com.github.klee0kai.thekey.stone.ksp.target.component +import com.github.klee0kai.stone.__hidden__.CacheAction import com.github.klee0kai.stone.__hidden__.IModule import com.github.klee0kai.stone.__hidden__.IPrivateComponent import com.github.klee0kai.stone.__hidden__.SwitchCacheParam @@ -209,7 +210,12 @@ class GenComponentProcessor : TargetFileProcessor { } m.isBindInstanceMethod != null -> { - + genBindInstanceMethod( + componentCl = componentCl, + method = m, + modulesGraph = modulesGraph, + wrapHelper = wrapHelper, + ) } m.isGcMethod -> { @@ -295,6 +301,85 @@ class GenComponentProcessor : TargetFileProcessor { } + private fun TypeSpec.Builder.genBindInstanceMethod( + componentCl: KSClassDeclaration, + method: KSFunctionDeclaration, + modulesGraph: ModulesGraph, + wrapHelper: WrapHelper, + ) { + val returnType = method.returnType?.resolve()?.toTypeName() ?: return + val identifierTypes = componentCl.allIdentifierTypes.toList() + + val setValueArg = method.parameters.firstOrNull { it.type.resolve() !in identifierTypes } + ?: throw IncorrectSignatureException( + message = "Bind instance method must have bind instance arcgument", + element = method, + ) + + val nonWrappedBindType = wrapHelper.nonWrappedType(setValueArg.type.resolve().toTypeName()) + val isProvideMethod = wrapHelper + .nonWrappedType(method.returnType!!.resolve().toTypeName()) == nonWrappedBindType + val hidingProvideName = if (isProvideMethod) method.simpleName.asString() else null + + // bind object declared in module + val cacheControlInvoke = modulesGraph.invokeControlCacheForType( + hidingProvideName, + nonWrappedBindType, + method.qualifierAnnotations.map { it.toQualifierAnn() }.toSet() + ) + + val isListCache = wrapHelper.isList(cacheControlInvoke!!.rawReturnType()) + val cacheControlType = if (isListCache) List::class.asClassName().parameterizedBy(nonWrappedBindType) + else nonWrappedBindType + + // bind object declared in module + genOverrideFun(method) { + addCode( + cacheControlInvoke.invokeCode( + envFields = method.parameters.map { it.toFieldDetail() }, + argGen = { _ -> + codeBlock { + add("%T.setValueAction(", CacheAction::class) + add( + wrapHelper.transform( + setValueArg.type.resolve().toTypeName(), + cacheControlType, + CodeBlock.of(setValueArg.name!!.asString()) + ) + ) + add(")") + } + } + ) + ) + addStatement("") + + + addStatement( + "%L{ module -> module.%L( %L ); } ", + eachModuleMethodName, + GenModuleProcessor.updateBindInstancesFrom, + cacheControlInvoke.bestSequence().first().methodName, + ) + addStatement("") + + if (isProvideMethod) { + addCode("return ") + addCode( + modulesGraph.codeProvideType( + hidingProvideName, + returnType, + method.qualifierAnnotations.map { it.toQualifierAnn() }.toSet(), + method.parameters.map { it.toFieldDetail() }, + )!! + ) + addCode("\n") + } + } + + } + + private fun TypeSpec.Builder.genInjectMethod( componentCl: KSClassDeclaration, method: KSFunctionDeclaration, diff --git a/tests/src/main/java/com/github/klee0kai/test/di/house/simple/AreasModule.kt b/tests/src/main/java/com/github/klee0kai/test/di/house/simple/AreasModule.kt index 5df859c4..f02ee3af 100644 --- a/tests/src/main/java/com/github/klee0kai/test/di/house/simple/AreasModule.kt +++ b/tests/src/main/java/com/github/klee0kai/test/di/house/simple/AreasModule.kt @@ -8,7 +8,7 @@ import com.github.klee0kai.test.house.kitchen.sinkarea.SinkArea import com.github.klee0kai.test.house.kitchen.storagearea.* @Module -internal abstract class AreasModule { +abstract class AreasModule { @Provide(cache = Provide.CacheType.Soft) abstract fun cookingArea(): CookingArea? From 00c95b9201caabdacc8a4f5999f1df3edbcb3fc4 Mon Sep 17 00:00:00 2001 From: klee0kai Date: Sat, 13 Dec 2025 21:15:17 +0100 Subject: [PATCH 059/122] correct wrap process --- .../thekey/stone/ksp/helpers/wrap/WrapHelper.kt | 5 +++-- .../target/component/GenComponentProcessor.kt | 16 +++++++++++++--- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/wrap/WrapHelper.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/wrap/WrapHelper.kt index 1ca0d7da..390cbb5a 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/wrap/WrapHelper.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/wrap/WrapHelper.kt @@ -203,8 +203,9 @@ class WrapHelper { LazyProvide::class, AsyncCoroutineProvide::class )) { - val wrapper = cl.asClassName() val isNoCachingWrapper = cl != LazyProvide::class.java && cl != AsyncCoroutineProvide::class + + val wrapper = cl.asClassName() val wrapType = WrapType( typeName = wrapper, isNoCachingWrapper = isNoCachingWrapper, @@ -212,7 +213,7 @@ class WrapHelper { wrap = { or -> CodeBlock.of( "%T{ %L } ", - if (isNoCachingWrapper) PhantomProvide::class.asClassName() else wrapper, + wrapper, or, ) }, diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/component/GenComponentProcessor.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/component/GenComponentProcessor.kt index 3b4529b1..b85746fb 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/component/GenComponentProcessor.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/component/GenComponentProcessor.kt @@ -176,13 +176,23 @@ class GenComponentProcessor : TargetFileProcessor { Module::class.asClassName(), Component::class.asClassName() ).any() -> { - addStatement("%L( %L )", initMethodName, param.name!!.asString()); + addStatement( + "%L?.let{ %L( %L ) }", + param.name!!.asString(), + initMethodName, + param.name!!.asString() + ) } paramType.anyAnnotation( Dependencies::class.asClassName(), ).any() -> { - addStatement("%L( %L )", initDepsMethodName, param.name!!.asString()); + addStatement( + "%L?.let{ %L( %L ) }", + param.name!!.asString(), + initDepsMethodName, + param.name!!.asString() + ) } else -> { @@ -456,7 +466,7 @@ class GenComponentProcessor : TargetFileProcessor { providingArgsCode.add(provideCode) } - addCode("%L.%L( ", injectableField.name, injectMethod.simpleName.asString()) + addCode("%L?.%L( ", injectableField.name!!.asString(), injectMethod.simpleName.asString()) addCode(providingArgsCode.build()) addStatement(")"); } From 2c61a6dc91d96e7743f2a7b91725dd16aec77055 Mon Sep 17 00:00:00 2001 From: klee0kai Date: Sat, 13 Dec 2025 21:41:09 +0100 Subject: [PATCH 060/122] gen switch cache methods --- .../klee0kai/thekey/stone/ksp/Processor.kt | 16 ++++--- .../target/component/GenComponentProcessor.kt | 45 ++++++++++++++++--- .../stone/__hidden__/SwitchCacheParam.kt | 3 +- .../__hidden__/types/holders/MapItemHolder.kt | 3 +- .../types/holders/SingleItemHolder.kt | 3 +- 5 files changed, 50 insertions(+), 20 deletions(-) diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/Processor.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/Processor.kt index 48a517ad..29bab5de 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/Processor.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/Processor.kt @@ -63,7 +63,7 @@ class Processor( // force changes // debug = true -// debugPkgFilter = "com.github.klee0kai.test.di.house.simple" +// debugPkgFilter = "com.github.klee0kai.test.di.swcache" } @@ -95,6 +95,14 @@ class Processor( var symbols = launchConductor.finishTogether { var symbols = findSymbolsMutex.withLock { processor.findSymbolsToProcess(resolver) } + if (debug && debugPkgFilter != null) { + symbols = symbols + .filter { + it.containingFile?.packageName + ?.asString()?.startsWith(debugPkgFilter!!) ?: true + } + } + var takeSymbolsCount = 0 processSymbolsCounter.updateAndGet { totalCount -> takeSymbolsCount = min( @@ -106,12 +114,6 @@ class Processor( totalCount + takeSymbolsCount } - if (debug && debugPkgFilter != null) { - symbols = symbols - .filter { - it.containingFile?.packageName?.asString()?.startsWith(debugPkgFilter!!) ?: true - } - } // skip to next run symbols = symbols.nowTakeOnly(takeSymbolsCount) diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/component/GenComponentProcessor.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/component/GenComponentProcessor.kt index b85746fb..a9f40e69 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/component/GenComponentProcessor.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/component/GenComponentProcessor.kt @@ -2,15 +2,13 @@ package com.github.klee0kai.thekey.stone.ksp.target.component -import com.github.klee0kai.stone.__hidden__.CacheAction -import com.github.klee0kai.stone.__hidden__.IModule -import com.github.klee0kai.stone.__hidden__.IPrivateComponent -import com.github.klee0kai.stone.__hidden__.SwitchCacheParam +import com.github.klee0kai.stone.__hidden__.* import com.github.klee0kai.stone.__hidden__.collections.RefCollection import com.github.klee0kai.stone.__hidden__.types.WeakList import com.github.klee0kai.stone.__hidden__.types.holders.TimeHolder import com.github.klee0kai.stone.annotations.component.Component import com.github.klee0kai.stone.annotations.component.ProtectInjected +import com.github.klee0kai.stone.annotations.component.SwitchCache import com.github.klee0kai.stone.annotations.dependencies.Dependencies import com.github.klee0kai.stone.annotations.module.Module import com.github.klee0kai.stone.weakref.Inject @@ -29,7 +27,6 @@ import com.github.klee0kai.thekey.stone.ksp.ksp.arch.SymbolsToProcess import com.github.klee0kai.thekey.stone.ksp.ksp.arch.TargetFileProcessor import com.github.klee0kai.thekey.stone.ksp.ksp.getAllMethods import com.github.klee0kai.thekey.stone.ksp.poet.* -import com.github.klee0kai.thekey.stone.ksp.poet.member.CoroutinesMemberFunctions.SupervisorJob import com.github.klee0kai.thekey.stone.ksp.target.GenModuleProcessor import com.google.devtools.ksp.KspExperimental import com.google.devtools.ksp.containingFile @@ -237,7 +234,10 @@ class GenComponentProcessor : TargetFileProcessor { } m.isSwitchCacheMethod -> { - + genSwitchRefMethod( + componentCl = componentCl, + method = m, + ) } m.isInjectMethod -> { @@ -608,6 +608,37 @@ class GenComponentProcessor : TargetFileProcessor { } } + private fun TypeSpec.Builder.genSwitchRefMethod( + componentCl: KSClassDeclaration, + method: KSFunctionDeclaration, + ) { + val switchCacheAnn = method.getAnnotationsByType(SwitchCache::class).first() + val scopesCode = codeBlock { + method.scopeAnnotations.forEachIndexed { index, annotation -> + if (index > 0) add(", ") + add("%T::class", annotation.annotationType.resolve().toTypeName()) + } + } + + genOverrideFun(method) { + addStatement( + "val scopes = setOf<%T>( %L )", + KClass::class.asClassName().parameterizedBy(STAR), scopesCode + ) + addStatement( + "val switchCacheParams = %T( %T.%L , %L )", + SwitchCacheParam::class, + SwitchCache.CacheType::class, switchCacheAnn.cache.name, + switchCacheAnn.timeMillis, + ) + + addStatement( + "%L{ m -> m.%L(scopes, switchCacheParams) } ", + eachModuleMethodName, GenModuleProcessor.switchRefMethodName, + ) + } + } + private fun TypeSpec.Builder.genIComponentMethods( componentCl: KSClassDeclaration, delayedCodeBlocks: DelayedCodeBlocks, @@ -643,7 +674,7 @@ class GenComponentProcessor : TargetFileProcessor { ) { addModifiers(KModifier.PRIVATE) mutable(true) - initializer("%T(%M())", CoroutineScope::class.asClassName(), SupervisorJob) + initializer(" %T.stoneCoroutineScope ", StoneScope::class) } genProperty( diff --git a/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/__hidden__/SwitchCacheParam.kt b/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/__hidden__/SwitchCacheParam.kt index 83bdfcbe..009e8956 100644 --- a/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/__hidden__/SwitchCacheParam.kt +++ b/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/__hidden__/SwitchCacheParam.kt @@ -1,14 +1,13 @@ package com.github.klee0kai.stone.__hidden__ import com.github.klee0kai.stone.annotations.component.SwitchCache -import kotlin.time.Duration /** * Stone Private class */ class SwitchCacheParam( val cache: SwitchCache.CacheType, - val time: Duration = Duration.INFINITE, + val time: Long = -1, ) { companion object { fun toWeak() = SwitchCacheParam(SwitchCache.CacheType.Weak) diff --git a/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/__hidden__/types/holders/MapItemHolder.kt b/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/__hidden__/types/holders/MapItemHolder.kt index 438a0a01..468665ca 100644 --- a/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/__hidden__/types/holders/MapItemHolder.kt +++ b/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/__hidden__/types/holders/MapItemHolder.kt @@ -7,7 +7,6 @@ import com.github.klee0kai.stone.weakref.Ref import kotlinx.atomicfu.atomic import kotlinx.coroutines.delay import kotlinx.coroutines.launch -import kotlin.time.Duration /** * Stone Private class @@ -175,7 +174,7 @@ class MapItemHolder( SwitchCache.CacheType.Strong -> setRefType(StoneRefType.StrongObject) } - if (args.time != Duration.INFINITE) { + if (args.time > 0) { shedTaskCount.incrementAndGet() StoneScope.stoneCoroutineScope.launch { delay(args.time) diff --git a/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/__hidden__/types/holders/SingleItemHolder.kt b/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/__hidden__/types/holders/SingleItemHolder.kt index 0096b174..7f5a84d9 100644 --- a/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/__hidden__/types/holders/SingleItemHolder.kt +++ b/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/__hidden__/types/holders/SingleItemHolder.kt @@ -7,7 +7,6 @@ import com.github.klee0kai.stone.weakref.Ref import kotlinx.atomicfu.atomic import kotlinx.coroutines.delay import kotlinx.coroutines.launch -import kotlin.time.Duration /** * Stone Private class @@ -135,7 +134,7 @@ class SingleItemHolder( SwitchCache.CacheType.Strong -> setRefType(StoneRefType.StrongObject) } - if (args.time != Duration.INFINITE) { + if (args.time > 0) { shedTaskCount.incrementAndGet() StoneScope.stoneCoroutineScope.launch { delay(args.time) From 9fbe89190936168f096404e69068e6da52820b0f Mon Sep 17 00:00:00 2001 From: klee0kai Date: Sat, 13 Dec 2025 23:33:01 +0100 Subject: [PATCH 061/122] Rename .java to .kt --- .../simple/{GodFirstWorkDayTest.java => GodFirstWorkDayTest.kt} | 0 .../bindinstance/simple/{GodTouchTest.java => GodTouchTest.kt} | 0 .../simple_inject/{SevenPlanetTests.java => SevenPlanetTests.kt} | 0 .../{PlanetProvideTests.java => PlanetProvideTests.kt} | 0 .../singlemethod/{StarProvideTests.java => StarProvideTests.kt} | 0 .../{PlanetRollingTests.java => PlanetRollingTests.kt} | 0 ...kyProtectInjectedTests.java => MoonSkyProtectInjectedTests.kt} | 0 .../singlemethod_inject/{MoonSkyTests.java => MoonSkyTests.kt} | 0 .../solarsystem/{SolarSystemTests.java => SolarSystemTests.kt} | 0 .../stone/test/cache/{EarthCacheTests.java => EarthCacheTests.kt} | 0 .../{EarthSwitchCacheTests.java => EarthSwitchCacheTests.kt} | 0 .../test/deps/{HouseFactoryTests.java => HouseFactoryTests.kt} | 0 .../stone/test/deps/{HouseNullsTests.java => HouseNullsTests.kt} | 0 .../klee0kai/stone/test/deps/{HouseTests.java => HouseTests.kt} | 0 .../stone/test/deps/{InHouseTests.java => InHouseTests.kt} | 0 .../test/gc/{EarthLastDayTests.java => EarthLastDayTests.kt} | 0 .../test/gc/{GodLastWorkDayTests.java => GodLastWorkDayTests.kt} | 0 .../{GoodPhoneInjectTests.java => GoodPhoneInjectTests.kt} | 0 .../{MultiIdentifiersTests.java => MultiIdentifiersTests.kt} | 0 .../{TechComponentsTests.java => TechComponentsTests.kt} | 0 ...echFactoryComponentTests.java => TechFactoryComponentTests.kt} | 0 .../identifiers/{TechFactoryTests.java => TechFactoryTests.kt} | 0 ...{TechFactoryWrappersTests.java => TechFactoryWrappersTests.kt} | 0 .../test/inject/{HorseInjectTests.java => HorseInjectTests.kt} | 0 .../{HorseProtectInjectTests.java => HorseProtectInjectTests.kt} | 0 ...ethodWrappersTests.java => MowgliInjectMethodWrappersTests.kt} | 0 ...owgliInjectWrappersTests.java => MowgliInjectWrappersTests.kt} | 0 ...jectWrappersTests.java => SchoolProtectInjectWrappersTests.kt} | 0 .../test/interfaceprovide/{DeepCaveTest.java => DeepCaveTest.kt} | 0 .../test/interfaceprovide/{EarthWayTest.java => EarthWayTest.kt} | 0 .../{GoodPhoneRepairTests.java => GoodPhoneRepairTests.kt} | 0 .../{OnePhoneRepairTests.java => OnePhoneRepairTests.kt} | 0 .../{BeginOfBegins2Tests.java => BeginOfBegins2Tests.kt} | 0 .../moduleinit/{BeginOfBeginsTests.java => BeginOfBeginsTests.kt} | 0 .../stone/test/parameterized/{WireTest.java => WireTest.kt} | 0 35 files changed, 0 insertions(+), 0 deletions(-) rename tests/src/test/java/com/github/klee0kai/stone/test/bindinstance/simple/{GodFirstWorkDayTest.java => GodFirstWorkDayTest.kt} (100%) rename tests/src/test/java/com/github/klee0kai/stone/test/bindinstance/simple/{GodTouchTest.java => GodTouchTest.kt} (100%) rename tests/src/test/java/com/github/klee0kai/stone/test/bindinstance/simple_inject/{SevenPlanetTests.java => SevenPlanetTests.kt} (100%) rename tests/src/test/java/com/github/klee0kai/stone/test/bindinstance/singlemethod/{PlanetProvideTests.java => PlanetProvideTests.kt} (100%) rename tests/src/test/java/com/github/klee0kai/stone/test/bindinstance/singlemethod/{StarProvideTests.java => StarProvideTests.kt} (100%) rename tests/src/test/java/com/github/klee0kai/stone/test/bindinstance/singlemethod_gc/{PlanetRollingTests.java => PlanetRollingTests.kt} (100%) rename tests/src/test/java/com/github/klee0kai/stone/test/bindinstance/singlemethod_inject/{MoonSkyProtectInjectedTests.java => MoonSkyProtectInjectedTests.kt} (100%) rename tests/src/test/java/com/github/klee0kai/stone/test/bindinstance/singlemethod_inject/{MoonSkyTests.java => MoonSkyTests.kt} (100%) rename tests/src/test/java/com/github/klee0kai/stone/test/bindinstance/solarsystem/{SolarSystemTests.java => SolarSystemTests.kt} (100%) rename tests/src/test/java/com/github/klee0kai/stone/test/cache/{EarthCacheTests.java => EarthCacheTests.kt} (100%) rename tests/src/test/java/com/github/klee0kai/stone/test/cache/{EarthSwitchCacheTests.java => EarthSwitchCacheTests.kt} (100%) rename tests/src/test/java/com/github/klee0kai/stone/test/deps/{HouseFactoryTests.java => HouseFactoryTests.kt} (100%) rename tests/src/test/java/com/github/klee0kai/stone/test/deps/{HouseNullsTests.java => HouseNullsTests.kt} (100%) rename tests/src/test/java/com/github/klee0kai/stone/test/deps/{HouseTests.java => HouseTests.kt} (100%) rename tests/src/test/java/com/github/klee0kai/stone/test/deps/{InHouseTests.java => InHouseTests.kt} (100%) rename tests/src/test/java/com/github/klee0kai/stone/test/gc/{EarthLastDayTests.java => EarthLastDayTests.kt} (100%) rename tests/src/test/java/com/github/klee0kai/stone/test/gc/{GodLastWorkDayTests.java => GodLastWorkDayTests.kt} (100%) rename tests/src/test/java/com/github/klee0kai/stone/test/identifiers/{GoodPhoneInjectTests.java => GoodPhoneInjectTests.kt} (100%) rename tests/src/test/java/com/github/klee0kai/stone/test/identifiers/{MultiIdentifiersTests.java => MultiIdentifiersTests.kt} (100%) rename tests/src/test/java/com/github/klee0kai/stone/test/identifiers/{TechComponentsTests.java => TechComponentsTests.kt} (100%) rename tests/src/test/java/com/github/klee0kai/stone/test/identifiers/{TechFactoryComponentTests.java => TechFactoryComponentTests.kt} (100%) rename tests/src/test/java/com/github/klee0kai/stone/test/identifiers/{TechFactoryTests.java => TechFactoryTests.kt} (100%) rename tests/src/test/java/com/github/klee0kai/stone/test/identifiers/{TechFactoryWrappersTests.java => TechFactoryWrappersTests.kt} (100%) rename tests/src/test/java/com/github/klee0kai/stone/test/inject/{HorseInjectTests.java => HorseInjectTests.kt} (100%) rename tests/src/test/java/com/github/klee0kai/stone/test/inject/{HorseProtectInjectTests.java => HorseProtectInjectTests.kt} (100%) rename tests/src/test/java/com/github/klee0kai/stone/test/inject/{MowgliInjectMethodWrappersTests.java => MowgliInjectMethodWrappersTests.kt} (100%) rename tests/src/test/java/com/github/klee0kai/stone/test/inject/{MowgliInjectWrappersTests.java => MowgliInjectWrappersTests.kt} (100%) rename tests/src/test/java/com/github/klee0kai/stone/test/inject/{SchoolProtectInjectWrappersTests.java => SchoolProtectInjectWrappersTests.kt} (100%) rename tests/src/test/java/com/github/klee0kai/stone/test/interfaceprovide/{DeepCaveTest.java => DeepCaveTest.kt} (100%) rename tests/src/test/java/com/github/klee0kai/stone/test/interfaceprovide/{EarthWayTest.java => EarthWayTest.kt} (100%) rename tests/src/test/java/com/github/klee0kai/stone/test/lifecycle/{GoodPhoneRepairTests.java => GoodPhoneRepairTests.kt} (100%) rename tests/src/test/java/com/github/klee0kai/stone/test/lifecycle/{OnePhoneRepairTests.java => OnePhoneRepairTests.kt} (100%) rename tests/src/test/java/com/github/klee0kai/stone/test/moduleinit/{BeginOfBegins2Tests.java => BeginOfBegins2Tests.kt} (100%) rename tests/src/test/java/com/github/klee0kai/stone/test/moduleinit/{BeginOfBeginsTests.java => BeginOfBeginsTests.kt} (100%) rename tests/src/test/java/com/github/klee0kai/stone/test/parameterized/{WireTest.java => WireTest.kt} (100%) diff --git a/tests/src/test/java/com/github/klee0kai/stone/test/bindinstance/simple/GodFirstWorkDayTest.java b/tests/src/test/java/com/github/klee0kai/stone/test/bindinstance/simple/GodFirstWorkDayTest.kt similarity index 100% rename from tests/src/test/java/com/github/klee0kai/stone/test/bindinstance/simple/GodFirstWorkDayTest.java rename to tests/src/test/java/com/github/klee0kai/stone/test/bindinstance/simple/GodFirstWorkDayTest.kt diff --git a/tests/src/test/java/com/github/klee0kai/stone/test/bindinstance/simple/GodTouchTest.java b/tests/src/test/java/com/github/klee0kai/stone/test/bindinstance/simple/GodTouchTest.kt similarity index 100% rename from tests/src/test/java/com/github/klee0kai/stone/test/bindinstance/simple/GodTouchTest.java rename to tests/src/test/java/com/github/klee0kai/stone/test/bindinstance/simple/GodTouchTest.kt diff --git a/tests/src/test/java/com/github/klee0kai/stone/test/bindinstance/simple_inject/SevenPlanetTests.java b/tests/src/test/java/com/github/klee0kai/stone/test/bindinstance/simple_inject/SevenPlanetTests.kt similarity index 100% rename from tests/src/test/java/com/github/klee0kai/stone/test/bindinstance/simple_inject/SevenPlanetTests.java rename to tests/src/test/java/com/github/klee0kai/stone/test/bindinstance/simple_inject/SevenPlanetTests.kt diff --git a/tests/src/test/java/com/github/klee0kai/stone/test/bindinstance/singlemethod/PlanetProvideTests.java b/tests/src/test/java/com/github/klee0kai/stone/test/bindinstance/singlemethod/PlanetProvideTests.kt similarity index 100% rename from tests/src/test/java/com/github/klee0kai/stone/test/bindinstance/singlemethod/PlanetProvideTests.java rename to tests/src/test/java/com/github/klee0kai/stone/test/bindinstance/singlemethod/PlanetProvideTests.kt diff --git a/tests/src/test/java/com/github/klee0kai/stone/test/bindinstance/singlemethod/StarProvideTests.java b/tests/src/test/java/com/github/klee0kai/stone/test/bindinstance/singlemethod/StarProvideTests.kt similarity index 100% rename from tests/src/test/java/com/github/klee0kai/stone/test/bindinstance/singlemethod/StarProvideTests.java rename to tests/src/test/java/com/github/klee0kai/stone/test/bindinstance/singlemethod/StarProvideTests.kt diff --git a/tests/src/test/java/com/github/klee0kai/stone/test/bindinstance/singlemethod_gc/PlanetRollingTests.java b/tests/src/test/java/com/github/klee0kai/stone/test/bindinstance/singlemethod_gc/PlanetRollingTests.kt similarity index 100% rename from tests/src/test/java/com/github/klee0kai/stone/test/bindinstance/singlemethod_gc/PlanetRollingTests.java rename to tests/src/test/java/com/github/klee0kai/stone/test/bindinstance/singlemethod_gc/PlanetRollingTests.kt diff --git a/tests/src/test/java/com/github/klee0kai/stone/test/bindinstance/singlemethod_inject/MoonSkyProtectInjectedTests.java b/tests/src/test/java/com/github/klee0kai/stone/test/bindinstance/singlemethod_inject/MoonSkyProtectInjectedTests.kt similarity index 100% rename from tests/src/test/java/com/github/klee0kai/stone/test/bindinstance/singlemethod_inject/MoonSkyProtectInjectedTests.java rename to tests/src/test/java/com/github/klee0kai/stone/test/bindinstance/singlemethod_inject/MoonSkyProtectInjectedTests.kt diff --git a/tests/src/test/java/com/github/klee0kai/stone/test/bindinstance/singlemethod_inject/MoonSkyTests.java b/tests/src/test/java/com/github/klee0kai/stone/test/bindinstance/singlemethod_inject/MoonSkyTests.kt similarity index 100% rename from tests/src/test/java/com/github/klee0kai/stone/test/bindinstance/singlemethod_inject/MoonSkyTests.java rename to tests/src/test/java/com/github/klee0kai/stone/test/bindinstance/singlemethod_inject/MoonSkyTests.kt diff --git a/tests/src/test/java/com/github/klee0kai/stone/test/bindinstance/solarsystem/SolarSystemTests.java b/tests/src/test/java/com/github/klee0kai/stone/test/bindinstance/solarsystem/SolarSystemTests.kt similarity index 100% rename from tests/src/test/java/com/github/klee0kai/stone/test/bindinstance/solarsystem/SolarSystemTests.java rename to tests/src/test/java/com/github/klee0kai/stone/test/bindinstance/solarsystem/SolarSystemTests.kt diff --git a/tests/src/test/java/com/github/klee0kai/stone/test/cache/EarthCacheTests.java b/tests/src/test/java/com/github/klee0kai/stone/test/cache/EarthCacheTests.kt similarity index 100% rename from tests/src/test/java/com/github/klee0kai/stone/test/cache/EarthCacheTests.java rename to tests/src/test/java/com/github/klee0kai/stone/test/cache/EarthCacheTests.kt diff --git a/tests/src/test/java/com/github/klee0kai/stone/test/cache/EarthSwitchCacheTests.java b/tests/src/test/java/com/github/klee0kai/stone/test/cache/EarthSwitchCacheTests.kt similarity index 100% rename from tests/src/test/java/com/github/klee0kai/stone/test/cache/EarthSwitchCacheTests.java rename to tests/src/test/java/com/github/klee0kai/stone/test/cache/EarthSwitchCacheTests.kt diff --git a/tests/src/test/java/com/github/klee0kai/stone/test/deps/HouseFactoryTests.java b/tests/src/test/java/com/github/klee0kai/stone/test/deps/HouseFactoryTests.kt similarity index 100% rename from tests/src/test/java/com/github/klee0kai/stone/test/deps/HouseFactoryTests.java rename to tests/src/test/java/com/github/klee0kai/stone/test/deps/HouseFactoryTests.kt diff --git a/tests/src/test/java/com/github/klee0kai/stone/test/deps/HouseNullsTests.java b/tests/src/test/java/com/github/klee0kai/stone/test/deps/HouseNullsTests.kt similarity index 100% rename from tests/src/test/java/com/github/klee0kai/stone/test/deps/HouseNullsTests.java rename to tests/src/test/java/com/github/klee0kai/stone/test/deps/HouseNullsTests.kt diff --git a/tests/src/test/java/com/github/klee0kai/stone/test/deps/HouseTests.java b/tests/src/test/java/com/github/klee0kai/stone/test/deps/HouseTests.kt similarity index 100% rename from tests/src/test/java/com/github/klee0kai/stone/test/deps/HouseTests.java rename to tests/src/test/java/com/github/klee0kai/stone/test/deps/HouseTests.kt diff --git a/tests/src/test/java/com/github/klee0kai/stone/test/deps/InHouseTests.java b/tests/src/test/java/com/github/klee0kai/stone/test/deps/InHouseTests.kt similarity index 100% rename from tests/src/test/java/com/github/klee0kai/stone/test/deps/InHouseTests.java rename to tests/src/test/java/com/github/klee0kai/stone/test/deps/InHouseTests.kt diff --git a/tests/src/test/java/com/github/klee0kai/stone/test/gc/EarthLastDayTests.java b/tests/src/test/java/com/github/klee0kai/stone/test/gc/EarthLastDayTests.kt similarity index 100% rename from tests/src/test/java/com/github/klee0kai/stone/test/gc/EarthLastDayTests.java rename to tests/src/test/java/com/github/klee0kai/stone/test/gc/EarthLastDayTests.kt diff --git a/tests/src/test/java/com/github/klee0kai/stone/test/gc/GodLastWorkDayTests.java b/tests/src/test/java/com/github/klee0kai/stone/test/gc/GodLastWorkDayTests.kt similarity index 100% rename from tests/src/test/java/com/github/klee0kai/stone/test/gc/GodLastWorkDayTests.java rename to tests/src/test/java/com/github/klee0kai/stone/test/gc/GodLastWorkDayTests.kt diff --git a/tests/src/test/java/com/github/klee0kai/stone/test/identifiers/GoodPhoneInjectTests.java b/tests/src/test/java/com/github/klee0kai/stone/test/identifiers/GoodPhoneInjectTests.kt similarity index 100% rename from tests/src/test/java/com/github/klee0kai/stone/test/identifiers/GoodPhoneInjectTests.java rename to tests/src/test/java/com/github/klee0kai/stone/test/identifiers/GoodPhoneInjectTests.kt diff --git a/tests/src/test/java/com/github/klee0kai/stone/test/identifiers/MultiIdentifiersTests.java b/tests/src/test/java/com/github/klee0kai/stone/test/identifiers/MultiIdentifiersTests.kt similarity index 100% rename from tests/src/test/java/com/github/klee0kai/stone/test/identifiers/MultiIdentifiersTests.java rename to tests/src/test/java/com/github/klee0kai/stone/test/identifiers/MultiIdentifiersTests.kt diff --git a/tests/src/test/java/com/github/klee0kai/stone/test/identifiers/TechComponentsTests.java b/tests/src/test/java/com/github/klee0kai/stone/test/identifiers/TechComponentsTests.kt similarity index 100% rename from tests/src/test/java/com/github/klee0kai/stone/test/identifiers/TechComponentsTests.java rename to tests/src/test/java/com/github/klee0kai/stone/test/identifiers/TechComponentsTests.kt diff --git a/tests/src/test/java/com/github/klee0kai/stone/test/identifiers/TechFactoryComponentTests.java b/tests/src/test/java/com/github/klee0kai/stone/test/identifiers/TechFactoryComponentTests.kt similarity index 100% rename from tests/src/test/java/com/github/klee0kai/stone/test/identifiers/TechFactoryComponentTests.java rename to tests/src/test/java/com/github/klee0kai/stone/test/identifiers/TechFactoryComponentTests.kt diff --git a/tests/src/test/java/com/github/klee0kai/stone/test/identifiers/TechFactoryTests.java b/tests/src/test/java/com/github/klee0kai/stone/test/identifiers/TechFactoryTests.kt similarity index 100% rename from tests/src/test/java/com/github/klee0kai/stone/test/identifiers/TechFactoryTests.java rename to tests/src/test/java/com/github/klee0kai/stone/test/identifiers/TechFactoryTests.kt diff --git a/tests/src/test/java/com/github/klee0kai/stone/test/identifiers/TechFactoryWrappersTests.java b/tests/src/test/java/com/github/klee0kai/stone/test/identifiers/TechFactoryWrappersTests.kt similarity index 100% rename from tests/src/test/java/com/github/klee0kai/stone/test/identifiers/TechFactoryWrappersTests.java rename to tests/src/test/java/com/github/klee0kai/stone/test/identifiers/TechFactoryWrappersTests.kt diff --git a/tests/src/test/java/com/github/klee0kai/stone/test/inject/HorseInjectTests.java b/tests/src/test/java/com/github/klee0kai/stone/test/inject/HorseInjectTests.kt similarity index 100% rename from tests/src/test/java/com/github/klee0kai/stone/test/inject/HorseInjectTests.java rename to tests/src/test/java/com/github/klee0kai/stone/test/inject/HorseInjectTests.kt diff --git a/tests/src/test/java/com/github/klee0kai/stone/test/inject/HorseProtectInjectTests.java b/tests/src/test/java/com/github/klee0kai/stone/test/inject/HorseProtectInjectTests.kt similarity index 100% rename from tests/src/test/java/com/github/klee0kai/stone/test/inject/HorseProtectInjectTests.java rename to tests/src/test/java/com/github/klee0kai/stone/test/inject/HorseProtectInjectTests.kt diff --git a/tests/src/test/java/com/github/klee0kai/stone/test/inject/MowgliInjectMethodWrappersTests.java b/tests/src/test/java/com/github/klee0kai/stone/test/inject/MowgliInjectMethodWrappersTests.kt similarity index 100% rename from tests/src/test/java/com/github/klee0kai/stone/test/inject/MowgliInjectMethodWrappersTests.java rename to tests/src/test/java/com/github/klee0kai/stone/test/inject/MowgliInjectMethodWrappersTests.kt diff --git a/tests/src/test/java/com/github/klee0kai/stone/test/inject/MowgliInjectWrappersTests.java b/tests/src/test/java/com/github/klee0kai/stone/test/inject/MowgliInjectWrappersTests.kt similarity index 100% rename from tests/src/test/java/com/github/klee0kai/stone/test/inject/MowgliInjectWrappersTests.java rename to tests/src/test/java/com/github/klee0kai/stone/test/inject/MowgliInjectWrappersTests.kt diff --git a/tests/src/test/java/com/github/klee0kai/stone/test/inject/SchoolProtectInjectWrappersTests.java b/tests/src/test/java/com/github/klee0kai/stone/test/inject/SchoolProtectInjectWrappersTests.kt similarity index 100% rename from tests/src/test/java/com/github/klee0kai/stone/test/inject/SchoolProtectInjectWrappersTests.java rename to tests/src/test/java/com/github/klee0kai/stone/test/inject/SchoolProtectInjectWrappersTests.kt diff --git a/tests/src/test/java/com/github/klee0kai/stone/test/interfaceprovide/DeepCaveTest.java b/tests/src/test/java/com/github/klee0kai/stone/test/interfaceprovide/DeepCaveTest.kt similarity index 100% rename from tests/src/test/java/com/github/klee0kai/stone/test/interfaceprovide/DeepCaveTest.java rename to tests/src/test/java/com/github/klee0kai/stone/test/interfaceprovide/DeepCaveTest.kt diff --git a/tests/src/test/java/com/github/klee0kai/stone/test/interfaceprovide/EarthWayTest.java b/tests/src/test/java/com/github/klee0kai/stone/test/interfaceprovide/EarthWayTest.kt similarity index 100% rename from tests/src/test/java/com/github/klee0kai/stone/test/interfaceprovide/EarthWayTest.java rename to tests/src/test/java/com/github/klee0kai/stone/test/interfaceprovide/EarthWayTest.kt diff --git a/tests/src/test/java/com/github/klee0kai/stone/test/lifecycle/GoodPhoneRepairTests.java b/tests/src/test/java/com/github/klee0kai/stone/test/lifecycle/GoodPhoneRepairTests.kt similarity index 100% rename from tests/src/test/java/com/github/klee0kai/stone/test/lifecycle/GoodPhoneRepairTests.java rename to tests/src/test/java/com/github/klee0kai/stone/test/lifecycle/GoodPhoneRepairTests.kt diff --git a/tests/src/test/java/com/github/klee0kai/stone/test/lifecycle/OnePhoneRepairTests.java b/tests/src/test/java/com/github/klee0kai/stone/test/lifecycle/OnePhoneRepairTests.kt similarity index 100% rename from tests/src/test/java/com/github/klee0kai/stone/test/lifecycle/OnePhoneRepairTests.java rename to tests/src/test/java/com/github/klee0kai/stone/test/lifecycle/OnePhoneRepairTests.kt diff --git a/tests/src/test/java/com/github/klee0kai/stone/test/moduleinit/BeginOfBegins2Tests.java b/tests/src/test/java/com/github/klee0kai/stone/test/moduleinit/BeginOfBegins2Tests.kt similarity index 100% rename from tests/src/test/java/com/github/klee0kai/stone/test/moduleinit/BeginOfBegins2Tests.java rename to tests/src/test/java/com/github/klee0kai/stone/test/moduleinit/BeginOfBegins2Tests.kt diff --git a/tests/src/test/java/com/github/klee0kai/stone/test/moduleinit/BeginOfBeginsTests.java b/tests/src/test/java/com/github/klee0kai/stone/test/moduleinit/BeginOfBeginsTests.kt similarity index 100% rename from tests/src/test/java/com/github/klee0kai/stone/test/moduleinit/BeginOfBeginsTests.java rename to tests/src/test/java/com/github/klee0kai/stone/test/moduleinit/BeginOfBeginsTests.kt diff --git a/tests/src/test/java/com/github/klee0kai/stone/test/parameterized/WireTest.java b/tests/src/test/java/com/github/klee0kai/stone/test/parameterized/WireTest.kt similarity index 100% rename from tests/src/test/java/com/github/klee0kai/stone/test/parameterized/WireTest.java rename to tests/src/test/java/com/github/klee0kai/stone/test/parameterized/WireTest.kt From e49d93d3ba85deae48f5ea5d52d62e4a2011cf8f Mon Sep 17 00:00:00 2001 From: klee0kai Date: Sat, 13 Dec 2025 23:33:01 +0100 Subject: [PATCH 062/122] migrate tests module tests to kotlin --- .../klee0kai/test/mowgli/animal/Mowgli.kt | 1 - .../simple/GodFirstWorkDayTest.kt | 100 +++-- .../test/bindinstance/simple/GodTouchTest.kt | 92 +++-- .../simple_inject/SevenPlanetTests.kt | 44 ++- .../singlemethod/PlanetProvideTests.kt | 91 +++-- .../singlemethod/StarProvideTests.kt | 67 ++-- .../singlemethod_gc/PlanetRollingTests.kt | 292 +++++++-------- .../MoonSkyProtectInjectedTests.kt | 84 ++--- .../singlemethod_inject/MoonSkyTests.kt | 54 ++- .../solarsystem/SolarSystemTests.kt | 38 +- .../stone/test/cache/EarthCacheTests.kt | 134 ++++--- .../stone/test/cache/EarthSwitchCacheTests.kt | 85 ++--- .../stone/test/deps/HouseFactoryTests.kt | 34 +- .../stone/test/deps/HouseNullsTests.kt | 27 +- .../klee0kai/stone/test/deps/HouseTests.kt | 87 +++-- .../klee0kai/stone/test/deps/InHouseTests.kt | 111 +++--- .../stone/test/gc/EarthLastDayTests.kt | 349 +++++++++--------- .../stone/test/gc/GodLastWorkDayTests.kt | 194 +++++----- .../test/identifiers/GoodPhoneInjectTests.kt | 45 ++- .../test/identifiers/MultiIdentifiersTests.kt | 59 ++- .../test/identifiers/TechComponentsTests.kt | 65 ++-- .../identifiers/TechFactoryComponentTests.kt | 89 ++--- .../test/identifiers/TechFactoryTests.kt | 44 +-- .../identifiers/TechFactoryWrappersTests.kt | 84 ++--- .../stone/test/inject/HorseInjectTests.kt | 96 ++--- .../test/inject/HorseProtectInjectTests.kt | 72 ++-- .../inject/MowgliInjectMethodWrappersTests.kt | 91 +++-- .../test/inject/MowgliInjectWrappersTests.kt | 91 +++-- .../SchoolProtectInjectWrappersTests.kt | 64 ++-- .../test/interfaceprovide/DeepCaveTest.kt | 32 +- .../test/interfaceprovide/EarthWayTest.kt | 21 +- .../test/lifecycle/GoodPhoneRepairTests.kt | 155 ++++---- .../test/lifecycle/OnePhoneRepairTests.kt | 153 ++++---- .../test/moduleinit/BeginOfBegins2Tests.kt | 128 +++---- .../test/moduleinit/BeginOfBeginsTests.kt | 70 ++-- .../stone/test/parameterized/WireTest.kt | 56 +-- .../stone/test/types/ListUtilTests.java | 56 ++- 37 files changed, 1616 insertions(+), 1739 deletions(-) diff --git a/tests/src/main/java/com/github/klee0kai/test/mowgli/animal/Mowgli.kt b/tests/src/main/java/com/github/klee0kai/test/mowgli/animal/Mowgli.kt index da2d4a7d..f8577fb0 100644 --- a/tests/src/main/java/com/github/klee0kai/test/mowgli/animal/Mowgli.kt +++ b/tests/src/main/java/com/github/klee0kai/test/mowgli/animal/Mowgli.kt @@ -54,7 +54,6 @@ class Mowgli : IAnimal { @Inject var knowledgePhantomProvide: PhantomProvide? = null - @JvmField var methodKnowledgeWeakRef: WeakReference? = null diff --git a/tests/src/test/java/com/github/klee0kai/stone/test/bindinstance/simple/GodFirstWorkDayTest.kt b/tests/src/test/java/com/github/klee0kai/stone/test/bindinstance/simple/GodFirstWorkDayTest.kt index da4bc33b..aa4f8d57 100644 --- a/tests/src/test/java/com/github/klee0kai/stone/test/bindinstance/simple/GodFirstWorkDayTest.kt +++ b/tests/src/test/java/com/github/klee0kai/stone/test/bindinstance/simple/GodFirstWorkDayTest.kt @@ -1,90 +1,86 @@ -package com.github.klee0kai.stone.test.bindinstance.simple; +package com.github.klee0kai.stone.test.bindinstance.simple -import com.github.klee0kai.stone.Stone; -import com.github.klee0kai.test.di.bindinstance.simple.GodWorkspaceComponent; -import com.github.klee0kai.test.mowgli.galaxy.Earth; -import com.github.klee0kai.test.mowgli.galaxy.Saturn; -import com.github.klee0kai.test.mowgli.galaxy.Sun; -import org.junit.jupiter.api.Test; +import com.github.klee0kai.test.di.bindinstance.simple.GodWorkspaceComponentStoneComponent +import com.github.klee0kai.test.mowgli.galaxy.Earth +import com.github.klee0kai.test.mowgli.galaxy.Saturn +import com.github.klee0kai.test.mowgli.galaxy.Sun +import org.junit.jupiter.api.Assertions.assertEquals +import org.junit.jupiter.api.Assertions.assertNull +import org.junit.jupiter.api.Test -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNull; - -public class GodFirstWorkDayTest { +class GodFirstWorkDayTest { @Test - public void firstCreateSunTest() { + fun firstCreateSunTest() { //Given - GodWorkspaceComponent DI = Stone.createComponent(GodWorkspaceComponent.class); - Sun sun = new Sun(); + val DI = GodWorkspaceComponentStoneComponent() + val sun = com.github.klee0kai.test.mowgli.galaxy.Sun() //When - DI.bindSun(sun); + DI.bindSun(sun) //Then - assertEquals(sun.uuid, DI.sunSystem().sun().uuid); - assertNull(DI.sunSystem().earth()); + assertEquals(sun.uuid, DI.sunSystem().sun()!!.uuid) + assertNull(DI.sunSystem().earth()) } @Test - public void createSunAndEarthTest() { + fun createSunAndEarthTest() { //Given - GodWorkspaceComponent DI = Stone.createComponent(GodWorkspaceComponent.class); - Sun sun = new Sun(); - Earth earth = new Earth(); + val DI = GodWorkspaceComponentStoneComponent() + val sun = Sun() + val earth = Earth() //When - DI.bindSun(sun); - DI.bindEarth(earth); + DI.bindSun(sun) + DI.bindEarth(earth) //Then - assertEquals(sun.uuid, DI.sunSystem().sun().uuid); - assertEquals(earth.uuid, DI.sunSystem().earth().uuid); - assertNull(DI.sunSystem().planet()); + assertEquals(sun.uuid, DI.sunSystem().sun()!!.uuid) + assertEquals(earth.uuid, DI.sunSystem().earth()!!.uuid) + assertNull(DI.sunSystem().planet()) } @Test - public void createSunEarthSaturnTest() { + fun createSunEarthSaturnTest() { //Given - GodWorkspaceComponent DI = Stone.createComponent(GodWorkspaceComponent.class); - Sun sun = new Sun(); - Earth earth = new Earth(); - Saturn saturn = new Saturn(); + val DI = GodWorkspaceComponentStoneComponent() + val sun = Sun() + val earth = Earth() + val saturn = Saturn() //When - DI.bindSun(sun); - DI.bindEarth(earth); - DI.bindSaturn(saturn); + DI.bindSun(sun) + DI.bindEarth(earth) + DI.bindSaturn(saturn) //Then - assertEquals(sun.uuid, DI.sunSystem().sun().uuid); - assertEquals(earth.uuid, DI.sunSystem().earth().uuid); - assertEquals(saturn.uuid, DI.sunSystem().saturn().uuid); - assertNull(DI.sunSystem().planet()); + assertEquals(sun.uuid, DI.sunSystem().sun()!!.uuid) + assertEquals(earth.uuid, DI.sunSystem().earth()!!.uuid) + assertEquals(saturn.uuid, DI.sunSystem().saturn()!!.uuid) + assertNull(DI.sunSystem().planet()) } @Test - public void createSaturnEarthSunTest() { + fun createSaturnEarthSunTest() { //Given - GodWorkspaceComponent DI = Stone.createComponent(GodWorkspaceComponent.class); - Sun sun = new Sun(); - Earth earth = new Earth(); - Saturn saturn = new Saturn(); + val DI = GodWorkspaceComponentStoneComponent() + val sun = Sun() + val earth = Earth() + val saturn = Saturn() //When - DI.bindSaturn(saturn); - DI.bindEarth(earth); - DI.bindSun(sun); + DI.bindSaturn(saturn) + DI.bindEarth(earth) + DI.bindSun(sun) //Then - assertEquals(sun.uuid, DI.sunSystem().sun().uuid); - assertEquals(earth.uuid, DI.sunSystem().earth().uuid); - assertEquals(saturn.uuid, DI.sunSystem().saturn().uuid); - assertNull(DI.sunSystem().planet()); + assertEquals(sun.uuid, DI.sunSystem().sun()!!.uuid) + assertEquals(earth.uuid, DI.sunSystem().earth()!!.uuid) + assertEquals(saturn.uuid, DI.sunSystem().saturn()!!.uuid) + assertNull(DI.sunSystem().planet()) } - - } diff --git a/tests/src/test/java/com/github/klee0kai/stone/test/bindinstance/simple/GodTouchTest.kt b/tests/src/test/java/com/github/klee0kai/stone/test/bindinstance/simple/GodTouchTest.kt index 638b9d17..0c1edc13 100644 --- a/tests/src/test/java/com/github/klee0kai/stone/test/bindinstance/simple/GodTouchTest.kt +++ b/tests/src/test/java/com/github/klee0kai/stone/test/bindinstance/simple/GodTouchTest.kt @@ -1,85 +1,83 @@ -package com.github.klee0kai.stone.test.bindinstance.simple; +package com.github.klee0kai.stone.test.bindinstance.simple -import com.github.klee0kai.stone.Stone; -import com.github.klee0kai.test.di.bindinstance.simple.GodWorkspaceComponent; -import com.github.klee0kai.test.mowgli.galaxy.Earth; -import com.github.klee0kai.test.mowgli.galaxy.Saturn; -import com.github.klee0kai.test.mowgli.galaxy.Sun; -import org.junit.jupiter.api.Test; +import com.github.klee0kai.test.di.bindinstance.simple.GodWorkspaceComponentStoneComponent +import com.github.klee0kai.test.mowgli.galaxy.Earth +import com.github.klee0kai.test.mowgli.galaxy.Saturn +import com.github.klee0kai.test.mowgli.galaxy.Sun +import org.junit.jupiter.api.Assertions.assertEquals +import org.junit.jupiter.api.Test +import org.junit.jupiter.api.assertNull -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNull; -public class GodTouchTest { +class GodTouchTest { @Test - public void firstCreateSunTest() { + fun firstCreateSunTest() { //Given - GodWorkspaceComponent DI = Stone.createComponent(GodWorkspaceComponent.class); - Sun sun = new Sun(); + val DI = GodWorkspaceComponentStoneComponent() + val sun = Sun() //When - DI.bindSun(sun); + DI.bindSun(sun) //Then - assertEquals(sun.uuid, DI.sunSystem().sun().uuid); - assertNull(DI.sunSystem().earth()); + assertEquals(sun.uuid, DI.sunSystem().sun()!!.uuid) + assertNull(DI.sunSystem().earth()) } - @Test - public void createSunAndEarthTest() { + @org.junit.jupiter.api.Test + fun createSunAndEarthTest() { //Given - GodWorkspaceComponent DI = Stone.createComponent(GodWorkspaceComponent.class); - Sun sun = new Sun(); - Earth earth = new Earth(); + val DI = GodWorkspaceComponentStoneComponent() + val sun = Sun() + val earth = Earth() //When - DI.bindSun(sun); - DI.bindEarth(earth); + DI.bindSun(sun) + DI.bindEarth(earth) //Then - assertEquals(sun.uuid, DI.sunSystem().sun().uuid); - assertEquals(earth.uuid, DI.sunSystem().earth().uuid); - assertNull(DI.sunSystem().planet()); + assertEquals(sun.uuid, DI.sunSystem().sun()!!.uuid) + assertEquals(earth.uuid, DI.sunSystem().earth()!!.uuid) + assertNull(DI.sunSystem().planet()) } @Test - public void createSaturnEarthSunTest() { + fun createSaturnEarthSunTest() { //Given - GodWorkspaceComponent DI = Stone.createComponent(GodWorkspaceComponent.class); - Sun sun = new Sun(); - Earth earth = new Earth(); - Saturn saturn = new Saturn(); + val DI = GodWorkspaceComponentStoneComponent() + + val sun = Sun() + val earth = Earth() + val saturn = Saturn() //When - DI.bindEarth(earth); - DI.bindSun(sun); - DI.bindPlanet(saturn); + DI.bindEarth(earth) + DI.bindSun(sun) + DI.bindPlanet(saturn) //Then - assertEquals(sun.uuid, DI.sunSystem().sun().uuid); - assertEquals(earth.uuid, DI.sunSystem().earth().uuid); - assertEquals(saturn, DI.sunSystem().planet()); - assertNull(DI.sunSystem().saturn()); + assertEquals(sun.uuid, DI.sunSystem().sun()!!.uuid) + assertEquals(earth.uuid, DI.sunSystem().earth()!!.uuid) + assertEquals(saturn, DI.sunSystem().planet()) + assertNull(DI.sunSystem().saturn()) } @Test - public void planetIsPlanetTest() { + fun planetIsPlanetTest() { //Given - GodWorkspaceComponent DI = Stone.createComponent(GodWorkspaceComponent.class); - Earth earth = new Earth(); + val DI = GodWorkspaceComponentStoneComponent() + val earth = Earth() //When - DI.planet(earth); - DI.planet(null); + DI.planet(earth) + DI.planet(null) //Then - assertEquals(earth, DI.planet(null)); - assertEquals(earth, DI.providePlanet()); + assertEquals(earth, DI.planet(null)) + assertEquals(earth, DI.providePlanet()) } - - } diff --git a/tests/src/test/java/com/github/klee0kai/stone/test/bindinstance/simple_inject/SevenPlanetTests.kt b/tests/src/test/java/com/github/klee0kai/stone/test/bindinstance/simple_inject/SevenPlanetTests.kt index efb11448..88d2e50a 100644 --- a/tests/src/test/java/com/github/klee0kai/stone/test/bindinstance/simple_inject/SevenPlanetTests.kt +++ b/tests/src/test/java/com/github/klee0kai/stone/test/bindinstance/simple_inject/SevenPlanetTests.kt @@ -1,35 +1,33 @@ -package com.github.klee0kai.stone.test.bindinstance.simple_inject; +package com.github.klee0kai.stone.test.bindinstance.simple_inject -import com.github.klee0kai.stone.Stone; -import com.github.klee0kai.test.di.bindinstance.simple_inject.SevenPlanetComponent; -import com.github.klee0kai.test.mowgli.MoonSky; -import com.github.klee0kai.test.mowgli.galaxy.Earth; -import com.github.klee0kai.test.mowgli.galaxy.Mercury; -import org.junit.jupiter.api.Test; +import com.github.klee0kai.test.di.bindinstance.simple_inject.SevenPlanetComponentStoneComponent +import com.github.klee0kai.test.mowgli.MoonSky +import com.github.klee0kai.test.mowgli.galaxy.Earth +import com.github.klee0kai.test.mowgli.galaxy.Mercury +import org.junit.jupiter.api.Assertions.assertEquals +import org.junit.jupiter.api.Test -import static org.junit.jupiter.api.Assertions.assertEquals; - -public class SevenPlanetTests { +class SevenPlanetTests { @Test - public void moonSkyTest() { + fun moonSkyTest() { //Given - SevenPlanetComponent component = Stone.createComponent(SevenPlanetComponent.class); - Earth earth = new Earth(); - Mercury mercury = new Mercury(); - Earth planet = new Earth(); - component.bind(earth); - component.bind(mercury); - component.bindPlanet(planet); + val component = SevenPlanetComponentStoneComponent() + val earth = Earth() + val mercury = Mercury() + val planet = Earth() + component.bind(earth) + component.bind(mercury) + component.bindPlanet(planet) //When - MoonSky moonSky = new MoonSky(); - component.inject(moonSky); + val moonSky = MoonSky() + component.inject(moonSky) //Then - assertEquals(earth, moonSky.earth); - assertEquals(mercury, moonSky.mercury); - assertEquals(planet, moonSky.planet); + assertEquals(earth, moonSky.earth) + assertEquals(mercury, moonSky.mercury) + assertEquals(planet, moonSky.planet) } } diff --git a/tests/src/test/java/com/github/klee0kai/stone/test/bindinstance/singlemethod/PlanetProvideTests.kt b/tests/src/test/java/com/github/klee0kai/stone/test/bindinstance/singlemethod/PlanetProvideTests.kt index 83dc1330..f52a59fa 100644 --- a/tests/src/test/java/com/github/klee0kai/stone/test/bindinstance/singlemethod/PlanetProvideTests.kt +++ b/tests/src/test/java/com/github/klee0kai/stone/test/bindinstance/singlemethod/PlanetProvideTests.kt @@ -1,83 +1,80 @@ -package com.github.klee0kai.stone.test.bindinstance.singlemethod; +package com.github.klee0kai.stone.test.bindinstance.singlemethod -import com.github.klee0kai.stone.Stone; -import com.github.klee0kai.test.di.bindinstance.singlemethod.PlanetComponent; -import com.github.klee0kai.test.di.bindinstance.singlemethod_gc.PlanetRollingComponent; -import com.github.klee0kai.test.mowgli.galaxy.Earth; -import org.junit.jupiter.api.Test; +import com.github.klee0kai.test.di.bindinstance.singlemethod.PlanetComponentStoneComponent +import com.github.klee0kai.test.di.bindinstance.singlemethod_gc.PlanetRollingComponentStoneComponent +import com.github.klee0kai.test.mowgli.galaxy.Earth +import org.junit.jupiter.api.Assertions.assertEquals +import org.junit.jupiter.api.Test +import org.junit.jupiter.api.assertNull -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNull; - -public class PlanetProvideTests { +class PlanetProvideTests { @Test - public void bindPlanetTest() { + fun bindPlanetTest() { //Given - PlanetComponent DI = Stone.createComponent(PlanetComponent.class); - Earth earth = new Earth(); + val DI = PlanetComponentStoneComponent() + val earth = Earth() //When - DI.planet(earth); + DI.planet(earth) //Then - assertEquals(earth, DI.planet(null)); - assertEquals(earth, DI.planet(null)); - assertEquals(earth, DI.providePlanet()); - assertEquals(earth, DI.providePlanet()); - assertNull(DI.earth(null)); + assertEquals(earth, DI.planet(null)) + assertEquals(earth, DI.planet(null)) + assertEquals(earth, DI.providePlanet()) + assertEquals(earth, DI.providePlanet()) + assertNull(DI.earth(null)) } @Test - public void bindEarthTest() { + fun bindEarthTest() { //Given - PlanetComponent DI = Stone.createComponent(PlanetComponent.class); - Earth earth = new Earth(); + val DI = PlanetComponentStoneComponent() + val earth = Earth() //When - DI.earth(earth); + DI.earth(earth) //Then - assertEquals(earth, DI.earth(null)); - assertEquals(earth, DI.earth(null)); - assertNull(DI.planet(null)); - assertNull(DI.providePlanet()); + assertEquals(earth, DI.earth(null)) + assertEquals(earth, DI.earth(null)) + assertNull(DI.planet(null)) + assertNull(DI.providePlanet()) } @Test - public void bindEarthCommonTest() { + fun bindEarthCommonTest() { //Given - PlanetComponent DI = Stone.createComponent(PlanetComponent.class); - Earth earth = new Earth(); + val DI = PlanetComponentStoneComponent() + val earth = Earth() //When - DI.earth(earth); + DI.earth(earth) //Then - assertEquals(earth, DI.earth(null)); - assertEquals(earth, DI.earth(null)); - assertNull(DI.planet(null)); - assertNull(DI.providePlanet()); + assertEquals(earth, DI.earth(null)) + assertEquals(earth, DI.earth(null)) + assertNull(DI.planet(null)) + assertNull(DI.providePlanet()) } @Test - public void separateBindEarthTest() { + fun separateBindEarthTest() { //Given - PlanetRollingComponent DI = Stone.createComponent(PlanetRollingComponent.class); - Earth earth1 = new Earth(); - Earth earth2 = new Earth(); - Earth earth3 = new Earth(); + val DI = PlanetRollingComponentStoneComponent() + val earth1 = Earth() + val earth2 = Earth() + val earth3 = Earth() //When - DI.earthStrong(earth1); - DI.earthSoft(earth2); - DI.earth(earth3); + DI.earthStrong(earth1) + DI.earthSoft(earth2) + DI.earth(earth3) //Then - assertEquals(earth1, DI.earthStrong(null)); - assertEquals(earth2, DI.earthSoft(null)); - assertEquals(earth3, DI.earth(null)); + assertEquals(earth1, DI.earthStrong(null)) + assertEquals(earth2, DI.earthSoft(null)) + assertEquals(earth3, DI.earth(null)) } - } diff --git a/tests/src/test/java/com/github/klee0kai/stone/test/bindinstance/singlemethod/StarProvideTests.kt b/tests/src/test/java/com/github/klee0kai/stone/test/bindinstance/singlemethod/StarProvideTests.kt index d80a8921..3d7e188f 100644 --- a/tests/src/test/java/com/github/klee0kai/stone/test/bindinstance/singlemethod/StarProvideTests.kt +++ b/tests/src/test/java/com/github/klee0kai/stone/test/bindinstance/singlemethod/StarProvideTests.kt @@ -1,64 +1,61 @@ -package com.github.klee0kai.stone.test.bindinstance.singlemethod; +package com.github.klee0kai.stone.test.bindinstance.singlemethod -import com.github.klee0kai.stone.Stone; -import com.github.klee0kai.test.di.bindinstance.singlemethod.PlanetComponent; -import com.github.klee0kai.test.mowgli.galaxy.Sun; -import org.junit.jupiter.api.Test; +import com.github.klee0kai.test.di.bindinstance.singlemethod.PlanetComponentStoneComponent +import com.github.klee0kai.test.mowgli.galaxy.Sun +import org.junit.jupiter.api.Assertions.assertEquals +import org.junit.jupiter.api.Test +import org.junit.jupiter.api.assertNull -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNull; - -public class StarProvideTests { +class StarProvideTests { @Test - public void bindSunTest() { + fun bindSunTest() { //Given - PlanetComponent DI = Stone.createComponent(PlanetComponent.class); - Sun sun = new Sun(); + val DI = PlanetComponentStoneComponent() + val sun = Sun() //When - DI.sunModule().sun(sun); + DI.sunModule().sun(sun) //Then - assertEquals(sun, DI.sunModule().sun(null)); - assertEquals(sun, DI.sunModule().sun(null)); - assertNull(DI.sunModule().star(null)); + assertEquals(sun, DI.sunModule().sun(null)) + assertEquals(sun, DI.sunModule().sun(null)) + assertNull(DI.sunModule().star(null)) } @Test - public void bindStarTest() { + fun bindStarTest() { //Given - PlanetComponent DI = Stone.createComponent(PlanetComponent.class); - Sun sun = new Sun(); + val DI = PlanetComponentStoneComponent() + val sun = Sun() //When - DI.sunModule().star(sun); + DI.sunModule().star(sun) //Then - assertEquals(sun, DI.sunModule().star(null)); - assertEquals(sun, DI.sunModule().star(null)); - assertNull(DI.sunModule().sun(null)); + assertEquals(sun, DI.sunModule().star(null)) + assertEquals(sun, DI.sunModule().star(null)) + assertNull(DI.sunModule().sun(null)) } @Test - public void separateSunBindingTest() { + fun separateSunBindingTest() { //Given - PlanetComponent DI = Stone.createComponent(PlanetComponent.class); - Sun sun1 = new Sun(); - Sun sun2 = new Sun(); - Sun sun3 = new Sun(); + val DI = PlanetComponentStoneComponent() + val sun1 = Sun() + val sun2 = Sun() + val sun3 = Sun() //When - DI.sunModule().sunStrong(sun1); - DI.sunModule().sunSoft(sun2); - DI.sunModule().sun(sun3); + DI.sunModule().sunStrong(sun1) + DI.sunModule().sunSoft(sun2) + DI.sunModule().sun(sun3) //Then - assertEquals(sun1, DI.sunModule().sunStrong(null)); - assertEquals(sun2, DI.sunModule().sunSoft(null)); - assertEquals(sun3, DI.sunModule().sun(null)); + assertEquals(sun1, DI.sunModule().sunStrong(null)) + assertEquals(sun2, DI.sunModule().sunSoft(null)) + assertEquals(sun3, DI.sunModule().sun(null)) } - } diff --git a/tests/src/test/java/com/github/klee0kai/stone/test/bindinstance/singlemethod_gc/PlanetRollingTests.kt b/tests/src/test/java/com/github/klee0kai/stone/test/bindinstance/singlemethod_gc/PlanetRollingTests.kt index 12df635b..92a17860 100644 --- a/tests/src/test/java/com/github/klee0kai/stone/test/bindinstance/singlemethod_gc/PlanetRollingTests.kt +++ b/tests/src/test/java/com/github/klee0kai/stone/test/bindinstance/singlemethod_gc/PlanetRollingTests.kt @@ -1,228 +1,222 @@ -package com.github.klee0kai.stone.test.bindinstance.singlemethod_gc; +package com.github.klee0kai.stone.test.bindinstance.singlemethod_gc -import com.github.klee0kai.stone.Stone; -import com.github.klee0kai.test.di.bindinstance.singlemethod_gc.PlanetRollingComponent; -import com.github.klee0kai.test.mowgli.galaxy.Earth; -import com.github.klee0kai.test.mowgli.galaxy.Sun; -import org.junit.jupiter.api.Test; +import com.github.klee0kai.test.di.bindinstance.singlemethod_gc.PlanetRollingComponentStoneComponent +import com.github.klee0kai.test.mowgli.galaxy.Earth +import com.github.klee0kai.test.mowgli.galaxy.Sun +import org.junit.jupiter.api.Test +import org.junit.jupiter.api.assertNotNull +import org.junit.jupiter.api.assertNull +import java.lang.ref.WeakReference -import java.lang.ref.WeakReference; -import java.util.Arrays; - -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertNull; - -public class PlanetRollingTests { +class PlanetRollingTests { @Test - public void gcAllTest() { + fun gcAllTest() { //Given - PlanetRollingComponent DI = Stone.createComponent(PlanetRollingComponent.class); - WeakReference earthStrong = new WeakReference<>(new Earth()); - WeakReference earthSoft = new WeakReference<>(new Earth()); - WeakReference planetWeak = new WeakReference<>(new Earth()); - WeakReference sunStrong = new WeakReference<>(new Sun()); - WeakReference sunSoft = new WeakReference<>(new Sun()); - WeakReference starWeak = new WeakReference<>(new Sun()); - DI.earthStrong(earthStrong.get()); - DI.earthSoft(earthSoft.get()); - DI.planet(planetWeak.get()); - DI.sunModule().sunStrong(sunStrong.get()); - DI.sunModule().sunSoft(sunSoft.get()); - DI.sunModule().star(starWeak.get()); + val DI = PlanetRollingComponentStoneComponent() + val earthStrong = WeakReference(Earth()) + val earthSoft = WeakReference(Earth()) + val planetWeak = WeakReference(Earth()) + val sunStrong = WeakReference(Sun()) + val sunSoft = WeakReference(Sun()) + val starWeak = WeakReference(Sun()) + DI.earthStrong(earthStrong.get()) + DI.earthSoft(earthSoft.get()) + DI.planet(planetWeak.get()) + DI.sunModule().sunStrong(sunStrong.get()) + DI.sunModule().sunSoft(sunSoft.get()) + DI.sunModule().star(starWeak.get()) //When - DI.gcAll(); + DI.gcAll() //Then - for (WeakReference ref : Arrays.asList( - earthStrong, earthSoft, planetWeak, - sunStrong, sunSoft, starWeak + for (ref in listOf( + earthStrong, earthSoft, planetWeak, + sunStrong, sunSoft, starWeak )) { - assertNull(ref.get()); + assertNull(ref.get()) } } @Test - public void gcStrongTest() { + fun gcStrongTest() { //Given - PlanetRollingComponent DI = Stone.createComponent(PlanetRollingComponent.class); - WeakReference earthStrong = new WeakReference<>(new Earth()); - WeakReference earthSoft = new WeakReference<>(new Earth()); - WeakReference planetWeak = new WeakReference<>(new Earth()); - WeakReference sunStrong = new WeakReference<>(new Sun()); - WeakReference sunSoft = new WeakReference<>(new Sun()); - WeakReference starWeak = new WeakReference<>(new Sun()); - DI.earthStrong(earthStrong.get()); - DI.earthSoft(earthSoft.get()); - DI.planet(planetWeak.get()); - DI.sunModule().sunStrong(sunStrong.get()); - DI.sunModule().sunSoft(sunSoft.get()); - DI.sunModule().star(starWeak.get()); + val DI = PlanetRollingComponentStoneComponent() + val earthStrong = WeakReference(Earth()) + val earthSoft = WeakReference(Earth()) + val planetWeak = WeakReference(Earth()) + val sunStrong = WeakReference(Sun()) + val sunSoft = WeakReference(Sun()) + val starWeak = WeakReference(Sun()) + DI.earthStrong(earthStrong.get()) + DI.earthSoft(earthSoft.get()) + DI.planet(planetWeak.get()) + DI.sunModule().sunStrong(sunStrong.get()) + DI.sunModule().sunSoft(sunSoft.get()) + DI.sunModule().star(starWeak.get()) //When - DI.gcStrong(); + DI.gcStrong() //Then - for (WeakReference ref : Arrays.asList( - earthStrong, planetWeak, - sunStrong, starWeak + for (ref in listOf( + earthStrong, planetWeak, + sunStrong, starWeak )) { - assertNull(ref.get()); + assertNull(ref.get()) } - for (WeakReference ref : Arrays.asList( - earthSoft, - sunSoft + for (ref in listOf( + earthSoft, + sunSoft )) { - assertNotNull(ref.get()); + assertNotNull(ref.get()) } } @Test - public void gcSoftTest() { + fun gcSoftTest() { //Given - PlanetRollingComponent DI = Stone.createComponent(PlanetRollingComponent.class); - WeakReference earthStrong = new WeakReference<>(new Earth()); - WeakReference earthSoft = new WeakReference<>(new Earth()); - WeakReference planetWeak = new WeakReference<>(new Earth()); - WeakReference sunStrong = new WeakReference<>(new Sun()); - WeakReference sunSoft = new WeakReference<>(new Sun()); - WeakReference starWeak = new WeakReference<>(new Sun()); - DI.earthStrong(earthStrong.get()); - DI.earthSoft(earthSoft.get()); - DI.planet(planetWeak.get()); - DI.sunModule().sunStrong(sunStrong.get()); - DI.sunModule().sunSoft(sunSoft.get()); - DI.sunModule().star(starWeak.get()); + val DI = PlanetRollingComponentStoneComponent() + val earthStrong = WeakReference(Earth()) + val earthSoft = WeakReference(Earth()) + val planetWeak = WeakReference(Earth()) + val sunStrong = WeakReference(Sun()) + val sunSoft = WeakReference(Sun()) + val starWeak = WeakReference(Sun()) + DI.earthStrong(earthStrong.get()) + DI.earthSoft(earthSoft.get()) + DI.planet(planetWeak.get()) + DI.sunModule().sunStrong(sunStrong.get()) + DI.sunModule().sunSoft(sunSoft.get()) + DI.sunModule().star(starWeak.get()) //When - DI.gcSoft(); + DI.gcSoft() //Then - for (WeakReference ref : Arrays.asList( - earthSoft, planetWeak, - sunSoft, starWeak + for (ref in listOf( + earthSoft, planetWeak, + sunSoft, starWeak )) { - assertNull(ref.get()); + assertNull(ref.get()) } - for (WeakReference ref : Arrays.asList( - earthStrong, - sunStrong + for (ref in listOf( + earthStrong, + sunStrong )) { - assertNotNull(ref.get()); + assertNotNull(ref.get()) } } @Test - public void gcWeakTest() { + fun gcWeakTest() { //Given - PlanetRollingComponent DI = Stone.createComponent(PlanetRollingComponent.class); - WeakReference earthStrong = new WeakReference<>(new Earth()); - WeakReference earthSoft = new WeakReference<>(new Earth()); - WeakReference planetWeak = new WeakReference<>(new Earth()); - WeakReference sunStrong = new WeakReference<>(new Sun()); - WeakReference sunSoft = new WeakReference<>(new Sun()); - WeakReference starWeak = new WeakReference<>(new Sun()); - DI.earthStrong(earthStrong.get()); - DI.earthSoft(earthSoft.get()); - DI.planet(planetWeak.get()); - DI.sunModule().sunStrong(sunStrong.get()); - DI.sunModule().sunSoft(sunSoft.get()); - DI.sunModule().star(starWeak.get()); + val DI = PlanetRollingComponentStoneComponent() + val earthStrong = WeakReference(Earth()) + val earthSoft = WeakReference(Earth()) + val planetWeak = WeakReference(Earth()) + val sunStrong = WeakReference(Sun()) + val sunSoft = WeakReference(Sun()) + val starWeak = WeakReference(Sun()) + DI.earthStrong(earthStrong.get()) + DI.earthSoft(earthSoft.get()) + DI.planet(planetWeak.get()) + DI.sunModule().sunStrong(sunStrong.get()) + DI.sunModule().sunSoft(sunSoft.get()) + DI.sunModule().star(starWeak.get()) //When - DI.gcWeak(); + DI.gcWeak() //Then - for (WeakReference ref : Arrays.asList( - planetWeak, - starWeak + for (ref in listOf( + planetWeak, + starWeak )) { - assertNull(ref.get()); + assertNull(ref.get()) } - for (WeakReference ref : Arrays.asList( - earthStrong, earthSoft, - sunStrong, sunSoft + for (ref in listOf( + earthStrong, earthSoft, + sunStrong, sunSoft )) { - assertNotNull(ref.get()); + assertNotNull(ref.get()) } } @Test - public void gcSoftSunTest() { + fun gcSoftSunTest() { //Given - PlanetRollingComponent DI = Stone.createComponent(PlanetRollingComponent.class); - WeakReference earthStrong = new WeakReference<>(new Earth()); - WeakReference earthSoft = new WeakReference<>(new Earth()); - WeakReference planetWeak = new WeakReference<>(new Earth()); - WeakReference sunStrong = new WeakReference<>(new Sun()); - WeakReference sunSoft = new WeakReference<>(new Sun()); - WeakReference starWeak = new WeakReference<>(new Sun()); - DI.earthStrong(earthStrong.get()); - DI.earthSoft(earthSoft.get()); - DI.planet(planetWeak.get()); - DI.sunModule().sunStrong(sunStrong.get()); - DI.sunModule().sunSoft(sunSoft.get()); - DI.sunModule().star(starWeak.get()); + val DI = PlanetRollingComponentStoneComponent() + val earthStrong = WeakReference(Earth()) + val earthSoft = WeakReference(Earth()) + val planetWeak = WeakReference(Earth()) + val sunStrong = WeakReference(Sun()) + val sunSoft = WeakReference(Sun()) + val starWeak = WeakReference(Sun()) + DI.earthStrong(earthStrong.get()) + DI.earthSoft(earthSoft.get()) + DI.planet(planetWeak.get()) + DI.sunModule().sunStrong(sunStrong.get()) + DI.sunModule().sunSoft(sunSoft.get()) + DI.sunModule().star(starWeak.get()) //When - DI.gcSoftSun(); + DI.gcSoftSun() //Then - for (WeakReference ref : Arrays.asList( - planetWeak, - sunSoft, starWeak + for (ref in listOf( + planetWeak, + sunSoft, starWeak )) { - assertNull(ref.get()); + assertNull(ref.get()) } - for (WeakReference ref : Arrays.asList( - earthStrong, earthSoft, - sunStrong + for (ref in listOf( + earthStrong, earthSoft, + sunStrong )) { - assertNotNull(ref.get()); + assertNotNull(ref.get()) } } @Test - public void gcSoftPlanetsTest() { + fun gcSoftPlanetsTest() { //Given - PlanetRollingComponent DI = Stone.createComponent(PlanetRollingComponent.class); - WeakReference earthStrong = new WeakReference<>(new Earth()); - WeakReference earthSoft = new WeakReference<>(new Earth()); - WeakReference planetWeak = new WeakReference<>(new Earth()); - WeakReference sunStrong = new WeakReference<>(new Sun()); - WeakReference sunSoft = new WeakReference<>(new Sun()); - WeakReference starWeak = new WeakReference<>(new Sun()); - DI.earthStrong(earthStrong.get()); - DI.earthSoft(earthSoft.get()); - DI.planet(planetWeak.get()); - DI.sunModule().sunStrong(sunStrong.get()); - DI.sunModule().sunSoft(sunSoft.get()); - DI.sunModule().star(starWeak.get()); + val DI = PlanetRollingComponentStoneComponent() + val earthStrong = WeakReference(Earth()) + val earthSoft = WeakReference(Earth()) + val planetWeak = WeakReference(Earth()) + val sunStrong = WeakReference(Sun()) + val sunSoft = WeakReference(Sun()) + val starWeak = WeakReference(Sun()) + DI.earthStrong(earthStrong.get()) + DI.earthSoft(earthSoft.get()) + DI.planet(planetWeak.get()) + DI.sunModule().sunStrong(sunStrong.get()) + DI.sunModule().sunSoft(sunSoft.get()) + DI.sunModule().star(starWeak.get()) //When - DI.gcSoftPlanets(); + DI.gcSoftPlanets() //Then - for (WeakReference ref : Arrays.asList( - earthSoft, planetWeak, - starWeak + for (ref in listOf( + earthSoft, planetWeak, + starWeak )) { - assertNull(ref.get()); + assertNull(ref.get()) } - for (WeakReference ref : Arrays.asList( - earthStrong, - sunStrong, sunSoft + for (ref in listOf( + earthStrong, + sunStrong, sunSoft )) { - assertNotNull(ref.get()); + assertNotNull(ref.get()) } } - - } diff --git a/tests/src/test/java/com/github/klee0kai/stone/test/bindinstance/singlemethod_inject/MoonSkyProtectInjectedTests.kt b/tests/src/test/java/com/github/klee0kai/stone/test/bindinstance/singlemethod_inject/MoonSkyProtectInjectedTests.kt index 3ab408a7..9f2e391a 100644 --- a/tests/src/test/java/com/github/klee0kai/stone/test/bindinstance/singlemethod_inject/MoonSkyProtectInjectedTests.kt +++ b/tests/src/test/java/com/github/klee0kai/stone/test/bindinstance/singlemethod_inject/MoonSkyProtectInjectedTests.kt @@ -1,65 +1,63 @@ -package com.github.klee0kai.stone.test.bindinstance.singlemethod_inject; +package com.github.klee0kai.stone.test.bindinstance.singlemethod_inject -import com.github.klee0kai.stone.Stone; -import com.github.klee0kai.test.di.bindinstance.singlemethod_inject.StarSkyComponent; -import com.github.klee0kai.test.mowgli.MoonSky; -import com.github.klee0kai.test.mowgli.galaxy.Mercury; -import com.github.klee0kai.test.mowgli.galaxy.Sun; -import org.junit.jupiter.api.Test; +import com.github.klee0kai.test.di.bindinstance.singlemethod_inject.StarSkyComponentStoneComponent +import com.github.klee0kai.test.mowgli.MoonSky +import com.github.klee0kai.test.mowgli.galaxy.Mercury +import com.github.klee0kai.test.mowgli.galaxy.Sun +import org.junit.jupiter.api.Test +import org.junit.jupiter.api.assertNotNull +import org.junit.jupiter.api.assertNull +import java.lang.ref.WeakReference -import java.lang.ref.WeakReference; - -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertNull; - -public class MoonSkyProtectInjectedTests { +class MoonSkyProtectInjectedTests { @Test - public void withoutProtectInjectedTest() { + fun withoutProtectInjectedTest() { //Given - StarSkyComponent component = Stone.createComponent(StarSkyComponent.class); - WeakReference mercury = new WeakReference<>(new Mercury()); - WeakReference star = new WeakReference<>(new Sun()); - component.starModule().star(star.get()); - component.mercury(mercury.get()); + val component = StarSkyComponentStoneComponent() + val mercury = WeakReference(Mercury()) + val star = WeakReference(Sun()) + component.starModule().star(star.get()) + component.mercury(mercury.get()) //When - MoonSky moonSky = new MoonSky(); - component.inject(moonSky); - moonSky = null; - component.gcAll(); + var moonSky: MoonSky? = MoonSky() + component.inject(moonSky) + moonSky = null + component.gcAll() //Then - assertNull(mercury.get()); - assertNull(star.get()); + assertNull(mercury.get()) + assertNull(star.get()) } @Test - public void withProtectInjectedTest() throws InterruptedException { + @Throws(InterruptedException::class) + fun withProtectInjectedTest() { //Given - System.gc(); - StarSkyComponent component = Stone.createComponent(StarSkyComponent.class); - WeakReference mercury = new WeakReference<>(new Mercury()); - WeakReference star = new WeakReference<>(new Sun()); - component.starModule().star(star.get()); - component.mercury(mercury.get()); + System.gc() + val component = StarSkyComponentStoneComponent() + val mercury = WeakReference(Mercury()) + val star = WeakReference(Sun()) + component.starModule().star(star.get()) + component.mercury(mercury.get()) //When - MoonSky moonSky = new MoonSky(); - component.inject(moonSky); - component.protectInjected(moonSky); - moonSky = null; - component.gcAll(); + var moonSky: MoonSky? = MoonSky() + component.inject(moonSky) + component.protectInjected(moonSky) + moonSky = null + component.gcAll() - assertNotNull(mercury.get()); - assertNotNull(star.get()); + assertNotNull(mercury.get()) + assertNotNull(star.get()) //Then after protect finished - Thread.sleep(100); - System.gc(); - assertNull(mercury.get()); - assertNull(star.get()); + Thread.sleep(100) + System.gc() + assertNull(mercury.get()) + assertNull(star.get()) } } diff --git a/tests/src/test/java/com/github/klee0kai/stone/test/bindinstance/singlemethod_inject/MoonSkyTests.kt b/tests/src/test/java/com/github/klee0kai/stone/test/bindinstance/singlemethod_inject/MoonSkyTests.kt index ca1aaeb0..c603ae77 100644 --- a/tests/src/test/java/com/github/klee0kai/stone/test/bindinstance/singlemethod_inject/MoonSkyTests.kt +++ b/tests/src/test/java/com/github/klee0kai/stone/test/bindinstance/singlemethod_inject/MoonSkyTests.kt @@ -1,39 +1,35 @@ -package com.github.klee0kai.stone.test.bindinstance.singlemethod_inject; +package com.github.klee0kai.stone.test.bindinstance.singlemethod_inject -import com.github.klee0kai.stone.Stone; -import com.github.klee0kai.test.di.bindinstance.singlemethod_inject.StarSkyComponent; -import com.github.klee0kai.test.mowgli.MoonSky; -import com.github.klee0kai.test.mowgli.galaxy.Earth; -import com.github.klee0kai.test.mowgli.galaxy.Mercury; -import com.github.klee0kai.test.mowgli.galaxy.Sun; -import org.junit.jupiter.api.Test; +import com.github.klee0kai.test.di.bindinstance.singlemethod_inject.StarSkyComponentStoneComponent +import com.github.klee0kai.test.mowgli.MoonSky +import com.github.klee0kai.test.mowgli.galaxy.Earth +import com.github.klee0kai.test.mowgli.galaxy.Mercury +import com.github.klee0kai.test.mowgli.galaxy.Sun +import org.junit.jupiter.api.Assertions.assertEquals -import static org.junit.jupiter.api.Assertions.assertEquals; +class MoonSkyTests { -public class MoonSkyTests { - - @Test - public void moonSkyTest() { + @org.junit.jupiter.api.Test + fun moonSkyTest() { //Given - StarSkyComponent component = Stone.createComponent(StarSkyComponent.class); - Sun sun = new Sun(); - Sun star = new Sun(); - Earth earth = new Earth(); - Mercury planet = new Mercury(); - component.starModule().sun(sun); - component.starModule().star(star); - component.earth(earth); - component.planet(planet); + val component = StarSkyComponentStoneComponent() + val sun = Sun() + val star = Sun() + val earth = Earth() + val planet = Mercury() + component.starModule().sun(sun) + component.starModule().star(star) + component.earth(earth) + component.planet(planet) //When - MoonSky moonSky = new MoonSky(); - component.inject(moonSky); + val moonSky: MoonSky = MoonSky() + component.inject(moonSky) //Then - assertEquals(sun, moonSky.sun); - assertEquals(star, moonSky.star); - assertEquals(earth, moonSky.earth); - assertEquals(planet, moonSky.planet); + assertEquals(sun, moonSky.sun) + assertEquals(star, moonSky.star) + assertEquals(earth, moonSky.earth) + assertEquals(planet, moonSky.planet) } - } diff --git a/tests/src/test/java/com/github/klee0kai/stone/test/bindinstance/solarsystem/SolarSystemTests.kt b/tests/src/test/java/com/github/klee0kai/stone/test/bindinstance/solarsystem/SolarSystemTests.kt index 1975bee6..b2c1215d 100644 --- a/tests/src/test/java/com/github/klee0kai/stone/test/bindinstance/solarsystem/SolarSystemTests.kt +++ b/tests/src/test/java/com/github/klee0kai/stone/test/bindinstance/solarsystem/SolarSystemTests.kt @@ -1,41 +1,37 @@ -package com.github.klee0kai.stone.test.bindinstance.solarsystem; +package com.github.klee0kai.stone.test.bindinstance.solarsystem -import com.github.klee0kai.stone.Stone; -import com.github.klee0kai.test.di.bindinstance.solarsystem.SolarSystemComponent; -import com.github.klee0kai.test.mowgli.galaxy.SolarSystem; -import org.junit.jupiter.api.Test; +import com.github.klee0kai.test.di.bindinstance.solarsystem.SolarSystemComponentStoneComponent +import com.github.klee0kai.test.mowgli.galaxy.SolarSystem +import org.junit.jupiter.api.Assertions.assertEquals +import org.junit.jupiter.api.Assertions.assertNotNull +import org.junit.jupiter.api.Test -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotNull; - -public class SolarSystemTests { +class SolarSystemTests { @Test - public void provideSolarSystemTest() { + fun provideSolarSystemTest() { //Given - SolarSystemComponent DI = Stone.createComponent(SolarSystemComponent.class); - SolarSystem solarSystem = new SolarSystem(); + val DI = SolarSystemComponentStoneComponent() + val solarSystem = SolarSystem() // When - DI.bind(solarSystem); + DI.bind(solarSystem) // Then - assertEquals(solarSystem, DI.bind(null)); + assertEquals(solarSystem, DI.bind(null)) } @Test - public void provideEarthTest() { + fun provideEarthTest() { //Given - SolarSystemComponent DI = Stone.createComponent(SolarSystemComponent.class); - SolarSystem solarSystem = new SolarSystem(); + val DI = SolarSystemComponentStoneComponent() + val solarSystem = SolarSystem() // When - DI.bind(solarSystem); + DI.bind(solarSystem) // Then - assertNotNull(DI.earth()); + assertNotNull(DI.earth()) } - - } diff --git a/tests/src/test/java/com/github/klee0kai/stone/test/cache/EarthCacheTests.kt b/tests/src/test/java/com/github/klee0kai/stone/test/cache/EarthCacheTests.kt index d3236967..de952bf4 100644 --- a/tests/src/test/java/com/github/klee0kai/stone/test/cache/EarthCacheTests.kt +++ b/tests/src/test/java/com/github/klee0kai/stone/test/cache/EarthCacheTests.kt @@ -1,148 +1,144 @@ -package com.github.klee0kai.stone.test.cache; +package com.github.klee0kai.stone.test.cache -import com.github.klee0kai.stone.Stone; -import com.github.klee0kai.test.di.gcforest.GcGodComponent; -import com.github.klee0kai.test.mowgli.earth.Mountain; -import org.junit.jupiter.api.Test; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotEquals; - -public class EarthCacheTests { +import com.github.klee0kai.test.di.gcforest.GcGodComponentStoneComponent +import org.junit.jupiter.api.Assertions.assertEquals +import org.junit.jupiter.api.Assertions.assertNotEquals +import org.junit.jupiter.api.Test +class EarthCacheTests { @Test - public void strongCacheTest() { + fun strongCacheTest() { //Given - GcGodComponent DI = Stone.createComponent(GcGodComponent.class); + val DI = GcGodComponentStoneComponent() //When - Mountain mountain1 = DI.earth().mountainStrong(); - Mountain mountain2 = DI.earth().mountainStrong(); + val mountain1 = DI.earth().mountainStrong() + val mountain2 = DI.earth().mountainStrong() //Then assertEquals( - mountain1.uuid, - mountain2.uuid - ); + mountain1?.uuid, + mountain2?.uuid + ) } @Test - public void softCacheTest() { + fun softCacheTest() { //Given - GcGodComponent DI = Stone.createComponent(GcGodComponent.class); + val DI = GcGodComponentStoneComponent() //When - Mountain mountain1 = DI.earth().mountainSoft(); - Mountain mountain2 = DI.earth().mountainSoft(); + val mountain1 = DI.earth().mountainSoft() + val mountain2 = DI.earth().mountainSoft() //Then assertEquals( - mountain1.uuid, - mountain2.uuid - ); + mountain1?.uuid, + mountain2?.uuid + ) } @Test - public void weakCacheTest() { + fun weakCacheTest() { //Given - GcGodComponent DI = Stone.createComponent(GcGodComponent.class); + val DI = GcGodComponentStoneComponent() //When - Mountain mountain1 = DI.earth().mountainWeak(); - Mountain mountain2 = DI.earth().mountainWeak(); + val mountain1 = DI.earth().mountainWeak() + val mountain2 = DI.earth().mountainWeak() //Then assertEquals( - mountain1.uuid, - mountain2.uuid - ); + mountain1?.uuid, + mountain2?.uuid + ) } @Test - public void defCacheTest() { + fun defCacheTest() { //Given - GcGodComponent DI = Stone.createComponent(GcGodComponent.class); + val DI = GcGodComponentStoneComponent() //When - Mountain mountain1 = DI.earth().mountainDefaultFactory(); - Mountain mountain2 = DI.earth().mountainDefaultFactory(); + val mountain1 = DI.earth().mountainDefaultFactory() + val mountain2 = DI.earth().mountainDefaultFactory() //Then assertNotEquals( - mountain1.uuid, - mountain2.uuid, - "Default is factory providing" - ); + mountain1?.uuid, + mountain2?.uuid, + "Default is factory providing" + ) } @Test - public void defCache2Test() { + fun defCache2Test() { //Given - GcGodComponent DI = Stone.createComponent(GcGodComponent.class); + val DI = GcGodComponentStoneComponent() //When - Mountain mountain1 = DI.earth().mountainDefault2Factory(); - Mountain mountain2 = DI.earth().mountainDefault2Factory(); + val mountain1 = DI.earth().mountainDefault2Factory() + val mountain2 = DI.earth().mountainDefault2Factory() //Then assertNotEquals( - mountain1.uuid, - mountain2.uuid, - "Default is factory providing" - ); + mountain1?.uuid, + mountain2?.uuid, + "Default is factory providing" + ) } @Test - public void differentMethodDifferentCacheTest() { + fun differentMethodDifferentCacheTest() { //Given - GcGodComponent DI = Stone.createComponent(GcGodComponent.class); + val DI = GcGodComponentStoneComponent() //When - Mountain mountainStrong = DI.earth().mountainStrong(); - Mountain mountainSoft = DI.earth().mountainSoft(); + val mountainStrong = DI.earth().mountainStrong() + val mountainSoft = DI.earth().mountainSoft() //Then assertNotEquals( - mountainStrong.uuid, - mountainSoft.uuid - ); + mountainStrong?.uuid, + mountainSoft?.uuid + ) } @Test - public void factoryNotCacheTest() { + fun factoryNotCacheTest() { //Given - GcGodComponent DI = Stone.createComponent(GcGodComponent.class); + val DI = GcGodComponentStoneComponent() //When - Mountain mountain1 = DI.earth().mountainFactory(); - Mountain mountain2 = DI.earth().mountainFactory(); + val mountain1 = DI.earth().mountainFactory() + val mountain2 = DI.earth().mountainFactory() //Then assertNotEquals( - mountain1.uuid, - mountain2.uuid - ); + mountain1?.uuid, + mountain2?.uuid + ) } @Test - public void differentDIDifferentCacheTest() { + fun differentDIDifferentCacheTest() { //Given - GcGodComponent DI1 = Stone.createComponent(GcGodComponent.class); - GcGodComponent DI2 = Stone.createComponent(GcGodComponent.class); + val DI1 = GcGodComponentStoneComponent() + val DI2 = GcGodComponentStoneComponent() //When - Mountain mountain1 = DI1.earth().mountainStrong(); - Mountain mountain2 = DI2.earth().mountainStrong(); + val mountain1 = DI1.earth().mountainStrong() + val mountain2 = DI2.earth().mountainStrong() //Then assertNotEquals( - mountain1.uuid, - mountain2.uuid - ); + mountain1?.uuid, + mountain2?.uuid, + ) } } diff --git a/tests/src/test/java/com/github/klee0kai/stone/test/cache/EarthSwitchCacheTests.kt b/tests/src/test/java/com/github/klee0kai/stone/test/cache/EarthSwitchCacheTests.kt index b62ee09d..b1e29388 100644 --- a/tests/src/test/java/com/github/klee0kai/stone/test/cache/EarthSwitchCacheTests.kt +++ b/tests/src/test/java/com/github/klee0kai/stone/test/cache/EarthSwitchCacheTests.kt @@ -1,87 +1,80 @@ -package com.github.klee0kai.stone.test.cache; +package com.github.klee0kai.stone.test.cache -import com.github.klee0kai.stone.Stone; -import com.github.klee0kai.test.di.swcache.SwitchCacheComponent; -import com.github.klee0kai.test.mowgli.earth.Mountain; -import com.github.klee0kai.test.mowgli.earth.River; -import org.junit.jupiter.api.Test; - -import java.lang.ref.WeakReference; - -import static java.lang.Thread.sleep; -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertNull; - -public class EarthSwitchCacheTests { +import com.github.klee0kai.test.di.swcache.SwitchCacheComponentStoneComponent +import org.junit.jupiter.api.Test +import org.junit.jupiter.api.assertNotNull +import org.junit.jupiter.api.assertNull +import java.lang.ref.WeakReference +class EarthSwitchCacheTests { @Test - public void allToWeakTest() { + fun allToWeakTest() { //Given - SwitchCacheComponent DI = Stone.createComponent(SwitchCacheComponent.class); - WeakReference mountain = new WeakReference<>(DI.earth().mountainStrong()); + val DI = SwitchCacheComponentStoneComponent() + val mountain = WeakReference(DI.earth().mountainStrong()) //When - DI.allWeak(); - System.gc(); + DI.allWeak() + System.gc() //Then - assertNull(mountain.get()); + assertNull(mountain.get()) } @Test - public void strongToWeakTest() { + fun strongToWeakTest() { //Given - SwitchCacheComponent DI = Stone.createComponent(SwitchCacheComponent.class); - WeakReference mountainStrong = new WeakReference<>(DI.earth().mountainStrong()); - WeakReference mountainSoft = new WeakReference<>(DI.earth().mountainSoft()); + val DI = SwitchCacheComponentStoneComponent() + val mountainStrong = WeakReference(DI.earth().mountainStrong()) + val mountainSoft = WeakReference(DI.earth().mountainSoft()) //When - DI.strongToWeak(); - System.gc(); + DI.strongToWeak() + System.gc() //Then - assertNull(mountainStrong.get()); - assertNotNull(mountainSoft.get()); + assertNull(mountainStrong.get()) + assertNotNull(mountainSoft.get()) } @Test - public void weakToStrongFewMillisTest() throws InterruptedException { + @Throws(InterruptedException::class) + fun weakToStrongFewMillisTest() { //Given - SwitchCacheComponent DI = Stone.createComponent(SwitchCacheComponent.class); - WeakReference mountainWeak = new WeakReference<>(DI.earth().mountainWeak()); + val DI = SwitchCacheComponentStoneComponent() + val mountainWeak = WeakReference(DI.earth().mountainWeak()) //When - DI.allStrongFewMillis(); - System.gc(); + DI.allStrongFewMillis() + System.gc() //Then: can't GC - assertNotNull(mountainWeak.get()); + assertNotNull(mountainWeak.get()) //When: after few millis - sleep(110); - System.gc(); + Thread.sleep(110) + System.gc() //Then: can GC - assertNull(mountainWeak.get()); + assertNull(mountainWeak.get()) } @Test - public void mountainToWeakTest() { + fun mountainToWeakTest() { //Given - SwitchCacheComponent DI = Stone.createComponent(SwitchCacheComponent.class); - WeakReference mountain = new WeakReference<>(DI.earth().mountainStrong()); - WeakReference river = new WeakReference<>(DI.earth().riverSoft()); + val DI = SwitchCacheComponentStoneComponent() + val mountain = WeakReference(DI.earth().mountainStrong()) + val river = WeakReference(DI.earth().riverSoft()) //When - DI.mountainToWeak(); - System.gc(); + DI.mountainToWeak() + System.gc() //Then - assertNull(mountain.get()); - assertNotNull(river.get()); + assertNull(mountain.get()) + assertNotNull(river.get()) } - } diff --git a/tests/src/test/java/com/github/klee0kai/stone/test/deps/HouseFactoryTests.kt b/tests/src/test/java/com/github/klee0kai/stone/test/deps/HouseFactoryTests.kt index 15d46efc..86c2e84a 100644 --- a/tests/src/test/java/com/github/klee0kai/stone/test/deps/HouseFactoryTests.kt +++ b/tests/src/test/java/com/github/klee0kai/stone/test/deps/HouseFactoryTests.kt @@ -1,40 +1,38 @@ -package com.github.klee0kai.stone.test.deps; +package com.github.klee0kai.stone.test.deps -import com.github.klee0kai.stone.Stone; -import com.github.klee0kai.test.di.house.simple.HouseComponent; -import com.github.klee0kai.test.house.House; -import org.junit.jupiter.api.Test; +import com.github.klee0kai.test.di.house.simple.HouseComponentStoneComponent +import org.junit.jupiter.api.Assertions.assertEquals +import org.junit.jupiter.api.Assertions.assertNotEquals +import org.junit.jupiter.api.Test -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotEquals; +class HouseFactoryTests { -public class HouseFactoryTests { @Test - public void cacheTest() { + fun cacheTest() { //Given - HouseComponent di = Stone.createComponent(HouseComponent.class); + val di = HouseComponentStoneComponent() //when - House house1 = di.module().house(null, null, null, null); - House house2 = di.module().house(null, null, null, null); + val house1 = di.module().house(null, null, null, null) + val house2 = di.module().house(null, null, null, null) //then - assertEquals(house1.uuid, house2.uuid); + assertEquals(house1?.uuid, house2?.uuid) } @Test - public void factoryTest() { + fun factoryTest() { //Given - HouseComponent di = Stone.createComponent(HouseComponent.class); + val di = HouseComponentStoneComponent() //when - House house1 = di.moduleFactory().house(null, null, null, null); - House house2 = di.moduleFactory().house(null, null, null, null); + val house1 = di.moduleFactory()?.house(null, null, null, null) + val house2 = di.moduleFactory()?.house(null, null, null, null) //then - assertNotEquals(house1.uuid, house2.uuid); + assertNotEquals(house1?.uuid, house2?.uuid) } } diff --git a/tests/src/test/java/com/github/klee0kai/stone/test/deps/HouseNullsTests.kt b/tests/src/test/java/com/github/klee0kai/stone/test/deps/HouseNullsTests.kt index 2437a54a..05dd2a74 100644 --- a/tests/src/test/java/com/github/klee0kai/stone/test/deps/HouseNullsTests.kt +++ b/tests/src/test/java/com/github/klee0kai/stone/test/deps/HouseNullsTests.kt @@ -1,27 +1,24 @@ -package com.github.klee0kai.stone.test.deps; +package com.github.klee0kai.stone.test.deps -import com.github.klee0kai.stone.Stone; -import com.github.klee0kai.test.di.house.nulls.HouseNullsComponent; -import com.github.klee0kai.test.house.House; -import org.junit.jupiter.api.Test; +import com.github.klee0kai.test.di.house.nulls.HouseNullsComponentStoneComponent +import org.junit.jupiter.api.Test +import org.junit.jupiter.api.assertNull -import static org.junit.jupiter.api.Assertions.assertNull; - -public class HouseNullsTests { +class HouseNullsTests { @Test - public void buildOnlyKitchenTest() { + fun buildOnlyKitchenTest() { //Given - HouseNullsComponent di = Stone.createComponent(HouseNullsComponent.class); + val di = HouseNullsComponentStoneComponent() //when - House house = di.house(); + val house = di.house() //then - assertNull(house.bathRoom); - assertNull(house.kichen.cookingArea); - assertNull(house.kichen.storeArea); - assertNull(house.kichen.sinkArea); + assertNull(house?.bathRoom) + assertNull(house?.kichen?.cookingArea) + assertNull(house?.kichen?.storeArea) + assertNull(house?.kichen?.sinkArea) } } diff --git a/tests/src/test/java/com/github/klee0kai/stone/test/deps/HouseTests.kt b/tests/src/test/java/com/github/klee0kai/stone/test/deps/HouseTests.kt index a2eea9b8..4bbaf791 100644 --- a/tests/src/test/java/com/github/klee0kai/stone/test/deps/HouseTests.kt +++ b/tests/src/test/java/com/github/klee0kai/stone/test/deps/HouseTests.kt @@ -1,85 +1,92 @@ -package com.github.klee0kai.stone.test.deps; +package com.github.klee0kai.stone.test.deps -import com.github.klee0kai.stone.Stone; -import com.github.klee0kai.test.di.house.simple.HouseComponent; -import com.github.klee0kai.test.house.House; -import com.github.klee0kai.test.house.kitchen.storagearea.Sanitizers; -import com.github.klee0kai.test.house.identifiers.StoreAreaType; -import org.junit.jupiter.api.Test; +import com.github.klee0kai.test.di.house.simple.HouseComponentStoneComponent +import com.github.klee0kai.test.house.House +import com.github.klee0kai.test.house.identifiers.StoreAreaType +import org.junit.jupiter.api.Assertions.assertEquals +import org.junit.jupiter.api.Assertions.assertNotEquals +import org.junit.jupiter.api.Test +import org.junit.jupiter.api.assertNotNull +import org.junit.jupiter.api.assertNull -import static org.junit.jupiter.api.Assertions.*; - -public class HouseTests { +class HouseTests { @Test - public void buildHouseTest() { + fun buildHouseTest() { //Given - HouseComponent di = Stone.createComponent(HouseComponent.class); + val di = HouseComponentStoneComponent() //when - House house = di.house(); + val house = di.house() //then - assertNotNull(house.bathRoom); - assertNotNull(house.kichen.cookingArea); - assertNotNull(house.kichen.storeArea); - assertNotNull(house.kichen.sinkArea); + assertNotNull(house?.bathRoom) + assertNotNull(house?.kichen?.cookingArea) + assertNotNull(house?.kichen?.storeArea) + assertNotNull(house?.kichen?.sinkArea) } @Test - public void identifiersTest() { + fun identifiersTest() { //Given - HouseComponent di = Stone.createComponent(HouseComponent.class); + val di = HouseComponentStoneComponent() //when - House house = di.house(StoreAreaType.CLOSED); + val house = di.house(StoreAreaType.CLOSED) //then - assertEquals(StoreAreaType.CLOSED, house.kichen.storeArea.type); + assertEquals(StoreAreaType.CLOSED, house?.kichen?.storeArea?.type) } @Test - public void identifiersNullTest() { + fun identifiersNullTest() { //Given - HouseComponent di = Stone.createComponent(HouseComponent.class); + val di = HouseComponentStoneComponent() //when - House house = di.house(); + val house = di.house() //then - assertNull(house.kichen.storeArea.type); + assertNull(house?.kichen?.storeArea?.type) } @Test - public void cacheTest() { + fun cacheTest() { //Given - HouseComponent di = Stone.createComponent(HouseComponent.class); + val di = HouseComponentStoneComponent() //when - House house1 = di.house(); - House house2 = di.house(); + val house1: House? = di.house() + val house2: House? = di.house() //then - assertEquals(house1.kichen.uuid, house2.kichen.uuid); + assertEquals( + house1?.kichen?.uuid, + house2?.kichen?.uuid + ) } @Test - public void factoryTest() { + fun factoryTest() { //Given - HouseComponent di = Stone.createComponent(HouseComponent.class); + val di = HouseComponentStoneComponent() //when - House house = di.house(); - Sanitizers sanitizers1 = di.sanitizers(); - Sanitizers sanitizers2 = di.sanitizers(); + val house: House? = di.house() + val sanitizers1 = di.sanitizers() + val sanitizers2 = di.sanitizers() //then - assertNotEquals(sanitizers1.uuid, sanitizers2.uuid); - assertNotEquals(house.kichen.storeArea.sanitizers, house.bathRoom.storeArea.sanitizers); - assertNotEquals(house.kichen.storeArea.sanitizers, house.bedRoom.storeArea.sanitizers); + assertNotEquals(sanitizers1?.uuid, sanitizers2?.uuid) + assertNotEquals( + house?.kichen?.storeArea?.sanitizers, + house?.bathRoom?.storeArea?.sanitizers + ) + assertNotEquals( + house?.kichen?.storeArea?.sanitizers, + house?.bedRoom?.storeArea?.sanitizers + ) } - - } diff --git a/tests/src/test/java/com/github/klee0kai/stone/test/deps/InHouseTests.kt b/tests/src/test/java/com/github/klee0kai/stone/test/deps/InHouseTests.kt index bdd5d5cf..928421bd 100644 --- a/tests/src/test/java/com/github/klee0kai/stone/test/deps/InHouseTests.kt +++ b/tests/src/test/java/com/github/klee0kai/stone/test/deps/InHouseTests.kt @@ -1,91 +1,98 @@ -package com.github.klee0kai.stone.test.deps; - -import com.github.klee0kai.stone.Stone; -import com.github.klee0kai.test.di.house.simple.HouseComponent; -import com.github.klee0kai.test.house.InHouse; -import com.github.klee0kai.test.house.identifiers.StoreAreaType; -import org.junit.jupiter.api.Test; - -import static org.junit.jupiter.api.Assertions.*; - -public class InHouseTests { - - @Test - public void buildHouseTest() { +package com.github.klee0kai.stone.test.deps + +import com.github.klee0kai.test.di.house.simple.HouseComponentStoneComponent +import com.github.klee0kai.test.house.InHouse +import com.github.klee0kai.test.house.identifiers.StoreAreaType +import org.junit.jupiter.api.Assertions.assertEquals +import org.junit.jupiter.api.Assertions.assertNotEquals +import org.junit.jupiter.api.assertNotNull +import org.junit.jupiter.api.assertNull + +class InHouseTests { + @org.junit.jupiter.api.Test + fun buildHouseTest() { //Given - HouseComponent di = Stone.createComponent(HouseComponent.class); - InHouse inHouse = new InHouse(); + val di = HouseComponentStoneComponent() + val inHouse = InHouse() //when - di.inject(inHouse); + di.inject(inHouse) //then - assertNotNull(inHouse.bathRoom); - assertNotNull(inHouse.kichen.cookingArea); - assertNotNull(inHouse.kichen.storeArea); - assertNotNull(inHouse.kichen.sinkArea); - assertNotNull(inHouse.bedStoreArea); + assertNotNull(inHouse.bathRoom) + assertNotNull(inHouse.kichen?.cookingArea) + assertNotNull(inHouse.kichen?.storeArea) + assertNotNull(inHouse.kichen?.sinkArea) + assertNotNull(inHouse.bedStoreArea) } - @Test - public void identifiersTest() { + @org.junit.jupiter.api.Test + fun identifiersTest() { //Given - HouseComponent di = Stone.createComponent(HouseComponent.class); - InHouse inHouse = new InHouse(); + val di = HouseComponentStoneComponent() + val inHouse = InHouse() //when - di.inject(StoreAreaType.CLOSED,inHouse); + di.inject(StoreAreaType.CLOSED, inHouse) //then - assertEquals(StoreAreaType.CLOSED, inHouse.kichen.storeArea.type); + assertEquals(StoreAreaType.CLOSED, inHouse.kichen?.storeArea?.type) } - @Test - public void identifiersNullTest() { + @org.junit.jupiter.api.Test + fun identifiersNullTest() { //Given - HouseComponent di = Stone.createComponent(HouseComponent.class); - InHouse inHouse = new InHouse(); + val di = HouseComponentStoneComponent() + val inHouse = InHouse() //when - di.inject(inHouse); + di.inject(inHouse) //then - assertNull(inHouse.kichen.storeArea.type); + assertNull(inHouse.kichen?.storeArea?.type) } - @Test - public void cacheTest() { + @org.junit.jupiter.api.Test + fun cacheTest() { //Given - HouseComponent di = Stone.createComponent(HouseComponent.class); - InHouse inHouse1 = new InHouse(); - InHouse inHouse2 = new InHouse(); + val di = HouseComponentStoneComponent() + val inHouse1 = InHouse() + val inHouse2 = InHouse() //when - di.inject(inHouse1); - di.inject(inHouse2); + di.inject(inHouse1) + di.inject(inHouse2) //then - assertEquals(inHouse1.kichen.uuid, inHouse2.kichen.uuid); + assertEquals( + inHouse1.kichen?.uuid, + inHouse2.kichen?.uuid + ) } - @Test - public void factoryTest() { + @org.junit.jupiter.api.Test + fun factoryTest() { //Given - HouseComponent di = Stone.createComponent(HouseComponent.class); - InHouse inHouse1 = new InHouse(); - InHouse inHouse2 = new InHouse(); + val di = HouseComponentStoneComponent() + val inHouse1 = InHouse() + val inHouse2 = InHouse() //when - di.inject(inHouse1); - di.inject(inHouse2); + di.inject(inHouse1) + di.inject(inHouse2) //then - assertNotEquals(inHouse1.kichen.storeArea.sanitizers,inHouse2.bathRoom.storeArea.sanitizers); - assertNotEquals(inHouse1.kichen.storeArea.sanitizers,inHouse2.bedRoom.storeArea.sanitizers); + assertNotEquals( + inHouse1.kichen?.storeArea?.sanitizers, + inHouse2.bathRoom?.storeArea?.sanitizers, + ) + assertNotEquals( + inHouse1.kichen?.storeArea?.sanitizers, + inHouse2.bedRoom?.storeArea?.sanitizers, + ) } - } diff --git a/tests/src/test/java/com/github/klee0kai/stone/test/gc/EarthLastDayTests.kt b/tests/src/test/java/com/github/klee0kai/stone/test/gc/EarthLastDayTests.kt index 39a492ac..fb313122 100644 --- a/tests/src/test/java/com/github/klee0kai/stone/test/gc/EarthLastDayTests.kt +++ b/tests/src/test/java/com/github/klee0kai/stone/test/gc/EarthLastDayTests.kt @@ -1,287 +1,280 @@ -package com.github.klee0kai.stone.test.gc; +package com.github.klee0kai.stone.test.gc -import com.github.klee0kai.stone.Stone; -import com.github.klee0kai.test.di.gcforest.GcGodComponent; -import com.github.klee0kai.test.mowgli.earth.Mountain; -import com.github.klee0kai.test.mowgli.earth.River; -import org.junit.jupiter.api.Test; +import com.github.klee0kai.test.di.gcforest.GcGodComponentStoneComponent +import org.junit.jupiter.api.Test +import org.junit.jupiter.api.assertNotNull +import org.junit.jupiter.api.assertNull +import java.lang.ref.WeakReference -import java.lang.ref.Reference; -import java.lang.ref.WeakReference; -import java.util.Arrays; - -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertNull; - -public class EarthLastDayTests { +class EarthLastDayTests { @Test - void gcAllTest() { + fun gcAllTest() { //Given - GcGodComponent di = Stone.createComponent(GcGodComponent.class); - WeakReference mountainStrong = new WeakReference<>(di.earth().mountainStrong()); - WeakReference mountainSoft = new WeakReference<>(di.earth().mountainSoft()); - WeakReference mountainWeak = new WeakReference<>(di.earth().mountainWeak()); - WeakReference mountainDef = new WeakReference<>(di.earth().mountainDefaultFactory()); - WeakReference mountainDef2 = new WeakReference<>(di.earth().mountainDefault2Factory()); - WeakReference riverStrong = new WeakReference<>(di.earth().riverStrong()); - WeakReference riverSoft = new WeakReference<>(di.earth().riverSoft()); - WeakReference riverWeak = new WeakReference<>(di.earth().riverWeak()); - WeakReference riverDef = new WeakReference<>(di.earth().riverDefaultSoft()); + val di = GcGodComponentStoneComponent() + val mountainStrong = WeakReference(di.earth().mountainStrong()) + val mountainSoft = WeakReference(di.earth().mountainSoft()) + val mountainWeak = WeakReference(di.earth().mountainWeak()) + val mountainDef = WeakReference(di.earth().mountainDefaultFactory()) + val mountainDef2 = WeakReference(di.earth().mountainDefault2Factory()) + val riverStrong = WeakReference(di.earth().riverStrong()) + val riverSoft = WeakReference(di.earth().riverSoft()) + val riverWeak = WeakReference(di.earth().riverWeak()) + val riverDef = WeakReference(di.earth().riverDefaultSoft()) //When - di.gcAll(); + di.gcAll() //Then - for (Reference ref : Arrays.asList( - mountainStrong, mountainSoft, mountainDef2, mountainWeak, mountainDef, - riverStrong, riverSoft, riverWeak, riverDef + for (ref in listOf( + mountainStrong, mountainSoft, mountainDef2, mountainWeak, mountainDef, + riverStrong, riverSoft, riverWeak, riverDef )) { - assertNull(ref.get()); + assertNull(ref.get()) } } @Test - void gcStrongTest() { + fun gcStrongTest() { //Given - GcGodComponent di = Stone.createComponent(GcGodComponent.class); - WeakReference mountainStrong = new WeakReference<>(di.earth().mountainStrong()); - WeakReference mountainSoft = new WeakReference<>(di.earth().mountainSoft()); - WeakReference mountainWeak = new WeakReference<>(di.earth().mountainWeak()); - WeakReference mountainDef = new WeakReference<>(di.earth().mountainDefaultFactory()); - WeakReference mountainDef2 = new WeakReference<>(di.earth().mountainDefault2Factory()); - WeakReference riverStrong = new WeakReference<>(di.earth().riverStrong()); - WeakReference riverSoft = new WeakReference<>(di.earth().riverSoft()); - WeakReference riverWeak = new WeakReference<>(di.earth().riverWeak()); - WeakReference riverDef = new WeakReference<>(di.earth().riverDefaultSoft()); + val di = GcGodComponentStoneComponent() + val mountainStrong = WeakReference(di.earth().mountainStrong()) + val mountainSoft = WeakReference(di.earth().mountainSoft()) + val mountainWeak = WeakReference(di.earth().mountainWeak()) + val mountainDef = WeakReference(di.earth().mountainDefaultFactory()) + val mountainDef2 = WeakReference(di.earth().mountainDefault2Factory()) + val riverStrong = WeakReference(di.earth().riverStrong()) + val riverSoft = WeakReference(di.earth().riverSoft()) + val riverWeak = WeakReference(di.earth().riverWeak()) + val riverDef = WeakReference(di.earth().riverDefaultSoft()) //When - di.gcStrong(); + di.gcStrong() //Then - for (Reference ref : Arrays.asList( - mountainStrong, mountainWeak, mountainDef, mountainDef2, - riverStrong, riverWeak, riverDef + for (ref in listOf( + mountainStrong, mountainWeak, mountainDef, mountainDef2, + riverStrong, riverWeak, riverDef )) { - assertNull(ref.get()); + assertNull(ref.get()) } - for (Reference ref : Arrays.asList( - mountainSoft, - riverSoft + for (ref in listOf( + mountainSoft, + riverSoft )) { - assertNotNull(ref.get()); + assertNotNull(ref.get()) } } @Test - void gcSoftTest() { + fun gcSoftTest() { //Given - GcGodComponent di = Stone.createComponent(GcGodComponent.class); - WeakReference mountainStrong = new WeakReference<>(di.earth().mountainStrong()); - WeakReference mountainSoft = new WeakReference<>(di.earth().mountainSoft()); - WeakReference mountainWeak = new WeakReference<>(di.earth().mountainWeak()); - WeakReference mountainDef = new WeakReference<>(di.earth().mountainDefaultFactory()); - WeakReference mountainDef2 = new WeakReference<>(di.earth().mountainDefault2Factory()); - WeakReference riverStrong = new WeakReference<>(di.earth().riverStrong()); - WeakReference riverSoft = new WeakReference<>(di.earth().riverSoft()); - WeakReference riverWeak = new WeakReference<>(di.earth().riverWeak()); - WeakReference riverDef = new WeakReference<>(di.earth().riverDefaultSoft()); + val di = GcGodComponentStoneComponent() + val mountainStrong = WeakReference(di.earth().mountainStrong()) + val mountainSoft = WeakReference(di.earth().mountainSoft()) + val mountainWeak = WeakReference(di.earth().mountainWeak()) + val mountainDef = WeakReference(di.earth().mountainDefaultFactory()) + val mountainDef2 = WeakReference(di.earth().mountainDefault2Factory()) + val riverStrong = WeakReference(di.earth().riverStrong()) + val riverSoft = WeakReference(di.earth().riverSoft()) + val riverWeak = WeakReference(di.earth().riverWeak()) + val riverDef = WeakReference(di.earth().riverDefaultSoft()) //When - di.gcSoft(); + di.gcSoft() //Then - for (Reference ref : Arrays.asList( - mountainSoft, mountainWeak, mountainDef, mountainDef2, - riverSoft, riverWeak, riverDef + for (ref in listOf( + mountainSoft, mountainWeak, mountainDef, mountainDef2, + riverSoft, riverWeak, riverDef )) { - assertNull(ref.get()); + assertNull(ref.get()) } - for (Reference ref : Arrays.asList( - mountainStrong, - riverStrong + for (ref in listOf( + mountainStrong, + riverStrong )) { - assertNotNull(ref.get()); + assertNotNull(ref.get()) } } @Test - void gcWeakTest() { + fun gcWeakTest() { //Given - GcGodComponent di = Stone.createComponent(GcGodComponent.class); - WeakReference mountainStrong = new WeakReference<>(di.earth().mountainStrong()); - WeakReference mountainSoft = new WeakReference<>(di.earth().mountainSoft()); - WeakReference mountainWeak = new WeakReference<>(di.earth().mountainWeak()); - WeakReference mountainDef = new WeakReference<>(di.earth().mountainDefaultFactory()); - WeakReference riverStrong = new WeakReference<>(di.earth().riverStrong()); - WeakReference riverSoft = new WeakReference<>(di.earth().riverSoft()); - WeakReference riverWeak = new WeakReference<>(di.earth().riverWeak()); - WeakReference riverDef = new WeakReference<>(di.earth().riverDefaultSoft()); + val di = GcGodComponentStoneComponent() + val mountainStrong = WeakReference(di.earth().mountainStrong()) + val mountainSoft = WeakReference(di.earth().mountainSoft()) + val mountainWeak = WeakReference(di.earth().mountainWeak()) + val mountainDef = WeakReference(di.earth().mountainDefaultFactory()) + val riverStrong = WeakReference(di.earth().riverStrong()) + val riverSoft = WeakReference(di.earth().riverSoft()) + val riverWeak = WeakReference(di.earth().riverWeak()) + val riverDef = WeakReference(di.earth().riverDefaultSoft()) //When - di.gcWeak(); + di.gcWeak() //Then - for (Reference ref : Arrays.asList( - mountainWeak, mountainDef, - riverWeak, riverDef + for (ref in listOf( + mountainWeak, mountainDef, + riverWeak, riverDef )) { - assertNull(ref.get()); + assertNull(ref.get()) } - for (Reference ref : Arrays.asList( - mountainStrong, mountainSoft, - riverStrong, riverSoft + for (ref in listOf( + mountainStrong, mountainSoft, + riverStrong, riverSoft )) { - assertNotNull(ref.get()); + assertNotNull(ref.get()) } } @Test - void gcMountainTest() { + fun gcMountainTest() { //Given - GcGodComponent di = Stone.createComponent(GcGodComponent.class); - WeakReference mountainStrong = new WeakReference<>(di.earth().mountainStrong()); - WeakReference mountainSoft = new WeakReference<>(di.earth().mountainSoft()); - WeakReference mountainWeak = new WeakReference<>(di.earth().mountainWeak()); - WeakReference mountainDef = new WeakReference<>(di.earth().mountainDefaultFactory()); - WeakReference riverStrong = new WeakReference<>(di.earth().riverStrong()); - WeakReference riverSoft = new WeakReference<>(di.earth().riverSoft()); - WeakReference riverWeak = new WeakReference<>(di.earth().riverWeak()); - WeakReference riverDef = new WeakReference<>(di.earth().riverDefaultSoft()); + val di = GcGodComponentStoneComponent() + val mountainStrong = WeakReference(di.earth().mountainStrong()) + val mountainSoft = WeakReference(di.earth().mountainSoft()) + val mountainWeak = WeakReference(di.earth().mountainWeak()) + val mountainDef = WeakReference(di.earth().mountainDefaultFactory()) + val riverStrong = WeakReference(di.earth().riverStrong()) + val riverSoft = WeakReference(di.earth().riverSoft()) + val riverWeak = WeakReference(di.earth().riverWeak()) + val riverDef = WeakReference(di.earth().riverDefaultSoft()) //When - di.gcMountains(); + di.gcMountains() //Then - for (Reference ref : Arrays.asList( - mountainStrong, mountainSoft, mountainWeak, mountainDef, - riverWeak, riverDef + for (ref in listOf( + mountainStrong, mountainSoft, mountainWeak, mountainDef, + riverWeak, riverDef )) { - assertNull(ref.get()); + assertNull(ref.get()) } - for (Reference ref : Arrays.asList( - riverStrong, riverSoft + for (ref in listOf( + riverStrong, riverSoft )) { - assertNotNull(ref.get()); + assertNotNull(ref.get()) } } @Test - void gcRiverTest() { + fun gcRiverTest() { //Given - GcGodComponent di = Stone.createComponent(GcGodComponent.class); - WeakReference mountainStrong = new WeakReference<>(di.earth().mountainStrong()); - WeakReference mountainSoft = new WeakReference<>(di.earth().mountainSoft()); - WeakReference mountainWeak = new WeakReference<>(di.earth().mountainWeak()); - WeakReference mountainDef = new WeakReference<>(di.earth().mountainDefaultFactory()); - WeakReference riverStrong = new WeakReference<>(di.earth().riverStrong()); - WeakReference riverSoft = new WeakReference<>(di.earth().riverSoft()); - WeakReference riverWeak = new WeakReference<>(di.earth().riverWeak()); - WeakReference riverDef = new WeakReference<>(di.earth().riverDefaultSoft()); + val di = GcGodComponentStoneComponent() + val mountainStrong = WeakReference(di.earth().mountainStrong()) + val mountainSoft = WeakReference(di.earth().mountainSoft()) + val mountainWeak = WeakReference(di.earth().mountainWeak()) + val mountainDef = WeakReference(di.earth().mountainDefaultFactory()) + val riverStrong = WeakReference(di.earth().riverStrong()) + val riverSoft = WeakReference(di.earth().riverSoft()) + val riverWeak = WeakReference(di.earth().riverWeak()) + val riverDef = WeakReference(di.earth().riverDefaultSoft()) //When - di.gcRivers(); + di.gcRivers() //Then - for (Reference ref : Arrays.asList( - mountainWeak, mountainDef, - riverStrong, riverSoft, riverWeak, riverDef + for (ref in listOf( + mountainWeak, mountainDef, + riverStrong, riverSoft, riverWeak, riverDef )) { - assertNull(ref.get()); + assertNull(ref.get()) } - for (Reference ref : Arrays.asList( - mountainStrong, mountainSoft + for (ref in listOf( + mountainStrong, mountainSoft )) { - assertNotNull(ref.get()); + assertNotNull(ref.get()) } } @Test - void gcMountainAndRiverTest() { + fun gcMountainAndRiverTest() { //Given - GcGodComponent di = Stone.createComponent(GcGodComponent.class); - WeakReference mountainStrong = new WeakReference<>(di.earth().mountainStrong()); - WeakReference mountainSoft = new WeakReference<>(di.earth().mountainSoft()); - WeakReference mountainWeak = new WeakReference<>(di.earth().mountainWeak()); - WeakReference mountainDef = new WeakReference<>(di.earth().mountainDefaultFactory()); - WeakReference riverStrong = new WeakReference<>(di.earth().riverStrong()); - WeakReference riverSoft = new WeakReference<>(di.earth().riverSoft()); - WeakReference riverWeak = new WeakReference<>(di.earth().riverWeak()); - WeakReference riverDef = new WeakReference<>(di.earth().riverDefaultSoft()); + val di = GcGodComponentStoneComponent() + val mountainStrong = WeakReference(di.earth().mountainStrong()) + val mountainSoft = WeakReference(di.earth().mountainSoft()) + val mountainWeak = WeakReference(di.earth().mountainWeak()) + val mountainDef = WeakReference(di.earth().mountainDefaultFactory()) + val riverStrong = WeakReference(di.earth().riverStrong()) + val riverSoft = WeakReference(di.earth().riverSoft()) + val riverWeak = WeakReference(di.earth().riverWeak()) + val riverDef = WeakReference(di.earth().riverDefaultSoft()) //When - di.gcMountainsAndRivers(); + di.gcMountainsAndRivers() //Then - for (Reference ref : Arrays.asList( - mountainStrong, mountainSoft, mountainWeak, mountainDef, - riverStrong, riverSoft, riverWeak, riverDef + for (ref in listOf( + mountainStrong, mountainSoft, mountainWeak, mountainDef, + riverStrong, riverSoft, riverWeak, riverDef )) { - assertNull(ref.get()); + assertNull(ref.get()) } } @Test - void gcSoftMountainTest() { + fun gcSoftMountainTest() { //Given - GcGodComponent di = Stone.createComponent(GcGodComponent.class); - WeakReference mountainStrong = new WeakReference<>(di.earth().mountainStrong()); - WeakReference mountainSoft = new WeakReference<>(di.earth().mountainSoft()); - WeakReference mountainWeak = new WeakReference<>(di.earth().mountainWeak()); - WeakReference mountainDef = new WeakReference<>(di.earth().mountainDefaultFactory()); - WeakReference riverStrong = new WeakReference<>(di.earth().riverStrong()); - WeakReference riverSoft = new WeakReference<>(di.earth().riverSoft()); - WeakReference riverWeak = new WeakReference<>(di.earth().riverWeak()); - WeakReference riverDef = new WeakReference<>(di.earth().riverDefaultSoft()); + val di = GcGodComponentStoneComponent() + val mountainStrong = WeakReference(di.earth().mountainStrong()) + val mountainSoft = WeakReference(di.earth().mountainSoft()) + val mountainWeak = WeakReference(di.earth().mountainWeak()) + val mountainDef = WeakReference(di.earth().mountainDefaultFactory()) + val riverStrong = WeakReference(di.earth().riverStrong()) + val riverSoft = WeakReference(di.earth().riverSoft()) + val riverWeak = WeakReference(di.earth().riverWeak()) + val riverDef = WeakReference(di.earth().riverDefaultSoft()) //When - di.gcSoftMountains(); + di.gcSoftMountains() //Then - for (Reference ref : Arrays.asList( - mountainSoft, mountainWeak, mountainDef, - riverWeak, riverDef + for (ref in listOf( + mountainSoft, mountainWeak, mountainDef, + riverWeak, riverDef )) { - assertNull(ref.get()); + assertNull(ref.get()) } - for (Reference ref : Arrays.asList( - mountainStrong, - riverStrong, riverSoft + for (ref in listOf( + mountainStrong, + riverStrong, riverSoft )) { - assertNotNull(ref.get()); + assertNotNull(ref.get()) } } @Test - void gcStrongMountainTest() { + fun gcStrongMountainTest() { //Given - GcGodComponent di = Stone.createComponent(GcGodComponent.class); - WeakReference mountainStrong = new WeakReference<>(di.earth().mountainStrong()); - WeakReference mountainSoft = new WeakReference<>(di.earth().mountainSoft()); - WeakReference mountainWeak = new WeakReference<>(di.earth().mountainWeak()); - WeakReference mountainDef = new WeakReference<>(di.earth().mountainDefaultFactory()); - WeakReference riverStrong = new WeakReference<>(di.earth().riverStrong()); - WeakReference riverSoft = new WeakReference<>(di.earth().riverSoft()); - WeakReference riverWeak = new WeakReference<>(di.earth().riverWeak()); - WeakReference riverDef = new WeakReference<>(di.earth().riverDefaultSoft()); + val di = GcGodComponentStoneComponent() + val mountainStrong = WeakReference(di.earth().mountainStrong()) + val mountainSoft = WeakReference(di.earth().mountainSoft()) + val mountainWeak = WeakReference(di.earth().mountainWeak()) + val mountainDef = WeakReference(di.earth().mountainDefaultFactory()) + val riverStrong = WeakReference(di.earth().riverStrong()) + val riverSoft = WeakReference(di.earth().riverSoft()) + val riverWeak = WeakReference(di.earth().riverWeak()) + val riverDef = WeakReference(di.earth().riverDefaultSoft()) //When - di.gcStrongMountains(); + di.gcStrongMountains() //Then - for (Reference ref : Arrays.asList( - mountainStrong, mountainWeak, mountainDef, - riverWeak, riverDef + for (ref in listOf( + mountainStrong, mountainWeak, mountainDef, + riverWeak, riverDef )) { - assertNull(ref.get()); + assertNull(ref.get()) } - for (Reference ref : Arrays.asList( - mountainSoft, - riverStrong, riverSoft + for (ref in listOf( + mountainSoft, + riverStrong, riverSoft )) { - assertNotNull(ref.get()); + assertNotNull(ref.get()) } } diff --git a/tests/src/test/java/com/github/klee0kai/stone/test/gc/GodLastWorkDayTests.kt b/tests/src/test/java/com/github/klee0kai/stone/test/gc/GodLastWorkDayTests.kt index 8d92eee5..74c26a84 100644 --- a/tests/src/test/java/com/github/klee0kai/stone/test/gc/GodLastWorkDayTests.kt +++ b/tests/src/test/java/com/github/klee0kai/stone/test/gc/GodLastWorkDayTests.kt @@ -1,162 +1,158 @@ -package com.github.klee0kai.stone.test.gc; +package com.github.klee0kai.stone.test.gc -import com.github.klee0kai.stone.Stone; -import com.github.klee0kai.test.di.gcforest.GcGodComponent; -import com.github.klee0kai.test.mowgli.galaxy.Earth; -import com.github.klee0kai.test.mowgli.galaxy.Saturn; -import com.github.klee0kai.test.mowgli.galaxy.Sun; -import org.junit.jupiter.api.Test; - -import java.lang.ref.WeakReference; - -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertNull; - - -public class GodLastWorkDayTests { +import com.github.klee0kai.test.di.gcforest.GcGodComponentStoneComponent +import com.github.klee0kai.test.mowgli.galaxy.Earth +import com.github.klee0kai.test.mowgli.galaxy.Saturn +import com.github.klee0kai.test.mowgli.galaxy.Sun +import org.junit.jupiter.api.Test +import org.junit.jupiter.api.assertNotNull +import org.junit.jupiter.api.assertNull +import java.lang.ref.WeakReference +class GodLastWorkDayTests { @Test - void gcAllTest() { + fun gcAllTest() { //Given - GcGodComponent di = Stone.createComponent(GcGodComponent.class); - WeakReference sunRef = new WeakReference<>(new Sun()); - WeakReference earthRef = new WeakReference<>(new Earth()); - WeakReference saturnRef = new WeakReference<>(new Saturn()); - di.bind(sunRef.get()); - di.bind(earthRef.get()); - di.bind(saturnRef.get()); + val di = GcGodComponentStoneComponent() + val sunRef = WeakReference(Sun()) + val earthRef = WeakReference(Earth()) + val saturnRef = WeakReference(Saturn()) + di.bind(sunRef.get()) + di.bind(earthRef.get()) + di.bind(saturnRef.get()) //When - di.gcAll(); + di.gcAll() //Then - assertNull(sunRef.get()); - assertNull(earthRef.get()); - assertNull(saturnRef.get()); + assertNull(sunRef.get()) + assertNull(earthRef.get()) + assertNull(saturnRef.get()) } @Test - void gcWeakTest() { + fun gcWeakTest() { //Given - GcGodComponent di = Stone.createComponent(GcGodComponent.class); - WeakReference sunRef = new WeakReference<>(new Sun()); - WeakReference earthRef = new WeakReference<>(new Earth()); - WeakReference saturnRef = new WeakReference<>(new Saturn()); - di.bind(sunRef.get()); - di.bind(earthRef.get()); - di.bind(saturnRef.get()); + val di = GcGodComponentStoneComponent() + val sunRef = WeakReference(Sun()) + val earthRef = WeakReference(Earth()) + val saturnRef = WeakReference(Saturn()) + di.bind(sunRef.get()) + di.bind(earthRef.get()) + di.bind(saturnRef.get()) //When - di.gcWeak(); + di.gcWeak() //Then - assertNotNull(sunRef.get()); - assertNotNull(earthRef.get()); - assertNull(saturnRef.get()); + assertNotNull(sunRef.get()) + assertNotNull(earthRef.get()) + assertNull(saturnRef.get()) } @Test - void gcSoftTest() { + fun gcSoftTest() { //Given - GcGodComponent di = Stone.createComponent(GcGodComponent.class); - WeakReference sunRef = new WeakReference<>(new Sun()); - WeakReference earthRef = new WeakReference<>(new Earth()); - WeakReference saturnRef = new WeakReference<>(new Saturn()); - di.bind(sunRef.get()); - di.bind(earthRef.get()); - di.bind(saturnRef.get()); + val di = GcGodComponentStoneComponent() + val sunRef = WeakReference(Sun()) + val earthRef = WeakReference(Earth()) + val saturnRef = WeakReference(Saturn()) + di.bind(sunRef.get()) + di.bind(earthRef.get()) + di.bind(saturnRef.get()) //When - di.gcSoft(); + di.gcSoft() //Then - assertNotNull(sunRef.get()); - assertNull(earthRef.get()); - assertNull(saturnRef.get()); + assertNotNull(sunRef.get()) + assertNull(earthRef.get()) + assertNull(saturnRef.get()) } @Test - void gcStrongTest() { + fun gcStrongTest() { //Given - GcGodComponent di = Stone.createComponent(GcGodComponent.class); - WeakReference sunRef = new WeakReference<>(new Sun()); - WeakReference earthRef = new WeakReference<>(new Earth()); - WeakReference saturnRef = new WeakReference<>(new Saturn()); - di.bind(sunRef.get()); - di.bind(earthRef.get()); - di.bind(saturnRef.get()); + val di = GcGodComponentStoneComponent() + val sunRef = WeakReference(Sun()) + val earthRef = WeakReference(Earth()) + val saturnRef = WeakReference(Saturn()) + di.bind(sunRef.get()) + di.bind(earthRef.get()) + di.bind(saturnRef.get()) //When - di.gcStrong(); + di.gcStrong() //Then - assertNull(sunRef.get()); - assertNotNull(earthRef.get()); - assertNull(saturnRef.get()); + assertNull(sunRef.get()) + assertNotNull(earthRef.get()) + assertNull(saturnRef.get()) } @Test - void gcSunTest() { + fun gcSunTest() { //Given - GcGodComponent di = Stone.createComponent(GcGodComponent.class); - WeakReference sunRef = new WeakReference<>(new Sun()); - WeakReference earthRef = new WeakReference<>(new Earth()); - WeakReference saturnRef = new WeakReference<>(new Saturn()); - di.bind(sunRef.get()); - di.bind(earthRef.get()); - di.bind(saturnRef.get()); + val di = GcGodComponentStoneComponent() + val sunRef = WeakReference(Sun()) + val earthRef = WeakReference(Earth()) + val saturnRef = WeakReference(Saturn()) + di.bind(sunRef.get()) + di.bind(earthRef.get()) + di.bind(saturnRef.get()) //When - di.gcSun(); + di.gcSun() //Then - assertNull(sunRef.get()); - assertNotNull(earthRef.get()); - assertNull(saturnRef.get()); + assertNull(sunRef.get()) + assertNotNull(earthRef.get()) + assertNull(saturnRef.get()) } @Test - void gcPlanetsTest() { + fun gcPlanetsTest() { //Given - GcGodComponent di = Stone.createComponent(GcGodComponent.class); - WeakReference sunRef = new WeakReference<>(new Sun()); - WeakReference earthRef = new WeakReference<>(new Earth()); - WeakReference saturnRef = new WeakReference<>(new Saturn()); - di.bind(sunRef.get()); - di.bind(earthRef.get()); - di.bind(saturnRef.get()); + val di = GcGodComponentStoneComponent() + val sunRef = WeakReference(Sun()) + val earthRef = WeakReference(Earth()) + val saturnRef = WeakReference(Saturn()) + di.bind(sunRef.get()) + di.bind(earthRef.get()) + di.bind(saturnRef.get()) //When - di.gcPlanets(); + di.gcPlanets() //Then - assertNotNull(sunRef.get()); - assertNull(earthRef.get()); - assertNull(saturnRef.get()); + assertNotNull(sunRef.get()) + assertNull(earthRef.get()) + assertNull(saturnRef.get()) } @Test - void gcSunAndPlanetsTest() { + fun gcSunAndPlanetsTest() { //Given - GcGodComponent di = Stone.createComponent(GcGodComponent.class); - WeakReference sunRef = new WeakReference<>(new Sun()); - WeakReference earthRef = new WeakReference<>(new Earth()); - WeakReference saturnRef = new WeakReference<>(new Saturn()); - di.bind(sunRef.get()); - di.bind(earthRef.get()); - di.bind(saturnRef.get()); + val di = GcGodComponentStoneComponent() + val sunRef = WeakReference(Sun()) + val earthRef = WeakReference(Earth()) + val saturnRef = WeakReference(Saturn()) + di.bind(sunRef.get()) + di.bind(earthRef.get()) + di.bind(saturnRef.get()) //When - di.gcSunAndPlanets(); + di.gcSunAndPlanets() //Then - assertNull(sunRef.get()); - assertNull(earthRef.get()); - assertNull(saturnRef.get()); + assertNull(sunRef.get()) + assertNull(earthRef.get()) + assertNull(saturnRef.get()) } + } diff --git a/tests/src/test/java/com/github/klee0kai/stone/test/identifiers/GoodPhoneInjectTests.kt b/tests/src/test/java/com/github/klee0kai/stone/test/identifiers/GoodPhoneInjectTests.kt index 369f25eb..8d836020 100644 --- a/tests/src/test/java/com/github/klee0kai/stone/test/identifiers/GoodPhoneInjectTests.kt +++ b/tests/src/test/java/com/github/klee0kai/stone/test/identifiers/GoodPhoneInjectTests.kt @@ -1,44 +1,41 @@ -package com.github.klee0kai.stone.test.identifiers; +package com.github.klee0kai.stone.test.identifiers -import com.github.klee0kai.stone.Stone; -import com.github.klee0kai.test.di.base_phone.PhoneComponent; -import com.github.klee0kai.test.di.base_phone.identifiers.DataStorageSize; -import com.github.klee0kai.test.di.base_phone.identifiers.RamSize; -import com.github.klee0kai.test.tech.phone.GoodPhone; -import org.junit.jupiter.api.Test; - -import static org.junit.jupiter.api.Assertions.assertEquals; - -public class GoodPhoneInjectTests { +import com.github.klee0kai.test.di.base_phone.PhoneComponentStoneComponent +import com.github.klee0kai.test.di.base_phone.identifiers.DataStorageSize +import com.github.klee0kai.test.di.base_phone.identifiers.RamSize +import com.github.klee0kai.test.tech.phone.GoodPhone +import org.junit.jupiter.api.Assertions.assertEquals +import org.junit.jupiter.api.Test +class GoodPhoneInjectTests { @Test - public void createGoodPhoneTest() { + fun createGoodPhoneTest() { //Given - PhoneComponent DI = Stone.createComponent(PhoneComponent.class); - GoodPhone goodPhone = new GoodPhone(); + val DI = PhoneComponentStoneComponent() + val goodPhone = GoodPhone() //When - DI.inject(goodPhone, goodPhone.lifeCycleOwner, new DataStorageSize("120GB"), new RamSize("8GB")); + DI.inject(goodPhone, goodPhone.lifeCycleOwner, DataStorageSize("120GB"), RamSize("8GB")) //Then - assertEquals("120GB", goodPhone.dataStorage.size); - assertEquals("8GB", goodPhone.ram.size); + assertEquals("120GB", goodPhone.dataStorage!!.size) + assertEquals("8GB", goodPhone.ram!!.size) } @Test - public void cacheInjectedPhoneTest() { + fun cacheInjectedPhoneTest() { //Given - PhoneComponent DI = Stone.createComponent(PhoneComponent.class); - GoodPhone goodPhone1 = new GoodPhone(); - GoodPhone goodPhone2 = new GoodPhone(); + val DI = PhoneComponentStoneComponent() + val goodPhone1 = GoodPhone() + val goodPhone2 = GoodPhone() //When - DI.inject(goodPhone1, goodPhone1.lifeCycleOwner, new DataStorageSize("120GB"), new RamSize("8GB")); - DI.inject(goodPhone2, goodPhone2.lifeCycleOwner, new DataStorageSize("120GB"), new RamSize("8GB")); + DI.inject(goodPhone1, goodPhone1.lifeCycleOwner, DataStorageSize("120GB"), RamSize("8GB")) + DI.inject(goodPhone2, goodPhone2.lifeCycleOwner, DataStorageSize("120GB"), RamSize("8GB")) //Then - assertEquals(goodPhone1.ram.uuid, goodPhone2.ram.uuid); + assertEquals(goodPhone1.ram!!.uuid, goodPhone2.ram!!.uuid) } } diff --git a/tests/src/test/java/com/github/klee0kai/stone/test/identifiers/MultiIdentifiersTests.kt b/tests/src/test/java/com/github/klee0kai/stone/test/identifiers/MultiIdentifiersTests.kt index 29d825c3..f6b5d5c2 100644 --- a/tests/src/test/java/com/github/klee0kai/stone/test/identifiers/MultiIdentifiersTests.kt +++ b/tests/src/test/java/com/github/klee0kai/stone/test/identifiers/MultiIdentifiersTests.kt @@ -1,66 +1,65 @@ -package com.github.klee0kai.stone.test.identifiers; +package com.github.klee0kai.stone.test.identifiers -import com.github.klee0kai.stone.Stone; -import com.github.klee0kai.test.di.base_phone.PhoneComponent; -import com.github.klee0kai.test.di.base_phone.identifiers.PhoneOsType; -import com.github.klee0kai.test.di.base_phone.identifiers.PhoneOsVersion; -import com.github.klee0kai.test.tech.components.OperationSystem; -import org.junit.jupiter.api.Test; +import com.github.klee0kai.test.di.base_phone.PhoneComponentStoneComponent +import com.github.klee0kai.test.di.base_phone.identifiers.PhoneOsType +import com.github.klee0kai.test.di.base_phone.identifiers.PhoneOsVersion +import org.junit.jupiter.api.Assertions.assertEquals +import org.junit.jupiter.api.Assertions.assertNotEquals +import org.junit.jupiter.api.Test -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotEquals; +class MultiIdentifiersTests { -public class MultiIdentifiersTests { @Test - public void differentCreatePhoneTest() { + fun differentCreatePhoneTest() { //Given - PhoneComponent DI = Stone.createComponent(PhoneComponent.class); + val DI = PhoneComponentStoneComponent() //When - OperationSystem androidDemo = DI.components().phoneOs(PhoneOsType.Android, null); - OperationSystem android11 = DI.components().phoneOs(PhoneOsType.Android, new PhoneOsVersion("11")); + val androidDemo = DI.components().phoneOs(PhoneOsType.Android, null) + val android11 = DI.components().phoneOs(PhoneOsType.Android, PhoneOsVersion("11")) //Then - assertNotEquals(androidDemo.uuid, android11.uuid); + assertNotEquals(androidDemo?.uuid, android11?.uuid) } @Test - public void differentMethodDifferentCacheTest() { + fun differentMethodDifferentCacheTest() { //Given - PhoneComponent DI = Stone.createComponent(PhoneComponent.class); + val DI = PhoneComponentStoneComponent() //When - OperationSystem android11 = DI.components().phoneOs(PhoneOsType.Android, new PhoneOsVersion("11")); - OperationSystem androidSimple = DI.components().phoneOs(PhoneOsType.Android); + val android11 = DI.components().phoneOs(PhoneOsType.Android, PhoneOsVersion("11")) + val androidSimple = DI.components().phoneOs(PhoneOsType.Android) //Then - assertNotEquals(androidSimple.uuid, android11.uuid); + assertNotEquals(androidSimple?.uuid, android11?.uuid) } @Test - public void cacheByIdentifiersTest() { + fun cacheByIdentifiersTest() { //Given - PhoneComponent DI = Stone.createComponent(PhoneComponent.class); + val DI = PhoneComponentStoneComponent() //When - OperationSystem android11 = DI.components().phoneOs(PhoneOsType.Android, new PhoneOsVersion("11")); - OperationSystem android11_2 = DI.components().phoneOs(PhoneOsType.Android, new PhoneOsVersion("11")); + val android11 = DI.components().phoneOs(PhoneOsType.Android, PhoneOsVersion("11")) + val android11_2 = DI.components().phoneOs(PhoneOsType.Android, PhoneOsVersion("11")) //Then - assertEquals(android11.uuid, android11_2.uuid); + assertEquals(android11?.uuid, android11_2?.uuid) } @Test - public void sepCacheByIdentifiersTest() { + fun sepCacheByIdentifiersTest() { //Given - PhoneComponent DI = Stone.createComponent(PhoneComponent.class); + val DI = PhoneComponentStoneComponent() //When - OperationSystem android11 = DI.components().phoneOs(PhoneOsType.Android, new PhoneOsVersion("11")); - OperationSystem android12 = DI.components().phoneOs(PhoneOsType.Android, new PhoneOsVersion("12")); + val android11 = DI.components().phoneOs(PhoneOsType.Android, PhoneOsVersion("11")) + val android12 = DI.components().phoneOs(PhoneOsType.Android, PhoneOsVersion("12")) //Then - assertNotEquals(android11.uuid, android12.uuid); + assertNotEquals(android11?.uuid, android12?.uuid) } + } diff --git a/tests/src/test/java/com/github/klee0kai/stone/test/identifiers/TechComponentsTests.kt b/tests/src/test/java/com/github/klee0kai/stone/test/identifiers/TechComponentsTests.kt index 5f57ca62..f8f7a487 100644 --- a/tests/src/test/java/com/github/klee0kai/stone/test/identifiers/TechComponentsTests.kt +++ b/tests/src/test/java/com/github/klee0kai/stone/test/identifiers/TechComponentsTests.kt @@ -1,71 +1,66 @@ -package com.github.klee0kai.stone.test.identifiers; +package com.github.klee0kai.stone.test.identifiers -import com.github.klee0kai.stone.Stone; -import com.github.klee0kai.test.di.base_phone.PhoneComponent; -import com.github.klee0kai.test.di.base_phone.identifiers.PhoneOsType; -import com.github.klee0kai.test.di.base_phone.identifiers.RamSize; -import com.github.klee0kai.test.tech.components.OperationSystem; -import com.github.klee0kai.test.tech.components.Ram; -import org.junit.jupiter.api.Test; +import com.github.klee0kai.test.di.base_phone.PhoneComponentStoneComponent +import com.github.klee0kai.test.di.base_phone.identifiers.PhoneOsType +import com.github.klee0kai.test.di.base_phone.identifiers.RamSize +import org.junit.jupiter.api.Assertions.assertEquals +import org.junit.jupiter.api.Assertions.assertNotEquals +import org.junit.jupiter.api.Test -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotEquals; - -public class TechComponentsTests { +class TechComponentsTests { @Test - public void differentCreateTest() { + fun differentCreateTest() { //Given - PhoneComponent DI = Stone.createComponent(PhoneComponent.class); + val DI = PhoneComponentStoneComponent() //When - Ram ram8Gb = DI.components().ram(new RamSize("8GB")); - Ram ram9Gb = DI.components().ram(new RamSize("9GB")); + val ram8Gb = DI.components().ram(RamSize("8GB")) + val ram9Gb = DI.components().ram(RamSize("9GB")) //Then: created components are different - assertNotEquals(ram8Gb.uuid, ram9Gb.uuid); + assertNotEquals(ram8Gb?.uuid, ram9Gb?.uuid) } @Test - public void singleCacheTest() { + fun singleCacheTest() { //Given - PhoneComponent DI = Stone.createComponent(PhoneComponent.class); + val DI = PhoneComponentStoneComponent() //When - Ram ram1 = DI.components().ram(new RamSize("8GB")); - Ram ram2 = DI.components().ram(new RamSize("8GB")); + val ram1 = DI.components().ram(RamSize("8GB")) + val ram2 = DI.components().ram(RamSize("8GB")) //Then: cached ram - assertEquals(ram1.uuid, ram2.uuid); + assertEquals(ram1?.uuid, ram2?.uuid) } @Test - public void enumDifferentTest() { + fun enumDifferentTest() { //Given - PhoneComponent DI = Stone.createComponent(PhoneComponent.class); + val DI = PhoneComponentStoneComponent() //When - OperationSystem android = DI.components().phoneOs(PhoneOsType.Android); - OperationSystem osNull = DI.components().phoneOs(null); - OperationSystem ios = DI.components().phoneOs(PhoneOsType.Ios); + val android = DI.components().phoneOs(PhoneOsType.Android) + val osNull = DI.components().phoneOs(null) + val ios = DI.components().phoneOs(PhoneOsType.Ios) //Then: created components are different - assertNotEquals(android.uuid, osNull.uuid); - assertNotEquals(android.uuid, ios.uuid); + assertNotEquals(android?.uuid, osNull?.uuid) + assertNotEquals(android?.uuid, ios?.uuid) } @Test - public void enumCachedTest() { + fun enumCachedTest() { //Given - PhoneComponent DI = Stone.createComponent(PhoneComponent.class); + val DI = PhoneComponentStoneComponent() //When - OperationSystem android = DI.components().phoneOs(PhoneOsType.Android); - OperationSystem android2 = DI.components().phoneOs(PhoneOsType.Android); + val android = DI.components().phoneOs(PhoneOsType.Android) + val android2 = DI.components().phoneOs(PhoneOsType.Android) //Then: created components are different - assertEquals(android.uuid, android2.uuid); + assertEquals(android?.uuid, android2?.uuid) } - } diff --git a/tests/src/test/java/com/github/klee0kai/stone/test/identifiers/TechFactoryComponentTests.kt b/tests/src/test/java/com/github/klee0kai/stone/test/identifiers/TechFactoryComponentTests.kt index 4122779a..fe89b81f 100644 --- a/tests/src/test/java/com/github/klee0kai/stone/test/identifiers/TechFactoryComponentTests.kt +++ b/tests/src/test/java/com/github/klee0kai/stone/test/identifiers/TechFactoryComponentTests.kt @@ -1,99 +1,100 @@ -package com.github.klee0kai.stone.test.identifiers; +package com.github.klee0kai.stone.test.identifiers -import com.github.klee0kai.stone.Stone; -import com.github.klee0kai.test.di.base_phone.identifiers.PhoneOsType; -import com.github.klee0kai.test.di.base_phone.identifiers.PhoneOsVersion; -import com.github.klee0kai.test.di.base_phone.identifiers.RamSize; -import com.github.klee0kai.test.di.techfactory.TechFactoryComponent; -import com.github.klee0kai.test.tech.components.OperationSystem; -import com.github.klee0kai.test.tech.components.Ram; -import org.junit.jupiter.api.Test; +import com.github.klee0kai.test.di.base_phone.identifiers.PhoneOsType +import com.github.klee0kai.test.di.base_phone.identifiers.PhoneOsVersion +import com.github.klee0kai.test.di.base_phone.identifiers.RamSize +import com.github.klee0kai.test.di.techfactory.TechFactoryComponentStoneComponent +import org.junit.jupiter.api.Assertions.assertEquals +import org.junit.jupiter.api.Assertions.assertNotEquals +import org.junit.jupiter.api.Test +import org.junit.jupiter.api.assertNull -import static org.junit.jupiter.api.Assertions.*; - -public class TechFactoryComponentTests { +class TechFactoryComponentTests { @Test - public void nonArgProvideTest() { + fun nonArgProvideTest() { //Given - TechFactoryComponent DI = Stone.createComponent(TechFactoryComponent.class); + val DI = TechFactoryComponentStoneComponent() //When - Ram ram = DI.ram(); + val ram = DI.ram() //Then - assertEquals("default", ram.size); + assertEquals("default", ram?.size) } @Test - public void singleArgProvideTest() { + fun singleArgProvideTest() { //Given - TechFactoryComponent DI = Stone.createComponent(TechFactoryComponent.class); + val DI = TechFactoryComponentStoneComponent() + //When - Ram ram = DI.ram(new RamSize("4G")); + val ram = DI.ram(RamSize("4G")) //Then - assertEquals("4G", ram.size); + assertEquals("4G", ram?.size) } @Test - public void nullGenerateArgProvideTest() { + fun nullGenerateArgProvideTest() { //Given - TechFactoryComponent DI = Stone.createComponent(TechFactoryComponent.class); + val DI = TechFactoryComponentStoneComponent() + //When - OperationSystem os = DI.phoneOs(); + val os = DI.phoneOs() //Then: should pass null missing args - assertNull(os.phoneOsType); // missing args - assertEquals("default", os.version.version); // default from constructor + assertNull(os?.phoneOsType) // missing args + assertEquals("default", os?.version?.version) // default from constructor } @Test - public void coupleArgsProvideTest() { + fun coupleArgsProvideTest() { //Given - TechFactoryComponent DI = Stone.createComponent(TechFactoryComponent.class); + val DI = TechFactoryComponentStoneComponent() + //When - OperationSystem os = DI.phoneOs(PhoneOsType.Ios, new PhoneOsVersion("11")); + val os = DI.phoneOs(PhoneOsType.Ios, PhoneOsVersion("11")) //Then - assertEquals(PhoneOsType.Ios, os.phoneOsType); - assertEquals("11", os.version.version); + assertEquals(PhoneOsType.Ios, os?.phoneOsType) + assertEquals("11", os?.version?.version) } @Test - public void differentCreateTest() { + fun differentCreateTest() { //Given - TechFactoryComponent DI = Stone.createComponent(TechFactoryComponent.class); + val DI = TechFactoryComponentStoneComponent() + //When - Ram ram8Gb = DI.ram(new RamSize("8GB")); - Ram ram8Gb2 = DI.ram(new RamSize("8GB")); + val ram8Gb = DI.ram(RamSize("8GB")) + val ram8Gb2 = DI.ram(RamSize("8GB")) //Then: created components are different - assertEquals("8GB", ram8Gb.size); - assertNotEquals(ram8Gb.uuid, ram8Gb2.uuid); + assertEquals("8GB", ram8Gb?.size) + assertNotEquals(ram8Gb?.uuid, ram8Gb2?.uuid) } @Test - public void enumDifferentTest() { + fun enumDifferentTest() { //Given - TechFactoryComponent DI = Stone.createComponent(TechFactoryComponent.class); + val DI = TechFactoryComponentStoneComponent() //When - OperationSystem android = DI.phoneOs(PhoneOsType.Android); - OperationSystem android2 = DI.phoneOs(PhoneOsType.Android); - OperationSystem osNull = DI.phoneOs(null); + val android = DI.phoneOs(PhoneOsType.Android) + val android2 = DI.phoneOs(PhoneOsType.Android) + val osNull = DI.phoneOs(null) //Then: created components are different - assertNotEquals(android.uuid, osNull.uuid); - assertNotEquals(android.uuid, android2.uuid); + assertNotEquals(android?.uuid, osNull?.uuid) + assertNotEquals(android?.uuid, android2?.uuid) } - } diff --git a/tests/src/test/java/com/github/klee0kai/stone/test/identifiers/TechFactoryTests.kt b/tests/src/test/java/com/github/klee0kai/stone/test/identifiers/TechFactoryTests.kt index 96e837eb..f0085b19 100644 --- a/tests/src/test/java/com/github/klee0kai/stone/test/identifiers/TechFactoryTests.kt +++ b/tests/src/test/java/com/github/klee0kai/stone/test/identifiers/TechFactoryTests.kt @@ -1,45 +1,39 @@ -package com.github.klee0kai.stone.test.identifiers; +package com.github.klee0kai.stone.test.identifiers -import com.github.klee0kai.stone.Stone; -import com.github.klee0kai.test.di.base_phone.identifiers.PhoneOsType; -import com.github.klee0kai.test.di.base_phone.identifiers.RamSize; -import com.github.klee0kai.test.di.techfactory.TechFactoryComponent; -import com.github.klee0kai.test.tech.components.OperationSystem; -import com.github.klee0kai.test.tech.components.Ram; -import org.junit.jupiter.api.Test; +import com.github.klee0kai.test.di.base_phone.identifiers.PhoneOsType +import com.github.klee0kai.test.di.base_phone.identifiers.RamSize +import com.github.klee0kai.test.di.techfactory.TechFactoryComponentStoneComponent +import org.junit.jupiter.api.Assertions.assertNotEquals +import org.junit.jupiter.api.Test -import static org.junit.jupiter.api.Assertions.assertNotEquals; - -public class TechFactoryTests { +class TechFactoryTests { @Test - public void differentCreateTest() { + fun differentCreateTest() { //Given - TechFactoryComponent DI = Stone.createComponent(TechFactoryComponent.class); + val DI = TechFactoryComponentStoneComponent() //When - Ram ram8Gb = DI.factory().ram(new RamSize("8GB")); - Ram ram8Gb2 = DI.factory().ram(new RamSize("8GB")); + val ram8Gb = DI.factory().ram(RamSize("8GB")) + val ram8Gb2 = DI.factory().ram(RamSize("8GB")) //Then: created components are different - assertNotEquals(ram8Gb.uuid, ram8Gb2.uuid); + assertNotEquals(ram8Gb?.uuid, ram8Gb2?.uuid) } @Test - public void enumDifferentTest() { + fun enumDifferentTest() { //Given - TechFactoryComponent DI = Stone.createComponent(TechFactoryComponent.class); + val DI = TechFactoryComponentStoneComponent() //When - OperationSystem android = DI.factory().phoneOs(PhoneOsType.Android); - OperationSystem android2 = DI.factory().phoneOs(PhoneOsType.Android); - OperationSystem osNull = DI.factory().phoneOs(null); + val android = DI.factory().phoneOs(PhoneOsType.Android) + val android2 = DI.factory().phoneOs(PhoneOsType.Android) + val osNull = DI.factory().phoneOs(null) //Then: created components are different - assertNotEquals(android.uuid, osNull.uuid); - assertNotEquals(android.uuid, android2.uuid); + assertNotEquals(android?.uuid, osNull?.uuid) + assertNotEquals(android?.uuid, android2?.uuid) } - - } diff --git a/tests/src/test/java/com/github/klee0kai/stone/test/identifiers/TechFactoryWrappersTests.kt b/tests/src/test/java/com/github/klee0kai/stone/test/identifiers/TechFactoryWrappersTests.kt index f239b749..538994e3 100644 --- a/tests/src/test/java/com/github/klee0kai/stone/test/identifiers/TechFactoryWrappersTests.kt +++ b/tests/src/test/java/com/github/klee0kai/stone/test/identifiers/TechFactoryWrappersTests.kt @@ -1,101 +1,95 @@ -package com.github.klee0kai.stone.test.identifiers; +package com.github.klee0kai.stone.test.identifiers -import com.github.klee0kai.stone.Stone; -import com.github.klee0kai.stone.wrappers.Ref; -import com.github.klee0kai.test.di.techfactory.TechFactoryComponent; -import com.github.klee0kai.test.tech.components.Battery; -import org.junit.jupiter.api.Test; +import com.github.klee0kai.test.di.techfactory.TechFactoryComponentStoneComponent +import org.junit.jupiter.api.Assertions.assertEquals +import org.junit.jupiter.api.Assertions.assertNotEquals +import org.junit.jupiter.api.Test +import org.junit.jupiter.api.assertNotNull -import javax.inject.Provider; -import java.lang.ref.Reference; - -import static org.junit.jupiter.api.Assertions.*; - -public class TechFactoryWrappersTests { +class TechFactoryWrappersTests { @Test - public void lazyProvideTest() { + fun lazyProvideTest() { //Given - TechFactoryComponent DI = Stone.createComponent(TechFactoryComponent.class); + val DI = TechFactoryComponentStoneComponent() //When - Ref battery = DI.batteryLazy(); + val battery = DI.batteryLazy() //Then assertEquals( - battery.get().uuid, - battery.get().uuid - ); + battery?.get()?.uuid, + battery?.get()?.uuid, + ) } @Test - public void softRefProvideTest() { + fun softRefProvideTest() { //Given - TechFactoryComponent DI = Stone.createComponent(TechFactoryComponent.class); + val DI = TechFactoryComponentStoneComponent() //When - Reference battery = DI.batterySoft(); + val battery = DI.batterySoft() //Then - assertNotNull(battery.get()); + assertNotNull(battery!!.get()) } @Test - public void weakRefProvideTest() { + fun weakRefProvideTest() { //Given - TechFactoryComponent DI = Stone.createComponent(TechFactoryComponent.class); + val DI = TechFactoryComponentStoneComponent() //When - Reference battery = DI.batteryWeak(); + val battery = DI.batteryWeak() //Then - assertNotNull(battery.get()); + assertNotNull(battery!!.get()) } @Test - public void phantom1ProvideTest() { + fun phantom1ProvideTest() { //Given - TechFactoryComponent DI = Stone.createComponent(TechFactoryComponent.class); + val DI = TechFactoryComponentStoneComponent() //When - Ref battery = DI.batteryPhantomProvider(); + val battery = DI.batteryPhantomProvider() //Then assertNotEquals( - battery.get().uuid, - battery.get().uuid - ); + battery!!.get()!!.uuid, + battery.get()!!.uuid, + ) } @Test - public void phantom2ProvideTest() { + fun phantom2ProvideTest() { //Given - TechFactoryComponent DI = Stone.createComponent(TechFactoryComponent.class); + val DI = TechFactoryComponentStoneComponent() //When - Provider battery = DI.batteryProvider(); + val battery = DI.batteryProvider() //Then assertNotEquals( - battery.get().uuid, - battery.get().uuid - ); + battery!!.get()!!.uuid, + battery.get()!!.uuid, + ) } @Test - public void phantom3ProvideTest() { + fun phantom3ProvideTest() { //Given - TechFactoryComponent DI = Stone.createComponent(TechFactoryComponent.class); + val DI = TechFactoryComponentStoneComponent() //When - Ref battery = DI.batteryProviderIRef(); + val battery = DI.batteryProviderIRef() //Then assertNotEquals( - battery.get().uuid, - battery.get().uuid - ); + battery!!.get()!!.uuid, + battery.get()!!.uuid, + ) } - } diff --git a/tests/src/test/java/com/github/klee0kai/stone/test/inject/HorseInjectTests.kt b/tests/src/test/java/com/github/klee0kai/stone/test/inject/HorseInjectTests.kt index 70de85fe..76c67432 100644 --- a/tests/src/test/java/com/github/klee0kai/stone/test/inject/HorseInjectTests.kt +++ b/tests/src/test/java/com/github/klee0kai/stone/test/inject/HorseInjectTests.kt @@ -1,85 +1,89 @@ -package com.github.klee0kai.stone.test.inject; +package com.github.klee0kai.stone.test.inject -import com.github.klee0kai.stone.Stone; -import com.github.klee0kai.test.di.base_forest.ForestComponent; -import com.github.klee0kai.test.mowgli.animal.Horse; -import com.github.klee0kai.test.mowgli.animal.Mowgli; -import com.github.klee0kai.test.mowgli.animal.Snake; -import org.junit.jupiter.api.Test; +import com.github.klee0kai.stone.lifecycle.StoneLifeCycleOwner +import com.github.klee0kai.test.di.base_forest.ForestComponentStoneComponent +import com.github.klee0kai.test.mowgli.animal.Horse +import com.github.klee0kai.test.mowgli.animal.Mowgli +import com.github.klee0kai.test.mowgli.animal.Snake +import org.junit.jupiter.api.Assertions.assertEquals +import org.junit.jupiter.api.Assertions.assertNotEquals +import org.junit.jupiter.api.Test +import org.junit.jupiter.api.assertNotNull -import static org.junit.jupiter.api.Assertions.*; - - -public class HorseInjectTests { +class HorseInjectTests { @Test - public void horseBornTest() { + fun horseBornTest() { //Given - ForestComponent DI = Stone.createComponent(ForestComponent.class); - Horse horse = new Horse(); + val DI = ForestComponentStoneComponent() + val horse = Horse() //When - DI.inject(horse, listener -> { - - }); + DI.inject( + horse, + stoneLifeCycleOwner = StoneLifeCycleOwner { listener -> } + ) //Then - assertNotNull(horse.blood); - assertNotNull(horse.knowledge); - assertNotNull(horse.conscience); - assertNotNull(horse.methodInjectedConscience); - assertNotNull(horse.methodInjectedKnowledge); + assertNotNull(horse.blood) + assertNotNull(horse.knowledge) + assertNotNull(horse.conscience) + assertNotNull(horse.methodInjectedConscience) + assertNotNull(horse.methodInjectedKnowledge) } - @Test - public void mowgliBornTest() { + fun mowgliBornTest() { //Given - ForestComponent DI = Stone.createComponent(ForestComponent.class); - Mowgli mowgli = new Mowgli(); + val DI = ForestComponentStoneComponent() + val mowgli = Mowgli() //When - DI.inject(mowgli); + DI.inject(mowgli) //Then - assertNotNull(mowgli.blood); - assertNotNull(mowgli.knowledge); - assertNotNull(mowgli.conscience); + assertNotNull(mowgli.blood) + assertNotNull(mowgli.knowledge) + assertNotNull(mowgli.conscience) } @Test - public void oneBloodTest() { + fun oneBloodTest() { //Given - ForestComponent DI = Stone.createComponent(ForestComponent.class); - Mowgli mowgli = new Mowgli(); - Snake snake = new Snake(); + val DI = ForestComponentStoneComponent() + val mowgli = Mowgli() + val snake = Snake() //When - DI.inject(mowgli); - DI.inject(snake); + DI.inject(mowgli) + DI.inject(snake) //Then - assertEquals(mowgli.blood.uuid, snake.blood.uuid); + assertEquals( + mowgli.blood!!.uuid, + snake.blood!!.uuid + ) } @Test - public void personalityTest() { + fun personalityTest() { //Given - ForestComponent DI = Stone.createComponent(ForestComponent.class); - Mowgli mowgli = new Mowgli(); - Snake snake = new Snake(); + val DI = ForestComponentStoneComponent() + val mowgli = Mowgli() + val snake = Snake() //When - DI.inject(mowgli); - DI.inject(snake); + DI.inject(mowgli) + DI.inject(snake) //Then - assertNotEquals(mowgli.conscience.uuid, snake.conscience.uuid); + assertNotEquals( + mowgli.conscience!!.uuid, + snake.conscience!!.uuid, + ) } - - } diff --git a/tests/src/test/java/com/github/klee0kai/stone/test/inject/HorseProtectInjectTests.kt b/tests/src/test/java/com/github/klee0kai/stone/test/inject/HorseProtectInjectTests.kt index 46be3676..5c2ff833 100644 --- a/tests/src/test/java/com/github/klee0kai/stone/test/inject/HorseProtectInjectTests.kt +++ b/tests/src/test/java/com/github/klee0kai/stone/test/inject/HorseProtectInjectTests.kt @@ -1,62 +1,60 @@ -package com.github.klee0kai.stone.test.inject; +package com.github.klee0kai.stone.test.inject -import com.github.klee0kai.stone.Stone; -import com.github.klee0kai.test.di.base_forest.ForestComponent; -import com.github.klee0kai.test.mowgli.animal.Horse; -import com.github.klee0kai.test.mowgli.community.History; -import org.junit.jupiter.api.Test; - -import java.lang.ref.WeakReference; - -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertNull; - - -public class HorseProtectInjectTests { +import com.github.klee0kai.test.di.base_forest.ForestComponentStoneComponent +import com.github.klee0kai.test.mowgli.animal.Horse +import org.junit.jupiter.api.Test +import org.junit.jupiter.api.assertNotNull +import org.junit.jupiter.api.assertNull +import java.lang.ref.WeakReference +class HorseProtectInjectTests { @Test - public void withoutProtectInjectTest() { + fun withoutProtectInjectTest() { // Given - ForestComponent DI = Stone.createComponent(ForestComponent.class); - Horse horse = new Horse(); + val DI = ForestComponentStoneComponent() + var horse: Horse? = Horse() //When - DI.inject(horse, listener -> { + DI.inject( + horse, + stoneLifeCycleOwner = { } + ) - }); - WeakReference historyWeakReference = new WeakReference<>(horse.history); - horse = null; - System.gc(); + val historyWeakReference = WeakReference(horse?.history) + horse = null + System.gc() //Then: without protect all not uses should be garbage collected - assertNull(historyWeakReference.get()); - + assertNull(historyWeakReference.get()) } @Test - public void withProtectInjectTest() throws InterruptedException { + @Throws(InterruptedException::class) + fun withProtectInjectTest() { // Given - ForestComponent DI = Stone.createComponent(ForestComponent.class); - Horse horse = new Horse(); + val DI = ForestComponentStoneComponent() + var horse: Horse? = Horse() //When - DI.inject(horse, listener -> { + DI.inject( + horse, + stoneLifeCycleOwner = {} + ) - }); - WeakReference historyWeakReference = new WeakReference<>(horse.history); - DI.protectInjected(horse); - horse = null; - DI.gcAll(); + val historyWeakReference = WeakReference(horse!!.history) + DI.protectInjected(horse) + horse = null + DI.gcAll() //Then - assertNotNull(historyWeakReference.get()); + assertNotNull(historyWeakReference.get()) //after protect finished - Thread.sleep(50); - DI.gcAll(); - assertNull(historyWeakReference.get()); + Thread.sleep(50) + DI.gcAll() + assertNull(historyWeakReference.get()) } } diff --git a/tests/src/test/java/com/github/klee0kai/stone/test/inject/MowgliInjectMethodWrappersTests.kt b/tests/src/test/java/com/github/klee0kai/stone/test/inject/MowgliInjectMethodWrappersTests.kt index ea347da3..2fb3982a 100644 --- a/tests/src/test/java/com/github/klee0kai/stone/test/inject/MowgliInjectMethodWrappersTests.kt +++ b/tests/src/test/java/com/github/klee0kai/stone/test/inject/MowgliInjectMethodWrappersTests.kt @@ -1,83 +1,82 @@ -package com.github.klee0kai.stone.test.inject; +package com.github.klee0kai.stone.test.inject -import com.github.klee0kai.stone.Stone; -import com.github.klee0kai.test.di.base_forest.ForestComponent; -import com.github.klee0kai.test.mowgli.animal.Mowgli; -import org.junit.jupiter.api.Test; +import com.github.klee0kai.test.di.base_forest.ForestComponentStoneComponent +import com.github.klee0kai.test.mowgli.animal.Mowgli +import org.junit.jupiter.api.Assertions.assertEquals +import org.junit.jupiter.api.Assertions.assertNotEquals +import org.junit.jupiter.api.Test +import org.junit.jupiter.api.assertNotNull -import java.util.Objects; - -import static org.junit.jupiter.api.Assertions.*; - -public class MowgliInjectMethodWrappersTests { +class MowgliInjectMethodWrappersTests { @Test - public void supportWrappersTest() { + fun supportWrappersTest() { //Given - ForestComponent DI = Stone.createComponent(ForestComponent.class); - Mowgli mowgli = new Mowgli(); + val DI = ForestComponentStoneComponent() + val mowgli = Mowgli() //When - DI.inject(mowgli); + DI.inject(mowgli) //Then - assertNotNull(mowgli.methodKnowledgeWeakRef.get()); - assertNotNull(mowgli.methodKnowledgeSoftRef.get()); - assertNotNull(mowgli.methodKnowledgeLazyProvide.get()); - assertNotNull(mowgli.methodKnowledgePhantomProvide.get()); - assertNotNull(mowgli.methodKnowledgePhantomProvide2.get()); - assertNotNull(mowgli.methodKnowledgePhantomProvide3.get()); + assertNotNull(mowgli.methodKnowledgeWeakRef!!.get()) + assertNotNull(mowgli.methodKnowledgeSoftRef!!.get()) + assertNotNull(mowgli.methodKnowledgeLazyProvide!!.get()) + assertNotNull(mowgli.methodKnowledgePhantomProvide!!.get()) + assertNotNull(mowgli.methodKnowledgePhantomProvide2!!.get()) + assertNotNull(mowgli.methodKnowledgePhantomProvide3!!.get()) } @Test - public void refWrapperTest() { + fun refWrapperTest() { //Given - ForestComponent DI = Stone.createComponent(ForestComponent.class); - Mowgli mowgli = new Mowgli(); + val DI = ForestComponentStoneComponent() + val mowgli = Mowgli() //When - DI.inject(mowgli); + DI.inject(mowgli) //Then assertEquals( - Objects.requireNonNull(mowgli.methodKnowledgeWeakRef.get()).uuid, - Objects.requireNonNull(mowgli.methodKnowledgeWeakRef.get()).uuid - ); + mowgli.methodKnowledgeWeakRef!!.get()!!.uuid, + mowgli.methodKnowledgeWeakRef!!.get()!!.uuid, + ) assertEquals( - Objects.requireNonNull(mowgli.methodKnowledgeSoftRef.get()).uuid, - Objects.requireNonNull(mowgli.methodKnowledgeSoftRef.get()).uuid - ); + mowgli.methodKnowledgeSoftRef!!.get()!!.uuid, + mowgli.methodKnowledgeSoftRef!!.get()!!.uuid + ) assertEquals( - Objects.requireNonNull(mowgli.methodKnowledgeLazyProvide.get()).uuid, - Objects.requireNonNull(mowgli.methodKnowledgeLazyProvide.get()).uuid - ); + mowgli.methodKnowledgeLazyProvide!!.get()!!.uuid, + mowgli.methodKnowledgeLazyProvide!!.get()!!.uuid, + ) } @Test - public void genWrapperTest() { + fun genWrapperTest() { //Given - ForestComponent DI = Stone.createComponent(ForestComponent.class); - Mowgli mowgli = new Mowgli(); + val DI = ForestComponentStoneComponent() + val mowgli = Mowgli() //When - DI.inject(mowgli); + DI.inject(mowgli) //Then assertNotEquals( - mowgli.methodKnowledgePhantomProvide.get().uuid, - mowgli.methodKnowledgePhantomProvide.get().uuid - ); + mowgli.methodKnowledgePhantomProvide!!.get()!!.uuid, + mowgli.methodKnowledgePhantomProvide!!.get()!!.uuid, + ) assertNotEquals( - mowgli.methodKnowledgePhantomProvide2.get().uuid, - mowgli.methodKnowledgePhantomProvide2.get().uuid - ); + mowgli.methodKnowledgePhantomProvide2!!.get()!!.uuid, + mowgli.methodKnowledgePhantomProvide2!!.get()!!.uuid, + ) assertNotEquals( - mowgli.methodKnowledgePhantomProvide3.get().uuid, - mowgli.methodKnowledgePhantomProvide3.get().uuid - ); + mowgli.methodKnowledgePhantomProvide3!!.get()!!.uuid, + mowgli.methodKnowledgePhantomProvide3!!.get()!!.uuid, + ) } + } diff --git a/tests/src/test/java/com/github/klee0kai/stone/test/inject/MowgliInjectWrappersTests.kt b/tests/src/test/java/com/github/klee0kai/stone/test/inject/MowgliInjectWrappersTests.kt index ada55cd4..229b7e93 100644 --- a/tests/src/test/java/com/github/klee0kai/stone/test/inject/MowgliInjectWrappersTests.kt +++ b/tests/src/test/java/com/github/klee0kai/stone/test/inject/MowgliInjectWrappersTests.kt @@ -1,83 +1,78 @@ -package com.github.klee0kai.stone.test.inject; +package com.github.klee0kai.stone.test.inject -import com.github.klee0kai.stone.Stone; -import com.github.klee0kai.test.di.base_forest.ForestComponent; -import com.github.klee0kai.test.mowgli.animal.Mowgli; -import org.junit.jupiter.api.Test; +import com.github.klee0kai.test.di.base_forest.ForestComponentStoneComponent +import com.github.klee0kai.test.mowgli.animal.Mowgli +import org.junit.jupiter.api.Assertions.* +import org.junit.jupiter.api.Test -import java.util.Objects; - -import static org.junit.jupiter.api.Assertions.*; - -public class MowgliInjectWrappersTests { +class MowgliInjectWrappersTests { @Test - public void supportWrappersTest() { + fun supportWrappersTest() { //Given - ForestComponent DI = Stone.createComponent(ForestComponent.class); - Mowgli mowgli = new Mowgli(); + val DI = ForestComponentStoneComponent() + val mowgli = Mowgli() //When - DI.inject(mowgli); + DI.inject(mowgli) //Then - assertNotNull(mowgli.knowledge); - assertNotNull(mowgli.knowledgeWeakRef.get()); - assertNotNull(mowgli.knowledgeSoftRef.get()); - assertNotNull(mowgli.knowledgeLazyProvide.get()); - assertNotNull(mowgli.knowledgePhantomProvide.get()); - assertNotNull(mowgli.knowledgePhantomProvide2.get()); - assertNotNull(mowgli.knowledgePhantomProvide3.get()); + assertNotNull(mowgli.knowledge) + assertNotNull(mowgli.knowledgeWeakRef!!.get()) + assertNotNull(mowgli.knowledgeSoftRef!!.get()) + assertNotNull(mowgli.knowledgeLazyProvide!!.get()) + assertNotNull(mowgli.knowledgePhantomProvide!!.get()) + assertNotNull(mowgli.knowledgePhantomProvide2!!.get()) + assertNotNull(mowgli.knowledgePhantomProvide3!!.get()) } @Test - public void refWrapperTest() { + fun refWrapperTest() { //Given - ForestComponent DI = Stone.createComponent(ForestComponent.class); - Mowgli mowgli = new Mowgli(); + val DI = ForestComponentStoneComponent() + val mowgli = Mowgli() //When - DI.inject(mowgli); + DI.inject(mowgli) //Then assertEquals( - Objects.requireNonNull(mowgli.knowledgeWeakRef.get()).uuid, - Objects.requireNonNull(mowgli.knowledgeWeakRef.get()).uuid - ); + mowgli.knowledgeWeakRef!!.get()!!.uuid, + mowgli.knowledgeWeakRef!!.get()!!.uuid, + ) assertEquals( - Objects.requireNonNull(mowgli.knowledgeSoftRef.get()).uuid, - Objects.requireNonNull(mowgli.knowledgeSoftRef.get()).uuid - ); + mowgli.knowledgeSoftRef!!.get()!!.uuid, + mowgli.knowledgeSoftRef!!.get()!!.uuid, + ) assertEquals( - Objects.requireNonNull(mowgli.knowledgeLazyProvide.get()).uuid, - Objects.requireNonNull(mowgli.knowledgeLazyProvide.get()).uuid - ); + mowgli.knowledgeLazyProvide!!.get()!!.uuid, + mowgli.knowledgeLazyProvide!!.get()!!.uuid, + ) } @Test - public void genWrapperTest() { + fun genWrapperTest() { //Given - ForestComponent DI = Stone.createComponent(ForestComponent.class); - Mowgli mowgli = new Mowgli(); + val DI = ForestComponentStoneComponent() + val mowgli = Mowgli() //When - DI.inject(mowgli); - + DI.inject(mowgli) //Then assertNotEquals( - mowgli.knowledgePhantomProvide.get().uuid, - mowgli.knowledgePhantomProvide.get().uuid - ); + mowgli.knowledgePhantomProvide!!.get()!!.uuid, + mowgli.knowledgePhantomProvide!!.get()!!.uuid, + ) assertNotEquals( - mowgli.knowledgePhantomProvide2.get().uuid, - mowgli.knowledgePhantomProvide2.get().uuid - ); + mowgli.knowledgePhantomProvide2!!.get()!!.uuid, + mowgli.knowledgePhantomProvide2!!.get()!!.uuid, + ) assertNotEquals( - mowgli.knowledgePhantomProvide3.get().uuid, - mowgli.knowledgePhantomProvide3.get().uuid - ); + mowgli.knowledgePhantomProvide3!!.get()!!.uuid, + mowgli.knowledgePhantomProvide3!!.get()!!.uuid, + ) } } diff --git a/tests/src/test/java/com/github/klee0kai/stone/test/inject/SchoolProtectInjectWrappersTests.kt b/tests/src/test/java/com/github/klee0kai/stone/test/inject/SchoolProtectInjectWrappersTests.kt index 7dd5b85a..046fd77d 100644 --- a/tests/src/test/java/com/github/klee0kai/stone/test/inject/SchoolProtectInjectWrappersTests.kt +++ b/tests/src/test/java/com/github/klee0kai/stone/test/inject/SchoolProtectInjectWrappersTests.kt @@ -1,55 +1,49 @@ -package com.github.klee0kai.stone.test.inject; +package com.github.klee0kai.stone.test.inject -import com.github.klee0kai.stone.Stone; -import com.github.klee0kai.test.di.base_forest.ForestComponent; -import com.github.klee0kai.test.mowgli.School; -import com.github.klee0kai.test.mowgli.community.History; -import com.github.klee0kai.test.mowgli.identity.Knowledge; -import org.junit.jupiter.api.Test; +import com.github.klee0kai.test.di.base_forest.ForestComponentStoneComponent +import com.github.klee0kai.test.mowgli.School +import org.junit.jupiter.api.Test +import org.junit.jupiter.api.assertNotNull +import org.junit.jupiter.api.assertNull +import java.lang.ref.WeakReference -import java.lang.ref.WeakReference; - -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertNull; - - -public class SchoolProtectInjectWrappersTests { +class SchoolProtectInjectWrappersTests { @Test - public void lazyWrapperProtectTest() { + fun lazyWrapperProtectTest() { // Given - ForestComponent DI = Stone.createComponent(ForestComponent.class); - School school = new School(); + val DI = ForestComponentStoneComponent() + val school = School() //When - DI.inject(school); + DI.inject(school) - WeakReference history = new WeakReference<>(school.historyLazyProvide.get()); - DI.protectInjected(school); - DI.gcAll(); + val history = WeakReference(school.historyLazyProvide!!.get()) + DI.protectInjected(school) + DI.gcAll() //Then - assertNotNull(history.get()); + assertNotNull(history.get()) } @Test - public void ignoreProvideWrapperProtectTest() { + fun ignoreProvideWrapperProtectTest() { // Given - ForestComponent DI = Stone.createComponent(ForestComponent.class); - School school = new School(); + val DI = ForestComponentStoneComponent() + val school: School = School() //When - DI.inject(school); - WeakReference knowledge1 = new WeakReference<>(school.knowledgePhantomProvide.get()); - WeakReference knowledge2 = new WeakReference<>(school.knowledgePhantomProvide2.get()); - WeakReference knowledge3 = new WeakReference<>(school.knowledgePhantomProvide3.get()); - DI.protectInjected(school); - DI.gcAll(); + DI.inject(school) + val knowledge1 = WeakReference(school.knowledgePhantomProvide!!.get()) + val knowledge2 = WeakReference(school.knowledgePhantomProvide2!!.get()) + val knowledge3 = WeakReference(school.knowledgePhantomProvide3!!.get()) + DI.protectInjected(school) + DI.gcAll() //Then - assertNull(knowledge1.get()); - assertNull(knowledge2.get()); - assertNull(knowledge3.get()); - + assertNull(knowledge1.get()) + assertNull(knowledge2.get()) + assertNull(knowledge3.get()) } + } diff --git a/tests/src/test/java/com/github/klee0kai/stone/test/interfaceprovide/DeepCaveTest.kt b/tests/src/test/java/com/github/klee0kai/stone/test/interfaceprovide/DeepCaveTest.kt index 499740e6..38bfce5b 100644 --- a/tests/src/test/java/com/github/klee0kai/stone/test/interfaceprovide/DeepCaveTest.kt +++ b/tests/src/test/java/com/github/klee0kai/stone/test/interfaceprovide/DeepCaveTest.kt @@ -1,34 +1,30 @@ -package com.github.klee0kai.stone.test.interfaceprovide; +package com.github.klee0kai.stone.test.interfaceprovide -import com.github.klee0kai.stone.Stone; -import com.github.klee0kai.test.di.earthmirror.EarthComponent; -import com.github.klee0kai.test.mowgli.earth.Cave; -import org.junit.jupiter.api.Test; - -import static org.junit.jupiter.api.Assertions.assertNotNull; - -public class DeepCaveTest { +import com.github.klee0kai.test.di.earthmirror.EarthComponentStoneComponent +import com.github.klee0kai.test.mowgli.earth.Cave +import org.junit.jupiter.api.Test +import org.junit.jupiter.api.assertNotNull +class DeepCaveTest { @Test - public void justCaveTest() { + fun justCaveTest() { //When - EarthComponent di = Stone.createComponent(EarthComponent.class); + val di = EarthComponentStoneComponent() //Then: Cave simple constructor is available - assertNotNull(di.east().cave()); - assertNotNull(di.west().cave()); + assertNotNull(di.east().cave()) + assertNotNull(di.west().cave()) } @Test - public void theCaveTest() { + fun theCaveTest() { //When - EarthComponent di = Stone.createComponent(EarthComponent.class); + val di = EarthComponentStoneComponent() //Then: Cave 2 params constructor is available - assertNotNull(di.east().cave(Cave.CaveType.Glacier, 2)); - assertNotNull(di.west().cave(Cave.CaveType.Fracture, 6)); + assertNotNull(di.east().cave(Cave.CaveType.Glacier, 2)) + assertNotNull(di.west().cave(Cave.CaveType.Fracture, 6)) } - } diff --git a/tests/src/test/java/com/github/klee0kai/stone/test/interfaceprovide/EarthWayTest.kt b/tests/src/test/java/com/github/klee0kai/stone/test/interfaceprovide/EarthWayTest.kt index b8964593..c0893f55 100644 --- a/tests/src/test/java/com/github/klee0kai/stone/test/interfaceprovide/EarthWayTest.kt +++ b/tests/src/test/java/com/github/klee0kai/stone/test/interfaceprovide/EarthWayTest.kt @@ -1,20 +1,19 @@ -package com.github.klee0kai.stone.test.interfaceprovide; +package com.github.klee0kai.stone.test.interfaceprovide -import com.github.klee0kai.stone.Stone; -import com.github.klee0kai.test.di.earthmirror.EarthComponent; -import org.junit.jupiter.api.Test; +import com.github.klee0kai.test.di.earthmirror.EarthComponentStoneComponent +import org.junit.jupiter.api.Test +import org.junit.jupiter.api.assertNotNull -import static org.junit.jupiter.api.Assertions.assertNotNull; - -public class EarthWayTest { +class EarthWayTest { @Test - public void ChristopherColumbusTest() { + fun christopherColumbusTest() { //When - EarthComponent di = Stone.createComponent(EarthComponent.class); + val di = EarthComponentStoneComponent() //Then - assertNotNull(di.west().mountainImp()); - assertNotNull(di.west().riverImpl()); + assertNotNull(di.west().mountainImp()) + assertNotNull(di.west().riverImpl()) } + } diff --git a/tests/src/test/java/com/github/klee0kai/stone/test/lifecycle/GoodPhoneRepairTests.kt b/tests/src/test/java/com/github/klee0kai/stone/test/lifecycle/GoodPhoneRepairTests.kt index e7dc3309..e47756ba 100644 --- a/tests/src/test/java/com/github/klee0kai/stone/test/lifecycle/GoodPhoneRepairTests.kt +++ b/tests/src/test/java/com/github/klee0kai/stone/test/lifecycle/GoodPhoneRepairTests.kt @@ -1,132 +1,131 @@ -package com.github.klee0kai.stone.test.lifecycle; - -import com.github.klee0kai.stone.Stone; -import com.github.klee0kai.test.di.base_phone.PhoneComponent; -import com.github.klee0kai.test.di.base_phone.identifiers.DataStorageSize; -import com.github.klee0kai.test.di.base_phone.identifiers.RamSize; -import com.github.klee0kai.test.tech.components.Battery; -import com.github.klee0kai.test.tech.components.DataStorage; -import com.github.klee0kai.test.tech.components.Ram; -import com.github.klee0kai.test.tech.phone.GoodPhone; -import org.junit.jupiter.api.Test; - -import java.lang.ref.WeakReference; -import java.util.UUID; - -import static org.junit.jupiter.api.Assertions.*; - +package com.github.klee0kai.stone.test.lifecycle + +import com.github.klee0kai.test.di.base_phone.PhoneComponentStoneComponent +import com.github.klee0kai.test.di.base_phone.identifiers.DataStorageSize +import com.github.klee0kai.test.di.base_phone.identifiers.RamSize +import com.github.klee0kai.test.tech.phone.GoodPhone +import org.junit.jupiter.api.Assertions +import org.junit.jupiter.api.Assertions.assertEquals +import org.junit.jupiter.api.Assertions.assertNotEquals +import org.junit.jupiter.api.Test +import org.junit.jupiter.api.assertNotNull +import org.junit.jupiter.api.assertNull +import java.lang.ref.WeakReference /** * Test lifecycle owner over LifecycleUtils */ -public class GoodPhoneRepairTests { +class GoodPhoneRepairTests { @Test - public void goodPhoneInjectTest() { + fun goodPhoneInjectTest() { //Given - PhoneComponent DI = Stone.createComponent(PhoneComponent.class); + val DI = PhoneComponentStoneComponent() //When buy - GoodPhone goodPhone = new GoodPhone(); - DI.inject(goodPhone, goodPhone.lifeCycleOwner, new DataStorageSize("64G"), new RamSize("4G")); + val goodPhone = GoodPhone() + DI.inject(goodPhone, goodPhone.lifeCycleOwner, DataStorageSize("64G"), RamSize("4G")) //Then - assertNotNull(goodPhone.battery); - assertNotNull(goodPhone.dataStorage); - assertNotNull(goodPhone.ram); + assertNotNull(goodPhone.battery) + assertNotNull(goodPhone.dataStorage) + assertNotNull(goodPhone.ram) } @Test - public void goodPhoneBrokeTest() { + fun goodPhoneBrokeTest() { //Given - PhoneComponent DI = Stone.createComponent(PhoneComponent.class); - GoodPhone goodPhone = new GoodPhone(); - DI.inject(goodPhone, goodPhone.lifeCycleOwner, new DataStorageSize("64G"), new RamSize("4G")); - WeakReference batteryRef = new WeakReference<>(goodPhone.battery); - WeakReference dataStorageRef = new WeakReference<>(goodPhone.dataStorage); - WeakReference ramRef = new WeakReference<>(goodPhone.ram); + val DI = PhoneComponentStoneComponent() + val goodPhone = GoodPhone() + DI.inject(goodPhone, goodPhone.lifeCycleOwner, DataStorageSize("64G"), RamSize("4G")) + val batteryRef = WeakReference(goodPhone.battery) + val dataStorageRef = WeakReference(goodPhone.dataStorage) + val ramRef = WeakReference(goodPhone.ram) //When broke and repair - goodPhone.broke(); - System.gc(); - DI.inject(goodPhone, new DataStorageSize("64G"), new RamSize("4G")); + goodPhone.broke() + System.gc() + DI.inject(goodPhone, DataStorageSize("64G"), RamSize("4G")) //Then: Need new details for repair phone. Old components collected by GC - assertNull(batteryRef.get()); - assertNull(dataStorageRef.get()); - assertNull(ramRef.get()); + assertNull(batteryRef.get()) + assertNull(dataStorageRef.get()) + assertNull(ramRef.get()) } @Test - public void goodPhoneDropWatterTest() throws InterruptedException { + @Throws(InterruptedException::class) + fun goodPhoneDropWatterTest() { //Given - PhoneComponent DI = Stone.createComponent(PhoneComponent.class); - GoodPhone goodPhone = new GoodPhone(); - DI.inject(goodPhone, goodPhone.lifeCycleOwner, new DataStorageSize("64G"), new RamSize("4G")); - WeakReference batteryRef = new WeakReference<>(goodPhone.battery); - WeakReference dataStorageRef = new WeakReference<>(goodPhone.dataStorage); - WeakReference ramRef = new WeakReference<>(goodPhone.ram); + val DI = PhoneComponentStoneComponent() + val goodPhone = GoodPhone() + DI.inject(goodPhone, goodPhone.lifeCycleOwner, DataStorageSize("64G"), RamSize("4G")) + val batteryRef = WeakReference(goodPhone.battery) + val dataStorageRef = WeakReference(goodPhone.dataStorage) + val ramRef = WeakReference(goodPhone.ram) //When - goodPhone.dropToWater(); - System.gc(); + goodPhone.dropToWater() + System.gc() //Then: Phone not link with his components - assertNull(goodPhone.battery); - assertNull(goodPhone.dataStorage); - assertNull(goodPhone.ram); + assertNull(goodPhone.battery) + assertNull(goodPhone.dataStorage) + assertNull(goodPhone.ram) //Then: Phone components is alive little time. - assertNotNull(batteryRef.get()); - assertNotNull(dataStorageRef.get()); - assertNotNull(ramRef.get()); + assertNotNull(batteryRef.get()) + assertNotNull(dataStorageRef.get()) + assertNotNull(ramRef.get()) //When: After little time - Thread.sleep(120); - System.gc(); + Thread.sleep(120) + System.gc() //Then: Phone can not be repaired, components lost - assertNull(batteryRef.get()); - assertNull(dataStorageRef.get()); - assertNull(ramRef.get()); + assertNull(batteryRef.get()) + assertNull(dataStorageRef.get()) + assertNull(ramRef.get()) } @Test - public void goodPhoneDrownedRepairTest() throws InterruptedException { + @Throws(InterruptedException::class) + fun goodPhoneDrownedRepairTest() { //Given - PhoneComponent DI = Stone.createComponent(PhoneComponent.class); - GoodPhone goodPhone = new GoodPhone(); - DI.inject(goodPhone, goodPhone.lifeCycleOwner, new DataStorageSize("64G"), new RamSize("4G")); - UUID ramUuid = goodPhone.dataStorage.uuid; + val DI = PhoneComponentStoneComponent() + val goodPhone = GoodPhone() + DI.inject(goodPhone, goodPhone.lifeCycleOwner, DataStorageSize("64G"), RamSize("4G")) + val ramUuid = goodPhone.dataStorage!!.uuid //When - goodPhone.dropToWater(); - Thread.sleep(10); - System.gc(); - DI.inject(goodPhone, goodPhone.lifeCycleOwner, new DataStorageSize("64G"), new RamSize("4G")); + goodPhone.dropToWater() + Thread.sleep(10) + System.gc() + DI.inject(goodPhone, goodPhone.lifeCycleOwner, DataStorageSize("64G"), RamSize("4G")) //Then: Can be repair after little time - assertEquals(ramUuid, goodPhone.dataStorage.uuid); + assertEquals(ramUuid, goodPhone.dataStorage!!.uuid) } @Test - public void goodPhoneDeepDrownedRepairTest() throws InterruptedException { + @Throws(InterruptedException::class) + fun goodPhoneDeepDrownedRepairTest() { //Given - PhoneComponent DI = Stone.createComponent(PhoneComponent.class); - GoodPhone goodPhone = new GoodPhone(); - DI.inject(goodPhone, goodPhone.lifeCycleOwner, new DataStorageSize("64G"), new RamSize("4G")); - UUID ramUuid = goodPhone.dataStorage.uuid; + val DI = PhoneComponentStoneComponent() + val goodPhone = GoodPhone() + DI.inject(goodPhone, goodPhone.lifeCycleOwner, DataStorageSize("64G"), RamSize("4G")) + val ramUuid = goodPhone.dataStorage!!.uuid //When - goodPhone.dropToWater(); - Thread.sleep(120); - System.gc(); - DI.inject(goodPhone, goodPhone.lifeCycleOwner, new DataStorageSize("64G"), new RamSize("4G")); + goodPhone.dropToWater() + Thread.sleep(120) + System.gc() + DI.inject(goodPhone, goodPhone.lifeCycleOwner, DataStorageSize("64G"), RamSize("4G")) //Then: Can not be repair without new details - assertNotEquals(ramUuid, goodPhone.dataStorage.uuid); + assertNotEquals(ramUuid, goodPhone.dataStorage!!.uuid) } } diff --git a/tests/src/test/java/com/github/klee0kai/stone/test/lifecycle/OnePhoneRepairTests.kt b/tests/src/test/java/com/github/klee0kai/stone/test/lifecycle/OnePhoneRepairTests.kt index 259c57b8..b0621efe 100644 --- a/tests/src/test/java/com/github/klee0kai/stone/test/lifecycle/OnePhoneRepairTests.kt +++ b/tests/src/test/java/com/github/klee0kai/stone/test/lifecycle/OnePhoneRepairTests.kt @@ -1,131 +1,128 @@ -package com.github.klee0kai.stone.test.lifecycle; - -import com.github.klee0kai.stone.Stone; -import com.github.klee0kai.test.di.base_phone.PhoneComponent; -import com.github.klee0kai.test.tech.components.Battery; -import com.github.klee0kai.test.tech.components.DataStorage; -import com.github.klee0kai.test.tech.components.Ram; -import com.github.klee0kai.test.tech.phone.OnePhone; -import org.junit.jupiter.api.Test; - -import java.lang.ref.WeakReference; -import java.util.UUID; - -import static org.junit.jupiter.api.Assertions.*; - +package com.github.klee0kai.stone.test.lifecycle + +import com.github.klee0kai.test.di.base_phone.PhoneComponentStoneComponent +import com.github.klee0kai.test.tech.phone.OnePhone +import org.junit.jupiter.api.Assertions.assertEquals +import org.junit.jupiter.api.Assertions.assertNotEquals +import org.junit.jupiter.api.Test +import org.junit.jupiter.api.assertNotNull +import org.junit.jupiter.api.assertNull +import java.lang.ref.WeakReference +import java.util.* /** * Test lifecycle owner implemented in providing model */ -public class OnePhoneRepairTests { - +class OnePhoneRepairTests { @Test - public void onePhoneInjectTest() { + fun onePhoneInjectTest() { //Given - PhoneComponent DI = Stone.createComponent(PhoneComponent.class); + val DI = PhoneComponentStoneComponent() //When - OnePhone onePhone = new OnePhone(); - DI.inject(onePhone); + val onePhone = OnePhone() + DI.inject(onePhone) //Then - assertNotNull(onePhone.battery); - assertNotNull(onePhone.dataStorage); - assertNotNull(onePhone.ram); + assertNotNull(onePhone.battery) + assertNotNull(onePhone.dataStorage) + assertNotNull(onePhone.ram) } @Test - public void onePhoneBrokeTest() { + fun onePhoneBrokeTest() { //Given - PhoneComponent DI = Stone.createComponent(PhoneComponent.class); - OnePhone onePhone = new OnePhone(); - DI.inject(onePhone); - WeakReference batteryRef = new WeakReference<>(onePhone.battery); - WeakReference dataStorageRef = new WeakReference<>(onePhone.dataStorage); - WeakReference ramRef = new WeakReference<>(onePhone.ram); + val DI = PhoneComponentStoneComponent() + val onePhone: OnePhone = OnePhone() + DI.inject(onePhone) + val batteryRef = WeakReference(onePhone.battery) + val dataStorageRef = WeakReference(onePhone.dataStorage) + val ramRef = WeakReference(onePhone.ram) //When - onePhone.broke(); - System.gc(); - DI.inject(onePhone); + onePhone.broke() + System.gc() + DI.inject(onePhone) //Then: Need new details for repair phone. Old components collected by GC - assertNull(batteryRef.get()); - assertNull(dataStorageRef.get()); - assertNull(ramRef.get()); + assertNull(batteryRef.get()) + assertNull(dataStorageRef.get()) + assertNull(ramRef.get()) } @Test - public void onePhoneDropWatterTest() throws InterruptedException { + @Throws(InterruptedException::class) + fun onePhoneDropWatterTest() { //Given - PhoneComponent DI = Stone.createComponent(PhoneComponent.class); - OnePhone onePhone = new OnePhone(); - DI.inject(onePhone); - WeakReference batteryRef = new WeakReference<>(onePhone.battery); - WeakReference dataStorageRef = new WeakReference<>(onePhone.dataStorage); - WeakReference ramRef = new WeakReference<>(onePhone.ram); + val DI = PhoneComponentStoneComponent() + val onePhone: OnePhone = OnePhone() + DI.inject(onePhone) + val batteryRef = WeakReference(onePhone.battery) + val dataStorageRef = WeakReference(onePhone.dataStorage) + val ramRef = WeakReference(onePhone.ram) //When - onePhone.dropToWatter(); - System.gc(); + onePhone.dropToWatter() + System.gc() //Then: Phone not link with his components - assertNull(onePhone.battery); - assertNull(onePhone.dataStorage); - assertNull(onePhone.ram); + assertNull(onePhone.battery) + assertNull(onePhone.dataStorage) + assertNull(onePhone.ram) //Then: Phone components is alive little time. - assertNotNull(batteryRef.get()); - assertNotNull(dataStorageRef.get()); - assertNotNull(ramRef.get()); + assertNotNull(batteryRef.get()) + assertNotNull(dataStorageRef.get()) + assertNotNull(ramRef.get()) //When: After little time - Thread.sleep(120); - System.gc(); + Thread.sleep(120) + System.gc() //Then: Phone can not be repaired, components lost - assertNull(batteryRef.get()); - assertNull(dataStorageRef.get()); - assertNull(ramRef.get()); + assertNull(batteryRef.get()) + assertNull(dataStorageRef.get()) + assertNull(ramRef.get()) } @Test - public void onePhoneDrownedRepairTest() throws InterruptedException { + @Throws(InterruptedException::class) + fun onePhoneDrownedRepairTest() { //Given - PhoneComponent DI = Stone.createComponent(PhoneComponent.class); - OnePhone onePhone = new OnePhone(); - DI.inject(onePhone); - UUID ramUuid = onePhone.dataStorage.uuid; + val DI = PhoneComponentStoneComponent() + val onePhone: OnePhone = OnePhone() + DI.inject(onePhone) + val ramUuid: UUID = onePhone.dataStorage!!.uuid //When - onePhone.dropToWatter(); - Thread.sleep(10); - System.gc(); - DI.inject(onePhone); + onePhone.dropToWatter() + Thread.sleep(10) + System.gc() + DI.inject(onePhone) //Then: Can be repair after little time - assertEquals(ramUuid, onePhone.dataStorage.uuid); + assertEquals(ramUuid, onePhone.dataStorage?.uuid) } @Test - public void onePhoneDeepDrownedRepairTest() throws InterruptedException { + @Throws(InterruptedException::class) + fun onePhoneDeepDrownedRepairTest() { //Given - PhoneComponent DI = Stone.createComponent(PhoneComponent.class); - OnePhone onePhone = new OnePhone(); - DI.inject(onePhone); - UUID ramUuid = onePhone.dataStorage.uuid; + val DI = PhoneComponentStoneComponent() + val onePhone: OnePhone = OnePhone() + DI.inject(onePhone) + val ramUuid: UUID = onePhone.dataStorage!!.uuid //When - onePhone.dropToWatter(); - Thread.sleep(120); - System.gc(); - DI.inject(onePhone); + onePhone.dropToWatter() + Thread.sleep(120) + System.gc() + DI.inject(onePhone) //Then: Can not be repair without new details - assertNotEquals(ramUuid, onePhone.dataStorage.uuid); + assertNotEquals(ramUuid, onePhone.dataStorage!!.uuid) } - } diff --git a/tests/src/test/java/com/github/klee0kai/stone/test/moduleinit/BeginOfBegins2Tests.kt b/tests/src/test/java/com/github/klee0kai/stone/test/moduleinit/BeginOfBegins2Tests.kt index 33c78f3c..1a937a0f 100644 --- a/tests/src/test/java/com/github/klee0kai/stone/test/moduleinit/BeginOfBegins2Tests.kt +++ b/tests/src/test/java/com/github/klee0kai/stone/test/moduleinit/BeginOfBegins2Tests.kt @@ -1,112 +1,84 @@ -package com.github.klee0kai.stone.test.moduleinit; +package com.github.klee0kai.stone.test.moduleinit -import com.github.klee0kai.stone.Stone; -import com.github.klee0kai.test.di.base_forest.ForestComponent; -import com.github.klee0kai.test.di.base_forest.IdentityModule; -import com.github.klee0kai.test.di.base_forest.UnitedModule; -import com.github.klee0kai.test.mowgli.community.History; -import com.github.klee0kai.test.mowgli.galaxy.Earth; -import com.github.klee0kai.test.mowgli.identity.Conscience; -import com.github.klee0kai.test.mowgli.identity.Ideology; -import com.github.klee0kai.test.mowgli.identity.Knowledge; -import org.junit.jupiter.api.Test; +import com.github.klee0kai.test.di.base_forest.ForestComponentStoneComponent +import com.github.klee0kai.test.di.base_forest.IdentityModule +import com.github.klee0kai.test.di.base_forest.UnitedModule +import com.github.klee0kai.test.mowgli.community.History +import com.github.klee0kai.test.mowgli.galaxy.Earth +import com.github.klee0kai.test.mowgli.identity.Conscience +import com.github.klee0kai.test.mowgli.identity.Ideology +import com.github.klee0kai.test.mowgli.identity.Knowledge +import org.junit.jupiter.api.Assertions.assertEquals +import org.junit.jupiter.api.Test -import static org.junit.jupiter.api.Assertions.assertEquals; - -public class BeginOfBegins2Tests { - - private static final Earth earth = new Earth(); - private static final Ideology ideology = new Ideology(); +class BeginOfBegins2Tests { @Test - public void initByFactory() { + fun initByFactory() { //Given - UnitedModule module = new UnitedModule() { - @Override - public Earth earth() { - return earth; - } - - @Override - public History history() { - return null; - } - }; - ForestComponent DI = Stone.createComponent(ForestComponent.class); + val module = object : UnitedModule() { + override fun earth(): Earth = earth + override fun history(): History? = null + + } + val DI = ForestComponentStoneComponent() //When - DI.initUnitedModule(module); + DI.initUnitedModule(module) //Then - assertEquals(earth, DI.united().earth()); + assertEquals(earth, DI.united().earth()) } @Test - public void initByFactoryClass() { + fun initByFactoryClass() { //Given - ForestComponent DI = Stone.createComponent(ForestComponent.class); + TODO("implement this") + val DI = ForestComponentStoneComponent() //When - DI.initUnitedModule(UnitedModuleFactory.class); + DI.initUnitedModule(UnitedModuleFactory::class.java as UnitedModule?) //Then - assertEquals(earth, DI.united().earth()); + assertEquals(earth, DI.united().earth()) } @Test - public void initAllModules() { + fun initAllModules() { //Given - UnitedModule module = new UnitedModule() { - @Override - public Earth earth() { - return earth; - } - - @Override - public History history() { - return null; - } - }; - IdentityModule identityModule = new IdentityModule() { - @Override - public Knowledge knowledge() { - return null; - } - - @Override - public Conscience conscience() { - return null; - } - - @Override - public Ideology ideology() { - return ideology; - } - }; - - ForestComponent DI = Stone.createComponent(ForestComponent.class); + val module: UnitedModule = object : UnitedModule() { + override fun earth(): Earth = earth + override fun history(): History? = null + + } + val identityModule: IdentityModule = object : IdentityModule { + override fun knowledge(): Knowledge? = null + override fun conscience(): Conscience? = null + override fun ideology(): Ideology = ideology + } + + val DI = ForestComponentStoneComponent() //When - DI.iniAllModules(module, identityModule); + DI.iniAllModules(module, identityModule) //Then - assertEquals(earth, DI.united().earth()); - assertEquals(ideology, DI.identity().ideology()); + assertEquals(earth, DI.united().earth()) + assertEquals(ideology, DI.identity().ideology()) + } - public static class UnitedModuleFactory extends UnitedModule { + class UnitedModuleFactory : UnitedModule() { + override fun earth(): Earth = earth - @Override - public Earth earth() { - return earth; - } + override fun history(): History? = null + } - @Override - public History history() { - return null; - } + companion object { + private val earth: Earth = Earth() + private val ideology: Ideology = Ideology() } } diff --git a/tests/src/test/java/com/github/klee0kai/stone/test/moduleinit/BeginOfBeginsTests.kt b/tests/src/test/java/com/github/klee0kai/stone/test/moduleinit/BeginOfBeginsTests.kt index b3169b32..7bd9e3c9 100644 --- a/tests/src/test/java/com/github/klee0kai/stone/test/moduleinit/BeginOfBeginsTests.kt +++ b/tests/src/test/java/com/github/klee0kai/stone/test/moduleinit/BeginOfBeginsTests.kt @@ -1,67 +1,49 @@ -package com.github.klee0kai.stone.test.moduleinit; +package com.github.klee0kai.stone.test.moduleinit -import com.github.klee0kai.stone.Stone; -import com.github.klee0kai.test.di.base_forest.ForestComponent; -import com.github.klee0kai.test.di.base_forest.UnitedModule; -import com.github.klee0kai.test.mowgli.community.History; -import com.github.klee0kai.test.mowgli.galaxy.Earth; -import org.junit.jupiter.api.Test; +import com.github.klee0kai.test.di.base_forest.ForestComponentStoneComponent +import com.github.klee0kai.test.di.base_forest.UnitedModule +import com.github.klee0kai.test.mowgli.community.History +import com.github.klee0kai.test.mowgli.galaxy.Earth +import org.junit.jupiter.api.Assertions.assertEquals +import org.junit.jupiter.api.Test -import static org.junit.jupiter.api.Assertions.assertEquals; - -public class BeginOfBeginsTests { - - private static final Earth earth = new Earth(); +class BeginOfBeginsTests { @Test - public void initByFactory() { + fun initByFactory() { //Given - UnitedModule module = new UnitedModule() { - - - @Override - public Earth earth() { - return earth; - } - - @Override - public History history() { - return null; - } - }; - ForestComponent DI = Stone.createComponent(ForestComponent.class); + val module: UnitedModule = object : UnitedModule() { + override fun earth(): Earth = earth + override fun history() = null + } + val DI = ForestComponentStoneComponent() //When - DI.initUnitedModule(module); + DI.initUnitedModule(module) //Then - assertEquals(earth, DI.united().earth()); + assertEquals(earth, DI.united().earth()) } @Test - public void initByFactoryClass() { + fun initByFactoryClass() { //Given - ForestComponent DI = Stone.createComponent(ForestComponent.class); + val DI = ForestComponentStoneComponent() //When - DI.initUnitedModule(UnitedModuleFactory.class); + DI.initUnitedModule(UnitedModuleFactory::class.java as UnitedModule?) //Then - assertEquals(earth, DI.united().earth()); + assertEquals(earth, DI.united().earth()) } - public static class UnitedModuleFactory extends UnitedModule { - - @Override - public Earth earth() { - return earth; - } - - @Override - public History history() { - return null; - } + class UnitedModuleFactory : UnitedModule() { + override fun earth(): Earth = earth + override fun history(): History? = null } + companion object { + private val earth: Earth = Earth() + } } diff --git a/tests/src/test/java/com/github/klee0kai/stone/test/parameterized/WireTest.kt b/tests/src/test/java/com/github/klee0kai/stone/test/parameterized/WireTest.kt index 9196176d..e7e80cc4 100644 --- a/tests/src/test/java/com/github/klee0kai/stone/test/parameterized/WireTest.kt +++ b/tests/src/test/java/com/github/klee0kai/stone/test/parameterized/WireTest.kt @@ -1,38 +1,48 @@ -package com.github.klee0kai.stone.test.parameterized; +package com.github.klee0kai.stone.test.parameterized -import com.github.klee0kai.stone.Stone; -import com.github.klee0kai.test.di.wire.WireComponent; -import com.github.klee0kai.test.wire.Wire; -import com.github.klee0kai.test.wire.types.MiniUsb; -import org.junit.jupiter.api.Test; +import com.github.klee0kai.test.di.wire.WireComponentStoneComponent +import com.github.klee0kai.test.wire.Wire +import com.github.klee0kai.test.wire.types.MiniUsb +import org.junit.jupiter.api.Assertions.assertEquals +import org.junit.jupiter.api.Assertions.assertNotEquals +import org.junit.jupiter.api.Test +import org.junit.jupiter.api.assertNotNull -import static org.junit.jupiter.api.Assertions.*; - -public class WireTest { +class WireTest { @Test - public void usbUsbProvideTest() { + fun usbUsbProvideTest() { //When - WireComponent di = Stone.createComponent(WireComponent.class); + val di = WireComponentStoneComponent() //Then - assertNotNull(di.module().usb_usb()); - assertEquals(di.module().usb_usb().uuid, di.module().usb_usb().uuid); - assertEquals(di.usb_usb().get().uuid, di.module().usb_usb().uuid); - assertNotEquals(di.module().usb_usb().uuid, di.module().usb_hdmi().uuid); + assertNotNull(di.module().usb_usb()) + assertEquals( + di.module().usb_usb()!!.uuid, + di.module().usb_usb()!!.uuid + ) + assertEquals( + di.usb_usb()!!.get()!!.uuid, + di.module().usb_usb()!!.uuid + ) + assertNotEquals( + di.module().usb_usb()!!.uuid, + di.module().usb_hdmi()!!.uuid, + ) } - @Test - public void miniUsbBindTest() { + @org.junit.jupiter.api.Test + fun miniUsbBindTest() { //When - WireComponent di = Stone.createComponent(WireComponent.class); - Wire wire = new Wire<>(); - di.miniusb_miniusb(wire); + val di = WireComponentStoneComponent() + val wire = Wire() + di.miniusb_miniusb(wire) //Then - assertEquals(wire.uuid, di.miniusb_miniusb(null).uuid); + assertEquals( + wire.uuid, + di.miniusb_miniusb(null)!!.uuid, + ) } - - } diff --git a/tests/src/test/java/com/github/klee0kai/stone/test/types/ListUtilTests.java b/tests/src/test/java/com/github/klee0kai/stone/test/types/ListUtilTests.java index 2d97c2de..ee5b6ec3 100644 --- a/tests/src/test/java/com/github/klee0kai/stone/test/types/ListUtilTests.java +++ b/tests/src/test/java/com/github/klee0kai/stone/test/types/ListUtilTests.java @@ -1,45 +1,41 @@ package com.github.klee0kai.stone.test.types; -import com.github.klee0kai.stone._hidden_.types.ListUtils; +import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; -import java.util.Arrays; -import java.util.Collections; -import java.util.LinkedList; - -import static org.junit.jupiter.api.Assertions.assertEquals; - public class ListUtilTests { @Test + @Disabled("deprecated") public void sortedAddTest() { - LinkedList sortedList = new LinkedList<>(Arrays.asList(4, 3, 4, 5, 10, 11)); - Collections.sort(sortedList); - - ListUtils.orderedAdd(sortedList, 6, (ob1, ob2) -> ob1 - ob2); - ListUtils.orderedAdd(sortedList, 1, (ob1, ob2) -> ob1 - ob2); - ListUtils.orderedAdd(sortedList, 2, (ob1, ob2) -> ob1 - ob2); - ListUtils.orderedAdd(sortedList, 13, (ob1, ob2) -> ob1 - ob2); - ListUtils.orderedAdd(sortedList, 13, (ob1, ob2) -> ob1 - ob2); - ListUtils.orderedAdd(sortedList, 12, (ob1, ob2) -> ob1 - ob2); - - assertEquals(sortedList, Arrays.asList(1, 2, 3, 4, 4, 5, 6, 10, 11, 12, 13, 13)); - System.out.println(Arrays.toString(sortedList.toArray())); +// LinkedList sortedList = new LinkedList<>(Arrays.asList(4, 3, 4, 5, 10, 11)); +// Collections.sort(sortedList); +// +// ListUtils.orderedAdd(sortedList, 6, (ob1, ob2) -> ob1 - ob2); +// ListUtils.orderedAdd(sortedList, 1, (ob1, ob2) -> ob1 - ob2); +// ListUtils.orderedAdd(sortedList, 2, (ob1, ob2) -> ob1 - ob2); +// ListUtils.orderedAdd(sortedList, 13, (ob1, ob2) -> ob1 - ob2); +// ListUtils.orderedAdd(sortedList, 13, (ob1, ob2) -> ob1 - ob2); +// ListUtils.orderedAdd(sortedList, 12, (ob1, ob2) -> ob1 - ob2); +// +// assertEquals(sortedList, Arrays.asList(1, 2, 3, 4, 4, 5, 6, 10, 11, 12, 13, 13)); +// System.out.println(Arrays.toString(sortedList.toArray())); } @Test + @Disabled("deprecated") public void sortedAddTest2() { - LinkedList sortedList = new LinkedList<>(); - - ListUtils.orderedAdd(sortedList, 6, (ob1, ob2) -> ob1 - ob2); - ListUtils.orderedAdd(sortedList, 1, (ob1, ob2) -> ob1 - ob2); - ListUtils.orderedAdd(sortedList, 2, (ob1, ob2) -> ob1 - ob2); - ListUtils.orderedAdd(sortedList, 13, (ob1, ob2) -> ob1 - ob2); - ListUtils.orderedAdd(sortedList, 13, (ob1, ob2) -> ob1 - ob2); - ListUtils.orderedAdd(sortedList, 12, (ob1, ob2) -> ob1 - ob2); - - assertEquals(sortedList, Arrays.asList(1, 2, 6, 12, 13, 13)); - System.out.println(Arrays.toString(sortedList.toArray())); +// LinkedList sortedList = new LinkedList<>(); +// +// ListUtils.orderedAdd(sortedList, 6, (ob1, ob2) -> ob1 - ob2); +// ListUtils.orderedAdd(sortedList, 1, (ob1, ob2) -> ob1 - ob2); +// ListUtils.orderedAdd(sortedList, 2, (ob1, ob2) -> ob1 - ob2); +// ListUtils.orderedAdd(sortedList, 13, (ob1, ob2) -> ob1 - ob2); +// ListUtils.orderedAdd(sortedList, 13, (ob1, ob2) -> ob1 - ob2); +// ListUtils.orderedAdd(sortedList, 12, (ob1, ob2) -> ob1 - ob2); +// +// assertEquals(sortedList, Arrays.asList(1, 2, 6, 12, 13, 13)); +// System.out.println(Arrays.toString(sortedList.toArray())); } } From d5dc974508b37b89c58b258fc759dcb439fca25e Mon Sep 17 00:00:00 2001 From: klee0kai Date: Sun, 14 Dec 2025 10:36:54 +0100 Subject: [PATCH 063/122] fix build --- .../klee0kai/thekey/stone/ksp/Processor.kt | 2 +- .../ksp/helpers/ComponentDeclarationExt.kt | 6 ++-- .../stone/ksp/ksp/KSClassDeclarationExt.kt | 2 +- .../stone/ksp/ksp/KSFunctionDeclarationExt.kt | 2 +- .../stone/ksp/target/GenModuleProcessor.kt | 28 +++++++++++-------- .../target/component/GenComponentProcessor.kt | 3 +- .../hiddenmodule/GenHiddenModuleProcessor.kt | 14 ++++++---- .../test/di/base_phone/PhoneComponent.kt | 3 +- .../simple/GodFirstWorkDayTest.kt | 2 +- 9 files changed, 35 insertions(+), 27 deletions(-) diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/Processor.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/Processor.kt index 29bab5de..8a12cfc2 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/Processor.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/Processor.kt @@ -63,7 +63,7 @@ class Processor( // force changes // debug = true -// debugPkgFilter = "com.github.klee0kai.test.di.swcache" +// debugPkgFilter = "com.github.klee0kai.test.di.wire" } diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/ComponentDeclarationExt.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/ComponentDeclarationExt.kt index be298df0..a5981e37 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/ComponentDeclarationExt.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/ComponentDeclarationExt.kt @@ -43,14 +43,14 @@ val KSClassDeclaration.allIdentifierTypes: Sequence fun List.identifierParameters( allIdentifierTypes: List, -) = filter { it.type.resolve() in allIdentifierTypes } +) = filter { it.type.resolveAlias() in allIdentifierTypes } fun List.notIdentifierParameters( allIdentifierTypes: List, -) = filter { it.type.resolve() !in allIdentifierTypes } +) = filter { it.type.resolveAlias() !in allIdentifierTypes } fun List.lifeCycleParameter() = firstOrNull { - (it.type.resolve().declaration as? KSClassDeclaration) + (it.type.resolveAlias().declaration as? KSClassDeclaration) ?.isChildOf(StoneLifeCycleOwner::class.asClassName()) == true } diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/ksp/KSClassDeclarationExt.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/ksp/KSClassDeclarationExt.kt index 2973eae4..58ae55b7 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/ksp/KSClassDeclarationExt.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/ksp/KSClassDeclarationExt.kt @@ -10,7 +10,7 @@ import com.squareup.kotlinpoet.ksp.toClassNameOrNull import kotlin.reflect.KClass -fun KSTypeReference.resolveAlias(): KSType = resolve().unwrapAlias() +fun KSTypeReference.resolveAlias(): KSType = resolve().makeNotNullable().unwrapAlias() fun KSType.unwrapAlias(): KSType { var current: KSType = this diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/ksp/KSFunctionDeclarationExt.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/ksp/KSFunctionDeclarationExt.kt index a9bc744b..56768754 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/ksp/KSFunctionDeclarationExt.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/ksp/KSFunctionDeclarationExt.kt @@ -24,7 +24,7 @@ fun KSFunctionDeclaration.joinInvokeArguments( availableVariables: List, ): String { return parameters.mapNotNull { parameter -> - val availableVariable = availableVariables.firstOrNull { it.type.resolve() == parameter.type.resolve() } + val availableVariable = availableVariables.firstOrNull { it.type.resolveAlias() == parameter.type.resolveAlias() } if (availableVariable != null) { "${parameter.name!!.asString()} = ${availableVariable.name!!.asString()}" } else { diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/GenModuleProcessor.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/GenModuleProcessor.kt index dc6a6a09..da1105a2 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/GenModuleProcessor.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/GenModuleProcessor.kt @@ -153,11 +153,10 @@ class GenModuleProcessor : TargetFileProcessor { codeBlocks.bindMethodBody.apply { add( - "if (or is %T && or::class == %T::class) {\n", - nonWrappedType, - nonWrappedType, + "if (or::class == %T::class) {\n", + rawTypeOf(nonWrappedType), ) - add(codeSetCachedValue(CodeBlock.of("or"), false)) + add(codeSetCachedValue(CodeBlock.of("or as? %T", nonWrappedType), false)) add("\n") add("%L = true\n", appliedLocalFieldName) add("}\n") @@ -174,6 +173,7 @@ class GenModuleProcessor : TargetFileProcessor { function = function, idArguments = idArguments, itemHolderCodeHelper = itemHolderCodeHelper, + wrapHelper = wrapHelper, ) @@ -191,6 +191,9 @@ class GenModuleProcessor : TargetFileProcessor { val returnType = function.returnType?.resolve()?.toTypeName() returnType?.let { returns(returnType.copy(nullable = true)) } addParameter("__action", CacheAction::class) + idArguments.forEach { + addParameter(it.name!!.asString(), it.type.resolve().toTypeName()) + } addStatement("return null") } } @@ -220,6 +223,7 @@ class GenModuleProcessor : TargetFileProcessor { function = function, idArguments = idArguments, itemHolderCodeHelper = itemHolderCodeHelper, + wrapHelper = wrapHelper, ) } } @@ -356,8 +360,10 @@ class GenModuleProcessor : TargetFileProcessor { function: KSFunctionDeclaration, idArguments: List, itemHolderCodeHelper: ItemHolderCodeHelper, + wrapHelper: WrapHelper, ) { val returnType = function.returnType?.resolve()?.toTypeName() ?: return + val cacheControlType = wrapHelper.listWrapTypeIfNeed(returnType) genFun(function.cacheControlMethodName) { modifiers.add(KModifier.OVERRIDE) returns(returnType.copy(nullable = true)) @@ -378,7 +384,7 @@ class GenModuleProcessor : TargetFileProcessor { beginControlFlow("%T.SET_VALUE ->", CacheAction.ActionType::class) addCode( codeBlock = itemHolderCodeHelper.codeSetCachedValue( - CodeBlock.of("__action.value as? %T", rawTypeOf(returnType)), + CodeBlock.of("__action.value as? %T", cacheControlType), onlyIfNull = false ) ) @@ -387,7 +393,7 @@ class GenModuleProcessor : TargetFileProcessor { beginControlFlow("%T.SET_IF_NULL ->", CacheAction.ActionType::class) addCode( codeBlock = itemHolderCodeHelper.codeSetCachedValue( - CodeBlock.of("__action.value as? %T", rawTypeOf(returnType)), + CodeBlock.of("__action.value as? %T", cacheControlType), onlyIfNull = true ) ) @@ -524,9 +530,8 @@ class GenModuleProcessor : TargetFileProcessor { exceptNames = arrayOf(""), ).forEach { protoProvideMethod -> val cacheControlMethod = protoProvideMethod.cacheControlMethodName - val idArguments = protoProvideMethod.parameters - .filter { it.type.resolve() in identifierTypes } - if (!idArguments.isEmpty()) { + val idArguments = protoProvideMethod.parameters.identifierParameters(identifierTypes) + if (idArguments.isNotEmpty()) { // TODO https://github.com/klee0kai/stone/issues/42 return@forEach } @@ -565,9 +570,8 @@ class GenModuleProcessor : TargetFileProcessor { } val cacheControlMethod = protoProvideMethod.cacheControlMethodName - val idArguments = protoProvideMethod.parameters - .filter { it.type.resolve() in identifierTypes } - if (!idArguments.isEmpty()) { + val idArguments = protoProvideMethod.parameters.identifierParameters(identifierTypes) + if (idArguments.isNotEmpty()) { // TODO https://github.com/klee0kai/stone/issues/42 return@forEach } diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/component/GenComponentProcessor.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/component/GenComponentProcessor.kt index a9f40e69..ed096acf 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/component/GenComponentProcessor.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/component/GenComponentProcessor.kt @@ -26,6 +26,7 @@ import com.github.klee0kai.thekey.stone.ksp.ksp.arch.GenSpec import com.github.klee0kai.thekey.stone.ksp.ksp.arch.SymbolsToProcess import com.github.klee0kai.thekey.stone.ksp.ksp.arch.TargetFileProcessor import com.github.klee0kai.thekey.stone.ksp.ksp.getAllMethods +import com.github.klee0kai.thekey.stone.ksp.ksp.resolveAlias import com.github.klee0kai.thekey.stone.ksp.poet.* import com.github.klee0kai.thekey.stone.ksp.target.GenModuleProcessor import com.google.devtools.ksp.KspExperimental @@ -320,7 +321,7 @@ class GenComponentProcessor : TargetFileProcessor { val returnType = method.returnType?.resolve()?.toTypeName() ?: return val identifierTypes = componentCl.allIdentifierTypes.toList() - val setValueArg = method.parameters.firstOrNull { it.type.resolve() !in identifierTypes } + val setValueArg = method.parameters.firstOrNull { it.type.resolveAlias() !in identifierTypes } ?: throw IncorrectSignatureException( message = "Bind instance method must have bind instance arcgument", element = method, diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/hiddenmodule/GenHiddenModuleProcessor.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/hiddenmodule/GenHiddenModuleProcessor.kt index 410e0a50..624191f6 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/hiddenmodule/GenHiddenModuleProcessor.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/hiddenmodule/GenHiddenModuleProcessor.kt @@ -126,11 +126,10 @@ class GenHiddenModuleProcessor : TargetFileProcessor { codeBlocks.bindMethodBody.apply { add( - "if (or is %T && or::class == %T::class) {\n", - nonWrappedType, - nonWrappedType, + "if (or::class == %T::class) {\n", + rawTypeOf(nonWrappedType), ) - add(codeSetCachedValue(CodeBlock.of("or"), false)) + add(codeSetCachedValue(CodeBlock.of("or as? %T", nonWrappedType), false)) add("\n") add("%L = true\n", appliedLocalFieldName) add("}\n") @@ -147,6 +146,7 @@ class GenHiddenModuleProcessor : TargetFileProcessor { function = function, idArguments = idArguments, itemHolderCodeHelper = itemHolderCodeHelper, + wrapHelper = wrapHelper, ) } @@ -221,8 +221,10 @@ class GenHiddenModuleProcessor : TargetFileProcessor { function: KSFunctionDeclaration, idArguments: List, itemHolderCodeHelper: ItemHolderCodeHelper, + wrapHelper: WrapHelper, ) { val returnType = function.returnType?.resolve()?.toTypeName() ?: return + val cacheControlType = wrapHelper.listWrapTypeIfNeed(returnType) genFun(function.cacheControlMethodName) { modifiers.add(KModifier.OVERRIDE) returns(returnType.copy(nullable = true)) @@ -243,7 +245,7 @@ class GenHiddenModuleProcessor : TargetFileProcessor { beginControlFlow("%T.SET_VALUE ->", CacheAction.ActionType::class) addCode( codeBlock = itemHolderCodeHelper.codeSetCachedValue( - CodeBlock.of("__action.value as? %T", rawTypeOf(returnType)), + CodeBlock.of("__action.value as? %T", cacheControlType), onlyIfNull = false, ) ) @@ -252,7 +254,7 @@ class GenHiddenModuleProcessor : TargetFileProcessor { beginControlFlow("%T.SET_IF_NULL ->", CacheAction.ActionType::class) addCode( codeBlock = itemHolderCodeHelper.codeSetCachedValue( - CodeBlock.of("__action.value as? %T", rawTypeOf(returnType)), + CodeBlock.of("__action.value as? %T", cacheControlType), onlyIfNull = true, ) ) diff --git a/tests/src/main/java/com/github/klee0kai/test/di/base_phone/PhoneComponent.kt b/tests/src/main/java/com/github/klee0kai/test/di/base_phone/PhoneComponent.kt index 39097466..ee62865e 100644 --- a/tests/src/main/java/com/github/klee0kai/test/di/base_phone/PhoneComponent.kt +++ b/tests/src/main/java/com/github/klee0kai/test/di/base_phone/PhoneComponent.kt @@ -10,7 +10,8 @@ import com.github.klee0kai.test.tech.phone.GoodPhone import com.github.klee0kai.test.tech.phone.OnePhone @Component( - identifiers = [DataStorageSize::class, RamSize::class, PhoneOsType::class, PhoneOsVersion::class + identifiers = [ + DataStorageSize::class, RamSize::class, PhoneOsType::class, PhoneOsVersion::class ] ) interface PhoneComponent { diff --git a/tests/src/test/java/com/github/klee0kai/stone/test/bindinstance/simple/GodFirstWorkDayTest.kt b/tests/src/test/java/com/github/klee0kai/stone/test/bindinstance/simple/GodFirstWorkDayTest.kt index aa4f8d57..3a268cf3 100644 --- a/tests/src/test/java/com/github/klee0kai/stone/test/bindinstance/simple/GodFirstWorkDayTest.kt +++ b/tests/src/test/java/com/github/klee0kai/stone/test/bindinstance/simple/GodFirstWorkDayTest.kt @@ -14,7 +14,7 @@ class GodFirstWorkDayTest { fun firstCreateSunTest() { //Given val DI = GodWorkspaceComponentStoneComponent() - val sun = com.github.klee0kai.test.mowgli.galaxy.Sun() + val sun = Sun() //When DI.bindSun(sun) From b1f2a1025ae064727dc3a64b66db7afac5512fe7 Mon Sep 17 00:00:00 2001 From: klee0kai Date: Sun, 14 Dec 2025 18:06:40 +0100 Subject: [PATCH 064/122] fix few tests --- .../com/github/klee0kai/thekey/stone/ksp/Processor.kt | 2 +- .../thekey/stone/ksp/ksp/KSClassDeclarationExt.kt | 9 +++++---- .../thekey/stone/ksp/target/GenModuleFactoryProcessor.kt | 6 ++++-- .../thekey/stone/ksp/target/GenModuleProcessor.kt | 2 ++ .../ksp/target/hiddenmodule/GenHiddenModuleProcessor.kt | 2 ++ .../github/klee0kai/test/tech/components/DataStorage.kt | 4 ++-- .../java/com/github/klee0kai/test/tech/components/Ram.kt | 4 ++-- 7 files changed, 18 insertions(+), 11 deletions(-) diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/Processor.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/Processor.kt index 8a12cfc2..4f437a68 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/Processor.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/Processor.kt @@ -63,7 +63,7 @@ class Processor( // force changes // debug = true -// debugPkgFilter = "com.github.klee0kai.test.di.wire" +// debugPkgFilter = "com.github.klee0kai.test.di.base_phone" } diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/ksp/KSClassDeclarationExt.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/ksp/KSClassDeclarationExt.kt index 58ae55b7..a9b6028b 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/ksp/KSClassDeclarationExt.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/ksp/KSClassDeclarationExt.kt @@ -24,10 +24,11 @@ fun KSType.unwrapAlias(): KSType { fun KSClassDeclaration.findConstructor( parameters: List, -): KSFunctionDeclaration? = getDeclaredFunctions().firstOrNull { function -> - function.simpleName.asString() == "" - && function.parameters.all { it.type.resolve() in parameters || it.hasDefault } -} +): KSFunctionDeclaration? = getDeclaredFunctions() + .filter { function -> + function.simpleName.asString() == "" + && function.parameters.all { it.type.resolveAlias() in parameters || it.hasDefault } + }.maxByOrNull { it.parameters.size } fun KSDeclaration.isAnyType( vararg cl: KClass<*>, diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/GenModuleFactoryProcessor.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/GenModuleFactoryProcessor.kt index bcb89f27..5aba071b 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/GenModuleFactoryProcessor.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/GenModuleFactoryProcessor.kt @@ -13,6 +13,7 @@ import com.github.klee0kai.thekey.stone.ksp.ksp.arch.TargetFileProcessor import com.github.klee0kai.thekey.stone.ksp.ksp.findConstructor import com.github.klee0kai.thekey.stone.ksp.ksp.getAllMethods import com.github.klee0kai.thekey.stone.ksp.ksp.joinInvokeArguments +import com.github.klee0kai.thekey.stone.ksp.ksp.resolveAlias import com.github.klee0kai.thekey.stone.ksp.poet.genClass import com.github.klee0kai.thekey.stone.ksp.poet.genFileSpec import com.github.klee0kai.thekey.stone.ksp.poet.genLibComment @@ -72,14 +73,14 @@ class GenModuleFactoryProcessor : TargetFileProcessor { validSymbol.getAllMethods(false, false, "") .forEachFun { _, function -> if (!function.modifiers.contains(Modifier.ABSTRACT) && moduleCl.classKind != ClassKind.INTERFACE) return@forEachFun - val returnCl = function.returnType?.resolve() + val returnCl = function.returnType?.resolveAlias() ?.declaration as? KSClassDeclaration ?: return@forEachFun val bindInstanceAnn = function.getAnnotationsByType(BindInstance::class) .firstOrNull() val constructorFun by lazy { returnCl.findConstructor( - parameters = function.parameters.map { it.type.resolve() }) + parameters = function.parameters.map { it.type.resolveAlias() }) } genOverrideFun(function) { @@ -110,6 +111,7 @@ class GenModuleFactoryProcessor : TargetFileProcessor { } } } + } } diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/GenModuleProcessor.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/GenModuleProcessor.kt index da1105a2..63acf1c2 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/GenModuleProcessor.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/GenModuleProcessor.kt @@ -382,6 +382,7 @@ class GenModuleProcessor : TargetFileProcessor { addStatement("%T.GET_VALUE -> Unit", CacheAction.ActionType::class) //set value beginControlFlow("%T.SET_VALUE ->", CacheAction.ActionType::class) + addCode("if ( __action.value != null ) ") addCode( codeBlock = itemHolderCodeHelper.codeSetCachedValue( CodeBlock.of("__action.value as? %T", cacheControlType), @@ -391,6 +392,7 @@ class GenModuleProcessor : TargetFileProcessor { endControlFlow() //set if null value beginControlFlow("%T.SET_IF_NULL ->", CacheAction.ActionType::class) + addCode("if ( __action.value != null ) ") addCode( codeBlock = itemHolderCodeHelper.codeSetCachedValue( CodeBlock.of("__action.value as? %T", cacheControlType), diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/hiddenmodule/GenHiddenModuleProcessor.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/hiddenmodule/GenHiddenModuleProcessor.kt index 624191f6..6f056fbd 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/hiddenmodule/GenHiddenModuleProcessor.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/hiddenmodule/GenHiddenModuleProcessor.kt @@ -243,6 +243,7 @@ class GenHiddenModuleProcessor : TargetFileProcessor { addStatement("%T.GET_VALUE -> Unit", CacheAction.ActionType::class) //set value beginControlFlow("%T.SET_VALUE ->", CacheAction.ActionType::class) + addCode("if ( __action.value != null ) ") addCode( codeBlock = itemHolderCodeHelper.codeSetCachedValue( CodeBlock.of("__action.value as? %T", cacheControlType), @@ -252,6 +253,7 @@ class GenHiddenModuleProcessor : TargetFileProcessor { endControlFlow() //set if null value beginControlFlow("%T.SET_IF_NULL ->", CacheAction.ActionType::class) + addCode("if ( __action.value != null ) ") addCode( codeBlock = itemHolderCodeHelper.codeSetCachedValue( CodeBlock.of("__action.value as? %T", cacheControlType), diff --git a/tests/src/main/java/com/github/klee0kai/test/tech/components/DataStorage.kt b/tests/src/main/java/com/github/klee0kai/test/tech/components/DataStorage.kt index f5f64a94..6515bfcb 100644 --- a/tests/src/main/java/com/github/klee0kai/test/tech/components/DataStorage.kt +++ b/tests/src/main/java/com/github/klee0kai/test/tech/components/DataStorage.kt @@ -14,7 +14,7 @@ class DataStorage { size = null } - constructor(size: DataStorageSize) { - this.size = size.size + constructor(size: DataStorageSize?) { + this.size = size?.size } } diff --git a/tests/src/main/java/com/github/klee0kai/test/tech/components/Ram.kt b/tests/src/main/java/com/github/klee0kai/test/tech/components/Ram.kt index af9d56ab..23ae80bb 100644 --- a/tests/src/main/java/com/github/klee0kai/test/tech/components/Ram.kt +++ b/tests/src/main/java/com/github/klee0kai/test/tech/components/Ram.kt @@ -14,7 +14,7 @@ open class Ram { size = "default" } - constructor(ramSize: RamSize) { - this.size = ramSize.size + constructor(ramSize: RamSize?) { + this.size = ramSize?.size } } From 442c04f773e318b84c5cc1ff0a93ef1bf2afecaf Mon Sep 17 00:00:00 2001 From: klee0kai Date: Sun, 14 Dec 2025 18:09:28 +0100 Subject: [PATCH 065/122] few changes --- .../com/github/klee0kai/test/di/base_forest/UnitedModule.kt | 1 + .../java/com/github/klee0kai/test/di/base_phone/TechModule.kt | 1 - .../test/di/bindinstance/simple/GodWorkspaceComponent.kt | 2 ++ .../klee0kai/test/di/bindinstance/simple_inject/StarsModule.kt | 2 ++ .../test/di/bindinstance/singlemethod_inject/StarSkyModule.kt | 1 + .../java/com/github/klee0kai/test/di/gcforest/GcEarthModule.kt | 1 + 6 files changed, 7 insertions(+), 1 deletion(-) diff --git a/tests/src/main/java/com/github/klee0kai/test/di/base_forest/UnitedModule.kt b/tests/src/main/java/com/github/klee0kai/test/di/base_forest/UnitedModule.kt index 4e459f81..92c59090 100644 --- a/tests/src/main/java/com/github/klee0kai/test/di/base_forest/UnitedModule.kt +++ b/tests/src/main/java/com/github/klee0kai/test/di/base_forest/UnitedModule.kt @@ -9,6 +9,7 @@ import java.awt.Color @Module abstract class UnitedModule { + @Provide(cache = Provide.CacheType.Strong) open fun blood(): Blood? { return Blood(Color.RED) diff --git a/tests/src/main/java/com/github/klee0kai/test/di/base_phone/TechModule.kt b/tests/src/main/java/com/github/klee0kai/test/di/base_phone/TechModule.kt index 34cd83aa..f5f2c7b3 100644 --- a/tests/src/main/java/com/github/klee0kai/test/di/base_phone/TechModule.kt +++ b/tests/src/main/java/com/github/klee0kai/test/di/base_phone/TechModule.kt @@ -27,7 +27,6 @@ interface TechModule { @Provide(cache = Provide.CacheType.Weak) fun ram(ramSize: RamSize?): Ram? - @Named("null_args") @Provide(cache = Provide.CacheType.Weak) fun ram(): Ram? diff --git a/tests/src/main/java/com/github/klee0kai/test/di/bindinstance/simple/GodWorkspaceComponent.kt b/tests/src/main/java/com/github/klee0kai/test/di/bindinstance/simple/GodWorkspaceComponent.kt index a8ffb6a3..067ca6ce 100644 --- a/tests/src/main/java/com/github/klee0kai/test/di/bindinstance/simple/GodWorkspaceComponent.kt +++ b/tests/src/main/java/com/github/klee0kai/test/di/bindinstance/simple/GodWorkspaceComponent.kt @@ -9,6 +9,7 @@ import com.github.klee0kai.test.mowgli.galaxy.Sun @Component interface GodWorkspaceComponent { + fun sunSystem(): SunSystemModule? @BindInstance @@ -27,4 +28,5 @@ interface GodWorkspaceComponent { fun bindSaturn(saturn: Saturn?) fun providePlanet(): IPlanet? + } diff --git a/tests/src/main/java/com/github/klee0kai/test/di/bindinstance/simple_inject/StarsModule.kt b/tests/src/main/java/com/github/klee0kai/test/di/bindinstance/simple_inject/StarsModule.kt index 2c0f7bdd..dbc97295 100644 --- a/tests/src/main/java/com/github/klee0kai/test/di/bindinstance/simple_inject/StarsModule.kt +++ b/tests/src/main/java/com/github/klee0kai/test/di/bindinstance/simple_inject/StarsModule.kt @@ -7,9 +7,11 @@ import com.github.klee0kai.test.mowgli.galaxy.Sun @Module interface StarsModule { + @BindInstance fun star(): IStar? @BindInstance fun sun(): Sun? + } diff --git a/tests/src/main/java/com/github/klee0kai/test/di/bindinstance/singlemethod_inject/StarSkyModule.kt b/tests/src/main/java/com/github/klee0kai/test/di/bindinstance/singlemethod_inject/StarSkyModule.kt index a29441f5..bb1fc839 100644 --- a/tests/src/main/java/com/github/klee0kai/test/di/bindinstance/singlemethod_inject/StarSkyModule.kt +++ b/tests/src/main/java/com/github/klee0kai/test/di/bindinstance/singlemethod_inject/StarSkyModule.kt @@ -9,6 +9,7 @@ import com.github.klee0kai.test.mowgli.galaxy.Sun @Module interface StarSkyModule { + @GcSunScope @BindInstance fun sun(sun: Sun?): Sun? diff --git a/tests/src/main/java/com/github/klee0kai/test/di/gcforest/GcEarthModule.kt b/tests/src/main/java/com/github/klee0kai/test/di/gcforest/GcEarthModule.kt index 0c110c3f..54387b55 100644 --- a/tests/src/main/java/com/github/klee0kai/test/di/gcforest/GcEarthModule.kt +++ b/tests/src/main/java/com/github/klee0kai/test/di/gcforest/GcEarthModule.kt @@ -9,6 +9,7 @@ import com.github.klee0kai.test.mowgli.earth.River @Module abstract class GcEarthModule { + @GcMountainScope @Provide(cache = Provide.CacheType.Strong) abstract fun mountainStrong(): Mountain? From 2d2a0678807aaf7bf4fb44ace8e67d947a513354 Mon Sep 17 00:00:00 2001 From: klee0kai Date: Sun, 14 Dec 2025 18:26:18 +0100 Subject: [PATCH 066/122] move classes --- .../klee0kai/thekey/stone/ksp/Processor.kt | 6 +++--- .../target/component/ComponentsMethodsExt.kt | 2 +- .../target/component/GenComponentProcessor.kt | 2 +- .../GenHiddenModuleCacheControlProcessor.kt | 2 +- .../hiddenmodule/GenHiddenModuleProcessor.kt | 18 +++++++++--------- .../GenModuleCacheControlProcessor.kt | 2 +- .../{ => module}/GenModuleFactoryProcessor.kt | 2 +- .../target/{ => module}/GenModuleProcessor.kt | 2 +- 8 files changed, 18 insertions(+), 18 deletions(-) rename stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/{ => module}/GenModuleCacheControlProcessor.kt (98%) rename stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/{ => module}/GenModuleFactoryProcessor.kt (98%) rename stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/{ => module}/GenModuleProcessor.kt (99%) diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/Processor.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/Processor.kt index 4f437a68..0638ec8f 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/Processor.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/Processor.kt @@ -7,9 +7,9 @@ import com.github.klee0kai.thekey.stone.ksp.ksp.arch.GenSpec import com.github.klee0kai.thekey.stone.ksp.ksp.arch.filter import com.github.klee0kai.thekey.stone.ksp.ksp.arch.forceProcess import com.github.klee0kai.thekey.stone.ksp.ksp.arch.nowTakeOnly -import com.github.klee0kai.thekey.stone.ksp.target.GenModuleCacheControlProcessor -import com.github.klee0kai.thekey.stone.ksp.target.GenModuleFactoryProcessor -import com.github.klee0kai.thekey.stone.ksp.target.GenModuleProcessor +import com.github.klee0kai.thekey.stone.ksp.target.module.GenModuleCacheControlProcessor +import com.github.klee0kai.thekey.stone.ksp.target.module.GenModuleFactoryProcessor +import com.github.klee0kai.thekey.stone.ksp.target.module.GenModuleProcessor import com.github.klee0kai.thekey.stone.ksp.target.component.GenComponentProcessor import com.github.klee0kai.thekey.stone.ksp.target.hiddenmodule.GenHiddenModuleCacheControlProcessor import com.github.klee0kai.thekey.stone.ksp.target.hiddenmodule.GenHiddenModuleProcessor diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/component/ComponentsMethodsExt.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/component/ComponentsMethodsExt.kt index 58f09c6b..d01bba32 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/component/ComponentsMethodsExt.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/component/ComponentsMethodsExt.kt @@ -14,7 +14,7 @@ import com.github.klee0kai.thekey.stone.ksp.ksp.isClassReturn import com.github.klee0kai.thekey.stone.ksp.ksp.isNotPrimitive import com.github.klee0kai.thekey.stone.ksp.ksp.isUnit import com.github.klee0kai.thekey.stone.ksp.ksp.resolveAlias -import com.github.klee0kai.thekey.stone.ksp.target.GenModuleProcessor +import com.github.klee0kai.thekey.stone.ksp.target.module.GenModuleProcessor import com.google.devtools.ksp.getAllSuperTypes import com.google.devtools.ksp.symbol.KSClassDeclaration import com.google.devtools.ksp.symbol.KSFunctionDeclaration diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/component/GenComponentProcessor.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/component/GenComponentProcessor.kt index ed096acf..9ec71e5b 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/component/GenComponentProcessor.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/component/GenComponentProcessor.kt @@ -28,7 +28,7 @@ import com.github.klee0kai.thekey.stone.ksp.ksp.arch.TargetFileProcessor import com.github.klee0kai.thekey.stone.ksp.ksp.getAllMethods import com.github.klee0kai.thekey.stone.ksp.ksp.resolveAlias import com.github.klee0kai.thekey.stone.ksp.poet.* -import com.github.klee0kai.thekey.stone.ksp.target.GenModuleProcessor +import com.github.klee0kai.thekey.stone.ksp.target.module.GenModuleProcessor import com.google.devtools.ksp.KspExperimental import com.google.devtools.ksp.containingFile import com.google.devtools.ksp.getAllSuperTypes diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/hiddenmodule/GenHiddenModuleCacheControlProcessor.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/hiddenmodule/GenHiddenModuleCacheControlProcessor.kt index b0555934..9d1490dc 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/hiddenmodule/GenHiddenModuleCacheControlProcessor.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/hiddenmodule/GenHiddenModuleCacheControlProcessor.kt @@ -13,7 +13,7 @@ import com.github.klee0kai.thekey.stone.ksp.ksp.arch.SymbolsToProcess import com.github.klee0kai.thekey.stone.ksp.ksp.arch.TargetFileProcessor import com.github.klee0kai.thekey.stone.ksp.ksp.getAllMethods import com.github.klee0kai.thekey.stone.ksp.poet.* -import com.github.klee0kai.thekey.stone.ksp.target.GenModuleProcessor +import com.github.klee0kai.thekey.stone.ksp.target.module.GenModuleProcessor import com.github.klee0kai.thekey.stone.ksp.target.component.BindInstanceType import com.github.klee0kai.thekey.stone.ksp.target.component.isBindInstanceMethod import com.google.devtools.ksp.KspExperimental diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/hiddenmodule/GenHiddenModuleProcessor.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/hiddenmodule/GenHiddenModuleProcessor.kt index 6f056fbd..895c31bd 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/hiddenmodule/GenHiddenModuleProcessor.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/hiddenmodule/GenHiddenModuleProcessor.kt @@ -22,15 +22,15 @@ import com.github.klee0kai.thekey.stone.ksp.ksp.arch.SymbolsToProcess import com.github.klee0kai.thekey.stone.ksp.ksp.arch.TargetFileProcessor import com.github.klee0kai.thekey.stone.ksp.ksp.getAllMethods import com.github.klee0kai.thekey.stone.ksp.poet.* -import com.github.klee0kai.thekey.stone.ksp.target.GenModuleProcessor.Companion.appliedLocalFieldName -import com.github.klee0kai.thekey.stone.ksp.target.GenModuleProcessor.Companion.bindMethodName -import com.github.klee0kai.thekey.stone.ksp.target.GenModuleProcessor.Companion.clearNullsMethodName -import com.github.klee0kai.thekey.stone.ksp.target.GenModuleProcessor.Companion.factoryFieldName -import com.github.klee0kai.thekey.stone.ksp.target.GenModuleProcessor.Companion.initCachesFromMethodName -import com.github.klee0kai.thekey.stone.ksp.target.GenModuleProcessor.Companion.initMethodName -import com.github.klee0kai.thekey.stone.ksp.target.GenModuleProcessor.Companion.overridedModuleFieldName -import com.github.klee0kai.thekey.stone.ksp.target.GenModuleProcessor.Companion.switchRefMethodName -import com.github.klee0kai.thekey.stone.ksp.target.GenModuleProcessor.Companion.updateBindInstancesFrom +import com.github.klee0kai.thekey.stone.ksp.target.module.GenModuleProcessor.Companion.appliedLocalFieldName +import com.github.klee0kai.thekey.stone.ksp.target.module.GenModuleProcessor.Companion.bindMethodName +import com.github.klee0kai.thekey.stone.ksp.target.module.GenModuleProcessor.Companion.clearNullsMethodName +import com.github.klee0kai.thekey.stone.ksp.target.module.GenModuleProcessor.Companion.factoryFieldName +import com.github.klee0kai.thekey.stone.ksp.target.module.GenModuleProcessor.Companion.initCachesFromMethodName +import com.github.klee0kai.thekey.stone.ksp.target.module.GenModuleProcessor.Companion.initMethodName +import com.github.klee0kai.thekey.stone.ksp.target.module.GenModuleProcessor.Companion.overridedModuleFieldName +import com.github.klee0kai.thekey.stone.ksp.target.module.GenModuleProcessor.Companion.switchRefMethodName +import com.github.klee0kai.thekey.stone.ksp.target.module.GenModuleProcessor.Companion.updateBindInstancesFrom import com.github.klee0kai.thekey.stone.ksp.target.component.BindInstanceType import com.github.klee0kai.thekey.stone.ksp.target.component.collectComponentGraph import com.github.klee0kai.thekey.stone.ksp.target.component.collectWrapHelper diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/GenModuleCacheControlProcessor.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/module/GenModuleCacheControlProcessor.kt similarity index 98% rename from stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/GenModuleCacheControlProcessor.kt rename to stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/module/GenModuleCacheControlProcessor.kt index af4f5d95..0b1eb077 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/GenModuleCacheControlProcessor.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/module/GenModuleCacheControlProcessor.kt @@ -1,6 +1,6 @@ @file:OptIn(KspExperimental::class) -package com.github.klee0kai.thekey.stone.ksp.target +package com.github.klee0kai.thekey.stone.ksp.target.module import com.github.klee0kai.stone.__hidden__.CacheAction import com.github.klee0kai.stone.__hidden__.SwitchCacheParam diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/GenModuleFactoryProcessor.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/module/GenModuleFactoryProcessor.kt similarity index 98% rename from stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/GenModuleFactoryProcessor.kt rename to stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/module/GenModuleFactoryProcessor.kt index 5aba071b..1eca5073 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/GenModuleFactoryProcessor.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/module/GenModuleFactoryProcessor.kt @@ -1,6 +1,6 @@ @file:OptIn(KspExperimental::class) -package com.github.klee0kai.thekey.stone.ksp.target +package com.github.klee0kai.thekey.stone.ksp.target.module import com.github.klee0kai.stone.__hidden__.IModuleFactory import com.github.klee0kai.stone.annotations.module.BindInstance diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/GenModuleProcessor.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/module/GenModuleProcessor.kt similarity index 99% rename from stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/GenModuleProcessor.kt rename to stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/module/GenModuleProcessor.kt index 63acf1c2..bf2d1828 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/GenModuleProcessor.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/module/GenModuleProcessor.kt @@ -1,6 +1,6 @@ @file:OptIn(KspExperimental::class) -package com.github.klee0kai.thekey.stone.ksp.target +package com.github.klee0kai.thekey.stone.ksp.target.module import com.github.klee0kai.stone.__hidden__.CacheAction import com.github.klee0kai.stone.__hidden__.IModule From 84f4f1cc896048b5f6b8984cbff7d45270116497 Mon Sep 17 00:00:00 2001 From: klee0kai Date: Sun, 14 Dec 2025 19:30:55 +0100 Subject: [PATCH 067/122] module init from class not supporting. remove useless tests --- .../test/moduleinit/BeginOfBegins2Tests.kt | 21 ------------------- .../test/moduleinit/BeginOfBeginsTests.kt | 18 ---------------- 2 files changed, 39 deletions(-) diff --git a/tests/src/test/java/com/github/klee0kai/stone/test/moduleinit/BeginOfBegins2Tests.kt b/tests/src/test/java/com/github/klee0kai/stone/test/moduleinit/BeginOfBegins2Tests.kt index 1a937a0f..79a5afba 100644 --- a/tests/src/test/java/com/github/klee0kai/stone/test/moduleinit/BeginOfBegins2Tests.kt +++ b/tests/src/test/java/com/github/klee0kai/stone/test/moduleinit/BeginOfBegins2Tests.kt @@ -30,21 +30,6 @@ class BeginOfBegins2Tests { assertEquals(earth, DI.united().earth()) } - - @Test - fun initByFactoryClass() { - //Given - TODO("implement this") - val DI = ForestComponentStoneComponent() - - //When - DI.initUnitedModule(UnitedModuleFactory::class.java as UnitedModule?) - - //Then - assertEquals(earth, DI.united().earth()) - } - - @Test fun initAllModules() { //Given @@ -70,12 +55,6 @@ class BeginOfBegins2Tests { } - class UnitedModuleFactory : UnitedModule() { - override fun earth(): Earth = earth - - override fun history(): History? = null - } - companion object { private val earth: Earth = Earth() private val ideology: Ideology = Ideology() diff --git a/tests/src/test/java/com/github/klee0kai/stone/test/moduleinit/BeginOfBeginsTests.kt b/tests/src/test/java/com/github/klee0kai/stone/test/moduleinit/BeginOfBeginsTests.kt index 7bd9e3c9..a2f6de64 100644 --- a/tests/src/test/java/com/github/klee0kai/stone/test/moduleinit/BeginOfBeginsTests.kt +++ b/tests/src/test/java/com/github/klee0kai/stone/test/moduleinit/BeginOfBeginsTests.kt @@ -25,24 +25,6 @@ class BeginOfBeginsTests { assertEquals(earth, DI.united().earth()) } - - @Test - fun initByFactoryClass() { - //Given - val DI = ForestComponentStoneComponent() - - //When - DI.initUnitedModule(UnitedModuleFactory::class.java as UnitedModule?) - - //Then - assertEquals(earth, DI.united().earth()) - } - - class UnitedModuleFactory : UnitedModule() { - override fun earth(): Earth = earth - override fun history(): History? = null - } - companion object { private val earth: Earth = Earth() } From 34ee067c1813520dd52947445f70452131d38b84 Mon Sep 17 00:00:00 2001 From: klee0kai Date: Sun, 14 Dec 2025 20:25:07 +0100 Subject: [PATCH 068/122] tests at tests_kotlin gradle module --- .../stone/ksp/helpers/wrap/FormatSimple.kt | 1 + .../stone/ksp/helpers/wrap/WrapHelper.kt | 102 ++++++++++++++---- .../target/component/GenComponentProcessor.kt | 7 +- .../stone/wrappers/KotlinWrappersStone.kt | 25 +++++ .../klee0kai/stone/wrappers/LazyProvide.kt | 6 +- .../klee0kai/stone/wrappers/PhantomProvide.kt | 6 +- .../klee0kai/stone/wrappers/WrappersExt.kt | 6 ++ .../stone/wrappers/WrappersExt.jvm.kt | 10 ++ .../test_kotlin/tech/ComputerStore.kt | 5 +- .../test_kotlin/tech/comp/DesktopComp.kt | 4 +- .../definterface/DefInterfaceTest.kt | 9 +- .../MonitorFactoryWrappersTests.kt | 51 ++++----- .../inject/GorillaInjectTests.kt | 10 +- .../inject/GorillaInjectWrappersTests.kt | 13 ++- .../inject/GorillaProtectInjectTests.kt | 7 +- .../GorillaProtectInjectWrappersTests.kt | 7 +- .../InterfaceDelegatesTest.kt | 9 +- .../lifecycle/DeskCompRepairTest.kt | 1 + .../lifecycle/GameCompRepairTest.kt | 1 + 19 files changed, 188 insertions(+), 92 deletions(-) create mode 100644 stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/wrappers/KotlinWrappersStone.kt create mode 100644 stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/wrappers/WrappersExt.kt create mode 100644 stone_multiplatform/src/jvmMain/kotlin/com/github/klee0kai/stone/wrappers/WrappersExt.jvm.kt diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/wrap/FormatSimple.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/wrap/FormatSimple.kt index 71ae517a..9d523339 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/wrap/FormatSimple.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/wrap/FormatSimple.kt @@ -11,5 +11,6 @@ fun interface FormatSimple { */ fun formatCode( or: CodeBlock, + nullable: Boolean, ): CodeBlock } diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/wrap/WrapHelper.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/wrap/WrapHelper.kt index 390cbb5a..63e74c84 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/wrap/WrapHelper.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/wrap/WrapHelper.kt @@ -7,6 +7,7 @@ import com.github.klee0kai.stone.wrappers.PhantomProvide import com.github.klee0kai.thekey.stone.ksp.exceptions.StoneException import com.github.klee0kai.thekey.stone.ksp.helpers.wrap.ClassNameUtils.noWildCardType import com.github.klee0kai.thekey.stone.ksp.helpers.wrap.ClassNameUtils.rawTypeOf +import com.github.klee0kai.thekey.stone.ksp.poet.codeBlock import com.squareup.kotlinpoet.* import com.squareup.kotlinpoet.ParameterizedTypeName.Companion.parameterizedBy import java.lang.ref.Reference @@ -138,7 +139,7 @@ class WrapHelper { codeBuilder = wrapListType.inListFormat!!.formatCode( originalListType = unwrapType.typeName, or = codeBuilder.build(), - itemTransformFun = { listItemCode -> + itemTransformFun = { listItemCode, nullable -> transform(unWrapItemType, wrapItemType, listItemCode) } ).toBuilder() @@ -152,7 +153,7 @@ class WrapHelper { break } } - codeBuilder = unwrapType.unwrap.formatCode(codeBuilder.build()) + codeBuilder = unwrapType.unwrap.formatCode(codeBuilder.build(), unwrapType.typeName.isNullable) .toBuilder() unwrapPath.pollFirst() @@ -160,12 +161,15 @@ class WrapHelper { } while (!wrapPath.isEmpty()) { - codeBuilder = wrapPath[0].wrap.formatCode(codeBuilder.build()) + codeBuilder = wrapPath[0].wrap.formatCode(codeBuilder.build(), wrapPath[0].typeName.isNullable) .toBuilder() wrapPath.pollFirst() wrapPathNames.pollFirst() } + if (!wannaType.isNullable) { + codeBuilder.add("!!") + } return codeBuilder.build() } @@ -182,20 +186,61 @@ class WrapHelper { val wrapType = WrapType( typeName = wrapper, isNoCachingWrapper = false, - wrap = { or -> - CodeBlock.builder() - .add("%L?.let{ %T(it) }", or, creator) - .build() + wrap = { or, nullable -> + codeBlock { + if (nullable) { + add("%T( %L )", creator, or) + } else { + add("%T( %L!! )", creator, or) + } + } }, - unwrap = { or -> - CodeBlock.builder() - .add("%L?.get()", or) - .build() + unwrap = { or, nullable -> + codeBlock { + if (nullable) { + add("%L?.get()", or) + } else { + add("%L!!.get()", or) + } + } } ) support(wrapType) } + for (cl in listOf( + Lazy::class, + )) { + val wrapper = cl.asClassName() + val wrapType = WrapType( + typeName = wrapper, + isNoCachingWrapper = false, + isAsyncProvider = true, + wrap = { or, nullable -> + if (nullable) { + CodeBlock.of( + "lazy{ %L } ", + or, + ) + } else { + CodeBlock.of( + "lazy{ %L!! } ", + or, + ) + } + + }, + unwrap = { or, nullable -> + if (nullable) { + CodeBlock.of("%L?.value", or) + } else { + CodeBlock.of("%L!!.value", or) + } + }, + ) + support(wrapType) + } + for (cl in listOf( PhantomProvide::class, Ref::class, @@ -210,14 +255,29 @@ class WrapHelper { typeName = wrapper, isNoCachingWrapper = isNoCachingWrapper, isAsyncProvider = true, - wrap = { or -> - CodeBlock.of( - "%T{ %L } ", - wrapper, - or, - ) + wrap = { or, nullable -> + if (nullable) { + CodeBlock.of( + "%T{ %L } ", + wrapper, + or, + ) + } else { + CodeBlock.of( + "%T{ %L!! } ", + wrapper, + or, + ) + } + + }, + unwrap = { or, nullable -> + if (nullable) { + CodeBlock.of("%L?.get()", or) + } else { + CodeBlock.of("%L!!.get()", or) + } }, - unwrap = { or -> CodeBlock.of("%L?.get()", or) }, ) support(wrapType) } @@ -230,13 +290,13 @@ class WrapHelper { val wrapType = WrapType( typeName = wrapper, - wrap = { or -> + wrap = { or, nullable -> val builder = CodeBlock.builder() builder.add("listOfNotNull( %L ) ", or) if (needConstructor) builder.add(".let { %T(it) }", createType) builder.build() }, - unwrap = { or -> + unwrap = { or, nullable -> CodeBlock.builder() .add("%L.first( %L )", or) .build() @@ -246,7 +306,7 @@ class WrapHelper { val isListNeedConstructor = needConstructor && rawTypeOf(wrapper) != rawTypeOf(originalListType) - val itemTransform = itemTransformFun.formatCode(CodeBlock.of("it")) + val itemTransform = itemTransformFun.formatCode(CodeBlock.of("it"), nullable = false) if (itemTransform.toString() == "it") { //no transforms builder.add(originalListCode) diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/component/GenComponentProcessor.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/component/GenComponentProcessor.kt index 9ec71e5b..b563ed03 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/component/GenComponentProcessor.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/component/GenComponentProcessor.kt @@ -340,8 +340,11 @@ class GenComponentProcessor : TargetFileProcessor { ) val isListCache = wrapHelper.isList(cacheControlInvoke!!.rawReturnType()) - val cacheControlType = if (isListCache) List::class.asClassName().parameterizedBy(nonWrappedBindType) - else nonWrappedBindType + val cacheControlType = if (isListCache) { + List::class.asClassName().parameterizedBy(nonWrappedBindType).copy(nullable = true) + } else { + nonWrappedBindType.copy(nullable = true) + } // bind object declared in module genOverrideFun(method) { diff --git a/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/wrappers/KotlinWrappersStone.kt b/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/wrappers/KotlinWrappersStone.kt new file mode 100644 index 00000000..15e42b06 --- /dev/null +++ b/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/wrappers/KotlinWrappersStone.kt @@ -0,0 +1,25 @@ +package com.github.klee0kai.stone.wrappers + +import com.github.klee0kai.stone.annotations.wrappers.WrappersCreator +import com.github.klee0kai.stone.weakref.Provider +import com.github.klee0kai.stone.wrappers.creators.ProviderWrapper +import kotlin.reflect.KClass + +@WrappersCreator( + wrappers = [ + Lazy::class, + ] +) +open class KotlinWrappersStone : ProviderWrapper { + + override fun wrap( + wrapperCl: KClass?, + originalProvider: Provider? + ): Wr? { + return when { + wrapperCl == Lazy::class -> lazy { originalProvider?.get() } as Wr + else -> null + } + } + +} \ No newline at end of file diff --git a/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/wrappers/LazyProvide.kt b/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/wrappers/LazyProvide.kt index 7497b250..b6895c0d 100644 --- a/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/wrappers/LazyProvide.kt +++ b/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/wrappers/LazyProvide.kt @@ -13,12 +13,12 @@ import com.github.klee0kai.stone.weakref.Ref * } ` * */ -class LazyProvide(private val call: Ref) : Ref { +class LazyProvide(private val call: Ref) : Ref { private var value: T? = null - override fun get(): T? { - if (value != null) return value + override fun get(): T { + value?.let { return it } return call.get().also { value = it } } diff --git a/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/wrappers/PhantomProvide.kt b/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/wrappers/PhantomProvide.kt index 1695835a..5799a649 100644 --- a/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/wrappers/PhantomProvide.kt +++ b/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/wrappers/PhantomProvide.kt @@ -18,10 +18,8 @@ import com.github.klee0kai.stone.weakref.Ref * } ` * */ -class PhantomProvide(private val call: Ref) : Ref { +class PhantomProvide(private val call: Ref) : Ref { - override fun get(): T? { - return call.get() - } + override fun get(): T = call.get() } diff --git a/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/wrappers/WrappersExt.kt b/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/wrappers/WrappersExt.kt new file mode 100644 index 00000000..76afb5d3 --- /dev/null +++ b/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/wrappers/WrappersExt.kt @@ -0,0 +1,6 @@ +package com.github.klee0kai.stone.wrappers + +import com.github.klee0kai.stone.weakref.Ref +import kotlin.reflect.KProperty + +operator fun Ref.getValue(t: Any?, property: KProperty<*>): T = get()!! diff --git a/stone_multiplatform/src/jvmMain/kotlin/com/github/klee0kai/stone/wrappers/WrappersExt.jvm.kt b/stone_multiplatform/src/jvmMain/kotlin/com/github/klee0kai/stone/wrappers/WrappersExt.jvm.kt new file mode 100644 index 00000000..fb12979a --- /dev/null +++ b/stone_multiplatform/src/jvmMain/kotlin/com/github/klee0kai/stone/wrappers/WrappersExt.jvm.kt @@ -0,0 +1,10 @@ +package com.github.klee0kai.stone.wrappers + +import java.lang.ref.SoftReference +import java.lang.ref.WeakReference +import kotlin.reflect.KProperty + +operator fun SoftReference.getValue(t: Any?, property: KProperty<*>): T? = get() + +operator fun WeakReference.getValue(t: Any?, property: KProperty<*>): T? = get() + diff --git a/tests_kotlin/src/main/kotlin/com/github/klee0kai/test_kotlin/tech/ComputerStore.kt b/tests_kotlin/src/main/kotlin/com/github/klee0kai/test_kotlin/tech/ComputerStore.kt index 20c42a87..81a4b873 100644 --- a/tests_kotlin/src/main/kotlin/com/github/klee0kai/test_kotlin/tech/ComputerStore.kt +++ b/tests_kotlin/src/main/kotlin/com/github/klee0kai/test_kotlin/tech/ComputerStore.kt @@ -1,11 +1,12 @@ package com.github.klee0kai.test_kotlin.tech import com.github.klee0kai.test_kotlin.di.base_comp.CompComponent +import com.github.klee0kai.test_kotlin.di.base_comp.CompComponentStoneComponent object ComputerStore { - var DI: CompComponent = TODO("Stone.createComponent(CompComponent::class.java)") + var DI: CompComponent = CompComponentStoneComponent() fun recreate() { - DI = TODO("Stone.createComponent(CompComponent::class.java)") + DI = CompComponentStoneComponent() } } \ No newline at end of file diff --git a/tests_kotlin/src/main/kotlin/com/github/klee0kai/test_kotlin/tech/comp/DesktopComp.kt b/tests_kotlin/src/main/kotlin/com/github/klee0kai/test_kotlin/tech/comp/DesktopComp.kt index daf45e43..67b3d16c 100644 --- a/tests_kotlin/src/main/kotlin/com/github/klee0kai/test_kotlin/tech/comp/DesktopComp.kt +++ b/tests_kotlin/src/main/kotlin/com/github/klee0kai/test_kotlin/tech/comp/DesktopComp.kt @@ -32,13 +32,13 @@ class DesktopComp( ComputerStore.DI.inject(this, monitorSize, monCompany, kConnectType) } - override fun subscribe(listener: StoneLifeCycleListener?) { + override fun subscribe(listener: StoneLifeCycleListener) { super.subscribe(object : ATechLifecycle { override fun onBuy() = Unit override fun onBroken() = Unit override fun onDrown() { - listener?.protectForInjected(100) + listener.protectForInjected(100) } }) } diff --git a/tests_kotlin/src/test/kotlin/com/github/klee0kai/tests/kotlin_models/definterface/DefInterfaceTest.kt b/tests_kotlin/src/test/kotlin/com/github/klee0kai/tests/kotlin_models/definterface/DefInterfaceTest.kt index 24d77567..a3745cc6 100644 --- a/tests_kotlin/src/test/kotlin/com/github/klee0kai/tests/kotlin_models/definterface/DefInterfaceTest.kt +++ b/tests_kotlin/src/test/kotlin/com/github/klee0kai/tests/kotlin_models/definterface/DefInterfaceTest.kt @@ -1,9 +1,8 @@ package com.github.klee0kai.tests.kotlin_models.definterface -import com.github.klee0kai.stone.Stone import com.github.klee0kai.test_kotlin.di.base_comp.identifiers.KConnectType import com.github.klee0kai.test_kotlin.di.base_comp.identifiers.MonitorSize -import com.github.klee0kai.test_kotlin.di.definterface.DefInterfaceComponent +import com.github.klee0kai.test_kotlin.di.definterface.DefInterfaceComponentStoneComponent import org.junit.jupiter.api.Assertions.* import org.junit.jupiter.api.Test @@ -12,7 +11,7 @@ class DefInterfaceTest { @Test fun provideKeyboardTest() { //Given - val DI = Stone.createComponent(DefInterfaceComponent::class.java) + val DI = DefInterfaceComponentStoneComponent() //When val keyboard1 = DI.factory().keyboard() @@ -33,7 +32,7 @@ class DefInterfaceTest { @Test fun provideMonitorTest() { //Given - val DI = Stone.createComponent(DefInterfaceComponent::class.java) + val DI = DefInterfaceComponentStoneComponent() //When val monitor = DI.factory().monitor(MonitorSize("2")) @@ -47,7 +46,7 @@ class DefInterfaceTest { @Test fun provideMouseTest() { //Given - val DI = Stone.createComponent(DefInterfaceComponent::class.java) + val DI = DefInterfaceComponentStoneComponent() //When val mouse1 = DI.factory().mouse() diff --git a/tests_kotlin/src/test/kotlin/com/github/klee0kai/tests/kotlin_models/identifiers/MonitorFactoryWrappersTests.kt b/tests_kotlin/src/test/kotlin/com/github/klee0kai/tests/kotlin_models/identifiers/MonitorFactoryWrappersTests.kt index ffc54609..717a1bfd 100644 --- a/tests_kotlin/src/test/kotlin/com/github/klee0kai/tests/kotlin_models/identifiers/MonitorFactoryWrappersTests.kt +++ b/tests_kotlin/src/test/kotlin/com/github/klee0kai/tests/kotlin_models/identifiers/MonitorFactoryWrappersTests.kt @@ -1,9 +1,7 @@ package com.github.klee0kai.tests.kotlin_models.identifiers -import com.github.klee0kai.stone.Stone -import com.github.klee0kai.stone.type.wrappers.getValue -import com.github.klee0kai.stone.weakref.Ref -import com.github.klee0kai.test_kotlin.di.compfactory.CompFactoryComponent +import com.github.klee0kai.stone.wrappers.getValue +import com.github.klee0kai.test_kotlin.di.compfactory.CompFactoryComponentStoneComponent import com.github.klee0kai.test_kotlin.tech.components.Monitor import org.junit.jupiter.api.Assertions.* import org.junit.jupiter.api.Test @@ -14,10 +12,10 @@ class MonitorFactoryWrappersTests { @Test fun lazyProvideTest() { //Given - val DI = Stone.createComponent(CompFactoryComponent::class.java) + val DI = CompFactoryComponentStoneComponent() //When - val monitor: Ref = DI.monitorLazy() + val monitor = DI.monitorLazy() //Then assertEquals( @@ -30,7 +28,7 @@ class MonitorFactoryWrappersTests { @Test fun softRefProvideTest() { //Given - val DI = Stone.createComponent(CompFactoryComponent::class.java) + val DI = CompFactoryComponentStoneComponent() //When val monitor: Reference = DI.monitorSoft() @@ -42,7 +40,7 @@ class MonitorFactoryWrappersTests { @Test fun weakRefProvideTest() { //Given - val DI = Stone.createComponent(CompFactoryComponent::class.java) + val DI = CompFactoryComponentStoneComponent() //When val monitor: Reference = DI.monitorWeak() @@ -54,10 +52,10 @@ class MonitorFactoryWrappersTests { @Test fun phantom1ProvideTest() { //Given - val DI = Stone.createComponent(CompFactoryComponent::class.java) + val DI = CompFactoryComponentStoneComponent() //When - val monitor: Ref = DI.monitorPhantomProvide() + val monitor = DI.monitorPhantomProvide() //Then assertNotEquals( @@ -69,22 +67,22 @@ class MonitorFactoryWrappersTests { @Test fun phantomProvideTest() { //Given - val DI = Stone.createComponent(CompFactoryComponent::class.java) + val DI = CompFactoryComponentStoneComponent() //When - val monitor: Ref = DI.monitorPhantomProvide() + val monitor = DI.monitorPhantomProvide() //Then assertNotEquals( monitor.get().uuid, - monitor.get().uuid + monitor.get().uuid, ) } @Test fun phantom3ProvideTest() { //Given - val DI = Stone.createComponent(CompFactoryComponent::class.java) + val DI = CompFactoryComponentStoneComponent() //When val monitor = DI.monitorProviderIRef() @@ -100,7 +98,7 @@ class MonitorFactoryWrappersTests { @Test fun kotlinLazyProvideTest() { //Given - val DI = Stone.createComponent(CompFactoryComponent::class.java) + val DI = CompFactoryComponentStoneComponent() //When val monitor = DI.monitorLazyDelegate() @@ -113,19 +111,18 @@ class MonitorFactoryWrappersTests { } - @Test fun lazyDelegateTest() { //Given - val DI = Stone.createComponent(CompFactoryComponent::class.java) + val DI = CompFactoryComponentStoneComponent() //When val monitor by DI.monitorLazy() //Then assertEquals( - monitor.uuid, - monitor.uuid + monitor!!.uuid, + monitor!!.uuid ) } @@ -133,7 +130,7 @@ class MonitorFactoryWrappersTests { @Test fun softRefDelegateTest() { //Given - val DI = Stone.createComponent(CompFactoryComponent::class.java) + val DI = CompFactoryComponentStoneComponent() //When val monitor by DI.monitorSoft() @@ -145,7 +142,7 @@ class MonitorFactoryWrappersTests { @Test fun weakRefDelegateTest() { //Given - val DI = Stone.createComponent(CompFactoryComponent::class.java) + val DI = CompFactoryComponentStoneComponent() //When val monitor by DI.monitorWeak() @@ -157,7 +154,7 @@ class MonitorFactoryWrappersTests { @Test fun phantom1DelegateTest() { //Given - val DI = Stone.createComponent(CompFactoryComponent::class.java) + val DI = CompFactoryComponentStoneComponent() //When val monitor by DI.monitorPhantomProvide() @@ -172,10 +169,10 @@ class MonitorFactoryWrappersTests { @Test fun phantom2DelegateTest() { //Given - val DI = Stone.createComponent(CompFactoryComponent::class.java) + val DI = CompFactoryComponentStoneComponent() //When - val monitor by DI.monitorPhantomProvide() + val monitor: Monitor by DI.monitorPhantomProvide() //Then assertNotEquals( @@ -187,7 +184,7 @@ class MonitorFactoryWrappersTests { @Test fun phantom3DelegateTest() { //Given - val DI = Stone.createComponent(CompFactoryComponent::class.java) + val DI = CompFactoryComponentStoneComponent() //When val monitor by DI.monitorProviderIRef() @@ -203,7 +200,7 @@ class MonitorFactoryWrappersTests { @Test fun kotlinLazyDelegateTest() { //Given - val DI = Stone.createComponent(CompFactoryComponent::class.java) + val DI = CompFactoryComponentStoneComponent() //When val monitor by DI.monitorLazyDelegate() @@ -216,8 +213,6 @@ class MonitorFactoryWrappersTests { } - - } diff --git a/tests_kotlin/src/test/kotlin/com/github/klee0kai/tests/kotlin_models/inject/GorillaInjectTests.kt b/tests_kotlin/src/test/kotlin/com/github/klee0kai/tests/kotlin_models/inject/GorillaInjectTests.kt index cf864513..3ae3226c 100644 --- a/tests_kotlin/src/test/kotlin/com/github/klee0kai/tests/kotlin_models/inject/GorillaInjectTests.kt +++ b/tests_kotlin/src/test/kotlin/com/github/klee0kai/tests/kotlin_models/inject/GorillaInjectTests.kt @@ -1,7 +1,6 @@ package com.github.klee0kai.tests.kotlin_models.inject -import com.github.klee0kai.stone.Stone -import com.github.klee0kai.test_kotlin.di.base_forest.RainForestComponent +import com.github.klee0kai.test_kotlin.di.base_forest.RainForestComponentStoneComponent import com.github.klee0kai.test_kotlin.mowgli.animal.Cougar import com.github.klee0kai.test_kotlin.mowgli.animal.Gorilla import org.junit.jupiter.api.Assertions.* @@ -12,7 +11,7 @@ class GorillaInjectTests { @Test fun gorillaBornTest() { //Given - val DI = Stone.createComponent(RainForestComponent::class.java) + val DI = RainForestComponentStoneComponent() val gorilla = Gorilla() @@ -28,7 +27,7 @@ class GorillaInjectTests { @Test fun oneBloodTest() { //Given - val DI = Stone.createComponent(RainForestComponent::class.java) + val DI = RainForestComponentStoneComponent() val gorilla = Gorilla() val cougar = Cougar() @@ -48,7 +47,7 @@ class GorillaInjectTests { @Test fun personalityTest() { //Given - val DI = Stone.createComponent(RainForestComponent::class.java) + val DI = RainForestComponentStoneComponent() val gorilla = Gorilla() val cougar = Cougar() @@ -63,4 +62,5 @@ class GorillaInjectTests { cougar.conscience!!.uuid ) } + } \ No newline at end of file diff --git a/tests_kotlin/src/test/kotlin/com/github/klee0kai/tests/kotlin_models/inject/GorillaInjectWrappersTests.kt b/tests_kotlin/src/test/kotlin/com/github/klee0kai/tests/kotlin_models/inject/GorillaInjectWrappersTests.kt index 41656089..271a0979 100644 --- a/tests_kotlin/src/test/kotlin/com/github/klee0kai/tests/kotlin_models/inject/GorillaInjectWrappersTests.kt +++ b/tests_kotlin/src/test/kotlin/com/github/klee0kai/tests/kotlin_models/inject/GorillaInjectWrappersTests.kt @@ -1,7 +1,6 @@ package com.github.klee0kai.tests.kotlin_models.inject -import com.github.klee0kai.stone.Stone -import com.github.klee0kai.test_kotlin.di.base_forest.RainForestComponent +import com.github.klee0kai.test_kotlin.di.base_forest.RainForestComponentStoneComponent import com.github.klee0kai.test_kotlin.mowgli.animal.Gorilla import org.junit.jupiter.api.Assertions.* import org.junit.jupiter.api.Test @@ -11,7 +10,7 @@ class GorillaInjectWrappersTests { @Test fun supportWrappersTest() { //Given - val DI = Stone.createComponent(RainForestComponent::class.java) + val DI = RainForestComponentStoneComponent() val gorilla = Gorilla() //When @@ -31,7 +30,7 @@ class GorillaInjectWrappersTests { @Test fun refWrapperTest() { //Given - val DI = Stone.createComponent(RainForestComponent::class.java) + val DI = RainForestComponentStoneComponent() val gorilla = Gorilla() //When @@ -56,7 +55,7 @@ class GorillaInjectWrappersTests { @Test fun genWrapperTest() { //Given - val DI = Stone.createComponent(RainForestComponent::class.java) + val DI = RainForestComponentStoneComponent() var gorilla = Gorilla() //When @@ -64,8 +63,8 @@ class GorillaInjectWrappersTests { //Then assertNotEquals( - gorilla.knowledgePhantomProvide!!.get().uuid, - gorilla.knowledgePhantomProvide!!.get().uuid + gorilla.knowledgePhantomProvide!!.get()!!.uuid, + gorilla.knowledgePhantomProvide!!.get()!!.uuid ) assertNotEquals( gorilla.knowledgePhantomProvide2!!.get().uuid, diff --git a/tests_kotlin/src/test/kotlin/com/github/klee0kai/tests/kotlin_models/inject/GorillaProtectInjectTests.kt b/tests_kotlin/src/test/kotlin/com/github/klee0kai/tests/kotlin_models/inject/GorillaProtectInjectTests.kt index 59538b92..569e7041 100644 --- a/tests_kotlin/src/test/kotlin/com/github/klee0kai/tests/kotlin_models/inject/GorillaProtectInjectTests.kt +++ b/tests_kotlin/src/test/kotlin/com/github/klee0kai/tests/kotlin_models/inject/GorillaProtectInjectTests.kt @@ -1,7 +1,6 @@ package com.github.klee0kai.tests.kotlin_models.inject -import com.github.klee0kai.stone.Stone -import com.github.klee0kai.test_kotlin.di.base_forest.RainForestComponent +import com.github.klee0kai.test_kotlin.di.base_forest.RainForestComponentStoneComponent import com.github.klee0kai.test_kotlin.mowgli.animal.Gorilla import org.junit.jupiter.api.Assertions.assertNotNull import org.junit.jupiter.api.Assertions.assertNull @@ -13,7 +12,7 @@ class GorillaProtectInjectTests { @Test fun withoutProtectInjectTest() { // Given - val DI = Stone.createComponent(RainForestComponent::class.java) + val DI = RainForestComponentStoneComponent() var gorilla: Gorilla? = Gorilla() @@ -32,7 +31,7 @@ class GorillaProtectInjectTests { @Throws(InterruptedException::class) fun withProtectInjectTest() { // Given - val DI = Stone.createComponent(RainForestComponent::class.java) + val DI = RainForestComponentStoneComponent() var gorrila: Gorilla? = Gorilla() diff --git a/tests_kotlin/src/test/kotlin/com/github/klee0kai/tests/kotlin_models/inject/GorillaProtectInjectWrappersTests.kt b/tests_kotlin/src/test/kotlin/com/github/klee0kai/tests/kotlin_models/inject/GorillaProtectInjectWrappersTests.kt index 552d3f14..8e8477a5 100644 --- a/tests_kotlin/src/test/kotlin/com/github/klee0kai/tests/kotlin_models/inject/GorillaProtectInjectWrappersTests.kt +++ b/tests_kotlin/src/test/kotlin/com/github/klee0kai/tests/kotlin_models/inject/GorillaProtectInjectWrappersTests.kt @@ -1,7 +1,6 @@ package com.github.klee0kai.tests.kotlin_models.inject -import com.github.klee0kai.stone.Stone -import com.github.klee0kai.test_kotlin.di.base_forest.RainForestComponent +import com.github.klee0kai.test_kotlin.di.base_forest.RainForestComponentStoneComponent import com.github.klee0kai.test_kotlin.mowgli.University import com.github.klee0kai.test_kotlin.mowgli.animal.Gorilla import org.junit.jupiter.api.Assertions.assertNotNull @@ -14,7 +13,7 @@ class GorillaProtectInjectWrappersTests { @Test fun lazyWrapperProtectTest() { // Given - val DI = Stone.createComponent(RainForestComponent::class.java) + val DI = RainForestComponentStoneComponent() val university = University() @@ -33,7 +32,7 @@ class GorillaProtectInjectWrappersTests { @Throws(InterruptedException::class) fun withProtectInjectTest() { // Given - val DI = Stone.createComponent(RainForestComponent::class.java) + val DI = RainForestComponentStoneComponent() var gorilla: Gorilla? = Gorilla() //When diff --git a/tests_kotlin/src/test/kotlin/com/github/klee0kai/tests/kotlin_models/interface_delegates/InterfaceDelegatesTest.kt b/tests_kotlin/src/test/kotlin/com/github/klee0kai/tests/kotlin_models/interface_delegates/InterfaceDelegatesTest.kt index 83d9126e..05c8e191 100644 --- a/tests_kotlin/src/test/kotlin/com/github/klee0kai/tests/kotlin_models/interface_delegates/InterfaceDelegatesTest.kt +++ b/tests_kotlin/src/test/kotlin/com/github/klee0kai/tests/kotlin_models/interface_delegates/InterfaceDelegatesTest.kt @@ -1,9 +1,8 @@ package com.github.klee0kai.tests.kotlin_models.interface_delegates -import com.github.klee0kai.stone.Stone import com.github.klee0kai.test_kotlin.di.base_comp.identifiers.KConnectType import com.github.klee0kai.test_kotlin.di.base_comp.identifiers.MonitorSize -import com.github.klee0kai.test_kotlin.di.interface_delegates.InterfaceDelegatesComponent +import com.github.klee0kai.test_kotlin.di.interface_delegates.InterfaceDelegatesComponentStoneComponent import org.junit.jupiter.api.Assertions.* import org.junit.jupiter.api.Test @@ -12,7 +11,7 @@ class InterfaceDelegatesTest { @Test fun provideKeyboardTest() { //Given - val DI = Stone.createComponent(InterfaceDelegatesComponent::class.java) + val DI = InterfaceDelegatesComponentStoneComponent() //When val keyboard1 = DI.factory().keyboard() @@ -33,7 +32,7 @@ class InterfaceDelegatesTest { @Test fun provideMonitorTest() { //Given - val DI = Stone.createComponent(InterfaceDelegatesComponent::class.java) + val DI = InterfaceDelegatesComponentStoneComponent() //When val monitor = DI.factory().monitor(MonitorSize("2")) @@ -47,7 +46,7 @@ class InterfaceDelegatesTest { @Test fun provideMouseTest() { //Given - val DI = Stone.createComponent(InterfaceDelegatesComponent::class.java) + val DI = InterfaceDelegatesComponentStoneComponent() //When val mouse1 = DI.factory().mouse() diff --git a/tests_kotlin/src/test/kotlin/com/github/klee0kai/tests/kotlin_models/lifecycle/DeskCompRepairTest.kt b/tests_kotlin/src/test/kotlin/com/github/klee0kai/tests/kotlin_models/lifecycle/DeskCompRepairTest.kt index 40e93531..c389efa0 100644 --- a/tests_kotlin/src/test/kotlin/com/github/klee0kai/tests/kotlin_models/lifecycle/DeskCompRepairTest.kt +++ b/tests_kotlin/src/test/kotlin/com/github/klee0kai/tests/kotlin_models/lifecycle/DeskCompRepairTest.kt @@ -1,5 +1,6 @@ package com.github.klee0kai.tests.kotlin_models.lifecycle +import com.github.klee0kai.test_kotlin.tech.ComputerStore import com.github.klee0kai.test_kotlin.tech.comp.DesktopComp import org.junit.jupiter.api.Assertions.* import org.junit.jupiter.api.Test diff --git a/tests_kotlin/src/test/kotlin/com/github/klee0kai/tests/kotlin_models/lifecycle/GameCompRepairTest.kt b/tests_kotlin/src/test/kotlin/com/github/klee0kai/tests/kotlin_models/lifecycle/GameCompRepairTest.kt index d07a57ce..5acf6ad9 100644 --- a/tests_kotlin/src/test/kotlin/com/github/klee0kai/tests/kotlin_models/lifecycle/GameCompRepairTest.kt +++ b/tests_kotlin/src/test/kotlin/com/github/klee0kai/tests/kotlin_models/lifecycle/GameCompRepairTest.kt @@ -1,5 +1,6 @@ package com.github.klee0kai.tests.kotlin_models.lifecycle +import com.github.klee0kai.test_kotlin.tech.ComputerStore import com.github.klee0kai.test_kotlin.tech.comp.GameComp import org.junit.jupiter.api.Assertions.* import org.junit.jupiter.api.Test From fd43452232844d50b26d3a6ac444815b310ca2f9 Mon Sep 17 00:00:00 2001 From: klee0kai Date: Sun, 14 Dec 2025 21:17:56 +0100 Subject: [PATCH 069/122] Rename .java to .kt --- .../base_phone/{PhoneExtComponent.java => PhoneExtComponent.kt} | 0 .../inject/di/base_phone/{TechExtModule.java => TechExtModule.kt} | 0 .../{GodRebrandingComponent.java => GodRebrandingComponent.kt} | 0 ...unSystemRebrandingModule.java => SunSystemRebrandingModule.kt} | 0 .../{ExtPlanetComponent.java => ExtPlanetComponent.kt} | 0 .../{PlanetSputnikComponent.java => PlanetSputnikComponent.kt} | 0 .../bindinstance/singlemethod/{StarModule.java => StarModule.kt} | 0 ...xtPlanetRollingComponent.java => ExtPlanetRollingComponent.kt} | 0 .../inject/di/forest/{DiseasesModule.java => DiseasesModule.kt} | 0 .../di/forest/{OldForestComponent.java => OldForestComponent.kt} | 0 .../di/forest/{OldIdentityModule.java => OldIdentityModule.kt} | 0 .../di/gcforest/{GcEarthExtModule.java => GcEarthExtModule.kt} | 0 .../di/gcforest/{GcGodExtComponent.java => GcGodExtComponent.kt} | 0 .../{GcSunSystemExtModule.java => GcSunSystemExtModule.kt} | 0 .../{IGcEarthExtComponent.java => IGcEarthExtComponent.kt} | 0 .../inject/di/gcscopes/{GcSiriusScope.java => GcSiriusScope.kt} | 0 .../inject/di/gcscopes/{GcSputnikScope.java => GcSputnikScope.kt} | 0 .../{SwitchCacheExtComponent.java => SwitchCacheExtComponent.kt} | 0 ...TechProviderExtComponent.java => ITechProviderExtComponent.kt} | 0 .../{TechFactoryExtComponent.java => TechFactoryExtComponent.kt} | 0 .../{TechFactoryExtModule.java => TechFactoryExtModule.kt} | 0 .../di/techfactory/identifiers/{Frequency.java => Frequency.kt} | 0 .../test_ext/inject/mowgli/animal/{OldHorse.java => OldHorse.kt} | 0 .../mowgli/diseases/{Osteoarthritis.java => Osteoarthritis.kt} | 0 .../klee0kai/test_ext/inject/mowgli/earth/{Bay.java => Bay.kt} | 0 .../test_ext/inject/mowgli/earth/{Desert.java => Desert.kt} | 0 .../test_ext/inject/mowgli/earth/{WaterFlow.java => WaterFlow.kt} | 0 .../test_ext/inject/mowgli/galaxy/{Pluton.java => Pluton.kt} | 0 .../inject/mowgli/galaxy/sputniks/{Calypso.java => Calypso.kt} | 0 .../test_ext/inject/mowgli/galaxy/sputniks/{Moon.java => Moon.kt} | 0 .../inject/mowgli/galaxy/stars/{Sirius.java => Sirius.kt} | 0 .../mowgli/identity/{FamilyIdeology.java => FamilyIdeology.kt} | 0 .../inject/mowgli/identity/{OldKnowledge.java => OldKnowledge.kt} | 0 .../test_ext/inject/tech/components/{DDR3Ram.java => DDR3Ram.kt} | 0 34 files changed, 0 insertions(+), 0 deletions(-) rename tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/di/base_phone/{PhoneExtComponent.java => PhoneExtComponent.kt} (100%) rename tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/di/base_phone/{TechExtModule.java => TechExtModule.kt} (100%) rename tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/di/bindinstance/simple/{GodRebrandingComponent.java => GodRebrandingComponent.kt} (100%) rename tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/di/bindinstance/simple/{SunSystemRebrandingModule.java => SunSystemRebrandingModule.kt} (100%) rename tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/di/bindinstance/singlemethod/{ExtPlanetComponent.java => ExtPlanetComponent.kt} (100%) rename tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/di/bindinstance/singlemethod/{PlanetSputnikComponent.java => PlanetSputnikComponent.kt} (100%) rename tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/di/bindinstance/singlemethod/{StarModule.java => StarModule.kt} (100%) rename tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/di/bindinstance/singlemethod_gc/{ExtPlanetRollingComponent.java => ExtPlanetRollingComponent.kt} (100%) rename tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/di/forest/{DiseasesModule.java => DiseasesModule.kt} (100%) rename tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/di/forest/{OldForestComponent.java => OldForestComponent.kt} (100%) rename tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/di/forest/{OldIdentityModule.java => OldIdentityModule.kt} (100%) rename tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/di/gcforest/{GcEarthExtModule.java => GcEarthExtModule.kt} (100%) rename tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/di/gcforest/{GcGodExtComponent.java => GcGodExtComponent.kt} (100%) rename tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/di/gcforest/{GcSunSystemExtModule.java => GcSunSystemExtModule.kt} (100%) rename tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/di/gcforest/{IGcEarthExtComponent.java => IGcEarthExtComponent.kt} (100%) rename tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/di/gcscopes/{GcSiriusScope.java => GcSiriusScope.kt} (100%) rename tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/di/gcscopes/{GcSputnikScope.java => GcSputnikScope.kt} (100%) rename tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/di/swcache/{SwitchCacheExtComponent.java => SwitchCacheExtComponent.kt} (100%) rename tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/di/techfactory/{ITechProviderExtComponent.java => ITechProviderExtComponent.kt} (100%) rename tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/di/techfactory/{TechFactoryExtComponent.java => TechFactoryExtComponent.kt} (100%) rename tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/di/techfactory/{TechFactoryExtModule.java => TechFactoryExtModule.kt} (100%) rename tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/di/techfactory/identifiers/{Frequency.java => Frequency.kt} (100%) rename tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/mowgli/animal/{OldHorse.java => OldHorse.kt} (100%) rename tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/mowgli/diseases/{Osteoarthritis.java => Osteoarthritis.kt} (100%) rename tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/mowgli/earth/{Bay.java => Bay.kt} (100%) rename tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/mowgli/earth/{Desert.java => Desert.kt} (100%) rename tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/mowgli/earth/{WaterFlow.java => WaterFlow.kt} (100%) rename tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/mowgli/galaxy/{Pluton.java => Pluton.kt} (100%) rename tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/mowgli/galaxy/sputniks/{Calypso.java => Calypso.kt} (100%) rename tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/mowgli/galaxy/sputniks/{Moon.java => Moon.kt} (100%) rename tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/mowgli/galaxy/stars/{Sirius.java => Sirius.kt} (100%) rename tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/mowgli/identity/{FamilyIdeology.java => FamilyIdeology.kt} (100%) rename tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/mowgli/identity/{OldKnowledge.java => OldKnowledge.kt} (100%) rename tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/tech/components/{DDR3Ram.java => DDR3Ram.kt} (100%) diff --git a/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/di/base_phone/PhoneExtComponent.java b/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/di/base_phone/PhoneExtComponent.kt similarity index 100% rename from tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/di/base_phone/PhoneExtComponent.java rename to tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/di/base_phone/PhoneExtComponent.kt diff --git a/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/di/base_phone/TechExtModule.java b/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/di/base_phone/TechExtModule.kt similarity index 100% rename from tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/di/base_phone/TechExtModule.java rename to tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/di/base_phone/TechExtModule.kt diff --git a/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/di/bindinstance/simple/GodRebrandingComponent.java b/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/di/bindinstance/simple/GodRebrandingComponent.kt similarity index 100% rename from tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/di/bindinstance/simple/GodRebrandingComponent.java rename to tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/di/bindinstance/simple/GodRebrandingComponent.kt diff --git a/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/di/bindinstance/simple/SunSystemRebrandingModule.java b/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/di/bindinstance/simple/SunSystemRebrandingModule.kt similarity index 100% rename from tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/di/bindinstance/simple/SunSystemRebrandingModule.java rename to tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/di/bindinstance/simple/SunSystemRebrandingModule.kt diff --git a/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/di/bindinstance/singlemethod/ExtPlanetComponent.java b/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/di/bindinstance/singlemethod/ExtPlanetComponent.kt similarity index 100% rename from tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/di/bindinstance/singlemethod/ExtPlanetComponent.java rename to tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/di/bindinstance/singlemethod/ExtPlanetComponent.kt diff --git a/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/di/bindinstance/singlemethod/PlanetSputnikComponent.java b/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/di/bindinstance/singlemethod/PlanetSputnikComponent.kt similarity index 100% rename from tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/di/bindinstance/singlemethod/PlanetSputnikComponent.java rename to tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/di/bindinstance/singlemethod/PlanetSputnikComponent.kt diff --git a/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/di/bindinstance/singlemethod/StarModule.java b/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/di/bindinstance/singlemethod/StarModule.kt similarity index 100% rename from tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/di/bindinstance/singlemethod/StarModule.java rename to tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/di/bindinstance/singlemethod/StarModule.kt diff --git a/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/di/bindinstance/singlemethod_gc/ExtPlanetRollingComponent.java b/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/di/bindinstance/singlemethod_gc/ExtPlanetRollingComponent.kt similarity index 100% rename from tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/di/bindinstance/singlemethod_gc/ExtPlanetRollingComponent.java rename to tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/di/bindinstance/singlemethod_gc/ExtPlanetRollingComponent.kt diff --git a/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/di/forest/DiseasesModule.java b/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/di/forest/DiseasesModule.kt similarity index 100% rename from tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/di/forest/DiseasesModule.java rename to tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/di/forest/DiseasesModule.kt diff --git a/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/di/forest/OldForestComponent.java b/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/di/forest/OldForestComponent.kt similarity index 100% rename from tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/di/forest/OldForestComponent.java rename to tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/di/forest/OldForestComponent.kt diff --git a/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/di/forest/OldIdentityModule.java b/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/di/forest/OldIdentityModule.kt similarity index 100% rename from tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/di/forest/OldIdentityModule.java rename to tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/di/forest/OldIdentityModule.kt diff --git a/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/di/gcforest/GcEarthExtModule.java b/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/di/gcforest/GcEarthExtModule.kt similarity index 100% rename from tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/di/gcforest/GcEarthExtModule.java rename to tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/di/gcforest/GcEarthExtModule.kt diff --git a/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/di/gcforest/GcGodExtComponent.java b/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/di/gcforest/GcGodExtComponent.kt similarity index 100% rename from tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/di/gcforest/GcGodExtComponent.java rename to tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/di/gcforest/GcGodExtComponent.kt diff --git a/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/di/gcforest/GcSunSystemExtModule.java b/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/di/gcforest/GcSunSystemExtModule.kt similarity index 100% rename from tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/di/gcforest/GcSunSystemExtModule.java rename to tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/di/gcforest/GcSunSystemExtModule.kt diff --git a/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/di/gcforest/IGcEarthExtComponent.java b/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/di/gcforest/IGcEarthExtComponent.kt similarity index 100% rename from tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/di/gcforest/IGcEarthExtComponent.java rename to tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/di/gcforest/IGcEarthExtComponent.kt diff --git a/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/di/gcscopes/GcSiriusScope.java b/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/di/gcscopes/GcSiriusScope.kt similarity index 100% rename from tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/di/gcscopes/GcSiriusScope.java rename to tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/di/gcscopes/GcSiriusScope.kt diff --git a/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/di/gcscopes/GcSputnikScope.java b/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/di/gcscopes/GcSputnikScope.kt similarity index 100% rename from tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/di/gcscopes/GcSputnikScope.java rename to tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/di/gcscopes/GcSputnikScope.kt diff --git a/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/di/swcache/SwitchCacheExtComponent.java b/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/di/swcache/SwitchCacheExtComponent.kt similarity index 100% rename from tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/di/swcache/SwitchCacheExtComponent.java rename to tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/di/swcache/SwitchCacheExtComponent.kt diff --git a/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/di/techfactory/ITechProviderExtComponent.java b/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/di/techfactory/ITechProviderExtComponent.kt similarity index 100% rename from tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/di/techfactory/ITechProviderExtComponent.java rename to tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/di/techfactory/ITechProviderExtComponent.kt diff --git a/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/di/techfactory/TechFactoryExtComponent.java b/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/di/techfactory/TechFactoryExtComponent.kt similarity index 100% rename from tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/di/techfactory/TechFactoryExtComponent.java rename to tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/di/techfactory/TechFactoryExtComponent.kt diff --git a/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/di/techfactory/TechFactoryExtModule.java b/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/di/techfactory/TechFactoryExtModule.kt similarity index 100% rename from tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/di/techfactory/TechFactoryExtModule.java rename to tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/di/techfactory/TechFactoryExtModule.kt diff --git a/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/di/techfactory/identifiers/Frequency.java b/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/di/techfactory/identifiers/Frequency.kt similarity index 100% rename from tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/di/techfactory/identifiers/Frequency.java rename to tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/di/techfactory/identifiers/Frequency.kt diff --git a/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/mowgli/animal/OldHorse.java b/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/mowgli/animal/OldHorse.kt similarity index 100% rename from tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/mowgli/animal/OldHorse.java rename to tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/mowgli/animal/OldHorse.kt diff --git a/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/mowgli/diseases/Osteoarthritis.java b/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/mowgli/diseases/Osteoarthritis.kt similarity index 100% rename from tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/mowgli/diseases/Osteoarthritis.java rename to tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/mowgli/diseases/Osteoarthritis.kt diff --git a/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/mowgli/earth/Bay.java b/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/mowgli/earth/Bay.kt similarity index 100% rename from tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/mowgli/earth/Bay.java rename to tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/mowgli/earth/Bay.kt diff --git a/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/mowgli/earth/Desert.java b/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/mowgli/earth/Desert.kt similarity index 100% rename from tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/mowgli/earth/Desert.java rename to tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/mowgli/earth/Desert.kt diff --git a/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/mowgli/earth/WaterFlow.java b/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/mowgli/earth/WaterFlow.kt similarity index 100% rename from tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/mowgli/earth/WaterFlow.java rename to tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/mowgli/earth/WaterFlow.kt diff --git a/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/mowgli/galaxy/Pluton.java b/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/mowgli/galaxy/Pluton.kt similarity index 100% rename from tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/mowgli/galaxy/Pluton.java rename to tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/mowgli/galaxy/Pluton.kt diff --git a/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/mowgli/galaxy/sputniks/Calypso.java b/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/mowgli/galaxy/sputniks/Calypso.kt similarity index 100% rename from tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/mowgli/galaxy/sputniks/Calypso.java rename to tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/mowgli/galaxy/sputniks/Calypso.kt diff --git a/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/mowgli/galaxy/sputniks/Moon.java b/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/mowgli/galaxy/sputniks/Moon.kt similarity index 100% rename from tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/mowgli/galaxy/sputniks/Moon.java rename to tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/mowgli/galaxy/sputniks/Moon.kt diff --git a/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/mowgli/galaxy/stars/Sirius.java b/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/mowgli/galaxy/stars/Sirius.kt similarity index 100% rename from tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/mowgli/galaxy/stars/Sirius.java rename to tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/mowgli/galaxy/stars/Sirius.kt diff --git a/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/mowgli/identity/FamilyIdeology.java b/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/mowgli/identity/FamilyIdeology.kt similarity index 100% rename from tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/mowgli/identity/FamilyIdeology.java rename to tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/mowgli/identity/FamilyIdeology.kt diff --git a/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/mowgli/identity/OldKnowledge.java b/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/mowgli/identity/OldKnowledge.kt similarity index 100% rename from tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/mowgli/identity/OldKnowledge.java rename to tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/mowgli/identity/OldKnowledge.kt diff --git a/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/tech/components/DDR3Ram.java b/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/tech/components/DDR3Ram.kt similarity index 100% rename from tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/tech/components/DDR3Ram.java rename to tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/tech/components/DDR3Ram.kt From c5110966aec6ff6e44a091c765360e6e97eb884a Mon Sep 17 00:00:00 2001 From: klee0kai Date: Sun, 14 Dec 2025 21:17:56 +0100 Subject: [PATCH 070/122] migrate test ext to kotlin --- .../target/component/ComponentsMethodsExt.kt | 2 +- .../test/di/base_forest/ForestComponent.kt | 2 + .../klee0kai/test/mowgli/animal/Horse.kt | 4 +- .../klee0kai/test/mowgli/earth/River.kt | 2 +- .../klee0kai/test/mowgli/identity/Ideology.kt | 5 +- .../klee0kai/test/tech/components/Ram.kt | 4 +- tests_ext/build.gradle.kts | 5 +- .../inject/di/base_phone/PhoneExtComponent.kt | 35 +++++++----- .../inject/di/base_phone/TechExtModule.kt | 22 +++----- .../simple/GodRebrandingComponent.kt | 15 +++-- .../simple/SunSystemRebrandingModule.kt | 14 ++--- .../singlemethod/ExtPlanetComponent.kt | 12 ++-- .../singlemethod/PlanetSputnikComponent.kt | 21 ++++--- .../bindinstance/singlemethod/StarModule.kt | 25 ++++----- .../ExtPlanetRollingComponent.kt | 56 +++++++++---------- .../inject/di/forest/DiseasesModule.kt | 12 ++-- .../inject/di/forest/OldForestComponent.kt | 25 ++++----- .../inject/di/forest/OldIdentityModule.kt | 22 ++++---- .../inject/di/gcforest/GcEarthExtModule.kt | 39 +++++++------ .../inject/di/gcforest/GcGodExtComponent.kt | 33 +++++------ .../di/gcforest/GcSunSystemExtModule.kt | 12 ++-- .../di/gcforest/IGcEarthExtComponent.kt | 23 ++++---- .../inject/di/gcscopes/GcSiriusScope.kt | 16 ++---- .../inject/di/gcscopes/GcSputnikScope.kt | 16 ++---- .../di/swcache/SwitchCacheExtComponent.kt | 16 +++--- .../techfactory/ITechProviderExtComponent.kt | 29 +++++----- .../di/techfactory/TechFactoryExtComponent.kt | 21 +++---- .../di/techfactory/TechFactoryExtModule.kt | 29 +++++----- .../di/techfactory/identifiers/Frequency.kt | 29 ++-------- .../test_ext/inject/mowgli/animal/OldHorse.kt | 21 ++++--- .../inject/mowgli/diseases/Osteoarthritis.kt | 11 ++-- .../test_ext/inject/mowgli/earth/Bay.kt | 10 ++-- .../test_ext/inject/mowgli/earth/Desert.kt | 10 ++-- .../test_ext/inject/mowgli/earth/WaterFlow.kt | 14 ++--- .../test_ext/inject/mowgli/galaxy/Pluton.kt | 14 ++--- .../inject/mowgli/galaxy/sputniks/Calypso.kt | 10 ++-- .../inject/mowgli/galaxy/sputniks/Moon.kt | 11 ++-- .../inject/mowgli/galaxy/stars/Sirius.kt | 14 ++--- .../inject/mowgli/identity/FamilyIdeology.kt | 18 +++--- .../inject/mowgli/identity/OldKnowledge.kt | 16 +++--- .../inject/tech/components/DDR3Ram.kt | 34 +++++------ 41 files changed, 315 insertions(+), 414 deletions(-) diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/component/ComponentsMethodsExt.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/component/ComponentsMethodsExt.kt index d01bba32..9839f595 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/component/ComponentsMethodsExt.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/component/ComponentsMethodsExt.kt @@ -165,7 +165,7 @@ fun KSFunctionDeclaration.isExtOfMethod( ) } val argumentType = parameters.firstOrNull()?.type - ?.resolve() as? KSClassDeclaration + ?.resolveAlias()?.declaration as? KSClassDeclaration ?: throw IncorrectSignatureException( message = "${simpleName.asString()} must have only one parameter of Component instance", element = this, diff --git a/tests/src/main/java/com/github/klee0kai/test/di/base_forest/ForestComponent.kt b/tests/src/main/java/com/github/klee0kai/test/di/base_forest/ForestComponent.kt index 7cf1cc83..8b36385d 100644 --- a/tests/src/main/java/com/github/klee0kai/test/di/base_forest/ForestComponent.kt +++ b/tests/src/main/java/com/github/klee0kai/test/di/base_forest/ForestComponent.kt @@ -7,8 +7,10 @@ import com.github.klee0kai.test.mowgli.animal.Horse import com.github.klee0kai.test.mowgli.animal.Mowgli import com.github.klee0kai.test.mowgli.animal.Snake + @Component interface ForestComponent { + fun united(): UnitedModule? fun identity(): IdentityModule? diff --git a/tests/src/main/java/com/github/klee0kai/test/mowgli/animal/Horse.kt b/tests/src/main/java/com/github/klee0kai/test/mowgli/animal/Horse.kt index db1e006a..8caf41f6 100644 --- a/tests/src/main/java/com/github/klee0kai/test/mowgli/animal/Horse.kt +++ b/tests/src/main/java/com/github/klee0kai/test/mowgli/animal/Horse.kt @@ -29,13 +29,13 @@ open class Horse : IAnimal { @Inject var knowledge: Knowledge? = null - @JvmField @Inject - var ideology: Ideology? = null + open var ideology: Ideology? = null @JvmField var methodInjectedConscience: Conscience? = null + @JvmField var methodInjectedKnowledge: Knowledge? = null diff --git a/tests/src/main/java/com/github/klee0kai/test/mowgli/earth/River.kt b/tests/src/main/java/com/github/klee0kai/test/mowgli/earth/River.kt index 12f823da..9613f0ff 100644 --- a/tests/src/main/java/com/github/klee0kai/test/mowgli/earth/River.kt +++ b/tests/src/main/java/com/github/klee0kai/test/mowgli/earth/River.kt @@ -3,5 +3,5 @@ package com.github.klee0kai.test.mowgli.earth import java.util.* open class River : IRiver { - var uuid: UUID = UUID.randomUUID() + open var uuid: UUID = UUID.randomUUID() } diff --git a/tests/src/main/java/com/github/klee0kai/test/mowgli/identity/Ideology.kt b/tests/src/main/java/com/github/klee0kai/test/mowgli/identity/Ideology.kt index 435a7825..00f875cf 100644 --- a/tests/src/main/java/com/github/klee0kai/test/mowgli/identity/Ideology.kt +++ b/tests/src/main/java/com/github/klee0kai/test/mowgli/identity/Ideology.kt @@ -3,9 +3,8 @@ package com.github.klee0kai.test.mowgli.identity import java.util.* open class Ideology { - var uuid: UUID = UUID.randomUUID() + open var uuid: UUID = UUID.randomUUID() + open val isFamilyIdeology: Boolean get() = false - open val isFamilyIdeology: Boolean - get() = false } diff --git a/tests/src/main/java/com/github/klee0kai/test/tech/components/Ram.kt b/tests/src/main/java/com/github/klee0kai/test/tech/components/Ram.kt index 23ae80bb..92d6b2cb 100644 --- a/tests/src/main/java/com/github/klee0kai/test/tech/components/Ram.kt +++ b/tests/src/main/java/com/github/klee0kai/test/tech/components/Ram.kt @@ -4,10 +4,8 @@ import com.github.klee0kai.test.di.base_phone.identifiers.RamSize import java.util.* open class Ram { - @JvmField - val uuid: UUID = UUID.randomUUID() + open val uuid: UUID = UUID.randomUUID() - @JvmField val size: String? constructor() { diff --git a/tests_ext/build.gradle.kts b/tests_ext/build.gradle.kts index e8333e6d..ad39040f 100644 --- a/tests_ext/build.gradle.kts +++ b/tests_ext/build.gradle.kts @@ -1,5 +1,6 @@ plugins { - java + alias(libs.plugins.kotlin.jvm) + alias(libs.plugins.kotlin.ksp) } tasks.test { @@ -8,7 +9,7 @@ tasks.test { dependencies { implementation(project(":stone_multiplatform")) - annotationProcessor(project(":stone_processor")) + ksp(project(":stone_ksp")) implementation(project(":tests")) diff --git a/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/di/base_phone/PhoneExtComponent.kt b/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/di/base_phone/PhoneExtComponent.kt index 7e291215..a4e746c7 100644 --- a/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/di/base_phone/PhoneExtComponent.kt +++ b/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/di/base_phone/PhoneExtComponent.kt @@ -1,25 +1,30 @@ -package com.github.klee0kai.test_ext.inject.di.base_phone; +package com.github.klee0kai.test_ext.inject.di.base_phone -import com.github.klee0kai.stone.annotations.component.Component; -import com.github.klee0kai.stone.annotations.component.ExtendOf; -import com.github.klee0kai.stone.lifecycle.StoneLifeCycleOwner; -import com.github.klee0kai.test.di.base_phone.PhoneComponent; -import com.github.klee0kai.test.di.base_phone.identifiers.DataStorageSize; -import com.github.klee0kai.test.di.base_phone.identifiers.RamSize; -import com.github.klee0kai.test.tech.phone.GoodPhone; -import com.github.klee0kai.test.tech.phone.OnePhone; +import com.github.klee0kai.stone.annotations.component.Component +import com.github.klee0kai.stone.annotations.component.ExtendOf +import com.github.klee0kai.stone.lifecycle.StoneLifeCycleOwner +import com.github.klee0kai.test.di.base_phone.PhoneComponent +import com.github.klee0kai.test.di.base_phone.identifiers.DataStorageSize +import com.github.klee0kai.test.di.base_phone.identifiers.RamSize +import com.github.klee0kai.test.tech.phone.GoodPhone +import com.github.klee0kai.test.tech.phone.OnePhone @Component -public interface PhoneExtComponent extends PhoneComponent { +interface PhoneExtComponent : PhoneComponent { - TechExtModule components(); + override fun components(): TechExtModule? @ExtendOf - void extOf(PhoneComponent parent); + fun extOf(parent: PhoneComponent?) - void injectExt(OnePhone onePhone); + fun injectExt(onePhone: OnePhone?) - void injectExt(GoodPhone goodPhone, DataStorageSize dataStorageSize, RamSize ramSize); + fun injectExt(goodPhone: GoodPhone?, dataStorageSize: DataStorageSize?, ramSize: RamSize?) - void injectExt(GoodPhone goodPhone, StoneLifeCycleOwner lifeCycleOwner, DataStorageSize dataStorageSize, RamSize ramSize); + fun injectExt( + goodPhone: GoodPhone?, + lifeCycleOwner: StoneLifeCycleOwner?, + dataStorageSize: DataStorageSize?, + ramSize: RamSize? + ) } diff --git a/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/di/base_phone/TechExtModule.kt b/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/di/base_phone/TechExtModule.kt index d4383f4f..df5ee1b3 100644 --- a/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/di/base_phone/TechExtModule.kt +++ b/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/di/base_phone/TechExtModule.kt @@ -1,22 +1,18 @@ -package com.github.klee0kai.test_ext.inject.di.base_phone; - -import com.github.klee0kai.stone.annotations.module.Module; -import com.github.klee0kai.stone.annotations.module.Provide; -import com.github.klee0kai.test.di.base_phone.TechModule; -import com.github.klee0kai.test.di.base_phone.identifiers.RamSize; -import com.github.klee0kai.test_ext.inject.tech.components.DDR3Ram; +package com.github.klee0kai.test_ext.inject.di.base_phone +import com.github.klee0kai.stone.annotations.module.Module +import com.github.klee0kai.stone.annotations.module.Provide +import com.github.klee0kai.test.di.base_phone.TechModule +import com.github.klee0kai.test.di.base_phone.identifiers.RamSize +import com.github.klee0kai.test_ext.inject.tech.components.DDR3Ram @Module -public interface TechExtModule extends TechModule { +interface TechExtModule : TechModule { - @Override @Provide(cache = Provide.CacheType.Weak) - DDR3Ram ram(); + override fun ram(): DDR3Ram - @Override @Provide(cache = Provide.CacheType.Weak) - DDR3Ram ram(RamSize ramSize); - + override fun ram(ramSize: RamSize?): DDR3Ram } diff --git a/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/di/bindinstance/simple/GodRebrandingComponent.kt b/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/di/bindinstance/simple/GodRebrandingComponent.kt index 9cc055eb..37ba8fc0 100644 --- a/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/di/bindinstance/simple/GodRebrandingComponent.kt +++ b/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/di/bindinstance/simple/GodRebrandingComponent.kt @@ -1,16 +1,15 @@ -package com.github.klee0kai.test_ext.inject.di.bindinstance.simple; +package com.github.klee0kai.test_ext.inject.di.bindinstance.simple -import com.github.klee0kai.stone.annotations.component.Component; -import com.github.klee0kai.stone.annotations.component.ExtendOf; -import com.github.klee0kai.test.di.bindinstance.simple.GodWorkspaceComponent; +import com.github.klee0kai.stone.annotations.component.Component +import com.github.klee0kai.stone.annotations.component.ExtendOf +import com.github.klee0kai.test.di.bindinstance.simple.GodWorkspaceComponent @Component -public interface GodRebrandingComponent extends GodWorkspaceComponent { +interface GodRebrandingComponent : GodWorkspaceComponent { - @Override - SunSystemRebrandingModule sunSystem(); + override fun sunSystem(): SunSystemRebrandingModule @ExtendOf - void extendComponent(GodWorkspaceComponent parent); + fun extendComponent(parent: GodWorkspaceComponent) } diff --git a/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/di/bindinstance/simple/SunSystemRebrandingModule.kt b/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/di/bindinstance/simple/SunSystemRebrandingModule.kt index 006b17ce..43cb33c9 100644 --- a/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/di/bindinstance/simple/SunSystemRebrandingModule.kt +++ b/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/di/bindinstance/simple/SunSystemRebrandingModule.kt @@ -1,14 +1,14 @@ -package com.github.klee0kai.test_ext.inject.di.bindinstance.simple; +package com.github.klee0kai.test_ext.inject.di.bindinstance.simple -import com.github.klee0kai.stone.annotations.module.BindInstance; -import com.github.klee0kai.stone.annotations.module.Module; -import com.github.klee0kai.test.di.bindinstance.simple.SunSystemModule; -import com.github.klee0kai.test_ext.inject.mowgli.galaxy.Pluton; +import com.github.klee0kai.stone.annotations.module.BindInstance +import com.github.klee0kai.stone.annotations.module.Module +import com.github.klee0kai.test.di.bindinstance.simple.SunSystemModule +import com.github.klee0kai.test_ext.inject.mowgli.galaxy.Pluton @Module -public interface SunSystemRebrandingModule extends SunSystemModule { +interface SunSystemRebrandingModule : SunSystemModule { @BindInstance - Pluton pluton(); + fun pluton(): Pluton? } diff --git a/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/di/bindinstance/singlemethod/ExtPlanetComponent.kt b/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/di/bindinstance/singlemethod/ExtPlanetComponent.kt index b7e721b4..1b5cb891 100644 --- a/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/di/bindinstance/singlemethod/ExtPlanetComponent.kt +++ b/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/di/bindinstance/singlemethod/ExtPlanetComponent.kt @@ -1,13 +1,13 @@ -package com.github.klee0kai.test_ext.inject.di.bindinstance.singlemethod; +package com.github.klee0kai.test_ext.inject.di.bindinstance.singlemethod -import com.github.klee0kai.stone.annotations.component.Component; -import com.github.klee0kai.stone.annotations.component.ExtendOf; -import com.github.klee0kai.test.di.bindinstance.singlemethod.PlanetComponent; +import com.github.klee0kai.stone.annotations.component.Component +import com.github.klee0kai.stone.annotations.component.ExtendOf +import com.github.klee0kai.test.di.bindinstance.singlemethod.PlanetComponent @Component -public interface ExtPlanetComponent extends PlanetComponent { +interface ExtPlanetComponent : PlanetComponent { @ExtendOf - void extendOf(PlanetComponent parent); + fun extendOf(parent: PlanetComponent?) } diff --git a/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/di/bindinstance/singlemethod/PlanetSputnikComponent.kt b/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/di/bindinstance/singlemethod/PlanetSputnikComponent.kt index cb1121d4..4a0c6bbe 100644 --- a/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/di/bindinstance/singlemethod/PlanetSputnikComponent.kt +++ b/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/di/bindinstance/singlemethod/PlanetSputnikComponent.kt @@ -1,21 +1,20 @@ -package com.github.klee0kai.test_ext.inject.di.bindinstance.singlemethod; +package com.github.klee0kai.test_ext.inject.di.bindinstance.singlemethod -import com.github.klee0kai.stone.annotations.component.Component; -import com.github.klee0kai.stone.annotations.component.ExtendOf; -import com.github.klee0kai.stone.annotations.module.BindInstance; -import com.github.klee0kai.test.di.bindinstance.singlemethod.PlanetComponent; -import com.github.klee0kai.test_ext.inject.mowgli.galaxy.sputniks.Moon; +import com.github.klee0kai.stone.annotations.component.Component +import com.github.klee0kai.stone.annotations.component.ExtendOf +import com.github.klee0kai.stone.annotations.module.BindInstance +import com.github.klee0kai.test.di.bindinstance.singlemethod.PlanetComponent +import com.github.klee0kai.test_ext.inject.mowgli.galaxy.sputniks.Moon @Component -public interface PlanetSputnikComponent extends PlanetComponent { +interface PlanetSputnikComponent : PlanetComponent { - @Override - StarModule sunModule(); + override fun sunModule(): StarModule @BindInstance(cache = BindInstance.CacheType.Weak) - Moon moon(Moon moon); + fun moon(moon: Moon?): Moon? @ExtendOf - void extendOf(PlanetComponent parent); + fun extendOf(parent: PlanetComponent?) } diff --git a/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/di/bindinstance/singlemethod/StarModule.kt b/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/di/bindinstance/singlemethod/StarModule.kt index 184c857e..b47db8b7 100644 --- a/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/di/bindinstance/singlemethod/StarModule.kt +++ b/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/di/bindinstance/singlemethod/StarModule.kt @@ -1,31 +1,28 @@ -package com.github.klee0kai.test_ext.inject.di.bindinstance.singlemethod; +package com.github.klee0kai.test_ext.inject.di.bindinstance.singlemethod -import com.github.klee0kai.stone.annotations.module.BindInstance; -import com.github.klee0kai.stone.annotations.module.Module; -import com.github.klee0kai.test.di.bindinstance.singlemethod.SunModule; -import com.github.klee0kai.test_ext.inject.di.gcscopes.GcSiriusScope; -import com.github.klee0kai.test_ext.inject.mowgli.galaxy.stars.Sirius; +import com.github.klee0kai.stone.annotations.module.BindInstance +import com.github.klee0kai.stone.annotations.module.Module +import com.github.klee0kai.test.di.bindinstance.singlemethod.SunModule +import com.github.klee0kai.test_ext.inject.di.gcscopes.GcSiriusScope +import com.github.klee0kai.test_ext.inject.mowgli.galaxy.stars.Sirius @Module -public interface StarModule extends SunModule { +interface StarModule : SunModule { @GcSiriusScope @BindInstance(cache = BindInstance.CacheType.Strong) - Sirius siriusStrong(Sirius sirius); + fun siriusStrong(sirius: Sirius?): Sirius? @GcSiriusScope @BindInstance(cache = BindInstance.CacheType.Soft) - Sirius siriusSoft(Sirius sirius); - + fun siriusSoft(sirius: Sirius?): Sirius? @GcSiriusScope @BindInstance - Sirius sirius(Sirius sirius); - + fun sirius(sirius: Sirius?): Sirius? @GcSiriusScope @BindInstance(cache = BindInstance.CacheType.Weak) - Sirius siriusWeak(Sirius star); - + fun siriusWeak(star: Sirius?): Sirius? } diff --git a/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/di/bindinstance/singlemethod_gc/ExtPlanetRollingComponent.kt b/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/di/bindinstance/singlemethod_gc/ExtPlanetRollingComponent.kt index 3533f474..f350a3d9 100644 --- a/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/di/bindinstance/singlemethod_gc/ExtPlanetRollingComponent.kt +++ b/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/di/bindinstance/singlemethod_gc/ExtPlanetRollingComponent.kt @@ -1,75 +1,69 @@ -package com.github.klee0kai.test_ext.inject.di.bindinstance.singlemethod_gc; - -import com.github.klee0kai.stone.annotations.component.*; -import com.github.klee0kai.stone.annotations.module.BindInstance; -import com.github.klee0kai.test.di.bindinstance.singlemethod_gc.PlanetRollingComponent; -import com.github.klee0kai.test.di.gcforest.scopes.GcPlanetScope; -import com.github.klee0kai.test.di.gcforest.scopes.GcSunScope; -import com.github.klee0kai.test_ext.inject.di.bindinstance.singlemethod.StarModule; -import com.github.klee0kai.test_ext.inject.di.gcscopes.GcSiriusScope; -import com.github.klee0kai.test_ext.inject.di.gcscopes.GcSputnikScope; -import com.github.klee0kai.test_ext.inject.mowgli.galaxy.sputniks.Moon; +package com.github.klee0kai.test_ext.inject.di.bindinstance.singlemethod_gc + +import com.github.klee0kai.stone.annotations.component.* +import com.github.klee0kai.stone.annotations.module.BindInstance +import com.github.klee0kai.test.di.bindinstance.singlemethod_gc.PlanetRollingComponent +import com.github.klee0kai.test.di.gcforest.scopes.GcPlanetScope +import com.github.klee0kai.test.di.gcforest.scopes.GcSunScope +import com.github.klee0kai.test_ext.inject.di.bindinstance.singlemethod.StarModule +import com.github.klee0kai.test_ext.inject.di.gcscopes.GcSiriusScope +import com.github.klee0kai.test_ext.inject.di.gcscopes.GcSputnikScope +import com.github.klee0kai.test_ext.inject.mowgli.galaxy.sputniks.Moon @Component -public interface ExtPlanetRollingComponent extends PlanetRollingComponent { +interface ExtPlanetRollingComponent : PlanetRollingComponent { - @Override - StarModule sunModule(); + override fun sunModule(): StarModule? @ExtendOf - void extOf(PlanetRollingComponent ext); + fun extOf(ext: PlanetRollingComponent?) @GcSputnikScope @BindInstance(cache = BindInstance.CacheType.Strong) - Moon moonStrong(Moon moon); + fun moonStrong(moon: Moon?): Moon? @GcSputnikScope @BindInstance(cache = BindInstance.CacheType.Soft) - Moon moonSoft(Moon moon); + fun moonSoft(moon: Moon?): Moon? @GcSputnikScope @BindInstance(cache = BindInstance.CacheType.Weak) - Moon moonWeak(Moon moon); + fun moonWeak(moon: Moon?): Moon? @RunGc @GcAllScope - void gcAllExt(); + fun gcAllExt() @RunGc @GcStrongScope - void gcStrongExt(); + fun gcStrongExt() @RunGc @GcSoftScope - void gcSoftExt(); + fun gcSoftExt() @RunGc @GcWeakScope - void gcWeakExt(); - + fun gcWeakExt() @RunGc @GcSoftScope @GcSunScope - void gcSoftSunExt(); + fun gcSoftSunExt() @RunGc @GcSoftScope @GcPlanetScope - void gcSoftPlanetsExt(); - + fun gcSoftPlanetsExt() @RunGc @GcSoftScope @GcSputnikScope - void gcSoftSputniksExt(); - + fun gcSoftSputniksExt() @RunGc @GcSoftScope @GcSiriusScope - void gcSoftSiriusExt(); - - + fun gcSoftSiriusExt() } diff --git a/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/di/forest/DiseasesModule.kt b/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/di/forest/DiseasesModule.kt index ea5c7dfa..493464e4 100644 --- a/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/di/forest/DiseasesModule.kt +++ b/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/di/forest/DiseasesModule.kt @@ -1,13 +1,13 @@ -package com.github.klee0kai.test_ext.inject.di.forest; +package com.github.klee0kai.test_ext.inject.di.forest -import com.github.klee0kai.stone.annotations.module.Module; -import com.github.klee0kai.stone.annotations.module.Provide; -import com.github.klee0kai.test_ext.inject.mowgli.diseases.Osteoarthritis; +import com.github.klee0kai.stone.annotations.module.Module +import com.github.klee0kai.stone.annotations.module.Provide +import com.github.klee0kai.test_ext.inject.mowgli.diseases.Osteoarthritis @Module -abstract public class DiseasesModule { +abstract class DiseasesModule { @Provide - abstract public Osteoarthritis osteoarthritis(); + abstract fun osteoarthritis(): Osteoarthritis } diff --git a/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/di/forest/OldForestComponent.kt b/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/di/forest/OldForestComponent.kt index 176b65ee..a026837e 100644 --- a/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/di/forest/OldForestComponent.kt +++ b/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/di/forest/OldForestComponent.kt @@ -1,24 +1,23 @@ -package com.github.klee0kai.test_ext.inject.di.forest; +package com.github.klee0kai.test_ext.inject.di.forest -import com.github.klee0kai.stone.annotations.component.Component; -import com.github.klee0kai.stone.annotations.component.ExtendOf; -import com.github.klee0kai.stone.lifecycle.StoneLifeCycleOwner; -import com.github.klee0kai.test.di.base_forest.ForestComponent; -import com.github.klee0kai.test_ext.inject.mowgli.animal.OldHorse; +import com.github.klee0kai.stone.annotations.component.Component +import com.github.klee0kai.stone.annotations.component.ExtendOf +import com.github.klee0kai.stone.lifecycle.StoneLifeCycleOwner +import com.github.klee0kai.test.di.base_forest.ForestComponent +import com.github.klee0kai.test_ext.inject.mowgli.animal.OldHorse @Component -public interface OldForestComponent extends ForestComponent { +interface OldForestComponent : ForestComponent { - @Override - OldIdentityModule identity(); + override fun identity(): OldIdentityModule @ExtendOf - void extOf(ForestComponent parent); + fun extOf(parent: ForestComponent) - DiseasesModule diseases(); + fun diseases(): DiseasesModule? - void inject(OldHorse horse, StoneLifeCycleOwner stoneLifeCycleOwner); + fun inject(horse: OldHorse?, stoneLifeCycleOwner: StoneLifeCycleOwner?) - void inject(OldHorse horse); + fun inject(horse: OldHorse?) } diff --git a/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/di/forest/OldIdentityModule.kt b/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/di/forest/OldIdentityModule.kt index 8d47ebc7..8a7db278 100644 --- a/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/di/forest/OldIdentityModule.kt +++ b/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/di/forest/OldIdentityModule.kt @@ -1,21 +1,19 @@ -package com.github.klee0kai.test_ext.inject.di.forest; +package com.github.klee0kai.test_ext.inject.di.forest - -import com.github.klee0kai.stone.annotations.module.Module; -import com.github.klee0kai.stone.annotations.module.Provide; -import com.github.klee0kai.test.di.base_forest.IdentityModule; -import com.github.klee0kai.test_ext.inject.mowgli.identity.FamilyIdeology; -import com.github.klee0kai.test_ext.inject.mowgli.identity.OldKnowledge; +import com.github.klee0kai.stone.annotations.module.Module +import com.github.klee0kai.stone.annotations.module.Provide +import com.github.klee0kai.test.di.base_forest.IdentityModule +import com.github.klee0kai.test_ext.inject.mowgli.identity.FamilyIdeology +import com.github.klee0kai.test_ext.inject.mowgli.identity.OldKnowledge @Module -public interface OldIdentityModule extends IdentityModule { +interface OldIdentityModule : IdentityModule { - @Override @Provide(cache = Provide.CacheType.Factory) - OldKnowledge knowledge(); + override fun knowledge(): OldKnowledge - @Override @Provide(cache = Provide.CacheType.Soft) - FamilyIdeology ideology(); + override fun ideology(): FamilyIdeology + } diff --git a/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/di/gcforest/GcEarthExtModule.kt b/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/di/gcforest/GcEarthExtModule.kt index 0ac282a9..c288a534 100644 --- a/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/di/gcforest/GcEarthExtModule.kt +++ b/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/di/gcforest/GcEarthExtModule.kt @@ -1,50 +1,49 @@ -package com.github.klee0kai.test_ext.inject.di.gcforest; +package com.github.klee0kai.test_ext.inject.di.gcforest -import com.github.klee0kai.stone.annotations.module.Module; -import com.github.klee0kai.stone.annotations.module.Provide; -import com.github.klee0kai.test.di.gcforest.GcEarthModule; -import com.github.klee0kai.test.di.gcforest.scopes.GcRiverScope; -import com.github.klee0kai.test_ext.inject.mowgli.earth.Desert; -import com.github.klee0kai.test_ext.inject.mowgli.earth.WaterFlow; +import com.github.klee0kai.stone.annotations.module.Module +import com.github.klee0kai.stone.annotations.module.Provide +import com.github.klee0kai.test.di.gcforest.GcEarthModule +import com.github.klee0kai.test.di.gcforest.scopes.GcRiverScope +import com.github.klee0kai.test_ext.inject.mowgli.earth.Desert +import com.github.klee0kai.test_ext.inject.mowgli.earth.WaterFlow @Module -public abstract class GcEarthExtModule extends GcEarthModule { +abstract class GcEarthExtModule : GcEarthModule() { @Provide(cache = Provide.CacheType.Strong) - abstract public Desert desertStrong(); + abstract fun desertStrong(): Desert? @Provide(cache = Provide.CacheType.Soft) - abstract public Desert desertSoft(); + abstract fun desertSoft(): Desert? @Provide(cache = Provide.CacheType.Weak) - abstract public Desert desertWeak(); + abstract fun desertWeak(): Desert? @Provide(cache = Provide.CacheType.Factory) - public Desert desertFactory() { - return new Desert(); + fun desertFactory(): Desert { + return Desert() } - @GcRiverScope @Provide(cache = Provide.CacheType.Strong) - abstract public WaterFlow riverStrong(); + public abstract override fun riverStrong(): WaterFlow? @GcRiverScope @Provide(cache = Provide.CacheType.Soft) - abstract public WaterFlow riverSoft(); + public abstract override fun riverSoft(): WaterFlow? @GcRiverScope @Provide(cache = Provide.CacheType.Weak) - abstract public WaterFlow riverWeak(); + public abstract override fun riverWeak(): WaterFlow? @GcRiverScope @Provide(cache = Provide.CacheType.Factory) - abstract public WaterFlow riverFactory(); + public abstract override fun riverFactory(): WaterFlow? @GcRiverScope @Provide - public WaterFlow riverDefaultSoft() { - return new WaterFlow(); + public override fun riverDefaultSoft(): WaterFlow? { + return WaterFlow() } } diff --git a/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/di/gcforest/GcGodExtComponent.kt b/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/di/gcforest/GcGodExtComponent.kt index 13420cb1..50d8da79 100644 --- a/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/di/gcforest/GcGodExtComponent.kt +++ b/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/di/gcforest/GcGodExtComponent.kt @@ -1,46 +1,43 @@ -package com.github.klee0kai.test_ext.inject.di.gcforest; +package com.github.klee0kai.test_ext.inject.di.gcforest -import com.github.klee0kai.stone.annotations.component.*; -import com.github.klee0kai.test.di.gcforest.GcGodComponent; -import com.github.klee0kai.test.di.gcforest.scopes.GcPlanetScope; -import com.github.klee0kai.test.di.gcforest.scopes.GcSunScope; +import com.github.klee0kai.stone.annotations.component.* +import com.github.klee0kai.test.di.gcforest.GcGodComponent +import com.github.klee0kai.test.di.gcforest.scopes.GcPlanetScope +import com.github.klee0kai.test.di.gcforest.scopes.GcSunScope @Component -public abstract class GcGodExtComponent extends GcGodComponent implements IGcEarthExtComponent { - +abstract class GcGodExtComponent : GcGodComponent(), IGcEarthExtComponent { @ExtendOf - public abstract void extOf(GcGodComponent parent); + abstract fun extOf(parent: GcGodComponent?) - @Override - public abstract GcSunSystemExtModule sunSystem(); + public abstract override fun sunSystem(): GcSunSystemExtModule? - @Override - public abstract GcEarthExtModule earth(); + public abstract override fun earth(): GcEarthExtModule? @RunGc @GcAllScope - public abstract void gcAllExt(); + abstract fun gcAllExt() @RunGc @GcStrongScope - public abstract void gcStrongExt(); + abstract fun gcStrongExt() @RunGc @GcSoftScope - public abstract void gcSoftExt(); + abstract fun gcSoftExt() @RunGc @GcWeakScope - public abstract void gcWeakExt(); + abstract fun gcWeakExt() @RunGc @GcSunScope - public abstract void gcSunExt(); + abstract fun gcSunExt() @RunGc @GcPlanetScope - public abstract void gcPlanetsExt(); + abstract fun gcPlanetsExt() } diff --git a/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/di/gcforest/GcSunSystemExtModule.kt b/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/di/gcforest/GcSunSystemExtModule.kt index bc1a8bb8..03f507c3 100644 --- a/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/di/gcforest/GcSunSystemExtModule.kt +++ b/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/di/gcforest/GcSunSystemExtModule.kt @@ -1,11 +1,7 @@ -package com.github.klee0kai.test_ext.inject.di.gcforest; +package com.github.klee0kai.test_ext.inject.di.gcforest -import com.github.klee0kai.stone.annotations.module.Module; -import com.github.klee0kai.test.di.gcforest.GcSunSystemModule; +import com.github.klee0kai.stone.annotations.module.Module +import com.github.klee0kai.test.di.gcforest.GcSunSystemModule @Module -public interface GcSunSystemExtModule extends GcSunSystemModule { - - - -} +interface GcSunSystemExtModule : GcSunSystemModule diff --git a/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/di/gcforest/IGcEarthExtComponent.kt b/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/di/gcforest/IGcEarthExtComponent.kt index 853279af..946076a2 100644 --- a/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/di/gcforest/IGcEarthExtComponent.kt +++ b/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/di/gcforest/IGcEarthExtComponent.kt @@ -1,30 +1,29 @@ -package com.github.klee0kai.test_ext.inject.di.gcforest; +package com.github.klee0kai.test_ext.inject.di.gcforest -import com.github.klee0kai.stone.annotations.component.GcSoftScope; -import com.github.klee0kai.stone.annotations.component.GcStrongScope; -import com.github.klee0kai.stone.annotations.component.RunGc; -import com.github.klee0kai.test.di.gcforest.scopes.GcMountainScope; -import com.github.klee0kai.test.di.gcforest.scopes.GcRiverScope; - -public interface IGcEarthExtComponent { +import com.github.klee0kai.stone.annotations.component.GcSoftScope +import com.github.klee0kai.stone.annotations.component.GcStrongScope +import com.github.klee0kai.stone.annotations.component.RunGc +import com.github.klee0kai.test.di.gcforest.scopes.GcMountainScope +import com.github.klee0kai.test.di.gcforest.scopes.GcRiverScope +interface IGcEarthExtComponent { @RunGc @GcMountainScope - void gcMountainsExt(); + fun gcMountainsExt() @RunGc @GcSoftScope @GcMountainScope - void gcSoftMountainsExt(); + fun gcSoftMountainsExt() @RunGc @GcStrongScope @GcMountainScope - void gcStrongMountainsExt(); + fun gcStrongMountainsExt() @RunGc @GcRiverScope - void gcRiversExt(); + fun gcRiversExt() } diff --git a/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/di/gcscopes/GcSiriusScope.kt b/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/di/gcscopes/GcSiriusScope.kt index 72bcd01f..f9b4267b 100644 --- a/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/di/gcscopes/GcSiriusScope.kt +++ b/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/di/gcscopes/GcSiriusScope.kt @@ -1,14 +1,8 @@ -package com.github.klee0kai.test_ext.inject.di.gcscopes; +package com.github.klee0kai.test_ext.inject.di.gcscopes -import javax.inject.Scope; -import java.lang.annotation.Retention; -import java.lang.annotation.Target; - -import static java.lang.annotation.ElementType.METHOD; -import static java.lang.annotation.RetentionPolicy.RUNTIME; +import javax.inject.Scope @Scope -@Retention(RUNTIME) -@Target(METHOD) -public @interface GcSiriusScope { -} +@Retention(AnnotationRetention.RUNTIME) +@Target(AnnotationTarget.FUNCTION, AnnotationTarget.PROPERTY_GETTER, AnnotationTarget.PROPERTY_SETTER) +annotation class GcSiriusScope diff --git a/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/di/gcscopes/GcSputnikScope.kt b/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/di/gcscopes/GcSputnikScope.kt index dbb68076..1e87616f 100644 --- a/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/di/gcscopes/GcSputnikScope.kt +++ b/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/di/gcscopes/GcSputnikScope.kt @@ -1,14 +1,8 @@ -package com.github.klee0kai.test_ext.inject.di.gcscopes; +package com.github.klee0kai.test_ext.inject.di.gcscopes -import javax.inject.Scope; -import java.lang.annotation.Retention; -import java.lang.annotation.Target; - -import static java.lang.annotation.ElementType.METHOD; -import static java.lang.annotation.RetentionPolicy.RUNTIME; +import javax.inject.Scope @Scope -@Retention(RUNTIME) -@Target(METHOD) -public @interface GcSputnikScope { -} +@Retention(AnnotationRetention.RUNTIME) +@Target(AnnotationTarget.FUNCTION, AnnotationTarget.PROPERTY_GETTER, AnnotationTarget.PROPERTY_SETTER) +annotation class GcSputnikScope diff --git a/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/di/swcache/SwitchCacheExtComponent.kt b/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/di/swcache/SwitchCacheExtComponent.kt index 0b904987..0809d3f0 100644 --- a/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/di/swcache/SwitchCacheExtComponent.kt +++ b/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/di/swcache/SwitchCacheExtComponent.kt @@ -1,24 +1,24 @@ -package com.github.klee0kai.test_ext.inject.di.swcache; +package com.github.klee0kai.test_ext.inject.di.swcache -import com.github.klee0kai.stone.annotations.component.*; -import com.github.klee0kai.test.di.swcache.SwitchCacheComponent; +import com.github.klee0kai.stone.annotations.component.* +import com.github.klee0kai.test.di.swcache.SwitchCacheComponent @Component -public interface SwitchCacheExtComponent extends SwitchCacheComponent { +interface SwitchCacheExtComponent : SwitchCacheComponent { @ExtendOf - void extOf(SwitchCacheComponent parent); + fun extOf(parent: SwitchCacheComponent?) @GcAllScope @SwitchCache(cache = SwitchCache.CacheType.Weak) - void allWeakExt(); + fun allWeakExt() @GcAllScope @SwitchCache(cache = SwitchCache.CacheType.Strong, timeMillis = 100) - void allStrongFewMillisExt(); + fun allStrongFewMillisExt() @GcStrongScope @SwitchCache(cache = SwitchCache.CacheType.Weak) - void strongToWeakExt(); + fun strongToWeakExt() } diff --git a/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/di/techfactory/ITechProviderExtComponent.kt b/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/di/techfactory/ITechProviderExtComponent.kt index 104d9c23..ce22ea4e 100644 --- a/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/di/techfactory/ITechProviderExtComponent.kt +++ b/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/di/techfactory/ITechProviderExtComponent.kt @@ -1,28 +1,27 @@ -package com.github.klee0kai.test_ext.inject.di.techfactory; +package com.github.klee0kai.test_ext.inject.di.techfactory -import com.github.klee0kai.test.di.base_phone.identifiers.RamSize; -import com.github.klee0kai.test.tech.components.Ram; -import com.github.klee0kai.test_ext.inject.di.techfactory.identifiers.Frequency; -import com.github.klee0kai.test_ext.inject.tech.components.DDR3Ram; +import com.github.klee0kai.test.di.base_phone.identifiers.RamSize +import com.github.klee0kai.test.tech.components.Ram +import com.github.klee0kai.test_ext.inject.di.techfactory.identifiers.Frequency +import com.github.klee0kai.test_ext.inject.tech.components.DDR3Ram +import javax.inject.Named -import javax.inject.Named; +interface ITechProviderExtComponent { -public interface ITechProviderExtComponent { + fun ramExt(): Ram? - Ram ramExt(); + fun ramExt(ramSize: RamSize?): Ram? - Ram ramExt(RamSize ramSize); + fun ramExt(ramSize: RamSize?, frequency: Frequency?): Ram - Ram ramExt(RamSize ramSize, Frequency frequency); - - @Named() - DDR3Ram ramDDr3Ext(); + @Named + fun ramDDr3Ext(): DDR3Ram? @Named("size") - DDR3Ram ramDdr3Ext(RamSize ramSize); + fun ramDdr3Ext(ramSize: RamSize?): DDR3Ram @Named("size-frequency") - DDR3Ram ramDDr3Ext(RamSize ramSize, Frequency frequency); + fun ramDDr3Ext(ramSize: RamSize?, frequency: Frequency?): DDR3Ram } diff --git a/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/di/techfactory/TechFactoryExtComponent.kt b/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/di/techfactory/TechFactoryExtComponent.kt index 4936cd59..3874e894 100644 --- a/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/di/techfactory/TechFactoryExtComponent.kt +++ b/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/di/techfactory/TechFactoryExtComponent.kt @@ -1,20 +1,17 @@ -package com.github.klee0kai.test_ext.inject.di.techfactory; +package com.github.klee0kai.test_ext.inject.di.techfactory +import com.github.klee0kai.stone.annotations.component.Component +import com.github.klee0kai.stone.annotations.component.ExtendOf +import com.github.klee0kai.test.di.techfactory.TechFactoryComponent +import com.github.klee0kai.test_ext.inject.di.techfactory.identifiers.Frequency -import com.github.klee0kai.stone.annotations.component.Component; -import com.github.klee0kai.stone.annotations.component.ExtendOf; -import com.github.klee0kai.test.di.techfactory.TechFactoryComponent; -import com.github.klee0kai.test_ext.inject.di.techfactory.identifiers.Frequency; -@Component( - identifiers = {Frequency.class} -) -public interface TechFactoryExtComponent extends TechFactoryComponent, ITechProviderExtComponent { +@Component(identifiers = [Frequency::class]) +interface TechFactoryExtComponent : TechFactoryComponent, ITechProviderExtComponent { - @Override - TechFactoryExtModule factory(); + override fun factory(): TechFactoryExtModule? @ExtendOf - void extOf(TechFactoryComponent parent); + fun extOf(parent: TechFactoryComponent?) } diff --git a/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/di/techfactory/TechFactoryExtModule.kt b/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/di/techfactory/TechFactoryExtModule.kt index 2973a165..a22a7640 100644 --- a/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/di/techfactory/TechFactoryExtModule.kt +++ b/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/di/techfactory/TechFactoryExtModule.kt @@ -1,29 +1,26 @@ -package com.github.klee0kai.test_ext.inject.di.techfactory; +package com.github.klee0kai.test_ext.inject.di.techfactory -import com.github.klee0kai.stone.annotations.module.Module; -import com.github.klee0kai.stone.annotations.module.Provide; -import com.github.klee0kai.test.di.base_phone.identifiers.RamSize; -import com.github.klee0kai.test.di.techfactory.TechFactoryModule; -import com.github.klee0kai.test_ext.inject.di.techfactory.identifiers.Frequency; -import com.github.klee0kai.test_ext.inject.tech.components.DDR3Ram; - -import javax.inject.Named; +import com.github.klee0kai.stone.annotations.module.Module +import com.github.klee0kai.stone.annotations.module.Provide +import com.github.klee0kai.test.di.base_phone.identifiers.RamSize +import com.github.klee0kai.test.di.techfactory.TechFactoryModule +import com.github.klee0kai.test_ext.inject.di.techfactory.identifiers.Frequency +import com.github.klee0kai.test_ext.inject.tech.components.DDR3Ram +import javax.inject.Named @Module -public interface TechFactoryExtModule extends TechFactoryModule { +interface TechFactoryExtModule : TechFactoryModule { - @Override - @Named() + @Named @Provide(cache = Provide.CacheType.Factory) - DDR3Ram ram(); + override fun ram(): DDR3Ram? - @Override @Named("size") @Provide(cache = Provide.CacheType.Factory) - DDR3Ram ram(RamSize ramSize); + override fun ram(ramSize: RamSize?): DDR3Ram? @Named("size-frequency") @Provide(cache = Provide.CacheType.Factory) - DDR3Ram ram(RamSize ramSize, Frequency frequency); + fun ram(ramSize: RamSize?, frequency: Frequency?): DDR3Ram } diff --git a/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/di/techfactory/identifiers/Frequency.kt b/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/di/techfactory/identifiers/Frequency.kt index 31263510..71ad9b51 100644 --- a/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/di/techfactory/identifiers/Frequency.kt +++ b/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/di/techfactory/identifiers/Frequency.kt @@ -1,26 +1,5 @@ -package com.github.klee0kai.test_ext.inject.di.techfactory.identifiers; +package com.github.klee0kai.test_ext.inject.di.techfactory.identifiers -import java.util.Objects; - -public class Frequency { - - public String frequency; - - public Frequency(String frequency) { - this.frequency = frequency; - } - - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - Frequency frequency = (Frequency) o; - return Objects.equals(this.frequency, frequency.frequency); - } - - @Override - public int hashCode() { - return Objects.hash(frequency); - } -} +data class Frequency( + var frequency: String?, +) diff --git a/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/mowgli/animal/OldHorse.kt b/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/mowgli/animal/OldHorse.kt index 6238aed2..0a737083 100644 --- a/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/mowgli/animal/OldHorse.kt +++ b/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/mowgli/animal/OldHorse.kt @@ -1,21 +1,20 @@ -package com.github.klee0kai.test_ext.inject.mowgli.animal; +package com.github.klee0kai.test_ext.inject.mowgli.animal -import com.github.klee0kai.test.mowgli.animal.Horse; -import com.github.klee0kai.test.mowgli.identity.Ideology; -import com.github.klee0kai.test_ext.inject.mowgli.diseases.Osteoarthritis; -import com.github.klee0kai.test_ext.inject.mowgli.identity.OldKnowledge; +import com.github.klee0kai.test.mowgli.animal.Horse +import com.github.klee0kai.test.mowgli.identity.Ideology +import com.github.klee0kai.test_ext.inject.mowgli.diseases.Osteoarthritis +import com.github.klee0kai.test_ext.inject.mowgli.identity.OldKnowledge +import javax.inject.Inject -import javax.inject.Inject; - -public class OldHorse extends Horse { +class OldHorse : Horse() { @Inject - public OldKnowledge oldKnowledge; + lateinit var oldKnowledge: OldKnowledge @Inject - public Osteoarthritis osteoarthritis; + lateinit var osteoarthritis: Osteoarthritis @Inject - public Ideology ideology; + override var ideology: Ideology? = null } diff --git a/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/mowgli/diseases/Osteoarthritis.kt b/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/mowgli/diseases/Osteoarthritis.kt index 24b86fc0..a9f8574c 100644 --- a/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/mowgli/diseases/Osteoarthritis.kt +++ b/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/mowgli/diseases/Osteoarthritis.kt @@ -1,11 +1,8 @@ -package com.github.klee0kai.test_ext.inject.mowgli.diseases; +package com.github.klee0kai.test_ext.inject.mowgli.diseases - -import java.util.UUID; - -public class Osteoarthritis { - - public UUID uuid = UUID.randomUUID(); +import java.util.* +class Osteoarthritis { + var uuid: UUID = UUID.randomUUID() } diff --git a/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/mowgli/earth/Bay.kt b/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/mowgli/earth/Bay.kt index 8ca0b11d..e651e849 100644 --- a/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/mowgli/earth/Bay.kt +++ b/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/mowgli/earth/Bay.kt @@ -1,9 +1,7 @@ -package com.github.klee0kai.test_ext.inject.mowgli.earth; +package com.github.klee0kai.test_ext.inject.mowgli.earth -import java.util.UUID; +import java.util.* -public class Bay { - - public UUID uuid = UUID.randomUUID(); - +class Bay { + var uuid: UUID = UUID.randomUUID() } diff --git a/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/mowgli/earth/Desert.kt b/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/mowgli/earth/Desert.kt index 076b42b7..f7c14511 100644 --- a/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/mowgli/earth/Desert.kt +++ b/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/mowgli/earth/Desert.kt @@ -1,9 +1,7 @@ -package com.github.klee0kai.test_ext.inject.mowgli.earth; +package com.github.klee0kai.test_ext.inject.mowgli.earth -import java.util.UUID; - -public class Desert { - - public UUID uuid = UUID.randomUUID(); +import java.util.* +class Desert { + var uuid: UUID = UUID.randomUUID() } diff --git a/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/mowgli/earth/WaterFlow.kt b/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/mowgli/earth/WaterFlow.kt index 81c2a69d..9acb5a69 100644 --- a/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/mowgli/earth/WaterFlow.kt +++ b/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/mowgli/earth/WaterFlow.kt @@ -1,12 +1,8 @@ -package com.github.klee0kai.test_ext.inject.mowgli.earth; - -import com.github.klee0kai.test.mowgli.earth.River; - -import java.util.UUID; - -public class WaterFlow extends River { - - public UUID uuid = UUID.randomUUID(); +package com.github.klee0kai.test_ext.inject.mowgli.earth +import com.github.klee0kai.test.mowgli.earth.River +import java.util.* +class WaterFlow : River() { + override var uuid: UUID = UUID.randomUUID() } diff --git a/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/mowgli/galaxy/Pluton.kt b/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/mowgli/galaxy/Pluton.kt index a90eb939..2fdfe802 100644 --- a/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/mowgli/galaxy/Pluton.kt +++ b/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/mowgli/galaxy/Pluton.kt @@ -1,12 +1,8 @@ -package com.github.klee0kai.test_ext.inject.mowgli.galaxy; - -import com.github.klee0kai.test.mowgli.galaxy.IPlanet; - -import java.util.UUID; - -public class Pluton implements IPlanet { - - public UUID uuid = UUID.randomUUID(); +package com.github.klee0kai.test_ext.inject.mowgli.galaxy +import com.github.klee0kai.test.mowgli.galaxy.IPlanet +import java.util.* +class Pluton : IPlanet { + var uuid: UUID = UUID.randomUUID() } diff --git a/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/mowgli/galaxy/sputniks/Calypso.kt b/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/mowgli/galaxy/sputniks/Calypso.kt index 4814c248..c27a4f4c 100644 --- a/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/mowgli/galaxy/sputniks/Calypso.kt +++ b/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/mowgli/galaxy/sputniks/Calypso.kt @@ -1,9 +1,7 @@ -package com.github.klee0kai.test_ext.inject.mowgli.galaxy.sputniks; +package com.github.klee0kai.test_ext.inject.mowgli.galaxy.sputniks -import java.util.UUID; - -public class Calypso { - - public UUID uuid = UUID.randomUUID(); +import java.util.* +class Calypso { + var uuid: UUID = UUID.randomUUID() } diff --git a/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/mowgli/galaxy/sputniks/Moon.kt b/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/mowgli/galaxy/sputniks/Moon.kt index e72f5242..9dc99fb2 100644 --- a/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/mowgli/galaxy/sputniks/Moon.kt +++ b/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/mowgli/galaxy/sputniks/Moon.kt @@ -1,10 +1,7 @@ -package com.github.klee0kai.test_ext.inject.mowgli.galaxy.sputniks; - -import java.util.UUID; - -public class Moon { - - public UUID uuid = UUID.randomUUID(); +package com.github.klee0kai.test_ext.inject.mowgli.galaxy.sputniks +import java.util.* +class Moon { + var uuid: UUID = UUID.randomUUID() } diff --git a/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/mowgli/galaxy/stars/Sirius.kt b/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/mowgli/galaxy/stars/Sirius.kt index 8279cad6..dd10a751 100644 --- a/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/mowgli/galaxy/stars/Sirius.kt +++ b/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/mowgli/galaxy/stars/Sirius.kt @@ -1,12 +1,8 @@ -package com.github.klee0kai.test_ext.inject.mowgli.galaxy.stars; - -import com.github.klee0kai.test.mowgli.galaxy.IStar; - -import java.util.UUID; - -public class Sirius implements IStar { - - public UUID uuid = UUID.randomUUID(); +package com.github.klee0kai.test_ext.inject.mowgli.galaxy.stars +import com.github.klee0kai.test.mowgli.galaxy.IStar +import java.util.* +class Sirius : IStar { + var uuid: UUID = UUID.randomUUID() } diff --git a/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/mowgli/identity/FamilyIdeology.kt b/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/mowgli/identity/FamilyIdeology.kt index 6f927760..320f13cc 100644 --- a/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/mowgli/identity/FamilyIdeology.kt +++ b/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/mowgli/identity/FamilyIdeology.kt @@ -1,16 +1,12 @@ -package com.github.klee0kai.test_ext.inject.mowgli.identity; +package com.github.klee0kai.test_ext.inject.mowgli.identity -import com.github.klee0kai.test.mowgli.identity.Ideology; +import com.github.klee0kai.test.mowgli.identity.Ideology +import java.util.* -import java.util.UUID; +class FamilyIdeology : Ideology() { + override var uuid: UUID = UUID.randomUUID() -public class FamilyIdeology extends Ideology { - - public UUID uuid = UUID.randomUUID(); - - - public boolean isFamilyIdeology() { - return true; - } + override val isFamilyIdeology: Boolean + get() = true } diff --git a/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/mowgli/identity/OldKnowledge.kt b/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/mowgli/identity/OldKnowledge.kt index afc0a76b..1b7dc281 100644 --- a/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/mowgli/identity/OldKnowledge.kt +++ b/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/mowgli/identity/OldKnowledge.kt @@ -1,16 +1,14 @@ -package com.github.klee0kai.test_ext.inject.mowgli.identity; +package com.github.klee0kai.test_ext.inject.mowgli.identity -import com.github.klee0kai.test.mowgli.identity.Knowledge; +import com.github.klee0kai.test.mowgli.identity.Knowledge -public class OldKnowledge extends Knowledge { +class OldKnowledge : Knowledge() { - - public boolean doChildKnowledge() { - return true; + fun doChildKnowledge(): Boolean { + return true } - public boolean isOldKnowledge() { - return true; - } + override val isOldKnowledge: Boolean + get() = true } diff --git a/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/tech/components/DDR3Ram.kt b/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/tech/components/DDR3Ram.kt index e5a325b4..bf06208e 100644 --- a/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/tech/components/DDR3Ram.kt +++ b/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/tech/components/DDR3Ram.kt @@ -1,30 +1,24 @@ -package com.github.klee0kai.test_ext.inject.tech.components; +package com.github.klee0kai.test_ext.inject.tech.components -import com.github.klee0kai.test.di.base_phone.identifiers.RamSize; -import com.github.klee0kai.test.tech.components.Ram; -import com.github.klee0kai.test_ext.inject.di.techfactory.identifiers.Frequency; +import com.github.klee0kai.test.di.base_phone.identifiers.RamSize +import com.github.klee0kai.test.tech.components.Ram +import com.github.klee0kai.test_ext.inject.di.techfactory.identifiers.Frequency +import java.util.* -import java.util.UUID; +class DDR3Ram : Ram { + override val uuid: UUID = UUID.randomUUID() -public class DDR3Ram extends Ram { + val frequency: String? - public final UUID uuid = UUID.randomUUID(); - - public final String frequency; - - public DDR3Ram() { - super(); - frequency = "default"; + constructor() : super() { + frequency = "default" } - public DDR3Ram(RamSize ramSize) { - super(ramSize); - this.frequency = "default"; + constructor(ramSize: RamSize?) : super(ramSize) { + this.frequency = "default" } - public DDR3Ram(RamSize ramSize, Frequency frequency) { - super(ramSize); - this.frequency = frequency.frequency; + constructor(ramSize: RamSize?, frequency: Frequency) : super(ramSize) { + this.frequency = frequency.frequency } - } From 66a7e96a3a4ffc562b680a286fcbb77e909c2942 Mon Sep 17 00:00:00 2001 From: klee0kai Date: Sun, 14 Dec 2025 23:48:19 +0100 Subject: [PATCH 071/122] fix error processing --- .../klee0kai/thekey/stone/ksp/Processor.kt | 27 +++++++++++-------- .../stone/ksp/exceptions/StoneException.kt | 5 +++- .../thekey/stone/ksp/exceptions/WrapExt.kt | 5 ++-- .../ksp/helpers/ComponentDeclarationExt.kt | 14 +++++----- .../ksp/helpers/invokecall/ModulesGraph.kt | 9 ++++--- .../helpers/invokecall/model/FieldDetail.kt | 3 ++- .../stone/ksp/ksp/KSClassDeclarationExt.kt | 14 +++++----- .../thekey/stone/ksp/utils/CommonExt.kt | 10 +++++++ .../test/di/base_forest/IdentityModule.kt | 1 + .../di/techfactory/TechFactoryExtComponent.kt | 6 ++++- 10 files changed, 61 insertions(+), 33 deletions(-) create mode 100644 stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/utils/CommonExt.kt diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/Processor.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/Processor.kt index 0638ec8f..a71af671 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/Processor.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/Processor.kt @@ -7,12 +7,12 @@ import com.github.klee0kai.thekey.stone.ksp.ksp.arch.GenSpec import com.github.klee0kai.thekey.stone.ksp.ksp.arch.filter import com.github.klee0kai.thekey.stone.ksp.ksp.arch.forceProcess import com.github.klee0kai.thekey.stone.ksp.ksp.arch.nowTakeOnly -import com.github.klee0kai.thekey.stone.ksp.target.module.GenModuleCacheControlProcessor -import com.github.klee0kai.thekey.stone.ksp.target.module.GenModuleFactoryProcessor -import com.github.klee0kai.thekey.stone.ksp.target.module.GenModuleProcessor import com.github.klee0kai.thekey.stone.ksp.target.component.GenComponentProcessor import com.github.klee0kai.thekey.stone.ksp.target.hiddenmodule.GenHiddenModuleCacheControlProcessor import com.github.klee0kai.thekey.stone.ksp.target.hiddenmodule.GenHiddenModuleProcessor +import com.github.klee0kai.thekey.stone.ksp.target.module.GenModuleCacheControlProcessor +import com.github.klee0kai.thekey.stone.ksp.target.module.GenModuleFactoryProcessor +import com.github.klee0kai.thekey.stone.ksp.target.module.GenModuleProcessor import com.google.devtools.ksp.containingFile import com.google.devtools.ksp.processing.CodeGenerator import com.google.devtools.ksp.processing.KSPLogger @@ -63,7 +63,7 @@ class Processor( // force changes // debug = true -// debugPkgFilter = "com.github.klee0kai.test.di.base_phone" +// debugPkgFilter = "com.github.klee0kai.test_ext.inject.di.techfactory" } @@ -132,16 +132,21 @@ class Processor( genSpecs.addAll( symbols.symbolsForProcessing .mapNotNull { targetSymbol -> - processor.process( - validSymbol = targetSymbol, - resolver = resolver, - options = options, - logger = logger, - ) + wrapKsNoteInfo(targetSymbol) { + processor.process( + validSymbol = targetSymbol, + resolver = resolver, + options = options, + logger = logger, + ) + } } ) } catch (e: StoneException) { - logger.error(e.toString(), e.findLastErrorElement()) + logger.error( + message = e.message ?: "", + symbol = e.findLastErrorElement(), + ) } } diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/exceptions/StoneException.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/exceptions/StoneException.kt index 67249a60..968460ea 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/exceptions/StoneException.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/exceptions/StoneException.kt @@ -1,6 +1,7 @@ package com.github.klee0kai.thekey.stone.ksp.exceptions import com.google.devtools.ksp.symbol.KSNode +import com.google.devtools.ksp.symbol.NonExistLocation open class StoneException( @@ -14,7 +15,9 @@ open class StoneException( if (cause is StoneException) { sourceElement = (cause as StoneException).findLastErrorElement() } - if (sourceElement == null) sourceElement = element + if (sourceElement == null || sourceElement.location is NonExistLocation) { + sourceElement = element + } return sourceElement } diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/exceptions/WrapExt.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/exceptions/WrapExt.kt index 9caa9c52..b765c01d 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/exceptions/WrapExt.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/exceptions/WrapExt.kt @@ -3,7 +3,7 @@ package com.github.klee0kai.thekey.stone.ksp.exceptions import com.google.devtools.ksp.symbol.KSFunctionDeclaration import com.google.devtools.ksp.symbol.KSNode -fun T.wrapKsNoteInfo( +inline fun T.wrapKsNoteInfo( ksNode: KSNode?, block: T.() -> R, ): R { @@ -11,8 +11,9 @@ fun T.wrapKsNoteInfo( block() } catch (e: Throwable) { throw StoneException( - message = e.message, + message = "${e.message}. At ${ksNode?.location} ", element = ksNode, + cause = e, ) } } diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/ComponentDeclarationExt.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/ComponentDeclarationExt.kt index a5981e37..4cb6185d 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/ComponentDeclarationExt.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/ComponentDeclarationExt.kt @@ -32,14 +32,14 @@ fun Resolver.findComponentForModuleOrDep( } } +val KSClassDeclaration.allParentDeclarations: Sequence + get() = (sequenceOf(this) + + superTypes.mapNotNull { it.resolveAlias().declaration as? KSClassDeclaration }) + val KSClassDeclaration.allIdentifierTypes: Sequence - get() { - val componentCl = this@allIdentifierTypes - val allParentsSequence = (sequenceOf(componentCl) + superTypes) - return allParentsSequence - .flatMap { it.findComponentAnnotation() } - .flatMap { it.identifiers } - } + get() = allParentDeclarations + .flatMap { it.findComponentAnnotation() } + .flatMap { it.identifiers } fun List.identifierParameters( allIdentifierTypes: List, diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/invokecall/ModulesGraph.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/invokecall/ModulesGraph.kt index 34721a6f..ab773bbd 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/invokecall/ModulesGraph.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/invokecall/ModulesGraph.kt @@ -16,6 +16,7 @@ import com.github.klee0kai.thekey.stone.ksp.helpers.qualifierAnnotations import com.github.klee0kai.thekey.stone.ksp.helpers.wrap.WrapHelper import com.github.klee0kai.thekey.stone.ksp.ksp.getAllMethods import com.github.klee0kai.thekey.stone.ksp.ksp.isNotPrimitive +import com.github.klee0kai.thekey.stone.ksp.ksp.resolveAlias import com.github.klee0kai.thekey.stone.ksp.target.component.* import com.github.klee0kai.thekey.stone.ksp.utils.LocalFieldName.genLocalFieldName import com.github.klee0kai.thekey.stone.ksp.utils.RecursiveDetector @@ -56,13 +57,13 @@ class ModulesGraph( .filter { it.isModuleProvideMethod || it.isDepsProvideMethod } .forEachFun { _, moduleProvideMethod -> - val module = moduleProvideMethod.returnType?.resolve() + val module = moduleProvideMethod.returnType?.resolveAlias() ?.declaration as? KSClassDeclaration ?: return@forEachFun - for (m in module.getAllMethods(false, true, "")) { - if (m.returnType?.resolve()?.isNotPrimitive == false) continue + for (m in module.getAllMethods(includeObjectMethods = false, allowDoubles = true, "")) { + if (m.returnType?.resolveAlias()?.isNotPrimitive == false) continue - val returnType = m.returnType?.resolve()?.toTypeName() ?: continue + val returnType = m.returnType?.resolveAlias()?.toTypeName() ?: continue val provTypeName = wrapHelper.nonWrappedType(returnType) val isCached = m.getAnnotationsByType(Provide::class) .firstOrNull()?.cache !in listOf(Provide.CacheType.Factory, null) diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/invokecall/model/FieldDetail.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/invokecall/model/FieldDetail.kt index 8645e891..4d382ee2 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/invokecall/model/FieldDetail.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/invokecall/model/FieldDetail.kt @@ -1,6 +1,7 @@ package com.github.klee0kai.thekey.stone.ksp.helpers.invokecall.model import com.github.klee0kai.thekey.stone.ksp.helpers.qualifierAnnotations +import com.github.klee0kai.thekey.stone.ksp.ksp.resolveAlias import com.google.devtools.ksp.symbol.KSValueParameter import com.squareup.kotlinpoet.TypeName import com.squareup.kotlinpoet.ksp.toTypeName @@ -19,7 +20,7 @@ fun FieldDetail.Companion.simple(name: String, type: TypeName) = FieldDetail(nam fun KSValueParameter.toFieldDetail() = FieldDetail( name = name?.asString() ?: "it", - type = type.resolve().toTypeName(), + type = type.resolveAlias().toTypeName().copy(nullable = false), qualifierAnns = qualifierAnnotations.map { it.toQualifierAnn() }.toSet(), ) diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/ksp/KSClassDeclarationExt.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/ksp/KSClassDeclarationExt.kt index a9b6028b..d82b356a 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/ksp/KSClassDeclarationExt.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/ksp/KSClassDeclarationExt.kt @@ -1,6 +1,7 @@ package com.github.klee0kai.thekey.stone.ksp.ksp import com.github.klee0kai.thekey.stone.ksp.utils.removeDoubles +import com.github.klee0kai.thekey.stone.ksp.utils.then import com.google.devtools.ksp.getAllSuperTypes import com.google.devtools.ksp.getDeclaredFunctions import com.google.devtools.ksp.symbol.* @@ -53,6 +54,8 @@ fun KSClassDeclaration.getAllMethods( } val allMethods = mutableListOf() + allMethods.addAll(getDeclaredFunctions()) + getAllSuperTypes().forEach { superType -> allMethods.addAll( (superType.declaration as KSClassDeclaration) @@ -63,15 +66,14 @@ fun KSClassDeclaration.getAllMethods( ) ) } - allMethods.addAll(getDeclaredFunctions()) yieldAll( allMethods - .filter { - it.simpleName.asString() !in exceptNames - } - .removeDoubles { it1, it2 -> - it1.isSameMethods(it2) + .filter { it.simpleName.asString() !in exceptNames } + .then(!allowDoubles) { + removeDoubles { it1, it2 -> + it1.isSameMethods(it2) + } } ) } diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/utils/CommonExt.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/utils/CommonExt.kt new file mode 100644 index 00000000..a6151ea0 --- /dev/null +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/utils/CommonExt.kt @@ -0,0 +1,10 @@ +package com.github.klee0kai.thekey.stone.ksp.utils + +inline fun T.then( + condition: Boolean, + block: T.() -> T, +) = if (condition) { + block() +} else { + this +} diff --git a/tests/src/main/java/com/github/klee0kai/test/di/base_forest/IdentityModule.kt b/tests/src/main/java/com/github/klee0kai/test/di/base_forest/IdentityModule.kt index e3c8b4e9..c71bb87c 100644 --- a/tests/src/main/java/com/github/klee0kai/test/di/base_forest/IdentityModule.kt +++ b/tests/src/main/java/com/github/klee0kai/test/di/base_forest/IdentityModule.kt @@ -9,6 +9,7 @@ import com.github.klee0kai.test.mowgli.identity.Knowledge @Module interface IdentityModule { + @Provide(cache = Provide.CacheType.Factory) fun knowledge(): Knowledge? diff --git a/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/di/techfactory/TechFactoryExtComponent.kt b/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/di/techfactory/TechFactoryExtComponent.kt index 3874e894..e418fb4b 100644 --- a/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/di/techfactory/TechFactoryExtComponent.kt +++ b/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/di/techfactory/TechFactoryExtComponent.kt @@ -6,7 +6,11 @@ import com.github.klee0kai.test.di.techfactory.TechFactoryComponent import com.github.klee0kai.test_ext.inject.di.techfactory.identifiers.Frequency -@Component(identifiers = [Frequency::class]) +@Component( + identifiers = [ + Frequency::class + ], +) interface TechFactoryExtComponent : TechFactoryComponent, ITechProviderExtComponent { override fun factory(): TechFactoryExtModule? From c99a4b43d7d63689fce03fdb69e640da34d3f0b2 Mon Sep 17 00:00:00 2001 From: klee0kai Date: Mon, 15 Dec 2025 00:00:00 +0100 Subject: [PATCH 072/122] correct same method check --- .../stone/ksp/ksp/KSFunctionDeclarationExt.kt | 5 ++-- .../module/GenModuleCacheControlProcessor.kt | 28 +++++++++---------- 2 files changed, 17 insertions(+), 16 deletions(-) diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/ksp/KSFunctionDeclarationExt.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/ksp/KSFunctionDeclarationExt.kt index 56768754..4d259df5 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/ksp/KSFunctionDeclarationExt.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/ksp/KSFunctionDeclarationExt.kt @@ -12,7 +12,7 @@ fun KSFunctionDeclaration.isSameMethods( return false } for (idx in parameters.indices) { - if (parameters[idx].type != other.parameters[idx].type) { + if (parameters[idx].type.resolve() != other.parameters[idx].type.resolve()) { return false } } @@ -24,7 +24,8 @@ fun KSFunctionDeclaration.joinInvokeArguments( availableVariables: List, ): String { return parameters.mapNotNull { parameter -> - val availableVariable = availableVariables.firstOrNull { it.type.resolveAlias() == parameter.type.resolveAlias() } + val availableVariable = availableVariables + .firstOrNull { it.type.resolveAlias() == parameter.type.resolveAlias() } if (availableVariable != null) { "${parameter.name!!.asString()} = ${availableVariable.name!!.asString()}" } else { diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/module/GenModuleCacheControlProcessor.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/module/GenModuleCacheControlProcessor.kt index 0b1eb077..49d4bc1b 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/module/GenModuleCacheControlProcessor.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/module/GenModuleCacheControlProcessor.kt @@ -82,23 +82,23 @@ class GenModuleCacheControlProcessor : TargetFileProcessor { addParameter("__params", SwitchCacheParam::class) } - validSymbol.getAllMethods(false, false, "") - .forEachFun { _, function -> - val idArguments = function.parameters.identifierParameters(identifierTypes) + val methods = validSymbol.getAllMethods(includeObjectMethods = false, allowDoubles = false, "") + methods.forEachFun { _, function -> + val idArguments = function.parameters.identifierParameters(identifierTypes) - genOverrideFun(function) { - modifiers.remove(KModifier.OVERRIDE) - modifiers.add(KModifier.ABSTRACT) - } - genFun(function.cacheControlMethodName) { - modifiers.add(KModifier.ABSTRACT) - returns(returnType = function.returnType!!.resolve().toTypeName().copy(nullable = true)) - addParameter("__action", CacheAction::class) - idArguments.forEach { - addParameter(it.name!!.asString(), it.type.resolve().toTypeName()) - } + genOverrideFun(function) { + modifiers.remove(KModifier.OVERRIDE) + modifiers.add(KModifier.ABSTRACT) + } + genFun(function.cacheControlMethodName) { + modifiers.add(KModifier.ABSTRACT) + returns(returnType = function.returnType!!.resolve().toTypeName().copy(nullable = true)) + addParameter("__action", CacheAction::class) + idArguments.forEach { + addParameter(it.name!!.asString(), it.type.resolve().toTypeName()) } } + } } } From 0c2fc125374074f73a0d2bb15847a47b10fc1f75 Mon Sep 17 00:00:00 2001 From: klee0kai Date: Thu, 18 Dec 2025 21:49:57 +0100 Subject: [PATCH 073/122] ext of method --- .../github/klee0kai/thekey/stone/ksp/Processor.kt | 2 +- .../thekey/stone/ksp/ksp/KSFunctionDeclarationExt.kt | 10 +++++++++- .../ksp/target/component/GenComponentProcessor.kt | 12 +++++++++--- .../test_ext/inject/di/gcforest/GcEarthExtModule.kt | 2 +- 4 files changed, 20 insertions(+), 6 deletions(-) diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/Processor.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/Processor.kt index a71af671..50333f7f 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/Processor.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/Processor.kt @@ -63,7 +63,7 @@ class Processor( // force changes // debug = true -// debugPkgFilter = "com.github.klee0kai.test_ext.inject.di.techfactory" +// debugPkgFilter = "com.github.klee0kai.test_ext.inject.di.base_phone" } diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/ksp/KSFunctionDeclarationExt.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/ksp/KSFunctionDeclarationExt.kt index 4d259df5..0183dcfb 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/ksp/KSFunctionDeclarationExt.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/ksp/KSFunctionDeclarationExt.kt @@ -27,7 +27,15 @@ fun KSFunctionDeclaration.joinInvokeArguments( val availableVariable = availableVariables .firstOrNull { it.type.resolveAlias() == parameter.type.resolveAlias() } if (availableVariable != null) { - "${parameter.name!!.asString()} = ${availableVariable.name!!.asString()}" + val notNullablePostFix = if (availableVariable.type.resolve().isMarkedNullable + && !parameter.type.resolve().isMarkedNullable + ) { + "!!" + } else { + "" + } + + "${parameter.name!!.asString()} = ${availableVariable.name!!.asString()}${notNullablePostFix}" } else { null } diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/component/GenComponentProcessor.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/component/GenComponentProcessor.kt index b563ed03..4e5bdedc 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/component/GenComponentProcessor.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/component/GenComponentProcessor.kt @@ -31,7 +31,6 @@ import com.github.klee0kai.thekey.stone.ksp.poet.* import com.github.klee0kai.thekey.stone.ksp.target.module.GenModuleProcessor import com.google.devtools.ksp.KspExperimental import com.google.devtools.ksp.containingFile -import com.google.devtools.ksp.getAllSuperTypes import com.google.devtools.ksp.getAnnotationsByType import com.google.devtools.ksp.processing.KSPLogger import com.google.devtools.ksp.processing.Resolver @@ -206,7 +205,14 @@ class GenComponentProcessor : TargetFileProcessor { } m.isExtOfMethod(componentCl) -> { - + genOverrideFun(m) { + addCode( + "(%L as? %T)?.let{ %L(it) }", + parameters.first().name, + IPrivateComponent::class.asClassName(), + extOfMethodName + ) + } } m.isObjectProvideMethod -> { @@ -732,7 +738,7 @@ class GenComponentProcessor : TargetFileProcessor { addModifiers(KModifier.OVERRIDE) addParameter("c", IPrivateComponent::class) - for (proto in componentCl.getAllSuperTypes().mapNotNull { it.declaration as? KSClassDeclaration }) { + for (proto in componentCl.allParentDeclarations) { if (proto.toClassName() == IPrivateComponent::class.asClassName()) continue val provideModuleMethods = proto .getAllMethods(includeObjectMethods = false, allowDoubles = false) diff --git a/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/di/gcforest/GcEarthExtModule.kt b/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/di/gcforest/GcEarthExtModule.kt index c288a534..2d889156 100644 --- a/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/di/gcforest/GcEarthExtModule.kt +++ b/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/di/gcforest/GcEarthExtModule.kt @@ -20,7 +20,7 @@ abstract class GcEarthExtModule : GcEarthModule() { abstract fun desertWeak(): Desert? @Provide(cache = Provide.CacheType.Factory) - fun desertFactory(): Desert { + open fun desertFactory(): Desert { return Desert() } From 406ad48d111e8a4fe500b61dfe71bd22a22d5db7 Mon Sep 17 00:00:00 2001 From: klee0kai Date: Fri, 19 Dec 2025 00:06:47 +0100 Subject: [PATCH 074/122] Rename .java to .kt --- ...medExtProtectTest.java => GodRebrandingAimedExtProtectTest.kt} | 0 .../{GodRebrandingAimedTest.java => GodRebrandingAimedTest.kt} | 0 ...etExtProtectTest.java => GodRebrandingPlanetExtProtectTest.kt} | 0 .../{GodRebrandingPlanetTest.java => GodRebrandingPlanetTest.kt} | 0 .../simple/{GodRebrandingTest.java => GodRebrandingTest.kt} | 0 .../simple_inject/{OldInjectTests.java => OldInjectTests.kt} | 0 .../singlemethod/{ExtPlanetTests.java => ExtPlanetTests.kt} | 0 .../{PlanetSputniksTests.java => PlanetSputniksTests.kt} | 0 .../singlemethod/{StarProvideTests.java => StarProvideTests.kt} | 0 .../{ExtPlanetRollingTests.java => ExtPlanetRollingTests.kt} | 0 ...{PlanetRollingAndProTests.java => PlanetRollingAndProTests.kt} | 0 ...lanetRollingFromProTests.java => PlanetRollingFromProTests.kt} | 0 .../{EarthCacheAndProTests.java => EarthCacheAndProTests.kt} | 0 .../{EarthCacheFromProTests.java => EarthCacheFromProTests.kt} | 0 .../cache/{EarthCacheMixedTests.java => EarthCacheMixedTests.kt} | 0 .../{EarthCacheProMixedTests.java => EarthCacheProMixedTests.kt} | 0 ...SwitchCacheAndProTests.java => EarthSwitchCacheAndProTests.kt} | 0 ...itchCacheFromProTests.java => EarthSwitchCacheFromProTests.kt} | 0 ...CacheFromProtoTests.java => EarthSwitchCacheFromProtoTests.kt} | 0 ...{ExtEarthSwitchCacheTests.java => ExtEarthSwitchCacheTests.kt} | 0 .../gc/{ExtEarthLastDayTests.java => ExtEarthLastDayTests.kt} | 0 21 files changed, 0 insertions(+), 0 deletions(-) rename tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/bindinstance/simple/{GodRebrandingAimedExtProtectTest.java => GodRebrandingAimedExtProtectTest.kt} (100%) rename tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/bindinstance/simple/{GodRebrandingAimedTest.java => GodRebrandingAimedTest.kt} (100%) rename tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/bindinstance/simple/{GodRebrandingPlanetExtProtectTest.java => GodRebrandingPlanetExtProtectTest.kt} (100%) rename tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/bindinstance/simple/{GodRebrandingPlanetTest.java => GodRebrandingPlanetTest.kt} (100%) rename tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/bindinstance/simple/{GodRebrandingTest.java => GodRebrandingTest.kt} (100%) rename tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/bindinstance/simple_inject/{OldInjectTests.java => OldInjectTests.kt} (100%) rename tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/bindinstance/singlemethod/{ExtPlanetTests.java => ExtPlanetTests.kt} (100%) rename tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/bindinstance/singlemethod/{PlanetSputniksTests.java => PlanetSputniksTests.kt} (100%) rename tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/bindinstance/singlemethod/{StarProvideTests.java => StarProvideTests.kt} (100%) rename tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/bindinstance/singlemethod_gc/{ExtPlanetRollingTests.java => ExtPlanetRollingTests.kt} (100%) rename tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/bindinstance/singlemethod_gc/{PlanetRollingAndProTests.java => PlanetRollingAndProTests.kt} (100%) rename tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/bindinstance/singlemethod_gc/{PlanetRollingFromProTests.java => PlanetRollingFromProTests.kt} (100%) rename tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/cache/{EarthCacheAndProTests.java => EarthCacheAndProTests.kt} (100%) rename tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/cache/{EarthCacheFromProTests.java => EarthCacheFromProTests.kt} (100%) rename tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/cache/{EarthCacheMixedTests.java => EarthCacheMixedTests.kt} (100%) rename tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/cache/{EarthCacheProMixedTests.java => EarthCacheProMixedTests.kt} (100%) rename tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/cache/{EarthSwitchCacheAndProTests.java => EarthSwitchCacheAndProTests.kt} (100%) rename tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/cache/{EarthSwitchCacheFromProTests.java => EarthSwitchCacheFromProTests.kt} (100%) rename tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/cache/{EarthSwitchCacheFromProtoTests.java => EarthSwitchCacheFromProtoTests.kt} (100%) rename tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/cache/{ExtEarthSwitchCacheTests.java => ExtEarthSwitchCacheTests.kt} (100%) rename tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/gc/{ExtEarthLastDayTests.java => ExtEarthLastDayTests.kt} (100%) diff --git a/tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/bindinstance/simple/GodRebrandingAimedExtProtectTest.java b/tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/bindinstance/simple/GodRebrandingAimedExtProtectTest.kt similarity index 100% rename from tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/bindinstance/simple/GodRebrandingAimedExtProtectTest.java rename to tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/bindinstance/simple/GodRebrandingAimedExtProtectTest.kt diff --git a/tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/bindinstance/simple/GodRebrandingAimedTest.java b/tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/bindinstance/simple/GodRebrandingAimedTest.kt similarity index 100% rename from tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/bindinstance/simple/GodRebrandingAimedTest.java rename to tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/bindinstance/simple/GodRebrandingAimedTest.kt diff --git a/tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/bindinstance/simple/GodRebrandingPlanetExtProtectTest.java b/tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/bindinstance/simple/GodRebrandingPlanetExtProtectTest.kt similarity index 100% rename from tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/bindinstance/simple/GodRebrandingPlanetExtProtectTest.java rename to tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/bindinstance/simple/GodRebrandingPlanetExtProtectTest.kt diff --git a/tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/bindinstance/simple/GodRebrandingPlanetTest.java b/tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/bindinstance/simple/GodRebrandingPlanetTest.kt similarity index 100% rename from tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/bindinstance/simple/GodRebrandingPlanetTest.java rename to tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/bindinstance/simple/GodRebrandingPlanetTest.kt diff --git a/tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/bindinstance/simple/GodRebrandingTest.java b/tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/bindinstance/simple/GodRebrandingTest.kt similarity index 100% rename from tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/bindinstance/simple/GodRebrandingTest.java rename to tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/bindinstance/simple/GodRebrandingTest.kt diff --git a/tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/bindinstance/simple_inject/OldInjectTests.java b/tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/bindinstance/simple_inject/OldInjectTests.kt similarity index 100% rename from tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/bindinstance/simple_inject/OldInjectTests.java rename to tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/bindinstance/simple_inject/OldInjectTests.kt diff --git a/tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/bindinstance/singlemethod/ExtPlanetTests.java b/tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/bindinstance/singlemethod/ExtPlanetTests.kt similarity index 100% rename from tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/bindinstance/singlemethod/ExtPlanetTests.java rename to tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/bindinstance/singlemethod/ExtPlanetTests.kt diff --git a/tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/bindinstance/singlemethod/PlanetSputniksTests.java b/tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/bindinstance/singlemethod/PlanetSputniksTests.kt similarity index 100% rename from tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/bindinstance/singlemethod/PlanetSputniksTests.java rename to tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/bindinstance/singlemethod/PlanetSputniksTests.kt diff --git a/tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/bindinstance/singlemethod/StarProvideTests.java b/tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/bindinstance/singlemethod/StarProvideTests.kt similarity index 100% rename from tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/bindinstance/singlemethod/StarProvideTests.java rename to tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/bindinstance/singlemethod/StarProvideTests.kt diff --git a/tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/bindinstance/singlemethod_gc/ExtPlanetRollingTests.java b/tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/bindinstance/singlemethod_gc/ExtPlanetRollingTests.kt similarity index 100% rename from tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/bindinstance/singlemethod_gc/ExtPlanetRollingTests.java rename to tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/bindinstance/singlemethod_gc/ExtPlanetRollingTests.kt diff --git a/tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/bindinstance/singlemethod_gc/PlanetRollingAndProTests.java b/tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/bindinstance/singlemethod_gc/PlanetRollingAndProTests.kt similarity index 100% rename from tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/bindinstance/singlemethod_gc/PlanetRollingAndProTests.java rename to tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/bindinstance/singlemethod_gc/PlanetRollingAndProTests.kt diff --git a/tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/bindinstance/singlemethod_gc/PlanetRollingFromProTests.java b/tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/bindinstance/singlemethod_gc/PlanetRollingFromProTests.kt similarity index 100% rename from tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/bindinstance/singlemethod_gc/PlanetRollingFromProTests.java rename to tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/bindinstance/singlemethod_gc/PlanetRollingFromProTests.kt diff --git a/tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/cache/EarthCacheAndProTests.java b/tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/cache/EarthCacheAndProTests.kt similarity index 100% rename from tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/cache/EarthCacheAndProTests.java rename to tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/cache/EarthCacheAndProTests.kt diff --git a/tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/cache/EarthCacheFromProTests.java b/tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/cache/EarthCacheFromProTests.kt similarity index 100% rename from tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/cache/EarthCacheFromProTests.java rename to tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/cache/EarthCacheFromProTests.kt diff --git a/tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/cache/EarthCacheMixedTests.java b/tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/cache/EarthCacheMixedTests.kt similarity index 100% rename from tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/cache/EarthCacheMixedTests.java rename to tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/cache/EarthCacheMixedTests.kt diff --git a/tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/cache/EarthCacheProMixedTests.java b/tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/cache/EarthCacheProMixedTests.kt similarity index 100% rename from tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/cache/EarthCacheProMixedTests.java rename to tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/cache/EarthCacheProMixedTests.kt diff --git a/tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/cache/EarthSwitchCacheAndProTests.java b/tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/cache/EarthSwitchCacheAndProTests.kt similarity index 100% rename from tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/cache/EarthSwitchCacheAndProTests.java rename to tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/cache/EarthSwitchCacheAndProTests.kt diff --git a/tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/cache/EarthSwitchCacheFromProTests.java b/tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/cache/EarthSwitchCacheFromProTests.kt similarity index 100% rename from tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/cache/EarthSwitchCacheFromProTests.java rename to tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/cache/EarthSwitchCacheFromProTests.kt diff --git a/tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/cache/EarthSwitchCacheFromProtoTests.java b/tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/cache/EarthSwitchCacheFromProtoTests.kt similarity index 100% rename from tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/cache/EarthSwitchCacheFromProtoTests.java rename to tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/cache/EarthSwitchCacheFromProtoTests.kt diff --git a/tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/cache/ExtEarthSwitchCacheTests.java b/tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/cache/ExtEarthSwitchCacheTests.kt similarity index 100% rename from tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/cache/ExtEarthSwitchCacheTests.java rename to tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/cache/ExtEarthSwitchCacheTests.kt diff --git a/tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/gc/ExtEarthLastDayTests.java b/tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/gc/ExtEarthLastDayTests.kt similarity index 100% rename from tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/gc/ExtEarthLastDayTests.java rename to tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/gc/ExtEarthLastDayTests.kt From 5463092d1fe3c84a2f381e364666b7d4821e3b9c Mon Sep 17 00:00:00 2001 From: klee0kai Date: Fri, 19 Dec 2025 00:06:47 +0100 Subject: [PATCH 075/122] migrate tests ext to kotlin --- .../GodRebrandingAimedExtProtectTest.kt | 112 ++- .../simple/GodRebrandingAimedTest.kt | 110 ++- .../GodRebrandingPlanetExtProtectTest.kt | 110 ++- .../simple/GodRebrandingPlanetTest.kt | 110 ++- .../bindinstance/simple/GodRebrandingTest.kt | 110 ++- .../simple_inject/OldInjectTests.kt | 119 ++- .../singlemethod/ExtPlanetTests.kt | 114 ++- .../singlemethod/PlanetSputniksTests.kt | 116 ++- .../singlemethod/StarProvideTests.kt | 87 ++- .../singlemethod_gc/ExtPlanetRollingTests.kt | 706 +++++++++--------- .../PlanetRollingAndProTests.kt | 516 +++++++------ .../PlanetRollingFromProTests.kt | 515 +++++++------ .../text_ext/cache/EarthCacheAndProTests.kt | 156 ++-- .../text_ext/cache/EarthCacheFromProTests.kt | 175 +++-- .../text_ext/cache/EarthCacheMixedTests.kt | 176 +++-- .../text_ext/cache/EarthCacheProMixedTests.kt | 176 ++--- .../cache/EarthSwitchCacheAndProTests.kt | 107 ++- .../cache/EarthSwitchCacheFromProTests.kt | 110 ++- .../cache/EarthSwitchCacheFromProtoTests.kt | 107 ++- .../cache/ExtEarthSwitchCacheTests.kt | 89 +-- .../stone/text_ext/gc/ExtEarthLastDayTests.kt | 556 +++++++------- 21 files changed, 2169 insertions(+), 2208 deletions(-) diff --git a/tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/bindinstance/simple/GodRebrandingAimedExtProtectTest.kt b/tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/bindinstance/simple/GodRebrandingAimedExtProtectTest.kt index d1749fd4..3f8954d9 100644 --- a/tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/bindinstance/simple/GodRebrandingAimedExtProtectTest.kt +++ b/tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/bindinstance/simple/GodRebrandingAimedExtProtectTest.kt @@ -1,102 +1,100 @@ -package com.dirgub.klee0kai.stone.text_ext.bindinstance.simple; +package com.dirgub.klee0kai.stone.text_ext.bindinstance.simple -import com.github.klee0kai.stone.Stone; -import com.github.klee0kai.test.di.bindinstance.simple.GodWorkspaceComponent; -import com.github.klee0kai.test.mowgli.galaxy.Earth; -import com.github.klee0kai.test_ext.inject.di.bindinstance.simple.GodRebrandingComponent; -import org.junit.jupiter.api.Test; +import com.github.klee0kai.test.di.bindinstance.simple.GodWorkspaceComponentStoneComponent +import com.github.klee0kai.test.mowgli.galaxy.Earth +import com.github.klee0kai.test_ext.inject.di.bindinstance.simple.GodRebrandingComponentStoneComponent +import org.junit.jupiter.api.Assertions.assertEquals +import org.junit.jupiter.api.Test +import org.junit.jupiter.api.assertNull -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNull; - -public class GodRebrandingAimedExtProtectTest { +class GodRebrandingAimedExtProtectTest { @Test - public void createdIsReusableTest() { + fun createdIsReusableTest() { // Given - GodWorkspaceComponent DI = Stone.createComponent(GodWorkspaceComponent.class); - Earth earth = new Earth(); - DI.bindEarth(earth); + val DI = GodWorkspaceComponentStoneComponent() + val earth = Earth() + DI.bindEarth(earth) //When - GodRebrandingComponent DIPro = Stone.createComponent(GodRebrandingComponent.class); - DIPro.extendComponent(DI); + val DIPro = GodRebrandingComponentStoneComponent() + DIPro.extendComponent(DI) //Then - assertEquals(earth, DI.sunSystem().earth()); - assertEquals(earth, DIPro.sunSystem().earth()); - assertNull(DI.sunSystem().planet()); - assertNull(DIPro.sunSystem().planet()); + assertEquals(earth, DI.sunSystem().earth()) + assertEquals(earth, DIPro.sunSystem().earth()) + assertNull(DI.sunSystem().planet()) + assertNull(DIPro.sunSystem().planet()) } @Test - public void createdAfterRebrandingTest() { + fun createdAfterRebrandingTest() { // Given - GodWorkspaceComponent DI = Stone.createComponent(GodWorkspaceComponent.class); - GodRebrandingComponent DIPro = Stone.createComponent(GodRebrandingComponent.class); - DIPro.extendComponent(DI); - Earth earth = new Earth(); + val DI = GodWorkspaceComponentStoneComponent() + val DIPro = GodRebrandingComponentStoneComponent() + DIPro.extendComponent(DI) + val earth = Earth() //When - DI.bindEarth(earth); + DI.bindEarth(earth) //Then - assertEquals(earth, DI.sunSystem().earth()); - assertEquals(earth, DIPro.sunSystem().earth()); - assertNull(DI.sunSystem().planet()); - assertNull(DIPro.sunSystem().planet()); + assertEquals(earth, DI.sunSystem().earth()) + assertEquals(earth, DIPro.sunSystem().earth()) + assertNull(DI.sunSystem().planet()) + assertNull(DIPro.sunSystem().planet()) } @Test - public void rebrandedSunTest() { + fun rebrandedSunTest() { // Given - GodWorkspaceComponent DI = Stone.createComponent(GodWorkspaceComponent.class); - Earth earth1 = new Earth(); - Earth earth2 = new Earth(); - DI.bindEarth(earth1); + val DI = GodWorkspaceComponentStoneComponent() + val earth1 = Earth() + val earth2 = Earth() + DI.bindEarth(earth1) //When - GodRebrandingComponent DIPro = Stone.createComponent(GodRebrandingComponent.class); - DIPro.extendComponent(DI); - DIPro.bindEarth(earth2); + val DIPro = GodRebrandingComponentStoneComponent() + DIPro.extendComponent(DI) + DIPro.bindEarth(earth2) //Then - assertEquals(earth2, DI.sunSystem().earth()); - assertEquals(earth2, DIPro.sunSystem().earth()); - assertNull(DI.sunSystem().planet()); - assertNull(DIPro.sunSystem().planet()); + assertEquals(earth2, DI.sunSystem().earth()) + assertEquals(earth2, DIPro.sunSystem().earth()) + assertNull(DI.sunSystem().planet()) + assertNull(DIPro.sunSystem().planet()) } @Test - public void updatedAfterRebrandingSunTest() { + fun updatedAfterRebrandingSunTest() { // Given - GodWorkspaceComponent DI = Stone.createComponent(GodWorkspaceComponent.class); - Earth earth1 = new Earth(); - Earth earth2 = new Earth(); - Earth earth3 = new Earth(); - DI.bindEarth(earth1); - GodRebrandingComponent DIPro = Stone.createComponent(GodRebrandingComponent.class); - DIPro.extendComponent(DI); - DIPro.bindEarth(earth2); + val DI = GodWorkspaceComponentStoneComponent() + val earth1 = Earth() + val earth2 = Earth() + val earth3 = Earth() + DI.bindEarth(earth1) + + val DIPro = GodRebrandingComponentStoneComponent() + DIPro.extendComponent(DI) + DIPro.bindEarth(earth2) //When - DI.bindEarth(earth3); + DI.bindEarth(earth3) //Then - assertEquals(earth3, DI.sunSystem().earth()); - assertEquals(earth3, DIPro.sunSystem().earth()); - assertNull(DI.sunSystem().planet()); - assertNull(DIPro.sunSystem().planet()); + assertEquals(earth3, DI.sunSystem().earth()) + assertEquals(earth3, DIPro.sunSystem().earth()) + assertNull(DI.sunSystem().planet()) + assertNull(DIPro.sunSystem().planet()) } - } diff --git a/tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/bindinstance/simple/GodRebrandingAimedTest.kt b/tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/bindinstance/simple/GodRebrandingAimedTest.kt index 71cc312a..e40ad548 100644 --- a/tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/bindinstance/simple/GodRebrandingAimedTest.kt +++ b/tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/bindinstance/simple/GodRebrandingAimedTest.kt @@ -1,102 +1,100 @@ -package com.dirgub.klee0kai.stone.text_ext.bindinstance.simple; +package com.dirgub.klee0kai.stone.text_ext.bindinstance.simple -import com.github.klee0kai.stone.Stone; -import com.github.klee0kai.test.di.bindinstance.simple.GodWorkspaceComponent; -import com.github.klee0kai.test.mowgli.galaxy.Earth; -import com.github.klee0kai.test_ext.inject.di.bindinstance.simple.GodRebrandingComponent; -import org.junit.jupiter.api.Test; +import com.github.klee0kai.test.di.bindinstance.simple.GodWorkspaceComponentStoneComponent +import com.github.klee0kai.test.mowgli.galaxy.Earth +import com.github.klee0kai.test_ext.inject.di.bindinstance.simple.GodRebrandingComponentStoneComponent +import org.junit.jupiter.api.Assertions.assertEquals +import org.junit.jupiter.api.Test +import org.junit.jupiter.api.assertNull -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNull; - -public class GodRebrandingAimedTest { +class GodRebrandingAimedTest { @Test - public void createdIsReusableTest() { + fun createdIsReusableTest() { // Given - GodWorkspaceComponent DI = Stone.createComponent(GodWorkspaceComponent.class); - Earth earth = new Earth(); - DI.bindEarth(earth); + val DI = GodWorkspaceComponentStoneComponent() + val earth = Earth() + DI.bindEarth(earth) //When - GodRebrandingComponent DIPro = Stone.createComponent(GodRebrandingComponent.class); - DIPro.extendComponent(DI); + val DIPro = GodRebrandingComponentStoneComponent() + DIPro.extendComponent(DI) //Then - assertEquals(earth, DI.sunSystem().earth()); - assertEquals(earth, DIPro.sunSystem().earth()); - assertNull(DI.sunSystem().planet()); - assertNull(DIPro.sunSystem().planet()); + assertEquals(earth, DI.sunSystem().earth()) + assertEquals(earth, DIPro.sunSystem().earth()) + assertNull(DI.sunSystem().planet()) + assertNull(DIPro.sunSystem().planet()) } @Test - public void createdAfterRebrandingTest() { + fun createdAfterRebrandingTest() { // Given - GodWorkspaceComponent DI = Stone.createComponent(GodWorkspaceComponent.class); - GodRebrandingComponent DIPro = Stone.createComponent(GodRebrandingComponent.class); - DIPro.extendComponent(DI); - Earth earth = new Earth(); + val DI = GodWorkspaceComponentStoneComponent() + val DIPro = GodRebrandingComponentStoneComponent() + DIPro.extendComponent(DI) + val earth = Earth() //When - DI.bindEarth(earth); + DI.bindEarth(earth) //Then - assertEquals(earth, DI.sunSystem().earth()); - assertEquals(earth, DIPro.sunSystem().earth()); - assertNull(DI.sunSystem().planet()); - assertNull(DIPro.sunSystem().planet()); + assertEquals(earth, DI.sunSystem().earth()) + assertEquals(earth, DIPro.sunSystem().earth()) + assertNull(DI.sunSystem().planet()) + assertNull(DIPro.sunSystem().planet()) } @Test - public void rebrandedSunTest() { + fun rebrandedSunTest() { // Given - GodWorkspaceComponent DI = Stone.createComponent(GodWorkspaceComponent.class); - Earth earth1 = new Earth(); - Earth earth2 = new Earth(); - DI.bindEarth(earth1); + val DI = GodWorkspaceComponentStoneComponent() + val earth1 = Earth() + val earth2 = Earth() + DI.bindEarth(earth1) //When - GodRebrandingComponent DIPro = Stone.createComponent(GodRebrandingComponent.class); - DIPro.extendComponent(DI); - DIPro.bindEarth(earth2); + val DIPro = GodRebrandingComponentStoneComponent() + DIPro.extendComponent(DI) + DIPro.bindEarth(earth2) //Then - assertEquals(earth2, DI.sunSystem().earth()); - assertEquals(earth2, DIPro.sunSystem().earth()); - assertNull(DI.sunSystem().planet()); - assertNull(DIPro.sunSystem().planet()); + assertEquals(earth2, DI.sunSystem().earth()) + assertEquals(earth2, DIPro.sunSystem().earth()) + assertNull(DI.sunSystem().planet()) + assertNull(DIPro.sunSystem().planet()) } @Test - public void updatedAfterRebrandingSunTest() { + fun updatedAfterRebrandingSunTest() { // Given - GodWorkspaceComponent DI = Stone.createComponent(GodWorkspaceComponent.class); - Earth earth1 = new Earth(); - Earth earth2 = new Earth(); - Earth earth3 = new Earth(); - DI.bindEarth(earth1); - GodRebrandingComponent DIPro = Stone.createComponent(GodRebrandingComponent.class); - DIPro.extendComponent(DI); - DIPro.bindEarth(earth2); + val DI = GodWorkspaceComponentStoneComponent() + val earth1 = Earth() + val earth2 = Earth() + val earth3 = Earth() + DI.bindEarth(earth1) + val DIPro = GodRebrandingComponentStoneComponent() + DIPro.extendComponent(DI) + DIPro.bindEarth(earth2) //When - DI.bindEarth(earth3); + DI.bindEarth(earth3) //Then - assertEquals(earth3, DI.sunSystem().earth()); - assertEquals(earth3, DIPro.sunSystem().earth()); - assertNull(DI.sunSystem().planet()); - assertNull(DIPro.sunSystem().planet()); + assertEquals(earth3, DI.sunSystem().earth()) + assertEquals(earth3, DIPro.sunSystem().earth()) + assertNull(DI.sunSystem().planet()) + assertNull(DIPro.sunSystem().planet()) } } diff --git a/tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/bindinstance/simple/GodRebrandingPlanetExtProtectTest.kt b/tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/bindinstance/simple/GodRebrandingPlanetExtProtectTest.kt index 838c028e..26e66784 100644 --- a/tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/bindinstance/simple/GodRebrandingPlanetExtProtectTest.kt +++ b/tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/bindinstance/simple/GodRebrandingPlanetExtProtectTest.kt @@ -1,102 +1,100 @@ -package com.dirgub.klee0kai.stone.text_ext.bindinstance.simple; +package com.dirgub.klee0kai.stone.text_ext.bindinstance.simple -import com.github.klee0kai.stone.Stone; -import com.github.klee0kai.test.di.bindinstance.simple.GodWorkspaceComponent; -import com.github.klee0kai.test.mowgli.galaxy.Earth; -import com.github.klee0kai.test_ext.inject.di.bindinstance.simple.GodRebrandingComponent; -import org.junit.jupiter.api.Test; +import com.github.klee0kai.test.di.bindinstance.simple.GodWorkspaceComponentStoneComponent +import com.github.klee0kai.test.mowgli.galaxy.Earth +import com.github.klee0kai.test_ext.inject.di.bindinstance.simple.GodRebrandingComponentStoneComponent +import org.junit.jupiter.api.Assertions.assertEquals +import org.junit.jupiter.api.Test +import org.junit.jupiter.api.assertNull -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNull; - -public class GodRebrandingPlanetExtProtectTest { +class GodRebrandingPlanetExtProtectTest { @Test - public void createdIsReusableTest() { + fun createdIsReusableTest() { // Given - GodWorkspaceComponent DI = Stone.createComponent(GodWorkspaceComponent.class); - Earth earth = new Earth(); - DI.bindPlanet(earth); + val DI = GodWorkspaceComponentStoneComponent() + val earth = Earth() + DI.bindPlanet(earth) //When - GodRebrandingComponent DIPro = Stone.createComponent(GodRebrandingComponent.class); - DIPro.extendComponent(DI); + val DIPro = GodRebrandingComponentStoneComponent() + DIPro.extendComponent(DI) //Then - assertEquals(earth, DI.sunSystem().planet()); - assertEquals(earth, DIPro.sunSystem().planet()); - assertNull(DI.sunSystem().earth()); - assertNull(DIPro.sunSystem().earth()); + assertEquals(earth, DI.sunSystem().planet()) + assertEquals(earth, DIPro.sunSystem().planet()) + assertNull(DI.sunSystem().earth()) + assertNull(DIPro.sunSystem().earth()) } @Test - public void createdAfterRebrandingTest() { + fun createdAfterRebrandingTest() { // Given - GodWorkspaceComponent DI = Stone.createComponent(GodWorkspaceComponent.class); - GodRebrandingComponent DIPro = Stone.createComponent(GodRebrandingComponent.class); - DIPro.extendComponent(DI); - Earth earth = new Earth(); + val DI = GodWorkspaceComponentStoneComponent() + val DIPro = GodRebrandingComponentStoneComponent() + DIPro.extendComponent(DI) + val earth = Earth() //When - DI.bindPlanet(earth); + DI.bindPlanet(earth) //Then - assertEquals(earth, DI.sunSystem().planet()); - assertEquals(earth, DIPro.sunSystem().planet()); - assertNull(DI.sunSystem().earth()); - assertNull(DIPro.sunSystem().earth()); + assertEquals(earth, DI.sunSystem().planet()) + assertEquals(earth, DIPro.sunSystem().planet()) + assertNull(DI.sunSystem().earth()) + assertNull(DIPro.sunSystem().earth()) } @Test - public void rebrandedSunTest() { + fun rebrandedSunTest() { // Given - GodWorkspaceComponent DI = Stone.createComponent(GodWorkspaceComponent.class); - Earth earth1 = new Earth(); - Earth earth2 = new Earth(); - DI.bindPlanet(earth1); + val DI = GodWorkspaceComponentStoneComponent() + val earth1 = Earth() + val earth2 = Earth() + DI.bindPlanet(earth1) //When - GodRebrandingComponent DIPro = Stone.createComponent(GodRebrandingComponent.class); - DIPro.extendComponent(DI); - DIPro.bindPlanet(earth2); + val DIPro = GodRebrandingComponentStoneComponent() + DIPro.extendComponent(DI) + DIPro.bindPlanet(earth2) //Then - assertEquals(earth2, DI.sunSystem().planet()); - assertEquals(earth2, DIPro.sunSystem().planet()); - assertNull(DI.sunSystem().earth()); - assertNull(DIPro.sunSystem().earth()); + assertEquals(earth2, DI.sunSystem().planet()) + assertEquals(earth2, DIPro.sunSystem().planet()) + assertNull(DI.sunSystem().earth()) + assertNull(DIPro.sunSystem().earth()) } @Test - public void updatedAfterRebrandingSunTest() { + fun updatedAfterRebrandingSunTest() { // Given - GodWorkspaceComponent DI = Stone.createComponent(GodWorkspaceComponent.class); - Earth earth1 = new Earth(); - Earth earth2 = new Earth(); - Earth earth3 = new Earth(); - DI.bindPlanet(earth1); - GodRebrandingComponent DIPro = Stone.createComponent(GodRebrandingComponent.class); - DIPro.extendComponent(DI); - DIPro.bindPlanet(earth2); + val DI = GodWorkspaceComponentStoneComponent() + val earth1 = Earth() + val earth2 = Earth() + val earth3 = Earth() + DI.bindPlanet(earth1) + val DIPro = GodRebrandingComponentStoneComponent() + DIPro.extendComponent(DI) + DIPro.bindPlanet(earth2) //When - DI.bindPlanet(earth3); + DI.bindPlanet(earth3) //Then - assertEquals(earth3, DI.sunSystem().planet()); - assertEquals(earth3, DIPro.sunSystem().planet()); - assertNull(DI.sunSystem().earth()); - assertNull(DIPro.sunSystem().earth()); + assertEquals(earth3, DI.sunSystem().planet()) + assertEquals(earth3, DIPro.sunSystem().planet()) + assertNull(DI.sunSystem().earth()) + assertNull(DIPro.sunSystem().earth()) } } diff --git a/tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/bindinstance/simple/GodRebrandingPlanetTest.kt b/tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/bindinstance/simple/GodRebrandingPlanetTest.kt index bd410d89..240764fd 100644 --- a/tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/bindinstance/simple/GodRebrandingPlanetTest.kt +++ b/tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/bindinstance/simple/GodRebrandingPlanetTest.kt @@ -1,102 +1,100 @@ -package com.dirgub.klee0kai.stone.text_ext.bindinstance.simple; +package com.dirgub.klee0kai.stone.text_ext.bindinstance.simple -import com.github.klee0kai.stone.Stone; -import com.github.klee0kai.test.di.bindinstance.simple.GodWorkspaceComponent; -import com.github.klee0kai.test.mowgli.galaxy.Earth; -import com.github.klee0kai.test_ext.inject.di.bindinstance.simple.GodRebrandingComponent; -import org.junit.jupiter.api.Test; +import com.github.klee0kai.test.di.bindinstance.simple.GodWorkspaceComponentStoneComponent +import com.github.klee0kai.test.mowgli.galaxy.Earth +import com.github.klee0kai.test_ext.inject.di.bindinstance.simple.GodRebrandingComponentStoneComponent +import org.junit.jupiter.api.Assertions.assertEquals +import org.junit.jupiter.api.Test +import org.junit.jupiter.api.assertNull -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNull; - -public class GodRebrandingPlanetTest { +class GodRebrandingPlanetTest { @Test - public void createdIsReusableTest() { + fun createdIsReusableTest() { // Given - GodWorkspaceComponent DI = Stone.createComponent(GodWorkspaceComponent.class); - Earth earth = new Earth(); - DI.bindPlanet(earth); + val DI = GodWorkspaceComponentStoneComponent() + val earth = Earth() + DI.bindPlanet(earth) //When - GodRebrandingComponent DIPro = Stone.createComponent(GodRebrandingComponent.class); - DIPro.extendComponent(DI); + val DIPro = GodRebrandingComponentStoneComponent() + DIPro.extendComponent(DI) //Then - assertEquals(earth, DI.sunSystem().planet()); - assertEquals(earth, DIPro.sunSystem().planet()); - assertNull(DI.sunSystem().earth()); - assertNull(DIPro.sunSystem().earth()); + assertEquals(earth, DI.sunSystem().planet()) + assertEquals(earth, DIPro.sunSystem().planet()) + assertNull(DI.sunSystem().earth()) + assertNull(DIPro.sunSystem().earth()) } @Test - public void createdAfterRebrandingTest() { + fun createdAfterRebrandingTest() { // Given - GodWorkspaceComponent DI = Stone.createComponent(GodWorkspaceComponent.class); - GodRebrandingComponent DIPro = Stone.createComponent(GodRebrandingComponent.class); - DIPro.extendComponent(DI); - Earth earth = new Earth(); + val DI = GodRebrandingComponentStoneComponent() + val DIPro = GodRebrandingComponentStoneComponent() + DIPro.extendComponent(DI) + val earth = Earth() //When - DI.bindPlanet(earth); + DI.bindPlanet(earth) //Then - assertEquals(earth, DI.sunSystem().planet()); - assertEquals(earth, DIPro.sunSystem().planet()); - assertNull(DI.sunSystem().earth()); - assertNull(DIPro.sunSystem().earth()); + assertEquals(earth, DI.sunSystem().planet()) + assertEquals(earth, DIPro.sunSystem().planet()) + assertNull(DI.sunSystem().earth()) + assertNull(DIPro.sunSystem().earth()) } @Test - public void rebrandedSunTest() { + fun rebrandedSunTest() { // Given - GodWorkspaceComponent DI = Stone.createComponent(GodWorkspaceComponent.class); - Earth earth1 = new Earth(); - Earth earth2 = new Earth(); - DI.bindPlanet(earth1); + val DI = GodWorkspaceComponentStoneComponent() + val earth1 = Earth() + val earth2 = Earth() + DI.bindPlanet(earth1) //When - GodRebrandingComponent DIPro = Stone.createComponent(GodRebrandingComponent.class); - DIPro.extendComponent(DI); - DIPro.bindPlanet(earth2); + val DIPro = GodRebrandingComponentStoneComponent() + DIPro.extendComponent(DI) + DIPro.bindPlanet(earth2) //Then - assertEquals(earth2, DI.sunSystem().planet()); - assertEquals(earth2, DIPro.sunSystem().planet()); - assertNull(DI.sunSystem().earth()); - assertNull(DIPro.sunSystem().earth()); + assertEquals(earth2, DI.sunSystem().planet()) + assertEquals(earth2, DIPro.sunSystem().planet()) + assertNull(DI.sunSystem().earth()) + assertNull(DIPro.sunSystem().earth()) } @Test - public void updatedAfterRebrandingSunTest() { + fun updatedAfterRebrandingSunTest() { // Given - GodWorkspaceComponent DI = Stone.createComponent(GodWorkspaceComponent.class); - Earth earth1 = new Earth(); - Earth earth2 = new Earth(); - Earth earth3 = new Earth(); - DI.bindPlanet(earth1); - GodRebrandingComponent DIPro = Stone.createComponent(GodRebrandingComponent.class); - DIPro.extendComponent(DI); - DIPro.bindPlanet(earth2); + val DI = GodWorkspaceComponentStoneComponent() + val earth1 = Earth() + val earth2 = Earth() + val earth3 = Earth() + DI.bindPlanet(earth1) + val DIPro = GodRebrandingComponentStoneComponent() + DIPro.extendComponent(DI) + DIPro.bindPlanet(earth2) //When - DI.bindPlanet(earth3); + DI.bindPlanet(earth3) //Then - assertEquals(earth3, DI.sunSystem().planet()); - assertEquals(earth3, DIPro.sunSystem().planet()); - assertNull(DI.sunSystem().earth()); - assertNull(DIPro.sunSystem().earth()); + assertEquals(earth3, DI.sunSystem().planet()) + assertEquals(earth3, DIPro.sunSystem().planet()) + assertNull(DI.sunSystem().earth()) + assertNull(DIPro.sunSystem().earth()) } } diff --git a/tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/bindinstance/simple/GodRebrandingTest.kt b/tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/bindinstance/simple/GodRebrandingTest.kt index 599a7e74..cdc12897 100644 --- a/tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/bindinstance/simple/GodRebrandingTest.kt +++ b/tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/bindinstance/simple/GodRebrandingTest.kt @@ -1,102 +1,100 @@ -package com.dirgub.klee0kai.stone.text_ext.bindinstance.simple; +package com.dirgub.klee0kai.stone.text_ext.bindinstance.simple -import com.github.klee0kai.stone.Stone; -import com.github.klee0kai.test.di.bindinstance.simple.GodWorkspaceComponent; -import com.github.klee0kai.test.mowgli.galaxy.Earth; -import com.github.klee0kai.test_ext.inject.di.bindinstance.simple.GodRebrandingComponent; -import org.junit.jupiter.api.Test; +import com.github.klee0kai.test.di.bindinstance.simple.GodWorkspaceComponentStoneComponent +import com.github.klee0kai.test.mowgli.galaxy.Earth +import com.github.klee0kai.test_ext.inject.di.bindinstance.simple.GodRebrandingComponentStoneComponent +import org.junit.jupiter.api.Assertions.assertEquals +import org.junit.jupiter.api.Test +import org.junit.jupiter.api.assertNull -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNull; - -public class GodRebrandingTest { +class GodRebrandingTest { @Test - public void createdIsReusableTest() { + fun createdIsReusableTest() { // Given - GodWorkspaceComponent DI = Stone.createComponent(GodWorkspaceComponent.class); - Earth earth = new Earth(); - DI.bindEarth(earth); + val DI = GodWorkspaceComponentStoneComponent() + val earth = Earth() + DI.bindEarth(earth) //When - GodRebrandingComponent DIPro = Stone.createComponent(GodRebrandingComponent.class); - DIPro.extendComponent(DI); + val DIPro = GodRebrandingComponentStoneComponent() + DIPro.extendComponent(DI) //Then - assertEquals(earth, DI.sunSystem().earth()); - assertEquals(earth, DIPro.sunSystem().earth()); - assertNull(DI.sunSystem().planet()); - assertNull(DIPro.sunSystem().planet()); + assertEquals(earth, DI.sunSystem().earth()) + assertEquals(earth, DIPro.sunSystem().earth()) + assertNull(DI.sunSystem().planet()) + assertNull(DIPro.sunSystem().planet()) } @Test - public void createdAfterRebrandingTest() { + fun createdAfterRebrandingTest() { // Given - GodWorkspaceComponent DI = Stone.createComponent(GodWorkspaceComponent.class); - GodRebrandingComponent DIPro = Stone.createComponent(GodRebrandingComponent.class); - DIPro.extendComponent(DI); - Earth earth = new Earth(); + val DI = GodWorkspaceComponentStoneComponent() + val DIPro = GodRebrandingComponentStoneComponent() + DIPro.extendComponent(DI) + val earth = Earth() //When - DI.bindEarth(earth); + DI.bindEarth(earth) //Then - assertEquals(earth, DI.sunSystem().earth()); - assertEquals(earth, DIPro.sunSystem().earth()); - assertNull(DI.sunSystem().planet()); - assertNull(DIPro.sunSystem().planet()); + assertEquals(earth, DI.sunSystem().earth()) + assertEquals(earth, DIPro.sunSystem().earth()) + assertNull(DI.sunSystem().planet()) + assertNull(DIPro.sunSystem().planet()) } @Test - public void rebrandedSunTest() { + fun rebrandedSunTest() { // Given - GodWorkspaceComponent DI = Stone.createComponent(GodWorkspaceComponent.class); - Earth earth1 = new Earth(); - Earth earth2 = new Earth(); - DI.bindEarth(earth1); + val DI = GodWorkspaceComponentStoneComponent() + val earth1 = Earth() + val earth2 = Earth() + DI.bindEarth(earth1) //When - GodRebrandingComponent DIPro = Stone.createComponent(GodRebrandingComponent.class); - DIPro.extendComponent(DI); - DIPro.bindEarth(earth2); + val DIPro = GodRebrandingComponentStoneComponent() + DIPro.extendComponent(DI) + DIPro.bindEarth(earth2) //Then - assertEquals(earth2, DI.sunSystem().earth()); - assertEquals(earth2, DIPro.sunSystem().earth()); - assertNull(DI.sunSystem().planet()); - assertNull(DIPro.sunSystem().planet()); + assertEquals(earth2, DI.sunSystem().earth()) + assertEquals(earth2, DIPro.sunSystem().earth()) + assertNull(DI.sunSystem().planet()) + assertNull(DIPro.sunSystem().planet()) } @Test - public void updatedAfterRebrandingSunTest() { + fun updatedAfterRebrandingSunTest() { // Given - GodWorkspaceComponent DI = Stone.createComponent(GodWorkspaceComponent.class); - Earth earth1 = new Earth(); - Earth earth2 = new Earth(); - Earth earth3 = new Earth(); - DI.bindEarth(earth1); - GodRebrandingComponent DIPro = Stone.createComponent(GodRebrandingComponent.class); - DIPro.extendComponent(DI); - DIPro.bindEarth(earth2); + val DI = GodWorkspaceComponentStoneComponent() + val earth1 = Earth() + val earth2 = Earth() + val earth3 = Earth() + DI.bindEarth(earth1) + val DIPro = GodRebrandingComponentStoneComponent() + DIPro.extendComponent(DI) + DIPro.bindEarth(earth2) //When - DI.bindEarth(earth3); + DI.bindEarth(earth3) //Then - assertEquals(earth3, DI.sunSystem().earth()); - assertEquals(earth3, DIPro.sunSystem().earth()); - assertNull(DI.sunSystem().planet()); - assertNull(DIPro.sunSystem().planet()); + assertEquals(earth3, DI.sunSystem().earth()) + assertEquals(earth3, DIPro.sunSystem().earth()) + assertNull(DI.sunSystem().planet()) + assertNull(DIPro.sunSystem().planet()) } } diff --git a/tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/bindinstance/simple_inject/OldInjectTests.kt b/tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/bindinstance/simple_inject/OldInjectTests.kt index 76e13c15..eb0cba00 100644 --- a/tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/bindinstance/simple_inject/OldInjectTests.kt +++ b/tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/bindinstance/simple_inject/OldInjectTests.kt @@ -1,118 +1,115 @@ +package com.dirgub.klee0kai.stone.text_ext.bindinstance.simple_inject -package com.dirgub.klee0kai.stone.text_ext.bindinstance.simple_inject; +import com.github.klee0kai.test.di.base_forest.ForestComponent +import com.github.klee0kai.test.di.base_forest.ForestComponentStoneComponent +import com.github.klee0kai.test.mowgli.animal.Horse +import com.github.klee0kai.test_ext.inject.di.forest.OldForestComponent +import com.github.klee0kai.test_ext.inject.di.forest.OldForestComponentStoneComponent +import com.github.klee0kai.test_ext.inject.mowgli.animal.OldHorse +import org.junit.jupiter.api.Assertions.assertFalse +import org.junit.jupiter.api.Assertions.assertTrue +import org.junit.jupiter.api.Test +import org.junit.jupiter.api.assertNotNull -import com.github.klee0kai.stone.Stone; -import com.github.klee0kai.test.di.base_forest.ForestComponent; -import com.github.klee0kai.test.mowgli.animal.Horse; -import com.github.klee0kai.test_ext.inject.di.forest.OldForestComponent; -import com.github.klee0kai.test_ext.inject.mowgli.animal.OldHorse; -import org.junit.jupiter.api.Test; - -import static org.junit.jupiter.api.Assertions.*; - - -public class OldInjectTests { +class OldInjectTests { @Test - public void oldHorseInjectTest() { + fun oldHorseInjectTest() { // Given - ForestComponent DI = Stone.createComponent(ForestComponent.class); - OldForestComponent DIPro = Stone.createComponent(OldForestComponent.class); - DIPro.extOf(DI); - OldHorse horse = new OldHorse(); + val DI = ForestComponentStoneComponent() + val DIPro = OldForestComponentStoneComponent() + DIPro.extOf(DI) + val horse = OldHorse() // When - DIPro.inject(horse); + DIPro.inject(horse) // Then - assertNotNull(horse.blood); - assertNotNull(horse.knowledge); - assertNotNull(horse.conscience); - assertNotNull(horse.oldKnowledge); - assertNotNull(horse.osteoarthritis); + assertNotNull(horse.blood) + assertNotNull(horse.knowledge) + assertNotNull(horse.conscience) + assertNotNull(horse.oldKnowledge) + assertNotNull(horse.osteoarthritis) } @Test - public void simpleProvideProTest() { + fun simpleProvideProTest() { // Given - ForestComponent DI = Stone.createComponent(ForestComponent.class); - OldForestComponent DIPro = Stone.createComponent(OldForestComponent.class); - DIPro.extOf(DI); - OldHorse horse = new OldHorse(); + val DI = ForestComponentStoneComponent() + val DIPro = OldForestComponentStoneComponent() + DIPro.extOf(DI) + val horse = OldHorse() // When - DIPro.inject(horse); + DIPro.inject(horse) // Then - assertTrue(horse.ideology.isFamilyIdeology()); - + assertTrue(horse.ideology!!.isFamilyIdeology) } @Test - public void overrideProvideTest() { + fun overrideProvideTest() { // Given - ForestComponent DI = Stone.createComponent(ForestComponent.class); - OldForestComponent DIPro = Stone.createComponent(OldForestComponent.class); - DIPro.extOf(DI); - OldHorse horse = new OldHorse(); + val DI = ForestComponentStoneComponent() + val DIPro = OldForestComponentStoneComponent() + DIPro.extOf(DI) + val horse = OldHorse() // When - DIPro.inject(horse); + DIPro.inject(horse) // Then: new items should generate from new DI component - assertTrue(horse.knowledge.isOldKnowledge()); + assertTrue(horse.knowledge!!.isOldKnowledge) } @Test - public void nonGenCacheTest() { + fun nonGenCacheTest() { // Given - ForestComponent DI = Stone.createComponent(ForestComponent.class); - Horse horse = new Horse(); + val DI: ForestComponent = ForestComponentStoneComponent() + val horse = Horse() // When - DI.inject(horse); + DI.inject(horse) // simply connect dynamic feature - OldForestComponent DIPro = Stone.createComponent(OldForestComponent.class); - DIPro.extOf(DI); - DI.inject(horse); + val DIPro: OldForestComponent = OldForestComponentStoneComponent() + DIPro.extOf(DI) + DI.inject(horse) // Then - assertFalse(horse.ideology.isFamilyIdeology()); + assertFalse(horse.ideology!!.isFamilyIdeology) } @Test - public void overrideCacheTest() { + fun overrideCacheTest() { // Given - ForestComponent DI = Stone.createComponent(ForestComponent.class); - Horse horse = new Horse(); + val DI: ForestComponent = ForestComponentStoneComponent() + val horse = Horse() // When - DI.inject(horse); + DI.inject(horse) // simply connect dynamic feature - OldForestComponent DIPro = Stone.createComponent(OldForestComponent.class); - DIPro.extOf(DI); - DI.inject(horse); + val DIPro: OldForestComponent = OldForestComponentStoneComponent() + DIPro.extOf(DI) + DI.inject(horse) //use cached component if not need use overrided - assertFalse(horse.ideology.isFamilyIdeology()); + assertFalse(horse.ideology!!.isFamilyIdeology) - OldHorse oldHorse = new OldHorse(); - DIPro.inject(oldHorse); + val oldHorse = OldHorse() + DIPro.inject(oldHorse) //check override on DIPro - assertTrue(oldHorse.ideology.isFamilyIdeology()); + assertTrue(oldHorse.ideology!!.isFamilyIdeology) // all use overrided features - DI.inject(horse); - - assertTrue(horse.ideology.isFamilyIdeology()); + DI.inject(horse) + assertTrue(horse.ideology!!.isFamilyIdeology) } - } diff --git a/tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/bindinstance/singlemethod/ExtPlanetTests.kt b/tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/bindinstance/singlemethod/ExtPlanetTests.kt index 30a25be0..4dbcf225 100644 --- a/tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/bindinstance/singlemethod/ExtPlanetTests.kt +++ b/tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/bindinstance/singlemethod/ExtPlanetTests.kt @@ -1,103 +1,101 @@ -package com.dirgub.klee0kai.stone.text_ext.bindinstance.singlemethod; +package com.dirgub.klee0kai.stone.text_ext.bindinstance.singlemethod -import com.github.klee0kai.stone.Stone; -import com.github.klee0kai.test.di.bindinstance.singlemethod.PlanetComponent; -import com.github.klee0kai.test.mowgli.galaxy.Earth; -import com.github.klee0kai.test_ext.inject.di.bindinstance.singlemethod.ExtPlanetComponent; -import org.junit.jupiter.api.Test; +import com.github.klee0kai.test.di.bindinstance.singlemethod.PlanetComponent +import com.github.klee0kai.test.di.bindinstance.singlemethod.PlanetComponentStoneComponent +import com.github.klee0kai.test.mowgli.galaxy.Earth +import com.github.klee0kai.test_ext.inject.di.bindinstance.singlemethod.ExtPlanetComponent +import com.github.klee0kai.test_ext.inject.di.bindinstance.singlemethod.ExtPlanetComponentStoneComponent +import org.junit.jupiter.api.Assertions.assertEquals +import org.junit.jupiter.api.Test +import org.junit.jupiter.api.assertNull -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNull; - -public class ExtPlanetTests { +class ExtPlanetTests { @Test - public void createdIsReusableTest() { + fun createdIsReusableTest() { // Given - PlanetComponent DI = Stone.createComponent(PlanetComponent.class); - Earth earth = new Earth(); - DI.earth(earth); + val DI: PlanetComponent = PlanetComponentStoneComponent() + val earth = Earth() + DI.earth(earth) //When - ExtPlanetComponent DIPro = Stone.createComponent(ExtPlanetComponent.class); - DIPro.extendOf(DI); + val DIPro: ExtPlanetComponent = ExtPlanetComponentStoneComponent() + DIPro.extendOf(DI) //Then - assertEquals(earth, DI.earth(null)); - assertEquals(earth, DIPro.earth(null)); - assertNull(DI.planet(null)); - assertNull(DIPro.planet(null)); + assertEquals(earth, DI.earth(null)) + assertEquals(earth, DIPro.earth(null)) + assertNull(DI.planet(null)) + assertNull(DIPro.planet(null)) } @Test - public void createdAfterExtendTest() { + fun createdAfterExtendTest() { // Given - PlanetComponent DI = Stone.createComponent(PlanetComponent.class); - ExtPlanetComponent DIPro = Stone.createComponent(ExtPlanetComponent.class); - DIPro.extendOf(DI); - Earth earth = new Earth(); + val DI: PlanetComponent = PlanetComponentStoneComponent() + val DIPro: ExtPlanetComponent = ExtPlanetComponentStoneComponent() + DIPro.extendOf(DI) + val earth = Earth() //When - DI.earth(earth); + DI.earth(earth) //Then - assertEquals(earth, DI.earth(null)); - assertEquals(earth, DIPro.earth(null)); - assertNull(DI.planet(null)); - assertNull(DIPro.planet(null)); + assertEquals(earth, DI.earth(null)) + assertEquals(earth, DIPro.earth(null)) + assertNull(DI.planet(null)) + assertNull(DIPro.planet(null)) } @Test - public void extendedEarthTest() { + fun extendedEarthTest() { // Given - PlanetComponent DI = Stone.createComponent(PlanetComponent.class); - Earth earth1 = new Earth(); - Earth earth2 = new Earth(); - DI.earth(earth1); + val DI: PlanetComponent = PlanetComponentStoneComponent() + val earth1 = Earth() + val earth2 = Earth() + DI.earth(earth1) //When - ExtPlanetComponent DIPro = Stone.createComponent(ExtPlanetComponent.class); - DIPro.extendOf(DI); - DIPro.earth(earth2); + val DIPro: ExtPlanetComponent = ExtPlanetComponentStoneComponent() + DIPro.extendOf(DI) + DIPro.earth(earth2) //Then - assertEquals(earth2, DI.earth(null)); - assertEquals(earth2, DIPro.earth(null)); - assertNull(DI.planet(null)); - assertNull(DIPro.planet(null)); + assertEquals(earth2, DI.earth(null)) + assertEquals(earth2, DIPro.earth(null)) + assertNull(DI.planet(null)) + assertNull(DIPro.planet(null)) } @Test - public void updatedAfterExtendEarthTest() { + fun updatedAfterExtendEarthTest() { // Given - PlanetComponent DI = Stone.createComponent(PlanetComponent.class); - Earth earth1 = new Earth(); - Earth earth2 = new Earth(); - Earth earth3 = new Earth(); - DI.earth(earth1); - ExtPlanetComponent DIPro = Stone.createComponent(ExtPlanetComponent.class); - DIPro.extendOf(DI); - DIPro.earth(earth2); + val DI: PlanetComponent = PlanetComponentStoneComponent() + val earth1 = Earth() + val earth2 = Earth() + val earth3 = Earth() + DI.earth(earth1) + val DIPro: ExtPlanetComponent = ExtPlanetComponentStoneComponent() + DIPro.extendOf(DI) + DIPro.earth(earth2) //When - DI.earth(earth3); + DI.earth(earth3) //Then - assertEquals(earth3, DI.earth(null)); - assertEquals(earth3, DIPro.earth(null)); - assertNull(DI.planet(null)); - assertNull(DIPro.planet(null)); + assertEquals(earth3, DI.earth(null)) + assertEquals(earth3, DIPro.earth(null)) + assertNull(DI.planet(null)) + assertNull(DIPro.planet(null)) } - - } diff --git a/tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/bindinstance/singlemethod/PlanetSputniksTests.kt b/tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/bindinstance/singlemethod/PlanetSputniksTests.kt index 1fd34e29..514a4294 100644 --- a/tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/bindinstance/singlemethod/PlanetSputniksTests.kt +++ b/tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/bindinstance/singlemethod/PlanetSputniksTests.kt @@ -1,103 +1,101 @@ -package com.dirgub.klee0kai.stone.text_ext.bindinstance.singlemethod; +package com.dirgub.klee0kai.stone.text_ext.bindinstance.singlemethod -import com.github.klee0kai.stone.Stone; -import com.github.klee0kai.test.di.bindinstance.singlemethod.PlanetComponent; -import com.github.klee0kai.test.mowgli.galaxy.Earth; -import com.github.klee0kai.test_ext.inject.di.bindinstance.singlemethod.PlanetSputnikComponent; -import org.junit.jupiter.api.Test; +import com.github.klee0kai.test.di.bindinstance.singlemethod.PlanetComponent +import com.github.klee0kai.test.di.bindinstance.singlemethod.PlanetComponentStoneComponent +import com.github.klee0kai.test.mowgli.galaxy.Earth +import com.github.klee0kai.test_ext.inject.di.bindinstance.singlemethod.PlanetSputnikComponent +import com.github.klee0kai.test_ext.inject.di.bindinstance.singlemethod.PlanetSputnikComponentStoneComponent +import org.junit.jupiter.api.Assertions.assertEquals +import org.junit.jupiter.api.Test +import org.junit.jupiter.api.assertNull -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNull; - -public class PlanetSputniksTests { +class PlanetSputniksTests { @Test - public void createdIsReusableTest() { + fun createdIsReusableTest() { // Given - PlanetComponent DI = Stone.createComponent(PlanetComponent.class); - Earth earth = new Earth(); - DI.earth(earth); + val DI: PlanetComponent = PlanetComponentStoneComponent() + val earth = Earth() + DI.earth(earth) //When - PlanetSputnikComponent DIPro = Stone.createComponent(PlanetSputnikComponent.class); - DIPro.extendOf(DI); + val DIPro: PlanetSputnikComponent = PlanetSputnikComponentStoneComponent() + DIPro.extendOf(DI) //Then - assertEquals(earth, DI.earth(null)); - assertEquals(earth, DIPro.earth(null)); - assertNull(DI.planet(null)); - assertNull(DIPro.planet(null)); + assertEquals(earth, DI.earth(null)) + assertEquals(earth, DIPro.earth(null)) + assertNull(DI.planet(null)) + assertNull(DIPro.planet(null)) } @Test - public void createdAfterExtendTest() { + fun createdAfterExtendTest() { // Given - PlanetComponent DI = Stone.createComponent(PlanetComponent.class); - PlanetSputnikComponent DIPro = Stone.createComponent(PlanetSputnikComponent.class); - DIPro.extendOf(DI); - Earth earth = new Earth(); + val DI: PlanetComponent = PlanetComponentStoneComponent() + val DIPro: PlanetSputnikComponent = PlanetSputnikComponentStoneComponent() + DIPro.extendOf(DI) + val earth = Earth() //When - DI.earth(earth); + DI.earth(earth) //Then - assertEquals(earth, DI.earth(null)); - assertEquals(earth, DIPro.earth(null)); - assertNull(DI.planet(null)); - assertNull(DIPro.planet(null)); + assertEquals(earth, DI.earth(null)) + assertEquals(earth, DIPro.earth(null)) + assertNull(DI.planet(null)) + assertNull(DIPro.planet(null)) } @Test - public void extendedEarthTest() { + fun extendedEarthTest() { // Given - PlanetComponent DI = Stone.createComponent(PlanetComponent.class); - Earth earth1 = new Earth(); - Earth earth2 = new Earth(); - DI.earth(earth1); + val DI: PlanetComponent = PlanetComponentStoneComponent() + val earth1 = Earth() + val earth2 = Earth() + DI.earth(earth1) //When - PlanetSputnikComponent DIPro = Stone.createComponent(PlanetSputnikComponent.class); - DIPro.extendOf(DI); - DIPro.earth(earth2); + val DIPro: PlanetSputnikComponent = PlanetSputnikComponentStoneComponent() + DIPro.extendOf(DI) + DIPro.earth(earth2) //Then - assertEquals(earth2, DI.earth(null)); - assertEquals(earth2, DIPro.earth(null)); - assertNull(DI.planet(null)); - assertNull(DIPro.planet(null)); + assertEquals(earth2, DI.earth(null)) + assertEquals(earth2, DIPro.earth(null)) + assertNull(DI.planet(null)) + assertNull(DIPro.planet(null)) } - @Test - public void updatedAfterExtendEarthTest() { + @org.junit.jupiter.api.Test + fun updatedAfterExtendEarthTest() { // Given - PlanetComponent DI = Stone.createComponent(PlanetComponent.class); - Earth earth1 = new Earth(); - Earth earth2 = new Earth(); - Earth earth3 = new Earth(); - DI.earth(earth1); - PlanetSputnikComponent DIPro = Stone.createComponent(PlanetSputnikComponent.class); - DIPro.extendOf(DI); - DIPro.earth(earth2); + val DI: PlanetComponent = PlanetComponentStoneComponent() + val earth1 = Earth() + val earth2 = Earth() + val earth3 = Earth() + DI.earth(earth1) + val DIPro: PlanetSputnikComponent = PlanetSputnikComponentStoneComponent() + DIPro.extendOf(DI) + DIPro.earth(earth2) //When - DI.earth(earth3); + DI.earth(earth3) //Then - assertEquals(earth3, DI.earth(null)); - assertEquals(earth3, DIPro.earth(null)); - assertNull(DI.planet(null)); - assertNull(DIPro.planet(null)); + assertEquals(earth3, DI.earth(null)) + assertEquals(earth3, DIPro.earth(null)) + assertNull(DI.planet(null)) + assertNull(DIPro.planet(null)) } - - } diff --git a/tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/bindinstance/singlemethod/StarProvideTests.kt b/tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/bindinstance/singlemethod/StarProvideTests.kt index f5c758b0..ec534d88 100644 --- a/tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/bindinstance/singlemethod/StarProvideTests.kt +++ b/tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/bindinstance/singlemethod/StarProvideTests.kt @@ -1,75 +1,72 @@ -package com.dirgub.klee0kai.stone.text_ext.bindinstance.singlemethod; +package com.dirgub.klee0kai.stone.text_ext.bindinstance.singlemethod -import com.github.klee0kai.stone.Stone; -import com.github.klee0kai.test.di.bindinstance.singlemethod.PlanetComponent; -import com.github.klee0kai.test.mowgli.galaxy.Sun; -import com.github.klee0kai.test_ext.inject.di.bindinstance.singlemethod.PlanetSputnikComponent; -import org.junit.jupiter.api.Test; +import com.github.klee0kai.test.di.bindinstance.singlemethod.PlanetComponent +import com.github.klee0kai.test.di.bindinstance.singlemethod.PlanetComponentStoneComponent +import com.github.klee0kai.test.mowgli.galaxy.Sun +import com.github.klee0kai.test_ext.inject.di.bindinstance.singlemethod.PlanetSputnikComponent +import com.github.klee0kai.test_ext.inject.di.bindinstance.singlemethod.PlanetSputnikComponentStoneComponent +import org.junit.jupiter.api.Assertions.assertEquals +import org.junit.jupiter.api.Test +import org.junit.jupiter.api.assertNull -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNull; - -public class StarProvideTests { +class StarProvideTests { @Test - public void sunReusableTest() { + fun sunReusableTest() { //Given - PlanetComponent DI = Stone.createComponent(PlanetComponent.class); - Sun sun = new Sun(); - DI.sunModule().sun(sun); + val DI: PlanetComponent = PlanetComponentStoneComponent() + val sun = Sun() + DI.sunModule()?.sun(sun) //When - PlanetSputnikComponent DIPro = Stone.createComponent(PlanetSputnikComponent.class); - DIPro.extendOf(DI); + val DIPro: PlanetSputnikComponent = PlanetSputnikComponentStoneComponent() + DIPro.extendOf(DI) //Then - assertEquals(sun, DI.sunModule().sun(null)); - assertEquals(sun, DI.sunModule().sun(null)); - assertNull(DI.sunModule().star(null)); - assertNull(DIPro.sunModule().star(null)); + assertEquals(sun, DI.sunModule()!!.sun(null)) + assertEquals(sun, DI.sunModule()!!.sun(null)) + assertNull(DI.sunModule()!!.star(null)) + assertNull(DIPro.sunModule().star(null)) } - @Test - public void createAfterExtendTest() { + fun createAfterExtendTest() { //Given - PlanetComponent DI = Stone.createComponent(PlanetComponent.class); - PlanetSputnikComponent DIPro = Stone.createComponent(PlanetSputnikComponent.class); - DIPro.extendOf(DI); - Sun sun = new Sun(); + val DI: PlanetComponent = PlanetComponentStoneComponent() + val DIPro: PlanetSputnikComponent = PlanetSputnikComponentStoneComponent() + DIPro.extendOf(DI) + val sun = Sun() //When - DI.sunModule().sun(sun); + DI.sunModule()!!.sun(sun) //Then - assertEquals(sun, DI.sunModule().sun(null)); - assertEquals(sun, DI.sunModule().sun(null)); - assertNull(DI.sunModule().star(null)); - assertNull(DIPro.sunModule().star(null)); + assertEquals(sun, DI.sunModule()!!.sun(null)) + assertEquals(sun, DI.sunModule()!!.sun(null)) + assertNull(DI.sunModule()!!.star(null)) + assertNull(DIPro.sunModule()!!.star(null)) } @Test - public void extendedSunTest() { + fun extendedSunTest() { //Given - PlanetComponent DI = Stone.createComponent(PlanetComponent.class); - Sun sun1 = new Sun(); - Sun sun2 = new Sun(); - DI.sunModule().sun(sun1); + val DI: PlanetComponent = PlanetComponentStoneComponent() + val sun1 = Sun() + val sun2 = Sun() + DI.sunModule()!!.sun(sun1) //When - PlanetSputnikComponent DIPro = Stone.createComponent(PlanetSputnikComponent.class); - DIPro.extendOf(DI); - DIPro.sunModule().sun(sun2); + val DIPro: PlanetSputnikComponent = PlanetSputnikComponentStoneComponent() + DIPro.extendOf(DI) + DIPro.sunModule().sun(sun2) //Then - assertEquals(sun2, DI.sunModule().sun(null)); - assertEquals(sun2, DI.sunModule().sun(null)); - assertNull(DI.sunModule().star(null)); - assertNull(DIPro.sunModule().star(null)); + assertEquals(sun2, DI.sunModule()!!.sun(null)) + assertEquals(sun2, DI.sunModule()!!.sun(null)) + assertNull(DI.sunModule()!!.star(null)) + assertNull(DIPro.sunModule().star(null)) } - - } diff --git a/tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/bindinstance/singlemethod_gc/ExtPlanetRollingTests.kt b/tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/bindinstance/singlemethod_gc/ExtPlanetRollingTests.kt index 604bd27a..f6550d5c 100644 --- a/tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/bindinstance/singlemethod_gc/ExtPlanetRollingTests.kt +++ b/tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/bindinstance/singlemethod_gc/ExtPlanetRollingTests.kt @@ -1,459 +1,471 @@ -package com.dirgub.klee0kai.stone.text_ext.bindinstance.singlemethod_gc; - -import com.github.klee0kai.stone.Stone; -import com.github.klee0kai.test.di.bindinstance.singlemethod_gc.PlanetRollingComponent; -import com.github.klee0kai.test.mowgli.galaxy.Earth; -import com.github.klee0kai.test.mowgli.galaxy.Sun; -import com.github.klee0kai.test_ext.inject.di.bindinstance.singlemethod_gc.ExtPlanetRollingComponent; -import com.github.klee0kai.test_ext.inject.mowgli.galaxy.sputniks.Moon; -import com.github.klee0kai.test_ext.inject.mowgli.galaxy.stars.Sirius; -import org.junit.jupiter.api.Test; - -import java.lang.ref.WeakReference; -import java.util.Arrays; - -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertNull; - -public class ExtPlanetRollingTests { +package com.dirgub.klee0kai.stone.text_ext.bindinstance.singlemethod_gc + +import com.github.klee0kai.stone.Stone +import com.github.klee0kai.test.di.bindinstance.singlemethod_gc.PlanetRollingComponent +import com.github.klee0kai.test.di.bindinstance.singlemethod_gc.PlanetRollingComponentStoneComponent +import com.github.klee0kai.test.mowgli.galaxy.Earth +import com.github.klee0kai.test.mowgli.galaxy.Sun +import com.github.klee0kai.test_ext.inject.di.bindinstance.singlemethod_gc.ExtPlanetRollingComponent +import com.github.klee0kai.test_ext.inject.di.bindinstance.singlemethod_gc.ExtPlanetRollingComponentStoneComponent +import com.github.klee0kai.test_ext.inject.mowgli.galaxy.sputniks.Moon +import com.github.klee0kai.test_ext.inject.mowgli.galaxy.stars.Sirius +import org.junit.jupiter.api.Test +import org.junit.jupiter.api.assertNotNull +import org.junit.jupiter.api.assertNull +import java.lang.ref.WeakReference + +class ExtPlanetRollingTests { @Test - public void gcAllTest() { + fun gcAllTest() { //Given - PlanetRollingComponent DI = Stone.createComponent(PlanetRollingComponent.class); - WeakReference earthStrong = new WeakReference<>(new Earth()); - WeakReference earthSoft = new WeakReference<>(new Earth()); - WeakReference planetWeak = new WeakReference<>(new Earth()); - WeakReference sunStrong = new WeakReference<>(new Sun()); - WeakReference sunSoft = new WeakReference<>(new Sun()); - WeakReference starWeak = new WeakReference<>(new Sun()); - DI.earthStrong(earthStrong.get()); - DI.earthSoft(earthSoft.get()); - DI.planet(planetWeak.get()); - DI.sunModule().sunStrong(sunStrong.get()); - DI.sunModule().sunSoft(sunSoft.get()); - DI.sunModule().star(starWeak.get()); + val DI: PlanetRollingComponent = PlanetRollingComponentStoneComponent() + val earthStrong = WeakReference(Earth()) + val earthSoft = WeakReference(Earth()) + val planetWeak = WeakReference(Earth()) + val sunStrong = WeakReference(Sun()) + val sunSoft = WeakReference(Sun()) + val starWeak = WeakReference(Sun()) + DI.earthStrong(earthStrong.get()) + DI.earthSoft(earthSoft.get()) + DI.planet(planetWeak.get()) + DI.sunModule()!!.sunStrong(sunStrong.get()) + DI.sunModule()!!.sunSoft(sunSoft.get()) + DI.sunModule()!!.star(starWeak.get()) //external component init - ExtPlanetRollingComponent DIPro = Stone.createComponent(ExtPlanetRollingComponent.class); - DIPro.extOf(DI); - WeakReference siriusStrong = new WeakReference<>(new Sirius()); - WeakReference siriusSoft = new WeakReference<>(new Sirius()); - WeakReference siriusWeak = new WeakReference<>(new Sirius()); - WeakReference moonStrong = new WeakReference<>(new Moon()); - WeakReference moonSoft = new WeakReference<>(new Moon()); - WeakReference moonWeak = new WeakReference<>(new Moon()); - DIPro.sunModule().siriusStrong(siriusStrong.get()); - DIPro.sunModule().siriusSoft(siriusSoft.get()); - DIPro.sunModule().siriusWeak(siriusWeak.get()); - DIPro.moonStrong(moonStrong.get()); - DIPro.moonSoft(moonSoft.get()); - DIPro.moonWeak(moonWeak.get()); + val DIPro: ExtPlanetRollingComponent = ExtPlanetRollingComponentStoneComponent() + DIPro.extOf(DI) + val siriusStrong = WeakReference(Sirius()) + val siriusSoft = WeakReference(Sirius()) + val siriusWeak = WeakReference(Sirius()) + val moonStrong = WeakReference(Moon()) + val moonSoft = WeakReference(Moon()) + val moonWeak = WeakReference(Moon()) + DIPro.sunModule()!!.siriusStrong(siriusStrong.get()) + DIPro.sunModule()!!.siriusSoft(siriusSoft.get()) + DIPro.sunModule()!!.siriusWeak(siriusWeak.get()) + DIPro.moonStrong(moonStrong.get()) + DIPro.moonSoft(moonSoft.get()) + DIPro.moonWeak(moonWeak.get()) //When - DIPro.gcAllExt(); + DIPro.gcAllExt() //Then - for (WeakReference ref : Arrays.asList( - earthStrong, earthSoft, planetWeak, - sunStrong, sunSoft, starWeak, - siriusStrong, siriusSoft, siriusWeak, - moonStrong, moonSoft, moonWeak + for (ref in listOf( + earthStrong, earthSoft, planetWeak, + sunStrong, sunSoft, starWeak, + siriusStrong, siriusSoft, siriusWeak, + moonStrong, moonSoft, moonWeak )) { - assertNull(ref.get()); + assertNull(ref.get()) } } @Test - public void gcStrongTest() { + fun gcStrongTest() { //Given - PlanetRollingComponent DI = Stone.createComponent(PlanetRollingComponent.class); - WeakReference earthStrong = new WeakReference<>(new Earth()); - WeakReference earthSoft = new WeakReference<>(new Earth()); - WeakReference planetWeak = new WeakReference<>(new Earth()); - WeakReference sunStrong = new WeakReference<>(new Sun()); - WeakReference sunSoft = new WeakReference<>(new Sun()); - WeakReference starWeak = new WeakReference<>(new Sun()); - DI.earthStrong(earthStrong.get()); - DI.earthSoft(earthSoft.get()); - DI.planet(planetWeak.get()); - DI.sunModule().sunStrong(sunStrong.get()); - DI.sunModule().sunSoft(sunSoft.get()); - DI.sunModule().star(starWeak.get()); + val DI: PlanetRollingComponent = PlanetRollingComponentStoneComponent() + val earthStrong = WeakReference(Earth()) + val earthSoft = WeakReference(Earth()) + val planetWeak = WeakReference(Earth()) + val sunStrong = WeakReference(Sun()) + val sunSoft = WeakReference(Sun()) + val starWeak = WeakReference(Sun()) + DI.earthStrong(earthStrong.get()) + DI.earthSoft(earthSoft.get()) + DI.planet(planetWeak.get()) + DI.sunModule()!!.sunStrong(sunStrong.get()) + DI.sunModule()!!.sunSoft(sunSoft.get()) + DI.sunModule()!!.star(starWeak.get()) //external component init - ExtPlanetRollingComponent DIPro = Stone.createComponent(ExtPlanetRollingComponent.class); - DIPro.extOf(DI); - WeakReference siriusStrong = new WeakReference<>(new Sirius()); - WeakReference siriusSoft = new WeakReference<>(new Sirius()); - WeakReference siriusWeak = new WeakReference<>(new Sirius()); - WeakReference moonStrong = new WeakReference<>(new Moon()); - WeakReference moonSoft = new WeakReference<>(new Moon()); - WeakReference moonWeak = new WeakReference<>(new Moon()); - DIPro.sunModule().siriusStrong(siriusStrong.get()); - DIPro.sunModule().siriusSoft(siriusSoft.get()); - DIPro.sunModule().siriusWeak(siriusWeak.get()); - DIPro.moonStrong(moonStrong.get()); - DIPro.moonSoft(moonSoft.get()); - DIPro.moonWeak(moonWeak.get()); + val DIPro: ExtPlanetRollingComponent = ExtPlanetRollingComponentStoneComponent() + DIPro.extOf(DI) + val siriusStrong = WeakReference(Sirius()) + val siriusSoft = WeakReference(Sirius()) + val siriusWeak = WeakReference(Sirius()) + val moonStrong = WeakReference(Moon()) + val moonSoft = WeakReference(Moon()) + val moonWeak = WeakReference(Moon()) + DIPro.sunModule()!!.siriusStrong(siriusStrong.get()) + DIPro.sunModule()!!.siriusSoft(siriusSoft.get()) + DIPro.sunModule()!!.siriusWeak(siriusWeak.get()) + DIPro.moonStrong(moonStrong.get()) + DIPro.moonSoft(moonSoft.get()) + DIPro.moonWeak(moonWeak.get()) //When - DIPro.gcStrongExt(); + DIPro.gcStrongExt() //Then - for (WeakReference ref : Arrays.asList( - earthStrong, planetWeak, - sunStrong, starWeak, - siriusStrong, siriusWeak, - moonStrong, moonWeak + for (ref in listOf( + earthStrong, planetWeak, + sunStrong, starWeak, + siriusStrong, siriusWeak, + moonStrong, moonWeak )) { - assertNull(ref.get()); + assertNull(ref.get()) } - for (WeakReference ref : Arrays.asList( - earthSoft, - sunSoft, - siriusSoft, - moonSoft + for (ref in listOf( + earthSoft, + sunSoft, + siriusSoft, + moonSoft )) { - assertNotNull(ref.get()); + assertNotNull(ref.get()) } } @Test - public void gcSoftTest() { + fun gcSoftTest() { //Given - PlanetRollingComponent DI = Stone.createComponent(PlanetRollingComponent.class); - WeakReference earthStrong = new WeakReference<>(new Earth()); - WeakReference earthSoft = new WeakReference<>(new Earth()); - WeakReference planetWeak = new WeakReference<>(new Earth()); - WeakReference sunStrong = new WeakReference<>(new Sun()); - WeakReference sunSoft = new WeakReference<>(new Sun()); - WeakReference starWeak = new WeakReference<>(new Sun()); - DI.earthStrong(earthStrong.get()); - DI.earthSoft(earthSoft.get()); - DI.planet(planetWeak.get()); - DI.sunModule().sunStrong(sunStrong.get()); - DI.sunModule().sunSoft(sunSoft.get()); - DI.sunModule().star(starWeak.get()); + val DI: PlanetRollingComponent = PlanetRollingComponentStoneComponent() + val earthStrong = WeakReference(Earth()) + val earthSoft = WeakReference(Earth()) + val planetWeak = WeakReference(Earth()) + val sunStrong = WeakReference(Sun()) + val sunSoft = WeakReference(Sun()) + val starWeak = WeakReference(Sun()) + DI.earthStrong(earthStrong.get()) + DI.earthSoft(earthSoft.get()) + DI.planet(planetWeak.get()) + DI.sunModule()!!.sunStrong(sunStrong.get()) + DI.sunModule()!!.sunSoft(sunSoft.get()) + DI.sunModule()!!.star(starWeak.get()) //external component init - ExtPlanetRollingComponent DIPro = Stone.createComponent(ExtPlanetRollingComponent.class); - DIPro.extOf(DI); - WeakReference siriusStrong = new WeakReference<>(new Sirius()); - WeakReference siriusSoft = new WeakReference<>(new Sirius()); - WeakReference siriusWeak = new WeakReference<>(new Sirius()); - WeakReference moonStrong = new WeakReference<>(new Moon()); - WeakReference moonSoft = new WeakReference<>(new Moon()); - WeakReference moonWeak = new WeakReference<>(new Moon()); - DIPro.sunModule().siriusStrong(siriusStrong.get()); - DIPro.sunModule().siriusSoft(siriusSoft.get()); - DIPro.sunModule().siriusWeak(siriusWeak.get()); - DIPro.moonStrong(moonStrong.get()); - DIPro.moonSoft(moonSoft.get()); - DIPro.moonWeak(moonWeak.get()); + val DIPro: ExtPlanetRollingComponent = ExtPlanetRollingComponentStoneComponent() + DIPro.extOf(DI) + val siriusStrong = WeakReference(Sirius()) + val siriusSoft = WeakReference(Sirius()) + val siriusWeak = WeakReference(Sirius()) + val moonStrong = WeakReference(Moon()) + val moonSoft = WeakReference(Moon()) + val moonWeak = WeakReference(Moon()) + DIPro.sunModule()!!.siriusStrong(siriusStrong.get()) + DIPro.sunModule()!!.siriusSoft(siriusSoft.get()) + DIPro.sunModule()!!.siriusWeak(siriusWeak.get()) + DIPro.moonStrong(moonStrong.get()) + DIPro.moonSoft(moonSoft.get()) + DIPro.moonWeak(moonWeak.get()) //When - DIPro.gcSoftExt(); + DIPro.gcSoftExt() //Then - for (WeakReference ref : Arrays.asList( - earthSoft, planetWeak, - sunSoft, starWeak, - siriusSoft, siriusWeak, - moonSoft, moonWeak + for (ref in listOf( + earthSoft, planetWeak, + sunSoft, starWeak, + siriusSoft, siriusWeak, + moonSoft, moonWeak )) { - assertNull(ref.get()); + assertNull(ref.get()) } - for (WeakReference ref : Arrays.asList( - earthStrong, - sunStrong, - siriusStrong, - moonStrong + for (ref in listOf( + earthStrong, + sunStrong, + siriusStrong, + moonStrong )) { - assertNotNull(ref.get()); + assertNotNull(ref.get()) } } - @Test - public void gcWeakTest() { + @org.junit.jupiter.api.Test + fun gcWeakTest() { //Given - PlanetRollingComponent DI = Stone.createComponent(PlanetRollingComponent.class); - WeakReference earthStrong = new WeakReference<>(new Earth()); - WeakReference earthSoft = new WeakReference<>(new Earth()); - WeakReference planetWeak = new WeakReference<>(new Earth()); - WeakReference sunStrong = new WeakReference<>(new Sun()); - WeakReference sunSoft = new WeakReference<>(new Sun()); - WeakReference starWeak = new WeakReference<>(new Sun()); - DI.earthStrong(earthStrong.get()); - DI.earthSoft(earthSoft.get()); - DI.planet(planetWeak.get()); - DI.sunModule().sunStrong(sunStrong.get()); - DI.sunModule().sunSoft(sunSoft.get()); - DI.sunModule().star(starWeak.get()); + val DI: PlanetRollingComponent = Stone.createComponent(PlanetRollingComponent::class.java) + val earthStrong: java.lang.ref.WeakReference = java.lang.ref.WeakReference(Earth()) + val earthSoft: java.lang.ref.WeakReference = java.lang.ref.WeakReference(Earth()) + val planetWeak: java.lang.ref.WeakReference = java.lang.ref.WeakReference(Earth()) + val sunStrong = + java.lang.ref.WeakReference(com.github.klee0kai.test.mowgli.galaxy.Sun()) + val sunSoft = + java.lang.ref.WeakReference(com.github.klee0kai.test.mowgli.galaxy.Sun()) + val starWeak = + java.lang.ref.WeakReference(com.github.klee0kai.test.mowgli.galaxy.Sun()) + DI.earthStrong(earthStrong.get()) + DI.earthSoft(earthSoft.get()) + DI.planet(planetWeak.get()) + DI.sunModule().sunStrong(sunStrong.get()) + DI.sunModule().sunSoft(sunSoft.get()) + DI.sunModule().star(starWeak.get()) //external component init - ExtPlanetRollingComponent DIPro = Stone.createComponent(ExtPlanetRollingComponent.class); - DIPro.extOf(DI); - WeakReference siriusStrong = new WeakReference<>(new Sirius()); - WeakReference siriusSoft = new WeakReference<>(new Sirius()); - WeakReference siriusWeak = new WeakReference<>(new Sirius()); - WeakReference moonStrong = new WeakReference<>(new Moon()); - WeakReference moonSoft = new WeakReference<>(new Moon()); - WeakReference moonWeak = new WeakReference<>(new Moon()); - DIPro.sunModule().siriusStrong(siriusStrong.get()); - DIPro.sunModule().siriusSoft(siriusSoft.get()); - DIPro.sunModule().siriusWeak(siriusWeak.get()); - DIPro.moonStrong(moonStrong.get()); - DIPro.moonSoft(moonSoft.get()); - DIPro.moonWeak(moonWeak.get()); + val DIPro: ExtPlanetRollingComponent = Stone.createComponent(ExtPlanetRollingComponent::class.java) + DIPro.extOf(DI) + val siriusStrong: java.lang.ref.WeakReference = java.lang.ref.WeakReference(Sirius()) + val siriusSoft: java.lang.ref.WeakReference = java.lang.ref.WeakReference(Sirius()) + val siriusWeak: java.lang.ref.WeakReference = java.lang.ref.WeakReference(Sirius()) + val moonStrong: java.lang.ref.WeakReference = java.lang.ref.WeakReference(Moon()) + val moonSoft: java.lang.ref.WeakReference = java.lang.ref.WeakReference(Moon()) + val moonWeak: java.lang.ref.WeakReference = java.lang.ref.WeakReference(Moon()) + DIPro.sunModule().siriusStrong(siriusStrong.get()) + DIPro.sunModule().siriusSoft(siriusSoft.get()) + DIPro.sunModule().siriusWeak(siriusWeak.get()) + DIPro.moonStrong(moonStrong.get()) + DIPro.moonSoft(moonSoft.get()) + DIPro.moonWeak(moonWeak.get()) //When - DIPro.gcWeakExt(); + DIPro.gcWeakExt() //Then - for (WeakReference ref : Arrays.asList( - planetWeak, - starWeak, - siriusWeak, - moonWeak + for (ref in java.util.Arrays.asList>( + planetWeak, + starWeak, + siriusWeak, + moonWeak )) { - assertNull(ref.get()); + org.junit.jupiter.api.Assertions.assertNull(ref.get()) } - for (WeakReference ref : Arrays.asList( - earthStrong, earthSoft, - sunStrong, sunSoft, - siriusStrong, siriusSoft, - moonStrong, moonSoft + for (ref in java.util.Arrays.asList>( + earthStrong, earthSoft, + sunStrong, sunSoft, + siriusStrong, siriusSoft, + moonStrong, moonSoft )) { - assertNotNull(ref.get()); + org.junit.jupiter.api.Assertions.assertNotNull(ref.get()) } } - @Test - public void gcSoftSunTest() { + @org.junit.jupiter.api.Test + fun gcSoftSunTest() { //Given - PlanetRollingComponent DI = Stone.createComponent(PlanetRollingComponent.class); - WeakReference earthStrong = new WeakReference<>(new Earth()); - WeakReference earthSoft = new WeakReference<>(new Earth()); - WeakReference planetWeak = new WeakReference<>(new Earth()); - WeakReference sunStrong = new WeakReference<>(new Sun()); - WeakReference sunSoft = new WeakReference<>(new Sun()); - WeakReference starWeak = new WeakReference<>(new Sun()); - DI.earthStrong(earthStrong.get()); - DI.earthSoft(earthSoft.get()); - DI.planet(planetWeak.get()); - DI.sunModule().sunStrong(sunStrong.get()); - DI.sunModule().sunSoft(sunSoft.get()); - DI.sunModule().star(starWeak.get()); + val DI: PlanetRollingComponent = Stone.createComponent(PlanetRollingComponent::class.java) + val earthStrong: java.lang.ref.WeakReference = java.lang.ref.WeakReference(Earth()) + val earthSoft: java.lang.ref.WeakReference = java.lang.ref.WeakReference(Earth()) + val planetWeak: java.lang.ref.WeakReference = java.lang.ref.WeakReference(Earth()) + val sunStrong = + java.lang.ref.WeakReference(com.github.klee0kai.test.mowgli.galaxy.Sun()) + val sunSoft = + java.lang.ref.WeakReference(com.github.klee0kai.test.mowgli.galaxy.Sun()) + val starWeak = + java.lang.ref.WeakReference(com.github.klee0kai.test.mowgli.galaxy.Sun()) + DI.earthStrong(earthStrong.get()) + DI.earthSoft(earthSoft.get()) + DI.planet(planetWeak.get()) + DI.sunModule().sunStrong(sunStrong.get()) + DI.sunModule().sunSoft(sunSoft.get()) + DI.sunModule().star(starWeak.get()) //external component init - ExtPlanetRollingComponent DIPro = Stone.createComponent(ExtPlanetRollingComponent.class); - DIPro.extOf(DI); - WeakReference siriusStrong = new WeakReference<>(new Sirius()); - WeakReference siriusSoft = new WeakReference<>(new Sirius()); - WeakReference siriusWeak = new WeakReference<>(new Sirius()); - WeakReference moonStrong = new WeakReference<>(new Moon()); - WeakReference moonSoft = new WeakReference<>(new Moon()); - WeakReference moonWeak = new WeakReference<>(new Moon()); - DIPro.sunModule().siriusStrong(siriusStrong.get()); - DIPro.sunModule().siriusSoft(siriusSoft.get()); - DIPro.sunModule().siriusWeak(siriusWeak.get()); - DIPro.moonStrong(moonStrong.get()); - DIPro.moonSoft(moonSoft.get()); - DIPro.moonWeak(moonWeak.get()); + val DIPro: ExtPlanetRollingComponent = Stone.createComponent(ExtPlanetRollingComponent::class.java) + DIPro.extOf(DI) + val siriusStrong: java.lang.ref.WeakReference = java.lang.ref.WeakReference(Sirius()) + val siriusSoft: java.lang.ref.WeakReference = java.lang.ref.WeakReference(Sirius()) + val siriusWeak: java.lang.ref.WeakReference = java.lang.ref.WeakReference(Sirius()) + val moonStrong: java.lang.ref.WeakReference = java.lang.ref.WeakReference(Moon()) + val moonSoft: java.lang.ref.WeakReference = java.lang.ref.WeakReference(Moon()) + val moonWeak: java.lang.ref.WeakReference = java.lang.ref.WeakReference(Moon()) + DIPro.sunModule().siriusStrong(siriusStrong.get()) + DIPro.sunModule().siriusSoft(siriusSoft.get()) + DIPro.sunModule().siriusWeak(siriusWeak.get()) + DIPro.moonStrong(moonStrong.get()) + DIPro.moonSoft(moonSoft.get()) + DIPro.moonWeak(moonWeak.get()) //When - DIPro.gcSoftSunExt(); + DIPro.gcSoftSunExt() //Then - for (WeakReference ref : Arrays.asList( - planetWeak, - sunSoft, starWeak, - siriusWeak, - moonWeak + for (ref in java.util.Arrays.asList>( + planetWeak, + sunSoft, starWeak, + siriusWeak, + moonWeak )) { - assertNull(ref.get()); + org.junit.jupiter.api.Assertions.assertNull(ref.get()) } - for (WeakReference ref : Arrays.asList( - earthStrong, earthSoft, - sunStrong, - siriusStrong, siriusSoft, - moonStrong, moonSoft + for (ref in java.util.Arrays.asList>( + earthStrong, earthSoft, + sunStrong, + siriusStrong, siriusSoft, + moonStrong, moonSoft )) { - assertNotNull(ref.get()); + org.junit.jupiter.api.Assertions.assertNotNull(ref.get()) } } - @Test - public void gcSoftPlanetsTest() { + @org.junit.jupiter.api.Test + fun gcSoftPlanetsTest() { //Given - PlanetRollingComponent DI = Stone.createComponent(PlanetRollingComponent.class); - WeakReference earthStrong = new WeakReference<>(new Earth()); - WeakReference earthSoft = new WeakReference<>(new Earth()); - WeakReference planetWeak = new WeakReference<>(new Earth()); - WeakReference sunStrong = new WeakReference<>(new Sun()); - WeakReference sunSoft = new WeakReference<>(new Sun()); - WeakReference starWeak = new WeakReference<>(new Sun()); - DI.earthStrong(earthStrong.get()); - DI.earthSoft(earthSoft.get()); - DI.planet(planetWeak.get()); - DI.sunModule().sunStrong(sunStrong.get()); - DI.sunModule().sunSoft(sunSoft.get()); - DI.sunModule().star(starWeak.get()); + val DI: PlanetRollingComponent = Stone.createComponent(PlanetRollingComponent::class.java) + val earthStrong: java.lang.ref.WeakReference = java.lang.ref.WeakReference(Earth()) + val earthSoft: java.lang.ref.WeakReference = java.lang.ref.WeakReference(Earth()) + val planetWeak: java.lang.ref.WeakReference = java.lang.ref.WeakReference(Earth()) + val sunStrong = + java.lang.ref.WeakReference(com.github.klee0kai.test.mowgli.galaxy.Sun()) + val sunSoft = + java.lang.ref.WeakReference(com.github.klee0kai.test.mowgli.galaxy.Sun()) + val starWeak = + java.lang.ref.WeakReference(com.github.klee0kai.test.mowgli.galaxy.Sun()) + DI.earthStrong(earthStrong.get()) + DI.earthSoft(earthSoft.get()) + DI.planet(planetWeak.get()) + DI.sunModule().sunStrong(sunStrong.get()) + DI.sunModule().sunSoft(sunSoft.get()) + DI.sunModule().star(starWeak.get()) //external component init - ExtPlanetRollingComponent DIPro = Stone.createComponent(ExtPlanetRollingComponent.class); - DIPro.extOf(DI); - WeakReference siriusStrong = new WeakReference<>(new Sirius()); - WeakReference siriusSoft = new WeakReference<>(new Sirius()); - WeakReference siriusWeak = new WeakReference<>(new Sirius()); - WeakReference moonStrong = new WeakReference<>(new Moon()); - WeakReference moonSoft = new WeakReference<>(new Moon()); - WeakReference moonWeak = new WeakReference<>(new Moon()); - DIPro.sunModule().siriusStrong(siriusStrong.get()); - DIPro.sunModule().siriusSoft(siriusSoft.get()); - DIPro.sunModule().siriusWeak(siriusWeak.get()); - DIPro.moonStrong(moonStrong.get()); - DIPro.moonSoft(moonSoft.get()); - DIPro.moonWeak(moonWeak.get()); + val DIPro: ExtPlanetRollingComponent = Stone.createComponent(ExtPlanetRollingComponent::class.java) + DIPro.extOf(DI) + val siriusStrong: java.lang.ref.WeakReference = java.lang.ref.WeakReference(Sirius()) + val siriusSoft: java.lang.ref.WeakReference = java.lang.ref.WeakReference(Sirius()) + val siriusWeak: java.lang.ref.WeakReference = java.lang.ref.WeakReference(Sirius()) + val moonStrong: java.lang.ref.WeakReference = java.lang.ref.WeakReference(Moon()) + val moonSoft: java.lang.ref.WeakReference = java.lang.ref.WeakReference(Moon()) + val moonWeak: java.lang.ref.WeakReference = java.lang.ref.WeakReference(Moon()) + DIPro.sunModule().siriusStrong(siriusStrong.get()) + DIPro.sunModule().siriusSoft(siriusSoft.get()) + DIPro.sunModule().siriusWeak(siriusWeak.get()) + DIPro.moonStrong(moonStrong.get()) + DIPro.moonSoft(moonSoft.get()) + DIPro.moonWeak(moonWeak.get()) //When - DIPro.gcSoftPlanetsExt(); + DIPro.gcSoftPlanetsExt() //Then - for (WeakReference ref : Arrays.asList( - earthSoft, planetWeak, - starWeak, - siriusWeak, - moonWeak + for (ref in java.util.Arrays.asList>( + earthSoft, planetWeak, + starWeak, + siriusWeak, + moonWeak )) { - assertNull(ref.get()); + org.junit.jupiter.api.Assertions.assertNull(ref.get()) } - for (WeakReference ref : Arrays.asList( - earthStrong, - sunStrong, sunSoft, - siriusStrong, siriusSoft, - moonStrong, moonSoft + for (ref in java.util.Arrays.asList>( + earthStrong, + sunStrong, sunSoft, + siriusStrong, siriusSoft, + moonStrong, moonSoft )) { - assertNotNull(ref.get()); + org.junit.jupiter.api.Assertions.assertNotNull(ref.get()) } } - @Test - public void gcSoftSiriusTest() { + @org.junit.jupiter.api.Test + fun gcSoftSiriusTest() { //Given - PlanetRollingComponent DI = Stone.createComponent(PlanetRollingComponent.class); - WeakReference earthStrong = new WeakReference<>(new Earth()); - WeakReference earthSoft = new WeakReference<>(new Earth()); - WeakReference planetWeak = new WeakReference<>(new Earth()); - WeakReference sunStrong = new WeakReference<>(new Sun()); - WeakReference sunSoft = new WeakReference<>(new Sun()); - WeakReference starWeak = new WeakReference<>(new Sun()); - DI.earthStrong(earthStrong.get()); - DI.earthSoft(earthSoft.get()); - DI.planet(planetWeak.get()); - DI.sunModule().sunStrong(sunStrong.get()); - DI.sunModule().sunSoft(sunSoft.get()); - DI.sunModule().star(starWeak.get()); + val DI: PlanetRollingComponent = Stone.createComponent(PlanetRollingComponent::class.java) + val earthStrong: java.lang.ref.WeakReference = java.lang.ref.WeakReference(Earth()) + val earthSoft: java.lang.ref.WeakReference = java.lang.ref.WeakReference(Earth()) + val planetWeak: java.lang.ref.WeakReference = java.lang.ref.WeakReference(Earth()) + val sunStrong = + java.lang.ref.WeakReference(com.github.klee0kai.test.mowgli.galaxy.Sun()) + val sunSoft = + java.lang.ref.WeakReference(com.github.klee0kai.test.mowgli.galaxy.Sun()) + val starWeak = + java.lang.ref.WeakReference(com.github.klee0kai.test.mowgli.galaxy.Sun()) + DI.earthStrong(earthStrong.get()) + DI.earthSoft(earthSoft.get()) + DI.planet(planetWeak.get()) + DI.sunModule().sunStrong(sunStrong.get()) + DI.sunModule().sunSoft(sunSoft.get()) + DI.sunModule().star(starWeak.get()) //external component init - ExtPlanetRollingComponent DIPro = Stone.createComponent(ExtPlanetRollingComponent.class); - DIPro.extOf(DI); - WeakReference siriusStrong = new WeakReference<>(new Sirius()); - WeakReference siriusSoft = new WeakReference<>(new Sirius()); - WeakReference siriusWeak = new WeakReference<>(new Sirius()); - WeakReference moonStrong = new WeakReference<>(new Moon()); - WeakReference moonSoft = new WeakReference<>(new Moon()); - WeakReference moonWeak = new WeakReference<>(new Moon()); - DIPro.sunModule().siriusStrong(siriusStrong.get()); - DIPro.sunModule().siriusSoft(siriusSoft.get()); - DIPro.sunModule().siriusWeak(siriusWeak.get()); - DIPro.moonStrong(moonStrong.get()); - DIPro.moonSoft(moonSoft.get()); - DIPro.moonWeak(moonWeak.get()); + val DIPro: ExtPlanetRollingComponent = Stone.createComponent(ExtPlanetRollingComponent::class.java) + DIPro.extOf(DI) + val siriusStrong: java.lang.ref.WeakReference = java.lang.ref.WeakReference(Sirius()) + val siriusSoft: java.lang.ref.WeakReference = java.lang.ref.WeakReference(Sirius()) + val siriusWeak: java.lang.ref.WeakReference = java.lang.ref.WeakReference(Sirius()) + val moonStrong: java.lang.ref.WeakReference = java.lang.ref.WeakReference(Moon()) + val moonSoft: java.lang.ref.WeakReference = java.lang.ref.WeakReference(Moon()) + val moonWeak: java.lang.ref.WeakReference = java.lang.ref.WeakReference(Moon()) + DIPro.sunModule().siriusStrong(siriusStrong.get()) + DIPro.sunModule().siriusSoft(siriusSoft.get()) + DIPro.sunModule().siriusWeak(siriusWeak.get()) + DIPro.moonStrong(moonStrong.get()) + DIPro.moonSoft(moonSoft.get()) + DIPro.moonWeak(moonWeak.get()) //When - DIPro.gcSoftSiriusExt(); + DIPro.gcSoftSiriusExt() //Then - for (WeakReference ref : Arrays.asList( - planetWeak, - starWeak, - siriusSoft, siriusWeak, - moonWeak + for (ref in java.util.Arrays.asList>( + planetWeak, + starWeak, + siriusSoft, siriusWeak, + moonWeak )) { - assertNull(ref.get()); + org.junit.jupiter.api.Assertions.assertNull(ref.get()) } - for (WeakReference ref : Arrays.asList( - earthStrong, earthSoft, - sunStrong, sunSoft, - siriusStrong, - moonStrong, moonSoft + for (ref in java.util.Arrays.asList>( + earthStrong, earthSoft, + sunStrong, sunSoft, + siriusStrong, + moonStrong, moonSoft )) { - assertNotNull(ref.get()); + org.junit.jupiter.api.Assertions.assertNotNull(ref.get()) } } - @Test - public void gcSputniksMoonTest() { + @org.junit.jupiter.api.Test + fun gcSputniksMoonTest() { //Given - PlanetRollingComponent DI = Stone.createComponent(PlanetRollingComponent.class); - WeakReference earthStrong = new WeakReference<>(new Earth()); - WeakReference earthSoft = new WeakReference<>(new Earth()); - WeakReference planetWeak = new WeakReference<>(new Earth()); - WeakReference sunStrong = new WeakReference<>(new Sun()); - WeakReference sunSoft = new WeakReference<>(new Sun()); - WeakReference starWeak = new WeakReference<>(new Sun()); - DI.earthStrong(earthStrong.get()); - DI.earthSoft(earthSoft.get()); - DI.planet(planetWeak.get()); - DI.sunModule().sunStrong(sunStrong.get()); - DI.sunModule().sunSoft(sunSoft.get()); - DI.sunModule().star(starWeak.get()); + val DI: PlanetRollingComponent = Stone.createComponent(PlanetRollingComponent::class.java) + val earthStrong: java.lang.ref.WeakReference = java.lang.ref.WeakReference(Earth()) + val earthSoft: java.lang.ref.WeakReference = java.lang.ref.WeakReference(Earth()) + val planetWeak: java.lang.ref.WeakReference = java.lang.ref.WeakReference(Earth()) + val sunStrong = + java.lang.ref.WeakReference(com.github.klee0kai.test.mowgli.galaxy.Sun()) + val sunSoft = + java.lang.ref.WeakReference(com.github.klee0kai.test.mowgli.galaxy.Sun()) + val starWeak = + java.lang.ref.WeakReference(com.github.klee0kai.test.mowgli.galaxy.Sun()) + DI.earthStrong(earthStrong.get()) + DI.earthSoft(earthSoft.get()) + DI.planet(planetWeak.get()) + DI.sunModule().sunStrong(sunStrong.get()) + DI.sunModule().sunSoft(sunSoft.get()) + DI.sunModule().star(starWeak.get()) //external component init - ExtPlanetRollingComponent DIPro = Stone.createComponent(ExtPlanetRollingComponent.class); - DIPro.extOf(DI); - WeakReference siriusStrong = new WeakReference<>(new Sirius()); - WeakReference siriusSoft = new WeakReference<>(new Sirius()); - WeakReference siriusWeak = new WeakReference<>(new Sirius()); - WeakReference moonStrong = new WeakReference<>(new Moon()); - WeakReference moonSoft = new WeakReference<>(new Moon()); - WeakReference moonWeak = new WeakReference<>(new Moon()); - DIPro.sunModule().siriusStrong(siriusStrong.get()); - DIPro.sunModule().siriusSoft(siriusSoft.get()); - DIPro.sunModule().siriusWeak(siriusWeak.get()); - DIPro.moonStrong(moonStrong.get()); - DIPro.moonSoft(moonSoft.get()); - DIPro.moonWeak(moonWeak.get()); + val DIPro: ExtPlanetRollingComponent = Stone.createComponent(ExtPlanetRollingComponent::class.java) + DIPro.extOf(DI) + val siriusStrong: java.lang.ref.WeakReference = java.lang.ref.WeakReference(Sirius()) + val siriusSoft: java.lang.ref.WeakReference = java.lang.ref.WeakReference(Sirius()) + val siriusWeak: java.lang.ref.WeakReference = java.lang.ref.WeakReference(Sirius()) + val moonStrong: java.lang.ref.WeakReference = java.lang.ref.WeakReference(Moon()) + val moonSoft: java.lang.ref.WeakReference = java.lang.ref.WeakReference(Moon()) + val moonWeak: java.lang.ref.WeakReference = java.lang.ref.WeakReference(Moon()) + DIPro.sunModule().siriusStrong(siriusStrong.get()) + DIPro.sunModule().siriusSoft(siriusSoft.get()) + DIPro.sunModule().siriusWeak(siriusWeak.get()) + DIPro.moonStrong(moonStrong.get()) + DIPro.moonSoft(moonSoft.get()) + DIPro.moonWeak(moonWeak.get()) //When - DIPro.gcSoftSputniksExt(); + DIPro.gcSoftSputniksExt() //Then - for (WeakReference ref : Arrays.asList( - planetWeak, - starWeak, - siriusWeak, - moonSoft, moonWeak + for (ref in java.util.Arrays.asList>( + planetWeak, + starWeak, + siriusWeak, + moonSoft, moonWeak )) { - assertNull(ref.get()); + org.junit.jupiter.api.Assertions.assertNull(ref.get()) } - for (WeakReference ref : Arrays.asList( - earthStrong, earthSoft, - sunStrong, sunSoft, - siriusStrong, siriusSoft, - moonStrong + for (ref in java.util.Arrays.asList>( + earthStrong, earthSoft, + sunStrong, sunSoft, + siriusStrong, siriusSoft, + moonStrong )) { - assertNotNull(ref.get()); + org.junit.jupiter.api.Assertions.assertNotNull(ref.get()) } } - - } diff --git a/tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/bindinstance/singlemethod_gc/PlanetRollingAndProTests.kt b/tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/bindinstance/singlemethod_gc/PlanetRollingAndProTests.kt index 69108664..981f8e58 100644 --- a/tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/bindinstance/singlemethod_gc/PlanetRollingAndProTests.kt +++ b/tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/bindinstance/singlemethod_gc/PlanetRollingAndProTests.kt @@ -1,347 +1,343 @@ -package com.dirgub.klee0kai.stone.text_ext.bindinstance.singlemethod_gc; - -import com.github.klee0kai.stone.Stone; -import com.github.klee0kai.test.di.bindinstance.singlemethod_gc.PlanetRollingComponent; -import com.github.klee0kai.test.mowgli.galaxy.Earth; -import com.github.klee0kai.test.mowgli.galaxy.Sun; -import com.github.klee0kai.test_ext.inject.di.bindinstance.singlemethod_gc.ExtPlanetRollingComponent; -import com.github.klee0kai.test_ext.inject.mowgli.galaxy.sputniks.Moon; -import com.github.klee0kai.test_ext.inject.mowgli.galaxy.stars.Sirius; -import org.junit.jupiter.api.Test; - -import java.lang.ref.WeakReference; -import java.util.Arrays; - -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertNull; - -public class PlanetRollingAndProTests { +package com.dirgub.klee0kai.stone.text_ext.bindinstance.singlemethod_gc + +import com.github.klee0kai.test.di.bindinstance.singlemethod_gc.PlanetRollingComponent +import com.github.klee0kai.test.di.bindinstance.singlemethod_gc.PlanetRollingComponentStoneComponent +import com.github.klee0kai.test.mowgli.galaxy.Earth +import com.github.klee0kai.test.mowgli.galaxy.Sun +import com.github.klee0kai.test_ext.inject.di.bindinstance.singlemethod_gc.ExtPlanetRollingComponent +import com.github.klee0kai.test_ext.inject.di.bindinstance.singlemethod_gc.ExtPlanetRollingComponentStoneComponent +import com.github.klee0kai.test_ext.inject.mowgli.galaxy.sputniks.Moon +import com.github.klee0kai.test_ext.inject.mowgli.galaxy.stars.Sirius +import org.junit.jupiter.api.Test +import org.junit.jupiter.api.assertNotNull +import org.junit.jupiter.api.assertNull +import java.lang.ref.WeakReference + +class PlanetRollingAndProTests { @Test - public void gcAllTest() { + fun gcAllTest() { //Given - PlanetRollingComponent DI = Stone.createComponent(PlanetRollingComponent.class); - WeakReference earthStrong = new WeakReference<>(new Earth()); - WeakReference earthSoft = new WeakReference<>(new Earth()); - WeakReference planetWeak = new WeakReference<>(new Earth()); - WeakReference sunStrong = new WeakReference<>(new Sun()); - WeakReference sunSoft = new WeakReference<>(new Sun()); - WeakReference starWeak = new WeakReference<>(new Sun()); - DI.earthStrong(earthStrong.get()); - DI.earthSoft(earthSoft.get()); - DI.planet(planetWeak.get()); - DI.sunModule().sunStrong(sunStrong.get()); - DI.sunModule().sunSoft(sunSoft.get()); - DI.sunModule().star(starWeak.get()); + val DI = PlanetRollingComponentStoneComponent() + val earthStrong = WeakReference(Earth()) + val earthSoft = WeakReference(Earth()) + val planetWeak = WeakReference(Earth()) + val sunStrong = WeakReference(Sun()) + val sunSoft = WeakReference(Sun()) + val starWeak = WeakReference(Sun()) + DI.earthStrong(earthStrong.get()) + DI.earthSoft(earthSoft.get()) + DI.planet(planetWeak.get()) + DI.sunModule().sunStrong(sunStrong.get()) + DI.sunModule().sunSoft(sunSoft.get()) + DI.sunModule().star(starWeak.get()) //external component init - ExtPlanetRollingComponent DIPro = Stone.createComponent(ExtPlanetRollingComponent.class); - DIPro.extOf(DI); - WeakReference siriusStrong = new WeakReference<>(new Sirius()); - WeakReference siriusSoft = new WeakReference<>(new Sirius()); - WeakReference siriusWeak = new WeakReference<>(new Sirius()); - WeakReference moonStrong = new WeakReference<>(new Moon()); - WeakReference moonSoft = new WeakReference<>(new Moon()); - WeakReference moonWeak = new WeakReference<>(new Moon()); - DIPro.sunModule().siriusStrong(siriusStrong.get()); - DIPro.sunModule().siriusSoft(siriusSoft.get()); - DIPro.sunModule().siriusWeak(siriusWeak.get()); - DIPro.moonStrong(moonStrong.get()); - DIPro.moonSoft(moonSoft.get()); - DIPro.moonWeak(moonWeak.get()); + val DIPro: ExtPlanetRollingComponent = ExtPlanetRollingComponentStoneComponent() + DIPro.extOf(DI) + val siriusStrong = WeakReference(Sirius()) + val siriusSoft = WeakReference(Sirius()) + val siriusWeak = WeakReference(Sirius()) + val moonStrong = WeakReference(Moon()) + val moonSoft = WeakReference(Moon()) + val moonWeak = WeakReference(Moon()) + DIPro.sunModule()!!.siriusStrong(siriusStrong.get()) + DIPro.sunModule()!!.siriusSoft(siriusSoft.get()) + DIPro.sunModule()!!.siriusWeak(siriusWeak.get()) + DIPro.moonStrong(moonStrong.get()) + DIPro.moonSoft(moonSoft.get()) + DIPro.moonWeak(moonWeak.get()) //When - DI.gcAll(); + DI.gcAll() //Then - for (WeakReference ref : Arrays.asList( - earthStrong, earthSoft, planetWeak, - sunStrong, sunSoft, starWeak, - siriusStrong, siriusSoft, siriusWeak, - moonStrong, moonSoft, moonWeak + for (ref in listOf( + earthStrong, earthSoft, planetWeak, + sunStrong, sunSoft, starWeak, + siriusStrong, siriusSoft, siriusWeak, + moonStrong, moonSoft, moonWeak )) { - assertNull(ref.get()); + assertNull(ref.get()) } } @Test - public void gcStrongTest() { + fun gcStrongTest() { //Given - PlanetRollingComponent DI = Stone.createComponent(PlanetRollingComponent.class); - WeakReference earthStrong = new WeakReference<>(new Earth()); - WeakReference earthSoft = new WeakReference<>(new Earth()); - WeakReference planetWeak = new WeakReference<>(new Earth()); - WeakReference sunStrong = new WeakReference<>(new Sun()); - WeakReference sunSoft = new WeakReference<>(new Sun()); - WeakReference starWeak = new WeakReference<>(new Sun()); - DI.earthStrong(earthStrong.get()); - DI.earthSoft(earthSoft.get()); - DI.planet(planetWeak.get()); - DI.sunModule().sunStrong(sunStrong.get()); - DI.sunModule().sunSoft(sunSoft.get()); - DI.sunModule().star(starWeak.get()); + val DI: PlanetRollingComponent = PlanetRollingComponentStoneComponent() + val earthStrong = WeakReference(Earth()) + val earthSoft = WeakReference(Earth()) + val planetWeak = WeakReference(Earth()) + val sunStrong = WeakReference(Sun()) + val sunSoft = WeakReference(Sun()) + val starWeak = WeakReference(Sun()) + DI.earthStrong(earthStrong.get()) + DI.earthSoft(earthSoft.get()) + DI.planet(planetWeak.get()) + DI.sunModule()!!.sunStrong(sunStrong.get()) + DI.sunModule()!!.sunSoft(sunSoft.get()) + DI.sunModule()!!.star(starWeak.get()) //external component init - ExtPlanetRollingComponent DIPro = Stone.createComponent(ExtPlanetRollingComponent.class); - DIPro.extOf(DI); - WeakReference siriusStrong = new WeakReference<>(new Sirius()); - WeakReference siriusSoft = new WeakReference<>(new Sirius()); - WeakReference siriusWeak = new WeakReference<>(new Sirius()); - WeakReference moonStrong = new WeakReference<>(new Moon()); - WeakReference moonSoft = new WeakReference<>(new Moon()); - WeakReference moonWeak = new WeakReference<>(new Moon()); - DIPro.sunModule().siriusStrong(siriusStrong.get()); - DIPro.sunModule().siriusSoft(siriusSoft.get()); - DIPro.sunModule().siriusWeak(siriusWeak.get()); - DIPro.moonStrong(moonStrong.get()); - DIPro.moonSoft(moonSoft.get()); - DIPro.moonWeak(moonWeak.get()); + val DIPro: ExtPlanetRollingComponent = ExtPlanetRollingComponentStoneComponent() + DIPro.extOf(DI) + val siriusStrong = WeakReference(Sirius()) + val siriusSoft = WeakReference(Sirius()) + val siriusWeak = WeakReference(Sirius()) + val moonStrong = WeakReference(Moon()) + val moonSoft = WeakReference(Moon()) + val moonWeak = WeakReference(Moon()) + DIPro.sunModule()!!.siriusStrong(siriusStrong.get()) + DIPro.sunModule()!!.siriusSoft(siriusSoft.get()) + DIPro.sunModule()!!.siriusWeak(siriusWeak.get()) + DIPro.moonStrong(moonStrong.get()) + DIPro.moonSoft(moonSoft.get()) + DIPro.moonWeak(moonWeak.get()) //When - DI.gcStrong(); + DI.gcStrong() //Then - for (WeakReference ref : Arrays.asList( - earthStrong, planetWeak, - sunStrong, starWeak, - siriusStrong, siriusWeak, - moonStrong, moonWeak + for (ref in listOf( + earthStrong, planetWeak, + sunStrong, starWeak, + siriusStrong, siriusWeak, + moonStrong, moonWeak )) { - assertNull(ref.get()); + assertNull(ref.get()) } - for (WeakReference ref : Arrays.asList( - earthSoft, - sunSoft, - siriusSoft, - moonSoft + for (ref in listOf( + earthSoft, + sunSoft, + siriusSoft, + moonSoft )) { - assertNotNull(ref.get()); + assertNotNull(ref.get()) } } @Test - public void gcSoftTest() { + fun gcSoftTest() { //Given - PlanetRollingComponent DI = Stone.createComponent(PlanetRollingComponent.class); - WeakReference earthStrong = new WeakReference<>(new Earth()); - WeakReference earthSoft = new WeakReference<>(new Earth()); - WeakReference planetWeak = new WeakReference<>(new Earth()); - WeakReference sunStrong = new WeakReference<>(new Sun()); - WeakReference sunSoft = new WeakReference<>(new Sun()); - WeakReference starWeak = new WeakReference<>(new Sun()); - DI.earthStrong(earthStrong.get()); - DI.earthSoft(earthSoft.get()); - DI.planet(planetWeak.get()); - DI.sunModule().sunStrong(sunStrong.get()); - DI.sunModule().sunSoft(sunSoft.get()); - DI.sunModule().star(starWeak.get()); + val DI: PlanetRollingComponent = PlanetRollingComponentStoneComponent() + val earthStrong = WeakReference(Earth()) + val earthSoft = WeakReference(Earth()) + val planetWeak = WeakReference(Earth()) + val sunStrong = WeakReference(Sun()) + val sunSoft = WeakReference(Sun()) + val starWeak = WeakReference(Sun()) + DI.earthStrong(earthStrong.get()) + DI.earthSoft(earthSoft.get()) + DI.planet(planetWeak.get()) + DI.sunModule()!!.sunStrong(sunStrong.get()) + DI.sunModule()!!.sunSoft(sunSoft.get()) + DI.sunModule()!!.star(starWeak.get()) //external component init - ExtPlanetRollingComponent DIPro = Stone.createComponent(ExtPlanetRollingComponent.class); - DIPro.extOf(DI); - WeakReference siriusStrong = new WeakReference<>(new Sirius()); - WeakReference siriusSoft = new WeakReference<>(new Sirius()); - WeakReference siriusWeak = new WeakReference<>(new Sirius()); - WeakReference moonStrong = new WeakReference<>(new Moon()); - WeakReference moonSoft = new WeakReference<>(new Moon()); - WeakReference moonWeak = new WeakReference<>(new Moon()); - DIPro.sunModule().siriusStrong(siriusStrong.get()); - DIPro.sunModule().siriusSoft(siriusSoft.get()); - DIPro.sunModule().siriusWeak(siriusWeak.get()); - DIPro.moonStrong(moonStrong.get()); - DIPro.moonSoft(moonSoft.get()); - DIPro.moonWeak(moonWeak.get()); + val DIPro: ExtPlanetRollingComponent = ExtPlanetRollingComponentStoneComponent() + DIPro.extOf(DI) + val siriusStrong = WeakReference(Sirius()) + val siriusSoft = WeakReference(Sirius()) + val siriusWeak = WeakReference(Sirius()) + val moonStrong = WeakReference(Moon()) + val moonSoft = WeakReference(Moon()) + val moonWeak = WeakReference(Moon()) + DIPro.sunModule()!!.siriusStrong(siriusStrong.get()) + DIPro.sunModule()!!.siriusSoft(siriusSoft.get()) + DIPro.sunModule()!!.siriusWeak(siriusWeak.get()) + DIPro.moonStrong(moonStrong.get()) + DIPro.moonSoft(moonSoft.get()) + DIPro.moonWeak(moonWeak.get()) //When - DI.gcSoft(); + DI.gcSoft() //Then - for (WeakReference ref : Arrays.asList( - earthSoft, planetWeak, - sunSoft, starWeak, - siriusSoft, siriusWeak, - moonSoft, moonWeak + for (ref in listOf( + earthSoft, planetWeak, + sunSoft, starWeak, + siriusSoft, siriusWeak, + moonSoft, moonWeak )) { - assertNull(ref.get()); + assertNull(ref.get()) } - for (WeakReference ref : Arrays.asList( - earthStrong, - sunStrong, - siriusStrong, - moonStrong + for (ref in listOf( + earthStrong, + sunStrong, + siriusStrong, + moonStrong )) { - assertNotNull(ref.get()); + assertNotNull(ref.get()) } } @Test - public void gcWeakTest() { + fun gcWeakTest() { //Given - PlanetRollingComponent DI = Stone.createComponent(PlanetRollingComponent.class); - WeakReference earthStrong = new WeakReference<>(new Earth()); - WeakReference earthSoft = new WeakReference<>(new Earth()); - WeakReference planetWeak = new WeakReference<>(new Earth()); - WeakReference sunStrong = new WeakReference<>(new Sun()); - WeakReference sunSoft = new WeakReference<>(new Sun()); - WeakReference starWeak = new WeakReference<>(new Sun()); - DI.earthStrong(earthStrong.get()); - DI.earthSoft(earthSoft.get()); - DI.planet(planetWeak.get()); - DI.sunModule().sunStrong(sunStrong.get()); - DI.sunModule().sunSoft(sunSoft.get()); - DI.sunModule().star(starWeak.get()); + val DI: PlanetRollingComponent = PlanetRollingComponentStoneComponent() + val earthStrong = WeakReference(Earth()) + val earthSoft = WeakReference(Earth()) + val planetWeak = WeakReference(Earth()) + val sunStrong = WeakReference(Sun()) + val sunSoft = WeakReference(Sun()) + val starWeak = WeakReference(Sun()) + DI.earthStrong(earthStrong.get()) + DI.earthSoft(earthSoft.get()) + DI.planet(planetWeak.get()) + DI.sunModule()!!.sunStrong(sunStrong.get()) + DI.sunModule()!!.sunSoft(sunSoft.get()) + DI.sunModule()!!.star(starWeak.get()) //external component init - ExtPlanetRollingComponent DIPro = Stone.createComponent(ExtPlanetRollingComponent.class); - DIPro.extOf(DI); - WeakReference siriusStrong = new WeakReference<>(new Sirius()); - WeakReference siriusSoft = new WeakReference<>(new Sirius()); - WeakReference siriusWeak = new WeakReference<>(new Sirius()); - WeakReference moonStrong = new WeakReference<>(new Moon()); - WeakReference moonSoft = new WeakReference<>(new Moon()); - WeakReference moonWeak = new WeakReference<>(new Moon()); - DIPro.sunModule().siriusStrong(siriusStrong.get()); - DIPro.sunModule().siriusSoft(siriusSoft.get()); - DIPro.sunModule().siriusWeak(siriusWeak.get()); - DIPro.moonStrong(moonStrong.get()); - DIPro.moonSoft(moonSoft.get()); - DIPro.moonWeak(moonWeak.get()); + val DIPro: ExtPlanetRollingComponent = ExtPlanetRollingComponentStoneComponent() + DIPro.extOf(DI) + val siriusStrong = WeakReference(Sirius()) + val siriusSoft = WeakReference(Sirius()) + val siriusWeak = WeakReference(Sirius()) + val moonStrong = WeakReference(Moon()) + val moonSoft = WeakReference(Moon()) + val moonWeak = WeakReference(Moon()) + DIPro.sunModule()!!.siriusStrong(siriusStrong.get()) + DIPro.sunModule()!!.siriusSoft(siriusSoft.get()) + DIPro.sunModule()!!.siriusWeak(siriusWeak.get()) + DIPro.moonStrong(moonStrong.get()) + DIPro.moonSoft(moonSoft.get()) + DIPro.moonWeak(moonWeak.get()) //When - DI.gcWeak(); + DI.gcWeak() //Then - for (WeakReference ref : Arrays.asList( - planetWeak, - starWeak, - siriusWeak, - moonWeak + for (ref in listOf( + planetWeak, + starWeak, + siriusWeak, + moonWeak )) { - assertNull(ref.get()); + assertNull(ref.get()) } - for (WeakReference ref : Arrays.asList( - earthStrong, earthSoft, - sunStrong, sunSoft, - siriusStrong, siriusSoft, - moonStrong, moonSoft + for (ref in listOf( + earthStrong, earthSoft, + sunStrong, sunSoft, + siriusStrong, siriusSoft, + moonStrong, moonSoft )) { - assertNotNull(ref.get()); + assertNotNull(ref.get()) } } @Test - public void gcSoftSunTest() { + fun gcSoftSunTest() { //Given - PlanetRollingComponent DI = Stone.createComponent(PlanetRollingComponent.class); - WeakReference earthStrong = new WeakReference<>(new Earth()); - WeakReference earthSoft = new WeakReference<>(new Earth()); - WeakReference planetWeak = new WeakReference<>(new Earth()); - WeakReference sunStrong = new WeakReference<>(new Sun()); - WeakReference sunSoft = new WeakReference<>(new Sun()); - WeakReference starWeak = new WeakReference<>(new Sun()); - DI.earthStrong(earthStrong.get()); - DI.earthSoft(earthSoft.get()); - DI.planet(planetWeak.get()); - DI.sunModule().sunStrong(sunStrong.get()); - DI.sunModule().sunSoft(sunSoft.get()); - DI.sunModule().star(starWeak.get()); + val DI: PlanetRollingComponent = PlanetRollingComponentStoneComponent() + val earthStrong = WeakReference(Earth()) + val earthSoft = WeakReference(Earth()) + val planetWeak = WeakReference(Earth()) + val sunStrong = WeakReference(Sun()) + val sunSoft = WeakReference(Sun()) + val starWeak = WeakReference(Sun()) + DI.earthStrong(earthStrong.get()) + DI.earthSoft(earthSoft.get()) + DI.planet(planetWeak.get()) + DI.sunModule()!!.sunStrong(sunStrong.get()) + DI.sunModule()!!.sunSoft(sunSoft.get()) + DI.sunModule()!!.star(starWeak.get()) //external component init - ExtPlanetRollingComponent DIPro = Stone.createComponent(ExtPlanetRollingComponent.class); - DIPro.extOf(DI); - WeakReference siriusStrong = new WeakReference<>(new Sirius()); - WeakReference siriusSoft = new WeakReference<>(new Sirius()); - WeakReference siriusWeak = new WeakReference<>(new Sirius()); - WeakReference moonStrong = new WeakReference<>(new Moon()); - WeakReference moonSoft = new WeakReference<>(new Moon()); - WeakReference moonWeak = new WeakReference<>(new Moon()); - DIPro.sunModule().siriusStrong(siriusStrong.get()); - DIPro.sunModule().siriusSoft(siriusSoft.get()); - DIPro.sunModule().siriusWeak(siriusWeak.get()); - DIPro.moonStrong(moonStrong.get()); - DIPro.moonSoft(moonSoft.get()); - DIPro.moonWeak(moonWeak.get()); + val DIPro: ExtPlanetRollingComponent = ExtPlanetRollingComponentStoneComponent() + DIPro.extOf(DI) + val siriusStrong = WeakReference(Sirius()) + val siriusSoft = WeakReference(Sirius()) + val siriusWeak = WeakReference(Sirius()) + val moonStrong = WeakReference(Moon()) + val moonSoft = WeakReference(Moon()) + val moonWeak = WeakReference(Moon()) + DIPro.sunModule()!!.siriusStrong(siriusStrong.get()) + DIPro.sunModule()!!.siriusSoft(siriusSoft.get()) + DIPro.sunModule()!!.siriusWeak(siriusWeak.get()) + DIPro.moonStrong(moonStrong.get()) + DIPro.moonSoft(moonSoft.get()) + DIPro.moonWeak(moonWeak.get()) //When - DI.gcSoftSun(); + DI.gcSoftSun() //Then - for (WeakReference ref : Arrays.asList( - planetWeak, - sunSoft, starWeak, - siriusWeak, - moonWeak + for (ref in listOf( + planetWeak, + sunSoft, starWeak, + siriusWeak, + moonWeak )) { - assertNull(ref.get()); + assertNull(ref.get()) } - for (WeakReference ref : Arrays.asList( - earthStrong, earthSoft, - sunStrong, - siriusStrong, siriusSoft, - moonStrong, moonSoft + for (ref in listOf( + earthStrong, earthSoft, + sunStrong, + siriusStrong, siriusSoft, + moonStrong, moonSoft )) { - assertNotNull(ref.get()); + assertNotNull(ref.get()) } } @Test - public void gcSoftPlanetsTest() { + fun gcSoftPlanetsTest() { //Given - PlanetRollingComponent DI = Stone.createComponent(PlanetRollingComponent.class); - WeakReference earthStrong = new WeakReference<>(new Earth()); - WeakReference earthSoft = new WeakReference<>(new Earth()); - WeakReference planetWeak = new WeakReference<>(new Earth()); - WeakReference sunStrong = new WeakReference<>(new Sun()); - WeakReference sunSoft = new WeakReference<>(new Sun()); - WeakReference starWeak = new WeakReference<>(new Sun()); - DI.earthStrong(earthStrong.get()); - DI.earthSoft(earthSoft.get()); - DI.planet(planetWeak.get()); - DI.sunModule().sunStrong(sunStrong.get()); - DI.sunModule().sunSoft(sunSoft.get()); - DI.sunModule().star(starWeak.get()); + val DI: PlanetRollingComponent = PlanetRollingComponentStoneComponent() + val earthStrong = WeakReference(Earth()) + val earthSoft = WeakReference(Earth()) + val planetWeak = WeakReference(Earth()) + val sunStrong = WeakReference(Sun()) + val sunSoft = WeakReference(Sun()) + val starWeak = WeakReference(Sun()) + DI.earthStrong(earthStrong.get()) + DI.earthSoft(earthSoft.get()) + DI.planet(planetWeak.get()) + DI.sunModule()!!.sunStrong(sunStrong.get()) + DI.sunModule()!!.sunSoft(sunSoft.get()) + DI.sunModule()!!.star(starWeak.get()) //external component init - ExtPlanetRollingComponent DIPro = Stone.createComponent(ExtPlanetRollingComponent.class); - DIPro.extOf(DI); - WeakReference siriusStrong = new WeakReference<>(new Sirius()); - WeakReference siriusSoft = new WeakReference<>(new Sirius()); - WeakReference siriusWeak = new WeakReference<>(new Sirius()); - WeakReference moonStrong = new WeakReference<>(new Moon()); - WeakReference moonSoft = new WeakReference<>(new Moon()); - WeakReference moonWeak = new WeakReference<>(new Moon()); - DIPro.sunModule().siriusStrong(siriusStrong.get()); - DIPro.sunModule().siriusSoft(siriusSoft.get()); - DIPro.sunModule().siriusWeak(siriusWeak.get()); - DIPro.moonStrong(moonStrong.get()); - DIPro.moonSoft(moonSoft.get()); - DIPro.moonWeak(moonWeak.get()); + val DIPro: ExtPlanetRollingComponent = ExtPlanetRollingComponentStoneComponent() + DIPro.extOf(DI) + val siriusStrong = WeakReference(Sirius()) + val siriusSoft = WeakReference(Sirius()) + val siriusWeak = WeakReference(Sirius()) + val moonStrong = WeakReference(Moon()) + val moonSoft = WeakReference(Moon()) + val moonWeak = WeakReference(Moon()) + DIPro.sunModule()!!.siriusStrong(siriusStrong.get()) + DIPro.sunModule()!!.siriusSoft(siriusSoft.get()) + DIPro.sunModule()!!.siriusWeak(siriusWeak.get()) + DIPro.moonStrong(moonStrong.get()) + DIPro.moonSoft(moonSoft.get()) + DIPro.moonWeak(moonWeak.get()) //When - DI.gcSoftPlanets(); + DI.gcSoftPlanets() //Then - for (WeakReference ref : Arrays.asList( - earthSoft, planetWeak, - starWeak, - siriusWeak, - moonWeak + for (ref in listOf( + earthSoft, planetWeak, + starWeak, + siriusWeak, + moonWeak )) { - assertNull(ref.get()); + assertNull(ref.get()) } - for (WeakReference ref : Arrays.asList( - earthStrong, - sunStrong, sunSoft, - siriusStrong, siriusSoft, - moonStrong, moonSoft + for (ref in listOf( + earthStrong, + sunStrong, sunSoft, + siriusStrong, siriusSoft, + moonStrong, moonSoft )) { - assertNotNull(ref.get()); + assertNotNull(ref.get()) } } - - } diff --git a/tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/bindinstance/singlemethod_gc/PlanetRollingFromProTests.kt b/tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/bindinstance/singlemethod_gc/PlanetRollingFromProTests.kt index e8cbe1d2..ff82d22f 100644 --- a/tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/bindinstance/singlemethod_gc/PlanetRollingFromProTests.kt +++ b/tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/bindinstance/singlemethod_gc/PlanetRollingFromProTests.kt @@ -1,347 +1,344 @@ -package com.dirgub.klee0kai.stone.text_ext.bindinstance.singlemethod_gc; - -import com.github.klee0kai.stone.Stone; -import com.github.klee0kai.test.di.bindinstance.singlemethod_gc.PlanetRollingComponent; -import com.github.klee0kai.test.mowgli.galaxy.Earth; -import com.github.klee0kai.test.mowgli.galaxy.Sun; -import com.github.klee0kai.test_ext.inject.di.bindinstance.singlemethod_gc.ExtPlanetRollingComponent; -import com.github.klee0kai.test_ext.inject.mowgli.galaxy.sputniks.Moon; -import com.github.klee0kai.test_ext.inject.mowgli.galaxy.stars.Sirius; -import org.junit.jupiter.api.Test; - -import java.lang.ref.WeakReference; -import java.util.Arrays; - -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertNull; - -public class PlanetRollingFromProTests { +package com.dirgub.klee0kai.stone.text_ext.bindinstance.singlemethod_gc + +import com.github.klee0kai.test.di.bindinstance.singlemethod_gc.PlanetRollingComponent +import com.github.klee0kai.test.di.bindinstance.singlemethod_gc.PlanetRollingComponentStoneComponent +import com.github.klee0kai.test.mowgli.galaxy.Earth +import com.github.klee0kai.test.mowgli.galaxy.Sun +import com.github.klee0kai.test_ext.inject.di.bindinstance.singlemethod_gc.ExtPlanetRollingComponent +import com.github.klee0kai.test_ext.inject.di.bindinstance.singlemethod_gc.ExtPlanetRollingComponentStoneComponent +import com.github.klee0kai.test_ext.inject.mowgli.galaxy.sputniks.Moon +import com.github.klee0kai.test_ext.inject.mowgli.galaxy.stars.Sirius +import org.junit.jupiter.api.Test +import org.junit.jupiter.api.assertNotNull +import org.junit.jupiter.api.assertNull +import java.lang.ref.WeakReference + +class PlanetRollingFromProTests { @Test - public void gcAllTest() { + fun gcAllTest() { //Given - PlanetRollingComponent DI = Stone.createComponent(PlanetRollingComponent.class); - WeakReference earthStrong = new WeakReference<>(new Earth()); - WeakReference earthSoft = new WeakReference<>(new Earth()); - WeakReference planetWeak = new WeakReference<>(new Earth()); - WeakReference sunStrong = new WeakReference<>(new Sun()); - WeakReference sunSoft = new WeakReference<>(new Sun()); - WeakReference starWeak = new WeakReference<>(new Sun()); - DI.earthStrong(earthStrong.get()); - DI.earthSoft(earthSoft.get()); - DI.planet(planetWeak.get()); - DI.sunModule().sunStrong(sunStrong.get()); - DI.sunModule().sunSoft(sunSoft.get()); - DI.sunModule().star(starWeak.get()); + val DI: PlanetRollingComponent = PlanetRollingComponentStoneComponent() + val earthStrong = WeakReference(Earth()) + val earthSoft = WeakReference(Earth()) + val planetWeak = WeakReference(Earth()) + val sunStrong = WeakReference(Sun()) + val sunSoft = WeakReference(Sun()) + val starWeak = WeakReference(Sun()) + DI.earthStrong(earthStrong.get()) + DI.earthSoft(earthSoft.get()) + DI.planet(planetWeak.get()) + DI.sunModule()!!.sunStrong(sunStrong.get()) + DI.sunModule()!!.sunSoft(sunSoft.get()) + DI.sunModule()!!.star(starWeak.get()) //external component init - ExtPlanetRollingComponent DIPro = Stone.createComponent(ExtPlanetRollingComponent.class); - DIPro.extOf(DI); - WeakReference siriusStrong = new WeakReference<>(new Sirius()); - WeakReference siriusSoft = new WeakReference<>(new Sirius()); - WeakReference siriusWeak = new WeakReference<>(new Sirius()); - WeakReference moonStrong = new WeakReference<>(new Moon()); - WeakReference moonSoft = new WeakReference<>(new Moon()); - WeakReference moonWeak = new WeakReference<>(new Moon()); - DIPro.sunModule().siriusStrong(siriusStrong.get()); - DIPro.sunModule().siriusSoft(siriusSoft.get()); - DIPro.sunModule().siriusWeak(siriusWeak.get()); - DIPro.moonStrong(moonStrong.get()); - DIPro.moonSoft(moonSoft.get()); - DIPro.moonWeak(moonWeak.get()); + val DIPro: ExtPlanetRollingComponent = ExtPlanetRollingComponentStoneComponent() + DIPro.extOf(DI) + val siriusStrong = WeakReference(Sirius()) + val siriusSoft = WeakReference(Sirius()) + val siriusWeak = WeakReference(Sirius()) + val moonStrong = WeakReference(Moon()) + val moonSoft = WeakReference(Moon()) + val moonWeak = WeakReference(Moon()) + DIPro.sunModule()!!.siriusStrong(siriusStrong.get()) + DIPro.sunModule()!!.siriusSoft(siriusSoft.get()) + DIPro.sunModule()!!.siriusWeak(siriusWeak.get()) + DIPro.moonStrong(moonStrong.get()) + DIPro.moonSoft(moonSoft.get()) + DIPro.moonWeak(moonWeak.get()) //When - DIPro.gcAll(); + DIPro.gcAll() //Then - for (WeakReference ref : Arrays.asList( - earthStrong, earthSoft, planetWeak, - sunStrong, sunSoft, starWeak, - siriusStrong, siriusSoft, siriusWeak, - moonStrong, moonSoft, moonWeak + for (ref in listOf( + earthStrong, earthSoft, planetWeak, + sunStrong, sunSoft, starWeak, + siriusStrong, siriusSoft, siriusWeak, + moonStrong, moonSoft, moonWeak )) { - assertNull(ref.get()); + assertNull(ref.get()) } } @Test - public void gcStrongTest() { + fun gcStrongTest() { //Given - PlanetRollingComponent DI = Stone.createComponent(PlanetRollingComponent.class); - WeakReference earthStrong = new WeakReference<>(new Earth()); - WeakReference earthSoft = new WeakReference<>(new Earth()); - WeakReference planetWeak = new WeakReference<>(new Earth()); - WeakReference sunStrong = new WeakReference<>(new Sun()); - WeakReference sunSoft = new WeakReference<>(new Sun()); - WeakReference starWeak = new WeakReference<>(new Sun()); - DI.earthStrong(earthStrong.get()); - DI.earthSoft(earthSoft.get()); - DI.planet(planetWeak.get()); - DI.sunModule().sunStrong(sunStrong.get()); - DI.sunModule().sunSoft(sunSoft.get()); - DI.sunModule().star(starWeak.get()); + val DI: PlanetRollingComponent = PlanetRollingComponentStoneComponent() + val earthStrong = WeakReference(Earth()) + val earthSoft = WeakReference(Earth()) + val planetWeak = WeakReference(Earth()) + val sunStrong = WeakReference(Sun()) + val sunSoft = WeakReference(Sun()) + val starWeak = WeakReference(Sun()) + DI.earthStrong(earthStrong.get()) + DI.earthSoft(earthSoft.get()) + DI.planet(planetWeak.get()) + DI.sunModule()!!.sunStrong(sunStrong.get()) + DI.sunModule()!!.sunSoft(sunSoft.get()) + DI.sunModule()!!.star(starWeak.get()) //external component init - ExtPlanetRollingComponent DIPro = Stone.createComponent(ExtPlanetRollingComponent.class); - DIPro.extOf(DI); - WeakReference siriusStrong = new WeakReference<>(new Sirius()); - WeakReference siriusSoft = new WeakReference<>(new Sirius()); - WeakReference siriusWeak = new WeakReference<>(new Sirius()); - WeakReference moonStrong = new WeakReference<>(new Moon()); - WeakReference moonSoft = new WeakReference<>(new Moon()); - WeakReference moonWeak = new WeakReference<>(new Moon()); - DIPro.sunModule().siriusStrong(siriusStrong.get()); - DIPro.sunModule().siriusSoft(siriusSoft.get()); - DIPro.sunModule().siriusWeak(siriusWeak.get()); - DIPro.moonStrong(moonStrong.get()); - DIPro.moonSoft(moonSoft.get()); - DIPro.moonWeak(moonWeak.get()); + val DIPro: ExtPlanetRollingComponent = ExtPlanetRollingComponentStoneComponent() + DIPro.extOf(DI) + val siriusStrong = WeakReference(Sirius()) + val siriusSoft = WeakReference(Sirius()) + val siriusWeak = WeakReference(Sirius()) + val moonStrong = WeakReference(Moon()) + val moonSoft = WeakReference(Moon()) + val moonWeak = WeakReference(Moon()) + DIPro.sunModule()!!.siriusStrong(siriusStrong.get()) + DIPro.sunModule()!!.siriusSoft(siriusSoft.get()) + DIPro.sunModule()!!.siriusWeak(siriusWeak.get()) + DIPro.moonStrong(moonStrong.get()) + DIPro.moonSoft(moonSoft.get()) + DIPro.moonWeak(moonWeak.get()) //When - DIPro.gcStrong(); + DIPro.gcStrong() //Then - for (WeakReference ref : Arrays.asList( - earthStrong, planetWeak, - sunStrong, starWeak, - siriusStrong, siriusWeak, - moonStrong, moonWeak + for (ref in listOf( + earthStrong, planetWeak, + sunStrong, starWeak, + siriusStrong, siriusWeak, + moonStrong, moonWeak )) { - assertNull(ref.get()); + assertNull(ref.get()) } - for (WeakReference ref : Arrays.asList( - earthSoft, - sunSoft, - siriusSoft, - moonSoft + for (ref in listOf( + earthSoft, + sunSoft, + siriusSoft, + moonSoft )) { - assertNotNull(ref.get()); + assertNotNull(ref.get()) } } @Test - public void gcSoftTest() { + fun gcSoftTest() { //Given - PlanetRollingComponent DI = Stone.createComponent(PlanetRollingComponent.class); - WeakReference earthStrong = new WeakReference<>(new Earth()); - WeakReference earthSoft = new WeakReference<>(new Earth()); - WeakReference planetWeak = new WeakReference<>(new Earth()); - WeakReference sunStrong = new WeakReference<>(new Sun()); - WeakReference sunSoft = new WeakReference<>(new Sun()); - WeakReference starWeak = new WeakReference<>(new Sun()); - DI.earthStrong(earthStrong.get()); - DI.earthSoft(earthSoft.get()); - DI.planet(planetWeak.get()); - DI.sunModule().sunStrong(sunStrong.get()); - DI.sunModule().sunSoft(sunSoft.get()); - DI.sunModule().star(starWeak.get()); + val DI: PlanetRollingComponent = PlanetRollingComponentStoneComponent() + val earthStrong = WeakReference(Earth()) + val earthSoft = WeakReference(Earth()) + val planetWeak = WeakReference(Earth()) + val sunStrong = WeakReference(Sun()) + val sunSoft = WeakReference(Sun()) + val starWeak = WeakReference(Sun()) + DI.earthStrong(earthStrong.get()) + DI.earthSoft(earthSoft.get()) + DI.planet(planetWeak.get()) + DI.sunModule()!!.sunStrong(sunStrong.get()) + DI.sunModule()!!.sunSoft(sunSoft.get()) + DI.sunModule()!!.star(starWeak.get()) //external component init - ExtPlanetRollingComponent DIPro = Stone.createComponent(ExtPlanetRollingComponent.class); - DIPro.extOf(DI); - WeakReference siriusStrong = new WeakReference<>(new Sirius()); - WeakReference siriusSoft = new WeakReference<>(new Sirius()); - WeakReference siriusWeak = new WeakReference<>(new Sirius()); - WeakReference moonStrong = new WeakReference<>(new Moon()); - WeakReference moonSoft = new WeakReference<>(new Moon()); - WeakReference moonWeak = new WeakReference<>(new Moon()); - DIPro.sunModule().siriusStrong(siriusStrong.get()); - DIPro.sunModule().siriusSoft(siriusSoft.get()); - DIPro.sunModule().siriusWeak(siriusWeak.get()); - DIPro.moonStrong(moonStrong.get()); - DIPro.moonSoft(moonSoft.get()); - DIPro.moonWeak(moonWeak.get()); + val DIPro: ExtPlanetRollingComponent = ExtPlanetRollingComponentStoneComponent() + DIPro.extOf(DI) + val siriusStrong = WeakReference(Sirius()) + val siriusSoft = WeakReference(Sirius()) + val siriusWeak = WeakReference(Sirius()) + val moonStrong = WeakReference(Moon()) + val moonSoft = WeakReference(Moon()) + val moonWeak = WeakReference(Moon()) + DIPro.sunModule()!!.siriusStrong(siriusStrong.get()) + DIPro.sunModule()!!.siriusSoft(siriusSoft.get()) + DIPro.sunModule()!!.siriusWeak(siriusWeak.get()) + DIPro.moonStrong(moonStrong.get()) + DIPro.moonSoft(moonSoft.get()) + DIPro.moonWeak(moonWeak.get()) //When - DIPro.gcSoft(); + DIPro.gcSoft() //Then - for (WeakReference ref : Arrays.asList( - earthSoft, planetWeak, - sunSoft, starWeak, - siriusSoft, siriusWeak, - moonSoft, moonWeak + for (ref in listOf( + earthSoft, planetWeak, + sunSoft, starWeak, + siriusSoft, siriusWeak, + moonSoft, moonWeak )) { - assertNull(ref.get()); + assertNull(ref.get()) } - for (WeakReference ref : Arrays.asList( - earthStrong, - sunStrong, - siriusStrong, - moonStrong + for (ref in listOf( + earthStrong, + sunStrong, + siriusStrong, + moonStrong )) { - assertNotNull(ref.get()); + assertNotNull(ref.get()) } } @Test - public void gcWeakTest() { + fun gcWeakTest() { //Given - PlanetRollingComponent DI = Stone.createComponent(PlanetRollingComponent.class); - WeakReference earthStrong = new WeakReference<>(new Earth()); - WeakReference earthSoft = new WeakReference<>(new Earth()); - WeakReference planetWeak = new WeakReference<>(new Earth()); - WeakReference sunStrong = new WeakReference<>(new Sun()); - WeakReference sunSoft = new WeakReference<>(new Sun()); - WeakReference starWeak = new WeakReference<>(new Sun()); - DI.earthStrong(earthStrong.get()); - DI.earthSoft(earthSoft.get()); - DI.planet(planetWeak.get()); - DI.sunModule().sunStrong(sunStrong.get()); - DI.sunModule().sunSoft(sunSoft.get()); - DI.sunModule().star(starWeak.get()); + val DI: PlanetRollingComponent = PlanetRollingComponentStoneComponent() + val earthStrong = WeakReference(Earth()) + val earthSoft = WeakReference(Earth()) + val planetWeak = WeakReference(Earth()) + val sunStrong = WeakReference(Sun()) + val sunSoft = WeakReference(Sun()) + val starWeak = WeakReference(Sun()) + DI.earthStrong(earthStrong.get()) + DI.earthSoft(earthSoft.get()) + DI.planet(planetWeak.get()) + DI.sunModule()!!.sunStrong(sunStrong.get()) + DI.sunModule()!!.sunSoft(sunSoft.get()) + DI.sunModule()!!.star(starWeak.get()) //external component init - ExtPlanetRollingComponent DIPro = Stone.createComponent(ExtPlanetRollingComponent.class); - DIPro.extOf(DI); - WeakReference siriusStrong = new WeakReference<>(new Sirius()); - WeakReference siriusSoft = new WeakReference<>(new Sirius()); - WeakReference siriusWeak = new WeakReference<>(new Sirius()); - WeakReference moonStrong = new WeakReference<>(new Moon()); - WeakReference moonSoft = new WeakReference<>(new Moon()); - WeakReference moonWeak = new WeakReference<>(new Moon()); - DIPro.sunModule().siriusStrong(siriusStrong.get()); - DIPro.sunModule().siriusSoft(siriusSoft.get()); - DIPro.sunModule().siriusWeak(siriusWeak.get()); - DIPro.moonStrong(moonStrong.get()); - DIPro.moonSoft(moonSoft.get()); - DIPro.moonWeak(moonWeak.get()); + val DIPro: ExtPlanetRollingComponent = ExtPlanetRollingComponentStoneComponent() + DIPro.extOf(DI) + val siriusStrong = WeakReference(Sirius()) + val siriusSoft = WeakReference(Sirius()) + val siriusWeak = WeakReference(Sirius()) + val moonStrong = WeakReference(Moon()) + val moonSoft = WeakReference(Moon()) + val moonWeak = WeakReference(Moon()) + DIPro.sunModule()!!.siriusStrong(siriusStrong.get()) + DIPro.sunModule()!!.siriusSoft(siriusSoft.get()) + DIPro.sunModule()!!.siriusWeak(siriusWeak.get()) + DIPro.moonStrong(moonStrong.get()) + DIPro.moonSoft(moonSoft.get()) + DIPro.moonWeak(moonWeak.get()) //When - DIPro.gcWeak(); + DIPro.gcWeak() //Then - for (WeakReference ref : Arrays.asList( - planetWeak, - starWeak, - siriusWeak, - moonWeak + for (ref in listOf( + planetWeak, + starWeak, + siriusWeak, + moonWeak )) { - assertNull(ref.get()); + assertNull(ref.get()) } - for (WeakReference ref : Arrays.asList( - earthStrong, earthSoft, - sunStrong, sunSoft, - siriusStrong, siriusSoft, - moonStrong, moonSoft + for (ref in listOf( + earthStrong, earthSoft, + sunStrong, sunSoft, + siriusStrong, siriusSoft, + moonStrong, moonSoft )) { - assertNotNull(ref.get()); + assertNotNull(ref.get()) } } @Test - public void gcSoftSunTest() { + fun gcSoftSunTest() { //Given - PlanetRollingComponent DI = Stone.createComponent(PlanetRollingComponent.class); - WeakReference earthStrong = new WeakReference<>(new Earth()); - WeakReference earthSoft = new WeakReference<>(new Earth()); - WeakReference planetWeak = new WeakReference<>(new Earth()); - WeakReference sunStrong = new WeakReference<>(new Sun()); - WeakReference sunSoft = new WeakReference<>(new Sun()); - WeakReference starWeak = new WeakReference<>(new Sun()); - DI.earthStrong(earthStrong.get()); - DI.earthSoft(earthSoft.get()); - DI.planet(planetWeak.get()); - DI.sunModule().sunStrong(sunStrong.get()); - DI.sunModule().sunSoft(sunSoft.get()); - DI.sunModule().star(starWeak.get()); + val DI: PlanetRollingComponent = PlanetRollingComponentStoneComponent() + val earthStrong = WeakReference(Earth()) + val earthSoft = WeakReference(Earth()) + val planetWeak = WeakReference(Earth()) + val sunStrong = WeakReference(Sun()) + val sunSoft = WeakReference(Sun()) + val starWeak = WeakReference(Sun()) + DI.earthStrong(earthStrong.get()) + DI.earthSoft(earthSoft.get()) + DI.planet(planetWeak.get()) + DI.sunModule()!!.sunStrong(sunStrong.get()) + DI.sunModule()!!.sunSoft(sunSoft.get()) + DI.sunModule()!!.star(starWeak.get()) //external component init - ExtPlanetRollingComponent DIPro = Stone.createComponent(ExtPlanetRollingComponent.class); - DIPro.extOf(DI); - WeakReference siriusStrong = new WeakReference<>(new Sirius()); - WeakReference siriusSoft = new WeakReference<>(new Sirius()); - WeakReference siriusWeak = new WeakReference<>(new Sirius()); - WeakReference moonStrong = new WeakReference<>(new Moon()); - WeakReference moonSoft = new WeakReference<>(new Moon()); - WeakReference moonWeak = new WeakReference<>(new Moon()); - DIPro.sunModule().siriusStrong(siriusStrong.get()); - DIPro.sunModule().siriusSoft(siriusSoft.get()); - DIPro.sunModule().siriusWeak(siriusWeak.get()); - DIPro.moonStrong(moonStrong.get()); - DIPro.moonSoft(moonSoft.get()); - DIPro.moonWeak(moonWeak.get()); + val DIPro: ExtPlanetRollingComponent = ExtPlanetRollingComponentStoneComponent() + DIPro.extOf(DI) + val siriusStrong = WeakReference(Sirius()) + val siriusSoft = WeakReference(Sirius()) + val siriusWeak = WeakReference(Sirius()) + val moonStrong = WeakReference(Moon()) + val moonSoft = WeakReference(Moon()) + val moonWeak = WeakReference(Moon()) + DIPro.sunModule()!!.siriusStrong(siriusStrong.get()) + DIPro.sunModule()!!.siriusSoft(siriusSoft.get()) + DIPro.sunModule()!!.siriusWeak(siriusWeak.get()) + DIPro.moonStrong(moonStrong.get()) + DIPro.moonSoft(moonSoft.get()) + DIPro.moonWeak(moonWeak.get()) //When - DIPro.gcSoftSun(); + DIPro.gcSoftSun() //Then - for (WeakReference ref : Arrays.asList( - planetWeak, - sunSoft, starWeak, - siriusWeak, - moonWeak + for (ref in listOf( + planetWeak, + sunSoft, starWeak, + siriusWeak, + moonWeak )) { - assertNull(ref.get()); + assertNull(ref.get()) } - for (WeakReference ref : Arrays.asList( - earthStrong, earthSoft, - sunStrong, - siriusStrong, siriusSoft, - moonStrong, moonSoft + for (ref in listOf( + earthStrong, earthSoft, + sunStrong, + siriusStrong, siriusSoft, + moonStrong, moonSoft )) { - assertNotNull(ref.get()); + assertNotNull(ref.get()) } } @Test - public void gcSoftPlanetsTest() { + fun gcSoftPlanetsTest() { //Given - PlanetRollingComponent DI = Stone.createComponent(PlanetRollingComponent.class); - WeakReference earthStrong = new WeakReference<>(new Earth()); - WeakReference earthSoft = new WeakReference<>(new Earth()); - WeakReference planetWeak = new WeakReference<>(new Earth()); - WeakReference sunStrong = new WeakReference<>(new Sun()); - WeakReference sunSoft = new WeakReference<>(new Sun()); - WeakReference starWeak = new WeakReference<>(new Sun()); - DI.earthStrong(earthStrong.get()); - DI.earthSoft(earthSoft.get()); - DI.planet(planetWeak.get()); - DI.sunModule().sunStrong(sunStrong.get()); - DI.sunModule().sunSoft(sunSoft.get()); - DI.sunModule().star(starWeak.get()); + val DI: PlanetRollingComponent = PlanetRollingComponentStoneComponent() + val earthStrong = WeakReference(Earth()) + val earthSoft = WeakReference(Earth()) + val planetWeak = WeakReference(Earth()) + val sunStrong = WeakReference(Sun()) + val sunSoft = WeakReference(Sun()) + val starWeak = WeakReference(Sun()) + DI.earthStrong(earthStrong.get()) + DI.earthSoft(earthSoft.get()) + DI.planet(planetWeak.get()) + DI.sunModule()!!.sunStrong(sunStrong.get()) + DI.sunModule()!!.sunSoft(sunSoft.get()) + DI.sunModule()!!.star(starWeak.get()) //external component init - ExtPlanetRollingComponent DIPro = Stone.createComponent(ExtPlanetRollingComponent.class); - DIPro.extOf(DI); - WeakReference siriusStrong = new WeakReference<>(new Sirius()); - WeakReference siriusSoft = new WeakReference<>(new Sirius()); - WeakReference siriusWeak = new WeakReference<>(new Sirius()); - WeakReference moonStrong = new WeakReference<>(new Moon()); - WeakReference moonSoft = new WeakReference<>(new Moon()); - WeakReference moonWeak = new WeakReference<>(new Moon()); - DIPro.sunModule().siriusStrong(siriusStrong.get()); - DIPro.sunModule().siriusSoft(siriusSoft.get()); - DIPro.sunModule().siriusWeak(siriusWeak.get()); - DIPro.moonStrong(moonStrong.get()); - DIPro.moonSoft(moonSoft.get()); - DIPro.moonWeak(moonWeak.get()); + val DIPro: ExtPlanetRollingComponent = ExtPlanetRollingComponentStoneComponent() + DIPro.extOf(DI) + val siriusStrong = WeakReference(Sirius()) + val siriusSoft = WeakReference(Sirius()) + val siriusWeak = WeakReference(Sirius()) + val moonStrong = WeakReference(Moon()) + val moonSoft = WeakReference(Moon()) + val moonWeak = WeakReference(Moon()) + DIPro.sunModule()!!.siriusStrong(siriusStrong.get()) + DIPro.sunModule()!!.siriusSoft(siriusSoft.get()) + DIPro.sunModule()!!.siriusWeak(siriusWeak.get()) + DIPro.moonStrong(moonStrong.get()) + DIPro.moonSoft(moonSoft.get()) + DIPro.moonWeak(moonWeak.get()) //When - DIPro.gcSoftPlanets(); + DIPro.gcSoftPlanets() //Then - for (WeakReference ref : Arrays.asList( - earthSoft, planetWeak, - starWeak, - siriusWeak, - moonWeak + for (ref in listOf( + earthSoft, planetWeak, + starWeak, + siriusWeak, + moonWeak )) { - assertNull(ref.get()); + assertNull(ref.get()) } - for (WeakReference ref : Arrays.asList( - earthStrong, - sunStrong, sunSoft, - siriusStrong, siriusSoft, - moonStrong, moonSoft + for (ref in listOf( + earthStrong, + sunStrong, sunSoft, + siriusStrong, siriusSoft, + moonStrong, moonSoft )) { - assertNotNull(ref.get()); + assertNotNull(ref.get()) } } - } diff --git a/tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/cache/EarthCacheAndProTests.kt b/tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/cache/EarthCacheAndProTests.kt index 20baec07..8e8376b6 100644 --- a/tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/cache/EarthCacheAndProTests.kt +++ b/tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/cache/EarthCacheAndProTests.kt @@ -1,148 +1,146 @@ -package com.dirgub.klee0kai.stone.text_ext.cache; +package com.dirgub.klee0kai.stone.text_ext.cache -import com.github.klee0kai.stone.Stone; -import com.github.klee0kai.test.di.gcforest.GcGodComponent; -import com.github.klee0kai.test.mowgli.earth.Mountain; -import com.github.klee0kai.test_ext.inject.di.gcforest.GcGodExtComponent; -import org.junit.jupiter.api.Test; +import com.github.klee0kai.test.di.gcforest.GcGodComponent +import com.github.klee0kai.test.di.gcforest.GcGodComponentStoneComponent +import com.github.klee0kai.test.mowgli.earth.Mountain +import com.github.klee0kai.test_ext.inject.di.gcforest.GcGodExtComponent +import com.github.klee0kai.test_ext.inject.di.gcforest.GcGodExtComponentStoneComponent +import org.junit.jupiter.api.Assertions.assertEquals +import org.junit.jupiter.api.Assertions.assertNotEquals +import org.junit.jupiter.api.Test -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotEquals; - -public class EarthCacheAndProTests { +class EarthCacheAndProTests { @Test - public void strongCacheTest() { + fun strongCacheTest() { //Given - GcGodComponent DI = Stone.createComponent(GcGodComponent.class); - GcGodExtComponent DIPro = Stone.createComponent(GcGodExtComponent.class); - DIPro.extOf(DI); + val DI: GcGodComponent = GcGodComponentStoneComponent() + val DIPro: GcGodExtComponent = GcGodExtComponentStoneComponent() + DIPro.extOf(DI) //When - Mountain mountain1 = DI.earth().mountainStrong(); - Mountain mountain2 = DI.earth().mountainStrong(); + val mountain1: Mountain? = DI.earth()!!.mountainStrong() + val mountain2: Mountain? = DI.earth()!!.mountainStrong() //Then assertEquals( - mountain1.uuid, - mountain2.uuid - ); + mountain1!!.uuid, + mountain2!!.uuid + ) } - @Test - public void softCacheTest() { + fun softCacheTest() { //Given - GcGodComponent DI = Stone.createComponent(GcGodComponent.class); - GcGodExtComponent DIPro = Stone.createComponent(GcGodExtComponent.class); - DIPro.extOf(DI); + val DI: GcGodComponent = GcGodComponentStoneComponent() + val DIPro: GcGodExtComponent = GcGodExtComponentStoneComponent() + DIPro.extOf(DI) //When - Mountain mountain1 = DI.earth().mountainSoft(); - Mountain mountain2 = DI.earth().mountainSoft(); + val mountain1 = DI.earth()!!.mountainSoft() + val mountain2 = DI.earth()!!.mountainSoft() //Then assertEquals( - mountain1.uuid, - mountain2.uuid - ); + mountain1!!.uuid, + mountain2!!.uuid + ) } @Test - public void weakCacheTest() { + fun weakCacheTest() { //Given - GcGodComponent DI = Stone.createComponent(GcGodComponent.class); - GcGodExtComponent DIPro = Stone.createComponent(GcGodExtComponent.class); - DIPro.extOf(DI); + val DI: GcGodComponent = GcGodComponentStoneComponent() + val DIPro: GcGodExtComponent = GcGodExtComponentStoneComponent() + DIPro.extOf(DI) //When - Mountain mountain1 = DI.earth().mountainWeak(); - Mountain mountain2 = DI.earth().mountainWeak(); + val mountain1: Mountain? = DI.earth()!!.mountainWeak() + val mountain2: Mountain? = DI.earth()!!.mountainWeak() //Then assertEquals( - mountain1.uuid, - mountain2.uuid - ); + mountain1!!.uuid, + mountain2!!.uuid, + ) } @Test - public void defCacheTest() { + fun defCacheTest() { //Given - GcGodComponent DI = Stone.createComponent(GcGodComponent.class); - GcGodExtComponent DIPro = Stone.createComponent(GcGodExtComponent.class); - DIPro.extOf(DI); + val DI: GcGodComponent = GcGodComponentStoneComponent() + val DIPro: GcGodExtComponent = GcGodExtComponentStoneComponent() + DIPro.extOf(DI) //When - Mountain mountain1 = DI.earth().mountainDefaultFactory(); - Mountain mountain2 = DI.earth().mountainDefaultFactory(); + val mountain1: Mountain? = DI.earth()!!.mountainDefaultFactory() + val mountain2: Mountain? = DI.earth()!!.mountainDefaultFactory() //Then assertNotEquals( - mountain1.uuid, - mountain2.uuid, - "Factory providing" - ); + mountain1!!.uuid, + mountain2!!.uuid, + "Factory providing" + ) } @Test - public void differentMethodDifferentCacheTest() { + fun differentMethodDifferentCacheTest() { //Given - GcGodComponent DI = Stone.createComponent(GcGodComponent.class); - GcGodExtComponent DIPro = Stone.createComponent(GcGodExtComponent.class); - DIPro.extOf(DI); + val DI: GcGodComponent = GcGodComponentStoneComponent() + val DIPro: GcGodExtComponent = GcGodExtComponentStoneComponent() + DIPro.extOf(DI) //When - Mountain mountainStrong = DI.earth().mountainStrong(); - Mountain mountainSoft = DI.earth().mountainSoft(); + val mountainStrong: Mountain? = DI.earth()!!.mountainStrong() + val mountainSoft: Mountain? = DI.earth()!!.mountainSoft() //Then assertNotEquals( - mountainStrong.uuid, - mountainSoft.uuid - ); + mountainStrong!!.uuid, + mountainSoft!!.uuid + ) } @Test - public void factoryNotCacheTest() { + fun factoryNotCacheTest() { //Given - GcGodComponent DI = Stone.createComponent(GcGodComponent.class); - GcGodExtComponent DIPro = Stone.createComponent(GcGodExtComponent.class); - DIPro.extOf(DI); + val DI: GcGodComponent = GcGodComponentStoneComponent() + val DIPro: GcGodExtComponent = GcGodExtComponentStoneComponent() + DIPro.extOf(DI) //When - Mountain mountain1 = DI.earth().mountainFactory(); - Mountain mountain2 = DI.earth().mountainFactory(); + val mountain1: Mountain? = DI.earth()!!.mountainFactory() + val mountain2: Mountain? = DI.earth()!!.mountainFactory() //Then assertNotEquals( - mountain1.uuid, - mountain2.uuid - ); + mountain1!!.uuid, + mountain2!!.uuid + ) } @Test - public void differentDIDifferentCacheTest() { + fun differentDIDifferentCacheTest() { //Given - GcGodComponent DI1 = Stone.createComponent(GcGodComponent.class); - GcGodExtComponent DIPro1 = Stone.createComponent(GcGodExtComponent.class); - DIPro1.extOf(DI1); - GcGodComponent DI2 = Stone.createComponent(GcGodComponent.class); - GcGodExtComponent DIPro2 = Stone.createComponent(GcGodExtComponent.class); - DIPro2.extOf(DI2); + val DI1: GcGodComponent = GcGodComponentStoneComponent() + val DIPro1: GcGodExtComponent = GcGodExtComponentStoneComponent() + DIPro1.extOf(DI1) + val DI2: GcGodComponent = GcGodComponentStoneComponent() + val DIPro2: GcGodExtComponent = GcGodExtComponentStoneComponent() + DIPro2.extOf(DI2) //When - Mountain mountain1 = DI1.earth().mountainStrong(); - Mountain mountain2 = DI2.earth().mountainStrong(); + val mountain1: Mountain? = DI1.earth()!!.mountainStrong() + val mountain2: Mountain? = DI2.earth()!!.mountainStrong() //Then assertNotEquals( - mountain1.uuid, - mountain2.uuid - ); + mountain1!!.uuid, + mountain2!!.uuid + ) } - } diff --git a/tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/cache/EarthCacheFromProTests.kt b/tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/cache/EarthCacheFromProTests.kt index 17064686..026e5ec8 100644 --- a/tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/cache/EarthCacheFromProTests.kt +++ b/tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/cache/EarthCacheFromProTests.kt @@ -1,167 +1,166 @@ -package com.dirgub.klee0kai.stone.text_ext.cache; +package com.dirgub.klee0kai.stone.text_ext.cache -import com.github.klee0kai.stone.Stone; -import com.github.klee0kai.test.di.gcforest.GcGodComponent; -import com.github.klee0kai.test.mowgli.earth.Mountain; -import com.github.klee0kai.test_ext.inject.di.gcforest.GcGodExtComponent; -import org.junit.jupiter.api.Test; +import com.github.klee0kai.test.di.gcforest.GcGodComponent +import com.github.klee0kai.test.di.gcforest.GcGodComponentStoneComponent +import com.github.klee0kai.test.mowgli.earth.Mountain +import com.github.klee0kai.test_ext.inject.di.gcforest.GcGodExtComponent +import com.github.klee0kai.test_ext.inject.di.gcforest.GcGodExtComponentStoneComponent +import org.junit.jupiter.api.Assertions.assertEquals +import org.junit.jupiter.api.Assertions.assertNotEquals +import org.junit.jupiter.api.Test -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotEquals; - -public class EarthCacheFromProTests { +class EarthCacheFromProTests { @Test - public void strongCacheTest() { + fun strongCacheTest() { //Given - GcGodComponent DI = Stone.createComponent(GcGodComponent.class); - GcGodExtComponent DIPro = Stone.createComponent(GcGodExtComponent.class); - DIPro.extOf(DI); + val DI = GcGodComponentStoneComponent() + val DIPro: GcGodExtComponent = GcGodExtComponentStoneComponent() + DIPro.extOf(DI) //When - Mountain mountain1 = DIPro.earth().mountainStrong(); - Mountain mountain2 = DIPro.earth().mountainStrong(); + val mountain1: Mountain? = DIPro.earth()!!.mountainStrong() + val mountain2: Mountain? = DIPro.earth()!!.mountainStrong() //Then assertEquals( - mountain1.uuid, - mountain2.uuid - ); + mountain1!!.uuid, + mountain2!!.uuid + ) } @Test - public void softCacheTest() { + fun softCacheTest() { //Given - GcGodComponent DI = Stone.createComponent(GcGodComponent.class); - GcGodExtComponent DIPro = Stone.createComponent(GcGodExtComponent.class); - DIPro.extOf(DI); + val DI: GcGodComponent = GcGodComponentStoneComponent() + val DIPro: GcGodExtComponent = GcGodExtComponentStoneComponent() + DIPro.extOf(DI) //When - Mountain mountain1 = DIPro.earth().mountainSoft(); - Mountain mountain2 = DIPro.earth().mountainSoft(); + val mountain1: Mountain? = DIPro.earth()!!.mountainSoft() + val mountain2: Mountain? = DIPro.earth()!!.mountainSoft() //Then assertEquals( - mountain1.uuid, - mountain2.uuid - ); + mountain1!!.uuid, + mountain2!!.uuid + ) } @Test - public void weakCacheTest() { + fun weakCacheTest() { //Given - GcGodComponent DI = Stone.createComponent(GcGodComponent.class); - GcGodExtComponent DIPro = Stone.createComponent(GcGodExtComponent.class); - DIPro.extOf(DI); + val DI: GcGodComponent = GcGodComponentStoneComponent() + val DIPro: GcGodExtComponent = GcGodExtComponentStoneComponent() + DIPro.extOf(DI) //When - Mountain mountain1 = DIPro.earth().mountainWeak(); - Mountain mountain2 = DIPro.earth().mountainWeak(); + val mountain1: Mountain? = DIPro.earth()!!.mountainWeak() + val mountain2: Mountain? = DIPro.earth()!!.mountainWeak() //Then assertEquals( - mountain1.uuid, - mountain2.uuid - ); + mountain1!!.uuid, + mountain2!!.uuid + ) } @Test - public void defCacheTest() { + fun defCacheTest() { //Given - GcGodComponent DI = Stone.createComponent(GcGodComponent.class); - GcGodExtComponent DIPro = Stone.createComponent(GcGodExtComponent.class); - DIPro.extOf(DI); + val DI: GcGodComponent = GcGodComponentStoneComponent() + val DIPro: GcGodExtComponent = GcGodExtComponentStoneComponent() + DIPro.extOf(DI) //When - Mountain mountain1 = DIPro.earth().mountainDefaultFactory(); - Mountain mountain2 = DIPro.earth().mountainDefaultFactory(); + val mountain1: Mountain? = DIPro.earth()!!.mountainDefaultFactory() + val mountain2: Mountain? = DIPro.earth()!!.mountainDefaultFactory() //Then assertNotEquals( - mountain1.uuid, - mountain2.uuid, - "Factory Providing" - ); + mountain1!!.uuid, + mountain2!!.uuid, + "Factory Providing" + ) } @Test - public void defCache2Test() { + fun defCache2Test() { //Given - GcGodComponent DI = Stone.createComponent(GcGodComponent.class); - GcGodExtComponent DIPro = Stone.createComponent(GcGodExtComponent.class); - DIPro.extOf(DI); + val DI: GcGodComponent = GcGodComponentStoneComponent() + val DIPro: GcGodExtComponent = GcGodExtComponentStoneComponent() + DIPro.extOf(DI) //When - Mountain mountain1 = DIPro.earth().mountainDefault2Factory(); - Mountain mountain2 = DIPro.earth().mountainDefault2Factory(); + val mountain1: Mountain? = DIPro.earth()!!.mountainDefault2Factory() + val mountain2: Mountain? = DIPro.earth()!!.mountainDefault2Factory() //Then assertNotEquals( - mountain1.uuid, - mountain2.uuid, - "Factory Providing" - ); + mountain1!!.uuid, + mountain2!!.uuid, + "Factory Providing" + ) } @Test - public void differentMethodDifferentCacheTest() { + fun differentMethodDifferentCacheTest() { //Given - GcGodComponent DI = Stone.createComponent(GcGodComponent.class); - GcGodExtComponent DIPro = Stone.createComponent(GcGodExtComponent.class); - DIPro.extOf(DI); + val DI: GcGodComponent = GcGodComponentStoneComponent() + val DIPro: GcGodExtComponent = GcGodExtComponentStoneComponent() + DIPro.extOf(DI) //When - Mountain mountainStrong = DIPro.earth().mountainStrong(); - Mountain mountainSoft = DIPro.earth().mountainSoft(); + val mountainStrong: Mountain? = DIPro.earth()!!.mountainStrong() + val mountainSoft: Mountain? = DIPro.earth()!!.mountainSoft() //Then assertNotEquals( - mountainStrong.uuid, - mountainSoft.uuid - ); + mountainStrong!!.uuid, + mountainSoft!!.uuid + ) } @Test - public void factoryNotCacheTest() { + fun factoryNotCacheTest() { //Given - GcGodComponent DI = Stone.createComponent(GcGodComponent.class); - GcGodExtComponent DIPro = Stone.createComponent(GcGodExtComponent.class); - DIPro.extOf(DI); + val DI: GcGodComponent = GcGodComponentStoneComponent() + val DIPro: GcGodExtComponent = GcGodExtComponentStoneComponent() + DIPro.extOf(DI) //When - Mountain mountain1 = DIPro.earth().mountainFactory(); - Mountain mountain2 = DIPro.earth().mountainFactory(); + val mountain1: Mountain? = DIPro.earth()!!.mountainFactory() + val mountain2: Mountain? = DIPro.earth()!!.mountainFactory() //Then assertNotEquals( - mountain1.uuid, - mountain2.uuid - ); + mountain1!!.uuid, + mountain2!!.uuid + ) } @Test - public void differentDIDifferentCacheTest() { + fun differentDIDifferentCacheTest() { //Given - GcGodComponent DI1 = Stone.createComponent(GcGodComponent.class); - GcGodExtComponent DIPro1 = Stone.createComponent(GcGodExtComponent.class); - DIPro1.extOf(DI1); - GcGodComponent DI2 = Stone.createComponent(GcGodComponent.class); - GcGodExtComponent DIPro2 = Stone.createComponent(GcGodExtComponent.class); - DIPro2.extOf(DI2); + val DI1: GcGodComponent = GcGodComponentStoneComponent() + val DIPro1: GcGodExtComponent = GcGodExtComponentStoneComponent() + DIPro1.extOf(DI1) + val DI2: GcGodComponent = GcGodComponentStoneComponent() + val DIPro2: GcGodExtComponent = GcGodExtComponentStoneComponent() + DIPro2.extOf(DI2) //When - Mountain mountain1 = DIPro1.earth().mountainStrong(); - Mountain mountain2 = DIPro2.earth().mountainStrong(); + val mountain1: Mountain? = DIPro1.earth()!!.mountainStrong() + val mountain2: Mountain? = DIPro2.earth()!!.mountainStrong() //Then assertNotEquals( - mountain1.uuid, - mountain2.uuid - ); + mountain1!!.uuid, + mountain2!!.uuid + ) } - } diff --git a/tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/cache/EarthCacheMixedTests.kt b/tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/cache/EarthCacheMixedTests.kt index c11ee395..36546888 100644 --- a/tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/cache/EarthCacheMixedTests.kt +++ b/tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/cache/EarthCacheMixedTests.kt @@ -1,167 +1,165 @@ -package com.dirgub.klee0kai.stone.text_ext.cache; +package com.dirgub.klee0kai.stone.text_ext.cache -import com.github.klee0kai.stone.Stone; -import com.github.klee0kai.test.di.gcforest.GcGodComponent; -import com.github.klee0kai.test.mowgli.earth.Mountain; -import com.github.klee0kai.test_ext.inject.di.gcforest.GcGodExtComponent; -import org.junit.jupiter.api.Test; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotEquals; - -public class EarthCacheMixedTests { +import com.github.klee0kai.test.di.gcforest.GcGodComponent +import com.github.klee0kai.test.di.gcforest.GcGodComponentStoneComponent +import com.github.klee0kai.test.mowgli.earth.Mountain +import com.github.klee0kai.test_ext.inject.di.gcforest.GcGodExtComponent +import com.github.klee0kai.test_ext.inject.di.gcforest.GcGodExtComponentStoneComponent +import org.junit.jupiter.api.Assertions.assertEquals +import org.junit.jupiter.api.Assertions.assertNotEquals +import org.junit.jupiter.api.Test +class EarthCacheMixedTests { @Test - public void strongCacheTest() { + fun strongCacheTest() { //Given - GcGodComponent DI = Stone.createComponent(GcGodComponent.class); - GcGodExtComponent DIPro = Stone.createComponent(GcGodExtComponent.class); - DIPro.extOf(DI); + val DI: GcGodComponent = GcGodComponentStoneComponent() + val DIPro: GcGodExtComponent = GcGodExtComponentStoneComponent() + DIPro.extOf(DI) //When - Mountain mountain1 = DI.earth().mountainStrong(); - Mountain mountain2 = DIPro.earth().mountainStrong(); + val mountain1: Mountain? = DI.earth()!!.mountainStrong() + val mountain2: Mountain? = DIPro.earth()!!.mountainStrong() //Then assertEquals( - mountain1.uuid, - mountain2.uuid - ); + mountain1!!.uuid, + mountain2!!.uuid + ) } @Test - public void softCacheTest() { + fun softCacheTest() { //Given - GcGodComponent DI = Stone.createComponent(GcGodComponent.class); - GcGodExtComponent DIPro = Stone.createComponent(GcGodExtComponent.class); - DIPro.extOf(DI); + val DI: GcGodComponent = GcGodComponentStoneComponent() + val DIPro: GcGodExtComponent = GcGodExtComponentStoneComponent() + DIPro.extOf(DI) //When - Mountain mountain1 = DI.earth().mountainSoft(); - Mountain mountain2 = DIPro.earth().mountainSoft(); + val mountain1: Mountain? = DI.earth()!!.mountainSoft() + val mountain2: Mountain? = DIPro.earth()!!.mountainSoft() //Then assertEquals( - mountain1.uuid, - mountain2.uuid - ); + mountain1!!.uuid, + mountain2!!.uuid + ) } @Test - public void weakCacheTest() { + fun weakCacheTest() { //Given - GcGodComponent DI = Stone.createComponent(GcGodComponent.class); - GcGodExtComponent DIPro = Stone.createComponent(GcGodExtComponent.class); - DIPro.extOf(DI); + val DI: GcGodComponent = GcGodComponentStoneComponent() + val DIPro: GcGodExtComponent = GcGodExtComponentStoneComponent() + DIPro.extOf(DI) //When - Mountain mountain1 = DI.earth().mountainWeak(); - Mountain mountain2 = DIPro.earth().mountainWeak(); + val mountain1: Mountain? = DI.earth()!!.mountainWeak() + val mountain2: Mountain? = DIPro.earth()!!.mountainWeak() //Then assertEquals( - mountain1.uuid, - mountain2.uuid - ); + mountain1!!.uuid, + mountain2!!.uuid + ) } @Test - public void defCacheTest() { + fun defCacheTest() { //Given - GcGodComponent DI = Stone.createComponent(GcGodComponent.class); - GcGodExtComponent DIPro = Stone.createComponent(GcGodExtComponent.class); - DIPro.extOf(DI); + val DI: GcGodComponent = GcGodComponentStoneComponent() + val DIPro: GcGodExtComponent = GcGodExtComponentStoneComponent() + DIPro.extOf(DI) //When - Mountain mountain1 = DI.earth().mountainDefaultFactory(); - Mountain mountain2 = DIPro.earth().mountainDefaultFactory(); + val mountain1: Mountain? = DI.earth()!!.mountainDefaultFactory() + val mountain2: Mountain? = DIPro.earth()!!.mountainDefaultFactory() //Then assertNotEquals( - mountain1.uuid, - mountain2.uuid, - "Factory providing" - ); + mountain1!!.uuid, + mountain2!!.uuid, + "Factory providing" + ) } @Test - public void defCache2Test() { + fun defCache2Test() { //Given - GcGodComponent DI = Stone.createComponent(GcGodComponent.class); - GcGodExtComponent DIPro = Stone.createComponent(GcGodExtComponent.class); - DIPro.extOf(DI); + val DI: GcGodComponent = GcGodComponentStoneComponent() + val DIPro: GcGodExtComponent = GcGodExtComponentStoneComponent() + DIPro.extOf(DI) //When - Mountain mountain1 = DI.earth().mountainDefault2Factory(); - Mountain mountain2 = DIPro.earth().mountainDefault2Factory(); + val mountain1: Mountain? = DI.earth()!!.mountainDefault2Factory() + val mountain2: Mountain? = DIPro.earth()!!.mountainDefault2Factory() //Then assertNotEquals( - mountain1.uuid, - mountain2.uuid, - "Factory providing" - ); + mountain1!!.uuid, + mountain2!!.uuid, + "Factory providing" + ) } @Test - public void differentMethodDifferentCacheTest() { + fun differentMethodDifferentCacheTest() { //Given - GcGodComponent DI = Stone.createComponent(GcGodComponent.class); - GcGodExtComponent DIPro = Stone.createComponent(GcGodExtComponent.class); - DIPro.extOf(DI); + val DI: GcGodComponent = GcGodComponentStoneComponent() + val DIPro: GcGodExtComponent = GcGodExtComponentStoneComponent() + DIPro.extOf(DI) //When - Mountain mountainStrong = DI.earth().mountainStrong(); - Mountain mountainSoft = DIPro.earth().mountainSoft(); + val mountainStrong: Mountain? = DI.earth()!!.mountainStrong() + val mountainSoft: Mountain? = DIPro.earth()!!.mountainSoft() //Then assertNotEquals( - mountainStrong.uuid, - mountainSoft.uuid - ); + mountainStrong!!.uuid, + mountainSoft!!.uuid + ) } @Test - public void factoryNotCacheTest() { + fun factoryNotCacheTest() { //Given - GcGodComponent DI = Stone.createComponent(GcGodComponent.class); - GcGodExtComponent DIPro = Stone.createComponent(GcGodExtComponent.class); - DIPro.extOf(DI); + val DI: GcGodComponent = GcGodComponentStoneComponent() + val DIPro: GcGodExtComponent = GcGodExtComponentStoneComponent() + DIPro.extOf(DI) //When - Mountain mountain1 = DI.earth().mountainFactory(); - Mountain mountain2 = DIPro.earth().mountainFactory(); + val mountain1: Mountain? = DI.earth()!!.mountainFactory() + val mountain2: Mountain? = DIPro.earth()!!.mountainFactory() //Then assertNotEquals( - mountain1.uuid, - mountain2.uuid - ); + mountain1!!.uuid, + mountain2!!.uuid + ) } @Test - public void differentDIDifferentCacheTest() { + fun differentDIDifferentCacheTest() { //Given - GcGodComponent DI1 = Stone.createComponent(GcGodComponent.class); - GcGodExtComponent DIPro1 = Stone.createComponent(GcGodExtComponent.class); - DIPro1.extOf(DI1); - GcGodComponent DI2 = Stone.createComponent(GcGodComponent.class); - GcGodExtComponent DIPro2 = Stone.createComponent(GcGodExtComponent.class); - DIPro2.extOf(DI2); + val DI1: GcGodComponent = GcGodComponentStoneComponent() + val DIPro1: GcGodExtComponent = GcGodExtComponentStoneComponent() + DIPro1.extOf(DI1) + val DI2: GcGodComponent = GcGodComponentStoneComponent() + val DIPro2: GcGodExtComponent = GcGodExtComponentStoneComponent() + DIPro2.extOf(DI2) //When - Mountain mountain1 = DI1.earth().mountainStrong(); - Mountain mountain2 = DIPro2.earth().mountainStrong(); + val mountain1: Mountain? = DI1.earth()!!.mountainStrong() + val mountain2: Mountain? = DIPro2.earth()!!.mountainStrong() //Then assertNotEquals( - mountain1.uuid, - mountain2.uuid - ); + mountain1!!.uuid, + mountain2!!.uuid + ) } - } diff --git a/tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/cache/EarthCacheProMixedTests.kt b/tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/cache/EarthCacheProMixedTests.kt index d47c737b..e034b073 100644 --- a/tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/cache/EarthCacheProMixedTests.kt +++ b/tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/cache/EarthCacheProMixedTests.kt @@ -1,168 +1,168 @@ -package com.dirgub.klee0kai.stone.text_ext.cache; +package com.dirgub.klee0kai.stone.text_ext.cache -import com.github.klee0kai.stone.Stone; -import com.github.klee0kai.test.di.gcforest.GcGodComponent; -import com.github.klee0kai.test.mowgli.earth.Mountain; -import com.github.klee0kai.test_ext.inject.di.gcforest.GcGodExtComponent; -import org.junit.jupiter.api.Test; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotEquals; - -public class EarthCacheProMixedTests { +import com.github.klee0kai.stone.Stone +import com.github.klee0kai.test.di.gcforest.GcGodComponent +import com.github.klee0kai.test.di.gcforest.GcGodComponentStoneComponent +import com.github.klee0kai.test.mowgli.earth.Mountain +import com.github.klee0kai.test_ext.inject.di.gcforest.GcGodExtComponent +import com.github.klee0kai.test_ext.inject.di.gcforest.GcGodExtComponentStoneComponent +import org.junit.jupiter.api.Assertions.assertEquals +import org.junit.jupiter.api.Assertions.assertNotEquals +import org.junit.jupiter.api.Test +class EarthCacheProMixedTests { @Test - public void strongCacheTest() { + fun strongCacheTest() { //Given - GcGodComponent DI = Stone.createComponent(GcGodComponent.class); - GcGodExtComponent DIPro = Stone.createComponent(GcGodExtComponent.class); - DIPro.extOf(DI); + val DI: GcGodComponent = GcGodComponentStoneComponent() + val DIPro: GcGodExtComponent = GcGodExtComponentStoneComponent() + DIPro.extOf(DI) //When - Mountain mountain1 = DIPro.earth().mountainStrong(); - Mountain mountain2 = DI.earth().mountainStrong(); + val mountain1: Mountain? = DIPro.earth()!!.mountainStrong() + val mountain2: Mountain? = DI.earth()!!.mountainStrong() //Then assertEquals( - mountain1.uuid, - mountain2.uuid - ); + mountain1!!.uuid, + mountain2!!.uuid + ) } @Test - public void softCacheTest() { + fun softCacheTest() { //Given - GcGodComponent DI = Stone.createComponent(GcGodComponent.class); - GcGodExtComponent DIPro = Stone.createComponent(GcGodExtComponent.class); - DIPro.extOf(DI); + val DI: GcGodComponent = GcGodComponentStoneComponent() + val DIPro: GcGodExtComponent = GcGodExtComponentStoneComponent() + DIPro.extOf(DI) //When - Mountain mountain1 = DIPro.earth().mountainSoft(); - Mountain mountain2 = DI.earth().mountainSoft(); + val mountain1: Mountain? = DIPro.earth()!!.mountainSoft() + val mountain2: Mountain? = DI.earth()!!.mountainSoft() //Then assertEquals( - mountain1.uuid, - mountain2.uuid - ); + mountain1!!.uuid, + mountain2!!.uuid + ) } @Test - public void weakCacheTest() { + fun weakCacheTest() { //Given - GcGodComponent DI = Stone.createComponent(GcGodComponent.class); - GcGodExtComponent DIPro = Stone.createComponent(GcGodExtComponent.class); - DIPro.extOf(DI); + val DI: GcGodComponent = GcGodComponentStoneComponent() + val DIPro: GcGodExtComponent = GcGodExtComponentStoneComponent() + DIPro.extOf(DI) //When - Mountain mountain1 = DIPro.earth().mountainWeak(); - Mountain mountain2 = DI.earth().mountainWeak(); + val mountain1: Mountain? = DIPro.earth()!!.mountainWeak() + val mountain2: Mountain? = DI.earth()!!.mountainWeak() //Then assertEquals( - mountain1.uuid, - mountain2.uuid - ); + mountain1!!.uuid, + mountain2!!.uuid + ) } @Test - public void defCacheTest() { + fun defCacheTest() { //Given - GcGodComponent DI = Stone.createComponent(GcGodComponent.class); - GcGodExtComponent DIPro = Stone.createComponent(GcGodExtComponent.class); - DIPro.extOf(DI); + val DI: GcGodComponent = GcGodComponentStoneComponent() + val DIPro: GcGodExtComponent = GcGodExtComponentStoneComponent() + DIPro.extOf(DI) //When - Mountain mountain1 = DIPro.earth().mountainDefaultFactory(); - Mountain mountain2 = DI.earth().mountainDefaultFactory(); + val mountain1: Mountain? = DIPro.earth()!!.mountainDefaultFactory() + val mountain2: Mountain? = DI.earth()!!.mountainDefaultFactory() //Then assertNotEquals( - mountain1.uuid, - mountain2.uuid, - "Factory providing" - ); + mountain1!!.uuid, + mountain2!!.uuid, + "Factory providing" + ) } @Test - public void defCache2Test() { + fun defCache2Test() { //Given - GcGodComponent DI = Stone.createComponent(GcGodComponent.class); - GcGodExtComponent DIPro = Stone.createComponent(GcGodExtComponent.class); - DIPro.extOf(DI); + val DI: GcGodComponent = GcGodComponentStoneComponent() + val DIPro: GcGodExtComponent = GcGodExtComponentStoneComponent() + DIPro.extOf(DI) //When - Mountain mountain1 = DIPro.earth().mountainDefault2Factory(); - Mountain mountain2 = DI.earth().mountainDefault2Factory(); + val mountain1: Mountain? = DIPro.earth()!!.mountainDefault2Factory() + val mountain2: Mountain? = DI.earth()!!.mountainDefault2Factory() //Then assertNotEquals( - mountain1.uuid, - mountain2.uuid, - "Factory providing" - ); + mountain1!!.uuid, + mountain2!!.uuid, + "Factory providing" + ) } @Test - public void differentMethodDifferentCacheTest() { + fun differentMethodDifferentCacheTest() { //Given - GcGodComponent DI = Stone.createComponent(GcGodComponent.class); - GcGodExtComponent DIPro = Stone.createComponent(GcGodExtComponent.class); - DIPro.extOf(DI); + val DI: GcGodComponent = GcGodComponentStoneComponent() + val DIPro: GcGodExtComponent = GcGodExtComponentStoneComponent() + DIPro.extOf(DI) //When - Mountain mountainStrong = DIPro.earth().mountainStrong(); - Mountain mountainSoft = DI.earth().mountainSoft(); + val mountainStrong: Mountain? = DIPro.earth()!!.mountainStrong() + val mountainSoft: Mountain? = DI.earth()!!.mountainSoft() //Then assertNotEquals( - mountainStrong.uuid, - mountainSoft.uuid - ); + mountainStrong!!.uuid, + mountainSoft!!.uuid + ) } @Test - public void factoryNotCacheTest() { + fun factoryNotCacheTest() { //Given - GcGodComponent DI = Stone.createComponent(GcGodComponent.class); - GcGodExtComponent DIPro = Stone.createComponent(GcGodExtComponent.class); - DIPro.extOf(DI); + val DI: GcGodComponent = GcGodComponentStoneComponent() + val DIPro: GcGodExtComponent = GcGodExtComponentStoneComponent() + DIPro.extOf(DI) //When - Mountain mountain1 = DIPro.earth().mountainFactory(); - Mountain mountain2 = DI.earth().mountainFactory(); + val mountain1: Mountain? = DIPro.earth()!!.mountainFactory() + val mountain2: Mountain? = DI.earth()!!.mountainFactory() //Then assertNotEquals( - mountain1.uuid, - mountain2.uuid - ); + mountain1!!.uuid, + mountain2!!.uuid + ) } @Test - public void differentDIDifferentCacheTest() { + fun differentDIDifferentCacheTest() { //Given - GcGodComponent DI1 = Stone.createComponent(GcGodComponent.class); - GcGodExtComponent DIPro1 = Stone.createComponent(GcGodExtComponent.class); - DIPro1.extOf(DI1); - GcGodComponent DI2 = Stone.createComponent(GcGodComponent.class); - GcGodExtComponent DIPro2 = Stone.createComponent(GcGodExtComponent.class); - DIPro2.extOf(DI2); + val DI1: GcGodComponent = GcGodComponentStoneComponent() + val DIPro1: GcGodExtComponent = GcGodExtComponentStoneComponent() + DIPro1.extOf(DI1) + val DI2: GcGodComponent = GcGodComponentStoneComponent() + val DIPro2: GcGodExtComponent = GcGodExtComponentStoneComponent() + DIPro2.extOf(DI2) //When - Mountain mountain1 = DIPro1.earth().mountainStrong(); - Mountain mountain2 = DI2.earth().mountainStrong(); + val mountain1: Mountain? = DIPro1.earth()!!.mountainStrong() + val mountain2: Mountain? = DI2.earth()!!.mountainStrong() //Then assertNotEquals( - mountain1.uuid, - mountain2.uuid - ); + mountain1!!.uuid, + mountain2!!.uuid + ) } } diff --git a/tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/cache/EarthSwitchCacheAndProTests.kt b/tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/cache/EarthSwitchCacheAndProTests.kt index e8a33dd1..84bc0210 100644 --- a/tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/cache/EarthSwitchCacheAndProTests.kt +++ b/tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/cache/EarthSwitchCacheAndProTests.kt @@ -1,96 +1,93 @@ -package com.dirgub.klee0kai.stone.text_ext.cache; +package com.dirgub.klee0kai.stone.text_ext.cache -import com.github.klee0kai.stone.Stone; -import com.github.klee0kai.test.di.swcache.SwitchCacheComponent; -import com.github.klee0kai.test.mowgli.earth.Mountain; -import com.github.klee0kai.test.mowgli.earth.River; -import com.github.klee0kai.test_ext.inject.di.swcache.SwitchCacheExtComponent; -import org.junit.jupiter.api.Test; - -import java.lang.ref.WeakReference; - -import static java.lang.Thread.sleep; -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertNull; - -public class EarthSwitchCacheAndProTests { +import com.github.klee0kai.test.di.swcache.SwitchCacheComponent +import com.github.klee0kai.test.di.swcache.SwitchCacheComponentStoneComponent +import com.github.klee0kai.test.mowgli.earth.Mountain +import com.github.klee0kai.test.mowgli.earth.River +import com.github.klee0kai.test_ext.inject.di.swcache.SwitchCacheExtComponent +import com.github.klee0kai.test_ext.inject.di.swcache.SwitchCacheExtComponentStoneComponent +import org.junit.jupiter.api.Test +import org.junit.jupiter.api.assertNotNull +import org.junit.jupiter.api.assertNull +import java.lang.ref.WeakReference +class EarthSwitchCacheAndProTests { @Test - public void allToWeakTest() { + fun allToWeakTest() { //Given - SwitchCacheComponent DI = Stone.createComponent(SwitchCacheComponent.class); - SwitchCacheExtComponent DIPro = Stone.createComponent(SwitchCacheExtComponent.class); - DIPro.extOf(DI); - WeakReference mountain = new WeakReference<>(DIPro.earth().mountainStrong()); + val DI: SwitchCacheComponent = SwitchCacheComponentStoneComponent() + val DIPro: SwitchCacheExtComponent = SwitchCacheExtComponentStoneComponent() + DIPro.extOf(DI) + val mountain = WeakReference(DIPro.earth()!!.mountainStrong()) //When - DI.allWeak(); - System.gc(); + DI.allWeak() + System.gc() //Then - assertNull(mountain.get()); + assertNull(mountain.get()) } @Test - public void strongToWeakTest() { + fun strongToWeakTest() { //Given - SwitchCacheComponent DI = Stone.createComponent(SwitchCacheComponent.class); - SwitchCacheExtComponent DIPro = Stone.createComponent(SwitchCacheExtComponent.class); - DIPro.extOf(DI); - WeakReference mountainStrong = new WeakReference<>(DIPro.earth().mountainStrong()); - WeakReference mountainSoft = new WeakReference<>(DIPro.earth().mountainSoft()); + val DI: SwitchCacheComponent = SwitchCacheComponentStoneComponent() + val DIPro: SwitchCacheExtComponent = SwitchCacheExtComponentStoneComponent() + DIPro.extOf(DI) + val mountainStrong = WeakReference(DIPro.earth()!!.mountainStrong()) + val mountainSoft = WeakReference(DIPro.earth()!!.mountainSoft()) //When - DI.strongToWeak(); - System.gc(); + DI.strongToWeak() + System.gc() //Then - assertNull(mountainStrong.get()); - assertNotNull(mountainSoft.get()); + assertNull(mountainStrong.get()) + assertNotNull(mountainSoft.get()) } @Test - public void weakToStrongFewMillisTest() throws InterruptedException { + @Throws(InterruptedException::class) + fun weakToStrongFewMillisTest() { //Given - SwitchCacheComponent DI = Stone.createComponent(SwitchCacheComponent.class); - SwitchCacheExtComponent DIPro = Stone.createComponent(SwitchCacheExtComponent.class); - DIPro.extOf(DI); - WeakReference mountainWeak = new WeakReference<>(DIPro.earth().mountainWeak()); + val DI: SwitchCacheComponent = SwitchCacheComponentStoneComponent() + val DIPro: SwitchCacheExtComponent = SwitchCacheExtComponentStoneComponent() + DIPro.extOf(DI) + val mountainWeak = WeakReference(DIPro.earth()!!.mountainWeak()) //When - DI.allStrongFewMillis(); - System.gc(); + DI.allStrongFewMillis() + System.gc() //Then: can't GC - assertNotNull(mountainWeak.get()); + assertNotNull(mountainWeak.get()) //When: after few millis - sleep(110); - System.gc(); + Thread.sleep(110) + System.gc() //Then: can GC - assertNull(mountainWeak.get()); + assertNull(mountainWeak.get()) } @Test - public void mountainToWeakTest() { + fun mountainToWeakTest() { //Given - SwitchCacheComponent DI = Stone.createComponent(SwitchCacheComponent.class); - SwitchCacheExtComponent DIPro = Stone.createComponent(SwitchCacheExtComponent.class); - DIPro.extOf(DI); - WeakReference mountain = new WeakReference<>(DIPro.earth().mountainStrong()); - WeakReference river = new WeakReference<>(DIPro.earth().riverSoft()); + val DI: SwitchCacheComponent = SwitchCacheComponentStoneComponent() + val DIPro: SwitchCacheExtComponent = SwitchCacheExtComponentStoneComponent() + DIPro.extOf(DI) + val mountain = WeakReference(DIPro.earth()!!.mountainStrong()) + val river = WeakReference(DIPro.earth()!!.riverSoft()) //When - DI.mountainToWeak(); - System.gc(); + DI.mountainToWeak() + System.gc() //Then - assertNull(mountain.get()); - assertNotNull(river.get()); + assertNull(mountain.get()) + assertNotNull(river.get()) } - } diff --git a/tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/cache/EarthSwitchCacheFromProTests.kt b/tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/cache/EarthSwitchCacheFromProTests.kt index 4a432c6f..f9ab4eee 100644 --- a/tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/cache/EarthSwitchCacheFromProTests.kt +++ b/tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/cache/EarthSwitchCacheFromProTests.kt @@ -1,96 +1,92 @@ -package com.dirgub.klee0kai.stone.text_ext.cache; +package com.dirgub.klee0kai.stone.text_ext.cache -import com.github.klee0kai.stone.Stone; -import com.github.klee0kai.test.di.swcache.SwitchCacheComponent; -import com.github.klee0kai.test.mowgli.earth.Mountain; -import com.github.klee0kai.test.mowgli.earth.River; -import com.github.klee0kai.test_ext.inject.di.swcache.SwitchCacheExtComponent; -import org.junit.jupiter.api.Test; - -import java.lang.ref.WeakReference; - -import static java.lang.Thread.sleep; -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertNull; - -public class EarthSwitchCacheFromProTests { +import com.github.klee0kai.test.di.swcache.SwitchCacheComponent +import com.github.klee0kai.test.di.swcache.SwitchCacheComponentStoneComponent +import com.github.klee0kai.test.mowgli.earth.Mountain +import com.github.klee0kai.test.mowgli.earth.River +import com.github.klee0kai.test_ext.inject.di.swcache.SwitchCacheExtComponent +import com.github.klee0kai.test_ext.inject.di.swcache.SwitchCacheExtComponentStoneComponent +import org.junit.jupiter.api.Test +import org.junit.jupiter.api.assertNotNull +import org.junit.jupiter.api.assertNull +import java.lang.ref.WeakReference +class EarthSwitchCacheFromProTests { @Test - public void allToWeakTest() { + fun allToWeakTest() { //Given - SwitchCacheComponent DI = Stone.createComponent(SwitchCacheComponent.class); - SwitchCacheExtComponent DIPro = Stone.createComponent(SwitchCacheExtComponent.class); - DIPro.extOf(DI); - WeakReference mountain = new WeakReference<>(DIPro.earth().mountainStrong()); + val DI: SwitchCacheComponent? = SwitchCacheComponentStoneComponent() + val DIPro: SwitchCacheExtComponent = SwitchCacheExtComponentStoneComponent() + DIPro.extOf(DI) + val mountain = WeakReference(DIPro.earth()!!.mountainStrong()) //When - DIPro.allWeak(); - System.gc(); + DIPro.allWeak() + System.gc() //Then - assertNull(mountain.get()); + assertNull(mountain.get()) } @Test - public void strongToWeakTest() { + fun strongToWeakTest() { //Given - SwitchCacheComponent DI = Stone.createComponent(SwitchCacheComponent.class); - SwitchCacheExtComponent DIPro = Stone.createComponent(SwitchCacheExtComponent.class); - DIPro.extOf(DI); - WeakReference mountainStrong = new WeakReference<>(DIPro.earth().mountainStrong()); - WeakReference mountainSoft = new WeakReference<>(DIPro.earth().mountainSoft()); + val DI: SwitchCacheComponent = SwitchCacheComponentStoneComponent() + val DIPro: SwitchCacheExtComponent = SwitchCacheExtComponentStoneComponent() + DIPro.extOf(DI) + val mountainStrong = WeakReference(DIPro.earth()!!.mountainStrong()) + val mountainSoft = WeakReference(DIPro.earth()!!.mountainSoft()) //When - DIPro.strongToWeak(); - System.gc(); + DIPro.strongToWeak() + System.gc() //Then - assertNull(mountainStrong.get()); - assertNotNull(mountainSoft.get()); + assertNull(mountainStrong.get()) + assertNotNull(mountainSoft.get()) } @Test - public void weakToStrongFewMillisTest() throws InterruptedException { + @Throws(InterruptedException::class) + fun weakToStrongFewMillisTest() { //Given - SwitchCacheComponent DI = Stone.createComponent(SwitchCacheComponent.class); - SwitchCacheExtComponent DIPro = Stone.createComponent(SwitchCacheExtComponent.class); - DIPro.extOf(DI); - WeakReference mountainWeak = new WeakReference<>(DIPro.earth().mountainWeak()); + val DI: SwitchCacheComponent = SwitchCacheComponentStoneComponent() + val DIPro: SwitchCacheExtComponent = SwitchCacheExtComponentStoneComponent() + DIPro.extOf(DI) + val mountainWeak = WeakReference(DIPro.earth()!!.mountainWeak()) //When - DIPro.allStrongFewMillis(); - System.gc(); + DIPro.allStrongFewMillis() + System.gc() //Then: can't GC - assertNotNull(mountainWeak.get()); + assertNotNull(mountainWeak.get()) //When: after few millis - sleep(110); - System.gc(); + Thread.sleep(110) + System.gc() //Then: can GC - assertNull(mountainWeak.get()); + assertNull(mountainWeak.get()) } - @Test - public void mountainToWeakTest() { + @org.junit.jupiter.api.Test + fun mountainToWeakTest() { //Given - SwitchCacheComponent DI = Stone.createComponent(SwitchCacheComponent.class); - SwitchCacheExtComponent DIPro = Stone.createComponent(SwitchCacheExtComponent.class); - DIPro.extOf(DI); - WeakReference mountain = new WeakReference<>(DIPro.earth().mountainStrong()); - WeakReference river = new WeakReference<>(DIPro.earth().riverSoft()); + val DI: SwitchCacheComponent = SwitchCacheComponentStoneComponent() + val DIPro: SwitchCacheExtComponent = SwitchCacheExtComponentStoneComponent() + DIPro.extOf(DI) + val mountain = WeakReference(DIPro.earth()!!.mountainStrong()) + val river: WeakReference = WeakReference(DIPro.earth()!!.riverSoft()) //When - DIPro.mountainToWeak(); - System.gc(); + DIPro.mountainToWeak() + System.gc() //Then - assertNull(mountain.get()); - assertNotNull(river.get()); + assertNull(mountain.get()) + assertNotNull(river.get()) } - - } diff --git a/tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/cache/EarthSwitchCacheFromProtoTests.kt b/tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/cache/EarthSwitchCacheFromProtoTests.kt index 6edb163b..19e11877 100644 --- a/tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/cache/EarthSwitchCacheFromProtoTests.kt +++ b/tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/cache/EarthSwitchCacheFromProtoTests.kt @@ -1,96 +1,93 @@ -package com.dirgub.klee0kai.stone.text_ext.cache; +package com.dirgub.klee0kai.stone.text_ext.cache -import com.github.klee0kai.stone.Stone; -import com.github.klee0kai.test.di.swcache.SwitchCacheComponent; -import com.github.klee0kai.test.mowgli.earth.Mountain; -import com.github.klee0kai.test.mowgli.earth.River; -import com.github.klee0kai.test_ext.inject.di.swcache.SwitchCacheExtComponent; -import org.junit.jupiter.api.Test; - -import java.lang.ref.WeakReference; - -import static java.lang.Thread.sleep; -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertNull; - -public class EarthSwitchCacheFromProtoTests { +import com.github.klee0kai.test.di.swcache.SwitchCacheComponent +import com.github.klee0kai.test.di.swcache.SwitchCacheComponentStoneComponent +import com.github.klee0kai.test.mowgli.earth.Mountain +import com.github.klee0kai.test.mowgli.earth.River +import com.github.klee0kai.test_ext.inject.di.swcache.SwitchCacheExtComponent +import com.github.klee0kai.test_ext.inject.di.swcache.SwitchCacheExtComponentStoneComponent +import org.junit.jupiter.api.Test +import org.junit.jupiter.api.assertNotNull +import org.junit.jupiter.api.assertNull +import java.lang.ref.WeakReference +class EarthSwitchCacheFromProtoTests { @Test - public void allToWeakTest() { + fun allToWeakTest() { //Given - SwitchCacheComponent DI = Stone.createComponent(SwitchCacheComponent.class); - SwitchCacheExtComponent DIPro = Stone.createComponent(SwitchCacheExtComponent.class); - DIPro.extOf(DI); - WeakReference mountain = new WeakReference<>(DI.earth().mountainStrong()); + val DI: SwitchCacheComponent = SwitchCacheComponentStoneComponent() + val DIPro: SwitchCacheExtComponent = SwitchCacheExtComponentStoneComponent() + DIPro.extOf(DI) + val mountain = WeakReference(DI.earth()!!.mountainStrong()) //When - DIPro.allWeak(); - System.gc(); + DIPro.allWeak() + System.gc() //Then - assertNull(mountain.get()); + assertNull(mountain.get()) } @Test - public void strongToWeakTest() { + fun strongToWeakTest() { //Given - SwitchCacheComponent DI = Stone.createComponent(SwitchCacheComponent.class); - SwitchCacheExtComponent DIPro = Stone.createComponent(SwitchCacheExtComponent.class); - DIPro.extOf(DI); - WeakReference mountainStrong = new WeakReference<>(DI.earth().mountainStrong()); - WeakReference mountainSoft = new WeakReference<>(DI.earth().mountainSoft()); + val DI: SwitchCacheComponent = SwitchCacheComponentStoneComponent() + val DIPro: SwitchCacheExtComponent = SwitchCacheExtComponentStoneComponent() + DIPro.extOf(DI) + val mountainStrong = WeakReference(DI.earth()!!.mountainStrong()) + val mountainSoft = WeakReference(DI.earth()!!.mountainSoft()) //When - DIPro.strongToWeak(); - System.gc(); + DIPro.strongToWeak() + System.gc() //Then - assertNull(mountainStrong.get()); - assertNotNull(mountainSoft.get()); + assertNull(mountainStrong.get()) + assertNotNull(mountainSoft.get()) } @Test - public void weakToStrongFewMillisTest() throws InterruptedException { + @Throws(InterruptedException::class) + fun weakToStrongFewMillisTest() { //Given - SwitchCacheComponent DI = Stone.createComponent(SwitchCacheComponent.class); - SwitchCacheExtComponent DIPro = Stone.createComponent(SwitchCacheExtComponent.class); - DIPro.extOf(DI); - WeakReference mountainWeak = new WeakReference<>(DI.earth().mountainWeak()); + val DI: SwitchCacheComponent = SwitchCacheComponentStoneComponent() + val DIPro: SwitchCacheExtComponent = SwitchCacheExtComponentStoneComponent() + DIPro.extOf(DI) + val mountainWeak = WeakReference(DI.earth()!!.mountainWeak()) //When - DIPro.allStrongFewMillis(); - System.gc(); + DIPro.allStrongFewMillis() + System.gc() //Then: can't GC - assertNotNull(mountainWeak.get()); + assertNotNull(mountainWeak.get()) //When: after few millis - sleep(110); - System.gc(); + Thread.sleep(110) + System.gc() //Then: can GC - assertNull(mountainWeak.get()); + assertNull(mountainWeak.get()) } @Test - public void mountainToWeakTest() { + fun mountainToWeakTest() { //Given - SwitchCacheComponent DI = Stone.createComponent(SwitchCacheComponent.class); - SwitchCacheExtComponent DIPro = Stone.createComponent(SwitchCacheExtComponent.class); - DIPro.extOf(DI); - WeakReference mountain = new WeakReference<>(DI.earth().mountainStrong()); - WeakReference river = new WeakReference<>(DI.earth().riverSoft()); + val DI: SwitchCacheComponent = SwitchCacheComponentStoneComponent() + val DIPro: SwitchCacheExtComponent = SwitchCacheExtComponentStoneComponent() + DIPro.extOf(DI) + val mountain = WeakReference(DI.earth()!!.mountainStrong()) + val river = WeakReference(DI.earth()!!.riverSoft()) //When - DIPro.mountainToWeak(); - System.gc(); + DIPro.mountainToWeak() + System.gc() //Then - assertNull(mountain.get()); - assertNotNull(river.get()); + assertNull(mountain.get()) + assertNotNull(river.get()) } - } diff --git a/tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/cache/ExtEarthSwitchCacheTests.kt b/tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/cache/ExtEarthSwitchCacheTests.kt index daccfc00..1b1c5f85 100644 --- a/tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/cache/ExtEarthSwitchCacheTests.kt +++ b/tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/cache/ExtEarthSwitchCacheTests.kt @@ -1,79 +1,72 @@ -package com.dirgub.klee0kai.stone.text_ext.cache; +package com.dirgub.klee0kai.stone.text_ext.cache -import com.github.klee0kai.stone.Stone; -import com.github.klee0kai.test.di.swcache.SwitchCacheComponent; -import com.github.klee0kai.test.mowgli.earth.Mountain; -import com.github.klee0kai.test_ext.inject.di.swcache.SwitchCacheExtComponent; -import org.junit.jupiter.api.Test; - -import java.lang.ref.WeakReference; - -import static java.lang.Thread.sleep; -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertNull; - -public class ExtEarthSwitchCacheTests { +import com.github.klee0kai.test.di.swcache.SwitchCacheComponent +import com.github.klee0kai.test.di.swcache.SwitchCacheComponentStoneComponent +import com.github.klee0kai.test.mowgli.earth.Mountain +import com.github.klee0kai.test_ext.inject.di.swcache.SwitchCacheExtComponent +import com.github.klee0kai.test_ext.inject.di.swcache.SwitchCacheExtComponentStoneComponent +import org.junit.jupiter.api.Test +import org.junit.jupiter.api.assertNotNull +import org.junit.jupiter.api.assertNull +import java.lang.ref.WeakReference +class ExtEarthSwitchCacheTests { @Test - public void allToWeakTest() { + fun allToWeakTest() { //Given - SwitchCacheComponent DI = Stone.createComponent(SwitchCacheComponent.class); - SwitchCacheExtComponent DIPro = Stone.createComponent(SwitchCacheExtComponent.class); - DIPro.extOf(DI); - WeakReference mountain = new WeakReference<>(DIPro.earth().mountainStrong()); + val DI: SwitchCacheComponent = SwitchCacheComponentStoneComponent() + val DIPro: SwitchCacheExtComponent = SwitchCacheExtComponentStoneComponent() + DIPro.extOf(DI) + val mountain = WeakReference(DIPro.earth()!!.mountainStrong()) //When - DIPro.allWeakExt(); - System.gc(); + DIPro.allWeakExt() + System.gc() //Then - assertNull(mountain.get()); + org.junit.jupiter.api.Assertions.assertNull(mountain.get()) } @Test - public void strongToWeakTest() { + fun strongToWeakTest() { //Given - SwitchCacheComponent DI = Stone.createComponent(SwitchCacheComponent.class); - SwitchCacheExtComponent DIPro = Stone.createComponent(SwitchCacheExtComponent.class); - DIPro.extOf(DI); - WeakReference mountainStrong = new WeakReference<>(DIPro.earth().mountainStrong()); - WeakReference mountainSoft = new WeakReference<>(DIPro.earth().mountainSoft()); + val DI: SwitchCacheComponent = SwitchCacheComponentStoneComponent() + val DIPro: SwitchCacheExtComponent = SwitchCacheExtComponentStoneComponent() + DIPro.extOf(DI) + val mountainStrong = WeakReference(DIPro.earth()!!.mountainStrong()) + val mountainSoft = WeakReference(DIPro.earth()!!.mountainSoft()) //When - DIPro.strongToWeakExt(); - System.gc(); + DIPro.strongToWeakExt() + System.gc() //Then - assertNull(mountainStrong.get()); - assertNotNull(mountainSoft.get()); + assertNull(mountainStrong.get()) + assertNotNull(mountainSoft.get()) } @Test - public void weakToStrongFewMillisTest() throws InterruptedException { + @Throws(InterruptedException::class) + fun weakToStrongFewMillisTest() { //Given - SwitchCacheComponent DI = Stone.createComponent(SwitchCacheComponent.class); - SwitchCacheExtComponent DIPro = Stone.createComponent(SwitchCacheExtComponent.class); - DIPro.extOf(DI); - WeakReference mountainWeak = new WeakReference<>(DIPro.earth().mountainWeak()); + val DI: SwitchCacheComponent = SwitchCacheComponentStoneComponent() + val DIPro: SwitchCacheExtComponent = SwitchCacheExtComponentStoneComponent() + DIPro.extOf(DI) + val mountainWeak = WeakReference(DIPro.earth()!!.mountainWeak()) //When - DIPro.allStrongFewMillisExt(); - System.gc(); + DIPro.allStrongFewMillisExt() + System.gc() //Then: can't GC - assertNotNull(mountainWeak.get()); + assertNotNull(mountainWeak.get()) //When: after few millis - sleep(110); - System.gc(); + Thread.sleep(110) + System.gc() //Then: can GC - assertNull(mountainWeak.get()); + assertNull(mountainWeak.get()) } - - - - - } diff --git a/tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/gc/ExtEarthLastDayTests.kt b/tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/gc/ExtEarthLastDayTests.kt index 8fd19555..2444f987 100644 --- a/tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/gc/ExtEarthLastDayTests.kt +++ b/tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/gc/ExtEarthLastDayTests.kt @@ -1,379 +1,377 @@ -package com.dirgub.klee0kai.stone.text_ext.gc; +package com.dirgub.klee0kai.stone.text_ext.gc -import com.github.klee0kai.stone.Stone; -import com.github.klee0kai.test.di.gcforest.GcGodComponent; -import com.github.klee0kai.test.mowgli.earth.Mountain; -import com.github.klee0kai.test.mowgli.earth.River; -import com.github.klee0kai.test_ext.inject.di.gcforest.GcGodExtComponent; -import com.github.klee0kai.test_ext.inject.mowgli.earth.Desert; -import com.github.klee0kai.test_ext.inject.mowgli.earth.WaterFlow; -import org.junit.jupiter.api.Test; +import com.github.klee0kai.test.di.gcforest.GcGodComponent +import com.github.klee0kai.test.di.gcforest.GcGodComponentStoneComponent +import com.github.klee0kai.test.mowgli.earth.Mountain +import com.github.klee0kai.test.mowgli.earth.River +import com.github.klee0kai.test_ext.inject.di.gcforest.GcGodExtComponent +import com.github.klee0kai.test_ext.inject.di.gcforest.GcGodExtComponentStoneComponent +import com.github.klee0kai.test_ext.inject.mowgli.earth.Desert +import com.github.klee0kai.test_ext.inject.mowgli.earth.WaterFlow +import org.junit.jupiter.api.Test +import org.junit.jupiter.api.assertNotNull +import org.junit.jupiter.api.assertNull +import java.lang.ref.WeakReference -import java.lang.ref.Reference; -import java.lang.ref.WeakReference; -import java.util.Arrays; +class ExtEarthLastDayTests { -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertNull; - -public class ExtEarthLastDayTests { @Test - void gcAllTest() { + fun gcAllTest() { //Given - GcGodComponent DI = Stone.createComponent(GcGodComponent.class); - WeakReference mountainStrong = new WeakReference<>(DI.earth().mountainStrong()); - WeakReference mountainSoft = new WeakReference<>(DI.earth().mountainSoft()); - WeakReference mountainWeak = new WeakReference<>(DI.earth().mountainWeak()); - WeakReference mountainDef = new WeakReference<>(DI.earth().mountainDefaultFactory()); - WeakReference mountainDef2 = new WeakReference<>(DI.earth().mountainDefault2Factory()); - WeakReference riverStrong = new WeakReference<>(DI.earth().riverStrong()); - WeakReference riverSoft = new WeakReference<>(DI.earth().riverSoft()); - WeakReference riverWeak = new WeakReference<>(DI.earth().riverWeak()); - WeakReference riverDef = new WeakReference<>(DI.earth().riverDefaultSoft()); - GcGodExtComponent DIPro = Stone.createComponent(GcGodExtComponent.class); - DIPro.extOf(DI); - WeakReference desertStrong = new WeakReference<>(DIPro.earth().desertStrong()); - WeakReference desertSoft = new WeakReference<>(DIPro.earth().desertSoft()); - WeakReference desertWeak = new WeakReference<>(DIPro.earth().desertWeak()); - WeakReference desertFactory = new WeakReference<>(DIPro.earth().desertFactory()); - WeakReference waterFlowStrong = new WeakReference<>(DIPro.earth().riverStrong()); - WeakReference waterFlowSoft = new WeakReference<>(DIPro.earth().riverSoft()); - WeakReference waterFlowWeak = new WeakReference<>(DIPro.earth().riverWeak()); - WeakReference waterFlowDefRef = new WeakReference<>(DIPro.earth().riverDefaultSoft()); + val DI: GcGodComponent = GcGodComponentStoneComponent() + val mountainStrong = WeakReference(DI.earth()!!.mountainStrong()) + val mountainSoft = WeakReference(DI.earth()!!.mountainSoft()) + val mountainWeak = WeakReference(DI.earth()!!.mountainWeak()) + val mountainDef = WeakReference(DI.earth()!!.mountainDefaultFactory()) + val mountainDef2 = WeakReference(DI.earth()!!.mountainDefault2Factory()) + val riverStrong = WeakReference(DI.earth()!!.riverStrong()) + val riverSoft = WeakReference(DI.earth()!!.riverSoft()) + val riverWeak = WeakReference(DI.earth()!!.riverWeak()) + val riverDef = WeakReference(DI.earth()!!.riverDefaultSoft()) + val DIPro: GcGodExtComponent = GcGodExtComponentStoneComponent() + DIPro.extOf(DI) + val desertStrong = WeakReference(DIPro.earth()!!.desertStrong()) + val desertSoft = WeakReference(DIPro.earth()!!.desertSoft()) + val desertWeak = WeakReference(DIPro.earth()!!.desertWeak()) + val desertFactory = WeakReference(DIPro.earth()!!.desertFactory()) + val waterFlowStrong = WeakReference(DIPro.earth()!!.riverStrong()) + val waterFlowSoft = WeakReference(DIPro.earth()!!.riverSoft()) + val waterFlowWeak = WeakReference(DIPro.earth()!!.riverWeak()) + val waterFlowDefRef = WeakReference(DIPro.earth()!!.riverDefaultSoft()) //When - DIPro.gcAllExt(); + DIPro.gcAllExt() //Then - for (Reference ref : Arrays.asList( - mountainStrong, mountainSoft, mountainDef2, mountainWeak, mountainDef, - riverStrong, riverSoft, riverWeak, riverDef, - desertStrong, desertSoft, desertWeak, desertFactory, - waterFlowStrong, waterFlowSoft, waterFlowWeak, waterFlowDefRef + for (ref in listOf( + mountainStrong, mountainSoft, mountainDef2, mountainWeak, mountainDef, + riverStrong, riverSoft, riverWeak, riverDef, + desertStrong, desertSoft, desertWeak, desertFactory, + waterFlowStrong, waterFlowSoft, waterFlowWeak, waterFlowDefRef )) { - assertNull(ref.get()); + assertNull(ref.get()) } } @Test - void gcStrongTest() { + fun gcStrongTest() { //Given - GcGodComponent DI = Stone.createComponent(GcGodComponent.class); - WeakReference mountainStrong = new WeakReference<>(DI.earth().mountainStrong()); - WeakReference mountainSoft = new WeakReference<>(DI.earth().mountainSoft()); - WeakReference mountainWeak = new WeakReference<>(DI.earth().mountainWeak()); - WeakReference mountainDef = new WeakReference<>(DI.earth().mountainDefaultFactory()); - WeakReference mountainDef2 = new WeakReference<>(DI.earth().mountainDefault2Factory()); - WeakReference riverStrong = new WeakReference<>(DI.earth().riverStrong()); - WeakReference riverSoft = new WeakReference<>(DI.earth().riverSoft()); - WeakReference riverWeak = new WeakReference<>(DI.earth().riverWeak()); - WeakReference riverDef = new WeakReference<>(DI.earth().riverDefaultSoft()); - GcGodExtComponent DIPro = Stone.createComponent(GcGodExtComponent.class); - DIPro.extOf(DI); - WeakReference desertStrong = new WeakReference<>(DIPro.earth().desertStrong()); - WeakReference desertSoft = new WeakReference<>(DIPro.earth().desertSoft()); - WeakReference desertWeak = new WeakReference<>(DIPro.earth().desertWeak()); - WeakReference desertFactory = new WeakReference<>(DIPro.earth().desertFactory()); - WeakReference waterFlowStrong = new WeakReference<>(DIPro.earth().riverStrong()); - WeakReference waterFlowSoft = new WeakReference<>(DIPro.earth().riverSoft()); - WeakReference waterFlowWeak = new WeakReference<>(DIPro.earth().riverWeak()); - WeakReference waterFlowDefRef = new WeakReference<>(DIPro.earth().riverDefaultSoft()); + val DI: GcGodComponent = GcGodComponentStoneComponent() + val mountainStrong = WeakReference(DI.earth()!!.mountainStrong()) + val mountainSoft = WeakReference(DI.earth()!!.mountainSoft()) + val mountainWeak = WeakReference(DI.earth()!!.mountainWeak()) + val mountainDef = WeakReference(DI.earth()!!.mountainDefaultFactory()) + val mountainDef2 = WeakReference(DI.earth()!!.mountainDefault2Factory()) + val riverStrong = WeakReference(DI.earth()!!.riverStrong()) + val riverSoft = WeakReference(DI.earth()!!.riverSoft()) + val riverWeak = WeakReference(DI.earth()!!.riverWeak()) + val riverDef = WeakReference(DI.earth()!!.riverDefaultSoft()) + val DIPro: GcGodExtComponent = GcGodExtComponentStoneComponent() + DIPro.extOf(DI) + val desertStrong = WeakReference(DIPro.earth()!!.desertStrong()) + val desertSoft = WeakReference(DIPro.earth()!!.desertSoft()) + val desertWeak = WeakReference(DIPro.earth()!!.desertWeak()) + val desertFactory = WeakReference(DIPro.earth()!!.desertFactory()) + val waterFlowStrong = WeakReference(DIPro.earth()!!.riverStrong()) + val waterFlowSoft = WeakReference(DIPro.earth()!!.riverSoft()) + val waterFlowWeak = WeakReference(DIPro.earth()!!.riverWeak()) + val waterFlowDefRef = WeakReference(DIPro.earth()!!.riverDefaultSoft()) //When - DIPro.gcStrongExt(); + DIPro.gcStrongExt() //Then - for (Reference ref : Arrays.asList( - mountainStrong, mountainWeak, mountainDef, mountainDef2, - riverStrong, riverWeak, riverDef, - desertStrong, desertWeak, desertFactory, - waterFlowStrong, waterFlowWeak, waterFlowDefRef + for (ref in listOf( + mountainStrong, mountainWeak, mountainDef, mountainDef2, + riverStrong, riverWeak, riverDef, + desertStrong, desertWeak, desertFactory, + waterFlowStrong, waterFlowWeak, waterFlowDefRef )) { - assertNull(ref.get()); + assertNull(ref.get()) } - for (Reference ref : Arrays.asList( - mountainSoft, - riverSoft, - desertSoft, - waterFlowSoft + for (ref in listOf( + mountainSoft, + riverSoft, + desertSoft, + waterFlowSoft )) { - assertNotNull(ref.get()); + assertNotNull(ref.get()) } } @Test - void gcSoftTest() { + fun gcSoftTest() { //Given - GcGodComponent DI = Stone.createComponent(GcGodComponent.class); - WeakReference mountainStrong = new WeakReference<>(DI.earth().mountainStrong()); - WeakReference mountainSoft = new WeakReference<>(DI.earth().mountainSoft()); - WeakReference mountainWeak = new WeakReference<>(DI.earth().mountainWeak()); - WeakReference mountainDef = new WeakReference<>(DI.earth().mountainDefaultFactory()); - WeakReference mountainDef2 = new WeakReference<>(DI.earth().mountainDefault2Factory()); - WeakReference riverStrong = new WeakReference<>(DI.earth().riverStrong()); - WeakReference riverSoft = new WeakReference<>(DI.earth().riverSoft()); - WeakReference riverWeak = new WeakReference<>(DI.earth().riverWeak()); - WeakReference riverDef = new WeakReference<>(DI.earth().riverDefaultSoft()); - GcGodExtComponent DIPro = Stone.createComponent(GcGodExtComponent.class); - DIPro.extOf(DI); - WeakReference desertStrong = new WeakReference<>(DIPro.earth().desertStrong()); - WeakReference desertSoft = new WeakReference<>(DIPro.earth().desertSoft()); - WeakReference desertWeak = new WeakReference<>(DIPro.earth().desertWeak()); - WeakReference desertFactory = new WeakReference<>(DIPro.earth().desertFactory()); - WeakReference waterFlowStrong = new WeakReference<>(DIPro.earth().riverStrong()); - WeakReference waterFlowSoft = new WeakReference<>(DIPro.earth().riverSoft()); - WeakReference waterFlowWeak = new WeakReference<>(DIPro.earth().riverWeak()); - WeakReference waterFlowDefRef = new WeakReference<>(DIPro.earth().riverDefaultSoft()); + val DI: GcGodComponent = GcGodComponentStoneComponent() + val mountainStrong = WeakReference(DI.earth()!!.mountainStrong()) + val mountainSoft = WeakReference(DI.earth()!!.mountainSoft()) + val mountainWeak = WeakReference(DI.earth()!!.mountainWeak()) + val mountainDef = WeakReference(DI.earth()!!.mountainDefaultFactory()) + val mountainDef2 = WeakReference(DI.earth()!!.mountainDefault2Factory()) + val riverStrong = WeakReference(DI.earth()!!.riverStrong()) + val riverSoft = WeakReference(DI.earth()!!.riverSoft()) + val riverWeak = WeakReference(DI.earth()!!.riverWeak()) + val riverDef = WeakReference(DI.earth()!!.riverDefaultSoft()) + val DIPro: GcGodExtComponent = GcGodExtComponentStoneComponent() + DIPro.extOf(DI) + val desertStrong = WeakReference(DIPro.earth()!!.desertStrong()) + val desertSoft = WeakReference(DIPro.earth()!!.desertSoft()) + val desertWeak = WeakReference(DIPro.earth()!!.desertWeak()) + val desertFactory = WeakReference(DIPro.earth()!!.desertFactory()) + val waterFlowStrong = WeakReference(DIPro.earth()!!.riverStrong()) + val waterFlowSoft = WeakReference(DIPro.earth()!!.riverSoft()) + val waterFlowWeak = WeakReference(DIPro.earth()!!.riverWeak()) + val waterFlowDefRef = WeakReference(DIPro.earth()!!.riverDefaultSoft()) //When - DIPro.gcSoftExt(); + DIPro.gcSoftExt() //Then - for (Reference ref : Arrays.asList( - mountainSoft, mountainWeak, mountainDef, mountainDef2, - riverSoft, riverWeak, riverDef, - desertSoft, desertWeak, desertFactory, - waterFlowSoft, waterFlowDefRef, waterFlowWeak + for (ref in listOf( + mountainSoft, mountainWeak, mountainDef, mountainDef2, + riverSoft, riverWeak, riverDef, + desertSoft, desertWeak, desertFactory, + waterFlowSoft, waterFlowDefRef, waterFlowWeak )) { - assertNull(ref.get()); + assertNull(ref.get()) } - for (Reference ref : Arrays.asList( - mountainStrong, - riverStrong, - desertStrong, - waterFlowStrong + for (ref in listOf( + mountainStrong, + riverStrong, + desertStrong, + waterFlowStrong )) { - assertNotNull(ref.get()); + assertNotNull(ref.get()) } } @Test - void gcWeakTest() { + fun gcWeakTest() { //Given - GcGodComponent DI = Stone.createComponent(GcGodComponent.class); - WeakReference mountainStrong = new WeakReference<>(DI.earth().mountainStrong()); - WeakReference mountainSoft = new WeakReference<>(DI.earth().mountainSoft()); - WeakReference mountainWeak = new WeakReference<>(DI.earth().mountainWeak()); - WeakReference mountainDef = new WeakReference<>(DI.earth().mountainDefaultFactory()); - WeakReference mountainDef2 = new WeakReference<>(DI.earth().mountainDefault2Factory()); - WeakReference riverStrong = new WeakReference<>(DI.earth().riverStrong()); - WeakReference riverSoft = new WeakReference<>(DI.earth().riverSoft()); - WeakReference riverWeak = new WeakReference<>(DI.earth().riverWeak()); - WeakReference riverDef = new WeakReference<>(DI.earth().riverDefaultSoft()); - GcGodExtComponent DIPro = Stone.createComponent(GcGodExtComponent.class); - DIPro.extOf(DI); - WeakReference desertStrong = new WeakReference<>(DIPro.earth().desertStrong()); - WeakReference desertSoft = new WeakReference<>(DIPro.earth().desertSoft()); - WeakReference desertWeak = new WeakReference<>(DIPro.earth().desertWeak()); - WeakReference desertFactory = new WeakReference<>(DIPro.earth().desertFactory()); - WeakReference waterFlowStrong = new WeakReference<>(DIPro.earth().riverStrong()); - WeakReference waterFlowSoft = new WeakReference<>(DIPro.earth().riverSoft()); - WeakReference waterFlowWeak = new WeakReference<>(DIPro.earth().riverWeak()); - WeakReference waterFlowDefRef = new WeakReference<>(DIPro.earth().riverDefaultSoft()); + val DI: GcGodComponent = GcGodComponentStoneComponent() + val mountainStrong = WeakReference(DI.earth()!!.mountainStrong()) + val mountainSoft = WeakReference(DI.earth()!!.mountainSoft()) + val mountainWeak = WeakReference(DI.earth()!!.mountainWeak()) + val mountainDef = WeakReference(DI.earth()!!.mountainDefaultFactory()) + val mountainDef2 = WeakReference(DI.earth()!!.mountainDefault2Factory()) + val riverStrong = WeakReference(DI.earth()!!.riverStrong()) + val riverSoft = WeakReference(DI.earth()!!.riverSoft()) + val riverWeak = WeakReference(DI.earth()!!.riverWeak()) + val riverDef = WeakReference(DI.earth()!!.riverDefaultSoft()) + val DIPro: GcGodExtComponent = GcGodExtComponentStoneComponent() + DIPro.extOf(DI) + val desertStrong = WeakReference(DIPro.earth()!!.desertStrong()) + val desertSoft = WeakReference(DIPro.earth()!!.desertSoft()) + val desertWeak = WeakReference(DIPro.earth()!!.desertWeak()) + val desertFactory = WeakReference(DIPro.earth()!!.desertFactory()) + val waterFlowStrong = WeakReference(DIPro.earth()!!.riverStrong()) + val waterFlowSoft = WeakReference(DIPro.earth()!!.riverSoft()) + val waterFlowWeak = WeakReference(DIPro.earth()!!.riverWeak()) + val waterFlowDefRef = WeakReference(DIPro.earth()!!.riverDefaultSoft()) //When - DIPro.gcWeakExt(); + DIPro.gcWeakExt() //Then - for (Reference ref : Arrays.asList( - mountainWeak, mountainDef, mountainDef2, - riverWeak, riverDef, - desertWeak, desertFactory, - waterFlowWeak, waterFlowDefRef + for (ref in listOf( + mountainWeak, mountainDef, mountainDef2, + riverWeak, riverDef, + desertWeak, desertFactory, + waterFlowWeak, waterFlowDefRef )) { - assertNull(ref.get()); + assertNull(ref.get()) } - for (Reference ref : Arrays.asList( - mountainStrong, mountainSoft, - riverStrong, riverSoft, - desertStrong, desertSoft, - waterFlowStrong, waterFlowSoft + for (ref in listOf( + mountainStrong, mountainSoft, + riverStrong, riverSoft, + desertStrong, desertSoft, + waterFlowStrong, waterFlowSoft )) { - assertNotNull(ref.get()); + assertNotNull(ref.get()) } } @Test - void gcMountainTest() { + fun gcMountainTest() { //Given - GcGodComponent DI = Stone.createComponent(GcGodComponent.class); - WeakReference mountainStrong = new WeakReference<>(DI.earth().mountainStrong()); - WeakReference mountainSoft = new WeakReference<>(DI.earth().mountainSoft()); - WeakReference mountainWeak = new WeakReference<>(DI.earth().mountainWeak()); - WeakReference mountainDef = new WeakReference<>(DI.earth().mountainDefaultFactory()); - WeakReference mountainDef2 = new WeakReference<>(DI.earth().mountainDefault2Factory()); - WeakReference riverStrong = new WeakReference<>(DI.earth().riverStrong()); - WeakReference riverSoft = new WeakReference<>(DI.earth().riverSoft()); - WeakReference riverWeak = new WeakReference<>(DI.earth().riverWeak()); - WeakReference riverDef = new WeakReference<>(DI.earth().riverDefaultSoft()); - GcGodExtComponent DIPro = Stone.createComponent(GcGodExtComponent.class); - DIPro.extOf(DI); - WeakReference desertStrong = new WeakReference<>(DIPro.earth().desertStrong()); - WeakReference desertSoft = new WeakReference<>(DIPro.earth().desertSoft()); - WeakReference desertWeak = new WeakReference<>(DIPro.earth().desertWeak()); - WeakReference desertFactory = new WeakReference<>(DIPro.earth().desertFactory()); - WeakReference waterFlowStrong = new WeakReference<>(DIPro.earth().riverStrong()); - WeakReference waterFlowSoft = new WeakReference<>(DIPro.earth().riverSoft()); - WeakReference waterFlowWeak = new WeakReference<>(DIPro.earth().riverWeak()); - WeakReference waterFlowDefRef = new WeakReference<>(DIPro.earth().riverDefaultSoft()); + val DI: GcGodComponent = GcGodComponentStoneComponent() + val mountainStrong = WeakReference(DI.earth()!!.mountainStrong()) + val mountainSoft = WeakReference(DI.earth()!!.mountainSoft()) + val mountainWeak = WeakReference(DI.earth()!!.mountainWeak()) + val mountainDef = WeakReference(DI.earth()!!.mountainDefaultFactory()) + val mountainDef2 = WeakReference(DI.earth()!!.mountainDefault2Factory()) + val riverStrong = WeakReference(DI.earth()!!.riverStrong()) + val riverSoft = WeakReference(DI.earth()!!.riverSoft()) + val riverWeak = WeakReference(DI.earth()!!.riverWeak()) + val riverDef = WeakReference(DI.earth()!!.riverDefaultSoft()) + val DIPro: GcGodExtComponent = GcGodExtComponentStoneComponent() + DIPro.extOf(DI) + val desertStrong = WeakReference(DIPro.earth()!!.desertStrong()) + val desertSoft = WeakReference(DIPro.earth()!!.desertSoft()) + val desertWeak = WeakReference(DIPro.earth()!!.desertWeak()) + val desertFactory = WeakReference(DIPro.earth()!!.desertFactory()) + val waterFlowStrong = WeakReference(DIPro.earth()!!.riverStrong()) + val waterFlowSoft = WeakReference(DIPro.earth()!!.riverSoft()) + val waterFlowWeak = WeakReference(DIPro.earth()!!.riverWeak()) + val waterFlowDefRef = WeakReference(DIPro.earth()!!.riverDefaultSoft()) //When - DIPro.gcMountainsExt(); + DIPro.gcMountainsExt() //Then - for (Reference ref : Arrays.asList( - mountainStrong, mountainSoft, mountainWeak, mountainDef, mountainDef2, - riverWeak, riverDef, - desertWeak, desertFactory, - waterFlowWeak, waterFlowDefRef + for (ref in listOf( + mountainStrong, mountainSoft, mountainWeak, mountainDef, mountainDef2, + riverWeak, riverDef, + desertWeak, desertFactory, + waterFlowWeak, waterFlowDefRef )) { - assertNull(ref.get()); + assertNull(ref.get()) } - for (Reference ref : Arrays.asList( - riverStrong, riverSoft, - desertStrong, desertSoft, - waterFlowStrong, waterFlowSoft + for (ref in listOf( + riverStrong, riverSoft, + desertStrong, desertSoft, + waterFlowStrong, waterFlowSoft )) { - assertNotNull(ref.get()); + assertNotNull(ref.get()) } } @Test - void gcRiverTest() { + fun gcRiverTest() { //Given - GcGodComponent DI = Stone.createComponent(GcGodComponent.class); - WeakReference mountainStrong = new WeakReference<>(DI.earth().mountainStrong()); - WeakReference mountainSoft = new WeakReference<>(DI.earth().mountainSoft()); - WeakReference mountainWeak = new WeakReference<>(DI.earth().mountainWeak()); - WeakReference mountainDef = new WeakReference<>(DI.earth().mountainDefaultFactory()); - WeakReference mountainDef2 = new WeakReference<>(DI.earth().mountainDefault2Factory()); - WeakReference riverStrong = new WeakReference<>(DI.earth().riverStrong()); - WeakReference riverSoft = new WeakReference<>(DI.earth().riverSoft()); - WeakReference riverWeak = new WeakReference<>(DI.earth().riverWeak()); - WeakReference riverDef = new WeakReference<>(DI.earth().riverDefaultSoft()); - GcGodExtComponent DIPro = Stone.createComponent(GcGodExtComponent.class); - DIPro.extOf(DI); - WeakReference desertStrong = new WeakReference<>(DIPro.earth().desertStrong()); - WeakReference desertSoft = new WeakReference<>(DIPro.earth().desertSoft()); - WeakReference desertWeak = new WeakReference<>(DIPro.earth().desertWeak()); - WeakReference desertFactory = new WeakReference<>(DIPro.earth().desertFactory()); - WeakReference waterFlowStrong = new WeakReference<>(DIPro.earth().riverStrong()); - WeakReference waterFlowSoft = new WeakReference<>(DIPro.earth().riverSoft()); - WeakReference waterFlowWeak = new WeakReference<>(DIPro.earth().riverWeak()); - WeakReference waterFlowDefRef = new WeakReference<>(DIPro.earth().riverDefaultSoft()); + val DI: GcGodComponent = GcGodComponentStoneComponent() + val mountainStrong = WeakReference(DI.earth()!!.mountainStrong()) + val mountainSoft = WeakReference(DI.earth()!!.mountainSoft()) + val mountainWeak = WeakReference(DI.earth()!!.mountainWeak()) + val mountainDef = WeakReference(DI.earth()!!.mountainDefaultFactory()) + val mountainDef2 = WeakReference(DI.earth()!!.mountainDefault2Factory()) + val riverStrong = WeakReference(DI.earth()!!.riverStrong()) + val riverSoft = WeakReference(DI.earth()!!.riverSoft()) + val riverWeak = WeakReference(DI.earth()!!.riverWeak()) + val riverDef = WeakReference(DI.earth()!!.riverDefaultSoft()) + val DIPro: GcGodExtComponent = GcGodExtComponentStoneComponent() + DIPro.extOf(DI) + val desertStrong = WeakReference(DIPro.earth()!!.desertStrong()) + val desertSoft = WeakReference(DIPro.earth()!!.desertSoft()) + val desertWeak = WeakReference(DIPro.earth()!!.desertWeak()) + val desertFactory = WeakReference(DIPro.earth()!!.desertFactory()) + val waterFlowStrong = WeakReference(DIPro.earth()!!.riverStrong()) + val waterFlowSoft = WeakReference(DIPro.earth()!!.riverSoft()) + val waterFlowWeak = WeakReference(DIPro.earth()!!.riverWeak()) + val waterFlowDefRef = WeakReference(DIPro.earth()!!.riverDefaultSoft()) //When - DIPro.gcRiversExt(); + DIPro.gcRiversExt() //Then - for (Reference ref : Arrays.asList( - mountainWeak, mountainDef, mountainDef2, - riverStrong, riverSoft, riverWeak, riverDef, - desertWeak, desertFactory, - waterFlowStrong, waterFlowSoft, waterFlowDefRef, waterFlowWeak + for (ref in listOf( + mountainWeak, mountainDef, mountainDef2, + riverStrong, riverSoft, riverWeak, riverDef, + desertWeak, desertFactory, + waterFlowStrong, waterFlowSoft, waterFlowDefRef, waterFlowWeak )) { - assertNull(ref.get()); + assertNull(ref.get()) } - for (Reference ref : Arrays.asList( - mountainStrong, mountainSoft, - desertStrong, desertSoft + for (ref in listOf( + mountainStrong, mountainSoft, + desertStrong, desertSoft )) { - assertNotNull(ref.get()); + assertNotNull(ref.get()) } } @Test - void gcSoftMountainTest() { + fun gcSoftMountainTest() { //Given - GcGodComponent DI = Stone.createComponent(GcGodComponent.class); - WeakReference mountainStrong = new WeakReference<>(DI.earth().mountainStrong()); - WeakReference mountainSoft = new WeakReference<>(DI.earth().mountainSoft()); - WeakReference mountainWeak = new WeakReference<>(DI.earth().mountainWeak()); - WeakReference mountainDef = new WeakReference<>(DI.earth().mountainDefaultFactory()); - WeakReference mountainDef2 = new WeakReference<>(DI.earth().mountainDefault2Factory()); - WeakReference riverStrong = new WeakReference<>(DI.earth().riverStrong()); - WeakReference riverSoft = new WeakReference<>(DI.earth().riverSoft()); - WeakReference riverWeak = new WeakReference<>(DI.earth().riverWeak()); - WeakReference riverDef = new WeakReference<>(DI.earth().riverDefaultSoft()); - GcGodExtComponent DIPro = Stone.createComponent(GcGodExtComponent.class); - DIPro.extOf(DI); - WeakReference desertStrong = new WeakReference<>(DIPro.earth().desertStrong()); - WeakReference desertSoft = new WeakReference<>(DIPro.earth().desertSoft()); - WeakReference desertWeak = new WeakReference<>(DIPro.earth().desertWeak()); - WeakReference desertFactory = new WeakReference<>(DIPro.earth().desertFactory()); - WeakReference waterFlowStrong = new WeakReference<>(DIPro.earth().riverStrong()); - WeakReference waterFlowSoft = new WeakReference<>(DIPro.earth().riverSoft()); - WeakReference waterFlowWeak = new WeakReference<>(DIPro.earth().riverWeak()); - WeakReference waterFlowDefRef = new WeakReference<>(DIPro.earth().riverDefaultSoft()); + val DI: GcGodComponent = GcGodComponentStoneComponent() + val mountainStrong = WeakReference(DI.earth()!!.mountainStrong()) + val mountainSoft = WeakReference(DI.earth()!!.mountainSoft()) + val mountainWeak = WeakReference(DI.earth()!!.mountainWeak()) + val mountainDef = WeakReference(DI.earth()!!.mountainDefaultFactory()) + val mountainDef2 = WeakReference(DI.earth()!!.mountainDefault2Factory()) + val riverStrong = WeakReference(DI.earth()!!.riverStrong()) + val riverSoft = WeakReference(DI.earth()!!.riverSoft()) + val riverWeak = WeakReference(DI.earth()!!.riverWeak()) + val riverDef = WeakReference(DI.earth()!!.riverDefaultSoft()) + val DIPro: GcGodExtComponent = GcGodExtComponentStoneComponent() + DIPro.extOf(DI) + val desertStrong = WeakReference(DIPro.earth()!!.desertStrong()) + val desertSoft = WeakReference(DIPro.earth()!!.desertSoft()) + val desertWeak = WeakReference(DIPro.earth()!!.desertWeak()) + val desertFactory = WeakReference(DIPro.earth()!!.desertFactory()) + val waterFlowStrong = WeakReference(DIPro.earth()!!.riverStrong()) + val waterFlowSoft = WeakReference(DIPro.earth()!!.riverSoft()) + val waterFlowWeak = WeakReference(DIPro.earth()!!.riverWeak()) + val waterFlowDefRef = WeakReference(DIPro.earth()!!.riverDefaultSoft()) //When - DIPro.gcSoftMountainsExt(); + DIPro.gcSoftMountainsExt() //Then - for (Reference ref : Arrays.asList( - mountainSoft, mountainWeak, mountainDef, mountainDef2, - riverWeak, riverDef, - desertFactory, desertWeak, - waterFlowWeak, waterFlowDefRef + for (ref in listOf( + mountainSoft, mountainWeak, mountainDef, mountainDef2, + riverWeak, riverDef, + desertFactory, desertWeak, + waterFlowWeak, waterFlowDefRef )) { - assertNull(ref.get()); + assertNull(ref.get()) } - for (Reference ref : Arrays.asList( - mountainStrong, - riverStrong, riverSoft, - desertStrong, desertSoft, - waterFlowStrong, waterFlowSoft + for (ref in listOf( + mountainStrong, + riverStrong, riverSoft, + desertStrong, desertSoft, + waterFlowStrong, waterFlowSoft )) { - assertNotNull(ref.get()); + assertNotNull(ref.get()) } } @Test - void gcStrongMountainTest() { + fun gcStrongMountainTest() { //Given - GcGodComponent DI = Stone.createComponent(GcGodComponent.class); - WeakReference mountainStrong = new WeakReference<>(DI.earth().mountainStrong()); - WeakReference mountainSoft = new WeakReference<>(DI.earth().mountainSoft()); - WeakReference mountainWeak = new WeakReference<>(DI.earth().mountainWeak()); - WeakReference mountainDef = new WeakReference<>(DI.earth().mountainDefaultFactory()); - WeakReference mountainDef2 = new WeakReference<>(DI.earth().mountainDefault2Factory()); - WeakReference riverStrong = new WeakReference<>(DI.earth().riverStrong()); - WeakReference riverSoft = new WeakReference<>(DI.earth().riverSoft()); - WeakReference riverWeak = new WeakReference<>(DI.earth().riverWeak()); - WeakReference riverDef = new WeakReference<>(DI.earth().riverDefaultSoft()); - GcGodExtComponent DIPro = Stone.createComponent(GcGodExtComponent.class); - DIPro.extOf(DI); - WeakReference desertStrong = new WeakReference<>(DIPro.earth().desertStrong()); - WeakReference desertSoft = new WeakReference<>(DIPro.earth().desertSoft()); - WeakReference desertWeak = new WeakReference<>(DIPro.earth().desertWeak()); - WeakReference desertFactory = new WeakReference<>(DIPro.earth().desertFactory()); - WeakReference waterFlowStrong = new WeakReference<>(DIPro.earth().riverStrong()); - WeakReference waterFlowSoft = new WeakReference<>(DIPro.earth().riverSoft()); - WeakReference waterFlowWeak = new WeakReference<>(DIPro.earth().riverWeak()); - WeakReference waterFlowDefRef = new WeakReference<>(DIPro.earth().riverDefaultSoft()); + val DI: GcGodComponent = GcGodComponentStoneComponent() + val mountainStrong = WeakReference(DI.earth()!!.mountainStrong()) + val mountainSoft = WeakReference(DI.earth()!!.mountainSoft()) + val mountainWeak = WeakReference(DI.earth()!!.mountainWeak()) + val mountainDef = WeakReference(DI.earth()!!.mountainDefaultFactory()) + val mountainDef2 = WeakReference(DI.earth()!!.mountainDefault2Factory()) + val riverStrong = WeakReference(DI.earth()!!.riverStrong()) + val riverSoft = WeakReference(DI.earth()!!.riverSoft()) + val riverWeak = WeakReference(DI.earth()!!.riverWeak()) + val riverDef = WeakReference(DI.earth()!!.riverDefaultSoft()) + val DIPro: GcGodExtComponent = GcGodExtComponentStoneComponent() + DIPro.extOf(DI) + val desertStrong = WeakReference(DIPro.earth()!!.desertStrong()) + val desertSoft = WeakReference(DIPro.earth()!!.desertSoft()) + val desertWeak = WeakReference(DIPro.earth()!!.desertWeak()) + val desertFactory = WeakReference(DIPro.earth()!!.desertFactory()) + val waterFlowStrong = WeakReference(DIPro.earth()!!.riverStrong()) + val waterFlowSoft = WeakReference(DIPro.earth()!!.riverSoft()) + val waterFlowWeak = WeakReference(DIPro.earth()!!.riverWeak()) + val waterFlowDefRef = WeakReference(DIPro.earth()!!.riverDefaultSoft()) //When - DIPro.gcStrongMountainsExt(); + DIPro.gcStrongMountainsExt() //Then - for (Reference ref : Arrays.asList( - mountainStrong, mountainWeak, mountainDef, mountainDef2, - riverWeak, riverDef, - desertFactory, desertWeak, - waterFlowWeak, waterFlowDefRef + for (ref in listOf( + mountainStrong, mountainWeak, mountainDef, mountainDef2, + riverWeak, riverDef, + desertFactory, desertWeak, + waterFlowWeak, waterFlowDefRef )) { - assertNull(ref.get()); + assertNull(ref.get()) } - for (Reference ref : Arrays.asList( - mountainSoft, - riverStrong, riverSoft, - desertStrong, desertSoft, - waterFlowStrong, waterFlowSoft + for (ref in listOf( + mountainSoft, + riverStrong, riverSoft, + desertStrong, desertSoft, + waterFlowStrong, waterFlowSoft )) { - assertNotNull(ref.get()); + assertNotNull(ref.get()) } } From e790b1d8af199c612b23b1d23a0365b18a98db96 Mon Sep 17 00:00:00 2001 From: klee0kai Date: Fri, 19 Dec 2025 22:56:20 +0100 Subject: [PATCH 076/122] Rename .java to .kt --- .../{EarthLastDayAndProTests.java => EarthLastDayAndProTests.kt} | 0 ...{EarthLastDayFromProTests.java => EarthLastDayFromProTests.kt} | 0 .../{GoodPhoneInjectExtTests.java => GoodPhoneInjectExtTests.kt} | 0 ...onentFromProTests.java => TechFactoryComponentFromProTests.kt} | 0 ...verriddenTests.java => TechFactoryComponentOverriddenTests.kt} | 0 5 files changed, 0 insertions(+), 0 deletions(-) rename tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/gc/{EarthLastDayAndProTests.java => EarthLastDayAndProTests.kt} (100%) rename tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/gc/{EarthLastDayFromProTests.java => EarthLastDayFromProTests.kt} (100%) rename tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/identifiers/{GoodPhoneInjectExtTests.java => GoodPhoneInjectExtTests.kt} (100%) rename tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/identifiers/{TechFactoryComponentFromProTests.java => TechFactoryComponentFromProTests.kt} (100%) rename tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/identifiers/{TechFactoryComponentOverriddenTests.java => TechFactoryComponentOverriddenTests.kt} (100%) diff --git a/tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/gc/EarthLastDayAndProTests.java b/tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/gc/EarthLastDayAndProTests.kt similarity index 100% rename from tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/gc/EarthLastDayAndProTests.java rename to tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/gc/EarthLastDayAndProTests.kt diff --git a/tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/gc/EarthLastDayFromProTests.java b/tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/gc/EarthLastDayFromProTests.kt similarity index 100% rename from tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/gc/EarthLastDayFromProTests.java rename to tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/gc/EarthLastDayFromProTests.kt diff --git a/tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/identifiers/GoodPhoneInjectExtTests.java b/tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/identifiers/GoodPhoneInjectExtTests.kt similarity index 100% rename from tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/identifiers/GoodPhoneInjectExtTests.java rename to tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/identifiers/GoodPhoneInjectExtTests.kt diff --git a/tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/identifiers/TechFactoryComponentFromProTests.java b/tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/identifiers/TechFactoryComponentFromProTests.kt similarity index 100% rename from tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/identifiers/TechFactoryComponentFromProTests.java rename to tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/identifiers/TechFactoryComponentFromProTests.kt diff --git a/tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/identifiers/TechFactoryComponentOverriddenTests.java b/tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/identifiers/TechFactoryComponentOverriddenTests.kt similarity index 100% rename from tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/identifiers/TechFactoryComponentOverriddenTests.java rename to tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/identifiers/TechFactoryComponentOverriddenTests.kt From d5f71db5c336e3d50163a5694cbae68c842a6352 Mon Sep 17 00:00:00 2001 From: klee0kai Date: Fri, 19 Dec 2025 22:56:20 +0100 Subject: [PATCH 077/122] run test ext --- .../singlemethod_gc/ExtPlanetRollingTests.kt | 267 ++++---- .../text_ext/cache/EarthCacheProMixedTests.kt | 1 - .../text_ext/gc/EarthLastDayAndProTests.kt | 626 +++++++++--------- .../text_ext/gc/EarthLastDayFromProTests.kt | 623 +++++++++-------- .../identifiers/GoodPhoneInjectExtTests.kt | 122 ++-- .../TechFactoryComponentFromProTests.kt | 129 ++-- .../TechFactoryComponentOverriddenTests.kt | 128 ++-- 7 files changed, 936 insertions(+), 960 deletions(-) diff --git a/tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/bindinstance/singlemethod_gc/ExtPlanetRollingTests.kt b/tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/bindinstance/singlemethod_gc/ExtPlanetRollingTests.kt index f6550d5c..24639c42 100644 --- a/tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/bindinstance/singlemethod_gc/ExtPlanetRollingTests.kt +++ b/tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/bindinstance/singlemethod_gc/ExtPlanetRollingTests.kt @@ -1,6 +1,5 @@ package com.dirgub.klee0kai.stone.text_ext.bindinstance.singlemethod_gc -import com.github.klee0kai.stone.Stone import com.github.klee0kai.test.di.bindinstance.singlemethod_gc.PlanetRollingComponent import com.github.klee0kai.test.di.bindinstance.singlemethod_gc.PlanetRollingComponentStoneComponent import com.github.klee0kai.test.mowgli.galaxy.Earth @@ -175,37 +174,34 @@ class ExtPlanetRollingTests { } - @org.junit.jupiter.api.Test + @Test fun gcWeakTest() { //Given - val DI: PlanetRollingComponent = Stone.createComponent(PlanetRollingComponent::class.java) - val earthStrong: java.lang.ref.WeakReference = java.lang.ref.WeakReference(Earth()) - val earthSoft: java.lang.ref.WeakReference = java.lang.ref.WeakReference(Earth()) - val planetWeak: java.lang.ref.WeakReference = java.lang.ref.WeakReference(Earth()) - val sunStrong = - java.lang.ref.WeakReference(com.github.klee0kai.test.mowgli.galaxy.Sun()) - val sunSoft = - java.lang.ref.WeakReference(com.github.klee0kai.test.mowgli.galaxy.Sun()) - val starWeak = - java.lang.ref.WeakReference(com.github.klee0kai.test.mowgli.galaxy.Sun()) + val DI: PlanetRollingComponent = PlanetRollingComponentStoneComponent() + val earthStrong = WeakReference(Earth()) + val earthSoft = WeakReference(Earth()) + val planetWeak = WeakReference(Earth()) + val sunStrong = WeakReference(Sun()) + val sunSoft = WeakReference(Sun()) + val starWeak = WeakReference(Sun()) DI.earthStrong(earthStrong.get()) DI.earthSoft(earthSoft.get()) DI.planet(planetWeak.get()) - DI.sunModule().sunStrong(sunStrong.get()) - DI.sunModule().sunSoft(sunSoft.get()) - DI.sunModule().star(starWeak.get()) + DI.sunModule()!!.sunStrong(sunStrong.get()) + DI.sunModule()!!.sunSoft(sunSoft.get()) + DI.sunModule()!!.star(starWeak.get()) //external component init - val DIPro: ExtPlanetRollingComponent = Stone.createComponent(ExtPlanetRollingComponent::class.java) + val DIPro: ExtPlanetRollingComponent = ExtPlanetRollingComponentStoneComponent() DIPro.extOf(DI) - val siriusStrong: java.lang.ref.WeakReference = java.lang.ref.WeakReference(Sirius()) - val siriusSoft: java.lang.ref.WeakReference = java.lang.ref.WeakReference(Sirius()) - val siriusWeak: java.lang.ref.WeakReference = java.lang.ref.WeakReference(Sirius()) - val moonStrong: java.lang.ref.WeakReference = java.lang.ref.WeakReference(Moon()) - val moonSoft: java.lang.ref.WeakReference = java.lang.ref.WeakReference(Moon()) - val moonWeak: java.lang.ref.WeakReference = java.lang.ref.WeakReference(Moon()) - DIPro.sunModule().siriusStrong(siriusStrong.get()) - DIPro.sunModule().siriusSoft(siriusSoft.get()) - DIPro.sunModule().siriusWeak(siriusWeak.get()) + val siriusStrong = WeakReference(Sirius()) + val siriusSoft = WeakReference(Sirius()) + val siriusWeak = WeakReference(Sirius()) + val moonStrong = WeakReference(Moon()) + val moonSoft = WeakReference(Moon()) + val moonWeak = WeakReference(Moon()) + DIPro.sunModule()!!.siriusStrong(siriusStrong.get()) + DIPro.sunModule()!!.siriusSoft(siriusSoft.get()) + DIPro.sunModule()!!.siriusWeak(siriusWeak.get()) DIPro.moonStrong(moonStrong.get()) DIPro.moonSoft(moonSoft.get()) DIPro.moonWeak(moonWeak.get()) @@ -214,57 +210,54 @@ class ExtPlanetRollingTests { DIPro.gcWeakExt() //Then - for (ref in java.util.Arrays.asList>( + for (ref in listOf( planetWeak, starWeak, siriusWeak, moonWeak )) { - org.junit.jupiter.api.Assertions.assertNull(ref.get()) + assertNull(ref.get()) } - for (ref in java.util.Arrays.asList>( + for (ref in listOf( earthStrong, earthSoft, sunStrong, sunSoft, siriusStrong, siriusSoft, moonStrong, moonSoft )) { - org.junit.jupiter.api.Assertions.assertNotNull(ref.get()) + assertNotNull(ref.get()) } } - @org.junit.jupiter.api.Test + @Test fun gcSoftSunTest() { //Given - val DI: PlanetRollingComponent = Stone.createComponent(PlanetRollingComponent::class.java) - val earthStrong: java.lang.ref.WeakReference = java.lang.ref.WeakReference(Earth()) - val earthSoft: java.lang.ref.WeakReference = java.lang.ref.WeakReference(Earth()) - val planetWeak: java.lang.ref.WeakReference = java.lang.ref.WeakReference(Earth()) - val sunStrong = - java.lang.ref.WeakReference(com.github.klee0kai.test.mowgli.galaxy.Sun()) - val sunSoft = - java.lang.ref.WeakReference(com.github.klee0kai.test.mowgli.galaxy.Sun()) - val starWeak = - java.lang.ref.WeakReference(com.github.klee0kai.test.mowgli.galaxy.Sun()) + val DI: PlanetRollingComponent = PlanetRollingComponentStoneComponent() + val earthStrong = WeakReference(Earth()) + val earthSoft = WeakReference(Earth()) + val planetWeak = WeakReference(Earth()) + val sunStrong = WeakReference(Sun()) + val sunSoft = WeakReference(Sun()) + val starWeak = WeakReference(Sun()) DI.earthStrong(earthStrong.get()) DI.earthSoft(earthSoft.get()) DI.planet(planetWeak.get()) - DI.sunModule().sunStrong(sunStrong.get()) - DI.sunModule().sunSoft(sunSoft.get()) - DI.sunModule().star(starWeak.get()) + DI.sunModule()!!.sunStrong(sunStrong.get()) + DI.sunModule()!!.sunSoft(sunSoft.get()) + DI.sunModule()!!.star(starWeak.get()) //external component init - val DIPro: ExtPlanetRollingComponent = Stone.createComponent(ExtPlanetRollingComponent::class.java) + val DIPro: ExtPlanetRollingComponent = ExtPlanetRollingComponentStoneComponent() DIPro.extOf(DI) - val siriusStrong: java.lang.ref.WeakReference = java.lang.ref.WeakReference(Sirius()) - val siriusSoft: java.lang.ref.WeakReference = java.lang.ref.WeakReference(Sirius()) - val siriusWeak: java.lang.ref.WeakReference = java.lang.ref.WeakReference(Sirius()) - val moonStrong: java.lang.ref.WeakReference = java.lang.ref.WeakReference(Moon()) - val moonSoft: java.lang.ref.WeakReference = java.lang.ref.WeakReference(Moon()) - val moonWeak: java.lang.ref.WeakReference = java.lang.ref.WeakReference(Moon()) - DIPro.sunModule().siriusStrong(siriusStrong.get()) - DIPro.sunModule().siriusSoft(siriusSoft.get()) - DIPro.sunModule().siriusWeak(siriusWeak.get()) + val siriusStrong = WeakReference(Sirius()) + val siriusSoft = WeakReference(Sirius()) + val siriusWeak = WeakReference(Sirius()) + val moonStrong = WeakReference(Moon()) + val moonSoft = WeakReference(Moon()) + val moonWeak = WeakReference(Moon()) + DIPro.sunModule()!!.siriusStrong(siriusStrong.get()) + DIPro.sunModule()!!.siriusSoft(siriusSoft.get()) + DIPro.sunModule()!!.siriusWeak(siriusWeak.get()) DIPro.moonStrong(moonStrong.get()) DIPro.moonSoft(moonSoft.get()) DIPro.moonWeak(moonWeak.get()) @@ -273,57 +266,54 @@ class ExtPlanetRollingTests { DIPro.gcSoftSunExt() //Then - for (ref in java.util.Arrays.asList>( + for (ref in listOf( planetWeak, sunSoft, starWeak, siriusWeak, moonWeak )) { - org.junit.jupiter.api.Assertions.assertNull(ref.get()) + assertNull(ref.get()) } - for (ref in java.util.Arrays.asList>( + for (ref in listOf( earthStrong, earthSoft, sunStrong, siriusStrong, siriusSoft, moonStrong, moonSoft )) { - org.junit.jupiter.api.Assertions.assertNotNull(ref.get()) + assertNotNull(ref.get()) } } - @org.junit.jupiter.api.Test + @Test fun gcSoftPlanetsTest() { //Given - val DI: PlanetRollingComponent = Stone.createComponent(PlanetRollingComponent::class.java) - val earthStrong: java.lang.ref.WeakReference = java.lang.ref.WeakReference(Earth()) - val earthSoft: java.lang.ref.WeakReference = java.lang.ref.WeakReference(Earth()) - val planetWeak: java.lang.ref.WeakReference = java.lang.ref.WeakReference(Earth()) - val sunStrong = - java.lang.ref.WeakReference(com.github.klee0kai.test.mowgli.galaxy.Sun()) - val sunSoft = - java.lang.ref.WeakReference(com.github.klee0kai.test.mowgli.galaxy.Sun()) - val starWeak = - java.lang.ref.WeakReference(com.github.klee0kai.test.mowgli.galaxy.Sun()) + val DI: PlanetRollingComponent = PlanetRollingComponentStoneComponent() + val earthStrong = WeakReference(Earth()) + val earthSoft = WeakReference(Earth()) + val planetWeak = WeakReference(Earth()) + val sunStrong = WeakReference(Sun()) + val sunSoft = WeakReference(Sun()) + val starWeak = WeakReference(Sun()) DI.earthStrong(earthStrong.get()) DI.earthSoft(earthSoft.get()) DI.planet(planetWeak.get()) - DI.sunModule().sunStrong(sunStrong.get()) - DI.sunModule().sunSoft(sunSoft.get()) - DI.sunModule().star(starWeak.get()) + DI.sunModule()!!.sunStrong(sunStrong.get()) + DI.sunModule()!!.sunSoft(sunSoft.get()) + DI.sunModule()!!.star(starWeak.get()) //external component init - val DIPro: ExtPlanetRollingComponent = Stone.createComponent(ExtPlanetRollingComponent::class.java) + val DIPro: ExtPlanetRollingComponent = ExtPlanetRollingComponentStoneComponent() DIPro.extOf(DI) - val siriusStrong: java.lang.ref.WeakReference = java.lang.ref.WeakReference(Sirius()) - val siriusSoft: java.lang.ref.WeakReference = java.lang.ref.WeakReference(Sirius()) - val siriusWeak: java.lang.ref.WeakReference = java.lang.ref.WeakReference(Sirius()) - val moonStrong: java.lang.ref.WeakReference = java.lang.ref.WeakReference(Moon()) - val moonSoft: java.lang.ref.WeakReference = java.lang.ref.WeakReference(Moon()) - val moonWeak: java.lang.ref.WeakReference = java.lang.ref.WeakReference(Moon()) - DIPro.sunModule().siriusStrong(siriusStrong.get()) - DIPro.sunModule().siriusSoft(siriusSoft.get()) - DIPro.sunModule().siriusWeak(siriusWeak.get()) + val siriusStrong = WeakReference(Sirius()) + val siriusSoft = WeakReference(Sirius()) + val siriusWeak = WeakReference(Sirius()) + val moonStrong = WeakReference(Moon()) + val moonSoft = WeakReference(Moon()) + val moonWeak = WeakReference(Moon()) + DIPro.sunModule()!!.siriusStrong(siriusStrong.get()) + DIPro.sunModule()!!.siriusSoft(siriusSoft.get()) + DIPro.sunModule()!!.siriusWeak(siriusWeak.get()) DIPro.moonStrong(moonStrong.get()) DIPro.moonSoft(moonSoft.get()) DIPro.moonWeak(moonWeak.get()) @@ -332,57 +322,54 @@ class ExtPlanetRollingTests { DIPro.gcSoftPlanetsExt() //Then - for (ref in java.util.Arrays.asList>( + for (ref in listOf( earthSoft, planetWeak, starWeak, siriusWeak, moonWeak )) { - org.junit.jupiter.api.Assertions.assertNull(ref.get()) + assertNull(ref.get()) } - for (ref in java.util.Arrays.asList>( + for (ref in listOf( earthStrong, sunStrong, sunSoft, siriusStrong, siriusSoft, moonStrong, moonSoft )) { - org.junit.jupiter.api.Assertions.assertNotNull(ref.get()) + assertNotNull(ref.get()) } } - @org.junit.jupiter.api.Test + @Test fun gcSoftSiriusTest() { //Given - val DI: PlanetRollingComponent = Stone.createComponent(PlanetRollingComponent::class.java) - val earthStrong: java.lang.ref.WeakReference = java.lang.ref.WeakReference(Earth()) - val earthSoft: java.lang.ref.WeakReference = java.lang.ref.WeakReference(Earth()) - val planetWeak: java.lang.ref.WeakReference = java.lang.ref.WeakReference(Earth()) - val sunStrong = - java.lang.ref.WeakReference(com.github.klee0kai.test.mowgli.galaxy.Sun()) - val sunSoft = - java.lang.ref.WeakReference(com.github.klee0kai.test.mowgli.galaxy.Sun()) - val starWeak = - java.lang.ref.WeakReference(com.github.klee0kai.test.mowgli.galaxy.Sun()) + val DI: PlanetRollingComponent = PlanetRollingComponentStoneComponent() + val earthStrong = WeakReference(Earth()) + val earthSoft = WeakReference(Earth()) + val planetWeak = WeakReference(Earth()) + val sunStrong = WeakReference(Sun()) + val sunSoft = WeakReference(Sun()) + val starWeak = WeakReference(Sun()) DI.earthStrong(earthStrong.get()) DI.earthSoft(earthSoft.get()) DI.planet(planetWeak.get()) - DI.sunModule().sunStrong(sunStrong.get()) - DI.sunModule().sunSoft(sunSoft.get()) - DI.sunModule().star(starWeak.get()) + DI.sunModule()!!.sunStrong(sunStrong.get()) + DI.sunModule()!!.sunSoft(sunSoft.get()) + DI.sunModule()!!.star(starWeak.get()) //external component init - val DIPro: ExtPlanetRollingComponent = Stone.createComponent(ExtPlanetRollingComponent::class.java) + val DIPro: ExtPlanetRollingComponent = ExtPlanetRollingComponentStoneComponent() DIPro.extOf(DI) - val siriusStrong: java.lang.ref.WeakReference = java.lang.ref.WeakReference(Sirius()) - val siriusSoft: java.lang.ref.WeakReference = java.lang.ref.WeakReference(Sirius()) - val siriusWeak: java.lang.ref.WeakReference = java.lang.ref.WeakReference(Sirius()) - val moonStrong: java.lang.ref.WeakReference = java.lang.ref.WeakReference(Moon()) - val moonSoft: java.lang.ref.WeakReference = java.lang.ref.WeakReference(Moon()) - val moonWeak: java.lang.ref.WeakReference = java.lang.ref.WeakReference(Moon()) - DIPro.sunModule().siriusStrong(siriusStrong.get()) - DIPro.sunModule().siriusSoft(siriusSoft.get()) - DIPro.sunModule().siriusWeak(siriusWeak.get()) + val siriusStrong = WeakReference(Sirius()) + val siriusSoft = WeakReference(Sirius()) + val siriusWeak = WeakReference(Sirius()) + val moonStrong = WeakReference(Moon()) + val moonSoft = WeakReference(Moon()) + val moonWeak = WeakReference(Moon()) + DIPro.sunModule()!!.siriusStrong(siriusStrong.get()) + DIPro.sunModule()!!.siriusSoft(siriusSoft.get()) + DIPro.sunModule()!!.siriusWeak(siriusWeak.get()) DIPro.moonStrong(moonStrong.get()) DIPro.moonSoft(moonSoft.get()) DIPro.moonWeak(moonWeak.get()) @@ -391,57 +378,54 @@ class ExtPlanetRollingTests { DIPro.gcSoftSiriusExt() //Then - for (ref in java.util.Arrays.asList>( + for (ref in listOf( planetWeak, starWeak, siriusSoft, siriusWeak, moonWeak )) { - org.junit.jupiter.api.Assertions.assertNull(ref.get()) + assertNull(ref.get()) } - for (ref in java.util.Arrays.asList>( + for (ref in listOf( earthStrong, earthSoft, sunStrong, sunSoft, siriusStrong, moonStrong, moonSoft )) { - org.junit.jupiter.api.Assertions.assertNotNull(ref.get()) + assertNotNull(ref.get()) } } - @org.junit.jupiter.api.Test + @Test fun gcSputniksMoonTest() { //Given - val DI: PlanetRollingComponent = Stone.createComponent(PlanetRollingComponent::class.java) - val earthStrong: java.lang.ref.WeakReference = java.lang.ref.WeakReference(Earth()) - val earthSoft: java.lang.ref.WeakReference = java.lang.ref.WeakReference(Earth()) - val planetWeak: java.lang.ref.WeakReference = java.lang.ref.WeakReference(Earth()) - val sunStrong = - java.lang.ref.WeakReference(com.github.klee0kai.test.mowgli.galaxy.Sun()) - val sunSoft = - java.lang.ref.WeakReference(com.github.klee0kai.test.mowgli.galaxy.Sun()) - val starWeak = - java.lang.ref.WeakReference(com.github.klee0kai.test.mowgli.galaxy.Sun()) + val DI: PlanetRollingComponent = PlanetRollingComponentStoneComponent() + val earthStrong = WeakReference(Earth()) + val earthSoft = WeakReference(Earth()) + val planetWeak = WeakReference(Earth()) + val sunStrong = WeakReference(Sun()) + val sunSoft = WeakReference(Sun()) + val starWeak = WeakReference(Sun()) DI.earthStrong(earthStrong.get()) DI.earthSoft(earthSoft.get()) DI.planet(planetWeak.get()) - DI.sunModule().sunStrong(sunStrong.get()) - DI.sunModule().sunSoft(sunSoft.get()) - DI.sunModule().star(starWeak.get()) + DI.sunModule()!!.sunStrong(sunStrong.get()) + DI.sunModule()!!.sunSoft(sunSoft.get()) + DI.sunModule()!!.star(starWeak.get()) //external component init - val DIPro: ExtPlanetRollingComponent = Stone.createComponent(ExtPlanetRollingComponent::class.java) + val DIPro: ExtPlanetRollingComponent = ExtPlanetRollingComponentStoneComponent() DIPro.extOf(DI) - val siriusStrong: java.lang.ref.WeakReference = java.lang.ref.WeakReference(Sirius()) - val siriusSoft: java.lang.ref.WeakReference = java.lang.ref.WeakReference(Sirius()) - val siriusWeak: java.lang.ref.WeakReference = java.lang.ref.WeakReference(Sirius()) - val moonStrong: java.lang.ref.WeakReference = java.lang.ref.WeakReference(Moon()) - val moonSoft: java.lang.ref.WeakReference = java.lang.ref.WeakReference(Moon()) - val moonWeak: java.lang.ref.WeakReference = java.lang.ref.WeakReference(Moon()) - DIPro.sunModule().siriusStrong(siriusStrong.get()) - DIPro.sunModule().siriusSoft(siriusSoft.get()) - DIPro.sunModule().siriusWeak(siriusWeak.get()) + val siriusStrong = WeakReference(Sirius()) + val siriusSoft = WeakReference(Sirius()) + val siriusWeak = WeakReference(Sirius()) + val moonStrong = WeakReference(Moon()) + val moonSoft = WeakReference(Moon()) + val moonWeak = WeakReference(Moon()) + DIPro.sunModule()!!.siriusStrong(siriusStrong.get()) + DIPro.sunModule()!!.siriusSoft(siriusSoft.get()) + DIPro.sunModule()!!.siriusWeak(siriusWeak.get()) DIPro.moonStrong(moonStrong.get()) DIPro.moonSoft(moonSoft.get()) DIPro.moonWeak(moonWeak.get()) @@ -450,22 +434,23 @@ class ExtPlanetRollingTests { DIPro.gcSoftSputniksExt() //Then - for (ref in java.util.Arrays.asList>( + for (ref in listOf( planetWeak, starWeak, siriusWeak, moonSoft, moonWeak )) { - org.junit.jupiter.api.Assertions.assertNull(ref.get()) + assertNull(ref.get()) } - for (ref in java.util.Arrays.asList>( + for (ref in listOf( earthStrong, earthSoft, sunStrong, sunSoft, siriusStrong, siriusSoft, moonStrong )) { - org.junit.jupiter.api.Assertions.assertNotNull(ref.get()) + assertNotNull(ref.get()) } } + } diff --git a/tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/cache/EarthCacheProMixedTests.kt b/tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/cache/EarthCacheProMixedTests.kt index e034b073..1bae1095 100644 --- a/tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/cache/EarthCacheProMixedTests.kt +++ b/tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/cache/EarthCacheProMixedTests.kt @@ -1,6 +1,5 @@ package com.dirgub.klee0kai.stone.text_ext.cache -import com.github.klee0kai.stone.Stone import com.github.klee0kai.test.di.gcforest.GcGodComponent import com.github.klee0kai.test.di.gcforest.GcGodComponentStoneComponent import com.github.klee0kai.test.mowgli.earth.Mountain diff --git a/tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/gc/EarthLastDayAndProTests.kt b/tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/gc/EarthLastDayAndProTests.kt index 4262cc4f..4f55a343 100644 --- a/tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/gc/EarthLastDayAndProTests.kt +++ b/tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/gc/EarthLastDayAndProTests.kt @@ -1,424 +1,420 @@ -package com.dirgub.klee0kai.stone.text_ext.gc; - -import com.github.klee0kai.stone.Stone; -import com.github.klee0kai.test.di.gcforest.GcGodComponent; -import com.github.klee0kai.test.mowgli.earth.Mountain; -import com.github.klee0kai.test.mowgli.earth.River; -import com.github.klee0kai.test_ext.inject.di.gcforest.GcGodExtComponent; -import com.github.klee0kai.test_ext.inject.mowgli.earth.Desert; -import com.github.klee0kai.test_ext.inject.mowgli.earth.WaterFlow; -import org.junit.jupiter.api.Test; - -import java.lang.ref.Reference; -import java.lang.ref.WeakReference; -import java.util.Arrays; - -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertNull; - -public class EarthLastDayAndProTests { +package com.dirgub.klee0kai.stone.text_ext.gc + +import com.github.klee0kai.test.di.gcforest.GcGodComponent +import com.github.klee0kai.test.di.gcforest.GcGodComponentStoneComponent +import com.github.klee0kai.test.mowgli.earth.Mountain +import com.github.klee0kai.test.mowgli.earth.River +import com.github.klee0kai.test_ext.inject.di.gcforest.GcGodExtComponent +import com.github.klee0kai.test_ext.inject.di.gcforest.GcGodExtComponentStoneComponent +import com.github.klee0kai.test_ext.inject.mowgli.earth.Desert +import com.github.klee0kai.test_ext.inject.mowgli.earth.WaterFlow +import org.junit.jupiter.api.Test +import org.junit.jupiter.api.assertNotNull +import org.junit.jupiter.api.assertNull +import java.lang.ref.WeakReference + +class EarthLastDayAndProTests { @Test - void gcAllTest() { + fun gcAllTest() { //Given - GcGodComponent DI = Stone.createComponent(GcGodComponent.class); - WeakReference mountainStrong = new WeakReference<>(DI.earth().mountainStrong()); - WeakReference mountainSoft = new WeakReference<>(DI.earth().mountainSoft()); - WeakReference mountainWeak = new WeakReference<>(DI.earth().mountainWeak()); - WeakReference mountainDef = new WeakReference<>(DI.earth().mountainDefaultFactory()); - WeakReference mountainDef2 = new WeakReference<>(DI.earth().mountainDefault2Factory()); - WeakReference riverStrong = new WeakReference<>(DI.earth().riverStrong()); - WeakReference riverSoft = new WeakReference<>(DI.earth().riverSoft()); - WeakReference riverWeak = new WeakReference<>(DI.earth().riverWeak()); - WeakReference riverDef = new WeakReference<>(DI.earth().riverDefaultSoft()); - GcGodExtComponent DIPro = Stone.createComponent(GcGodExtComponent.class); - DIPro.extOf(DI); - WeakReference desertStrong = new WeakReference<>(DIPro.earth().desertStrong()); - WeakReference desertSoft = new WeakReference<>(DIPro.earth().desertSoft()); - WeakReference desertWeak = new WeakReference<>(DIPro.earth().desertWeak()); - WeakReference desertFactory = new WeakReference<>(DIPro.earth().desertFactory()); - WeakReference waterFlowStrong = new WeakReference<>(DIPro.earth().riverStrong()); - WeakReference waterFlowSoft = new WeakReference<>(DIPro.earth().riverSoft()); - WeakReference waterFlowWeak = new WeakReference<>(DIPro.earth().riverWeak()); - WeakReference waterFlowDefRef = new WeakReference<>(DIPro.earth().riverDefaultSoft()); - + val DI: GcGodComponent = GcGodComponentStoneComponent() + val mountainStrong = WeakReference(DI.earth()?.mountainStrong()) + val mountainSoft = WeakReference(DI.earth()!!.mountainSoft()) + val mountainWeak = WeakReference(DI.earth()!!.mountainWeak()) + val mountainDef = WeakReference(DI.earth()!!.mountainDefaultFactory()) + val mountainDef2 = WeakReference(DI.earth()!!.mountainDefault2Factory()) + val riverStrong = WeakReference(DI.earth()!!.riverStrong()) + val riverSoft = WeakReference(DI.earth()!!.riverSoft()) + val riverWeak = WeakReference(DI.earth()!!.riverWeak()) + val riverDef = WeakReference(DI.earth()!!.riverDefaultSoft()) + val DIPro: GcGodExtComponent = GcGodExtComponentStoneComponent() + DIPro.extOf(DI) + val desertStrong = WeakReference(DIPro.earth()!!.desertStrong()) + val desertSoft = WeakReference(DIPro.earth()!!.desertSoft()) + val desertWeak = WeakReference(DIPro.earth()!!.desertWeak()) + val desertFactory = WeakReference(DIPro.earth()!!.desertFactory()) + val waterFlowStrong = WeakReference(DIPro.earth()!!.riverStrong()) + val waterFlowSoft = WeakReference(DIPro.earth()!!.riverSoft()) + val waterFlowWeak = WeakReference(DIPro.earth()!!.riverWeak()) + val waterFlowDefRef = WeakReference(DIPro.earth()!!.riverDefaultSoft()) //When - DI.gcAll(); + DI.gcAll() //Then - for (Reference ref : Arrays.asList( - mountainStrong, mountainSoft, mountainDef2, mountainWeak, mountainDef, - riverStrong, riverSoft, riverWeak, riverDef, - desertStrong, desertSoft, desertWeak, desertFactory, - waterFlowStrong, waterFlowSoft, waterFlowWeak, waterFlowDefRef + for (ref in listOf( + mountainStrong, mountainSoft, mountainDef2, mountainWeak, mountainDef, + riverStrong, riverSoft, riverWeak, riverDef, + desertStrong, desertSoft, desertWeak, desertFactory, + waterFlowStrong, waterFlowSoft, waterFlowWeak, waterFlowDefRef )) { - assertNull(ref.get()); + assertNull(ref.get()) } } @Test - void gcStrongTest() { + fun gcStrongTest() { //Given - GcGodComponent DI = Stone.createComponent(GcGodComponent.class); - WeakReference mountainStrong = new WeakReference<>(DI.earth().mountainStrong()); - WeakReference mountainSoft = new WeakReference<>(DI.earth().mountainSoft()); - WeakReference mountainWeak = new WeakReference<>(DI.earth().mountainWeak()); - WeakReference mountainDef = new WeakReference<>(DI.earth().mountainDefaultFactory()); - WeakReference mountainDef2 = new WeakReference<>(DI.earth().mountainDefault2Factory()); - WeakReference riverStrong = new WeakReference<>(DI.earth().riverStrong()); - WeakReference riverSoft = new WeakReference<>(DI.earth().riverSoft()); - WeakReference riverWeak = new WeakReference<>(DI.earth().riverWeak()); - WeakReference riverDef = new WeakReference<>(DI.earth().riverDefaultSoft()); - GcGodExtComponent DIPro = Stone.createComponent(GcGodExtComponent.class); - DIPro.extOf(DI); - WeakReference desertStrong = new WeakReference<>(DIPro.earth().desertStrong()); - WeakReference desertSoft = new WeakReference<>(DIPro.earth().desertSoft()); - WeakReference desertWeak = new WeakReference<>(DIPro.earth().desertWeak()); - WeakReference desertFactory = new WeakReference<>(DIPro.earth().desertFactory()); - WeakReference waterFlowStrong = new WeakReference<>(DIPro.earth().riverStrong()); - WeakReference waterFlowSoft = new WeakReference<>(DIPro.earth().riverSoft()); - WeakReference waterFlowWeak = new WeakReference<>(DIPro.earth().riverWeak()); - WeakReference waterFlowDefRef = new WeakReference<>(DIPro.earth().riverDefaultSoft()); + val DI: GcGodComponent = GcGodComponentStoneComponent() + val mountainStrong = WeakReference(DI.earth()?.mountainStrong()) + val mountainSoft = WeakReference(DI.earth()!!.mountainSoft()) + val mountainWeak = WeakReference(DI.earth()!!.mountainWeak()) + val mountainDef = WeakReference(DI.earth()!!.mountainDefaultFactory()) + val mountainDef2 = WeakReference(DI.earth()!!.mountainDefault2Factory()) + val riverStrong = WeakReference(DI.earth()!!.riverStrong()) + val riverSoft = WeakReference(DI.earth()!!.riverSoft()) + val riverWeak = WeakReference(DI.earth()!!.riverWeak()) + val riverDef = WeakReference(DI.earth()!!.riverDefaultSoft()) + val DIPro: GcGodExtComponent = GcGodExtComponentStoneComponent() + DIPro.extOf(DI) + val desertStrong = WeakReference(DIPro.earth()!!.desertStrong()) + val desertSoft = WeakReference(DIPro.earth()!!.desertSoft()) + val desertWeak = WeakReference(DIPro.earth()!!.desertWeak()) + val desertFactory = WeakReference(DIPro.earth()!!.desertFactory()) + val waterFlowStrong = WeakReference(DIPro.earth()!!.riverStrong()) + val waterFlowSoft = WeakReference(DIPro.earth()!!.riverSoft()) + val waterFlowWeak = WeakReference(DIPro.earth()!!.riverWeak()) + val waterFlowDefRef = WeakReference(DIPro.earth()!!.riverDefaultSoft()) //When - DI.gcStrong(); + DI.gcStrong() //Then - for (Reference ref : Arrays.asList( - mountainStrong, mountainWeak, mountainDef, mountainDef2, - riverStrong, riverWeak, riverDef, - desertStrong, desertWeak, desertFactory, - waterFlowStrong, waterFlowWeak, waterFlowDefRef + for (ref in listOf( + mountainStrong, mountainWeak, mountainDef, mountainDef2, + riverStrong, riverWeak, riverDef, + desertStrong, desertWeak, desertFactory, + waterFlowStrong, waterFlowWeak, waterFlowDefRef )) { - assertNull(ref.get()); + assertNull(ref.get()) } - for (Reference ref : Arrays.asList( - mountainSoft, - riverSoft, - desertSoft, - waterFlowSoft + for (ref in listOf( + mountainSoft, + riverSoft, + desertSoft, + waterFlowSoft )) { - assertNotNull(ref.get()); + assertNotNull(ref.get()) } } @Test - void gcSoftTest() { + fun gcSoftTest() { //Given - GcGodComponent DI = Stone.createComponent(GcGodComponent.class); - WeakReference mountainStrong = new WeakReference<>(DI.earth().mountainStrong()); - WeakReference mountainSoft = new WeakReference<>(DI.earth().mountainSoft()); - WeakReference mountainWeak = new WeakReference<>(DI.earth().mountainWeak()); - WeakReference mountainDef = new WeakReference<>(DI.earth().mountainDefaultFactory()); - WeakReference mountainDef2 = new WeakReference<>(DI.earth().mountainDefault2Factory()); - WeakReference riverStrong = new WeakReference<>(DI.earth().riverStrong()); - WeakReference riverSoft = new WeakReference<>(DI.earth().riverSoft()); - WeakReference riverWeak = new WeakReference<>(DI.earth().riverWeak()); - WeakReference riverDef = new WeakReference<>(DI.earth().riverDefaultSoft()); - GcGodExtComponent DIPro = Stone.createComponent(GcGodExtComponent.class); - DIPro.extOf(DI); - WeakReference desertStrong = new WeakReference<>(DIPro.earth().desertStrong()); - WeakReference desertSoft = new WeakReference<>(DIPro.earth().desertSoft()); - WeakReference desertWeak = new WeakReference<>(DIPro.earth().desertWeak()); - WeakReference desertFactory = new WeakReference<>(DIPro.earth().desertFactory()); - WeakReference waterFlowStrong = new WeakReference<>(DIPro.earth().riverStrong()); - WeakReference waterFlowSoft = new WeakReference<>(DIPro.earth().riverSoft()); - WeakReference waterFlowWeak = new WeakReference<>(DIPro.earth().riverWeak()); - WeakReference waterFlowDefRef = new WeakReference<>(DIPro.earth().riverDefaultSoft()); + val DI: GcGodComponent = GcGodComponentStoneComponent() + val mountainStrong = WeakReference(DI.earth()?.mountainStrong()) + val mountainSoft = WeakReference(DI.earth()!!.mountainSoft()) + val mountainWeak = WeakReference(DI.earth()!!.mountainWeak()) + val mountainDef = WeakReference(DI.earth()!!.mountainDefaultFactory()) + val mountainDef2 = WeakReference(DI.earth()!!.mountainDefault2Factory()) + val riverStrong = WeakReference(DI.earth()!!.riverStrong()) + val riverSoft = WeakReference(DI.earth()!!.riverSoft()) + val riverWeak = WeakReference(DI.earth()!!.riverWeak()) + val riverDef = WeakReference(DI.earth()!!.riverDefaultSoft()) + val DIPro: GcGodExtComponent = GcGodExtComponentStoneComponent() + DIPro.extOf(DI) + val desertStrong = WeakReference(DIPro.earth()!!.desertStrong()) + val desertSoft = WeakReference(DIPro.earth()!!.desertSoft()) + val desertWeak = WeakReference(DIPro.earth()!!.desertWeak()) + val desertFactory = WeakReference(DIPro.earth()!!.desertFactory()) + val waterFlowStrong = WeakReference(DIPro.earth()!!.riverStrong()) + val waterFlowSoft = WeakReference(DIPro.earth()!!.riverSoft()) + val waterFlowWeak = WeakReference(DIPro.earth()!!.riverWeak()) + val waterFlowDefRef = WeakReference(DIPro.earth()!!.riverDefaultSoft()) //When - DI.gcSoft(); + DI.gcSoft() //Then - for (Reference ref : Arrays.asList( - mountainSoft, mountainWeak, mountainDef, mountainDef2, - riverSoft, riverWeak, riverDef, - desertSoft, desertWeak, desertFactory, - waterFlowSoft, waterFlowDefRef, waterFlowWeak + for (ref in listOf( + mountainSoft, mountainWeak, mountainDef, mountainDef2, + riverSoft, riverWeak, riverDef, + desertSoft, desertWeak, desertFactory, + waterFlowSoft, waterFlowDefRef, waterFlowWeak )) { - assertNull(ref.get()); + assertNull(ref.get()) } - for (Reference ref : Arrays.asList( - mountainStrong, - riverStrong, - desertStrong, - waterFlowStrong + for (ref in listOf( + mountainStrong, + riverStrong, + desertStrong, + waterFlowStrong )) { - assertNotNull(ref.get()); + assertNotNull(ref.get()) } } @Test - void gcWeakTest() { + fun gcWeakTest() { //Given - GcGodComponent DI = Stone.createComponent(GcGodComponent.class); - WeakReference mountainStrong = new WeakReference<>(DI.earth().mountainStrong()); - WeakReference mountainSoft = new WeakReference<>(DI.earth().mountainSoft()); - WeakReference mountainWeak = new WeakReference<>(DI.earth().mountainWeak()); - WeakReference mountainDef = new WeakReference<>(DI.earth().mountainDefaultFactory()); - WeakReference mountainDef2 = new WeakReference<>(DI.earth().mountainDefault2Factory()); - WeakReference riverStrong = new WeakReference<>(DI.earth().riverStrong()); - WeakReference riverSoft = new WeakReference<>(DI.earth().riverSoft()); - WeakReference riverWeak = new WeakReference<>(DI.earth().riverWeak()); - WeakReference riverDef = new WeakReference<>(DI.earth().riverDefaultSoft()); - GcGodExtComponent DIPro = Stone.createComponent(GcGodExtComponent.class); - DIPro.extOf(DI); - WeakReference desertStrong = new WeakReference<>(DIPro.earth().desertStrong()); - WeakReference desertSoft = new WeakReference<>(DIPro.earth().desertSoft()); - WeakReference desertWeak = new WeakReference<>(DIPro.earth().desertWeak()); - WeakReference desertFactory = new WeakReference<>(DIPro.earth().desertFactory()); - WeakReference waterFlowStrong = new WeakReference<>(DIPro.earth().riverStrong()); - WeakReference waterFlowSoft = new WeakReference<>(DIPro.earth().riverSoft()); - WeakReference waterFlowWeak = new WeakReference<>(DIPro.earth().riverWeak()); - WeakReference waterFlowDefRef = new WeakReference<>(DIPro.earth().riverDefaultSoft()); + val DI: GcGodComponent = GcGodComponentStoneComponent() + val mountainStrong = WeakReference(DI.earth()?.mountainStrong()) + val mountainSoft = WeakReference(DI.earth()!!.mountainSoft()) + val mountainWeak = WeakReference(DI.earth()!!.mountainWeak()) + val mountainDef = WeakReference(DI.earth()!!.mountainDefaultFactory()) + val mountainDef2 = WeakReference(DI.earth()!!.mountainDefault2Factory()) + val riverStrong = WeakReference(DI.earth()!!.riverStrong()) + val riverSoft = WeakReference(DI.earth()!!.riverSoft()) + val riverWeak = WeakReference(DI.earth()!!.riverWeak()) + val riverDef = WeakReference(DI.earth()!!.riverDefaultSoft()) + val DIPro: GcGodExtComponent = GcGodExtComponentStoneComponent() + DIPro.extOf(DI) + val desertStrong = WeakReference(DIPro.earth()!!.desertStrong()) + val desertSoft = WeakReference(DIPro.earth()!!.desertSoft()) + val desertWeak = WeakReference(DIPro.earth()!!.desertWeak()) + val desertFactory = WeakReference(DIPro.earth()!!.desertFactory()) + val waterFlowStrong = WeakReference(DIPro.earth()!!.riverStrong()) + val waterFlowSoft = WeakReference(DIPro.earth()!!.riverSoft()) + val waterFlowWeak = WeakReference(DIPro.earth()!!.riverWeak()) + val waterFlowDefRef = WeakReference(DIPro.earth()!!.riverDefaultSoft()) //When - DI.gcWeak(); + DI.gcWeak() //Then - for (Reference ref : Arrays.asList( - mountainWeak, mountainDef, mountainDef2, - riverWeak, riverDef, - desertWeak, desertFactory, - waterFlowWeak, waterFlowDefRef + for (ref in listOf( + mountainWeak, mountainDef, mountainDef2, + riverWeak, riverDef, + desertWeak, desertFactory, + waterFlowWeak, waterFlowDefRef )) { - assertNull(ref.get()); + assertNull(ref.get()) } - for (Reference ref : Arrays.asList( - mountainStrong, mountainSoft, - riverStrong, riverSoft, - desertStrong, desertSoft, - waterFlowStrong, waterFlowSoft + for (ref in listOf( + mountainStrong, mountainSoft, + riverStrong, riverSoft, + desertStrong, desertSoft, + waterFlowStrong, waterFlowSoft )) { - assertNotNull(ref.get()); + assertNotNull(ref.get()) } } @Test - void gcMountainTest() { + fun gcMountainTest() { //Given - GcGodComponent DI = Stone.createComponent(GcGodComponent.class); - WeakReference mountainStrong = new WeakReference<>(DI.earth().mountainStrong()); - WeakReference mountainSoft = new WeakReference<>(DI.earth().mountainSoft()); - WeakReference mountainWeak = new WeakReference<>(DI.earth().mountainWeak()); - WeakReference mountainDef = new WeakReference<>(DI.earth().mountainDefaultFactory()); - WeakReference mountainDef2 = new WeakReference<>(DI.earth().mountainDefault2Factory()); - WeakReference riverStrong = new WeakReference<>(DI.earth().riverStrong()); - WeakReference riverSoft = new WeakReference<>(DI.earth().riverSoft()); - WeakReference riverWeak = new WeakReference<>(DI.earth().riverWeak()); - WeakReference riverDef = new WeakReference<>(DI.earth().riverDefaultSoft()); - GcGodExtComponent DIPro = Stone.createComponent(GcGodExtComponent.class); - DIPro.extOf(DI); - WeakReference desertStrong = new WeakReference<>(DIPro.earth().desertStrong()); - WeakReference desertSoft = new WeakReference<>(DIPro.earth().desertSoft()); - WeakReference desertWeak = new WeakReference<>(DIPro.earth().desertWeak()); - WeakReference desertFactory = new WeakReference<>(DIPro.earth().desertFactory()); - WeakReference waterFlowStrong = new WeakReference<>(DIPro.earth().riverStrong()); - WeakReference waterFlowSoft = new WeakReference<>(DIPro.earth().riverSoft()); - WeakReference waterFlowWeak = new WeakReference<>(DIPro.earth().riverWeak()); - WeakReference waterFlowDefRef = new WeakReference<>(DIPro.earth().riverDefaultSoft()); + val DI: GcGodComponent = GcGodComponentStoneComponent() + val mountainStrong = WeakReference(DI.earth()?.mountainStrong()) + val mountainSoft = WeakReference(DI.earth()!!.mountainSoft()) + val mountainWeak = WeakReference(DI.earth()!!.mountainWeak()) + val mountainDef = WeakReference(DI.earth()!!.mountainDefaultFactory()) + val mountainDef2 = WeakReference(DI.earth()!!.mountainDefault2Factory()) + val riverStrong = WeakReference(DI.earth()!!.riverStrong()) + val riverSoft = WeakReference(DI.earth()!!.riverSoft()) + val riverWeak = WeakReference(DI.earth()!!.riverWeak()) + val riverDef = WeakReference(DI.earth()!!.riverDefaultSoft()) + val DIPro: GcGodExtComponent = GcGodExtComponentStoneComponent() + DIPro.extOf(DI) + val desertStrong = WeakReference(DIPro.earth()!!.desertStrong()) + val desertSoft = WeakReference(DIPro.earth()!!.desertSoft()) + val desertWeak = WeakReference(DIPro.earth()!!.desertWeak()) + val desertFactory = WeakReference(DIPro.earth()!!.desertFactory()) + val waterFlowStrong = WeakReference(DIPro.earth()!!.riverStrong()) + val waterFlowSoft = WeakReference(DIPro.earth()!!.riverSoft()) + val waterFlowWeak = WeakReference(DIPro.earth()!!.riverWeak()) + val waterFlowDefRef = WeakReference(DIPro.earth()!!.riverDefaultSoft()) //When - DI.gcMountains(); + DI.gcMountains() //Then - for (Reference ref : Arrays.asList( - mountainStrong, mountainSoft, mountainWeak, mountainDef, mountainDef2, - riverWeak, riverDef, - desertWeak, desertFactory, - waterFlowWeak, waterFlowDefRef + for (ref in listOf( + mountainStrong, mountainSoft, mountainWeak, mountainDef, mountainDef2, + riverWeak, riverDef, + desertWeak, desertFactory, + waterFlowWeak, waterFlowDefRef )) { - assertNull(ref.get()); + assertNull(ref.get()) } - for (Reference ref : Arrays.asList( - riverStrong, riverSoft, - desertStrong, desertSoft, - waterFlowStrong, waterFlowSoft + for (ref in listOf( + riverStrong, riverSoft, + desertStrong, desertSoft, + waterFlowStrong, waterFlowSoft )) { - assertNotNull(ref.get()); + assertNotNull(ref.get()) } } - @Test - void gcRiverTest() { + @org.junit.jupiter.api.Test + fun gcRiverTest() { //Given - GcGodComponent DI = Stone.createComponent(GcGodComponent.class); - WeakReference mountainStrong = new WeakReference<>(DI.earth().mountainStrong()); - WeakReference mountainSoft = new WeakReference<>(DI.earth().mountainSoft()); - WeakReference mountainWeak = new WeakReference<>(DI.earth().mountainWeak()); - WeakReference mountainDef = new WeakReference<>(DI.earth().mountainDefaultFactory()); - WeakReference mountainDef2 = new WeakReference<>(DI.earth().mountainDefault2Factory()); - WeakReference riverStrong = new WeakReference<>(DI.earth().riverStrong()); - WeakReference riverSoft = new WeakReference<>(DI.earth().riverSoft()); - WeakReference riverWeak = new WeakReference<>(DI.earth().riverWeak()); - WeakReference riverDef = new WeakReference<>(DI.earth().riverDefaultSoft()); - GcGodExtComponent DIPro = Stone.createComponent(GcGodExtComponent.class); - DIPro.extOf(DI); - WeakReference desertStrong = new WeakReference<>(DIPro.earth().desertStrong()); - WeakReference desertSoft = new WeakReference<>(DIPro.earth().desertSoft()); - WeakReference desertWeak = new WeakReference<>(DIPro.earth().desertWeak()); - WeakReference desertFactory = new WeakReference<>(DIPro.earth().desertFactory()); - WeakReference waterFlowStrong = new WeakReference<>(DIPro.earth().riverStrong()); - WeakReference waterFlowSoft = new WeakReference<>(DIPro.earth().riverSoft()); - WeakReference waterFlowWeak = new WeakReference<>(DIPro.earth().riverWeak()); - WeakReference waterFlowDefRef = new WeakReference<>(DIPro.earth().riverDefaultSoft()); + val DI: GcGodComponent = GcGodComponentStoneComponent() + val mountainStrong = WeakReference(DI.earth()?.mountainStrong()) + val mountainSoft = WeakReference(DI.earth()!!.mountainSoft()) + val mountainWeak = WeakReference(DI.earth()!!.mountainWeak()) + val mountainDef = WeakReference(DI.earth()!!.mountainDefaultFactory()) + val mountainDef2 = WeakReference(DI.earth()!!.mountainDefault2Factory()) + val riverStrong = WeakReference(DI.earth()!!.riverStrong()) + val riverSoft = WeakReference(DI.earth()!!.riverSoft()) + val riverWeak = WeakReference(DI.earth()!!.riverWeak()) + val riverDef = WeakReference(DI.earth()!!.riverDefaultSoft()) + val DIPro: GcGodExtComponent = GcGodExtComponentStoneComponent() + DIPro.extOf(DI) + val desertStrong = WeakReference(DIPro.earth()!!.desertStrong()) + val desertSoft = WeakReference(DIPro.earth()!!.desertSoft()) + val desertWeak = WeakReference(DIPro.earth()!!.desertWeak()) + val desertFactory = WeakReference(DIPro.earth()!!.desertFactory()) + val waterFlowStrong = WeakReference(DIPro.earth()!!.riverStrong()) + val waterFlowSoft = WeakReference(DIPro.earth()!!.riverSoft()) + val waterFlowWeak = WeakReference(DIPro.earth()!!.riverWeak()) + val waterFlowDefRef = WeakReference(DIPro.earth()!!.riverDefaultSoft()) //When - DI.gcRivers(); + DI.gcRivers() //Then - for (Reference ref : Arrays.asList( - mountainWeak, mountainDef, mountainDef2, - riverStrong, riverSoft, riverWeak, riverDef, - desertWeak, desertFactory, - waterFlowStrong, waterFlowSoft, waterFlowDefRef, waterFlowWeak + for (ref in listOf( + mountainWeak, mountainDef, mountainDef2, + riverStrong, riverSoft, riverWeak, riverDef, + desertWeak, desertFactory, + waterFlowStrong, waterFlowSoft, waterFlowDefRef, waterFlowWeak )) { - assertNull(ref.get()); + assertNull(ref.get()) } - for (Reference ref : Arrays.asList( - mountainStrong, mountainSoft, - desertStrong, desertSoft + for (ref in listOf( + mountainStrong, mountainSoft, + desertStrong, desertSoft )) { - assertNotNull(ref.get()); + assertNotNull(ref.get()) } } @Test - void gcMountainAndRiverTest() { + fun gcMountainAndRiverTest() { //Given - GcGodComponent DI = Stone.createComponent(GcGodComponent.class); - WeakReference mountainStrong = new WeakReference<>(DI.earth().mountainStrong()); - WeakReference mountainSoft = new WeakReference<>(DI.earth().mountainSoft()); - WeakReference mountainWeak = new WeakReference<>(DI.earth().mountainWeak()); - WeakReference mountainDef = new WeakReference<>(DI.earth().mountainDefaultFactory()); - WeakReference mountainDef2 = new WeakReference<>(DI.earth().mountainDefault2Factory()); - WeakReference riverStrong = new WeakReference<>(DI.earth().riverStrong()); - WeakReference riverSoft = new WeakReference<>(DI.earth().riverSoft()); - WeakReference riverWeak = new WeakReference<>(DI.earth().riverWeak()); - WeakReference riverDef = new WeakReference<>(DI.earth().riverDefaultSoft()); - GcGodExtComponent DIPro = Stone.createComponent(GcGodExtComponent.class); - DIPro.extOf(DI); - WeakReference desertStrong = new WeakReference<>(DIPro.earth().desertStrong()); - WeakReference desertSoft = new WeakReference<>(DIPro.earth().desertSoft()); - WeakReference desertWeak = new WeakReference<>(DIPro.earth().desertWeak()); - WeakReference desertFactory = new WeakReference<>(DIPro.earth().desertFactory()); - WeakReference waterFlowStrong = new WeakReference<>(DIPro.earth().riverStrong()); - WeakReference waterFlowSoft = new WeakReference<>(DIPro.earth().riverSoft()); - WeakReference waterFlowWeak = new WeakReference<>(DIPro.earth().riverWeak()); - WeakReference waterFlowDefRef = new WeakReference<>(DIPro.earth().riverDefaultSoft()); + val DI: GcGodComponent = GcGodComponentStoneComponent() + val mountainStrong = WeakReference(DI.earth()?.mountainStrong()) + val mountainSoft = WeakReference(DI.earth()!!.mountainSoft()) + val mountainWeak = WeakReference(DI.earth()!!.mountainWeak()) + val mountainDef = WeakReference(DI.earth()!!.mountainDefaultFactory()) + val mountainDef2 = WeakReference(DI.earth()!!.mountainDefault2Factory()) + val riverStrong = WeakReference(DI.earth()!!.riverStrong()) + val riverSoft = WeakReference(DI.earth()!!.riverSoft()) + val riverWeak = WeakReference(DI.earth()!!.riverWeak()) + val riverDef = WeakReference(DI.earth()!!.riverDefaultSoft()) + val DIPro: GcGodExtComponent = GcGodExtComponentStoneComponent() + DIPro.extOf(DI) + val desertStrong = WeakReference(DIPro.earth()!!.desertStrong()) + val desertSoft = WeakReference(DIPro.earth()!!.desertSoft()) + val desertWeak = WeakReference(DIPro.earth()!!.desertWeak()) + val desertFactory = WeakReference(DIPro.earth()!!.desertFactory()) + val waterFlowStrong = WeakReference(DIPro.earth()!!.riverStrong()) + val waterFlowSoft = WeakReference(DIPro.earth()!!.riverSoft()) + val waterFlowWeak = WeakReference(DIPro.earth()!!.riverWeak()) + val waterFlowDefRef = WeakReference(DIPro.earth()!!.riverDefaultSoft()) //When - DI.gcMountainsAndRivers(); + DI.gcMountainsAndRivers() //Then - for (Reference ref : Arrays.asList( - mountainStrong, mountainSoft, mountainWeak, mountainDef, mountainDef2, - riverStrong, riverSoft, riverWeak, riverDef, - desertFactory, desertWeak, - waterFlowStrong, waterFlowSoft, waterFlowDefRef, waterFlowWeak + for (ref in listOf( + mountainStrong, mountainSoft, mountainWeak, mountainDef, mountainDef2, + riverStrong, riverSoft, riverWeak, riverDef, + desertFactory, desertWeak, + waterFlowStrong, waterFlowSoft, waterFlowDefRef, waterFlowWeak )) { - assertNull(ref.get()); + assertNull(ref.get()) } - for (Reference ref : Arrays.asList( - desertStrong, desertSoft + for (ref in listOf( + desertStrong, desertSoft )) { - assertNotNull(ref.get()); + assertNotNull(ref.get()) } } @Test - void gcSoftMountainTest() { + fun gcSoftMountainTest() { //Given - GcGodComponent DI = Stone.createComponent(GcGodComponent.class); - WeakReference mountainStrong = new WeakReference<>(DI.earth().mountainStrong()); - WeakReference mountainSoft = new WeakReference<>(DI.earth().mountainSoft()); - WeakReference mountainWeak = new WeakReference<>(DI.earth().mountainWeak()); - WeakReference mountainDef = new WeakReference<>(DI.earth().mountainDefaultFactory()); - WeakReference mountainDef2 = new WeakReference<>(DI.earth().mountainDefault2Factory()); - WeakReference riverStrong = new WeakReference<>(DI.earth().riverStrong()); - WeakReference riverSoft = new WeakReference<>(DI.earth().riverSoft()); - WeakReference riverWeak = new WeakReference<>(DI.earth().riverWeak()); - WeakReference riverDef = new WeakReference<>(DI.earth().riverDefaultSoft()); - GcGodExtComponent DIPro = Stone.createComponent(GcGodExtComponent.class); - DIPro.extOf(DI); - WeakReference desertStrong = new WeakReference<>(DIPro.earth().desertStrong()); - WeakReference desertSoft = new WeakReference<>(DIPro.earth().desertSoft()); - WeakReference desertWeak = new WeakReference<>(DIPro.earth().desertWeak()); - WeakReference desertFactory = new WeakReference<>(DIPro.earth().desertFactory()); - WeakReference waterFlowStrong = new WeakReference<>(DIPro.earth().riverStrong()); - WeakReference waterFlowSoft = new WeakReference<>(DIPro.earth().riverSoft()); - WeakReference waterFlowWeak = new WeakReference<>(DIPro.earth().riverWeak()); - WeakReference waterFlowDefRef = new WeakReference<>(DIPro.earth().riverDefaultSoft()); + val DI: GcGodComponent = GcGodComponentStoneComponent() + val mountainStrong = WeakReference(DI.earth()?.mountainStrong()) + val mountainSoft = WeakReference(DI.earth()!!.mountainSoft()) + val mountainWeak = WeakReference(DI.earth()!!.mountainWeak()) + val mountainDef = WeakReference(DI.earth()!!.mountainDefaultFactory()) + val mountainDef2 = WeakReference(DI.earth()!!.mountainDefault2Factory()) + val riverStrong = WeakReference(DI.earth()!!.riverStrong()) + val riverSoft = WeakReference(DI.earth()!!.riverSoft()) + val riverWeak = WeakReference(DI.earth()!!.riverWeak()) + val riverDef = WeakReference(DI.earth()!!.riverDefaultSoft()) + val DIPro: GcGodExtComponent = GcGodExtComponentStoneComponent() + DIPro.extOf(DI) + val desertStrong = WeakReference(DIPro.earth()!!.desertStrong()) + val desertSoft = WeakReference(DIPro.earth()!!.desertSoft()) + val desertWeak = WeakReference(DIPro.earth()!!.desertWeak()) + val desertFactory = WeakReference(DIPro.earth()!!.desertFactory()) + val waterFlowStrong = WeakReference(DIPro.earth()!!.riverStrong()) + val waterFlowSoft = WeakReference(DIPro.earth()!!.riverSoft()) + val waterFlowWeak = WeakReference(DIPro.earth()!!.riverWeak()) + val waterFlowDefRef = WeakReference(DIPro.earth()!!.riverDefaultSoft()) //When - DI.gcSoftMountains(); + DI.gcSoftMountains() //Then - for (Reference ref : Arrays.asList( - mountainSoft, mountainWeak, mountainDef, mountainDef2, - riverWeak, riverDef, - desertFactory, desertWeak, - waterFlowWeak, waterFlowDefRef + for (ref in listOf( + mountainSoft, mountainWeak, mountainDef, mountainDef2, + riverWeak, riverDef, + desertFactory, desertWeak, + waterFlowWeak, waterFlowDefRef )) { - assertNull(ref.get()); + assertNull(ref.get()) } - for (Reference ref : Arrays.asList( - mountainStrong, - riverStrong, riverSoft, - desertStrong, desertSoft, - waterFlowStrong, waterFlowSoft + for (ref in listOf( + mountainStrong, + riverStrong, riverSoft, + desertStrong, desertSoft, + waterFlowStrong, waterFlowSoft )) { - assertNotNull(ref.get()); + assertNotNull(ref.get()) } } @Test - void gcStrongMountainTest() { + fun gcStrongMountainTest() { //Given - GcGodComponent DI = Stone.createComponent(GcGodComponent.class); - WeakReference mountainStrong = new WeakReference<>(DI.earth().mountainStrong()); - WeakReference mountainSoft = new WeakReference<>(DI.earth().mountainSoft()); - WeakReference mountainWeak = new WeakReference<>(DI.earth().mountainWeak()); - WeakReference mountainDef = new WeakReference<>(DI.earth().mountainDefaultFactory()); - WeakReference mountainDef2 = new WeakReference<>(DI.earth().mountainDefault2Factory()); - WeakReference riverStrong = new WeakReference<>(DI.earth().riverStrong()); - WeakReference riverSoft = new WeakReference<>(DI.earth().riverSoft()); - WeakReference riverWeak = new WeakReference<>(DI.earth().riverWeak()); - WeakReference riverDef = new WeakReference<>(DI.earth().riverDefaultSoft()); - GcGodExtComponent DIPro = Stone.createComponent(GcGodExtComponent.class); - DIPro.extOf(DI); - WeakReference desertStrong = new WeakReference<>(DIPro.earth().desertStrong()); - WeakReference desertSoft = new WeakReference<>(DIPro.earth().desertSoft()); - WeakReference desertWeak = new WeakReference<>(DIPro.earth().desertWeak()); - WeakReference desertFactory = new WeakReference<>(DIPro.earth().desertFactory()); - WeakReference waterFlowStrong = new WeakReference<>(DIPro.earth().riverStrong()); - WeakReference waterFlowSoft = new WeakReference<>(DIPro.earth().riverSoft()); - WeakReference waterFlowWeak = new WeakReference<>(DIPro.earth().riverWeak()); - WeakReference waterFlowDefRef = new WeakReference<>(DIPro.earth().riverDefaultSoft()); + val DI: GcGodComponent = GcGodComponentStoneComponent() + val mountainStrong = WeakReference(DI.earth()?.mountainStrong()) + val mountainSoft = WeakReference(DI.earth()!!.mountainSoft()) + val mountainWeak = WeakReference(DI.earth()!!.mountainWeak()) + val mountainDef = WeakReference(DI.earth()!!.mountainDefaultFactory()) + val mountainDef2 = WeakReference(DI.earth()!!.mountainDefault2Factory()) + val riverStrong = WeakReference(DI.earth()!!.riverStrong()) + val riverSoft = WeakReference(DI.earth()!!.riverSoft()) + val riverWeak = WeakReference(DI.earth()!!.riverWeak()) + val riverDef = WeakReference(DI.earth()!!.riverDefaultSoft()) + val DIPro: GcGodExtComponent = GcGodExtComponentStoneComponent() + DIPro.extOf(DI) + val desertStrong = WeakReference(DIPro.earth()!!.desertStrong()) + val desertSoft = WeakReference(DIPro.earth()!!.desertSoft()) + val desertWeak = WeakReference(DIPro.earth()!!.desertWeak()) + val desertFactory = WeakReference(DIPro.earth()!!.desertFactory()) + val waterFlowStrong = WeakReference(DIPro.earth()!!.riverStrong()) + val waterFlowSoft = WeakReference(DIPro.earth()!!.riverSoft()) + val waterFlowWeak = WeakReference(DIPro.earth()!!.riverWeak()) + val waterFlowDefRef = WeakReference(DIPro.earth()!!.riverDefaultSoft()) //When - DI.gcStrongMountains(); + DI.gcStrongMountains() //Then - for (Reference ref : Arrays.asList( - mountainStrong, mountainWeak, mountainDef, mountainDef2, - riverWeak, riverDef, - desertFactory, desertWeak, - waterFlowWeak, waterFlowDefRef + for (ref in listOf( + mountainStrong, mountainWeak, mountainDef, mountainDef2, + riverWeak, riverDef, + desertFactory, desertWeak, + waterFlowWeak, waterFlowDefRef )) { - assertNull(ref.get()); + assertNull(ref.get()) } - for (Reference ref : Arrays.asList( - mountainSoft, - riverStrong, riverSoft, - desertStrong, desertSoft, - waterFlowStrong, waterFlowSoft + for (ref in listOf( + mountainSoft, + riverStrong, riverSoft, + desertStrong, desertSoft, + waterFlowStrong, waterFlowSoft )) { - assertNotNull(ref.get()); + assertNotNull(ref.get()) } } diff --git a/tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/gc/EarthLastDayFromProTests.kt b/tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/gc/EarthLastDayFromProTests.kt index 23f4e5f5..5e753490 100644 --- a/tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/gc/EarthLastDayFromProTests.kt +++ b/tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/gc/EarthLastDayFromProTests.kt @@ -1,424 +1,421 @@ -package com.dirgub.klee0kai.stone.text_ext.gc; - -import com.github.klee0kai.stone.Stone; -import com.github.klee0kai.test.di.gcforest.GcGodComponent; -import com.github.klee0kai.test.mowgli.earth.Mountain; -import com.github.klee0kai.test.mowgli.earth.River; -import com.github.klee0kai.test_ext.inject.di.gcforest.GcGodExtComponent; -import com.github.klee0kai.test_ext.inject.mowgli.earth.Desert; -import com.github.klee0kai.test_ext.inject.mowgli.earth.WaterFlow; -import org.junit.jupiter.api.Test; - -import java.lang.ref.Reference; -import java.lang.ref.WeakReference; -import java.util.Arrays; - -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertNull; - -public class EarthLastDayFromProTests { +package com.dirgub.klee0kai.stone.text_ext.gc + +import com.github.klee0kai.test.di.gcforest.GcGodComponent +import com.github.klee0kai.test.di.gcforest.GcGodComponentStoneComponent +import com.github.klee0kai.test.mowgli.earth.Mountain +import com.github.klee0kai.test.mowgli.earth.River +import com.github.klee0kai.test_ext.inject.di.gcforest.GcGodExtComponent +import com.github.klee0kai.test_ext.inject.di.gcforest.GcGodExtComponentStoneComponent +import com.github.klee0kai.test_ext.inject.mowgli.earth.Desert +import com.github.klee0kai.test_ext.inject.mowgli.earth.WaterFlow +import org.junit.jupiter.api.Test +import org.junit.jupiter.api.assertNotNull +import org.junit.jupiter.api.assertNull +import java.lang.ref.WeakReference + +class EarthLastDayFromProTests { @Test - void gcAllTest() { + fun gcAllTest() { //Given - GcGodComponent DI = Stone.createComponent(GcGodComponent.class); - WeakReference mountainStrong = new WeakReference<>(DI.earth().mountainStrong()); - WeakReference mountainSoft = new WeakReference<>(DI.earth().mountainSoft()); - WeakReference mountainWeak = new WeakReference<>(DI.earth().mountainWeak()); - WeakReference mountainDef = new WeakReference<>(DI.earth().mountainDefaultFactory()); - WeakReference mountainDef2 = new WeakReference<>(DI.earth().mountainDefault2Factory()); - WeakReference riverStrong = new WeakReference<>(DI.earth().riverStrong()); - WeakReference riverSoft = new WeakReference<>(DI.earth().riverSoft()); - WeakReference riverWeak = new WeakReference<>(DI.earth().riverWeak()); - WeakReference riverDef = new WeakReference<>(DI.earth().riverDefaultSoft()); - GcGodExtComponent DIPro = Stone.createComponent(GcGodExtComponent.class); - DIPro.extOf(DI); - WeakReference desertStrong = new WeakReference<>(DIPro.earth().desertStrong()); - WeakReference desertSoft = new WeakReference<>(DIPro.earth().desertSoft()); - WeakReference desertWeak = new WeakReference<>(DIPro.earth().desertWeak()); - WeakReference desertFactory = new WeakReference<>(DIPro.earth().desertFactory()); - WeakReference waterFlowStrong = new WeakReference<>(DIPro.earth().riverStrong()); - WeakReference waterFlowSoft = new WeakReference<>(DIPro.earth().riverSoft()); - WeakReference waterFlowWeak = new WeakReference<>(DIPro.earth().riverWeak()); - WeakReference waterFlowDefRef = new WeakReference<>(DIPro.earth().riverDefaultSoft()); + val DI: GcGodComponent = GcGodComponentStoneComponent() + val mountainStrong = WeakReference(DI.earth()?.mountainStrong()) + val mountainSoft = WeakReference(DI.earth()!!.mountainSoft()) + val mountainWeak = WeakReference(DI.earth()!!.mountainWeak()) + val mountainDef = WeakReference(DI.earth()!!.mountainDefaultFactory()) + val mountainDef2 = WeakReference(DI.earth()!!.mountainDefault2Factory()) + val riverStrong = WeakReference(DI.earth()!!.riverStrong()) + val riverSoft = WeakReference(DI.earth()!!.riverSoft()) + val riverWeak = WeakReference(DI.earth()!!.riverWeak()) + val riverDef = WeakReference(DI.earth()!!.riverDefaultSoft()) + val DIPro: GcGodExtComponent = GcGodExtComponentStoneComponent() + DIPro.extOf(DI) + val desertStrong = WeakReference(DIPro.earth()!!.desertStrong()) + val desertSoft = WeakReference(DIPro.earth()!!.desertSoft()) + val desertWeak = WeakReference(DIPro.earth()!!.desertWeak()) + val desertFactory = WeakReference(DIPro.earth()!!.desertFactory()) + val waterFlowStrong = WeakReference(DIPro.earth()!!.riverStrong()) + val waterFlowSoft = WeakReference(DIPro.earth()!!.riverSoft()) + val waterFlowWeak = WeakReference(DIPro.earth()!!.riverWeak()) + val waterFlowDefRef = WeakReference(DIPro.earth()!!.riverDefaultSoft()) //When - DIPro.gcAll(); + DIPro.gcAll() //Then - for (Reference ref : Arrays.asList( - mountainStrong, mountainSoft, mountainDef2, mountainWeak, mountainDef, - riverStrong, riverSoft, riverWeak, riverDef, - desertStrong, desertSoft, desertWeak, desertFactory, - waterFlowStrong, waterFlowSoft, waterFlowWeak, waterFlowDefRef + for (ref in listOf( + mountainStrong, mountainSoft, mountainDef2, mountainWeak, mountainDef, + riverStrong, riverSoft, riverWeak, riverDef, + desertStrong, desertSoft, desertWeak, desertFactory, + waterFlowStrong, waterFlowSoft, waterFlowWeak, waterFlowDefRef )) { - assertNull(ref.get()); + assertNull(ref.get()) } } @Test - void gcStrongTest() { + fun gcStrongTest() { //Given - GcGodComponent DI = Stone.createComponent(GcGodComponent.class); - WeakReference mountainStrong = new WeakReference<>(DI.earth().mountainStrong()); - WeakReference mountainSoft = new WeakReference<>(DI.earth().mountainSoft()); - WeakReference mountainWeak = new WeakReference<>(DI.earth().mountainWeak()); - WeakReference mountainDef = new WeakReference<>(DI.earth().mountainDefaultFactory()); - WeakReference mountainDef2 = new WeakReference<>(DI.earth().mountainDefault2Factory()); - WeakReference riverStrong = new WeakReference<>(DI.earth().riverStrong()); - WeakReference riverSoft = new WeakReference<>(DI.earth().riverSoft()); - WeakReference riverWeak = new WeakReference<>(DI.earth().riverWeak()); - WeakReference riverDef = new WeakReference<>(DI.earth().riverDefaultSoft()); - GcGodExtComponent DIPro = Stone.createComponent(GcGodExtComponent.class); - DIPro.extOf(DI); - WeakReference desertStrong = new WeakReference<>(DIPro.earth().desertStrong()); - WeakReference desertSoft = new WeakReference<>(DIPro.earth().desertSoft()); - WeakReference desertWeak = new WeakReference<>(DIPro.earth().desertWeak()); - WeakReference desertFactory = new WeakReference<>(DIPro.earth().desertFactory()); - WeakReference waterFlowStrong = new WeakReference<>(DIPro.earth().riverStrong()); - WeakReference waterFlowSoft = new WeakReference<>(DIPro.earth().riverSoft()); - WeakReference waterFlowWeak = new WeakReference<>(DIPro.earth().riverWeak()); - WeakReference waterFlowDefRef = new WeakReference<>(DIPro.earth().riverDefaultSoft()); + val DI: GcGodComponent = GcGodComponentStoneComponent() + val mountainStrong = WeakReference(DI.earth()?.mountainStrong()) + val mountainSoft = WeakReference(DI.earth()!!.mountainSoft()) + val mountainWeak = WeakReference(DI.earth()!!.mountainWeak()) + val mountainDef = WeakReference(DI.earth()!!.mountainDefaultFactory()) + val mountainDef2 = WeakReference(DI.earth()!!.mountainDefault2Factory()) + val riverStrong = WeakReference(DI.earth()!!.riverStrong()) + val riverSoft = WeakReference(DI.earth()!!.riverSoft()) + val riverWeak = WeakReference(DI.earth()!!.riverWeak()) + val riverDef = WeakReference(DI.earth()!!.riverDefaultSoft()) + val DIPro: GcGodExtComponent = GcGodExtComponentStoneComponent() + DIPro.extOf(DI) + val desertStrong = WeakReference(DIPro.earth()!!.desertStrong()) + val desertSoft = WeakReference(DIPro.earth()!!.desertSoft()) + val desertWeak = WeakReference(DIPro.earth()!!.desertWeak()) + val desertFactory = WeakReference(DIPro.earth()!!.desertFactory()) + val waterFlowStrong = WeakReference(DIPro.earth()!!.riverStrong()) + val waterFlowSoft = WeakReference(DIPro.earth()!!.riverSoft()) + val waterFlowWeak = WeakReference(DIPro.earth()!!.riverWeak()) + val waterFlowDefRef = WeakReference(DIPro.earth()!!.riverDefaultSoft()) //When - DIPro.gcStrong(); + DIPro.gcStrong() //Then - for (Reference ref : Arrays.asList( - mountainStrong, mountainWeak, mountainDef, mountainDef2, - riverStrong, riverWeak, riverDef, - desertStrong, desertWeak, desertFactory, - waterFlowStrong, waterFlowWeak, waterFlowDefRef + for (ref in listOf( + mountainStrong, mountainWeak, mountainDef, mountainDef2, + riverStrong, riverWeak, riverDef, + desertStrong, desertWeak, desertFactory, + waterFlowStrong, waterFlowWeak, waterFlowDefRef )) { - assertNull(ref.get()); + assertNull(ref.get()) } - for (Reference ref : Arrays.asList( - mountainSoft, - riverSoft, - desertSoft, - waterFlowSoft + for (ref in listOf( + mountainSoft, + riverSoft, + desertSoft, + waterFlowSoft )) { - assertNotNull(ref.get()); + assertNotNull(ref.get()) } } @Test - void gcSoftTest() { + fun gcSoftTest() { //Given - GcGodComponent DI = Stone.createComponent(GcGodComponent.class); - WeakReference mountainStrong = new WeakReference<>(DI.earth().mountainStrong()); - WeakReference mountainSoft = new WeakReference<>(DI.earth().mountainSoft()); - WeakReference mountainWeak = new WeakReference<>(DI.earth().mountainWeak()); - WeakReference mountainDef = new WeakReference<>(DI.earth().mountainDefaultFactory()); - WeakReference mountainDef2 = new WeakReference<>(DI.earth().mountainDefault2Factory()); - WeakReference riverStrong = new WeakReference<>(DI.earth().riverStrong()); - WeakReference riverSoft = new WeakReference<>(DI.earth().riverSoft()); - WeakReference riverWeak = new WeakReference<>(DI.earth().riverWeak()); - WeakReference riverDef = new WeakReference<>(DI.earth().riverDefaultSoft()); - GcGodExtComponent DIPro = Stone.createComponent(GcGodExtComponent.class); - DIPro.extOf(DI); - WeakReference desertStrong = new WeakReference<>(DIPro.earth().desertStrong()); - WeakReference desertSoft = new WeakReference<>(DIPro.earth().desertSoft()); - WeakReference desertWeak = new WeakReference<>(DIPro.earth().desertWeak()); - WeakReference desertFactory = new WeakReference<>(DIPro.earth().desertFactory()); - WeakReference waterFlowStrong = new WeakReference<>(DIPro.earth().riverStrong()); - WeakReference waterFlowSoft = new WeakReference<>(DIPro.earth().riverSoft()); - WeakReference waterFlowWeak = new WeakReference<>(DIPro.earth().riverWeak()); - WeakReference waterFlowDefRef = new WeakReference<>(DIPro.earth().riverDefaultSoft()); + val DI: GcGodComponent = GcGodComponentStoneComponent() + val mountainStrong = WeakReference(DI.earth()?.mountainStrong()) + val mountainSoft = WeakReference(DI.earth()!!.mountainSoft()) + val mountainWeak = WeakReference(DI.earth()!!.mountainWeak()) + val mountainDef = WeakReference(DI.earth()!!.mountainDefaultFactory()) + val mountainDef2 = WeakReference(DI.earth()!!.mountainDefault2Factory()) + val riverStrong = WeakReference(DI.earth()!!.riverStrong()) + val riverSoft = WeakReference(DI.earth()!!.riverSoft()) + val riverWeak = WeakReference(DI.earth()!!.riverWeak()) + val riverDef = WeakReference(DI.earth()!!.riverDefaultSoft()) + val DIPro: GcGodExtComponent = GcGodExtComponentStoneComponent() + DIPro.extOf(DI) + val desertStrong = WeakReference(DIPro.earth()!!.desertStrong()) + val desertSoft = WeakReference(DIPro.earth()!!.desertSoft()) + val desertWeak = WeakReference(DIPro.earth()!!.desertWeak()) + val desertFactory = WeakReference(DIPro.earth()!!.desertFactory()) + val waterFlowStrong = WeakReference(DIPro.earth()!!.riverStrong()) + val waterFlowSoft = WeakReference(DIPro.earth()!!.riverSoft()) + val waterFlowWeak = WeakReference(DIPro.earth()!!.riverWeak()) + val waterFlowDefRef = WeakReference(DIPro.earth()!!.riverDefaultSoft()) //When - DIPro.gcSoft(); + DIPro.gcSoft() //Then - for (Reference ref : Arrays.asList( - mountainSoft, mountainWeak, mountainDef, mountainDef2, - riverSoft, riverWeak, riverDef, - desertSoft, desertWeak, desertFactory, - waterFlowSoft, waterFlowDefRef, waterFlowWeak + for (ref in listOf( + mountainSoft, mountainWeak, mountainDef, mountainDef2, + riverSoft, riverWeak, riverDef, + desertSoft, desertWeak, desertFactory, + waterFlowSoft, waterFlowDefRef, waterFlowWeak )) { - assertNull(ref.get()); + assertNull(ref.get()) } - for (Reference ref : Arrays.asList( - mountainStrong, - riverStrong, - desertStrong, - waterFlowStrong + for (ref in listOf( + mountainStrong, + riverStrong, + desertStrong, + waterFlowStrong )) { - assertNotNull(ref.get()); + assertNotNull(ref.get()) } } @Test - void gcWeakTest() { + fun gcWeakTest() { //Given - GcGodComponent DI = Stone.createComponent(GcGodComponent.class); - WeakReference mountainStrong = new WeakReference<>(DI.earth().mountainStrong()); - WeakReference mountainSoft = new WeakReference<>(DI.earth().mountainSoft()); - WeakReference mountainWeak = new WeakReference<>(DI.earth().mountainWeak()); - WeakReference mountainDef = new WeakReference<>(DI.earth().mountainDefaultFactory()); - WeakReference mountainDef2 = new WeakReference<>(DI.earth().mountainDefault2Factory()); - WeakReference riverStrong = new WeakReference<>(DI.earth().riverStrong()); - WeakReference riverSoft = new WeakReference<>(DI.earth().riverSoft()); - WeakReference riverWeak = new WeakReference<>(DI.earth().riverWeak()); - WeakReference riverDef = new WeakReference<>(DI.earth().riverDefaultSoft()); - GcGodExtComponent DIPro = Stone.createComponent(GcGodExtComponent.class); - DIPro.extOf(DI); - WeakReference desertStrong = new WeakReference<>(DIPro.earth().desertStrong()); - WeakReference desertSoft = new WeakReference<>(DIPro.earth().desertSoft()); - WeakReference desertWeak = new WeakReference<>(DIPro.earth().desertWeak()); - WeakReference desertFactory = new WeakReference<>(DIPro.earth().desertFactory()); - WeakReference waterFlowStrong = new WeakReference<>(DIPro.earth().riverStrong()); - WeakReference waterFlowSoft = new WeakReference<>(DIPro.earth().riverSoft()); - WeakReference waterFlowWeak = new WeakReference<>(DIPro.earth().riverWeak()); - WeakReference waterFlowDefRef = new WeakReference<>(DIPro.earth().riverDefaultSoft()); + val DI: GcGodComponent = GcGodComponentStoneComponent() + val mountainStrong = WeakReference(DI.earth()?.mountainStrong()) + val mountainSoft = WeakReference(DI.earth()!!.mountainSoft()) + val mountainWeak = WeakReference(DI.earth()!!.mountainWeak()) + val mountainDef = WeakReference(DI.earth()!!.mountainDefaultFactory()) + val mountainDef2 = WeakReference(DI.earth()!!.mountainDefault2Factory()) + val riverStrong = WeakReference(DI.earth()!!.riverStrong()) + val riverSoft = WeakReference(DI.earth()!!.riverSoft()) + val riverWeak = WeakReference(DI.earth()!!.riverWeak()) + val riverDef = WeakReference(DI.earth()!!.riverDefaultSoft()) + val DIPro: GcGodExtComponent = GcGodExtComponentStoneComponent() + DIPro.extOf(DI) + val desertStrong = WeakReference(DIPro.earth()!!.desertStrong()) + val desertSoft = WeakReference(DIPro.earth()!!.desertSoft()) + val desertWeak = WeakReference(DIPro.earth()!!.desertWeak()) + val desertFactory = WeakReference(DIPro.earth()!!.desertFactory()) + val waterFlowStrong = WeakReference(DIPro.earth()!!.riverStrong()) + val waterFlowSoft = WeakReference(DIPro.earth()!!.riverSoft()) + val waterFlowWeak = WeakReference(DIPro.earth()!!.riverWeak()) + val waterFlowDefRef = WeakReference(DIPro.earth()!!.riverDefaultSoft()) //When - DIPro.gcWeak(); + DIPro.gcWeak() //Then - for (Reference ref : Arrays.asList( - mountainWeak, mountainDef, mountainDef2, - riverWeak, riverDef, - desertWeak, desertFactory, - waterFlowWeak, waterFlowDefRef + for (ref in listOf( + mountainWeak, mountainDef, mountainDef2, + riverWeak, riverDef, + desertWeak, desertFactory, + waterFlowWeak, waterFlowDefRef )) { - assertNull(ref.get()); + assertNull(ref.get()) } - for (Reference ref : Arrays.asList( - mountainStrong, mountainSoft, - riverStrong, riverSoft, - desertStrong, desertSoft, - waterFlowStrong, waterFlowSoft + for (ref in listOf( + mountainStrong, mountainSoft, + riverStrong, riverSoft, + desertStrong, desertSoft, + waterFlowStrong, waterFlowSoft )) { - assertNotNull(ref.get()); + assertNotNull(ref.get()) } } @Test - void gcMountainTest() { + fun gcMountainTest() { //Given - GcGodComponent DI = Stone.createComponent(GcGodComponent.class); - WeakReference mountainStrong = new WeakReference<>(DI.earth().mountainStrong()); - WeakReference mountainSoft = new WeakReference<>(DI.earth().mountainSoft()); - WeakReference mountainWeak = new WeakReference<>(DI.earth().mountainWeak()); - WeakReference mountainDef = new WeakReference<>(DI.earth().mountainDefaultFactory()); - WeakReference mountainDef2 = new WeakReference<>(DI.earth().mountainDefault2Factory()); - WeakReference riverStrong = new WeakReference<>(DI.earth().riverStrong()); - WeakReference riverSoft = new WeakReference<>(DI.earth().riverSoft()); - WeakReference riverWeak = new WeakReference<>(DI.earth().riverWeak()); - WeakReference riverDef = new WeakReference<>(DI.earth().riverDefaultSoft()); - GcGodExtComponent DIPro = Stone.createComponent(GcGodExtComponent.class); - DIPro.extOf(DI); - WeakReference desertStrong = new WeakReference<>(DIPro.earth().desertStrong()); - WeakReference desertSoft = new WeakReference<>(DIPro.earth().desertSoft()); - WeakReference desertWeak = new WeakReference<>(DIPro.earth().desertWeak()); - WeakReference desertFactory = new WeakReference<>(DIPro.earth().desertFactory()); - WeakReference waterFlowStrong = new WeakReference<>(DIPro.earth().riverStrong()); - WeakReference waterFlowSoft = new WeakReference<>(DIPro.earth().riverSoft()); - WeakReference waterFlowWeak = new WeakReference<>(DIPro.earth().riverWeak()); - WeakReference waterFlowDefRef = new WeakReference<>(DIPro.earth().riverDefaultSoft()); + val DI: GcGodComponent = GcGodComponentStoneComponent() + val mountainStrong = WeakReference(DI.earth()?.mountainStrong()) + val mountainSoft = WeakReference(DI.earth()!!.mountainSoft()) + val mountainWeak = WeakReference(DI.earth()!!.mountainWeak()) + val mountainDef = WeakReference(DI.earth()!!.mountainDefaultFactory()) + val mountainDef2 = WeakReference(DI.earth()!!.mountainDefault2Factory()) + val riverStrong = WeakReference(DI.earth()!!.riverStrong()) + val riverSoft = WeakReference(DI.earth()!!.riverSoft()) + val riverWeak = WeakReference(DI.earth()!!.riverWeak()) + val riverDef = WeakReference(DI.earth()!!.riverDefaultSoft()) + val DIPro: GcGodExtComponent = GcGodExtComponentStoneComponent() + DIPro.extOf(DI) + val desertStrong = WeakReference(DIPro.earth()!!.desertStrong()) + val desertSoft = WeakReference(DIPro.earth()!!.desertSoft()) + val desertWeak = WeakReference(DIPro.earth()!!.desertWeak()) + val desertFactory = WeakReference(DIPro.earth()!!.desertFactory()) + val waterFlowStrong = WeakReference(DIPro.earth()!!.riverStrong()) + val waterFlowSoft = WeakReference(DIPro.earth()!!.riverSoft()) + val waterFlowWeak = WeakReference(DIPro.earth()!!.riverWeak()) + val waterFlowDefRef = WeakReference(DIPro.earth()!!.riverDefaultSoft()) //When - DIPro.gcMountains(); + DIPro.gcMountains() //Then - for (Reference ref : Arrays.asList( - mountainStrong, mountainSoft, mountainWeak, mountainDef, mountainDef2, - riverWeak, riverDef, - desertWeak, desertFactory, - waterFlowWeak, waterFlowDefRef + for (ref in listOf( + mountainStrong, mountainSoft, mountainWeak, mountainDef, mountainDef2, + riverWeak, riverDef, + desertWeak, desertFactory, + waterFlowWeak, waterFlowDefRef )) { - assertNull(ref.get()); + assertNull(ref.get()) } - for (Reference ref : Arrays.asList( - riverStrong, riverSoft, - desertStrong, desertSoft, - waterFlowStrong, waterFlowSoft + for (ref in listOf( + riverStrong, riverSoft, + desertStrong, desertSoft, + waterFlowStrong, waterFlowSoft )) { - assertNotNull(ref.get()); + assertNotNull(ref.get()) } } @Test - void gcRiverTest() { + fun gcRiverTest() { //Given - GcGodComponent DI = Stone.createComponent(GcGodComponent.class); - WeakReference mountainStrong = new WeakReference<>(DI.earth().mountainStrong()); - WeakReference mountainSoft = new WeakReference<>(DI.earth().mountainSoft()); - WeakReference mountainWeak = new WeakReference<>(DI.earth().mountainWeak()); - WeakReference mountainDef = new WeakReference<>(DI.earth().mountainDefaultFactory()); - WeakReference mountainDef2 = new WeakReference<>(DI.earth().mountainDefault2Factory()); - WeakReference riverStrong = new WeakReference<>(DI.earth().riverStrong()); - WeakReference riverSoft = new WeakReference<>(DI.earth().riverSoft()); - WeakReference riverWeak = new WeakReference<>(DI.earth().riverWeak()); - WeakReference riverDef = new WeakReference<>(DI.earth().riverDefaultSoft()); - GcGodExtComponent DIPro = Stone.createComponent(GcGodExtComponent.class); - DIPro.extOf(DI); - WeakReference desertStrong = new WeakReference<>(DIPro.earth().desertStrong()); - WeakReference desertSoft = new WeakReference<>(DIPro.earth().desertSoft()); - WeakReference desertWeak = new WeakReference<>(DIPro.earth().desertWeak()); - WeakReference desertFactory = new WeakReference<>(DIPro.earth().desertFactory()); - WeakReference waterFlowStrong = new WeakReference<>(DIPro.earth().riverStrong()); - WeakReference waterFlowSoft = new WeakReference<>(DIPro.earth().riverSoft()); - WeakReference waterFlowWeak = new WeakReference<>(DIPro.earth().riverWeak()); - WeakReference waterFlowDefRef = new WeakReference<>(DIPro.earth().riverDefaultSoft()); + val DI: GcGodComponent = GcGodComponentStoneComponent() + val mountainStrong = WeakReference(DI.earth()?.mountainStrong()) + val mountainSoft = WeakReference(DI.earth()!!.mountainSoft()) + val mountainWeak = WeakReference(DI.earth()!!.mountainWeak()) + val mountainDef = WeakReference(DI.earth()!!.mountainDefaultFactory()) + val mountainDef2 = WeakReference(DI.earth()!!.mountainDefault2Factory()) + val riverStrong = WeakReference(DI.earth()!!.riverStrong()) + val riverSoft = WeakReference(DI.earth()!!.riverSoft()) + val riverWeak = WeakReference(DI.earth()!!.riverWeak()) + val riverDef = WeakReference(DI.earth()!!.riverDefaultSoft()) + val DIPro: GcGodExtComponent = GcGodExtComponentStoneComponent() + DIPro.extOf(DI) + val desertStrong = WeakReference(DIPro.earth()!!.desertStrong()) + val desertSoft = WeakReference(DIPro.earth()!!.desertSoft()) + val desertWeak = WeakReference(DIPro.earth()!!.desertWeak()) + val desertFactory = WeakReference(DIPro.earth()!!.desertFactory()) + val waterFlowStrong = WeakReference(DIPro.earth()!!.riverStrong()) + val waterFlowSoft = WeakReference(DIPro.earth()!!.riverSoft()) + val waterFlowWeak = WeakReference(DIPro.earth()!!.riverWeak()) + val waterFlowDefRef = WeakReference(DIPro.earth()!!.riverDefaultSoft()) //When - DIPro.gcRivers(); + DIPro.gcRivers() //Then - for (Reference ref : Arrays.asList( - mountainWeak, mountainDef, mountainDef2, - riverStrong, riverSoft, riverWeak, riverDef, - desertWeak, desertFactory, - waterFlowStrong, waterFlowSoft, waterFlowDefRef, waterFlowWeak + for (ref in listOf( + mountainWeak, mountainDef, mountainDef2, + riverStrong, riverSoft, riverWeak, riverDef, + desertWeak, desertFactory, + waterFlowStrong, waterFlowSoft, waterFlowDefRef, waterFlowWeak )) { - assertNull(ref.get()); + assertNull(ref.get()) } - for (Reference ref : Arrays.asList( - mountainStrong, mountainSoft, - desertStrong, desertSoft + for (ref in listOf( + mountainStrong, mountainSoft, + desertStrong, desertSoft )) { - assertNotNull(ref.get()); + assertNotNull(ref.get()) } } @Test - void gcMountainAndRiverTest() { + fun gcMountainAndRiverTest() { //Given - GcGodComponent DI = Stone.createComponent(GcGodComponent.class); - WeakReference mountainStrong = new WeakReference<>(DI.earth().mountainStrong()); - WeakReference mountainSoft = new WeakReference<>(DI.earth().mountainSoft()); - WeakReference mountainWeak = new WeakReference<>(DI.earth().mountainWeak()); - WeakReference mountainDef = new WeakReference<>(DI.earth().mountainDefaultFactory()); - WeakReference mountainDef2 = new WeakReference<>(DI.earth().mountainDefault2Factory()); - WeakReference riverStrong = new WeakReference<>(DI.earth().riverStrong()); - WeakReference riverSoft = new WeakReference<>(DI.earth().riverSoft()); - WeakReference riverWeak = new WeakReference<>(DI.earth().riverWeak()); - WeakReference riverDef = new WeakReference<>(DI.earth().riverDefaultSoft()); - GcGodExtComponent DIPro = Stone.createComponent(GcGodExtComponent.class); - DIPro.extOf(DI); - WeakReference desertStrong = new WeakReference<>(DIPro.earth().desertStrong()); - WeakReference desertSoft = new WeakReference<>(DIPro.earth().desertSoft()); - WeakReference desertWeak = new WeakReference<>(DIPro.earth().desertWeak()); - WeakReference desertFactory = new WeakReference<>(DIPro.earth().desertFactory()); - WeakReference waterFlowStrong = new WeakReference<>(DIPro.earth().riverStrong()); - WeakReference waterFlowSoft = new WeakReference<>(DIPro.earth().riverSoft()); - WeakReference waterFlowWeak = new WeakReference<>(DIPro.earth().riverWeak()); - WeakReference waterFlowDefRef = new WeakReference<>(DIPro.earth().riverDefaultSoft()); + val DI: GcGodComponent = GcGodComponentStoneComponent() + val mountainStrong = WeakReference(DI.earth()?.mountainStrong()) + val mountainSoft = WeakReference(DI.earth()!!.mountainSoft()) + val mountainWeak = WeakReference(DI.earth()!!.mountainWeak()) + val mountainDef = WeakReference(DI.earth()!!.mountainDefaultFactory()) + val mountainDef2 = WeakReference(DI.earth()!!.mountainDefault2Factory()) + val riverStrong = WeakReference(DI.earth()!!.riverStrong()) + val riverSoft = WeakReference(DI.earth()!!.riverSoft()) + val riverWeak = WeakReference(DI.earth()!!.riverWeak()) + val riverDef = WeakReference(DI.earth()!!.riverDefaultSoft()) + val DIPro: GcGodExtComponent = GcGodExtComponentStoneComponent() + DIPro.extOf(DI) + val desertStrong = WeakReference(DIPro.earth()!!.desertStrong()) + val desertSoft = WeakReference(DIPro.earth()!!.desertSoft()) + val desertWeak = WeakReference(DIPro.earth()!!.desertWeak()) + val desertFactory = WeakReference(DIPro.earth()!!.desertFactory()) + val waterFlowStrong = WeakReference(DIPro.earth()!!.riverStrong()) + val waterFlowSoft = WeakReference(DIPro.earth()!!.riverSoft()) + val waterFlowWeak = WeakReference(DIPro.earth()!!.riverWeak()) + val waterFlowDefRef = WeakReference(DIPro.earth()!!.riverDefaultSoft()) //When - DIPro.gcMountainsAndRivers(); + DIPro.gcMountainsAndRivers() //Then - for (Reference ref : Arrays.asList( - mountainStrong, mountainSoft, mountainWeak, mountainDef, mountainDef2, - riverStrong, riverSoft, riverWeak, riverDef, - desertFactory, desertWeak, - waterFlowStrong, waterFlowSoft, waterFlowDefRef, waterFlowWeak + for (ref in listOf( + mountainStrong, mountainSoft, mountainWeak, mountainDef, mountainDef2, + riverStrong, riverSoft, riverWeak, riverDef, + desertFactory, desertWeak, + waterFlowStrong, waterFlowSoft, waterFlowDefRef, waterFlowWeak )) { - assertNull(ref.get()); + assertNull(ref.get()) } - for (Reference ref : Arrays.asList( - desertStrong, desertSoft + for (ref in listOf( + desertStrong, desertSoft )) { - assertNotNull(ref.get()); + assertNotNull(ref.get()) } } @Test - void gcSoftMountainTest() { + fun gcSoftMountainTest() { //Given - GcGodComponent DI = Stone.createComponent(GcGodComponent.class); - WeakReference mountainStrong = new WeakReference<>(DI.earth().mountainStrong()); - WeakReference mountainSoft = new WeakReference<>(DI.earth().mountainSoft()); - WeakReference mountainWeak = new WeakReference<>(DI.earth().mountainWeak()); - WeakReference mountainDef = new WeakReference<>(DI.earth().mountainDefaultFactory()); - WeakReference mountainDef2 = new WeakReference<>(DI.earth().mountainDefault2Factory()); - WeakReference riverStrong = new WeakReference<>(DI.earth().riverStrong()); - WeakReference riverSoft = new WeakReference<>(DI.earth().riverSoft()); - WeakReference riverWeak = new WeakReference<>(DI.earth().riverWeak()); - WeakReference riverDef = new WeakReference<>(DI.earth().riverDefaultSoft()); - GcGodExtComponent DIPro = Stone.createComponent(GcGodExtComponent.class); - DIPro.extOf(DI); - WeakReference desertStrong = new WeakReference<>(DIPro.earth().desertStrong()); - WeakReference desertSoft = new WeakReference<>(DIPro.earth().desertSoft()); - WeakReference desertWeak = new WeakReference<>(DIPro.earth().desertWeak()); - WeakReference desertFactory = new WeakReference<>(DIPro.earth().desertFactory()); - WeakReference waterFlowStrong = new WeakReference<>(DIPro.earth().riverStrong()); - WeakReference waterFlowSoft = new WeakReference<>(DIPro.earth().riverSoft()); - WeakReference waterFlowWeak = new WeakReference<>(DIPro.earth().riverWeak()); - WeakReference waterFlowDefRef = new WeakReference<>(DIPro.earth().riverDefaultSoft()); + val DI: GcGodComponent = GcGodComponentStoneComponent() + val mountainStrong = WeakReference(DI.earth()?.mountainStrong()) + val mountainSoft = WeakReference(DI.earth()!!.mountainSoft()) + val mountainWeak = WeakReference(DI.earth()!!.mountainWeak()) + val mountainDef = WeakReference(DI.earth()!!.mountainDefaultFactory()) + val mountainDef2 = WeakReference(DI.earth()!!.mountainDefault2Factory()) + val riverStrong = WeakReference(DI.earth()!!.riverStrong()) + val riverSoft = WeakReference(DI.earth()!!.riverSoft()) + val riverWeak = WeakReference(DI.earth()!!.riverWeak()) + val riverDef = WeakReference(DI.earth()!!.riverDefaultSoft()) + val DIPro: GcGodExtComponent = GcGodExtComponentStoneComponent() + DIPro.extOf(DI) + val desertStrong = WeakReference(DIPro.earth()!!.desertStrong()) + val desertSoft = WeakReference(DIPro.earth()!!.desertSoft()) + val desertWeak = WeakReference(DIPro.earth()!!.desertWeak()) + val desertFactory = WeakReference(DIPro.earth()!!.desertFactory()) + val waterFlowStrong = WeakReference(DIPro.earth()!!.riverStrong()) + val waterFlowSoft = WeakReference(DIPro.earth()!!.riverSoft()) + val waterFlowWeak = WeakReference(DIPro.earth()!!.riverWeak()) + val waterFlowDefRef = WeakReference(DIPro.earth()!!.riverDefaultSoft()) //When - DIPro.gcSoftMountains(); + DIPro.gcSoftMountains() //Then - for (Reference ref : Arrays.asList( - mountainSoft, mountainWeak, mountainDef, mountainDef2, - riverWeak, riverDef, - desertFactory, desertWeak, - waterFlowWeak, waterFlowDefRef + for (ref in listOf( + mountainSoft, mountainWeak, mountainDef, mountainDef2, + riverWeak, riverDef, + desertFactory, desertWeak, + waterFlowWeak, waterFlowDefRef )) { - assertNull(ref.get()); + assertNull(ref.get()) } - for (Reference ref : Arrays.asList( - mountainStrong, - riverStrong, riverSoft, - desertStrong, desertSoft, - waterFlowStrong, waterFlowSoft + for (ref in listOf( + mountainStrong, + riverStrong, riverSoft, + desertStrong, desertSoft, + waterFlowStrong, waterFlowSoft )) { - assertNotNull(ref.get()); + assertNotNull(ref.get()) } } @Test - void gcStrongMountainTest() { + fun gcStrongMountainTest() { //Given - GcGodComponent DI = Stone.createComponent(GcGodComponent.class); - WeakReference mountainStrong = new WeakReference<>(DI.earth().mountainStrong()); - WeakReference mountainSoft = new WeakReference<>(DI.earth().mountainSoft()); - WeakReference mountainWeak = new WeakReference<>(DI.earth().mountainWeak()); - WeakReference mountainDef = new WeakReference<>(DI.earth().mountainDefaultFactory()); - WeakReference mountainDef2 = new WeakReference<>(DI.earth().mountainDefault2Factory()); - WeakReference riverStrong = new WeakReference<>(DI.earth().riverStrong()); - WeakReference riverSoft = new WeakReference<>(DI.earth().riverSoft()); - WeakReference riverWeak = new WeakReference<>(DI.earth().riverWeak()); - WeakReference riverDef = new WeakReference<>(DI.earth().riverDefaultSoft()); - GcGodExtComponent DIPro = Stone.createComponent(GcGodExtComponent.class); - DIPro.extOf(DI); - WeakReference desertStrong = new WeakReference<>(DIPro.earth().desertStrong()); - WeakReference desertSoft = new WeakReference<>(DIPro.earth().desertSoft()); - WeakReference desertWeak = new WeakReference<>(DIPro.earth().desertWeak()); - WeakReference desertFactory = new WeakReference<>(DIPro.earth().desertFactory()); - WeakReference waterFlowStrong = new WeakReference<>(DIPro.earth().riverStrong()); - WeakReference waterFlowSoft = new WeakReference<>(DIPro.earth().riverSoft()); - WeakReference waterFlowWeak = new WeakReference<>(DIPro.earth().riverWeak()); - WeakReference waterFlowDefRef = new WeakReference<>(DIPro.earth().riverDefaultSoft()); + val DI: GcGodComponent = GcGodComponentStoneComponent() + val mountainStrong = WeakReference(DI.earth()?.mountainStrong()) + val mountainSoft = WeakReference(DI.earth()!!.mountainSoft()) + val mountainWeak = WeakReference(DI.earth()!!.mountainWeak()) + val mountainDef = WeakReference(DI.earth()!!.mountainDefaultFactory()) + val mountainDef2 = WeakReference(DI.earth()!!.mountainDefault2Factory()) + val riverStrong = WeakReference(DI.earth()!!.riverStrong()) + val riverSoft = WeakReference(DI.earth()!!.riverSoft()) + val riverWeak = WeakReference(DI.earth()!!.riverWeak()) + val riverDef = WeakReference(DI.earth()!!.riverDefaultSoft()) + val DIPro: GcGodExtComponent = GcGodExtComponentStoneComponent() + DIPro.extOf(DI) + val desertStrong = WeakReference(DIPro.earth()!!.desertStrong()) + val desertSoft = WeakReference(DIPro.earth()!!.desertSoft()) + val desertWeak = WeakReference(DIPro.earth()!!.desertWeak()) + val desertFactory = WeakReference(DIPro.earth()!!.desertFactory()) + val waterFlowStrong = WeakReference(DIPro.earth()!!.riverStrong()) + val waterFlowSoft = WeakReference(DIPro.earth()!!.riverSoft()) + val waterFlowWeak = WeakReference(DIPro.earth()!!.riverWeak()) + val waterFlowDefRef = WeakReference(DIPro.earth()!!.riverDefaultSoft()) //When - DIPro.gcStrongMountains(); + DIPro.gcStrongMountains() //Then - for (Reference ref : Arrays.asList( - mountainStrong, mountainWeak, mountainDef, mountainDef2, - riverWeak, riverDef, - desertFactory, desertWeak, - waterFlowWeak, waterFlowDefRef + for (ref in listOf( + mountainStrong, mountainWeak, mountainDef, mountainDef2, + riverWeak, riverDef, + desertFactory, desertWeak, + waterFlowWeak, waterFlowDefRef )) { - assertNull(ref.get()); + assertNull(ref.get()) } - for (Reference ref : Arrays.asList( - mountainSoft, - riverStrong, riverSoft, - desertStrong, desertSoft, - waterFlowStrong, waterFlowSoft + for (ref in listOf( + mountainSoft, + riverStrong, riverSoft, + desertStrong, desertSoft, + waterFlowStrong, waterFlowSoft )) { - assertNotNull(ref.get()); + assertNotNull(ref.get()) } } diff --git a/tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/identifiers/GoodPhoneInjectExtTests.kt b/tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/identifiers/GoodPhoneInjectExtTests.kt index a2862a4d..363a10c1 100644 --- a/tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/identifiers/GoodPhoneInjectExtTests.kt +++ b/tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/identifiers/GoodPhoneInjectExtTests.kt @@ -1,114 +1,114 @@ -package com.dirgub.klee0kai.stone.text_ext.identifiers; +package com.dirgub.klee0kai.stone.text_ext.identifiers -import com.github.klee0kai.stone.Stone; -import com.github.klee0kai.test.di.base_phone.PhoneComponent; -import com.github.klee0kai.test.di.base_phone.identifiers.DataStorageSize; -import com.github.klee0kai.test.di.base_phone.identifiers.RamSize; -import com.github.klee0kai.test.tech.phone.GoodPhone; -import com.github.klee0kai.test_ext.inject.di.base_phone.PhoneExtComponent; -import com.github.klee0kai.test_ext.inject.tech.components.DDR3Ram; -import org.junit.jupiter.api.Disabled; -import org.junit.jupiter.api.Test; +import com.github.klee0kai.test.di.base_phone.PhoneComponent +import com.github.klee0kai.test.di.base_phone.PhoneComponentStoneComponent +import com.github.klee0kai.test.di.base_phone.identifiers.DataStorageSize +import com.github.klee0kai.test.di.base_phone.identifiers.RamSize +import com.github.klee0kai.test.tech.phone.GoodPhone +import com.github.klee0kai.test_ext.inject.di.base_phone.PhoneExtComponent +import com.github.klee0kai.test_ext.inject.di.base_phone.PhoneExtComponentStoneComponent +import com.github.klee0kai.test_ext.inject.tech.components.DDR3Ram +import org.junit.jupiter.api.Assertions.assertEquals +import org.junit.jupiter.api.Assertions.assertTrue +import org.junit.jupiter.api.Disabled +import org.junit.jupiter.api.Test -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertTrue; - -public class GoodPhoneInjectExtTests { +class GoodPhoneInjectExtTests { @Test @Disabled("https://github.com/klee0kai/stone/issues/42") - public void createdIsReusableTest() { + fun createdIsReusableTest() { //Given - PhoneComponent DI = Stone.createComponent(PhoneComponent.class); - GoodPhone goodPhone1 = new GoodPhone(); - DI.inject(goodPhone1, goodPhone1.lifeCycleOwner, new DataStorageSize("120GB"), new RamSize("8GB")); + val DI: PhoneComponent = PhoneComponentStoneComponent() + val goodPhone1 = GoodPhone() + DI.inject(goodPhone1, goodPhone1.lifeCycleOwner, DataStorageSize("120GB"), RamSize("8GB")) //When - PhoneExtComponent DIPro = Stone.createComponent(PhoneExtComponent.class); - DIPro.extOf(DI); - GoodPhone goodPhone2 = new GoodPhone(); - DIPro.inject(goodPhone2, goodPhone2.lifeCycleOwner, new DataStorageSize("120GB"), new RamSize("8GB")); + val DIPro: PhoneExtComponent = PhoneExtComponentStoneComponent() + DIPro.extOf(DI) + val goodPhone2 = GoodPhone() + DIPro.inject(goodPhone2, goodPhone2.lifeCycleOwner, DataStorageSize("120GB"), RamSize("8GB")) //Then - assertEquals(goodPhone1.ram.uuid, goodPhone2.ram.uuid); - assertTrue(goodPhone1.ram instanceof DDR3Ram); + assertEquals(goodPhone1.ram!!.uuid, goodPhone2.ram!!.uuid) + assertTrue(goodPhone1.ram is DDR3Ram) } @Test - public void createGoodPhoneFromProtoTest() { + fun createGoodPhoneFromProtoTest() { //Given - PhoneComponent DI = Stone.createComponent(PhoneComponent.class); - PhoneExtComponent DIPro = Stone.createComponent(PhoneExtComponent.class); - DIPro.extOf(DI); + val DI: PhoneComponent = PhoneComponentStoneComponent() + val DIPro: PhoneExtComponent = PhoneExtComponentStoneComponent() + DIPro.extOf(DI) - GoodPhone goodPhone = new GoodPhone(); + val goodPhone = GoodPhone() //When - DI.inject(goodPhone, goodPhone.lifeCycleOwner, new DataStorageSize("120GB"), new RamSize("8GB")); + DI.inject(goodPhone, goodPhone.lifeCycleOwner, DataStorageSize("120GB"), RamSize("8GB")) //Then - assertEquals("120GB", goodPhone.dataStorage.size); - assertEquals("8GB", goodPhone.ram.size); - assertTrue(goodPhone.ram instanceof DDR3Ram); + assertEquals("120GB", goodPhone.dataStorage!!.size) + assertEquals("8GB", goodPhone.ram!!.size) + assertTrue(goodPhone.ram is DDR3Ram) } @Test - public void createGoodPhoneFromProTest() { + fun createGoodPhoneFromProTest() { //Given - PhoneComponent DI = Stone.createComponent(PhoneComponent.class); - PhoneExtComponent DIPro = Stone.createComponent(PhoneExtComponent.class); - DIPro.extOf(DI); + val DI: PhoneComponent = PhoneComponentStoneComponent() + val DIPro: PhoneExtComponent = PhoneExtComponentStoneComponent() + DIPro.extOf(DI) - GoodPhone goodPhone = new GoodPhone(); + val goodPhone = GoodPhone() //When - DIPro.inject(goodPhone, goodPhone.lifeCycleOwner, new DataStorageSize("120GB"), new RamSize("8GB")); + DIPro.inject(goodPhone, goodPhone.lifeCycleOwner, DataStorageSize("120GB"), RamSize("8GB")) //Then - assertEquals("120GB", goodPhone.dataStorage.size); - assertEquals("8GB", goodPhone.ram.size); - assertTrue(goodPhone.ram instanceof DDR3Ram); + assertEquals("120GB", goodPhone.dataStorage!!.size) + assertEquals("8GB", goodPhone.ram!!.size) + assertTrue(goodPhone.ram is DDR3Ram) } @Test - public void createGoodPhoneFromProExtTest() { + fun createGoodPhoneFromProExtTest() { //Given - PhoneComponent DI = Stone.createComponent(PhoneComponent.class); - PhoneExtComponent DIPro = Stone.createComponent(PhoneExtComponent.class); - DIPro.extOf(DI); - GoodPhone goodPhone = new GoodPhone(); + val DI: PhoneComponent = PhoneComponentStoneComponent() + val DIPro: PhoneExtComponent = PhoneExtComponentStoneComponent() + DIPro.extOf(DI) + val goodPhone = GoodPhone() //When - DIPro.injectExt(goodPhone, goodPhone.lifeCycleOwner, new DataStorageSize("120GB"), new RamSize("8GB")); + DIPro.injectExt(goodPhone, goodPhone.lifeCycleOwner, DataStorageSize("120GB"), RamSize("8GB")) //Then - assertEquals("120GB", goodPhone.dataStorage.size); - assertEquals("8GB", goodPhone.ram.size); - assertTrue(goodPhone.ram instanceof DDR3Ram); + assertEquals("120GB", goodPhone.dataStorage!!.size) + assertEquals("8GB", goodPhone.ram!!.size) + assertTrue(goodPhone.ram is DDR3Ram) } @Test - public void cacheInjectedPhoneTest() { + fun cacheInjectedPhoneTest() { //Given - PhoneComponent DI = Stone.createComponent(PhoneComponent.class); - PhoneExtComponent DIPro = Stone.createComponent(PhoneExtComponent.class); - DIPro.extOf(DI); - GoodPhone goodPhone1 = new GoodPhone(); - GoodPhone goodPhone2 = new GoodPhone(); + val DI: PhoneComponent = PhoneComponentStoneComponent() + val DIPro: PhoneExtComponent = PhoneExtComponentStoneComponent() + DIPro.extOf(DI) + val goodPhone1 = GoodPhone() + val goodPhone2 = GoodPhone() //When - DI.inject(goodPhone1, goodPhone1.lifeCycleOwner, new DataStorageSize("120GB"), new RamSize("8GB")); - DIPro.inject(goodPhone2, goodPhone2.lifeCycleOwner, new DataStorageSize("120GB"), new RamSize("8GB")); + DI.inject(goodPhone1, goodPhone1.lifeCycleOwner, DataStorageSize("120GB"), RamSize("8GB")) + DIPro.inject(goodPhone2, goodPhone2.lifeCycleOwner, DataStorageSize("120GB"), RamSize("8GB")) //Then - assertEquals(goodPhone1.ram.uuid, goodPhone2.ram.uuid); - assertTrue(goodPhone1.ram instanceof DDR3Ram); + assertEquals(goodPhone1.ram!!.uuid, goodPhone2.ram!!.uuid) + assertTrue(goodPhone1.ram is DDR3Ram) } } diff --git a/tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/identifiers/TechFactoryComponentFromProTests.kt b/tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/identifiers/TechFactoryComponentFromProTests.kt index 9ced5c86..1c6d8253 100644 --- a/tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/identifiers/TechFactoryComponentFromProTests.kt +++ b/tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/identifiers/TechFactoryComponentFromProTests.kt @@ -1,118 +1,117 @@ -package com.dirgub.klee0kai.stone.text_ext.identifiers; - -import com.github.klee0kai.stone.Stone; -import com.github.klee0kai.test.di.base_phone.identifiers.PhoneOsType; -import com.github.klee0kai.test.di.base_phone.identifiers.PhoneOsVersion; -import com.github.klee0kai.test.di.base_phone.identifiers.RamSize; -import com.github.klee0kai.test.di.techfactory.TechFactoryComponent; -import com.github.klee0kai.test.tech.components.OperationSystem; -import com.github.klee0kai.test.tech.components.Ram; -import com.github.klee0kai.test_ext.inject.di.techfactory.TechFactoryExtComponent; -import com.github.klee0kai.test_ext.inject.tech.components.DDR3Ram; -import org.junit.jupiter.api.Test; - -import static org.junit.jupiter.api.Assertions.*; - -public class TechFactoryComponentFromProTests { +package com.dirgub.klee0kai.stone.text_ext.identifiers + +import com.github.klee0kai.test.di.base_phone.identifiers.PhoneOsType +import com.github.klee0kai.test.di.base_phone.identifiers.PhoneOsVersion +import com.github.klee0kai.test.di.base_phone.identifiers.RamSize +import com.github.klee0kai.test.di.techfactory.TechFactoryComponent +import com.github.klee0kai.test.di.techfactory.TechFactoryComponentStoneComponent +import com.github.klee0kai.test.tech.components.OperationSystem +import com.github.klee0kai.test.tech.components.Ram +import com.github.klee0kai.test_ext.inject.di.techfactory.TechFactoryExtComponent +import com.github.klee0kai.test_ext.inject.di.techfactory.TechFactoryExtComponentStoneComponent +import com.github.klee0kai.test_ext.inject.tech.components.DDR3Ram +import org.junit.jupiter.api.Assertions.* +import org.junit.jupiter.api.Test +import org.junit.jupiter.api.assertNull + +class TechFactoryComponentFromProTests { @Test - public void nonArgProvideTest() { + fun nonArgProvideTest() { //Given - TechFactoryComponent DI = Stone.createComponent(TechFactoryComponent.class); - TechFactoryExtComponent DIPro = Stone.createComponent(TechFactoryExtComponent.class); - DIPro.extOf(DI); + val DI: TechFactoryComponent = TechFactoryComponentStoneComponent() + val DIPro: TechFactoryExtComponent = TechFactoryExtComponentStoneComponent() + DIPro.extOf(DI) //When - Ram ram = DIPro.ram(); + val ram: Ram? = DIPro.ram() //Then - assertEquals("default", ram.size); - assertTrue(ram instanceof DDR3Ram); + assertEquals("default", ram!!.size) + assertTrue(ram is DDR3Ram) } @Test - public void singleArgProvideTest() { + fun singleArgProvideTest() { //Given - TechFactoryComponent DI = Stone.createComponent(TechFactoryComponent.class); - TechFactoryExtComponent DIPro = Stone.createComponent(TechFactoryExtComponent.class); - DIPro.extOf(DI); + val DI: TechFactoryComponent = TechFactoryComponentStoneComponent() + val DIPro: TechFactoryExtComponent = TechFactoryExtComponentStoneComponent() + DIPro.extOf(DI) //When - Ram ram = DIPro.ram(new RamSize("4G")); + val ram: Ram? = DIPro.ram(RamSize("4G")) //Then - assertEquals("4G", ram.size); - assertTrue(ram instanceof DDR3Ram); + assertEquals("4G", ram!!.size) + assertTrue(ram is DDR3Ram) } @Test - public void nullGenerateArgProvideTest() { + fun nullGenerateArgProvideTest() { //Given - TechFactoryComponent DI = Stone.createComponent(TechFactoryComponent.class); - TechFactoryExtComponent DIPro = Stone.createComponent(TechFactoryExtComponent.class); - DIPro.extOf(DI); + val DI: TechFactoryComponent = TechFactoryComponentStoneComponent() + val DIPro: TechFactoryExtComponent = TechFactoryExtComponentStoneComponent() + DIPro.extOf(DI) //When - OperationSystem os = DIPro.phoneOs(); + val os: OperationSystem? = DIPro.phoneOs() //Then: should pass null missing args - assertNull(os.phoneOsType); // missing args - assertEquals("default", os.version.version); // default from constructor + assertNull(os!!.phoneOsType) // missing args + assertEquals("default", os.version!!.version) // default from constructor } @Test - public void coupleArgsProvideTest() { + fun coupleArgsProvideTest() { //Given - TechFactoryComponent DI = Stone.createComponent(TechFactoryComponent.class); - TechFactoryExtComponent DIPro = Stone.createComponent(TechFactoryExtComponent.class); - DIPro.extOf(DI); + val DI: TechFactoryComponent = TechFactoryComponentStoneComponent() + val DIPro: TechFactoryExtComponent = TechFactoryExtComponentStoneComponent() + DIPro.extOf(DI) //When - OperationSystem os = DIPro.phoneOs(PhoneOsType.Ios, new PhoneOsVersion("11")); + val os: OperationSystem? = DIPro.phoneOs(PhoneOsType.Ios, PhoneOsVersion("11")) //Then - assertEquals(PhoneOsType.Ios, os.phoneOsType); - assertEquals("11", os.version.version); + assertEquals(PhoneOsType.Ios, os!!.phoneOsType) + assertEquals("11", os.version!!.version) } @Test - public void differentCreateTest() { + fun differentCreateTest() { //Given - TechFactoryComponent DI = Stone.createComponent(TechFactoryComponent.class); - TechFactoryExtComponent DIPro = Stone.createComponent(TechFactoryExtComponent.class); - DIPro.extOf(DI); + val DI: TechFactoryComponent = TechFactoryComponentStoneComponent() + val DIPro: TechFactoryExtComponent = TechFactoryExtComponentStoneComponent() + DIPro.extOf(DI) //When - Ram ram8Gb = DIPro.ram(new RamSize("8GB")); - Ram ram8Gb2 = DIPro.ram(new RamSize("8GB")); + val ram8Gb: Ram? = DIPro.ram(RamSize("8GB")) + val ram8Gb2: Ram? = DIPro.ram(RamSize("8GB")) //Then: created components are different - assertEquals("8GB", ram8Gb.size); - assertNotEquals(ram8Gb.uuid, ram8Gb2.uuid); - assertTrue(ram8Gb instanceof DDR3Ram); - assertTrue(ram8Gb2 instanceof DDR3Ram); + assertEquals("8GB", ram8Gb!!.size) + assertNotEquals(ram8Gb!!.uuid, ram8Gb2!!.uuid) + assertTrue(ram8Gb is DDR3Ram) + assertTrue(ram8Gb2 is DDR3Ram) } @Test - public void enumDifferentTest() { + fun enumDifferentTest() { //Given - TechFactoryComponent DI = Stone.createComponent(TechFactoryComponent.class); - TechFactoryExtComponent DIPro = Stone.createComponent(TechFactoryExtComponent.class); - DIPro.extOf(DI); + val DI = TechFactoryComponentStoneComponent() + val DIPro: TechFactoryExtComponent = TechFactoryExtComponentStoneComponent() + DIPro.extOf(DI) //When - OperationSystem android = DIPro.phoneOs(PhoneOsType.Android); - OperationSystem android2 = DIPro.phoneOs(PhoneOsType.Android); - OperationSystem osNull = DIPro.phoneOs(null); + val android: OperationSystem? = DIPro.phoneOs(PhoneOsType.Android) + val android2: OperationSystem? = DIPro.phoneOs(PhoneOsType.Android) + val osNull: OperationSystem? = DIPro.phoneOs(null) //Then: created components are different - assertNotEquals(android.uuid, osNull.uuid); - assertNotEquals(android.uuid, android2.uuid); + assertNotEquals(android!!.uuid, osNull!!.uuid) + assertNotEquals(android!!.uuid, android2!!.uuid) } - - } diff --git a/tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/identifiers/TechFactoryComponentOverriddenTests.kt b/tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/identifiers/TechFactoryComponentOverriddenTests.kt index 6c3570db..e5316337 100644 --- a/tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/identifiers/TechFactoryComponentOverriddenTests.kt +++ b/tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/identifiers/TechFactoryComponentOverriddenTests.kt @@ -1,118 +1,118 @@ -package com.dirgub.klee0kai.stone.text_ext.identifiers; - -import com.github.klee0kai.stone.Stone; -import com.github.klee0kai.test.di.base_phone.identifiers.PhoneOsType; -import com.github.klee0kai.test.di.base_phone.identifiers.PhoneOsVersion; -import com.github.klee0kai.test.di.base_phone.identifiers.RamSize; -import com.github.klee0kai.test.di.techfactory.TechFactoryComponent; -import com.github.klee0kai.test.tech.components.OperationSystem; -import com.github.klee0kai.test.tech.components.Ram; -import com.github.klee0kai.test_ext.inject.di.techfactory.TechFactoryExtComponent; -import com.github.klee0kai.test_ext.inject.tech.components.DDR3Ram; -import org.junit.jupiter.api.Test; - -import static org.junit.jupiter.api.Assertions.*; - -public class TechFactoryComponentOverriddenTests { +package com.dirgub.klee0kai.stone.text_ext.identifiers + +import com.github.klee0kai.test.di.base_phone.identifiers.PhoneOsType +import com.github.klee0kai.test.di.base_phone.identifiers.PhoneOsVersion +import com.github.klee0kai.test.di.base_phone.identifiers.RamSize +import com.github.klee0kai.test.di.techfactory.TechFactoryComponent +import com.github.klee0kai.test.di.techfactory.TechFactoryComponentStoneComponent +import com.github.klee0kai.test.tech.components.OperationSystem +import com.github.klee0kai.test.tech.components.Ram +import com.github.klee0kai.test_ext.inject.di.techfactory.TechFactoryExtComponent +import com.github.klee0kai.test_ext.inject.di.techfactory.TechFactoryExtComponentStoneComponent +import com.github.klee0kai.test_ext.inject.tech.components.DDR3Ram +import org.junit.jupiter.api.Assertions.* +import org.junit.jupiter.api.Test +import org.junit.jupiter.api.assertNull + +class TechFactoryComponentOverriddenTests { @Test - public void nonArgProvideTest() { + fun nonArgProvideTest() { //Given - TechFactoryComponent DI = Stone.createComponent(TechFactoryComponent.class); - TechFactoryExtComponent DIPro = Stone.createComponent(TechFactoryExtComponent.class); - DIPro.extOf(DI); + val DI: TechFactoryComponent = TechFactoryComponentStoneComponent() + val DIPro: TechFactoryExtComponent = TechFactoryExtComponentStoneComponent() + DIPro.extOf(DI) //When - Ram ram = DI.ram(); + val ram: Ram? = DI.ram() //Then - assertEquals("default", ram.size); - assertTrue(ram instanceof DDR3Ram); + assertEquals("default", ram!!.size) + assertTrue(ram is DDR3Ram) } @Test - public void singleArgProvideTest() { + fun singleArgProvideTest() { //Given - TechFactoryComponent DI = Stone.createComponent(TechFactoryComponent.class); - TechFactoryExtComponent DIPro = Stone.createComponent(TechFactoryExtComponent.class); - DIPro.extOf(DI); + val DI: TechFactoryComponent = TechFactoryComponentStoneComponent() + val DIPro: TechFactoryExtComponent = TechFactoryExtComponentStoneComponent() + DIPro.extOf(DI) //When - Ram ram = DI.ram(new RamSize("4G")); + val ram: Ram? = DI.ram(RamSize("4G")) //Then - assertEquals("4G", ram.size); - assertTrue(ram instanceof DDR3Ram); + assertEquals("4G", ram!!.size) + assertTrue(ram is DDR3Ram) } @Test - public void nullGenerateArgProvideTest() { + fun nullGenerateArgProvideTest() { //Given - TechFactoryComponent DI = Stone.createComponent(TechFactoryComponent.class); - TechFactoryExtComponent DIPro = Stone.createComponent(TechFactoryExtComponent.class); - DIPro.extOf(DI); + val DI: TechFactoryComponent = TechFactoryComponentStoneComponent() + val DIPro: TechFactoryExtComponent = TechFactoryExtComponentStoneComponent() + DIPro.extOf(DI) //When - OperationSystem os = DI.phoneOs(); + val os: OperationSystem? = DI.phoneOs() //Then: should pass null missing args - assertNull(os.phoneOsType); // missing args - assertEquals("default", os.version.version); // default from constructor + assertNull(os!!.phoneOsType) // missing args + assertEquals("default", os.version!!.version) // default from constructor } @Test - public void coupleArgsProvideTest() { + fun coupleArgsProvideTest() { //Given - TechFactoryComponent DI = Stone.createComponent(TechFactoryComponent.class); - TechFactoryExtComponent DIPro = Stone.createComponent(TechFactoryExtComponent.class); - DIPro.extOf(DI); + val DI: TechFactoryComponent = TechFactoryComponentStoneComponent() + val DIPro: TechFactoryExtComponent = TechFactoryExtComponentStoneComponent() + DIPro.extOf(DI) //When - OperationSystem os = DI.phoneOs(PhoneOsType.Ios, new PhoneOsVersion("11")); + val os: OperationSystem? = DI.phoneOs(PhoneOsType.Ios, PhoneOsVersion("11")) //Then - assertEquals(PhoneOsType.Ios, os.phoneOsType); - assertEquals("11", os.version.version); + assertEquals(PhoneOsType.Ios, os!!.phoneOsType) + assertEquals("11", os.version!!.version) } @Test - public void differentCreateTest() { + fun differentCreateTest() { //Given - TechFactoryComponent DI = Stone.createComponent(TechFactoryComponent.class); - TechFactoryExtComponent DIPro = Stone.createComponent(TechFactoryExtComponent.class); - DIPro.extOf(DI); + val DI: TechFactoryComponent = TechFactoryComponentStoneComponent() + val DIPro: TechFactoryExtComponent = TechFactoryExtComponentStoneComponent() + DIPro.extOf(DI) //When - Ram ram8Gb = DI.ram(new RamSize("8GB")); - Ram ram8Gb2 = DI.ram(new RamSize("8GB")); + val ram8Gb: Ram? = DI.ram(RamSize("8GB")) + val ram8Gb2: Ram? = DI.ram(RamSize("8GB")) //Then: created components are different - assertEquals("8GB", ram8Gb.size); - assertNotEquals(ram8Gb.uuid, ram8Gb2.uuid); - assertTrue(ram8Gb instanceof DDR3Ram); - assertTrue(ram8Gb2 instanceof DDR3Ram); + assertEquals("8GB", ram8Gb!!.size) + assertNotEquals(ram8Gb.uuid, ram8Gb2!!.uuid) + assertTrue(ram8Gb is DDR3Ram) + assertTrue(ram8Gb2 is DDR3Ram) } @Test - public void enumDifferentTest() { + fun enumDifferentTest() { //Given - TechFactoryComponent DI = Stone.createComponent(TechFactoryComponent.class); - TechFactoryExtComponent DIPro = Stone.createComponent(TechFactoryExtComponent.class); - DIPro.extOf(DI); + val DI: TechFactoryComponent = TechFactoryComponentStoneComponent() + val DIPro: TechFactoryExtComponent = TechFactoryExtComponentStoneComponent() + DIPro.extOf(DI) //When - OperationSystem android = DI.phoneOs(PhoneOsType.Android); - OperationSystem android2 = DI.phoneOs(PhoneOsType.Android); - OperationSystem osNull = DI.phoneOs(null); + val android: OperationSystem? = DI.phoneOs(PhoneOsType.Android) + val android2: OperationSystem? = DI.phoneOs(PhoneOsType.Android) + val osNull: OperationSystem? = DI.phoneOs(null) //Then: created components are different - assertNotEquals(android.uuid, osNull.uuid); - assertNotEquals(android.uuid, android2.uuid); + assertNotEquals(android!!.uuid, osNull!!.uuid) + assertNotEquals(android.uuid, android2!!.uuid) } - } From dfc8ecb958985dccb1e521b7d7a9caa454fe75a8 Mon Sep 17 00:00:00 2001 From: klee0kai Date: Fri, 19 Dec 2025 23:34:53 +0100 Subject: [PATCH 078/122] fix test ext --- .../hiddenmodule/GenHiddenModuleProcessor.kt | 109 ++++++++++-------- .../ksp/target/module/GenModuleProcessor.kt | 11 +- 2 files changed, 70 insertions(+), 50 deletions(-) diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/hiddenmodule/GenHiddenModuleProcessor.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/hiddenmodule/GenHiddenModuleProcessor.kt index 895c31bd..c24cd008 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/hiddenmodule/GenHiddenModuleProcessor.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/hiddenmodule/GenHiddenModuleProcessor.kt @@ -12,6 +12,7 @@ import com.github.klee0kai.stone.annotations.component.GcAllScope import com.github.klee0kai.stone.annotations.module.BindInstance import com.github.klee0kai.thekey.stone.ksp.exceptions.forEachFun import com.github.klee0kai.thekey.stone.ksp.helpers.* +import com.github.klee0kai.thekey.stone.ksp.helpers.annotations.findComponentAnnotation import com.github.klee0kai.thekey.stone.ksp.helpers.itemholder.ItemHolderCodeHelper import com.github.klee0kai.thekey.stone.ksp.helpers.itemholder.of import com.github.klee0kai.thekey.stone.ksp.helpers.itemholder.toItemCacheType @@ -22,6 +23,9 @@ import com.github.klee0kai.thekey.stone.ksp.ksp.arch.SymbolsToProcess import com.github.klee0kai.thekey.stone.ksp.ksp.arch.TargetFileProcessor import com.github.klee0kai.thekey.stone.ksp.ksp.getAllMethods import com.github.klee0kai.thekey.stone.ksp.poet.* +import com.github.klee0kai.thekey.stone.ksp.target.component.BindInstanceType +import com.github.klee0kai.thekey.stone.ksp.target.component.collectWrapHelper +import com.github.klee0kai.thekey.stone.ksp.target.component.isBindInstanceMethod import com.github.klee0kai.thekey.stone.ksp.target.module.GenModuleProcessor.Companion.appliedLocalFieldName import com.github.klee0kai.thekey.stone.ksp.target.module.GenModuleProcessor.Companion.bindMethodName import com.github.klee0kai.thekey.stone.ksp.target.module.GenModuleProcessor.Companion.clearNullsMethodName @@ -31,10 +35,6 @@ import com.github.klee0kai.thekey.stone.ksp.target.module.GenModuleProcessor.Com import com.github.klee0kai.thekey.stone.ksp.target.module.GenModuleProcessor.Companion.overridedModuleFieldName import com.github.klee0kai.thekey.stone.ksp.target.module.GenModuleProcessor.Companion.switchRefMethodName import com.github.klee0kai.thekey.stone.ksp.target.module.GenModuleProcessor.Companion.updateBindInstancesFrom -import com.github.klee0kai.thekey.stone.ksp.target.component.BindInstanceType -import com.github.klee0kai.thekey.stone.ksp.target.component.collectComponentGraph -import com.github.klee0kai.thekey.stone.ksp.target.component.collectWrapHelper -import com.github.klee0kai.thekey.stone.ksp.target.component.isBindInstanceMethod import com.google.devtools.ksp.KspExperimental import com.google.devtools.ksp.containingFile import com.google.devtools.ksp.getAnnotationsByType @@ -81,20 +81,21 @@ class GenHiddenModuleProcessor : TargetFileProcessor { val genHiddenModuleCl = componentCl.hiddenModuleStoneClName val identifierTypes = componentCl.allIdentifierTypes.toList() val wrapHelper = componentCl.collectWrapHelper() - val modulesGraph = componentCl.collectComponentGraph() val codeBlocks = DelayedCodeBlocks() - val genCacheControlClassName = genHiddenModuleCl.cacheControlStoneClName val fileSpec = genFileSpec(genHiddenModuleCl.packageName, genHiddenModuleCl.simpleName) { genLibComment() genClass(genHiddenModuleCl) { addSuperinterface(IModule::class) - addSuperinterface(genCacheControlClassName) + componentCl.allParentDeclarations + .filter { it.findComponentAnnotation().any() } + .forEach { parentComponentCl -> addSuperinterface(parentComponentCl.hiddenModuleStoneClName.cacheControlStoneClName) } + val functions = validSymbol.getAllMethods(false, false, "") functions.forEachFun { funIdx, function -> - + val itemHolderIdx = funIdx + 1 val bindAnn = function.getAnnotationsByType(BindInstance::class).firstOrNull() val idArguments = function.parameters.identifierParameters(identifierTypes) @@ -108,7 +109,7 @@ class GenHiddenModuleProcessor : TargetFileProcessor { return@forEachFun val itemHolderCodeHelper = ItemHolderCodeHelper.of( - fieldName = "${function.simpleName.asString()}$funIdx", + fieldName = "${function.simpleName.asString()}$itemHolderIdx", returnType = returnType, idArguments = idArguments, cacheType = bindAnn.cache.toItemCacheType(), @@ -347,27 +348,35 @@ class GenHiddenModuleProcessor : TargetFileProcessor { addParameter("m", IModule::class) addStatement("if (m == this) return") - val cacheControlCl = componentCl.hiddenModuleStoneClName.cacheControlStoneClName - beginControlFlow("if ( m is %T )", cacheControlCl) - addStatement("val module = m as %T", cacheControlCl) - componentCl.getAllMethods( - includeObjectMethods = false, - allowDoubles = false, - exceptNames = arrayOf(""), - ).forEach { protoProvideMethod -> - if (protoProvideMethod.isBindInstanceMethod != BindInstanceType.BindInstanceAndProvide) { - return@forEach - } + componentCl.allParentDeclarations + .filter { it.findComponentAnnotation().any() } + .forEach { parentComponentCl -> + val cacheControlCl = parentComponentCl.hiddenModuleStoneClName.cacheControlStoneClName + beginControlFlow("if ( m is %T )", cacheControlCl) + addStatement("val module = m as %T", cacheControlCl) + + parentComponentCl.getAllMethods( + includeObjectMethods = false, + allowDoubles = false, + exceptNames = arrayOf(""), + ).forEach { protoProvideMethod -> + if (protoProvideMethod.isBindInstanceMethod != BindInstanceType.BindInstanceAndProvide) { + return@forEach + } - val cacheControlMethod = protoProvideMethod.cacheControlMethodName + val cacheControlMethod = protoProvideMethod.cacheControlMethodName + + addStatement( + "%L( %T.setIfNullValueAction( module.%L( %T.getValueAction ) ) )", + cacheControlMethod, CacheAction::class, + cacheControlMethod, CacheAction::class, + ) + } + + addStatement("return") + endControlFlow() + } - addStatement( - "%L( %T.setIfNullValueAction( module.%L( %T.getValueAction ) ) )", - cacheControlMethod, CacheAction::class, - cacheControlMethod, CacheAction::class, - ) - } - endControlFlow() } genFun(updateBindInstancesFrom) { @@ -375,27 +384,33 @@ class GenHiddenModuleProcessor : TargetFileProcessor { addParameter("m", IModule::class) addStatement("if (m == this) return") - val cacheControlCl = componentCl.hiddenModuleStoneClName.cacheControlStoneClName - beginControlFlow("if ( m is %T )", cacheControlCl) - addStatement("val module = m as %T", cacheControlCl) - componentCl.getAllMethods( - includeObjectMethods = false, - allowDoubles = false, - exceptNames = arrayOf(""), - ).forEach { protoProvideMethod -> - if (protoProvideMethod.isBindInstanceMethod != BindInstanceType.BindInstanceAndProvide) { - return@forEach - } + componentCl.allParentDeclarations + .filter { it.findComponentAnnotation().any() } + .forEach { parentComponentCl -> + val cacheControlCl = parentComponentCl.hiddenModuleStoneClName.cacheControlStoneClName + beginControlFlow("if ( m is %T )", cacheControlCl) + addStatement("val module = m as %T", cacheControlCl) + parentComponentCl.getAllMethods( + includeObjectMethods = false, + allowDoubles = false, + exceptNames = arrayOf(""), + ).forEach { protoProvideMethod -> + if (protoProvideMethod.isBindInstanceMethod != BindInstanceType.BindInstanceAndProvide) { + return@forEach + } - val cacheControlMethod = protoProvideMethod.cacheControlMethodName + val cacheControlMethod = protoProvideMethod.cacheControlMethodName + + addStatement( + "%L( %T.setValueAction( module.%L( %T.getValueAction ) ) )", + cacheControlMethod, CacheAction::class, + cacheControlMethod, CacheAction::class, + ) + } + addStatement("return") + endControlFlow() + } - addStatement( - "%L( %T.setValueAction( module.%L( %T.getValueAction ) ) )", - cacheControlMethod, CacheAction::class, - cacheControlMethod, CacheAction::class, - ); - } - endControlFlow() } genFun(clearNullsMethodName) { diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/module/GenModuleProcessor.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/module/GenModuleProcessor.kt index bf2d1828..b22fc6ef 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/module/GenModuleProcessor.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/module/GenModuleProcessor.kt @@ -115,12 +115,17 @@ class GenModuleProcessor : TargetFileProcessor { superclass(moduleCl.toClassName()) } addSuperinterface(IModule::class) - addSuperinterface(moduleCl.toClassName().cacheControlStoneClName) + + moduleCl.allParentDeclarations + .filter { it.getAnnotationsByType(Module::class).any() } + .forEach { parentModuleCl -> addSuperinterface(parentModuleCl.toClassName().cacheControlStoneClName) } + addModifiers(KModifier.OPEN) val codeBlocks = DelayedCodeBlocks() validSymbol.getAllMethods(false, false, "") .forEachFun { funIdx, function -> + val holderIdx = funIdx + 1 val bindAnn = function.getAnnotationsByType(BindInstance::class).firstOrNull() val provideAnn = function.getAnnotationsByType(Provide::class).firstOrNull() val idArguments = function.parameters.identifierParameters(identifierTypes) @@ -136,7 +141,7 @@ class GenModuleProcessor : TargetFileProcessor { when { bindAnn != null -> { val itemHolderCodeHelper = ItemHolderCodeHelper.of( - fieldName = "${function.simpleName.asString()}$funIdx", + fieldName = "${function.simpleName.asString()}$holderIdx", returnType = returnType, idArguments = idArguments, cacheType = bindAnn.cache.toItemCacheType(), @@ -200,7 +205,7 @@ class GenModuleProcessor : TargetFileProcessor { else -> { val itemHolderCodeHelper = ItemHolderCodeHelper.of( - fieldName = "${function.simpleName.asString()}$funIdx", + fieldName = "${function.simpleName.asString()}$holderIdx", returnType = returnType, idArguments = idArguments, cacheType = provideAnn.cache.toItemCacheType() ?: return@forEachFun, From 0a6a8317cc5ca286d180c736d8a040efcc2881c9 Mon Sep 17 00:00:00 2001 From: klee0kai Date: Sat, 20 Dec 2025 08:46:51 +0100 Subject: [PATCH 079/122] test_wraps migrate to multiplatform lib --- settings.gradle.kts | 1 - .../klee0kai/thekey/stone/ksp/Processor.kt | 1 + tests_wraps/build.gradle.kts | 15 - .../di/inject/CarBoxedInjectComponent.java | 29 -- .../boxed/di/inject/CarBoxedInjectModule.java | 59 ---- .../klee0kai/test/boxed/model/CarBox.java | 10 - .../klee0kai/test/boxed/model/CarBoxed.java | 38 -- .../test/boxed/model/CarBoxedInject.java | 34 -- .../test/boxed/model/CarBoxedInjectLists.java | 36 -- .../boxed/model/CarBoxedInjectProvider.java | 36 -- .../car/di/bestOf/blue/BlueCarComponent.java | 18 - .../car/di/bestOf/both/BothCarComponent.java | 21 -- .../car/di/bestOf/both/BothCarModule.java | 56 --- .../car/di/bestOf/red/RedCarComponent.java | 18 - .../bindinstance/simple/CarBindComponent.java | 52 --- .../di/bindinstance/simple/CarBindModule.java | 24 -- .../di/cachecontrol/gc/BumperGcModule.java | 43 --- .../di/cachecontrol/gc/CarGcComponent.java | 86 ----- .../car/di/cachecontrol/gc/WheelGcModule.java | 30 -- .../cachecontrol/gc/WheelMappedGcModule.java | 38 -- .../gc/WheelMultiMappedGcModule.java | 38 -- .../di/cachecontrol/gc/WindowGcModule.java | 41 --- .../cachecontrol/gc/WindowMappedGcModule.java | 41 --- .../gc/WindowMultiMappedGcModule.java | 41 --- .../gc/scopes/GcBumperRedScope.java | 14 - .../cachecontrol/gc/scopes/GcBumperScope.java | 14 - .../cachecontrol/gc/scopes/GcWheelScope.java | 14 - .../cachecontrol/gc/scopes/GcWindowScope.java | 14 - .../swcache/CarSwCacheComponent.java | 88 ----- .../car/di/inject/CarInjectComponent.java | 32 -- .../test/car/di/inject/CarInjectModule.java | 47 --- .../lists/cached/CarMultiCachedComponent.java | 31 -- .../di/lists/cached/CarMultiCachedModule.java | 55 --- .../di/lists/factory/CarMultiComponent.java | 38 -- .../car/di/lists/factory/CarMultiModule.java | 57 --- .../test/car/di/qualifiers/CarQCModule.java | 150 -------- .../test/car/di/qualifiers/CarQComponent.java | 62 ---- .../test/car/di/qualifiers/CarQPModule.java | 46 --- .../qualifiers/BumperQualifier.java | 22 -- .../di/qualifiers/qualifiers/MyQualifier.java | 14 - .../qualifiers/MyQualifierMulti.java | 27 -- .../qualifiers/MyQualifierWithString.java | 17 - .../di/qualifiers/qualifiers/WheelCount.java | 16 - .../create/CarWrappedCreateComponent.java | 44 --- .../create/CarWrappedCreateModule.java | 30 -- .../custom/CarCustomWrapperModule.java | 28 -- .../custom/CarCustomWrappersComponent.java | 24 -- .../di/wrapped/custom/wrappers/CarLazy.java | 20 -- .../wrapped/custom/wrappers/CarProvide.java | 17 - .../custom/wrappers/CarProviderWrapper.java | 22 -- .../di/wrapped/custom/wrappers/CarRef.java | 15 - .../wrapped/custom/wrappers/CarWrapper.java | 17 - .../klee0kai/test/car/model/Bumper.java | 15 - .../github/klee0kai/test/car/model/Car.java | 36 -- .../klee0kai/test/car/model/CarInject.java | 31 -- .../test/car/model/CarInjectLists.java | 32 -- .../test/car/model/CarInjectProvider.java | 33 -- .../test/car/model/CarsInjectQualifiers.java | 112 ------ .../github/klee0kai/test/car/model/Wheel.java | 15 - .../klee0kai/test/car/model/Window.java | 13 - .../inject/CarBoxedInjectMethodTests.java | 159 --------- .../boxed/inject/CarBoxedInjectTests.java | 158 --------- .../inject/CarBoxedProtectInjectedTests.java | 91 ----- .../bindinstance/simple/BindBumperTests.java | 72 ---- .../simple/BindWheelRefTests.java | 93 ----- .../bindinstance/simple/BindWheelTests.java | 76 ---- .../simple/BindWindowCollectionRefTests.java | 137 -------- .../simple/BindWindowCollectionTests.java | 105 ------ .../bindinstance/simple/BindWindowTests.java | 75 ---- .../stone/test/car/bluecar/BlueCarTest.java | 98 ------ .../gc/BumperGcResusableTests.java | 222 ------------ .../car/cachecontrol/gc/BumperGcTests.java | 216 ------------ .../car/cachecontrol/gc/WheelGcTests.java | 203 ----------- .../cachecontrol/gc/WheelMappedGcTests.java | 203 ----------- .../gc/WheelMultiMappedGcTests.java | 203 ----------- .../cachecontrol/gc/WheelReusableGcTests.java | 195 ----------- .../car/cachecontrol/gc/WindowGcTests.java | 217 ------------ .../cachecontrol/gc/WindowMappedGcTests.java | 216 ------------ .../gc/WindowMappedPartialGcTests.java | 97 ------ .../gc/WindowMappedReusableGcTests.java | 326 ------------------ .../gc/WindowMultiMappedGcTests.java | 216 ------------ .../gc/WindowMultiMappedPartialGcTests.java | 97 ------ .../gc/WindowMultiMappedReusableGcTests.java | 317 ----------------- .../cachecontrol/gc/WindowPartialGcTests.java | 114 ------ .../swcache/BumperSwitchCacheTests.java | 226 ------------ .../swcache/WheelSwitchCacheTests.java | 238 ------------- .../swcache/WindowMappedSwitchCacheTests.java | 250 -------------- .../WindowMultiMappedSwitchCacheTests.java | 248 ------------- .../swcache/WindowSwitchCacheTests.java | 208 ----------- .../test/car/inject/CarInjectMethodTests.java | 152 -------- .../test/car/inject/CarInjectMixedTests.java | 89 ----- .../stone/test/car/inject/CarInjectTests.java | 150 -------- .../car/inject/CarProtectInjectedTests.java | 91 ----- .../test/car/muti/MultiCachedProvideTest.java | 209 ----------- .../stone/test/car/muti/MultiProvideTest.java | 206 ----------- ...CarInjectAllMethodsWithQualifiersTest.java | 204 ----------- .../CarInjectAllWithQualifiersTest.java | 204 ----------- .../CarInjectMethodWithQualifiersTest.java | 222 ------------ .../CarInjectWithQualifiersTest.java | 222 ------------ .../CarProvideAllWithQualifiersTests.java | 193 ----------- .../CarProvideWithQualifiersTests.java | 153 -------- .../car/wrapper/CarSingleWrapperTests.java | 234 ------------- .../car/wrapper/CurCustomWrapperTests.java | 89 ----- tests_wraps_kotlin/build.gradle.kts | 6 +- .../boxed/di/inject/CarBoxedInjectModule.kt | 3 +- .../boxed/model/CarBoxedInjectProvider.kt | 2 +- .../test/car/di/bestOf/both/BothCarModule.kt | 2 +- .../bindinstance/simple/CarBindComponent.kt | 2 +- .../test/car/di/inject/CarInjectModule.kt | 2 +- .../lists/cached/CarMultiCachedComponent.kt | 2 +- .../di/lists/cached/CarMultiCachedModule.kt | 1 + .../car/di/lists/factory/CarMultiComponent.kt | 4 +- .../car/di/lists/factory/CarMultiModule.kt | 2 +- .../test/car/di/qualifiers/CarQPModule.kt | 2 +- 114 files changed, 15 insertions(+), 9575 deletions(-) delete mode 100644 tests_wraps/build.gradle.kts delete mode 100644 tests_wraps/src/main/java/com/github/klee0kai/test/boxed/di/inject/CarBoxedInjectComponent.java delete mode 100644 tests_wraps/src/main/java/com/github/klee0kai/test/boxed/di/inject/CarBoxedInjectModule.java delete mode 100644 tests_wraps/src/main/java/com/github/klee0kai/test/boxed/model/CarBox.java delete mode 100644 tests_wraps/src/main/java/com/github/klee0kai/test/boxed/model/CarBoxed.java delete mode 100644 tests_wraps/src/main/java/com/github/klee0kai/test/boxed/model/CarBoxedInject.java delete mode 100644 tests_wraps/src/main/java/com/github/klee0kai/test/boxed/model/CarBoxedInjectLists.java delete mode 100644 tests_wraps/src/main/java/com/github/klee0kai/test/boxed/model/CarBoxedInjectProvider.java delete mode 100644 tests_wraps/src/main/java/com/github/klee0kai/test/car/di/bestOf/blue/BlueCarComponent.java delete mode 100644 tests_wraps/src/main/java/com/github/klee0kai/test/car/di/bestOf/both/BothCarComponent.java delete mode 100644 tests_wraps/src/main/java/com/github/klee0kai/test/car/di/bestOf/both/BothCarModule.java delete mode 100644 tests_wraps/src/main/java/com/github/klee0kai/test/car/di/bestOf/red/RedCarComponent.java delete mode 100644 tests_wraps/src/main/java/com/github/klee0kai/test/car/di/bindinstance/simple/CarBindComponent.java delete mode 100644 tests_wraps/src/main/java/com/github/klee0kai/test/car/di/bindinstance/simple/CarBindModule.java delete mode 100644 tests_wraps/src/main/java/com/github/klee0kai/test/car/di/cachecontrol/gc/BumperGcModule.java delete mode 100644 tests_wraps/src/main/java/com/github/klee0kai/test/car/di/cachecontrol/gc/CarGcComponent.java delete mode 100644 tests_wraps/src/main/java/com/github/klee0kai/test/car/di/cachecontrol/gc/WheelGcModule.java delete mode 100644 tests_wraps/src/main/java/com/github/klee0kai/test/car/di/cachecontrol/gc/WheelMappedGcModule.java delete mode 100644 tests_wraps/src/main/java/com/github/klee0kai/test/car/di/cachecontrol/gc/WheelMultiMappedGcModule.java delete mode 100644 tests_wraps/src/main/java/com/github/klee0kai/test/car/di/cachecontrol/gc/WindowGcModule.java delete mode 100644 tests_wraps/src/main/java/com/github/klee0kai/test/car/di/cachecontrol/gc/WindowMappedGcModule.java delete mode 100644 tests_wraps/src/main/java/com/github/klee0kai/test/car/di/cachecontrol/gc/WindowMultiMappedGcModule.java delete mode 100644 tests_wraps/src/main/java/com/github/klee0kai/test/car/di/cachecontrol/gc/scopes/GcBumperRedScope.java delete mode 100644 tests_wraps/src/main/java/com/github/klee0kai/test/car/di/cachecontrol/gc/scopes/GcBumperScope.java delete mode 100644 tests_wraps/src/main/java/com/github/klee0kai/test/car/di/cachecontrol/gc/scopes/GcWheelScope.java delete mode 100644 tests_wraps/src/main/java/com/github/klee0kai/test/car/di/cachecontrol/gc/scopes/GcWindowScope.java delete mode 100644 tests_wraps/src/main/java/com/github/klee0kai/test/car/di/cachecontrol/swcache/CarSwCacheComponent.java delete mode 100644 tests_wraps/src/main/java/com/github/klee0kai/test/car/di/inject/CarInjectComponent.java delete mode 100644 tests_wraps/src/main/java/com/github/klee0kai/test/car/di/inject/CarInjectModule.java delete mode 100644 tests_wraps/src/main/java/com/github/klee0kai/test/car/di/lists/cached/CarMultiCachedComponent.java delete mode 100644 tests_wraps/src/main/java/com/github/klee0kai/test/car/di/lists/cached/CarMultiCachedModule.java delete mode 100644 tests_wraps/src/main/java/com/github/klee0kai/test/car/di/lists/factory/CarMultiComponent.java delete mode 100644 tests_wraps/src/main/java/com/github/klee0kai/test/car/di/lists/factory/CarMultiModule.java delete mode 100644 tests_wraps/src/main/java/com/github/klee0kai/test/car/di/qualifiers/CarQCModule.java delete mode 100644 tests_wraps/src/main/java/com/github/klee0kai/test/car/di/qualifiers/CarQComponent.java delete mode 100644 tests_wraps/src/main/java/com/github/klee0kai/test/car/di/qualifiers/CarQPModule.java delete mode 100644 tests_wraps/src/main/java/com/github/klee0kai/test/car/di/qualifiers/qualifiers/BumperQualifier.java delete mode 100644 tests_wraps/src/main/java/com/github/klee0kai/test/car/di/qualifiers/qualifiers/MyQualifier.java delete mode 100644 tests_wraps/src/main/java/com/github/klee0kai/test/car/di/qualifiers/qualifiers/MyQualifierMulti.java delete mode 100644 tests_wraps/src/main/java/com/github/klee0kai/test/car/di/qualifiers/qualifiers/MyQualifierWithString.java delete mode 100644 tests_wraps/src/main/java/com/github/klee0kai/test/car/di/qualifiers/qualifiers/WheelCount.java delete mode 100644 tests_wraps/src/main/java/com/github/klee0kai/test/car/di/wrapped/create/CarWrappedCreateComponent.java delete mode 100644 tests_wraps/src/main/java/com/github/klee0kai/test/car/di/wrapped/create/CarWrappedCreateModule.java delete mode 100644 tests_wraps/src/main/java/com/github/klee0kai/test/car/di/wrapped/custom/CarCustomWrapperModule.java delete mode 100644 tests_wraps/src/main/java/com/github/klee0kai/test/car/di/wrapped/custom/CarCustomWrappersComponent.java delete mode 100644 tests_wraps/src/main/java/com/github/klee0kai/test/car/di/wrapped/custom/wrappers/CarLazy.java delete mode 100644 tests_wraps/src/main/java/com/github/klee0kai/test/car/di/wrapped/custom/wrappers/CarProvide.java delete mode 100644 tests_wraps/src/main/java/com/github/klee0kai/test/car/di/wrapped/custom/wrappers/CarProviderWrapper.java delete mode 100644 tests_wraps/src/main/java/com/github/klee0kai/test/car/di/wrapped/custom/wrappers/CarRef.java delete mode 100644 tests_wraps/src/main/java/com/github/klee0kai/test/car/di/wrapped/custom/wrappers/CarWrapper.java delete mode 100644 tests_wraps/src/main/java/com/github/klee0kai/test/car/model/Bumper.java delete mode 100644 tests_wraps/src/main/java/com/github/klee0kai/test/car/model/Car.java delete mode 100644 tests_wraps/src/main/java/com/github/klee0kai/test/car/model/CarInject.java delete mode 100644 tests_wraps/src/main/java/com/github/klee0kai/test/car/model/CarInjectLists.java delete mode 100644 tests_wraps/src/main/java/com/github/klee0kai/test/car/model/CarInjectProvider.java delete mode 100644 tests_wraps/src/main/java/com/github/klee0kai/test/car/model/CarsInjectQualifiers.java delete mode 100644 tests_wraps/src/main/java/com/github/klee0kai/test/car/model/Wheel.java delete mode 100644 tests_wraps/src/main/java/com/github/klee0kai/test/car/model/Window.java delete mode 100644 tests_wraps/src/test/java/com/github/klee0kai/stone/test/boxed/inject/CarBoxedInjectMethodTests.java delete mode 100644 tests_wraps/src/test/java/com/github/klee0kai/stone/test/boxed/inject/CarBoxedInjectTests.java delete mode 100644 tests_wraps/src/test/java/com/github/klee0kai/stone/test/boxed/inject/CarBoxedProtectInjectedTests.java delete mode 100644 tests_wraps/src/test/java/com/github/klee0kai/stone/test/car/bindinstance/simple/BindBumperTests.java delete mode 100644 tests_wraps/src/test/java/com/github/klee0kai/stone/test/car/bindinstance/simple/BindWheelRefTests.java delete mode 100644 tests_wraps/src/test/java/com/github/klee0kai/stone/test/car/bindinstance/simple/BindWheelTests.java delete mode 100644 tests_wraps/src/test/java/com/github/klee0kai/stone/test/car/bindinstance/simple/BindWindowCollectionRefTests.java delete mode 100644 tests_wraps/src/test/java/com/github/klee0kai/stone/test/car/bindinstance/simple/BindWindowCollectionTests.java delete mode 100644 tests_wraps/src/test/java/com/github/klee0kai/stone/test/car/bindinstance/simple/BindWindowTests.java delete mode 100644 tests_wraps/src/test/java/com/github/klee0kai/stone/test/car/bluecar/BlueCarTest.java delete mode 100644 tests_wraps/src/test/java/com/github/klee0kai/stone/test/car/cachecontrol/gc/BumperGcResusableTests.java delete mode 100644 tests_wraps/src/test/java/com/github/klee0kai/stone/test/car/cachecontrol/gc/BumperGcTests.java delete mode 100644 tests_wraps/src/test/java/com/github/klee0kai/stone/test/car/cachecontrol/gc/WheelGcTests.java delete mode 100644 tests_wraps/src/test/java/com/github/klee0kai/stone/test/car/cachecontrol/gc/WheelMappedGcTests.java delete mode 100644 tests_wraps/src/test/java/com/github/klee0kai/stone/test/car/cachecontrol/gc/WheelMultiMappedGcTests.java delete mode 100644 tests_wraps/src/test/java/com/github/klee0kai/stone/test/car/cachecontrol/gc/WheelReusableGcTests.java delete mode 100644 tests_wraps/src/test/java/com/github/klee0kai/stone/test/car/cachecontrol/gc/WindowGcTests.java delete mode 100644 tests_wraps/src/test/java/com/github/klee0kai/stone/test/car/cachecontrol/gc/WindowMappedGcTests.java delete mode 100644 tests_wraps/src/test/java/com/github/klee0kai/stone/test/car/cachecontrol/gc/WindowMappedPartialGcTests.java delete mode 100644 tests_wraps/src/test/java/com/github/klee0kai/stone/test/car/cachecontrol/gc/WindowMappedReusableGcTests.java delete mode 100644 tests_wraps/src/test/java/com/github/klee0kai/stone/test/car/cachecontrol/gc/WindowMultiMappedGcTests.java delete mode 100644 tests_wraps/src/test/java/com/github/klee0kai/stone/test/car/cachecontrol/gc/WindowMultiMappedPartialGcTests.java delete mode 100644 tests_wraps/src/test/java/com/github/klee0kai/stone/test/car/cachecontrol/gc/WindowMultiMappedReusableGcTests.java delete mode 100644 tests_wraps/src/test/java/com/github/klee0kai/stone/test/car/cachecontrol/gc/WindowPartialGcTests.java delete mode 100644 tests_wraps/src/test/java/com/github/klee0kai/stone/test/car/cachecontrol/swcache/BumperSwitchCacheTests.java delete mode 100644 tests_wraps/src/test/java/com/github/klee0kai/stone/test/car/cachecontrol/swcache/WheelSwitchCacheTests.java delete mode 100644 tests_wraps/src/test/java/com/github/klee0kai/stone/test/car/cachecontrol/swcache/WindowMappedSwitchCacheTests.java delete mode 100644 tests_wraps/src/test/java/com/github/klee0kai/stone/test/car/cachecontrol/swcache/WindowMultiMappedSwitchCacheTests.java delete mode 100644 tests_wraps/src/test/java/com/github/klee0kai/stone/test/car/cachecontrol/swcache/WindowSwitchCacheTests.java delete mode 100644 tests_wraps/src/test/java/com/github/klee0kai/stone/test/car/inject/CarInjectMethodTests.java delete mode 100644 tests_wraps/src/test/java/com/github/klee0kai/stone/test/car/inject/CarInjectMixedTests.java delete mode 100644 tests_wraps/src/test/java/com/github/klee0kai/stone/test/car/inject/CarInjectTests.java delete mode 100644 tests_wraps/src/test/java/com/github/klee0kai/stone/test/car/inject/CarProtectInjectedTests.java delete mode 100644 tests_wraps/src/test/java/com/github/klee0kai/stone/test/car/muti/MultiCachedProvideTest.java delete mode 100644 tests_wraps/src/test/java/com/github/klee0kai/stone/test/car/muti/MultiProvideTest.java delete mode 100644 tests_wraps/src/test/java/com/github/klee0kai/stone/test/car/qualifiers/CarInjectAllMethodsWithQualifiersTest.java delete mode 100644 tests_wraps/src/test/java/com/github/klee0kai/stone/test/car/qualifiers/CarInjectAllWithQualifiersTest.java delete mode 100644 tests_wraps/src/test/java/com/github/klee0kai/stone/test/car/qualifiers/CarInjectMethodWithQualifiersTest.java delete mode 100644 tests_wraps/src/test/java/com/github/klee0kai/stone/test/car/qualifiers/CarInjectWithQualifiersTest.java delete mode 100644 tests_wraps/src/test/java/com/github/klee0kai/stone/test/car/qualifiers/CarProvideAllWithQualifiersTests.java delete mode 100644 tests_wraps/src/test/java/com/github/klee0kai/stone/test/car/qualifiers/CarProvideWithQualifiersTests.java delete mode 100644 tests_wraps/src/test/java/com/github/klee0kai/stone/test/car/wrapper/CarSingleWrapperTests.java delete mode 100644 tests_wraps/src/test/java/com/github/klee0kai/stone/test/car/wrapper/CurCustomWrapperTests.java diff --git a/settings.gradle.kts b/settings.gradle.kts index 52f10e35..7d19b6b0 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -33,7 +33,6 @@ include(":wiki_kotlin") include(":tests") include(":tests_ext") include(":tests_kotlin") -include(":tests_wraps") include(":tests_wraps_kotlin") include(":tests_compile") include(":test_feature:companies:consulting") diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/Processor.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/Processor.kt index 50333f7f..37fe009c 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/Processor.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/Processor.kt @@ -147,6 +147,7 @@ class Processor( message = e.message ?: "", symbol = e.findLastErrorElement(), ) + throw e } } diff --git a/tests_wraps/build.gradle.kts b/tests_wraps/build.gradle.kts deleted file mode 100644 index 10cbe8a0..00000000 --- a/tests_wraps/build.gradle.kts +++ /dev/null @@ -1,15 +0,0 @@ -plugins { - java -} - -tasks.test { - useJUnitPlatform() -} - -dependencies { - implementation(project(":stone_lib")) - annotationProcessor(project(":stone_processor")) - - testImplementation(libs.bundles.junit) -} - diff --git a/tests_wraps/src/main/java/com/github/klee0kai/test/boxed/di/inject/CarBoxedInjectComponent.java b/tests_wraps/src/main/java/com/github/klee0kai/test/boxed/di/inject/CarBoxedInjectComponent.java deleted file mode 100644 index 6a3993e7..00000000 --- a/tests_wraps/src/main/java/com/github/klee0kai/test/boxed/di/inject/CarBoxedInjectComponent.java +++ /dev/null @@ -1,29 +0,0 @@ -package com.github.klee0kai.test.boxed.di.inject; - -import com.github.klee0kai.stone.annotations.component.Component; -import com.github.klee0kai.stone.annotations.component.ProtectInjected; -import com.github.klee0kai.test.boxed.model.CarBoxedInject; -import com.github.klee0kai.test.boxed.model.CarBoxedInjectLists; -import com.github.klee0kai.test.boxed.model.CarBoxedInjectProvider; - -@Component -public abstract class CarBoxedInjectComponent { - - protected abstract CarBoxedInjectModule module(); - - public abstract void inject(CarBoxedInject carInject); - - public abstract void inject(CarBoxedInjectLists carInject); - - public abstract void inject(CarBoxedInjectProvider carInject); - - @ProtectInjected - public abstract void protect(CarBoxedInject carInject); - - @ProtectInjected - public abstract void protect(CarBoxedInjectLists carInject); - - @ProtectInjected - public abstract void protect(CarBoxedInjectProvider carInject); - -} diff --git a/tests_wraps/src/main/java/com/github/klee0kai/test/boxed/di/inject/CarBoxedInjectModule.java b/tests_wraps/src/main/java/com/github/klee0kai/test/boxed/di/inject/CarBoxedInjectModule.java deleted file mode 100644 index d0935276..00000000 --- a/tests_wraps/src/main/java/com/github/klee0kai/test/boxed/di/inject/CarBoxedInjectModule.java +++ /dev/null @@ -1,59 +0,0 @@ -package com.github.klee0kai.test.boxed.di.inject; - -import com.github.klee0kai.stone.annotations.module.Module; -import com.github.klee0kai.stone.annotations.module.Provide; -import com.github.klee0kai.stone.wrappers.Ref; -import com.github.klee0kai.test.boxed.model.CarBox; -import com.github.klee0kai.test.car.model.Bumper; -import com.github.klee0kai.test.car.model.Wheel; -import com.github.klee0kai.test.car.model.Window; - -import javax.inject.Named; -import javax.inject.Provider; -import java.lang.ref.WeakReference; -import java.util.Arrays; -import java.util.Collection; -import java.util.List; - -@Module -public class CarBoxedInjectModule { - - @Named("fourWheels") - @Provide(cache = Provide.CacheType.Weak) - public List> fourWheels() { - return Arrays.asList( - new CarBox<>(new Wheel()), - new CarBox<>(new Wheel()), - new CarBox<>(new Wheel()), - new CarBox<>(new Wheel()) - ); - } - - @Provide(cache = Provide.CacheType.Weak) - public CarBox spareWheel() { - return new CarBox<>(new Wheel()); - } - - @Provide(cache = Provide.CacheType.Factory) - public Provider> frontWindow() { - return () -> new CarBox<>(new Window()); - } - - @Named() - @Provide(cache = Provide.CacheType.Factory) - public Provider>> backWindow() { - return () -> new WeakReference<>(new CarBox<>(new Window())); - } - - @Named() - @Provide(cache = Provide.CacheType.Factory) - public List>> passengerWindows() { - return Arrays.asList(() -> new CarBox<>(new Window()), () -> new CarBox<>(new Window())); - } - - @Provide(cache = Provide.CacheType.Weak) - public Collection> bumpers() { - return Arrays.asList(new CarBox<>(new Bumper()), new CarBox<>(new Bumper())); - } - -} diff --git a/tests_wraps/src/main/java/com/github/klee0kai/test/boxed/model/CarBox.java b/tests_wraps/src/main/java/com/github/klee0kai/test/boxed/model/CarBox.java deleted file mode 100644 index dfa80ba8..00000000 --- a/tests_wraps/src/main/java/com/github/klee0kai/test/boxed/model/CarBox.java +++ /dev/null @@ -1,10 +0,0 @@ -package com.github.klee0kai.test.boxed.model; - -public class CarBox { - - public T val; - - public CarBox(T val) { - this.val = val; - } -} diff --git a/tests_wraps/src/main/java/com/github/klee0kai/test/boxed/model/CarBoxed.java b/tests_wraps/src/main/java/com/github/klee0kai/test/boxed/model/CarBoxed.java deleted file mode 100644 index 968be405..00000000 --- a/tests_wraps/src/main/java/com/github/klee0kai/test/boxed/model/CarBoxed.java +++ /dev/null @@ -1,38 +0,0 @@ -package com.github.klee0kai.test.boxed.model; - -import com.github.klee0kai.test.car.model.Bumper; -import com.github.klee0kai.test.car.model.Wheel; -import com.github.klee0kai.test.car.model.Window; - -import java.util.Collections; -import java.util.List; -import java.util.UUID; - -public class CarBoxed { - - public static int createCount = 0; - public String uuid = UUID.randomUUID().toString(); - - public List> bumpers; - public List> wheels; - public List> windows; - - public CarBoxed( - CarBox bumper, - CarBox wheel, - CarBox window - ) { - createCount++; - bumpers = Collections.singletonList(bumper); - wheels = Collections.singletonList(wheel); - windows = Collections.singletonList(window); - } - - - public CarBoxed(List> bumpers, List> wheels, List> windows) { - createCount++; - this.bumpers = bumpers; - this.wheels = wheels; - this.windows = windows; - } -} diff --git a/tests_wraps/src/main/java/com/github/klee0kai/test/boxed/model/CarBoxedInject.java b/tests_wraps/src/main/java/com/github/klee0kai/test/boxed/model/CarBoxedInject.java deleted file mode 100644 index d4a59302..00000000 --- a/tests_wraps/src/main/java/com/github/klee0kai/test/boxed/model/CarBoxedInject.java +++ /dev/null @@ -1,34 +0,0 @@ -package com.github.klee0kai.test.boxed.model; - -import com.github.klee0kai.test.car.model.Bumper; -import com.github.klee0kai.test.car.model.Wheel; -import com.github.klee0kai.test.car.model.Window; - -import javax.inject.Inject; - -public class CarBoxedInject { - - @Inject - public CarBox bumper; - - @Inject - public CarBox wheel; - - @Inject - public CarBox window; - - public CarBox bumperFromMethod; - - public CarBox wheelFromMethod; - - public CarBox windowFromMethod; - - - @Inject - public void init(CarBox bumper, CarBox wheel, CarBox window) { - bumperFromMethod = bumper; - wheelFromMethod = wheel; - windowFromMethod = window; - } - -} diff --git a/tests_wraps/src/main/java/com/github/klee0kai/test/boxed/model/CarBoxedInjectLists.java b/tests_wraps/src/main/java/com/github/klee0kai/test/boxed/model/CarBoxedInjectLists.java deleted file mode 100644 index 8c6ab1e2..00000000 --- a/tests_wraps/src/main/java/com/github/klee0kai/test/boxed/model/CarBoxedInjectLists.java +++ /dev/null @@ -1,36 +0,0 @@ -package com.github.klee0kai.test.boxed.model; - -import com.github.klee0kai.test.car.model.Bumper; -import com.github.klee0kai.test.car.model.Wheel; -import com.github.klee0kai.test.car.model.Window; - -import javax.inject.Inject; -import java.util.List; - -public class CarBoxedInjectLists { - - - @Inject - public List> bumpers; - - @Inject - public List> wheels; - - @Inject - public List> windows; - - public List> bumpersMethodFrom; - - public List> wheelsMethodFrom; - - public List> windowsMethodFrom; - - @Inject - public void init(List> bumpers, List> wheels, List> windows) { - bumpersMethodFrom = bumpers; - wheelsMethodFrom = wheels; - windowsMethodFrom = windows; - } - - -} diff --git a/tests_wraps/src/main/java/com/github/klee0kai/test/boxed/model/CarBoxedInjectProvider.java b/tests_wraps/src/main/java/com/github/klee0kai/test/boxed/model/CarBoxedInjectProvider.java deleted file mode 100644 index e970dc4e..00000000 --- a/tests_wraps/src/main/java/com/github/klee0kai/test/boxed/model/CarBoxedInjectProvider.java +++ /dev/null @@ -1,36 +0,0 @@ -package com.github.klee0kai.test.boxed.model; - -import com.github.klee0kai.stone.wrappers.LazyProvide; -import com.github.klee0kai.stone.wrappers.Ref; -import com.github.klee0kai.test.car.di.wrapped.custom.wrappers.CarLazy; -import com.github.klee0kai.test.car.model.Bumper; -import com.github.klee0kai.test.car.model.Wheel; -import com.github.klee0kai.test.car.model.Window; - -import javax.inject.Inject; - -public class CarBoxedInjectProvider { - - @Inject - public LazyProvide> bumper; - - @Inject - public Ref> wheel; - - @Inject - public Ref>> window; - - public LazyProvide> bumperFromMethod; - - public Ref> wheelFromMethod; - - public Ref>> windowFromMethod; - - @Inject - public void init(LazyProvide> bumper, Ref> wheel, Ref>> window) { - bumperFromMethod = bumper; - wheelFromMethod = wheel; - windowFromMethod = window; - } - -} diff --git a/tests_wraps/src/main/java/com/github/klee0kai/test/car/di/bestOf/blue/BlueCarComponent.java b/tests_wraps/src/main/java/com/github/klee0kai/test/car/di/bestOf/blue/BlueCarComponent.java deleted file mode 100644 index ff377559..00000000 --- a/tests_wraps/src/main/java/com/github/klee0kai/test/car/di/bestOf/blue/BlueCarComponent.java +++ /dev/null @@ -1,18 +0,0 @@ -package com.github.klee0kai.test.car.di.bestOf.blue; - -import com.github.klee0kai.stone.annotations.component.Component; -import com.github.klee0kai.test.car.di.bestOf.both.BothCarModule; -import com.github.klee0kai.test.car.model.Car; - -import javax.inject.Named; -import javax.inject.Provider; - -@Component -public interface BlueCarComponent { - - BothCarModule myModule(); - - @Named("blueCar") - Provider blueCar(); - -} diff --git a/tests_wraps/src/main/java/com/github/klee0kai/test/car/di/bestOf/both/BothCarComponent.java b/tests_wraps/src/main/java/com/github/klee0kai/test/car/di/bestOf/both/BothCarComponent.java deleted file mode 100644 index 75786066..00000000 --- a/tests_wraps/src/main/java/com/github/klee0kai/test/car/di/bestOf/both/BothCarComponent.java +++ /dev/null @@ -1,21 +0,0 @@ -package com.github.klee0kai.test.car.di.bestOf.both; - -import com.github.klee0kai.stone.annotations.component.Component; -import com.github.klee0kai.test.car.model.Car; - -import javax.inject.Named; -import javax.inject.Provider; -import java.lang.ref.WeakReference; - -@Component -public interface BothCarComponent { - - BothCarModule myModule(); - - @Named("blueCar") - Provider blueCar(); - - @Named("redCar") - WeakReference redCar(); - -} diff --git a/tests_wraps/src/main/java/com/github/klee0kai/test/car/di/bestOf/both/BothCarModule.java b/tests_wraps/src/main/java/com/github/klee0kai/test/car/di/bestOf/both/BothCarModule.java deleted file mode 100644 index 0f441b07..00000000 --- a/tests_wraps/src/main/java/com/github/klee0kai/test/car/di/bestOf/both/BothCarModule.java +++ /dev/null @@ -1,56 +0,0 @@ -package com.github.klee0kai.test.car.di.bestOf.both; - -import com.github.klee0kai.stone.annotations.module.Module; -import com.github.klee0kai.stone.annotations.module.Provide; -import com.github.klee0kai.stone.wrappers.Ref; -import com.github.klee0kai.test.car.model.Bumper; -import com.github.klee0kai.test.car.model.Car; -import com.github.klee0kai.test.car.model.Wheel; -import com.github.klee0kai.test.car.model.Window; - -import javax.inject.Named; -import javax.inject.Provider; -import java.lang.ref.WeakReference; -import java.util.Arrays; -import java.util.Collection; -import java.util.List; - -@Module -public abstract class BothCarModule { - - @Provide(cache = Provide.CacheType.Weak) - public List fourWheels() { - return Arrays.asList(new Wheel(), new Wheel(), new Wheel(), new Wheel()); - } - - @Named - @Provide(cache = Provide.CacheType.Weak) - public abstract Wheel spareWheel(); - - @Provide(cache = Provide.CacheType.Factory) - public abstract Provider frontWindow(); - @Named - @Provide(cache = Provide.CacheType.Factory) - public abstract Provider> backWindow(); - - @Named - @Provide(cache = Provide.CacheType.Factory) - public List> passengerWindows() { - return Arrays.asList(Window::new, Window::new); - } - - @Provide(cache = Provide.CacheType.Weak) - public Collection bumpers() { - return Arrays.asList(new Bumper(), new Bumper()); - } - - @Named("redCar") - @Provide(cache = Provide.CacheType.Weak) - public abstract List redCar(Bumper bumper, Wheel wheel, Window window); - - @Named("blueCar") - @Provide(cache = Provide.CacheType.Weak) - public abstract Car blueCar(List bumpers, List wheels, List windows); - - -} diff --git a/tests_wraps/src/main/java/com/github/klee0kai/test/car/di/bestOf/red/RedCarComponent.java b/tests_wraps/src/main/java/com/github/klee0kai/test/car/di/bestOf/red/RedCarComponent.java deleted file mode 100644 index c606e438..00000000 --- a/tests_wraps/src/main/java/com/github/klee0kai/test/car/di/bestOf/red/RedCarComponent.java +++ /dev/null @@ -1,18 +0,0 @@ -package com.github.klee0kai.test.car.di.bestOf.red; - -import com.github.klee0kai.stone.annotations.component.Component; -import com.github.klee0kai.test.car.di.bestOf.both.BothCarModule; -import com.github.klee0kai.test.car.model.Car; - -import javax.inject.Named; -import java.lang.ref.WeakReference; - -@Component -public interface RedCarComponent { - - BothCarModule myModule(); - - @Named("redCar") - WeakReference redCar(); - -} diff --git a/tests_wraps/src/main/java/com/github/klee0kai/test/car/di/bindinstance/simple/CarBindComponent.java b/tests_wraps/src/main/java/com/github/klee0kai/test/car/di/bindinstance/simple/CarBindComponent.java deleted file mode 100644 index 0c092b7a..00000000 --- a/tests_wraps/src/main/java/com/github/klee0kai/test/car/di/bindinstance/simple/CarBindComponent.java +++ /dev/null @@ -1,52 +0,0 @@ -package com.github.klee0kai.test.car.di.bindinstance.simple; - -import com.github.klee0kai.stone.annotations.component.Component; -import com.github.klee0kai.stone.annotations.module.BindInstance; -import com.github.klee0kai.stone.wrappers.Ref; -import com.github.klee0kai.test.car.model.Bumper; -import com.github.klee0kai.test.car.model.Wheel; -import com.github.klee0kai.test.car.model.Window; - -import java.lang.ref.Reference; -import java.lang.ref.WeakReference; -import java.util.Collection; -import java.util.List; - -@Component -public interface CarBindComponent { - - CarBindModule module(); - - @BindInstance - void bindWheel(Wheel wheel); - - @BindInstance - void bindWheelRef(Reference wheel); - - @BindInstance - void bindBumper(Ref bumper); - - @BindInstance - void bindWindow(Window window); - - @BindInstance - void bindWindows(Collection window); - - @BindInstance - void bindWindowRefs(Collection> window); - - Wheel provideWheel(); - - Reference provideWheelRef(); - - List> provideWheels(); - - Ref provideBumper(); - - List provideBumpers(); - - Window provideWindow(); - - Collection provideWindows(); - -} diff --git a/tests_wraps/src/main/java/com/github/klee0kai/test/car/di/bindinstance/simple/CarBindModule.java b/tests_wraps/src/main/java/com/github/klee0kai/test/car/di/bindinstance/simple/CarBindModule.java deleted file mode 100644 index bc36a41c..00000000 --- a/tests_wraps/src/main/java/com/github/klee0kai/test/car/di/bindinstance/simple/CarBindModule.java +++ /dev/null @@ -1,24 +0,0 @@ -package com.github.klee0kai.test.car.di.bindinstance.simple; - -import com.github.klee0kai.stone.annotations.module.BindInstance; -import com.github.klee0kai.stone.annotations.module.Module; -import com.github.klee0kai.test.car.model.Bumper; -import com.github.klee0kai.test.car.model.Wheel; -import com.github.klee0kai.test.car.model.Window; - -import java.lang.ref.WeakReference; -import java.util.List; - -@Module -public interface CarBindModule { - - @BindInstance - Wheel wheel(); - - @BindInstance - WeakReference bumper(); - - @BindInstance - WeakReference> windows(); - -} diff --git a/tests_wraps/src/main/java/com/github/klee0kai/test/car/di/cachecontrol/gc/BumperGcModule.java b/tests_wraps/src/main/java/com/github/klee0kai/test/car/di/cachecontrol/gc/BumperGcModule.java deleted file mode 100644 index ae4c04ac..00000000 --- a/tests_wraps/src/main/java/com/github/klee0kai/test/car/di/cachecontrol/gc/BumperGcModule.java +++ /dev/null @@ -1,43 +0,0 @@ -package com.github.klee0kai.test.car.di.cachecontrol.gc; - -import com.github.klee0kai.stone.annotations.module.Module; -import com.github.klee0kai.stone.annotations.module.Provide; -import com.github.klee0kai.test.car.di.cachecontrol.gc.scopes.GcBumperRedScope; -import com.github.klee0kai.test.car.di.cachecontrol.gc.scopes.GcBumperScope; -import com.github.klee0kai.test.car.model.Bumper; - -import java.util.Arrays; -import java.util.List; - -@Module -public class BumperGcModule { - - @GcBumperScope - @Provide(cache = Provide.CacheType.Factory) - public List bumperFactory() { - return Arrays.asList(new Bumper(), new Bumper(), new Bumper()); - } - - - @GcBumperScope - @Provide(cache = Provide.CacheType.Weak) - public List bumperWeak() { - return Arrays.asList(new Bumper(), new Bumper(), new Bumper()); - } - - - @GcBumperScope - @Provide(cache = Provide.CacheType.Soft) - public List bumperSoft() { - return Arrays.asList(new Bumper(), new Bumper(), new Bumper()); - } - - @GcBumperScope - @GcBumperRedScope - @Provide(cache = Provide.CacheType.Strong) - public List bumperStrong() { - return Arrays.asList(new Bumper(), new Bumper(), new Bumper()); - } - - -} diff --git a/tests_wraps/src/main/java/com/github/klee0kai/test/car/di/cachecontrol/gc/CarGcComponent.java b/tests_wraps/src/main/java/com/github/klee0kai/test/car/di/cachecontrol/gc/CarGcComponent.java deleted file mode 100644 index 487d9216..00000000 --- a/tests_wraps/src/main/java/com/github/klee0kai/test/car/di/cachecontrol/gc/CarGcComponent.java +++ /dev/null @@ -1,86 +0,0 @@ -package com.github.klee0kai.test.car.di.cachecontrol.gc; - -import com.github.klee0kai.stone.annotations.component.*; -import com.github.klee0kai.test.car.di.cachecontrol.gc.scopes.GcBumperRedScope; -import com.github.klee0kai.test.car.di.cachecontrol.gc.scopes.GcBumperScope; -import com.github.klee0kai.test.car.di.cachecontrol.gc.scopes.GcWheelScope; -import com.github.klee0kai.test.car.di.cachecontrol.gc.scopes.GcWindowScope; - -@Component( - identifiers = {String.class, Integer.class} -) -public abstract class CarGcComponent { - - public abstract BumperGcModule bumpersModule(); - - public abstract WheelGcModule wheelsModule(); - - public abstract WheelMappedGcModule wheelMappedModule(); - - public abstract WheelMultiMappedGcModule wheelMultiMappedModule(); - - public abstract WindowGcModule windowsModule(); - - public abstract WindowMappedGcModule windowsMappedModule(); - - public abstract WindowMultiMappedGcModule windowsMultiMappedModule(); - - @RunGc - @GcAllScope - public abstract void gcAll(); - - @RunGc - @GcWeakScope - public abstract void gcWeak(); - - @RunGc - @GcSoftScope - public abstract void gcSoft(); - - @RunGc - @GcStrongScope - public abstract void gcStrong(); - - @RunGc - @GcWheelScope - public abstract void gcWheels(); - - @RunGc - @GcBumperScope - public abstract void gcBumpers(); - - @RunGc - @GcBumperRedScope - public abstract void gcRedBumpers(); - - @RunGc - @GcBumperRedScope - @GcBumperScope - public abstract void gcRedBumpers2(); - - @RunGc - @GcWindowScope - public abstract void gcWindows(); - - @RunGc - @GcWindowScope - @GcWeakScope - public abstract void gcWeakWindows(); - - @RunGc - @GcWindowScope - @GcSoftScope - public abstract void gcSoftWindows(); - - @RunGc - @GcWindowScope - @GcBumperScope - public abstract void gcNothing(); - - public void gcWindowsAndWheels() { - gcWindows(); - gcWheels(); - } - - -} diff --git a/tests_wraps/src/main/java/com/github/klee0kai/test/car/di/cachecontrol/gc/WheelGcModule.java b/tests_wraps/src/main/java/com/github/klee0kai/test/car/di/cachecontrol/gc/WheelGcModule.java deleted file mode 100644 index 9d112417..00000000 --- a/tests_wraps/src/main/java/com/github/klee0kai/test/car/di/cachecontrol/gc/WheelGcModule.java +++ /dev/null @@ -1,30 +0,0 @@ -package com.github.klee0kai.test.car.di.cachecontrol.gc; - -import com.github.klee0kai.stone.annotations.module.Module; -import com.github.klee0kai.stone.annotations.module.Provide; -import com.github.klee0kai.test.car.di.cachecontrol.gc.scopes.GcWheelScope; -import com.github.klee0kai.test.car.model.Wheel; - -import java.lang.ref.WeakReference; - -@Module -public interface WheelGcModule { - - @GcWheelScope - @Provide(cache = Provide.CacheType.Factory) - WeakReference wheelFactory(); - - @GcWheelScope - @Provide(cache = Provide.CacheType.Weak) - WeakReference wheelWeak(); - - @GcWheelScope - @Provide(cache = Provide.CacheType.Soft) - WeakReference wheelSoft(); - - @GcWheelScope - @Provide(cache = Provide.CacheType.Strong) - WeakReference wheelStrong(); - - -} diff --git a/tests_wraps/src/main/java/com/github/klee0kai/test/car/di/cachecontrol/gc/WheelMappedGcModule.java b/tests_wraps/src/main/java/com/github/klee0kai/test/car/di/cachecontrol/gc/WheelMappedGcModule.java deleted file mode 100644 index a22525ac..00000000 --- a/tests_wraps/src/main/java/com/github/klee0kai/test/car/di/cachecontrol/gc/WheelMappedGcModule.java +++ /dev/null @@ -1,38 +0,0 @@ -package com.github.klee0kai.test.car.di.cachecontrol.gc; - -import com.github.klee0kai.stone.annotations.module.Module; -import com.github.klee0kai.stone.annotations.module.Provide; -import com.github.klee0kai.test.car.di.cachecontrol.gc.scopes.GcWheelScope; -import com.github.klee0kai.test.car.model.Wheel; - -import java.lang.ref.WeakReference; - -@Module -public class WheelMappedGcModule { - - @GcWheelScope - @Provide(cache = Provide.CacheType.Factory) - public WeakReference wheelFactory(String q1) { - return new WeakReference<>(new Wheel()); - } - - @GcWheelScope - @Provide(cache = Provide.CacheType.Weak) - public WeakReference wheelWeak(String q1) { - return new WeakReference<>(new Wheel()); - } - - @GcWheelScope - @Provide(cache = Provide.CacheType.Soft) - public WeakReference wheelSoft(String q1) { - return new WeakReference<>(new Wheel()); - } - - @GcWheelScope - @Provide(cache = Provide.CacheType.Strong) - public WeakReference wheelStrong(String q1) { - return new WeakReference<>(new Wheel()); - } - - -} diff --git a/tests_wraps/src/main/java/com/github/klee0kai/test/car/di/cachecontrol/gc/WheelMultiMappedGcModule.java b/tests_wraps/src/main/java/com/github/klee0kai/test/car/di/cachecontrol/gc/WheelMultiMappedGcModule.java deleted file mode 100644 index 798d188e..00000000 --- a/tests_wraps/src/main/java/com/github/klee0kai/test/car/di/cachecontrol/gc/WheelMultiMappedGcModule.java +++ /dev/null @@ -1,38 +0,0 @@ -package com.github.klee0kai.test.car.di.cachecontrol.gc; - -import com.github.klee0kai.stone.annotations.module.Module; -import com.github.klee0kai.stone.annotations.module.Provide; -import com.github.klee0kai.test.car.di.cachecontrol.gc.scopes.GcWheelScope; -import com.github.klee0kai.test.car.model.Wheel; - -import java.lang.ref.WeakReference; - -@Module -public class WheelMultiMappedGcModule { - - @GcWheelScope - @Provide(cache = Provide.CacheType.Factory) - public WeakReference wheelFactory(String q1, Integer q2) { - return new WeakReference<>(new Wheel()); - } - - @GcWheelScope - @Provide(cache = Provide.CacheType.Weak) - public WeakReference wheelWeak(String q1, Integer q2) { - return new WeakReference<>(new Wheel()); - } - - @GcWheelScope - @Provide(cache = Provide.CacheType.Soft) - public WeakReference wheelSoft(String q1, Integer q2) { - return new WeakReference<>(new Wheel()); - } - - @GcWheelScope - @Provide(cache = Provide.CacheType.Strong) - public WeakReference wheelStrong(String q1, Integer q2) { - return new WeakReference<>(new Wheel()); - } - - -} diff --git a/tests_wraps/src/main/java/com/github/klee0kai/test/car/di/cachecontrol/gc/WindowGcModule.java b/tests_wraps/src/main/java/com/github/klee0kai/test/car/di/cachecontrol/gc/WindowGcModule.java deleted file mode 100644 index 390e18d1..00000000 --- a/tests_wraps/src/main/java/com/github/klee0kai/test/car/di/cachecontrol/gc/WindowGcModule.java +++ /dev/null @@ -1,41 +0,0 @@ -package com.github.klee0kai.test.car.di.cachecontrol.gc; - -import com.github.klee0kai.stone.annotations.module.Module; -import com.github.klee0kai.stone.annotations.module.Provide; -import com.github.klee0kai.test.car.di.cachecontrol.gc.scopes.GcWindowScope; -import com.github.klee0kai.test.car.model.Window; - -import java.lang.ref.WeakReference; -import java.util.Arrays; -import java.util.Collection; -import java.util.List; - -@Module -public class WindowGcModule { - - @GcWindowScope - @Provide(cache = Provide.CacheType.Factory) - public WeakReference> windowFactory() { - return new WeakReference<>(Arrays.asList(new Window(), new Window(), new Window())); - } - - @GcWindowScope - @Provide(cache = Provide.CacheType.Weak) - public WeakReference> windowWeak() { - return new WeakReference<>(Arrays.asList(new Window(), new Window(), new Window())); - } - - @GcWindowScope - @Provide(cache = Provide.CacheType.Soft) - public WeakReference> windowSoft() { - return new WeakReference<>(Arrays.asList(new Window(), new Window(), new Window())); - } - - @GcWindowScope - @Provide(cache = Provide.CacheType.Strong) - public WeakReference> windowStrong() { - return new WeakReference<>(Arrays.asList(new Window(), new Window(), new Window())); - } - - -} diff --git a/tests_wraps/src/main/java/com/github/klee0kai/test/car/di/cachecontrol/gc/WindowMappedGcModule.java b/tests_wraps/src/main/java/com/github/klee0kai/test/car/di/cachecontrol/gc/WindowMappedGcModule.java deleted file mode 100644 index deb8f491..00000000 --- a/tests_wraps/src/main/java/com/github/klee0kai/test/car/di/cachecontrol/gc/WindowMappedGcModule.java +++ /dev/null @@ -1,41 +0,0 @@ -package com.github.klee0kai.test.car.di.cachecontrol.gc; - -import com.github.klee0kai.stone.annotations.module.Module; -import com.github.klee0kai.stone.annotations.module.Provide; -import com.github.klee0kai.test.car.di.cachecontrol.gc.scopes.GcWindowScope; -import com.github.klee0kai.test.car.model.Window; - -import java.lang.ref.WeakReference; -import java.util.Arrays; -import java.util.Collection; -import java.util.List; - -@Module -public class WindowMappedGcModule { - - @GcWindowScope - @Provide(cache = Provide.CacheType.Factory) - public WeakReference> windowFactory(String qualifier) { - return new WeakReference<>(Arrays.asList(new Window(), new Window(), new Window())); - } - - @GcWindowScope - @Provide(cache = Provide.CacheType.Weak) - public WeakReference> windowWeak(String qualifier) { - return new WeakReference<>(Arrays.asList(new Window(), new Window(), new Window())); - } - - @GcWindowScope - @Provide(cache = Provide.CacheType.Soft) - public WeakReference> windowSoft(String qualifier) { - return new WeakReference<>(Arrays.asList(new Window(), new Window(), new Window())); - } - - @GcWindowScope - @Provide(cache = Provide.CacheType.Strong) - public WeakReference> windowStrong(String qualifier) { - return new WeakReference<>(Arrays.asList(new Window(), new Window(), new Window())); - } - - -} diff --git a/tests_wraps/src/main/java/com/github/klee0kai/test/car/di/cachecontrol/gc/WindowMultiMappedGcModule.java b/tests_wraps/src/main/java/com/github/klee0kai/test/car/di/cachecontrol/gc/WindowMultiMappedGcModule.java deleted file mode 100644 index fcb59373..00000000 --- a/tests_wraps/src/main/java/com/github/klee0kai/test/car/di/cachecontrol/gc/WindowMultiMappedGcModule.java +++ /dev/null @@ -1,41 +0,0 @@ -package com.github.klee0kai.test.car.di.cachecontrol.gc; - -import com.github.klee0kai.stone.annotations.module.Module; -import com.github.klee0kai.stone.annotations.module.Provide; -import com.github.klee0kai.test.car.di.cachecontrol.gc.scopes.GcWindowScope; -import com.github.klee0kai.test.car.model.Window; - -import java.lang.ref.WeakReference; -import java.util.Arrays; -import java.util.Collection; -import java.util.List; - -@Module -public class WindowMultiMappedGcModule { - - @GcWindowScope - @Provide(cache = Provide.CacheType.Factory) - public WeakReference> windowFactory(Integer inx, String qualifier) { - return new WeakReference<>(Arrays.asList(new Window(), new Window(), new Window())); - } - - @GcWindowScope - @Provide(cache = Provide.CacheType.Weak) - public WeakReference> windowWeak(Integer inx, String qualifier) { - return new WeakReference<>(Arrays.asList(new Window(), new Window(), new Window())); - } - - @GcWindowScope - @Provide(cache = Provide.CacheType.Soft) - public WeakReference> windowSoft(Integer inx, String qualifier) { - return new WeakReference<>(Arrays.asList(new Window(), new Window(), new Window())); - } - - @GcWindowScope - @Provide(cache = Provide.CacheType.Strong) - public WeakReference> windowStrong(Integer inx, String qualifier) { - return new WeakReference<>(Arrays.asList(new Window(), new Window(), new Window())); - } - - -} diff --git a/tests_wraps/src/main/java/com/github/klee0kai/test/car/di/cachecontrol/gc/scopes/GcBumperRedScope.java b/tests_wraps/src/main/java/com/github/klee0kai/test/car/di/cachecontrol/gc/scopes/GcBumperRedScope.java deleted file mode 100644 index 79b9a8dd..00000000 --- a/tests_wraps/src/main/java/com/github/klee0kai/test/car/di/cachecontrol/gc/scopes/GcBumperRedScope.java +++ /dev/null @@ -1,14 +0,0 @@ -package com.github.klee0kai.test.car.di.cachecontrol.gc.scopes; - -import javax.inject.Scope; -import java.lang.annotation.Retention; -import java.lang.annotation.Target; - -import static java.lang.annotation.ElementType.METHOD; -import static java.lang.annotation.RetentionPolicy.RUNTIME; - -@Scope -@Retention(RUNTIME) -@Target(METHOD) -public @interface GcBumperRedScope { -} diff --git a/tests_wraps/src/main/java/com/github/klee0kai/test/car/di/cachecontrol/gc/scopes/GcBumperScope.java b/tests_wraps/src/main/java/com/github/klee0kai/test/car/di/cachecontrol/gc/scopes/GcBumperScope.java deleted file mode 100644 index 3768334d..00000000 --- a/tests_wraps/src/main/java/com/github/klee0kai/test/car/di/cachecontrol/gc/scopes/GcBumperScope.java +++ /dev/null @@ -1,14 +0,0 @@ -package com.github.klee0kai.test.car.di.cachecontrol.gc.scopes; - -import javax.inject.Scope; -import java.lang.annotation.Retention; -import java.lang.annotation.Target; - -import static java.lang.annotation.ElementType.METHOD; -import static java.lang.annotation.RetentionPolicy.RUNTIME; - -@Scope -@Retention(RUNTIME) -@Target(METHOD) -public @interface GcBumperScope { -} diff --git a/tests_wraps/src/main/java/com/github/klee0kai/test/car/di/cachecontrol/gc/scopes/GcWheelScope.java b/tests_wraps/src/main/java/com/github/klee0kai/test/car/di/cachecontrol/gc/scopes/GcWheelScope.java deleted file mode 100644 index 35dcfd16..00000000 --- a/tests_wraps/src/main/java/com/github/klee0kai/test/car/di/cachecontrol/gc/scopes/GcWheelScope.java +++ /dev/null @@ -1,14 +0,0 @@ -package com.github.klee0kai.test.car.di.cachecontrol.gc.scopes; - -import javax.inject.Scope; -import java.lang.annotation.Retention; -import java.lang.annotation.Target; - -import static java.lang.annotation.ElementType.METHOD; -import static java.lang.annotation.RetentionPolicy.RUNTIME; - -@Scope -@Retention(RUNTIME) -@Target(METHOD) -public @interface GcWheelScope { -} diff --git a/tests_wraps/src/main/java/com/github/klee0kai/test/car/di/cachecontrol/gc/scopes/GcWindowScope.java b/tests_wraps/src/main/java/com/github/klee0kai/test/car/di/cachecontrol/gc/scopes/GcWindowScope.java deleted file mode 100644 index 6fec68e5..00000000 --- a/tests_wraps/src/main/java/com/github/klee0kai/test/car/di/cachecontrol/gc/scopes/GcWindowScope.java +++ /dev/null @@ -1,14 +0,0 @@ -package com.github.klee0kai.test.car.di.cachecontrol.gc.scopes; - -import javax.inject.Scope; -import java.lang.annotation.Retention; -import java.lang.annotation.Target; - -import static java.lang.annotation.ElementType.METHOD; -import static java.lang.annotation.RetentionPolicy.RUNTIME; - -@Scope -@Retention(RUNTIME) -@Target(METHOD) -public @interface GcWindowScope { -} diff --git a/tests_wraps/src/main/java/com/github/klee0kai/test/car/di/cachecontrol/swcache/CarSwCacheComponent.java b/tests_wraps/src/main/java/com/github/klee0kai/test/car/di/cachecontrol/swcache/CarSwCacheComponent.java deleted file mode 100644 index 58abb80a..00000000 --- a/tests_wraps/src/main/java/com/github/klee0kai/test/car/di/cachecontrol/swcache/CarSwCacheComponent.java +++ /dev/null @@ -1,88 +0,0 @@ -package com.github.klee0kai.test.car.di.cachecontrol.swcache; - -import com.github.klee0kai.stone.annotations.component.*; -import com.github.klee0kai.test.car.di.cachecontrol.gc.*; -import com.github.klee0kai.test.car.di.cachecontrol.gc.scopes.GcBumperRedScope; -import com.github.klee0kai.test.car.di.cachecontrol.gc.scopes.GcBumperScope; -import com.github.klee0kai.test.car.di.cachecontrol.gc.scopes.GcWheelScope; -import com.github.klee0kai.test.car.di.cachecontrol.gc.scopes.GcWindowScope; - -@Component( - identifiers = {String.class, Integer.class} -) -public abstract class CarSwCacheComponent { - - public abstract BumperGcModule bumpersModule(); - - public abstract WheelGcModule wheelsModule(); - - public abstract WindowGcModule windowsModule(); - - public abstract WindowMappedGcModule windowsMappedModule(); - - public abstract WindowMultiMappedGcModule windowsMultiMappedModule(); - - @GcAllScope - @SwitchCache(cache = SwitchCache.CacheType.Weak) - public abstract void allWeak(); - - @GcWeakScope - @SwitchCache(cache = SwitchCache.CacheType.Strong, timeMillis = 100) - public abstract void weakToStrongFewMillis(); - - @GcWeakScope - @SwitchCache(cache = SwitchCache.CacheType.Soft, timeMillis = 100) - public abstract void weakToSoftFewMillis(); - - - @GcSoftScope - @SwitchCache(cache = SwitchCache.CacheType.Weak) - public abstract void softToWeak(); - - @GcStrongScope - @SwitchCache(cache = SwitchCache.CacheType.Weak) - public abstract void strongToWeak(); - - @GcWheelScope - @SwitchCache(cache = SwitchCache.CacheType.Weak) - public abstract void wheelsToWeak(); - - @GcBumperScope - @SwitchCache(cache = SwitchCache.CacheType.Weak) - public abstract void bumpersToWeak(); - - @GcBumperRedScope - @SwitchCache(cache = SwitchCache.CacheType.Weak) - public abstract void redBumpersToWeak(); - - @GcBumperRedScope - @GcBumperScope - @SwitchCache(cache = SwitchCache.CacheType.Weak) - public abstract void redBumpersToWeak2(); - - @GcWindowScope - @SwitchCache(cache = SwitchCache.CacheType.Weak) - public abstract void windowsToWeak(); - - @GcWindowScope - @GcWeakScope - @SwitchCache(cache = SwitchCache.CacheType.Strong) - public abstract void weakWindowsToStrong(); - - @GcWindowScope - @GcSoftScope - @SwitchCache(cache = SwitchCache.CacheType.Weak) - public abstract void softWindowsToWeak(); - - @GcWindowScope - @GcBumperScope - @SwitchCache(cache = SwitchCache.CacheType.Weak) - public abstract void nothingToWeak(); - - public void windowsAndWheelsToWeak() { - wheelsToWeak(); - windowsToWeak(); - } - - -} diff --git a/tests_wraps/src/main/java/com/github/klee0kai/test/car/di/inject/CarInjectComponent.java b/tests_wraps/src/main/java/com/github/klee0kai/test/car/di/inject/CarInjectComponent.java deleted file mode 100644 index a3a239c4..00000000 --- a/tests_wraps/src/main/java/com/github/klee0kai/test/car/di/inject/CarInjectComponent.java +++ /dev/null @@ -1,32 +0,0 @@ -package com.github.klee0kai.test.car.di.inject; - -import com.github.klee0kai.stone.annotations.component.Component; -import com.github.klee0kai.stone.annotations.component.ProtectInjected; -import com.github.klee0kai.test.car.di.wrapped.custom.wrappers.CarProviderWrapper; -import com.github.klee0kai.test.car.model.CarInject; -import com.github.klee0kai.test.car.model.CarInjectLists; -import com.github.klee0kai.test.car.model.CarInjectProvider; - -@Component( - wrapperProviders = {CarProviderWrapper.class} -) -public abstract class CarInjectComponent { - - protected abstract CarInjectModule module(); - - public abstract void inject(CarInject carInject); - - public abstract void inject(CarInjectLists carInject); - - public abstract void inject(CarInjectProvider carInject); - - @ProtectInjected - public abstract void protect(CarInject carInject); - - @ProtectInjected - public abstract void protect(CarInjectLists carInject); - - @ProtectInjected - public abstract void protect(CarInjectProvider carInject); - -} diff --git a/tests_wraps/src/main/java/com/github/klee0kai/test/car/di/inject/CarInjectModule.java b/tests_wraps/src/main/java/com/github/klee0kai/test/car/di/inject/CarInjectModule.java deleted file mode 100644 index 22f2738e..00000000 --- a/tests_wraps/src/main/java/com/github/klee0kai/test/car/di/inject/CarInjectModule.java +++ /dev/null @@ -1,47 +0,0 @@ -package com.github.klee0kai.test.car.di.inject; - -import com.github.klee0kai.stone.annotations.module.Module; -import com.github.klee0kai.stone.annotations.module.Provide; -import com.github.klee0kai.stone.wrappers.Ref; -import com.github.klee0kai.test.car.model.Bumper; -import com.github.klee0kai.test.car.model.Wheel; -import com.github.klee0kai.test.car.model.Window; - -import javax.inject.Named; -import javax.inject.Provider; -import java.lang.ref.WeakReference; -import java.util.Arrays; -import java.util.Collection; -import java.util.List; - -@Module -public abstract class CarInjectModule { - - @Provide(cache = Provide.CacheType.Weak) - public List fourWheels() { - return Arrays.asList(new Wheel(), new Wheel(), new Wheel(), new Wheel()); - } - - @Named - @Provide(cache = Provide.CacheType.Weak) - public abstract Wheel spareWheel(); - - @Provide(cache = Provide.CacheType.Factory) - public abstract Provider frontWindow(); - - @Named - @Provide(cache = Provide.CacheType.Factory) - public abstract Provider> backWindow(); - - @Named - @Provide(cache = Provide.CacheType.Factory) - public List> passengerWindows() { - return Arrays.asList(Window::new, Window::new); - } - - @Provide(cache = Provide.CacheType.Weak) - public Collection bumpers() { - return Arrays.asList(new Bumper(), new Bumper()); - } - -} diff --git a/tests_wraps/src/main/java/com/github/klee0kai/test/car/di/lists/cached/CarMultiCachedComponent.java b/tests_wraps/src/main/java/com/github/klee0kai/test/car/di/lists/cached/CarMultiCachedComponent.java deleted file mode 100644 index 91be4967..00000000 --- a/tests_wraps/src/main/java/com/github/klee0kai/test/car/di/lists/cached/CarMultiCachedComponent.java +++ /dev/null @@ -1,31 +0,0 @@ -package com.github.klee0kai.test.car.di.lists.cached; - -import com.github.klee0kai.stone.annotations.component.Component; -import com.github.klee0kai.stone.wrappers.Ref; -import com.github.klee0kai.test.car.model.Bumper; -import com.github.klee0kai.test.car.model.Car; -import com.github.klee0kai.test.car.model.Wheel; -import com.github.klee0kai.test.car.model.Window; - -import javax.inject.Provider; -import java.lang.ref.WeakReference; -import java.util.List; - -@Component -public interface CarMultiCachedComponent { - - CarMultiCachedModule cachedModule(); - - Ref singleBumper(); - - List>> wheels(); - - Wheel wheel(); - - List> windows(); - - List>> windowsProviding(); - - List cars(); - -} diff --git a/tests_wraps/src/main/java/com/github/klee0kai/test/car/di/lists/cached/CarMultiCachedModule.java b/tests_wraps/src/main/java/com/github/klee0kai/test/car/di/lists/cached/CarMultiCachedModule.java deleted file mode 100644 index 4295ad49..00000000 --- a/tests_wraps/src/main/java/com/github/klee0kai/test/car/di/lists/cached/CarMultiCachedModule.java +++ /dev/null @@ -1,55 +0,0 @@ -package com.github.klee0kai.test.car.di.lists.cached; - -import com.github.klee0kai.stone.annotations.module.Module; -import com.github.klee0kai.stone.annotations.module.Provide; -import com.github.klee0kai.stone.wrappers.Ref; -import com.github.klee0kai.test.car.model.Bumper; -import com.github.klee0kai.test.car.model.Car; -import com.github.klee0kai.test.car.model.Wheel; -import com.github.klee0kai.test.car.model.Window; - -import javax.inject.Named; -import javax.inject.Provider; -import java.lang.ref.WeakReference; -import java.util.Arrays; -import java.util.Collection; -import java.util.List; - -@Module -public abstract class CarMultiCachedModule { - - @Provide(cache = Provide.CacheType.Weak) - public List fourWheels() { - return Arrays.asList(new Wheel(), new Wheel(), new Wheel(), new Wheel()); - } - - @Named - @Provide(cache = Provide.CacheType.Weak) - public abstract Wheel spareWheel(); - - @Provide(cache = Provide.CacheType.Factory) - public abstract Provider frontWindow(); - - @Named - @Provide(cache = Provide.CacheType.Factory) - public abstract Provider> backWindow(); - - @Named - @Provide(cache = Provide.CacheType.Factory) - public List> passengerWindows() { - return Arrays.asList(Window::new, Window::new); - } - - @Provide(cache = Provide.CacheType.Weak) - public Collection bumpers() { - return Arrays.asList(new Bumper(), new Bumper()); - } - - @Provide(cache = Provide.CacheType.Weak) - public abstract List redCar(Bumper bumper, Wheel wheel, Window window); - - @Provide(cache = Provide.CacheType.Weak) - public abstract Car blueCar(List bumpers, List wheels, List windows); - - -} diff --git a/tests_wraps/src/main/java/com/github/klee0kai/test/car/di/lists/factory/CarMultiComponent.java b/tests_wraps/src/main/java/com/github/klee0kai/test/car/di/lists/factory/CarMultiComponent.java deleted file mode 100644 index 5b66f578..00000000 --- a/tests_wraps/src/main/java/com/github/klee0kai/test/car/di/lists/factory/CarMultiComponent.java +++ /dev/null @@ -1,38 +0,0 @@ -package com.github.klee0kai.test.car.di.lists.factory; - -import com.github.klee0kai.stone.annotations.component.Component; -import com.github.klee0kai.stone.wrappers.Ref; -import com.github.klee0kai.test.car.model.Bumper; -import com.github.klee0kai.test.car.model.Car; -import com.github.klee0kai.test.car.model.Wheel; -import com.github.klee0kai.test.car.model.Window; - -import javax.inject.Named; -import javax.inject.Provider; -import java.lang.ref.WeakReference; -import java.util.List; - -@Component -public interface CarMultiComponent { - - CarMultiModule module(); - - Ref singleBumper(); - - List>> wheels(); - - Wheel wheel(); - - List> windows(); - - List>> windowsProviding(); - - List cars(); - - @Named("blueCar") - Provider blueCar(); - - @Named("redCar") - WeakReference redCar(); - -} diff --git a/tests_wraps/src/main/java/com/github/klee0kai/test/car/di/lists/factory/CarMultiModule.java b/tests_wraps/src/main/java/com/github/klee0kai/test/car/di/lists/factory/CarMultiModule.java deleted file mode 100644 index 54bec5c3..00000000 --- a/tests_wraps/src/main/java/com/github/klee0kai/test/car/di/lists/factory/CarMultiModule.java +++ /dev/null @@ -1,57 +0,0 @@ -package com.github.klee0kai.test.car.di.lists.factory; - -import com.github.klee0kai.stone.annotations.module.Module; -import com.github.klee0kai.stone.annotations.module.Provide; -import com.github.klee0kai.stone.wrappers.Ref; -import com.github.klee0kai.test.car.model.Bumper; -import com.github.klee0kai.test.car.model.Car; -import com.github.klee0kai.test.car.model.Wheel; -import com.github.klee0kai.test.car.model.Window; - -import javax.inject.Named; -import javax.inject.Provider; -import java.lang.ref.WeakReference; -import java.util.Arrays; -import java.util.Collection; -import java.util.List; - -@Module -public abstract class CarMultiModule { - - @Provide(cache = Provide.CacheType.Factory) - public List fourWheels() { - return Arrays.asList(new Wheel(), new Wheel(), new Wheel(), new Wheel()); - } - - @Named - @Provide(cache = Provide.CacheType.Factory) - public abstract Wheel spareWheel(); - - @Provide(cache = Provide.CacheType.Factory) - public abstract Provider frontWindow(); - - @Named - @Provide(cache = Provide.CacheType.Factory) - public abstract Provider> backWindow(); - - @Named - @Provide(cache = Provide.CacheType.Factory) - public List> passengerWindows() { - return Arrays.asList(Window::new, Window::new); - } - - @Provide(cache = Provide.CacheType.Factory) - public Collection bumpers() { - return Arrays.asList(new Bumper(), new Bumper()); - } - - @Named("redCar") - @Provide(cache = Provide.CacheType.Factory) - public abstract Car redCar(Bumper bumper, Wheel wheel, Window window); - - @Named("blueCar") - @Provide(cache = Provide.CacheType.Factory) - public abstract Car blueCar(List bumpers, List wheels, List windows); - - -} diff --git a/tests_wraps/src/main/java/com/github/klee0kai/test/car/di/qualifiers/CarQCModule.java b/tests_wraps/src/main/java/com/github/klee0kai/test/car/di/qualifiers/CarQCModule.java deleted file mode 100644 index 0344b977..00000000 --- a/tests_wraps/src/main/java/com/github/klee0kai/test/car/di/qualifiers/CarQCModule.java +++ /dev/null @@ -1,150 +0,0 @@ -package com.github.klee0kai.test.car.di.qualifiers; - -import com.github.klee0kai.stone.annotations.module.Module; -import com.github.klee0kai.stone.annotations.module.Provide; -import com.github.klee0kai.test.car.di.qualifiers.qualifiers.*; -import com.github.klee0kai.test.car.model.Bumper; -import com.github.klee0kai.test.car.model.Car; -import com.github.klee0kai.test.car.model.Wheel; -import com.github.klee0kai.test.car.model.Window; - -import javax.inject.Named; -import javax.inject.Provider; -import java.lang.ref.Reference; -import java.lang.ref.WeakReference; -import java.util.List; - -@Module -public class CarQCModule { - - @Provide(cache = Provide.CacheType.Factory) - public Car carSimple(Wheel wheel, @BumperQualifier Bumper bumper, Window window) { - return new Car(bumper, wheel, window); - } - - @Provide(cache = Provide.CacheType.Factory) - public Car carProvider(@BumperQualifier Provider bumper, Provider wheel, Provider window) { - return new Car(bumper.get(), wheel.get(), window.get()); - } - - @Provide(cache = Provide.CacheType.Factory) - public Car carRef(@BumperQualifier WeakReference bumper, Reference wheel, Reference window) { - return new Car(bumper.get(), wheel.get(), window.get()); - } - - - @Provide(cache = Provide.CacheType.Factory) - public Car carList(@BumperQualifier List bumper, List wheel, List window) { - return new Car(bumper, wheel, window); - } - - @Named() - @Provide(cache = Provide.CacheType.Factory) - public Car carNamedEmpty(@BumperQualifier List bumper, List wheel, List window) { - Car car = new Car(bumper, wheel, window); - car.qualifier = "named_empty"; - return car; - } - - - @Named("a") - @Provide(cache = Provide.CacheType.Factory) - public Car carNamedA( - @BumperQualifier(type = BumperQualifier.BumperType.Reinforced) List bumper, - List wheel, - List window - ) { - Car car = new Car(bumper, wheel, window); - car.qualifier = "named_a"; - return car; - } - - - @MyQualifier - @Provide(cache = Provide.CacheType.Factory) - public Car carMyQualifier(@BumperQualifier List bumper, List wheel, List window) { - Car car = new Car(bumper, wheel, window); - car.qualifier = "my_qualifier"; - return car; - } - - - @MyQualifierWithString() - @Provide(cache = Provide.CacheType.Factory) - public Car carIdQualifier(@BumperQualifier List bumper, List wheel, List window) { - Car car = new Car(bumper, wheel, window); - car.qualifier = "my_qualifier_with_string"; - return car; - } - - - @MyQualifierWithString(id = "a") - @Provide(cache = Provide.CacheType.Factory) - public Car carIdQualifierA( - @BumperQualifier(type = BumperQualifier.BumperType.Reinforced) List bumper, - @WheelCount(count = 4) List wheel, - List window - ) { - Car car = new Car(bumper, wheel, window); - car.qualifier = "my_qualifier_a"; - return car; - } - - - @MyQualifierWithString(id = "b") - @Provide(cache = Provide.CacheType.Factory) - public Car carIdQualifierB(@BumperQualifier List bumper, List wheel, List window) { - Car car = new Car(bumper, wheel, window); - car.qualifier = "my_qualifier_b"; - return car; - } - - - @MyQualifierMulti() - @Provide(cache = Provide.CacheType.Factory) - public Car carQualifierMulti( - @BumperQualifier List bumper, - @WheelCount(count = 4) List wheel, - List window - ) { - Car car = new Car(bumper, wheel, window); - car.qualifier = "qualifier_multi"; - return car; - } - - - @MyQualifierMulti(id = "a", indx = 1) - @Provide(cache = Provide.CacheType.Factory) - public Car carQualifierMultiA1(@BumperQualifier List bumper, List wheel, List window) { - Car car = new Car(bumper, wheel, window); - car.qualifier = "qualifier_multi_a1"; - return car; - } - - @MyQualifierMulti(id = "a", indx = 2) - @Provide(cache = Provide.CacheType.Factory) - public Car carQualifierMultiA2( - @BumperQualifier(type = BumperQualifier.BumperType.Reinforced) List bumper, - @WheelCount(count = 4) List wheel, - List window - ) { - Car car = new Car(bumper, wheel, window); - car.qualifier = "qualifier_multi_a2"; - return car; - } - - - @MyQualifierMulti(id = "a", indx = 2, type = MyQualifierMulti.Type.HARD) - @Provide(cache = Provide.CacheType.Factory) - public Car carQualifierMultiA2Hard( - @BumperQualifier(type = BumperQualifier.BumperType.Simple) List bumper, - @WheelCount(count = 4) List wheel, - List window - ) { - Car car = new Car(bumper, wheel, window); - car.qualifier = "qualifier_multi_a2_hard"; - return car; - } - - -} diff --git a/tests_wraps/src/main/java/com/github/klee0kai/test/car/di/qualifiers/CarQComponent.java b/tests_wraps/src/main/java/com/github/klee0kai/test/car/di/qualifiers/CarQComponent.java deleted file mode 100644 index 4f96c0a8..00000000 --- a/tests_wraps/src/main/java/com/github/klee0kai/test/car/di/qualifiers/CarQComponent.java +++ /dev/null @@ -1,62 +0,0 @@ -package com.github.klee0kai.test.car.di.qualifiers; - -import com.github.klee0kai.stone.annotations.component.Component; -import com.github.klee0kai.test.car.di.qualifiers.qualifiers.MyQualifier; -import com.github.klee0kai.test.car.di.qualifiers.qualifiers.MyQualifierMulti; -import com.github.klee0kai.test.car.di.qualifiers.qualifiers.MyQualifierWithString; -import com.github.klee0kai.test.car.model.Car; -import com.github.klee0kai.test.car.model.CarsInjectQualifiers; - -import javax.inject.Named; -import java.util.List; - -@Component -public interface CarQComponent { - - CarQPModule module1(); - - - CarQCModule module2(); - - - @Named() - Car carNamedEmpty(); - - @Named("a") - Car carNameA(); - - @MyQualifier - Car carMyQualifier(); - - @MyQualifierWithString - Car carMyQualifierString(); - - @MyQualifierWithString(id = "a") - Car carMyQualifierStringA(); - - @MyQualifierWithString(id = "b") - Car carMyQualifierStringB(); - - @MyQualifierMulti() - Car carMyQualifierMulti(); - - @MyQualifierMulti(indx = 1, id = "a") - Car carMyQualifierMultiA1(); - - - @MyQualifierMulti(id = "a", indx = 2) - Car carMyQualifierMultiA2(); - - @MyQualifierMulti(type = MyQualifierMulti.Type.HARD, indx = 2, id = "a") - Car carMyQualifierMultiA2Hard(); - - List allCars(); - - @Named - List provideCarsNamedEmpty(); - - @MyQualifierMulti(type = MyQualifierMulti.Type.HARD, indx = 2, id = "a") - List carsMyQualifierMultiA2Hard(); - - void inject(CarsInjectQualifiers carInject); -} diff --git a/tests_wraps/src/main/java/com/github/klee0kai/test/car/di/qualifiers/CarQPModule.java b/tests_wraps/src/main/java/com/github/klee0kai/test/car/di/qualifiers/CarQPModule.java deleted file mode 100644 index 12b52b94..00000000 --- a/tests_wraps/src/main/java/com/github/klee0kai/test/car/di/qualifiers/CarQPModule.java +++ /dev/null @@ -1,46 +0,0 @@ -package com.github.klee0kai.test.car.di.qualifiers; - -import com.github.klee0kai.stone.annotations.module.Module; -import com.github.klee0kai.stone.annotations.module.Provide; -import com.github.klee0kai.stone.wrappers.Ref; -import com.github.klee0kai.test.car.di.qualifiers.qualifiers.BumperQualifier; -import com.github.klee0kai.test.car.di.qualifiers.qualifiers.WheelCount; -import com.github.klee0kai.test.car.model.Bumper; -import com.github.klee0kai.test.car.model.Wheel; -import com.github.klee0kai.test.car.model.Window; - -import java.util.Arrays; -import java.util.List; - -@Module -public abstract class CarQPModule { - - @Provide(cache = Provide.CacheType.Factory) - public abstract Wheel wheel(); - - @WheelCount(count = 4) - @Provide(cache = Provide.CacheType.Factory) - public List fourWheel() { - return Arrays.asList(new Wheel(), new Wheel(), new Wheel(), new Wheel()); - } - - @BumperQualifier(type = BumperQualifier.BumperType.Simple) - @Provide(cache = Provide.CacheType.Factory) - public Bumper bumperSimple() { - Bumper bumper = new Bumper(); - bumper.qualifier = "simple"; - return bumper; - } - - @BumperQualifier(type = BumperQualifier.BumperType.Reinforced) - @Provide(cache = Provide.CacheType.Factory) - public Bumper bumper() { - Bumper bumper = new Bumper(); - bumper.qualifier = "reinforced"; - return bumper; - } - - @Provide(cache = Provide.CacheType.Factory) - public abstract Ref> windows(); - -} diff --git a/tests_wraps/src/main/java/com/github/klee0kai/test/car/di/qualifiers/qualifiers/BumperQualifier.java b/tests_wraps/src/main/java/com/github/klee0kai/test/car/di/qualifiers/qualifiers/BumperQualifier.java deleted file mode 100644 index 7977ec55..00000000 --- a/tests_wraps/src/main/java/com/github/klee0kai/test/car/di/qualifiers/qualifiers/BumperQualifier.java +++ /dev/null @@ -1,22 +0,0 @@ -package com.github.klee0kai.test.car.di.qualifiers.qualifiers; - - -import javax.inject.Qualifier; -import java.lang.annotation.Documented; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; - - -@Qualifier -@Retention(RetentionPolicy.RUNTIME) -@Documented -public @interface BumperQualifier { - BumperType type() default BumperType.Simple; - - enum BumperType { - Simple, - Reinforced - } - - -} diff --git a/tests_wraps/src/main/java/com/github/klee0kai/test/car/di/qualifiers/qualifiers/MyQualifier.java b/tests_wraps/src/main/java/com/github/klee0kai/test/car/di/qualifiers/qualifiers/MyQualifier.java deleted file mode 100644 index a26a2c05..00000000 --- a/tests_wraps/src/main/java/com/github/klee0kai/test/car/di/qualifiers/qualifiers/MyQualifier.java +++ /dev/null @@ -1,14 +0,0 @@ -package com.github.klee0kai.test.car.di.qualifiers.qualifiers; - - -import javax.inject.Qualifier; -import java.lang.annotation.Documented; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; - - -@Qualifier -@Retention(RetentionPolicy.RUNTIME) -@Documented -public @interface MyQualifier { -} diff --git a/tests_wraps/src/main/java/com/github/klee0kai/test/car/di/qualifiers/qualifiers/MyQualifierMulti.java b/tests_wraps/src/main/java/com/github/klee0kai/test/car/di/qualifiers/qualifiers/MyQualifierMulti.java deleted file mode 100644 index bda7ac5d..00000000 --- a/tests_wraps/src/main/java/com/github/klee0kai/test/car/di/qualifiers/qualifiers/MyQualifierMulti.java +++ /dev/null @@ -1,27 +0,0 @@ -package com.github.klee0kai.test.car.di.qualifiers.qualifiers; - - -import javax.inject.Qualifier; -import java.lang.annotation.Documented; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; - - -@Qualifier -@Retention(RetentionPolicy.RUNTIME) -@Documented -public @interface MyQualifierMulti { - - String id() default ""; - - int indx() default 0; - - Type type() default Type.SIMPLE; - - enum Type { - SIMPLE, - MIDDLE, - HARD, - } -} - diff --git a/tests_wraps/src/main/java/com/github/klee0kai/test/car/di/qualifiers/qualifiers/MyQualifierWithString.java b/tests_wraps/src/main/java/com/github/klee0kai/test/car/di/qualifiers/qualifiers/MyQualifierWithString.java deleted file mode 100644 index 39a6de81..00000000 --- a/tests_wraps/src/main/java/com/github/klee0kai/test/car/di/qualifiers/qualifiers/MyQualifierWithString.java +++ /dev/null @@ -1,17 +0,0 @@ -package com.github.klee0kai.test.car.di.qualifiers.qualifiers; - - -import javax.inject.Qualifier; -import java.lang.annotation.Documented; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; - - -@Qualifier -@Retention(RetentionPolicy.RUNTIME) -@Documented -public @interface MyQualifierWithString { - - String id() default ""; - -} diff --git a/tests_wraps/src/main/java/com/github/klee0kai/test/car/di/qualifiers/qualifiers/WheelCount.java b/tests_wraps/src/main/java/com/github/klee0kai/test/car/di/qualifiers/qualifiers/WheelCount.java deleted file mode 100644 index 6be5376c..00000000 --- a/tests_wraps/src/main/java/com/github/klee0kai/test/car/di/qualifiers/qualifiers/WheelCount.java +++ /dev/null @@ -1,16 +0,0 @@ -package com.github.klee0kai.test.car.di.qualifiers.qualifiers; - - -import javax.inject.Qualifier; -import java.lang.annotation.Documented; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; - - -@Qualifier -@Retention(RetentionPolicy.RUNTIME) -@Documented -public @interface WheelCount { - int count() default 1; - -} diff --git a/tests_wraps/src/main/java/com/github/klee0kai/test/car/di/wrapped/create/CarWrappedCreateComponent.java b/tests_wraps/src/main/java/com/github/klee0kai/test/car/di/wrapped/create/CarWrappedCreateComponent.java deleted file mode 100644 index 59740585..00000000 --- a/tests_wraps/src/main/java/com/github/klee0kai/test/car/di/wrapped/create/CarWrappedCreateComponent.java +++ /dev/null @@ -1,44 +0,0 @@ -package com.github.klee0kai.test.car.di.wrapped.create; - -import com.github.klee0kai.stone.annotations.component.Component; -import com.github.klee0kai.stone.wrappers.AsyncProvide; -import com.github.klee0kai.stone.wrappers.LazyProvide; -import com.github.klee0kai.test.car.model.Car; -import com.github.klee0kai.test.car.model.Wheel; -import com.github.klee0kai.test.car.model.Window; - -import javax.inject.Provider; -import java.lang.ref.WeakReference; - -@Component -public interface CarWrappedCreateComponent { - - CarWrappedCreateModule factory(); - - Wheel wheel(); - - Provider wheelProvide(); - - LazyProvide wheelLazy(); - - WeakReference wheelWeak(); - - Provider> whellProviderWeak(); - - LazyProvide>> whellLazyProviderWeak(); - - Provider whellProvider(); - - LazyProvide carLazy(); - - Provider carProvider(); - - WeakReference carWeak(); - - Window window(); - - Car car(); - - AsyncProvide carAsync(); - -} diff --git a/tests_wraps/src/main/java/com/github/klee0kai/test/car/di/wrapped/create/CarWrappedCreateModule.java b/tests_wraps/src/main/java/com/github/klee0kai/test/car/di/wrapped/create/CarWrappedCreateModule.java deleted file mode 100644 index 00efd0e5..00000000 --- a/tests_wraps/src/main/java/com/github/klee0kai/test/car/di/wrapped/create/CarWrappedCreateModule.java +++ /dev/null @@ -1,30 +0,0 @@ -package com.github.klee0kai.test.car.di.wrapped.create; - -import com.github.klee0kai.stone.annotations.module.Module; -import com.github.klee0kai.stone.annotations.module.Provide; -import com.github.klee0kai.test.car.model.Bumper; -import com.github.klee0kai.test.car.model.Car; -import com.github.klee0kai.test.car.model.Wheel; -import com.github.klee0kai.test.car.model.Window; - -import java.lang.ref.WeakReference; - -@Module -public interface CarWrappedCreateModule { - - - @Provide(cache = Provide.CacheType.Soft) - Wheel whell(); - - WeakReference bumper(); - - - @Provide(cache = Provide.CacheType.Soft) - Window window(); - - - @Provide(cache = Provide.CacheType.Soft) - Car car(Bumper bumper, Wheel wheel, Window window); - - -} diff --git a/tests_wraps/src/main/java/com/github/klee0kai/test/car/di/wrapped/custom/CarCustomWrapperModule.java b/tests_wraps/src/main/java/com/github/klee0kai/test/car/di/wrapped/custom/CarCustomWrapperModule.java deleted file mode 100644 index 0e570e90..00000000 --- a/tests_wraps/src/main/java/com/github/klee0kai/test/car/di/wrapped/custom/CarCustomWrapperModule.java +++ /dev/null @@ -1,28 +0,0 @@ -package com.github.klee0kai.test.car.di.wrapped.custom; - -import com.github.klee0kai.stone.annotations.module.Module; -import com.github.klee0kai.stone.annotations.module.Provide; -import com.github.klee0kai.test.car.model.Bumper; -import com.github.klee0kai.test.car.model.Car; -import com.github.klee0kai.test.car.model.Wheel; -import com.github.klee0kai.test.car.model.Window; - -import java.lang.ref.WeakReference; - -@Module -public interface CarCustomWrapperModule { - - @Provide(cache = Provide.CacheType.Factory) - Wheel whell(); - - @Provide(cache = Provide.CacheType.Factory) - WeakReference bumper(); - - @Provide(cache = Provide.CacheType.Factory) - Window window(); - - @Provide(cache = Provide.CacheType.Factory) - Car car(Bumper bumper, Wheel wheel, Window window); - - -} diff --git a/tests_wraps/src/main/java/com/github/klee0kai/test/car/di/wrapped/custom/CarCustomWrappersComponent.java b/tests_wraps/src/main/java/com/github/klee0kai/test/car/di/wrapped/custom/CarCustomWrappersComponent.java deleted file mode 100644 index 8e2e233a..00000000 --- a/tests_wraps/src/main/java/com/github/klee0kai/test/car/di/wrapped/custom/CarCustomWrappersComponent.java +++ /dev/null @@ -1,24 +0,0 @@ -package com.github.klee0kai.test.car.di.wrapped.custom; - -import com.github.klee0kai.stone.annotations.component.Component; -import com.github.klee0kai.test.car.di.wrapped.custom.wrappers.*; -import com.github.klee0kai.test.car.model.Car; - -@Component( - wrapperProviders = { - CarProviderWrapper.class, - CarWrapper.class, - } -) -public interface CarCustomWrappersComponent { - CarCustomWrapperModule module(); - - Car car(); - - CarRef carRef(); - - CarLazy carLazy(); - - CarProvide carProvide(); - -} diff --git a/tests_wraps/src/main/java/com/github/klee0kai/test/car/di/wrapped/custom/wrappers/CarLazy.java b/tests_wraps/src/main/java/com/github/klee0kai/test/car/di/wrapped/custom/wrappers/CarLazy.java deleted file mode 100644 index 254e9a01..00000000 --- a/tests_wraps/src/main/java/com/github/klee0kai/test/car/di/wrapped/custom/wrappers/CarLazy.java +++ /dev/null @@ -1,20 +0,0 @@ -package com.github.klee0kai.test.car.di.wrapped.custom.wrappers; - -import com.github.klee0kai.stone.wrappers.Ref; - -public class CarLazy { - - private T value = null; - private final Ref call; - - public CarLazy(Ref call) { - this.call = call; - } - - public T getValue() { - if (value != null) - return value; - return value = call.get(); - } - -} diff --git a/tests_wraps/src/main/java/com/github/klee0kai/test/car/di/wrapped/custom/wrappers/CarProvide.java b/tests_wraps/src/main/java/com/github/klee0kai/test/car/di/wrapped/custom/wrappers/CarProvide.java deleted file mode 100644 index 8be52d66..00000000 --- a/tests_wraps/src/main/java/com/github/klee0kai/test/car/di/wrapped/custom/wrappers/CarProvide.java +++ /dev/null @@ -1,17 +0,0 @@ -package com.github.klee0kai.test.car.di.wrapped.custom.wrappers; - -import com.github.klee0kai.stone.wrappers.Ref; - -public class CarProvide { - - private final Ref call; - - public CarProvide(Ref call) { - this.call = call; - } - - public T getValue() { - return call.get(); - } - -} diff --git a/tests_wraps/src/main/java/com/github/klee0kai/test/car/di/wrapped/custom/wrappers/CarProviderWrapper.java b/tests_wraps/src/main/java/com/github/klee0kai/test/car/di/wrapped/custom/wrappers/CarProviderWrapper.java deleted file mode 100644 index 0ead17a4..00000000 --- a/tests_wraps/src/main/java/com/github/klee0kai/test/car/di/wrapped/custom/wrappers/CarProviderWrapper.java +++ /dev/null @@ -1,22 +0,0 @@ -package com.github.klee0kai.test.car.di.wrapped.custom.wrappers; - -import com.github.klee0kai.stone.annotations.wrappers.WrappersCreator; -import com.github.klee0kai.stone.wrappers.creators.ProviderWrapper; - -import javax.inject.Provider; - -@WrappersCreator(wrappers = {CarLazy.class, CarProvide.class}) -public class CarProviderWrapper implements ProviderWrapper { - - @Override - public Wr wrap(Class wrapperCl, Provider originalProvider) { - if (wrapperCl.equals(CarLazy.class)) { - return (Wr) new CarLazy(originalProvider::get); - } - if (wrapperCl.equals(CarProvide.class)) { - return (Wr) new CarProvide(originalProvider::get); - } - return null; - } - -} diff --git a/tests_wraps/src/main/java/com/github/klee0kai/test/car/di/wrapped/custom/wrappers/CarRef.java b/tests_wraps/src/main/java/com/github/klee0kai/test/car/di/wrapped/custom/wrappers/CarRef.java deleted file mode 100644 index 3076da31..00000000 --- a/tests_wraps/src/main/java/com/github/klee0kai/test/car/di/wrapped/custom/wrappers/CarRef.java +++ /dev/null @@ -1,15 +0,0 @@ -package com.github.klee0kai.test.car.di.wrapped.custom.wrappers; - -public class CarRef { - - private T value = null; - - public CarRef(T v) { - this.value = v; - } - - public T getValue() { - return value; - } - -} \ No newline at end of file diff --git a/tests_wraps/src/main/java/com/github/klee0kai/test/car/di/wrapped/custom/wrappers/CarWrapper.java b/tests_wraps/src/main/java/com/github/klee0kai/test/car/di/wrapped/custom/wrappers/CarWrapper.java deleted file mode 100644 index 3979c4f4..00000000 --- a/tests_wraps/src/main/java/com/github/klee0kai/test/car/di/wrapped/custom/wrappers/CarWrapper.java +++ /dev/null @@ -1,17 +0,0 @@ -package com.github.klee0kai.test.car.di.wrapped.custom.wrappers; - -import com.github.klee0kai.stone.annotations.wrappers.WrappersCreator; -import com.github.klee0kai.stone.wrappers.creators.Wrapper; - -@WrappersCreator(wrappers = {CarRef.class}) -public class CarWrapper implements Wrapper { - - @Override - public Wr wrap(Class wrapperCl, T original) { - if (wrapperCl.equals(CarRef.class)) { - return (Wr) new CarRef<>(original); - - } - return null; - } -} diff --git a/tests_wraps/src/main/java/com/github/klee0kai/test/car/model/Bumper.java b/tests_wraps/src/main/java/com/github/klee0kai/test/car/model/Bumper.java deleted file mode 100644 index d56afcbe..00000000 --- a/tests_wraps/src/main/java/com/github/klee0kai/test/car/model/Bumper.java +++ /dev/null @@ -1,15 +0,0 @@ -package com.github.klee0kai.test.car.model; - -import java.util.UUID; - -public class Bumper { - - public static int createCount = 0; - public String uuid = UUID.randomUUID().toString(); - public String qualifier = null; - - public Bumper() { - createCount++; - } - -} diff --git a/tests_wraps/src/main/java/com/github/klee0kai/test/car/model/Car.java b/tests_wraps/src/main/java/com/github/klee0kai/test/car/model/Car.java deleted file mode 100644 index e7d21ed4..00000000 --- a/tests_wraps/src/main/java/com/github/klee0kai/test/car/model/Car.java +++ /dev/null @@ -1,36 +0,0 @@ -package com.github.klee0kai.test.car.model; - -import java.util.Collections; -import java.util.List; -import java.util.UUID; - -public class Car { - - public static int createCount = 0; - public String uuid = UUID.randomUUID().toString(); - - public List bumpers; - public List wheels; - public List windows; - - public String qualifier = null; - - public Car( - Bumper bumper, - Wheel wheel, - Window window - ) { - createCount++; - bumpers = Collections.singletonList(bumper); - wheels = Collections.singletonList(wheel); - windows = Collections.singletonList(window); - } - - - public Car(List bumpers, List wheels, List windows) { - createCount++; - this.bumpers = bumpers; - this.wheels = wheels; - this.windows = windows; - } -} diff --git a/tests_wraps/src/main/java/com/github/klee0kai/test/car/model/CarInject.java b/tests_wraps/src/main/java/com/github/klee0kai/test/car/model/CarInject.java deleted file mode 100644 index 2385b2c7..00000000 --- a/tests_wraps/src/main/java/com/github/klee0kai/test/car/model/CarInject.java +++ /dev/null @@ -1,31 +0,0 @@ -package com.github.klee0kai.test.car.model; - -import javax.inject.Inject; - -public class CarInject { - - - @Inject - public Bumper bumper; - - @Inject - public Wheel wheel; - - @Inject - public Window window; - - public Bumper bumperFromMethod; - - public Wheel wheelFromMethod; - - public Window windowFromMethod; - - - @Inject - public void init(Bumper bumper, Wheel wheel, Window window) { - bumperFromMethod = bumper; - wheelFromMethod = wheel; - windowFromMethod = window; - } - -} diff --git a/tests_wraps/src/main/java/com/github/klee0kai/test/car/model/CarInjectLists.java b/tests_wraps/src/main/java/com/github/klee0kai/test/car/model/CarInjectLists.java deleted file mode 100644 index 3d5a4274..00000000 --- a/tests_wraps/src/main/java/com/github/klee0kai/test/car/model/CarInjectLists.java +++ /dev/null @@ -1,32 +0,0 @@ -package com.github.klee0kai.test.car.model; - -import javax.inject.Inject; -import java.util.List; - -public class CarInjectLists { - - - @Inject - public List bumpers; - - @Inject - public List wheels; - - @Inject - public List windows; - - public List bumpersMethodFrom; - - public List wheelsMethodFrom; - - public List windowsMethodFrom; - - @Inject - public void init(List bumpers, List wheels, List windows) { - bumpersMethodFrom = bumpers; - wheelsMethodFrom = wheels; - windowsMethodFrom = windows; - } - - -} diff --git a/tests_wraps/src/main/java/com/github/klee0kai/test/car/model/CarInjectProvider.java b/tests_wraps/src/main/java/com/github/klee0kai/test/car/model/CarInjectProvider.java deleted file mode 100644 index 5c251778..00000000 --- a/tests_wraps/src/main/java/com/github/klee0kai/test/car/model/CarInjectProvider.java +++ /dev/null @@ -1,33 +0,0 @@ -package com.github.klee0kai.test.car.model; - -import com.github.klee0kai.stone.wrappers.LazyProvide; -import com.github.klee0kai.stone.wrappers.Ref; -import com.github.klee0kai.test.car.di.wrapped.custom.wrappers.CarLazy; - -import javax.inject.Inject; - -public class CarInjectProvider { - - @Inject - public LazyProvide bumper; - - @Inject - public Ref wheel; - - @Inject - public Ref> window; - - public LazyProvide bumperFromMethod; - - public Ref wheelFromMethod; - - public Ref> windowFromMethod; - - @Inject - public void init(LazyProvide bumper, Ref wheel, Ref> window) { - bumperFromMethod = bumper; - wheelFromMethod = wheel; - windowFromMethod = window; - } - -} diff --git a/tests_wraps/src/main/java/com/github/klee0kai/test/car/model/CarsInjectQualifiers.java b/tests_wraps/src/main/java/com/github/klee0kai/test/car/model/CarsInjectQualifiers.java deleted file mode 100644 index c5fc1ba4..00000000 --- a/tests_wraps/src/main/java/com/github/klee0kai/test/car/model/CarsInjectQualifiers.java +++ /dev/null @@ -1,112 +0,0 @@ -package com.github.klee0kai.test.car.model; - -import com.github.klee0kai.test.car.di.qualifiers.qualifiers.MyQualifier; -import com.github.klee0kai.test.car.di.qualifiers.qualifiers.MyQualifierMulti; -import com.github.klee0kai.test.car.di.qualifiers.qualifiers.MyQualifierWithString; - -import javax.inject.Inject; -import javax.inject.Named; -import java.util.List; - -public class CarsInjectQualifiers { - - @Inject - @Named - public Car carNamedEmpty; - - @Inject - @Named("a") - public Car carNamedA; - - @Inject - @MyQualifier - public Car carMyQualifier; - - @Inject - @MyQualifierWithString - public Car carMyQualifierString; - - @Inject - @MyQualifierWithString(id = "a") - public Car carMyQualifierA; - - @Inject - @MyQualifierWithString(id = "b") - public Car carMyQualifierB; - - @Inject - @MyQualifierMulti() - public Car carMyQualifierMulti; - - @Inject - @MyQualifierMulti(indx = 1, id = "a") - public Car carMyQualifierMultiA1; - - @Inject - @MyQualifierMulti(indx = 2, id = "a") - public Car carMyQualifierMultiA2; - - @Inject - @MyQualifierMulti(type = MyQualifierMulti.Type.HARD, id = "a", indx = 2) - public Car carMyQualifierMultiA2Hard; - - @Inject - public List allCars; - - @Inject - @Named - public List carsNamedEmpty; - - @Inject - @MyQualifierMulti(type = MyQualifierMulti.Type.HARD, id = "a", indx = 2) - public List carsMyQualifierMultiA2Hard; - - - public Car methodCarNamedEmpty; - public Car methodCarNamedA; - public Car methodCarMyQualifier; - public Car methodCarMyQualifierString; - public Car methodCarMyQualifierA; - public Car methodCarMyQualifierB; - public Car methodCarMyQualifierMulti; - public Car methodCarMyQualifierMultiA1; - public Car methodCarMyQualifierMultiA2; - public Car methodCarMyQualifierMultiA2Hard; - public List methodAllCars; - public List methodCarsNamedEmpty; - public List methodCarsMyQualifierMultiA2Hard; - - @Inject - public void init( - @Named Car carNamedEmpty, - @Named("a") Car carNamedA, - @MyQualifier Car carMyQualifier, - @MyQualifierWithString Car carMyQualifierString, - @MyQualifierWithString(id = "a") Car carMyQualifierA, - @MyQualifierWithString(id = "b") Car carMyQualifierB, - @MyQualifierMulti() Car carMyQualifierMulti, - @MyQualifierMulti(indx = 1, id = "a") Car carMyQualifierMultiA1, - @MyQualifierMulti(indx = 2, id = "a") Car carMyQualifierMultiA2, - @MyQualifierMulti(type = MyQualifierMulti.Type.HARD, id = "a", indx = 2) - Car carMyQualifierMultiA2Hard, - List allCars, - @Named List carsNamedEmpty, - @MyQualifierMulti(type = MyQualifierMulti.Type.HARD, id = "a", indx = 2) - List carsMyQualifierMultiA2Hard - ) { - methodCarNamedEmpty = carNamedEmpty; - methodCarNamedA = carNamedA; - methodCarMyQualifier = carMyQualifier; - methodCarMyQualifierString = carMyQualifierString; - methodCarMyQualifierA = carMyQualifierA; - methodCarMyQualifierB = carMyQualifierB; - methodCarMyQualifierMulti = carMyQualifierMulti; - methodCarMyQualifierMultiA1 = carMyQualifierMultiA1; - methodCarMyQualifierMultiA2 = carMyQualifierMultiA2; - methodCarMyQualifierMultiA2Hard = carMyQualifierMultiA2Hard; - methodAllCars = allCars; - methodCarsNamedEmpty = carsNamedEmpty; - methodCarsMyQualifierMultiA2Hard = carsMyQualifierMultiA2Hard; - } - -} diff --git a/tests_wraps/src/main/java/com/github/klee0kai/test/car/model/Wheel.java b/tests_wraps/src/main/java/com/github/klee0kai/test/car/model/Wheel.java deleted file mode 100644 index 4db4aabc..00000000 --- a/tests_wraps/src/main/java/com/github/klee0kai/test/car/model/Wheel.java +++ /dev/null @@ -1,15 +0,0 @@ -package com.github.klee0kai.test.car.model; - -import java.util.UUID; - -public class Wheel { - - public static int createCount = 0; - public String uuid = UUID.randomUUID().toString(); - - public Wheel(){ - createCount++; - } - - -} diff --git a/tests_wraps/src/main/java/com/github/klee0kai/test/car/model/Window.java b/tests_wraps/src/main/java/com/github/klee0kai/test/car/model/Window.java deleted file mode 100644 index 0e1967e2..00000000 --- a/tests_wraps/src/main/java/com/github/klee0kai/test/car/model/Window.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.github.klee0kai.test.car.model; - -import java.util.UUID; - -public class Window { - - public static int createCount = 0; - public String uuid = UUID.randomUUID().toString(); - - public Window() { - createCount++; - } -} diff --git a/tests_wraps/src/test/java/com/github/klee0kai/stone/test/boxed/inject/CarBoxedInjectMethodTests.java b/tests_wraps/src/test/java/com/github/klee0kai/stone/test/boxed/inject/CarBoxedInjectMethodTests.java deleted file mode 100644 index c929230c..00000000 --- a/tests_wraps/src/test/java/com/github/klee0kai/stone/test/boxed/inject/CarBoxedInjectMethodTests.java +++ /dev/null @@ -1,159 +0,0 @@ -package com.github.klee0kai.stone.test.boxed.inject; - -import com.github.klee0kai.stone.Stone; -import com.github.klee0kai.stone._hidden_.types.ListUtils; -import com.github.klee0kai.test.boxed.di.inject.CarBoxedInjectComponent; -import com.github.klee0kai.test.boxed.model.CarBox; -import com.github.klee0kai.test.boxed.model.CarBoxedInject; -import com.github.klee0kai.test.boxed.model.CarBoxedInjectLists; -import com.github.klee0kai.test.boxed.model.CarBoxedInjectProvider; -import com.github.klee0kai.test.car.model.Bumper; -import com.github.klee0kai.test.car.model.Car; -import com.github.klee0kai.test.car.model.Wheel; -import com.github.klee0kai.test.car.model.Window; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; - -import java.util.HashSet; -import java.util.Set; - -import static org.junit.jupiter.api.Assertions.*; - -public class CarBoxedInjectMethodTests { - - @BeforeEach - public void init() { - Bumper.createCount = 0; - Window.createCount = 0; - Wheel.createCount = 0; - Car.createCount = 0; - } - - @Test - void carInjectTest() { - //Given - CarBoxedInjectComponent DI = Stone.createComponent(CarBoxedInjectComponent.class); - - //When - CarBoxedInject carInject = new CarBoxedInject(); - DI.inject(carInject); - - // Then - assertEquals(2, Bumper.createCount, "Bumpers created from list"); - assertNotNull(carInject.bumperFromMethod.val.uuid); - assertNotNull(carInject.wheelFromMethod.val.uuid); - assertNotNull(carInject.windowFromMethod.val.uuid); - } - - @Test - void carInjectReusableTest() { - //Given - CarBoxedInjectComponent DI = Stone.createComponent(CarBoxedInjectComponent.class); - - //When - CarBoxedInject carInject1 = new CarBoxedInject(); - CarBoxedInject carInject2 = new CarBoxedInject(); - DI.inject(carInject1); - DI.inject(carInject2); - - - // Then - assertEquals(2, Bumper.createCount, "Bumpers created from list. And reused"); - assertEquals(carInject1.bumperFromMethod.val.uuid, carInject2.bumperFromMethod.val.uuid, "should cache"); - assertEquals(carInject1.wheelFromMethod.val.uuid, carInject2.wheelFromMethod.val.uuid, "should cache "); - assertNotEquals(carInject1.windowFromMethod.val.uuid, carInject2.windowFromMethod.val.uuid, "provide via Provider. No caching"); - } - - - @Test - void carInjectListTest() { - //Given - CarBoxedInjectComponent DI = Stone.createComponent(CarBoxedInjectComponent.class); - - //When - CarBoxedInjectLists carInject = new CarBoxedInjectLists(); - DI.inject(carInject); - - // Then - assertEquals(2, Bumper.createCount); - assertEquals(5, Wheel.createCount); - assertEquals(8, Window.createCount, "Windows created for fields and method"); - assertEquals(2, carInject.bumpersMethodFrom.size()); - assertEquals(5, carInject.wheelsMethodFrom.size()); - assertEquals(4, carInject.windowsMethodFrom.size()); - for (CarBox b : carInject.bumpersMethodFrom) assertNotNull(b.val.uuid); - Set bumperUids = new HashSet<>(ListUtils.format(carInject.bumpersMethodFrom, it -> it.val.uuid)); - assertEquals(2, bumperUids.size()); - for (CarBox w : carInject.wheelsMethodFrom) assertNotNull(w.val.uuid); - Set wheelsUid = new HashSet<>(ListUtils.format(carInject.wheels, it -> it.val.uuid)); - assertEquals(5, wheelsUid.size()); - for (CarBox w : carInject.windowsMethodFrom) assertNotNull(w.val.uuid); - Set windowUids = new HashSet<>(ListUtils.format(carInject.windows, it -> it.val.uuid)); - assertEquals(4, windowUids.size()); - } - - @Test - void carInjectListReusableTest() { - //Given - CarBoxedInjectComponent DI = Stone.createComponent(CarBoxedInjectComponent.class); - - //When - CarBoxedInjectLists carInject1 = new CarBoxedInjectLists(); - CarBoxedInjectLists carInject2 = new CarBoxedInjectLists(); - DI.inject(carInject1); - DI.inject(carInject2); - - // Then - assertEquals(2, carInject1.bumpersMethodFrom.size()); - assertEquals(5, carInject1.wheelsMethodFrom.size()); - assertEquals(4, carInject1.windowsMethodFrom.size()); - for (int i = 0; i < 2; i++) - assertEquals(carInject1.bumpersMethodFrom.get(i).val.uuid, carInject2.bumpersMethodFrom.get(i).val.uuid); - for (int i = 0; i < 2; i++) - assertEquals(carInject1.wheelsMethodFrom.get(i).val.uuid, carInject2.wheelsMethodFrom.get(i).val.uuid); - Set windowUids = new HashSet<>(); - for (int i = 0; i < 4; i++) windowUids.add(carInject1.windowsMethodFrom.get(i).val.uuid); - for (int i = 0; i < 4; i++) windowUids.add(carInject2.windowsMethodFrom.get(i).val.uuid); - assertEquals(8, windowUids.size()); - } - - - @Test - void carInjectProviderTest() { - //Given - CarBoxedInjectComponent DI = Stone.createComponent(CarBoxedInjectComponent.class); - - //When - CarBoxedInjectProvider carInject = new CarBoxedInjectProvider(); - DI.inject(carInject); - - // Then - assertEquals(0, Bumper.createCount, "Provide non used"); - assertNotNull(carInject.bumperFromMethod.get().val.uuid); - assertNotNull(carInject.wheelFromMethod.get().val.uuid); - assertNotNull(carInject.windowFromMethod.get().getValue().val.uuid); - assertEquals(2, Bumper.createCount, "Bumpers created from list"); - } - - - @Test - void carInjectProvideReusableTest() { - //Given - CarBoxedInjectComponent DI = Stone.createComponent(CarBoxedInjectComponent.class); - - //When - CarBoxedInjectProvider carInject1 = new CarBoxedInjectProvider(); - CarBoxedInjectProvider carInject2 = new CarBoxedInjectProvider(); - DI.inject(carInject1); - DI.inject(carInject2); - - - // Then - assertEquals(0, Bumper.createCount, "Provider non used"); - assertEquals(carInject1.bumperFromMethod.get().val.uuid, carInject2.bumperFromMethod.get().val.uuid, "should cache"); - assertEquals(carInject1.wheelFromMethod.get().val.uuid, carInject2.wheelFromMethod.get().val.uuid, "should cache "); - assertNotEquals(carInject1.windowFromMethod.get().getValue().val.uuid, carInject2.windowFromMethod.get().getValue().val.uuid, "provide via Provider. No caching"); - assertEquals(2, Bumper.createCount, "Bumpers created from list. And reused"); - } - -} diff --git a/tests_wraps/src/test/java/com/github/klee0kai/stone/test/boxed/inject/CarBoxedInjectTests.java b/tests_wraps/src/test/java/com/github/klee0kai/stone/test/boxed/inject/CarBoxedInjectTests.java deleted file mode 100644 index 0b92eccd..00000000 --- a/tests_wraps/src/test/java/com/github/klee0kai/stone/test/boxed/inject/CarBoxedInjectTests.java +++ /dev/null @@ -1,158 +0,0 @@ -package com.github.klee0kai.stone.test.boxed.inject; - -import com.github.klee0kai.stone.Stone; -import com.github.klee0kai.stone._hidden_.types.ListUtils; -import com.github.klee0kai.test.boxed.di.inject.CarBoxedInjectComponent; -import com.github.klee0kai.test.boxed.model.CarBox; -import com.github.klee0kai.test.boxed.model.CarBoxedInject; -import com.github.klee0kai.test.boxed.model.CarBoxedInjectLists; -import com.github.klee0kai.test.boxed.model.CarBoxedInjectProvider; -import com.github.klee0kai.test.car.model.Bumper; -import com.github.klee0kai.test.car.model.Car; -import com.github.klee0kai.test.car.model.Wheel; -import com.github.klee0kai.test.car.model.Window; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; - -import java.util.HashSet; -import java.util.Set; - -import static org.junit.jupiter.api.Assertions.*; - -public class CarBoxedInjectTests { - - @BeforeEach - public void init() { - Bumper.createCount = 0; - Window.createCount = 0; - Wheel.createCount = 0; - Car.createCount = 0; - } - - @Test - void carInjectTest() { - //Given - CarBoxedInjectComponent DI = Stone.createComponent(CarBoxedInjectComponent.class); - - //When - CarBoxedInject carInject = new CarBoxedInject(); - DI.inject(carInject); - - // Then - assertEquals(2, Bumper.createCount, "Bumpers created from list"); - assertNotNull(carInject.bumper.val.uuid); - assertNotNull(carInject.wheel.val.uuid); - assertNotNull(carInject.window.val.uuid); - } - - @Test - void carInjectReusableTest() { - //Given - CarBoxedInjectComponent DI = Stone.createComponent(CarBoxedInjectComponent.class); - - //When - CarBoxedInject carInject1 = new CarBoxedInject(); - CarBoxedInject carInject2 = new CarBoxedInject(); - DI.inject(carInject1); - DI.inject(carInject2); - - - // Then - assertEquals(2, Bumper.createCount, "Bumpers created from list. And reused"); - assertEquals(carInject1.bumper.val.uuid, carInject2.bumper.val.uuid, "should cache"); - assertEquals(carInject1.wheel.val.uuid, carInject2.wheel.val.uuid, "should cache "); - assertNotEquals(carInject1.window.val.uuid, carInject2.window.val.uuid, "provide via Provider. No caching"); - } - - - @Test - void carInjectListTest() { - //Given - CarBoxedInjectComponent DI = Stone.createComponent(CarBoxedInjectComponent.class); - - //When - CarBoxedInjectLists carInject = new CarBoxedInjectLists(); - DI.inject(carInject); - - // Then - assertEquals(2, Bumper.createCount); - assertEquals(5, Wheel.createCount); - assertEquals(8, Window.createCount, "Window created for fields and method"); - assertEquals(2, carInject.bumpers.size()); - assertEquals(5, carInject.wheels.size()); - assertEquals(4, carInject.windows.size()); - for (CarBox b : carInject.bumpers) assertNotNull(b.val.uuid); - Set bumperUids = new HashSet<>(ListUtils.format(carInject.bumpers, it -> it.val.uuid)); - assertEquals(2, bumperUids.size()); - for (CarBox w : carInject.wheels) assertNotNull(w.val.uuid); - Set wheelsUid = new HashSet<>(ListUtils.format(carInject.wheels, it -> it.val.uuid)); - assertEquals(5, wheelsUid.size()); - for (CarBox w : carInject.windows) assertNotNull(w.val.uuid); - Set windowUids = new HashSet<>(ListUtils.format(carInject.windows, it -> it.val.uuid)); - assertEquals(4, windowUids.size()); - } - - @Test - void carInjectListReusableTest() { - //Given - CarBoxedInjectComponent DI = Stone.createComponent(CarBoxedInjectComponent.class); - - //When - CarBoxedInjectLists carInject1 = new CarBoxedInjectLists(); - CarBoxedInjectLists carInject2 = new CarBoxedInjectLists(); - DI.inject(carInject1); - DI.inject(carInject2); - - // Then - assertEquals(2, carInject1.bumpers.size()); - assertEquals(5, carInject1.wheels.size()); - assertEquals(4, carInject1.windows.size()); - for (int i = 0; i < 2; i++) - assertEquals(carInject1.bumpers.get(i).val.uuid, carInject2.bumpers.get(i).val.uuid); - for (int i = 0; i < 2; i++) assertEquals(carInject1.wheels.get(i).val.uuid, carInject2.wheels.get(i).val.uuid); - Set windowUids = new HashSet<>(); - for (int i = 0; i < 4; i++) windowUids.add(carInject1.windows.get(i).val.uuid); - for (int i = 0; i < 4; i++) windowUids.add(carInject2.windows.get(i).val.uuid); - assertEquals(8, windowUids.size()); - } - - - @Test - void carInjectProviderTest() { - //Given - CarBoxedInjectComponent DI = Stone.createComponent(CarBoxedInjectComponent.class); - - //When - CarBoxedInjectProvider carInject = new CarBoxedInjectProvider(); - DI.inject(carInject); - - // Then - assertEquals(0, Bumper.createCount, "Provide non used"); - assertNotNull(carInject.bumper.get().val.uuid); - assertNotNull(carInject.wheel.get().val.uuid); - assertNotNull(carInject.window.get().getValue().val.uuid); - assertEquals(2, Bumper.createCount, "Bumpers created from list"); - } - - - @Test - void carInjectProvideReusableTest() { - //Given - CarBoxedInjectComponent DI = Stone.createComponent(CarBoxedInjectComponent.class); - - //When - CarBoxedInjectProvider carInject1 = new CarBoxedInjectProvider(); - CarBoxedInjectProvider carInject2 = new CarBoxedInjectProvider(); - DI.inject(carInject1); - DI.inject(carInject2); - - - // Then - assertEquals(0, Bumper.createCount, "Provider non used"); - assertEquals(carInject1.bumper.get().val.uuid, carInject2.bumper.get().val.uuid, "should cache"); - assertEquals(carInject1.wheel.get().val.uuid, carInject2.wheel.get().val.uuid, "should cache "); - assertNotEquals(carInject1.window.get().getValue().val.uuid, carInject2.window.get().getValue().val.uuid, "provide via Provider. No caching"); - assertEquals(2, Bumper.createCount, "Bumpers created from list. And reused"); - } - -} diff --git a/tests_wraps/src/test/java/com/github/klee0kai/stone/test/boxed/inject/CarBoxedProtectInjectedTests.java b/tests_wraps/src/test/java/com/github/klee0kai/stone/test/boxed/inject/CarBoxedProtectInjectedTests.java deleted file mode 100644 index 8bb7a181..00000000 --- a/tests_wraps/src/test/java/com/github/klee0kai/stone/test/boxed/inject/CarBoxedProtectInjectedTests.java +++ /dev/null @@ -1,91 +0,0 @@ -package com.github.klee0kai.stone.test.boxed.inject; - -import com.github.klee0kai.stone.Stone; -import com.github.klee0kai.stone._hidden_.types.ListUtils; -import com.github.klee0kai.test.boxed.di.inject.CarBoxedInjectComponent; -import com.github.klee0kai.test.boxed.model.CarBoxedInject; -import com.github.klee0kai.test.boxed.model.CarBoxedInjectLists; -import com.github.klee0kai.test.boxed.model.CarBoxedInjectProvider; -import org.junit.jupiter.api.Test; - -import java.util.List; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotEquals; - -public class CarBoxedProtectInjectedTests { - - @Test - void carProtectInjectedTest() { - //Given - CarBoxedInjectComponent DI = Stone.createComponent(CarBoxedInjectComponent.class); - - //When - CarBoxedInject carInject = new CarBoxedInject(); - DI.inject(carInject); - String bumperUid = carInject.bumper.val.uuid; - String wheelUid = carInject.wheel.val.uuid; - String windowUid = carInject.window.val.uuid; - DI.protect(carInject); - carInject = null; - System.gc(); - carInject = new CarBoxedInject(); - DI.inject(carInject); - - - // Then - assertEquals(bumperUid, carInject.bumper.val.uuid, "Providing with caching"); - assertEquals(wheelUid, carInject.wheel.val.uuid, "Providing with caching"); - assertNotEquals(windowUid, carInject.window.val.uuid, "Providing without caching"); - } - - - @Test - void carProtectListInjectedTest() { - CarBoxedInjectComponent DI = Stone.createComponent(CarBoxedInjectComponent.class); - - //When - CarBoxedInjectLists carInject = new CarBoxedInjectLists(); - DI.inject(carInject); - List bumperUids = ListUtils.format(carInject.bumpers, it -> it.val.uuid); - List wheelUids = ListUtils.format(carInject.wheels, it -> it.val.uuid); - List windowUids = ListUtils.format(carInject.windows, it -> it.val.uuid); - DI.protect(carInject); - carInject = null; - System.gc(); - carInject = new CarBoxedInjectLists(); - DI.inject(carInject); - - - // Then - assertEquals(bumperUids, ListUtils.format(carInject.bumpers, it -> it.val.uuid), "Providing with caching"); - assertEquals(wheelUids, ListUtils.format(carInject.wheels, it -> it.val.uuid), "Providing with caching"); - assertNotEquals(windowUids, ListUtils.format(carInject.windows, it -> it.val.uuid), "Providing without caching"); - } - - @Test - void carProtectProviderTest() { - //Given - CarBoxedInjectComponent DI = Stone.createComponent(CarBoxedInjectComponent.class); - - //When - CarBoxedInjectProvider carInject = new CarBoxedInjectProvider(); - DI.inject(carInject); - String bumperUid = carInject.bumper.get().val.uuid; - String wheelUid = carInject.wheel.get().val.uuid; - String windowUid = carInject.window.get().getValue().val.uuid; - DI.protect(carInject); - carInject = null; - System.gc(); - carInject = new CarBoxedInjectProvider(); - DI.inject(carInject); - - - // Then - assertEquals(bumperUid, carInject.bumper.get().val.uuid, "Lazy Provider caching and can be protected"); - assertNotEquals(wheelUid, carInject.wheel.get().val.uuid, "Ref is non caching and non should protect"); - assertNotEquals(windowUid, carInject.window.get().getValue().val.uuid, "LazyProvide non support caching. Non should protect"); - } - - -} diff --git a/tests_wraps/src/test/java/com/github/klee0kai/stone/test/car/bindinstance/simple/BindBumperTests.java b/tests_wraps/src/test/java/com/github/klee0kai/stone/test/car/bindinstance/simple/BindBumperTests.java deleted file mode 100644 index 5a8e8c1e..00000000 --- a/tests_wraps/src/test/java/com/github/klee0kai/stone/test/car/bindinstance/simple/BindBumperTests.java +++ /dev/null @@ -1,72 +0,0 @@ -package com.github.klee0kai.stone.test.car.bindinstance.simple; - -import com.github.klee0kai.stone.Stone; -import com.github.klee0kai.test.car.di.bindinstance.simple.CarBindComponent; -import com.github.klee0kai.test.car.model.Bumper; -import org.junit.jupiter.api.Test; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNull; - -public class BindBumperTests { - - @Test - void noBindTest() { - //Given - CarBindComponent DI = Stone.createComponent(CarBindComponent.class); - - //Then - assertNull(DI.module().bumper()); - assertNull(DI.provideBumper().get()); - assertEquals(0, DI.provideBumpers().size()); - } - - - @Test - void nullBindTest() { - //Given - CarBindComponent DI = Stone.createComponent(CarBindComponent.class); - - //When - DI.bindBumper(null); - - //Then - assertNull(DI.module().bumper()); - assertNull(DI.provideBumper().get()); - assertEquals(0, DI.provideBumpers().size()); - } - - @Test - void bindWheelSimpleTest() { - //Given - CarBindComponent DI = Stone.createComponent(CarBindComponent.class); - - //When - Bumper bumper = new Bumper(); - DI.bindBumper(() -> bumper); - - //Then - assertEquals(bumper.uuid, DI.module().bumper().get().uuid); - assertEquals(bumper.uuid, DI.provideBumper().get().uuid); - assertEquals(1, DI.provideBumpers().size()); - assertEquals(bumper.uuid, DI.provideBumpers().get(0).uuid); - } - - @Test - void rebindWheelSimpleTest() { - //Given - CarBindComponent DI = Stone.createComponent(CarBindComponent.class); - DI.bindBumper(() -> new Bumper()); - - //When - Bumper bumper = new Bumper(); - DI.bindBumper(() -> bumper); - - //Then - assertEquals(bumper.uuid, DI.module().bumper().get().uuid); - assertEquals(bumper.uuid, DI.provideBumper().get().uuid); - assertEquals(1, DI.provideBumpers().size()); - assertEquals(bumper.uuid, DI.provideBumpers().get(0).uuid); - } - -} diff --git a/tests_wraps/src/test/java/com/github/klee0kai/stone/test/car/bindinstance/simple/BindWheelRefTests.java b/tests_wraps/src/test/java/com/github/klee0kai/stone/test/car/bindinstance/simple/BindWheelRefTests.java deleted file mode 100644 index f2e65a0d..00000000 --- a/tests_wraps/src/test/java/com/github/klee0kai/stone/test/car/bindinstance/simple/BindWheelRefTests.java +++ /dev/null @@ -1,93 +0,0 @@ -package com.github.klee0kai.stone.test.car.bindinstance.simple; - -import com.github.klee0kai.stone.Stone; -import com.github.klee0kai.test.car.di.bindinstance.simple.CarBindComponent; -import com.github.klee0kai.test.car.model.Wheel; -import org.junit.jupiter.api.Test; - -import java.lang.ref.WeakReference; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNull; - -public class BindWheelRefTests { - - @Test - void noBindTest() { - //Given - CarBindComponent DI = Stone.createComponent(CarBindComponent.class); - - //Then - assertNull(DI.module().wheel()); - assertNull(DI.provideWheel()); - assertNull(DI.provideWheelRef()); - assertEquals(0, DI.provideWheels().size()); - } - - - @Test - void nullBindTest() { - //Given - CarBindComponent DI = Stone.createComponent(CarBindComponent.class); - - //When - DI.bindWheelRef(null); - - //Then - assertNull(DI.module().wheel()); - assertNull(DI.provideWheel()); - assertNull(DI.provideWheelRef()); - assertEquals(0, DI.provideWheels().size()); - } - - @Test - void nullRefBindTest() { - //Given - CarBindComponent DI = Stone.createComponent(CarBindComponent.class); - - //When - DI.bindWheelRef(new WeakReference<>(null)); - - //Then - assertNull(DI.module().wheel()); - assertNull(DI.provideWheel()); - assertNull(DI.provideWheelRef()); - assertEquals(0, DI.provideWheels().size()); - } - - @Test - void bindWheelSimpleTest() { - //Given - CarBindComponent DI = Stone.createComponent(CarBindComponent.class); - - //When - Wheel wheel = new Wheel(); - DI.bindWheelRef(new WeakReference<>(wheel)); - - //Then - assertEquals(wheel.uuid, DI.module().wheel().uuid); - assertEquals(wheel.uuid, DI.provideWheel().uuid); - assertEquals(wheel.uuid, DI.provideWheelRef().get().uuid); - assertEquals(1, DI.provideWheels().size()); - assertEquals(wheel.uuid, DI.provideWheels().get(0).get().uuid); - } - - @Test - void rebindWheelSimpleTest() { - //Given - CarBindComponent DI = Stone.createComponent(CarBindComponent.class); - DI.bindWheel(new Wheel()); - - //When - Wheel wheel = new Wheel(); - DI.bindWheelRef(new WeakReference<>(wheel)); - - //Then - assertEquals(wheel.uuid, DI.module().wheel().uuid); - assertEquals(wheel.uuid, DI.provideWheel().uuid); - assertEquals(wheel.uuid, DI.provideWheelRef().get().uuid); - assertEquals(1, DI.provideWheels().size()); - assertEquals(wheel.uuid, DI.provideWheels().get(0).get().uuid); - } - -} diff --git a/tests_wraps/src/test/java/com/github/klee0kai/stone/test/car/bindinstance/simple/BindWheelTests.java b/tests_wraps/src/test/java/com/github/klee0kai/stone/test/car/bindinstance/simple/BindWheelTests.java deleted file mode 100644 index ffef51be..00000000 --- a/tests_wraps/src/test/java/com/github/klee0kai/stone/test/car/bindinstance/simple/BindWheelTests.java +++ /dev/null @@ -1,76 +0,0 @@ -package com.github.klee0kai.stone.test.car.bindinstance.simple; - -import com.github.klee0kai.stone.Stone; -import com.github.klee0kai.test.car.di.bindinstance.simple.CarBindComponent; -import com.github.klee0kai.test.car.model.Wheel; -import org.junit.jupiter.api.Test; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNull; - -public class BindWheelTests { - - @Test - void noBindTest() { - //Given - CarBindComponent DI = Stone.createComponent(CarBindComponent.class); - - //Then - assertNull(DI.module().wheel()); - assertNull(DI.provideWheel()); - assertNull(DI.provideWheelRef()); - assertEquals(0, DI.provideWheels().size()); - } - - - @Test - void nullBindTest() { - //Given - CarBindComponent DI = Stone.createComponent(CarBindComponent.class); - - //When - DI.bindWheel(null); - - //Then - assertNull(DI.module().wheel()); - assertNull(DI.provideWheel()); - assertNull(DI.provideWheelRef()); - assertEquals(0, DI.provideWheels().size()); - } - - @Test - void bindWheelSimpleTest() { - //Given - CarBindComponent DI = Stone.createComponent(CarBindComponent.class); - - //When - Wheel wheel = new Wheel(); - DI.bindWheel(wheel); - - //Then - assertEquals(wheel.uuid, DI.module().wheel().uuid); - assertEquals(wheel.uuid, DI.provideWheel().uuid); - assertEquals(wheel.uuid, DI.provideWheelRef().get().uuid); - assertEquals(1, DI.provideWheels().size()); - assertEquals(wheel.uuid, DI.provideWheels().get(0).get().uuid); - } - - @Test - void rebindWheelSimpleTest() { - //Given - CarBindComponent DI = Stone.createComponent(CarBindComponent.class); - DI.bindWheel(new Wheel()); - - //When - Wheel wheel = new Wheel(); - DI.bindWheel(wheel); - - //Then - assertEquals(wheel.uuid, DI.module().wheel().uuid); - assertEquals(wheel.uuid, DI.provideWheel().uuid); - assertEquals(wheel.uuid, DI.provideWheelRef().get().uuid); - assertEquals(1, DI.provideWheels().size()); - assertEquals(wheel.uuid, DI.provideWheels().get(0).get().uuid); - } - -} diff --git a/tests_wraps/src/test/java/com/github/klee0kai/stone/test/car/bindinstance/simple/BindWindowCollectionRefTests.java b/tests_wraps/src/test/java/com/github/klee0kai/stone/test/car/bindinstance/simple/BindWindowCollectionRefTests.java deleted file mode 100644 index 53135180..00000000 --- a/tests_wraps/src/test/java/com/github/klee0kai/stone/test/car/bindinstance/simple/BindWindowCollectionRefTests.java +++ /dev/null @@ -1,137 +0,0 @@ -package com.github.klee0kai.stone.test.car.bindinstance.simple; - -import com.github.klee0kai.stone.Stone; -import com.github.klee0kai.test.car.di.bindinstance.simple.CarBindComponent; -import com.github.klee0kai.test.car.model.Window; -import org.junit.jupiter.api.Test; - -import java.lang.ref.WeakReference; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNull; - -public class BindWindowCollectionRefTests { - @Test - void bindWindowSimpleTest() { - //Given - CarBindComponent DI = Stone.createComponent(CarBindComponent.class); - - //When - Window window = new Window(); - DI.bindWindowRefs(Collections.singletonList(new WeakReference<>(window))); - - //Then - assertEquals(window.uuid, DI.module().windows().get().get(0).uuid); - assertEquals(window.uuid, DI.provideWindow().uuid); - assertEquals(1, DI.provideWindows().size()); - assertEquals(window.uuid, new ArrayList<>(DI.provideWindows()).get(0).uuid); - } - - - @Test - void bindWindowListTest() { - //Given - CarBindComponent DI = Stone.createComponent(CarBindComponent.class); - - //When - Window window1 = new Window(); - Window window2 = new Window(); - DI.bindWindowRefs(Arrays.asList(new WeakReference<>(window1), new WeakReference(window2))); - - //Then - assertEquals(window1.uuid, DI.module().windows().get().get(0).uuid); - assertEquals(window2.uuid, DI.module().windows().get().get(1).uuid); - assertEquals(window1.uuid, DI.provideWindow().uuid); - assertEquals(2, DI.provideWindows().size()); - assertEquals(window1.uuid, new ArrayList<>(DI.provideWindows()).get(0).uuid); - assertEquals(window2.uuid, new ArrayList<>(DI.provideWindows()).get(1).uuid); - } - - @Test - void rebindWindowSimpleTest() { - //Given - CarBindComponent DI = Stone.createComponent(CarBindComponent.class); - DI.bindWindow(new Window()); - - //When - Window window = new Window(); - DI.bindWindowRefs(Collections.singletonList(new WeakReference<>(window))); - - //Then - assertEquals(window.uuid, DI.module().windows().get().get(0).uuid); - assertEquals(window.uuid, DI.provideWindow().uuid); - assertEquals(1, DI.provideWindows().size()); - assertEquals(window.uuid, new ArrayList<>(DI.provideWindows()).get(0).uuid); - } - - @Test - void rebindWindowListTest() { - //Given - CarBindComponent DI = Stone.createComponent(CarBindComponent.class); - DI.bindWindow(new Window()); - - //When - Window window1 = new Window(); - Window window2 = new Window(); - DI.bindWindowRefs(Arrays.asList(new WeakReference<>(window1), new WeakReference<>(window2))); - - //Then - assertEquals(window1.uuid, DI.module().windows().get().get(0).uuid); - assertEquals(window2.uuid, DI.module().windows().get().get(1).uuid); - assertEquals(window1.uuid, DI.provideWindow().uuid); - assertEquals(2, DI.provideWindows().size()); - assertEquals(window1.uuid, new ArrayList<>(DI.provideWindows()).get(0).uuid); - assertEquals(window2.uuid, new ArrayList<>(DI.provideWindows()).get(1).uuid); - } - - @Test - void rebindWindowSimple2Test() { - //Given - CarBindComponent DI = Stone.createComponent(CarBindComponent.class); - DI.bindWindowRefs(Collections.singletonList(new WeakReference<>(new Window()))); - - //When - Window window = new Window(); - DI.bindWindowRefs(Collections.singletonList(new WeakReference<>(window))); - - //Then - assertEquals(window.uuid, DI.module().windows().get().get(0).uuid); - assertEquals(window.uuid, DI.provideWindow().uuid); - assertEquals(1, DI.provideWindows().size()); - assertEquals(window.uuid, new ArrayList<>(DI.provideWindows()).get(0).uuid); - } - - @Test - void unbindWindowEmptyListTest() { - //Given - CarBindComponent DI = Stone.createComponent(CarBindComponent.class); - DI.bindWindowRefs(Arrays.asList(new WeakReference<>(new Window()), new WeakReference<>(new Window()))); - - //When - DI.bindWindowRefs(Collections.emptyList()); - - //Then - assertEquals(0, DI.module().windows().get().size()); - assertNull(DI.provideWindow()); - assertEquals(0, DI.provideWindows().size()); - } - - @Test - void unbindWindowListRefTest() { - //Given - CarBindComponent DI = Stone.createComponent(CarBindComponent.class); - DI.bindWindowRefs(Arrays.asList(new WeakReference<>(new Window()), new WeakReference<>(new Window()))); - - //When - DI.bindWindowRefs(Collections.singletonList(new WeakReference<>(null))); - - //Then - assertNull(DI.provideWindow()); - assertEquals(0, DI.provideWindows().size()); - } - - -} diff --git a/tests_wraps/src/test/java/com/github/klee0kai/stone/test/car/bindinstance/simple/BindWindowCollectionTests.java b/tests_wraps/src/test/java/com/github/klee0kai/stone/test/car/bindinstance/simple/BindWindowCollectionTests.java deleted file mode 100644 index f9ad998a..00000000 --- a/tests_wraps/src/test/java/com/github/klee0kai/stone/test/car/bindinstance/simple/BindWindowCollectionTests.java +++ /dev/null @@ -1,105 +0,0 @@ -package com.github.klee0kai.stone.test.car.bindinstance.simple; - -import com.github.klee0kai.stone.Stone; -import com.github.klee0kai.test.car.di.bindinstance.simple.CarBindComponent; -import com.github.klee0kai.test.car.model.Window; -import org.junit.jupiter.api.Test; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; - -import static org.junit.jupiter.api.Assertions.assertEquals; - -public class BindWindowCollectionTests { - @Test - void bindWindowSimpleTest() { - //Given - CarBindComponent DI = Stone.createComponent(CarBindComponent.class); - - //When - Window window = new Window(); - DI.bindWindows(Collections.singletonList(window)); - - //Then - assertEquals(window.uuid, DI.module().windows().get().get(0).uuid); - assertEquals(window.uuid, DI.provideWindow().uuid); - assertEquals(1, DI.provideWindows().size()); - assertEquals(window.uuid, new ArrayList<>(DI.provideWindows()).get(0).uuid); - } - - - @Test - void bindWindowListTest() { - //Given - CarBindComponent DI = Stone.createComponent(CarBindComponent.class); - - //When - Window window1 = new Window(); - Window window2 = new Window(); - DI.bindWindows(Arrays.asList(window1, window2)); - - //Then - assertEquals(window1.uuid, DI.module().windows().get().get(0).uuid); - assertEquals(window2.uuid, DI.module().windows().get().get(1).uuid); - assertEquals(window1.uuid, DI.provideWindow().uuid); - assertEquals(2, DI.provideWindows().size()); - assertEquals(window1.uuid, new ArrayList<>(DI.provideWindows()).get(0).uuid); - assertEquals(window2.uuid, new ArrayList<>(DI.provideWindows()).get(1).uuid); - } - - @Test - void rebindWindowSimpleTest() { - //Given - CarBindComponent DI = Stone.createComponent(CarBindComponent.class); - DI.bindWindow(new Window()); - - //When - Window window = new Window(); - DI.bindWindows(Collections.singletonList(window)); - - //Then - assertEquals(window.uuid, DI.module().windows().get().get(0).uuid); - assertEquals(window.uuid, DI.provideWindow().uuid); - assertEquals(1, DI.provideWindows().size()); - assertEquals(window.uuid, new ArrayList<>(DI.provideWindows()).get(0).uuid); - } - - @Test - void rebindWindowListTest() { - //Given - CarBindComponent DI = Stone.createComponent(CarBindComponent.class); - DI.bindWindow(new Window()); - - //When - Window window1 = new Window(); - Window window2 = new Window(); - DI.bindWindows(Arrays.asList(window1, window2)); - - //Then - assertEquals(window1.uuid, DI.module().windows().get().get(0).uuid); - assertEquals(window2.uuid, DI.module().windows().get().get(1).uuid); - assertEquals(window1.uuid, DI.provideWindow().uuid); - assertEquals(2, DI.provideWindows().size()); - assertEquals(window1.uuid, new ArrayList<>(DI.provideWindows()).get(0).uuid); - assertEquals(window2.uuid, new ArrayList<>(DI.provideWindows()).get(1).uuid); - } - - @Test - void rebindWindowSimple2Test() { - //Given - CarBindComponent DI = Stone.createComponent(CarBindComponent.class); - DI.bindWindows(Collections.singletonList(new Window())); - - //When - Window window = new Window(); - DI.bindWindows(Collections.singletonList(window)); - - //Then - assertEquals(window.uuid, DI.module().windows().get().get(0).uuid); - assertEquals(window.uuid, DI.provideWindow().uuid); - assertEquals(1, DI.provideWindows().size()); - assertEquals(window.uuid, new ArrayList<>(DI.provideWindows()).get(0).uuid); - } - -} diff --git a/tests_wraps/src/test/java/com/github/klee0kai/stone/test/car/bindinstance/simple/BindWindowTests.java b/tests_wraps/src/test/java/com/github/klee0kai/stone/test/car/bindinstance/simple/BindWindowTests.java deleted file mode 100644 index c87a4d81..00000000 --- a/tests_wraps/src/test/java/com/github/klee0kai/stone/test/car/bindinstance/simple/BindWindowTests.java +++ /dev/null @@ -1,75 +0,0 @@ -package com.github.klee0kai.stone.test.car.bindinstance.simple; - -import com.github.klee0kai.stone.Stone; -import com.github.klee0kai.test.car.di.bindinstance.simple.CarBindComponent; -import com.github.klee0kai.test.car.model.Window; -import org.junit.jupiter.api.Test; - -import java.util.ArrayList; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNull; - -public class BindWindowTests { - - @Test - void noBindTest() { - //Given - CarBindComponent DI = Stone.createComponent(CarBindComponent.class); - - //Then - assertNull(DI.module().windows()); - assertNull(DI.provideWindow()); - assertEquals(0, DI.provideWindows().size()); - } - - - @Test - void nullBindTest() { - //Given - CarBindComponent DI = Stone.createComponent(CarBindComponent.class); - - //When - DI.bindWindow(null); - - //Then - assertNull(DI.module().windows()); - assertNull(DI.provideWindow()); - assertEquals(0, DI.provideWindows().size()); - } - - @Test - void bindWindowSimpleTest() { - //Given - CarBindComponent DI = Stone.createComponent(CarBindComponent.class); - - //When - Window window = new Window(); - DI.bindWindow(window); - - //Then - assertEquals(window.uuid, DI.module().windows().get().get(0).uuid); - assertEquals(window.uuid, DI.provideWindow().uuid); - assertEquals(1, DI.provideWindows().size()); - assertEquals(window.uuid, new ArrayList<>(DI.provideWindows()).get(0).uuid); - } - - @Test - void rebindWindowSimpleTest() { - //Given - CarBindComponent DI = Stone.createComponent(CarBindComponent.class); - DI.bindWindow(new Window()); - - //When - Window window = new Window(); - DI.bindWindow(window); - - //Then - assertEquals(window.uuid, DI.module().windows().get().get(0).uuid); - assertEquals(window.uuid, DI.provideWindow().uuid); - assertEquals(1, DI.provideWindows().size()); - assertEquals(window.uuid, new ArrayList<>(DI.provideWindows()).get(0).uuid); - } - - -} diff --git a/tests_wraps/src/test/java/com/github/klee0kai/stone/test/car/bluecar/BlueCarTest.java b/tests_wraps/src/test/java/com/github/klee0kai/stone/test/car/bluecar/BlueCarTest.java deleted file mode 100644 index f0f42f03..00000000 --- a/tests_wraps/src/test/java/com/github/klee0kai/stone/test/car/bluecar/BlueCarTest.java +++ /dev/null @@ -1,98 +0,0 @@ -package com.github.klee0kai.stone.test.car.bluecar; - -import com.github.klee0kai.stone.Stone; -import com.github.klee0kai.test.car.di.bestOf.blue.BlueCarComponent; -import com.github.klee0kai.test.car.di.bestOf.both.BothCarComponent; -import com.github.klee0kai.test.car.di.bestOf.red.RedCarComponent; -import com.github.klee0kai.test.car.model.Bumper; -import com.github.klee0kai.test.car.model.Car; -import com.github.klee0kai.test.car.model.Wheel; -import com.github.klee0kai.test.car.model.Window; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotNull; - -public class BlueCarTest { - - @BeforeEach - public void init() { - Bumper.createCount = 0; - Window.createCount = 0; - Wheel.createCount = 0; - Car.createCount = 0; - } - - @Test - public void blueCarComponent() { - //Given - BlueCarComponent DI = Stone.createComponent(BlueCarComponent.class); - - //When - assertEquals(0, Car.createCount); - Car blueCar = DI.blueCar().get(); - - //Then - assertEquals(1, Car.createCount); - assertNotNull(blueCar.uuid); - assertEquals(2, blueCar.bumpers.size(), "Blue Car use list bumper"); - assertEquals(5, blueCar.wheels.size(), "Blue Car use list wheel"); - assertEquals(4, blueCar.windows.size(), "Blue Car use list wheel"); - } - - - @Test - public void createBlueCar() { - //Given - BothCarComponent DI = Stone.createComponent(BothCarComponent.class); - - //When - assertEquals(0, Car.createCount); - Car blueCar = DI.blueCar().get(); - - //Then - assertEquals(1, Car.createCount); - assertNotNull(blueCar.uuid); - assertEquals(2, blueCar.bumpers.size(), "Blue Car use list bumper"); - assertEquals(5, blueCar.wheels.size(), "Blue Car use list wheel"); - assertEquals(4, blueCar.windows.size(), "Blue Car use list wheel"); - } - - @Test - public void redCarComponent() { - //Given - RedCarComponent DI = Stone.createComponent(RedCarComponent.class); - - //When - assertEquals(0, Car.createCount); - Car redCar = DI.redCar().get(); - - //Then - assertEquals(1, Car.createCount); - assertNotNull(redCar.uuid); - assertEquals(1, redCar.bumpers.size(), "Red Car use single bumper"); - assertEquals(1, redCar.wheels.size(), "Red Car use single wheel"); - assertEquals(1, redCar.windows.size(), "Red Car use single wheel"); - } - - @Test - public void createRedCar() { - //Given - BothCarComponent DI = Stone.createComponent(BothCarComponent.class); - - //When - assertEquals(0, Car.createCount); - Car redCar = DI.redCar().get(); - - //Then - assertEquals(1, Car.createCount); - assertNotNull(redCar.uuid); - assertEquals(1, redCar.bumpers.size(), "Red Car use single bumper"); - assertEquals(1, redCar.wheels.size(), "Red Car use single wheel"); - assertEquals(1, redCar.windows.size(), "Red Car use single wheel"); - } - - - -} diff --git a/tests_wraps/src/test/java/com/github/klee0kai/stone/test/car/cachecontrol/gc/BumperGcResusableTests.java b/tests_wraps/src/test/java/com/github/klee0kai/stone/test/car/cachecontrol/gc/BumperGcResusableTests.java deleted file mode 100644 index 77c19617..00000000 --- a/tests_wraps/src/test/java/com/github/klee0kai/stone/test/car/cachecontrol/gc/BumperGcResusableTests.java +++ /dev/null @@ -1,222 +0,0 @@ -package com.github.klee0kai.stone.test.car.cachecontrol.gc; - -import com.github.klee0kai.stone.Stone; -import com.github.klee0kai.stone._hidden_.types.ListUtils; -import com.github.klee0kai.test.car.di.cachecontrol.gc.CarGcComponent; -import org.junit.jupiter.api.Test; - -import java.util.List; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotEquals; - -public class BumperGcResusableTests { - - @Test - public void gcAllTest() { - // Given - CarGcComponent DI = Stone.createComponent(CarGcComponent.class); - List bumperFactoryUids1 = ListUtils.format(DI.bumpersModule().bumperFactory(), it -> it.uuid); - List bumperWeakUids1 = ListUtils.format(DI.bumpersModule().bumperWeak(), it -> it.uuid); - List bumperSoftUids1 = ListUtils.format(DI.bumpersModule().bumperSoft(), it -> it.uuid); - List bumperStrongUids1 = ListUtils.format(DI.bumpersModule().bumperStrong(), it -> it.uuid); - - //When - DI.gcAll(); - List bumperFactoryUids2 = ListUtils.format(DI.bumpersModule().bumperFactory(), it -> it.uuid); - List bumperWeakUids2 = ListUtils.format(DI.bumpersModule().bumperWeak(), it -> it.uuid); - List bumperSoftUids2 = ListUtils.format(DI.bumpersModule().bumperSoft(), it -> it.uuid); - List bumperStrongUids2 = ListUtils.format(DI.bumpersModule().bumperStrong(), it -> it.uuid); - - // Then - assertNotEquals(bumperFactoryUids1, bumperFactoryUids2); - assertNotEquals(bumperWeakUids1, bumperWeakUids2); - assertNotEquals(bumperSoftUids1, bumperSoftUids2); - assertNotEquals(bumperStrongUids1, bumperStrongUids2); - } - - @Test - public void gcWeakTest() { - // Given - CarGcComponent DI = Stone.createComponent(CarGcComponent.class); - List bumperFactoryUids1 = ListUtils.format(DI.bumpersModule().bumperFactory(), it -> it.uuid); - List bumperWeakUids1 = ListUtils.format(DI.bumpersModule().bumperWeak(), it -> it.uuid); - List bumperSoftUids1 = ListUtils.format(DI.bumpersModule().bumperSoft(), it -> it.uuid); - List bumperStrongUids1 = ListUtils.format(DI.bumpersModule().bumperStrong(), it -> it.uuid); - - //When - DI.gcWeak(); - List bumperFactoryUids2 = ListUtils.format(DI.bumpersModule().bumperFactory(), it -> it.uuid); - List bumperWeakUids2 = ListUtils.format(DI.bumpersModule().bumperWeak(), it -> it.uuid); - List bumperSoftUids2 = ListUtils.format(DI.bumpersModule().bumperSoft(), it -> it.uuid); - List bumperStrongUids2 = ListUtils.format(DI.bumpersModule().bumperStrong(), it -> it.uuid); - - // Then - assertNotEquals(bumperFactoryUids1, bumperFactoryUids2); - assertNotEquals(bumperWeakUids1, bumperWeakUids2); - assertEquals(bumperSoftUids1, bumperSoftUids2); - assertEquals(bumperStrongUids1, bumperStrongUids2); - } - - @Test - public void gcSoftTest() { - // Given - CarGcComponent DI = Stone.createComponent(CarGcComponent.class); - List bumperFactoryUids1 = ListUtils.format(DI.bumpersModule().bumperFactory(), it -> it.uuid); - List bumperWeakUids1 = ListUtils.format(DI.bumpersModule().bumperWeak(), it -> it.uuid); - List bumperSoftUids1 = ListUtils.format(DI.bumpersModule().bumperSoft(), it -> it.uuid); - List bumperStrongUids1 = ListUtils.format(DI.bumpersModule().bumperStrong(), it -> it.uuid); - - //When - DI.gcSoft(); - List bumperFactoryUids2 = ListUtils.format(DI.bumpersModule().bumperFactory(), it -> it.uuid); - List bumperWeakUids2 = ListUtils.format(DI.bumpersModule().bumperWeak(), it -> it.uuid); - List bumperSoftUids2 = ListUtils.format(DI.bumpersModule().bumperSoft(), it -> it.uuid); - List bumperStrongUids2 = ListUtils.format(DI.bumpersModule().bumperStrong(), it -> it.uuid); - - // Then - assertNotEquals(bumperFactoryUids1, bumperFactoryUids2); - assertNotEquals(bumperWeakUids1, bumperWeakUids2); - assertNotEquals(bumperSoftUids1, bumperSoftUids2); - assertEquals(bumperStrongUids1, bumperStrongUids2); - } - - @Test - public void gcStrongTest() { - // Given - CarGcComponent DI = Stone.createComponent(CarGcComponent.class); - List bumperFactoryUids1 = ListUtils.format(DI.bumpersModule().bumperFactory(), it -> it.uuid); - List bumperWeakUids1 = ListUtils.format(DI.bumpersModule().bumperWeak(), it -> it.uuid); - List bumperSoftUids1 = ListUtils.format(DI.bumpersModule().bumperSoft(), it -> it.uuid); - List bumperStrongUids1 = ListUtils.format(DI.bumpersModule().bumperStrong(), it -> it.uuid); - - //When - DI.gcStrong(); - List bumperFactoryUids2 = ListUtils.format(DI.bumpersModule().bumperFactory(), it -> it.uuid); - List bumperWeakUids2 = ListUtils.format(DI.bumpersModule().bumperWeak(), it -> it.uuid); - List bumperSoftUids2 = ListUtils.format(DI.bumpersModule().bumperSoft(), it -> it.uuid); - List bumperStrongUids2 = ListUtils.format(DI.bumpersModule().bumperStrong(), it -> it.uuid); - - // Then - assertNotEquals(bumperFactoryUids1, bumperFactoryUids2); - assertNotEquals(bumperWeakUids1, bumperWeakUids2); - assertEquals(bumperSoftUids1, bumperSoftUids2); - assertNotEquals(bumperStrongUids1, bumperStrongUids2); - } - - @Test - public void gcBumpers() { - // Given - CarGcComponent DI = Stone.createComponent(CarGcComponent.class); - List bumperFactoryUids1 = ListUtils.format(DI.bumpersModule().bumperFactory(), it -> it.uuid); - List bumperWeakUids1 = ListUtils.format(DI.bumpersModule().bumperWeak(), it -> it.uuid); - List bumperSoftUids1 = ListUtils.format(DI.bumpersModule().bumperSoft(), it -> it.uuid); - List bumperStrongUids1 = ListUtils.format(DI.bumpersModule().bumperStrong(), it -> it.uuid); - - //When - DI.gcBumpers(); - List bumperFactoryUids2 = ListUtils.format(DI.bumpersModule().bumperFactory(), it -> it.uuid); - List bumperWeakUids2 = ListUtils.format(DI.bumpersModule().bumperWeak(), it -> it.uuid); - List bumperSoftUids2 = ListUtils.format(DI.bumpersModule().bumperSoft(), it -> it.uuid); - List bumperStrongUids2 = ListUtils.format(DI.bumpersModule().bumperStrong(), it -> it.uuid); - - // Then - assertNotEquals(bumperFactoryUids1, bumperFactoryUids2); - assertNotEquals(bumperWeakUids1, bumperWeakUids2); - assertNotEquals(bumperSoftUids1, bumperSoftUids2); - assertNotEquals(bumperStrongUids1, bumperStrongUids2); - } - - @Test - public void gcRedBumpers() { - // Given - CarGcComponent DI = Stone.createComponent(CarGcComponent.class); - List bumperFactoryUids1 = ListUtils.format(DI.bumpersModule().bumperFactory(), it -> it.uuid); - List bumperWeakUids1 = ListUtils.format(DI.bumpersModule().bumperWeak(), it -> it.uuid); - List bumperSoftUids1 = ListUtils.format(DI.bumpersModule().bumperSoft(), it -> it.uuid); - List bumperStrongUids1 = ListUtils.format(DI.bumpersModule().bumperStrong(), it -> it.uuid); - - //When - DI.gcRedBumpers(); - List bumperFactoryUids2 = ListUtils.format(DI.bumpersModule().bumperFactory(), it -> it.uuid); - List bumperWeakUids2 = ListUtils.format(DI.bumpersModule().bumperWeak(), it -> it.uuid); - List bumperSoftUids2 = ListUtils.format(DI.bumpersModule().bumperSoft(), it -> it.uuid); - List bumperStrongUids2 = ListUtils.format(DI.bumpersModule().bumperStrong(), it -> it.uuid); - - // Then - assertNotEquals(bumperFactoryUids1, bumperFactoryUids2); - assertNotEquals(bumperWeakUids1, bumperWeakUids2); - assertEquals(bumperSoftUids1, bumperSoftUids2); - assertNotEquals(bumperStrongUids1, bumperStrongUids2); - } - - @Test - public void gcRedBumpers2() { - // Given - CarGcComponent DI = Stone.createComponent(CarGcComponent.class); - List bumperFactoryUids1 = ListUtils.format(DI.bumpersModule().bumperFactory(), it -> it.uuid); - List bumperWeakUids1 = ListUtils.format(DI.bumpersModule().bumperWeak(), it -> it.uuid); - List bumperSoftUids1 = ListUtils.format(DI.bumpersModule().bumperSoft(), it -> it.uuid); - List bumperStrongUids1 = ListUtils.format(DI.bumpersModule().bumperStrong(), it -> it.uuid); - - //When - DI.gcRedBumpers2(); - List bumperFactoryUids2 = ListUtils.format(DI.bumpersModule().bumperFactory(), it -> it.uuid); - List bumperWeakUids2 = ListUtils.format(DI.bumpersModule().bumperWeak(), it -> it.uuid); - List bumperSoftUids2 = ListUtils.format(DI.bumpersModule().bumperSoft(), it -> it.uuid); - List bumperStrongUids2 = ListUtils.format(DI.bumpersModule().bumperStrong(), it -> it.uuid); - - // Then - assertNotEquals(bumperFactoryUids1, bumperFactoryUids2); - assertNotEquals(bumperWeakUids1, bumperWeakUids2); - assertEquals(bumperSoftUids1, bumperSoftUids2); - assertNotEquals(bumperStrongUids1, bumperStrongUids2); - } - - @Test - public void gcWheelsTest() { - // Given - CarGcComponent DI = Stone.createComponent(CarGcComponent.class); - List bumperFactoryUids1 = ListUtils.format(DI.bumpersModule().bumperFactory(), it -> it.uuid); - List bumperWeakUids1 = ListUtils.format(DI.bumpersModule().bumperWeak(), it -> it.uuid); - List bumperSoftUids1 = ListUtils.format(DI.bumpersModule().bumperSoft(), it -> it.uuid); - List bumperStrongUids1 = ListUtils.format(DI.bumpersModule().bumperStrong(), it -> it.uuid); - - //When - DI.gcWheels(); - List bumperFactoryUids2 = ListUtils.format(DI.bumpersModule().bumperFactory(), it -> it.uuid); - List bumperWeakUids2 = ListUtils.format(DI.bumpersModule().bumperWeak(), it -> it.uuid); - List bumperSoftUids2 = ListUtils.format(DI.bumpersModule().bumperSoft(), it -> it.uuid); - List bumperStrongUids2 = ListUtils.format(DI.bumpersModule().bumperStrong(), it -> it.uuid); - - // Then - assertNotEquals(bumperFactoryUids1, bumperFactoryUids2); - assertNotEquals(bumperWeakUids1, bumperWeakUids2); - assertEquals(bumperSoftUids1, bumperSoftUids2); - assertEquals(bumperStrongUids1, bumperStrongUids2); - } - - @Test - public void gcNothing() { - // Given - CarGcComponent DI = Stone.createComponent(CarGcComponent.class); - List bumperFactoryUids1 = ListUtils.format(DI.bumpersModule().bumperFactory(), it -> it.uuid); - List bumperWeakUids1 = ListUtils.format(DI.bumpersModule().bumperWeak(), it -> it.uuid); - List bumperSoftUids1 = ListUtils.format(DI.bumpersModule().bumperSoft(), it -> it.uuid); - List bumperStrongUids1 = ListUtils.format(DI.bumpersModule().bumperStrong(), it -> it.uuid); - - //When - DI.gcNothing(); - List bumperFactoryUids2 = ListUtils.format(DI.bumpersModule().bumperFactory(), it -> it.uuid); - List bumperWeakUids2 = ListUtils.format(DI.bumpersModule().bumperWeak(), it -> it.uuid); - List bumperSoftUids2 = ListUtils.format(DI.bumpersModule().bumperSoft(), it -> it.uuid); - List bumperStrongUids2 = ListUtils.format(DI.bumpersModule().bumperStrong(), it -> it.uuid); - - // Then - assertNotEquals(bumperFactoryUids1, bumperFactoryUids2); - assertNotEquals(bumperWeakUids1, bumperWeakUids2); - assertEquals(bumperSoftUids1, bumperSoftUids2); - assertEquals(bumperStrongUids1, bumperStrongUids2); - } - -} diff --git a/tests_wraps/src/test/java/com/github/klee0kai/stone/test/car/cachecontrol/gc/BumperGcTests.java b/tests_wraps/src/test/java/com/github/klee0kai/stone/test/car/cachecontrol/gc/BumperGcTests.java deleted file mode 100644 index 4c145733..00000000 --- a/tests_wraps/src/test/java/com/github/klee0kai/stone/test/car/cachecontrol/gc/BumperGcTests.java +++ /dev/null @@ -1,216 +0,0 @@ -package com.github.klee0kai.stone.test.car.cachecontrol.gc; - -import com.github.klee0kai.stone.Stone; -import com.github.klee0kai.stone._hidden_.types.ListUtils; -import com.github.klee0kai.test.car.di.cachecontrol.gc.CarGcComponent; -import com.github.klee0kai.test.car.model.Bumper; -import org.junit.jupiter.api.Test; - -import java.lang.ref.WeakReference; -import java.util.List; - -import static org.junit.jupiter.api.Assertions.assertEquals; - -public class BumperGcTests { - - @Test - public void createWorkCorrect() { - // Given - CarGcComponent DI = Stone.createComponent(CarGcComponent.class); - - //When - List> bumperFactory = ListUtils.format(DI.bumpersModule().bumperFactory(), WeakReference::new); - List> bumperWeak = ListUtils.format(DI.bumpersModule().bumperWeak(), WeakReference::new); - List> bumperSoft = ListUtils.format(DI.bumpersModule().bumperSoft(), WeakReference::new); - List> bumperStrong = ListUtils.format(DI.bumpersModule().bumperStrong(), WeakReference::new); - - //Then - assertEquals(3, nonNullCount(bumperFactory)); - assertEquals(3, nonNullCount(bumperWeak)); - assertEquals(3, nonNullCount(bumperSoft)); - assertEquals(3, nonNullCount(bumperStrong)); - } - - @Test - public void gcAllTest() { - // Given - CarGcComponent DI = Stone.createComponent(CarGcComponent.class); - List> bumperFactory = ListUtils.format(DI.bumpersModule().bumperFactory(), WeakReference::new); - List> bumperWeak = ListUtils.format(DI.bumpersModule().bumperWeak(), WeakReference::new); - List> bumperSoft = ListUtils.format(DI.bumpersModule().bumperSoft(), WeakReference::new); - List> bumperStrong = ListUtils.format(DI.bumpersModule().bumperStrong(), WeakReference::new); - - //When - DI.gcAll(); - - // Then - assertEquals(0, nonNullCount(bumperFactory)); - assertEquals(0, nonNullCount(bumperWeak)); - assertEquals(0, nonNullCount(bumperSoft)); - assertEquals(0, nonNullCount(bumperStrong)); - } - - @Test - public void gcWeakTest() { - // Given - CarGcComponent DI = Stone.createComponent(CarGcComponent.class); - List> bumperFactory = ListUtils.format(DI.bumpersModule().bumperFactory(), WeakReference::new); - List> bumperWeak = ListUtils.format(DI.bumpersModule().bumperWeak(), WeakReference::new); - List> bumperSoft = ListUtils.format(DI.bumpersModule().bumperSoft(), WeakReference::new); - List> bumperStrong = ListUtils.format(DI.bumpersModule().bumperStrong(), WeakReference::new); - - //When - DI.gcWeak(); - - // Then - assertEquals(0, nonNullCount(bumperFactory)); - assertEquals(0, nonNullCount(bumperWeak)); - assertEquals(3, nonNullCount(bumperSoft)); - assertEquals(3, nonNullCount(bumperStrong)); - } - - @Test - public void gcSoftTest() { - // Given - CarGcComponent DI = Stone.createComponent(CarGcComponent.class); - List> bumperFactory = ListUtils.format(DI.bumpersModule().bumperFactory(), WeakReference::new); - List> bumperWeak = ListUtils.format(DI.bumpersModule().bumperWeak(), WeakReference::new); - List> bumperSoft = ListUtils.format(DI.bumpersModule().bumperSoft(), WeakReference::new); - List> bumperStrong = ListUtils.format(DI.bumpersModule().bumperStrong(), WeakReference::new); - - //When - DI.gcSoft(); - - // Then - assertEquals(0, nonNullCount(bumperFactory)); - assertEquals(0, nonNullCount(bumperWeak)); - assertEquals(0, nonNullCount(bumperSoft)); - assertEquals(3, nonNullCount(bumperStrong)); - } - - @Test - public void gcStrongTest() { - // Given - CarGcComponent DI = Stone.createComponent(CarGcComponent.class); - List> bumperFactory = ListUtils.format(DI.bumpersModule().bumperFactory(), WeakReference::new); - List> bumperWeak = ListUtils.format(DI.bumpersModule().bumperWeak(), WeakReference::new); - List> bumperSoft = ListUtils.format(DI.bumpersModule().bumperSoft(), WeakReference::new); - List> bumperStrong = ListUtils.format(DI.bumpersModule().bumperStrong(), WeakReference::new); - - //When - DI.gcStrong(); - - // Then - assertEquals(0, nonNullCount(bumperFactory)); - assertEquals(0, nonNullCount(bumperWeak)); - assertEquals(3, nonNullCount(bumperSoft)); - assertEquals(0, nonNullCount(bumperStrong)); - } - - @Test - public void gcBumpers() { - // Given - CarGcComponent DI = Stone.createComponent(CarGcComponent.class); - List> bumperFactory = ListUtils.format(DI.bumpersModule().bumperFactory(), WeakReference::new); - List> bumperWeak = ListUtils.format(DI.bumpersModule().bumperWeak(), WeakReference::new); - List> bumperSoft = ListUtils.format(DI.bumpersModule().bumperSoft(), WeakReference::new); - List> bumperStrong = ListUtils.format(DI.bumpersModule().bumperStrong(), WeakReference::new); - - //When - DI.gcBumpers(); - - // Then - assertEquals(0, nonNullCount(bumperFactory)); - assertEquals(0, nonNullCount(bumperWeak)); - assertEquals(0, nonNullCount(bumperSoft)); - assertEquals(0, nonNullCount(bumperStrong)); - } - - @Test - public void gcRedBumpers() { - // Given - CarGcComponent DI = Stone.createComponent(CarGcComponent.class); - List> bumperFactory = ListUtils.format(DI.bumpersModule().bumperFactory(), WeakReference::new); - List> bumperWeak = ListUtils.format(DI.bumpersModule().bumperWeak(), WeakReference::new); - List> bumperSoft = ListUtils.format(DI.bumpersModule().bumperSoft(), WeakReference::new); - List> bumperStrong = ListUtils.format(DI.bumpersModule().bumperStrong(), WeakReference::new); - - //When - DI.gcRedBumpers(); - - // Then - assertEquals(0, nonNullCount(bumperFactory)); - assertEquals(0, nonNullCount(bumperWeak)); - assertEquals(3, nonNullCount(bumperSoft)); - assertEquals(0, nonNullCount(bumperStrong)); - } - - @Test - public void gcRedBumpers2() { - // Given - CarGcComponent DI = Stone.createComponent(CarGcComponent.class); - List> bumperFactory = ListUtils.format(DI.bumpersModule().bumperFactory(), WeakReference::new); - List> bumperWeak = ListUtils.format(DI.bumpersModule().bumperWeak(), WeakReference::new); - List> bumperSoft = ListUtils.format(DI.bumpersModule().bumperSoft(), WeakReference::new); - List> bumperStrong = ListUtils.format(DI.bumpersModule().bumperStrong(), WeakReference::new); - - //When - DI.gcRedBumpers2(); - - // Then - assertEquals(0, nonNullCount(bumperFactory)); - assertEquals(0, nonNullCount(bumperWeak)); - assertEquals(3, nonNullCount(bumperSoft)); - assertEquals(0, nonNullCount(bumperStrong)); - } - - @Test - public void gcWheelsTest() { - // Given - CarGcComponent DI = Stone.createComponent(CarGcComponent.class); - List> bumperFactory = ListUtils.format(DI.bumpersModule().bumperFactory(), WeakReference::new); - List> bumperWeak = ListUtils.format(DI.bumpersModule().bumperWeak(), WeakReference::new); - List> bumperSoft = ListUtils.format(DI.bumpersModule().bumperSoft(), WeakReference::new); - List> bumperStrong = ListUtils.format(DI.bumpersModule().bumperStrong(), WeakReference::new); - - - //When - DI.gcWheels(); - - // Then - assertEquals(0, nonNullCount(bumperFactory)); - assertEquals(0, nonNullCount(bumperWeak)); - assertEquals(3, nonNullCount(bumperSoft)); - assertEquals(3, nonNullCount(bumperStrong)); - } - - @Test - public void gcNothing() { - // Given - CarGcComponent DI = Stone.createComponent(CarGcComponent.class); - List> bumperFactory = ListUtils.format(DI.bumpersModule().bumperFactory(), WeakReference::new); - List> bumperWeak = ListUtils.format(DI.bumpersModule().bumperWeak(), WeakReference::new); - List> bumperSoft = ListUtils.format(DI.bumpersModule().bumperSoft(), WeakReference::new); - List> bumperStrong = ListUtils.format(DI.bumpersModule().bumperStrong(), WeakReference::new); - - //When - DI.gcNothing(); - - // Then - assertEquals(0, nonNullCount(bumperFactory)); - assertEquals(0, nonNullCount(bumperWeak)); - assertEquals(3, nonNullCount(bumperSoft)); - assertEquals(3, nonNullCount(bumperStrong)); - } - - - private int nonNullCount(List> list) { - int count = 0; - for (int i = 0; i < list.size(); i++) { - if (list.get(i) != null && list.get(i).get() != null) count++; - } - return count; - } - - -} diff --git a/tests_wraps/src/test/java/com/github/klee0kai/stone/test/car/cachecontrol/gc/WheelGcTests.java b/tests_wraps/src/test/java/com/github/klee0kai/stone/test/car/cachecontrol/gc/WheelGcTests.java deleted file mode 100644 index 3d1c64b0..00000000 --- a/tests_wraps/src/test/java/com/github/klee0kai/stone/test/car/cachecontrol/gc/WheelGcTests.java +++ /dev/null @@ -1,203 +0,0 @@ -package com.github.klee0kai.stone.test.car.cachecontrol.gc; - -import com.github.klee0kai.stone.Stone; -import com.github.klee0kai.test.car.di.cachecontrol.gc.CarGcComponent; -import com.github.klee0kai.test.car.model.Wheel; -import org.junit.jupiter.api.Test; - -import java.lang.ref.WeakReference; - -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertNull; - -public class WheelGcTests { - - @Test - public void createWorkCorrect() { - // Given - CarGcComponent DI = Stone.createComponent(CarGcComponent.class); - - //When - WeakReference wheelFactory = DI.wheelsModule().wheelFactory(); - WeakReference wheelWeak = DI.wheelsModule().wheelWeak(); - WeakReference wheelSoft = DI.wheelsModule().wheelSoft(); - WeakReference wheelStrong = DI.wheelsModule().wheelStrong(); - - //Then - assertNotNull(wheelFactory.get()); - assertNotNull(wheelWeak.get()); - assertNotNull(wheelSoft.get()); - assertNotNull(wheelStrong.get()); - } - - @Test - public void createAfterGcWorkCorrect() { - // Given - CarGcComponent DI = Stone.createComponent(CarGcComponent.class); - DI.gcAll(); - - //When - WeakReference wheelFactory = DI.wheelsModule().wheelFactory(); - WeakReference wheelWeak = DI.wheelsModule().wheelWeak(); - WeakReference wheelSoft = DI.wheelsModule().wheelSoft(); - WeakReference wheelStrong = DI.wheelsModule().wheelStrong(); - - //Then - assertNotNull(wheelFactory.get()); - assertNotNull(wheelWeak.get()); - assertNotNull(wheelSoft.get()); - assertNotNull(wheelStrong.get()); - } - - @Test - public void gcAllTest() { - // Given - CarGcComponent DI = Stone.createComponent(CarGcComponent.class); - WeakReference wheelFactory = DI.wheelsModule().wheelFactory(); - WeakReference wheelWeak = DI.wheelsModule().wheelWeak(); - WeakReference wheelSoft = DI.wheelsModule().wheelSoft(); - WeakReference wheelStrong = DI.wheelsModule().wheelStrong(); - - //When - DI.gcAll(); - - // Then - assertNull(wheelFactory.get()); - assertNull(wheelWeak.get()); - assertNull(wheelSoft.get()); - assertNull(wheelStrong.get()); - } - - @Test - public void gcWeakTest() { - // Given - CarGcComponent DI = Stone.createComponent(CarGcComponent.class); - WeakReference wheelFactory = DI.wheelsModule().wheelFactory(); - WeakReference wheelWeak = DI.wheelsModule().wheelWeak(); - WeakReference wheelSoft = DI.wheelsModule().wheelSoft(); - WeakReference wheelStrong = DI.wheelsModule().wheelStrong(); - - //When - DI.gcWeak(); - - // Then - assertNull(wheelFactory.get()); - assertNull(wheelWeak.get()); - assertNotNull(wheelSoft.get()); - assertNotNull(wheelStrong.get()); - } - - @Test - public void gcSoftTest() { - // Given - CarGcComponent DI = Stone.createComponent(CarGcComponent.class); - WeakReference wheelFactory = DI.wheelsModule().wheelFactory(); - WeakReference wheelWeak = DI.wheelsModule().wheelWeak(); - WeakReference wheelSoft = DI.wheelsModule().wheelSoft(); - WeakReference wheelStrong = DI.wheelsModule().wheelStrong(); - - //When - DI.gcSoft(); - - // Then - assertNull(wheelFactory.get()); - assertNull(wheelWeak.get()); - assertNull(wheelSoft.get()); - assertNotNull(wheelStrong.get()); - } - - @Test - public void gcStrongTest() { - // Given - CarGcComponent DI = Stone.createComponent(CarGcComponent.class); - WeakReference wheelFactory = DI.wheelsModule().wheelFactory(); - WeakReference wheelWeak = DI.wheelsModule().wheelWeak(); - WeakReference wheelSoft = DI.wheelsModule().wheelSoft(); - WeakReference wheelStrong = DI.wheelsModule().wheelStrong(); - - //When - DI.gcStrong(); - - // Then - assertNull(wheelFactory.get()); - assertNull(wheelWeak.get()); - assertNotNull(wheelSoft.get()); - assertNull(wheelStrong.get()); - } - - @Test - public void gcWheelsTest() { - // Given - CarGcComponent DI = Stone.createComponent(CarGcComponent.class); - WeakReference wheelFactory = DI.wheelsModule().wheelFactory(); - WeakReference wheelWeak = DI.wheelsModule().wheelWeak(); - WeakReference wheelSoft = DI.wheelsModule().wheelSoft(); - WeakReference wheelStrong = DI.wheelsModule().wheelStrong(); - - //When - DI.gcWheels(); - - // Then - assertNull(wheelFactory.get()); - assertNull(wheelWeak.get()); - assertNull(wheelSoft.get()); - assertNull(wheelStrong.get()); - } - - @Test - public void gcNothing() { - // Given - CarGcComponent DI = Stone.createComponent(CarGcComponent.class); - WeakReference wheelFactory = DI.wheelsModule().wheelFactory(); - WeakReference wheelWeak = DI.wheelsModule().wheelWeak(); - WeakReference wheelSoft = DI.wheelsModule().wheelSoft(); - WeakReference wheelStrong = DI.wheelsModule().wheelStrong(); - - //When - DI.gcNothing(); - - // Then - assertNull(wheelFactory.get()); - assertNull(wheelWeak.get()); - assertNotNull(wheelSoft.get()); - assertNotNull(wheelStrong.get()); - } - - @Test - public void gcWindows() { - // Given - CarGcComponent DI = Stone.createComponent(CarGcComponent.class); - WeakReference wheelFactory = DI.wheelsModule().wheelFactory(); - WeakReference wheelWeak = DI.wheelsModule().wheelWeak(); - WeakReference wheelSoft = DI.wheelsModule().wheelSoft(); - WeakReference wheelStrong = DI.wheelsModule().wheelStrong(); - - //When - DI.gcWindows(); - - // Then - assertNull(wheelFactory.get()); - assertNull(wheelWeak.get()); - assertNotNull(wheelSoft.get()); - assertNotNull(wheelStrong.get()); - } - - @Test - public void gcWindowsAndWheels() { - // Given - CarGcComponent DI = Stone.createComponent(CarGcComponent.class); - WeakReference wheelFactory = DI.wheelsModule().wheelFactory(); - WeakReference wheelWeak = DI.wheelsModule().wheelWeak(); - WeakReference wheelSoft = DI.wheelsModule().wheelSoft(); - WeakReference wheelStrong = DI.wheelsModule().wheelStrong(); - - //When - DI.gcWindowsAndWheels(); - - // Then - assertNull(wheelFactory.get()); - assertNull(wheelWeak.get()); - assertNull(wheelSoft.get()); - assertNull(wheelStrong.get()); - } -} diff --git a/tests_wraps/src/test/java/com/github/klee0kai/stone/test/car/cachecontrol/gc/WheelMappedGcTests.java b/tests_wraps/src/test/java/com/github/klee0kai/stone/test/car/cachecontrol/gc/WheelMappedGcTests.java deleted file mode 100644 index 4517eb6a..00000000 --- a/tests_wraps/src/test/java/com/github/klee0kai/stone/test/car/cachecontrol/gc/WheelMappedGcTests.java +++ /dev/null @@ -1,203 +0,0 @@ -package com.github.klee0kai.stone.test.car.cachecontrol.gc; - -import com.github.klee0kai.stone.Stone; -import com.github.klee0kai.test.car.di.cachecontrol.gc.CarGcComponent; -import com.github.klee0kai.test.car.model.Wheel; -import org.junit.jupiter.api.Test; - -import java.lang.ref.WeakReference; - -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertNull; - -public class WheelMappedGcTests { - - @Test - public void createWorkCorrect() { - // Given - CarGcComponent DI = Stone.createComponent(CarGcComponent.class); - - //When - WeakReference wheelFactory = DI.wheelMappedModule().wheelFactory("1"); - WeakReference wheelWeak = DI.wheelMappedModule().wheelWeak("1"); - WeakReference wheelSoft = DI.wheelMappedModule().wheelSoft("1"); - WeakReference wheelStrong = DI.wheelMappedModule().wheelStrong("1"); - - //Then - assertNotNull(wheelFactory.get()); - assertNotNull(wheelWeak.get()); - assertNotNull(wheelSoft.get()); - assertNotNull(wheelStrong.get()); - } - - @Test - public void createAfterGcWorkCorrect() { - // Given - CarGcComponent DI = Stone.createComponent(CarGcComponent.class); - DI.gcAll(); - - //When - WeakReference wheelFactory = DI.wheelMappedModule().wheelFactory("1"); - WeakReference wheelWeak = DI.wheelMappedModule().wheelWeak("1"); - WeakReference wheelSoft = DI.wheelMappedModule().wheelSoft("1"); - WeakReference wheelStrong = DI.wheelMappedModule().wheelStrong("1"); - - //Then - assertNotNull(wheelFactory.get()); - assertNotNull(wheelWeak.get()); - assertNotNull(wheelSoft.get()); - assertNotNull(wheelStrong.get()); - } - - @Test - public void gcAllTest() { - // Given - CarGcComponent DI = Stone.createComponent(CarGcComponent.class); - WeakReference wheelFactory = DI.wheelMappedModule().wheelFactory("1"); - WeakReference wheelWeak = DI.wheelMappedModule().wheelWeak("1"); - WeakReference wheelSoft = DI.wheelMappedModule().wheelSoft("1"); - WeakReference wheelStrong = DI.wheelMappedModule().wheelStrong("1"); - - //When - DI.gcAll(); - - // Then - assertNull(wheelFactory.get()); - assertNull(wheelWeak.get()); - assertNull(wheelSoft.get()); - assertNull(wheelStrong.get()); - } - - @Test - public void gcWeakTest() { - // Given - CarGcComponent DI = Stone.createComponent(CarGcComponent.class); - WeakReference wheelFactory = DI.wheelMappedModule().wheelFactory("1"); - WeakReference wheelWeak = DI.wheelMappedModule().wheelWeak("1"); - WeakReference wheelSoft = DI.wheelMappedModule().wheelSoft("1"); - WeakReference wheelStrong = DI.wheelMappedModule().wheelStrong("1"); - - //When - DI.gcWeak(); - - // Then - assertNull(wheelFactory.get()); - assertNull(wheelWeak.get()); - assertNotNull(wheelSoft.get()); - assertNotNull(wheelStrong.get()); - } - - @Test - public void gcSoftTest() { - // Given - CarGcComponent DI = Stone.createComponent(CarGcComponent.class); - WeakReference wheelFactory = DI.wheelMappedModule().wheelFactory("1"); - WeakReference wheelWeak = DI.wheelMappedModule().wheelWeak("1"); - WeakReference wheelSoft = DI.wheelMappedModule().wheelSoft("1"); - WeakReference wheelStrong = DI.wheelMappedModule().wheelStrong("1"); - - //When - DI.gcSoft(); - - // Then - assertNull(wheelFactory.get()); - assertNull(wheelWeak.get()); - assertNull(wheelSoft.get()); - assertNotNull(wheelStrong.get()); - } - - @Test - public void gcStrongTest() { - // Given - CarGcComponent DI = Stone.createComponent(CarGcComponent.class); - WeakReference wheelFactory = DI.wheelMappedModule().wheelFactory("1"); - WeakReference wheelWeak = DI.wheelMappedModule().wheelWeak("1"); - WeakReference wheelSoft = DI.wheelMappedModule().wheelSoft("1"); - WeakReference wheelStrong = DI.wheelMappedModule().wheelStrong("1"); - - //When - DI.gcStrong(); - - // Then - assertNull(wheelFactory.get()); - assertNull(wheelWeak.get()); - assertNotNull(wheelSoft.get()); - assertNull(wheelStrong.get()); - } - - @Test - public void gcWheelsTest() { - // Given - CarGcComponent DI = Stone.createComponent(CarGcComponent.class); - WeakReference wheelFactory = DI.wheelMappedModule().wheelFactory("1"); - WeakReference wheelWeak = DI.wheelMappedModule().wheelWeak("1"); - WeakReference wheelSoft = DI.wheelMappedModule().wheelSoft("1"); - WeakReference wheelStrong = DI.wheelMappedModule().wheelStrong("1"); - - //When - DI.gcWheels(); - - // Then - assertNull(wheelFactory.get()); - assertNull(wheelWeak.get()); - assertNull(wheelSoft.get()); - assertNull(wheelStrong.get()); - } - - @Test - public void gcNothing() { - // Given - CarGcComponent DI = Stone.createComponent(CarGcComponent.class); - WeakReference wheelFactory = DI.wheelMappedModule().wheelFactory("1"); - WeakReference wheelWeak = DI.wheelMappedModule().wheelWeak("1"); - WeakReference wheelSoft = DI.wheelMappedModule().wheelSoft("1"); - WeakReference wheelStrong = DI.wheelMappedModule().wheelStrong("1"); - - //When - DI.gcNothing(); - - // Then - assertNull(wheelFactory.get()); - assertNull(wheelWeak.get()); - assertNotNull(wheelSoft.get()); - assertNotNull(wheelStrong.get()); - } - - @Test - public void gcWindows() { - // Given - CarGcComponent DI = Stone.createComponent(CarGcComponent.class); - WeakReference wheelFactory = DI.wheelMappedModule().wheelFactory("1"); - WeakReference wheelWeak = DI.wheelMappedModule().wheelWeak("1"); - WeakReference wheelSoft = DI.wheelMappedModule().wheelSoft("1"); - WeakReference wheelStrong = DI.wheelMappedModule().wheelStrong("1"); - - //When - DI.gcWindows(); - - // Then - assertNull(wheelFactory.get()); - assertNull(wheelWeak.get()); - assertNotNull(wheelSoft.get()); - assertNotNull(wheelStrong.get()); - } - - @Test - public void gcWindowsAndWheels() { - // Given - CarGcComponent DI = Stone.createComponent(CarGcComponent.class); - WeakReference wheelFactory = DI.wheelMappedModule().wheelFactory("1"); - WeakReference wheelWeak = DI.wheelMappedModule().wheelWeak("1"); - WeakReference wheelSoft = DI.wheelMappedModule().wheelSoft("1"); - WeakReference wheelStrong = DI.wheelMappedModule().wheelStrong("1"); - - //When - DI.gcWindowsAndWheels(); - - // Then - assertNull(wheelFactory.get()); - assertNull(wheelWeak.get()); - assertNull(wheelSoft.get()); - assertNull(wheelStrong.get()); - } -} diff --git a/tests_wraps/src/test/java/com/github/klee0kai/stone/test/car/cachecontrol/gc/WheelMultiMappedGcTests.java b/tests_wraps/src/test/java/com/github/klee0kai/stone/test/car/cachecontrol/gc/WheelMultiMappedGcTests.java deleted file mode 100644 index 457dae0e..00000000 --- a/tests_wraps/src/test/java/com/github/klee0kai/stone/test/car/cachecontrol/gc/WheelMultiMappedGcTests.java +++ /dev/null @@ -1,203 +0,0 @@ -package com.github.klee0kai.stone.test.car.cachecontrol.gc; - -import com.github.klee0kai.stone.Stone; -import com.github.klee0kai.test.car.di.cachecontrol.gc.CarGcComponent; -import com.github.klee0kai.test.car.model.Wheel; -import org.junit.jupiter.api.Test; - -import java.lang.ref.WeakReference; - -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertNull; - -public class WheelMultiMappedGcTests { - - @Test - public void createWorkCorrect() { - // Given - CarGcComponent DI = Stone.createComponent(CarGcComponent.class); - - //When - WeakReference wheelFactory = DI.wheelMultiMappedModule().wheelFactory("1", 1); - WeakReference wheelWeak = DI.wheelMultiMappedModule().wheelWeak("1", 1); - WeakReference wheelSoft = DI.wheelMultiMappedModule().wheelSoft("1", 1); - WeakReference wheelStrong = DI.wheelMultiMappedModule().wheelStrong("1", 1); - - //Then - assertNotNull(wheelFactory.get()); - assertNotNull(wheelWeak.get()); - assertNotNull(wheelSoft.get()); - assertNotNull(wheelStrong.get()); - } - - @Test - public void createAfterGcWorkCorrect() { - // Given - CarGcComponent DI = Stone.createComponent(CarGcComponent.class); - DI.gcAll(); - - //When - WeakReference wheelFactory = DI.wheelMultiMappedModule().wheelFactory("1", 1); - WeakReference wheelWeak = DI.wheelMultiMappedModule().wheelWeak("1", 1); - WeakReference wheelSoft = DI.wheelMultiMappedModule().wheelSoft("1", 1); - WeakReference wheelStrong = DI.wheelMultiMappedModule().wheelStrong("1", 1); - - //Then - assertNotNull(wheelFactory.get()); - assertNotNull(wheelWeak.get()); - assertNotNull(wheelSoft.get()); - assertNotNull(wheelStrong.get()); - } - - @Test - public void gcAllTest() { - // Given - CarGcComponent DI = Stone.createComponent(CarGcComponent.class); - WeakReference wheelFactory = DI.wheelMultiMappedModule().wheelFactory("1", 1); - WeakReference wheelWeak = DI.wheelMultiMappedModule().wheelWeak("1", 1); - WeakReference wheelSoft = DI.wheelMultiMappedModule().wheelSoft("1", 1); - WeakReference wheelStrong = DI.wheelMultiMappedModule().wheelStrong("1", 1); - - //When - DI.gcAll(); - - // Then - assertNull(wheelFactory.get()); - assertNull(wheelWeak.get()); - assertNull(wheelSoft.get()); - assertNull(wheelStrong.get()); - } - - @Test - public void gcWeakTest() { - // Given - CarGcComponent DI = Stone.createComponent(CarGcComponent.class); - WeakReference wheelFactory = DI.wheelMultiMappedModule().wheelFactory("1", 1); - WeakReference wheelWeak = DI.wheelMultiMappedModule().wheelWeak("1", 1); - WeakReference wheelSoft = DI.wheelMultiMappedModule().wheelSoft("1", 1); - WeakReference wheelStrong = DI.wheelMultiMappedModule().wheelStrong("1", 1); - - //When - DI.gcWeak(); - - // Then - assertNull(wheelFactory.get()); - assertNull(wheelWeak.get()); - assertNotNull(wheelSoft.get()); - assertNotNull(wheelStrong.get()); - } - - @Test - public void gcSoftTest() { - // Given - CarGcComponent DI = Stone.createComponent(CarGcComponent.class); - WeakReference wheelFactory = DI.wheelMultiMappedModule().wheelFactory("1", 1); - WeakReference wheelWeak = DI.wheelMultiMappedModule().wheelWeak("1", 1); - WeakReference wheelSoft = DI.wheelMultiMappedModule().wheelSoft("1", 1); - WeakReference wheelStrong = DI.wheelMultiMappedModule().wheelStrong("1", 1); - - //When - DI.gcSoft(); - - // Then - assertNull(wheelFactory.get()); - assertNull(wheelWeak.get()); - assertNull(wheelSoft.get()); - assertNotNull(wheelStrong.get()); - } - - @Test - public void gcStrongTest() { - // Given - CarGcComponent DI = Stone.createComponent(CarGcComponent.class); - WeakReference wheelFactory = DI.wheelMultiMappedModule().wheelFactory("1", 1); - WeakReference wheelWeak = DI.wheelMultiMappedModule().wheelWeak("1", 1); - WeakReference wheelSoft = DI.wheelMultiMappedModule().wheelSoft("1", 1); - WeakReference wheelStrong = DI.wheelMultiMappedModule().wheelStrong("1", 1); - - //When - DI.gcStrong(); - - // Then - assertNull(wheelFactory.get()); - assertNull(wheelWeak.get()); - assertNotNull(wheelSoft.get()); - assertNull(wheelStrong.get()); - } - - @Test - public void gcWheelsTest() { - // Given - CarGcComponent DI = Stone.createComponent(CarGcComponent.class); - WeakReference wheelFactory = DI.wheelMultiMappedModule().wheelFactory("1", 1); - WeakReference wheelWeak = DI.wheelMultiMappedModule().wheelWeak("1", 1); - WeakReference wheelSoft = DI.wheelMultiMappedModule().wheelSoft("1", 1); - WeakReference wheelStrong = DI.wheelMultiMappedModule().wheelStrong("1", 1); - - //When - DI.gcWheels(); - - // Then - assertNull(wheelFactory.get()); - assertNull(wheelWeak.get()); - assertNull(wheelSoft.get()); - assertNull(wheelStrong.get()); - } - - @Test - public void gcNothing() { - // Given - CarGcComponent DI = Stone.createComponent(CarGcComponent.class); - WeakReference wheelFactory = DI.wheelMultiMappedModule().wheelFactory("1", 1); - WeakReference wheelWeak = DI.wheelMultiMappedModule().wheelWeak("1", 1); - WeakReference wheelSoft = DI.wheelMultiMappedModule().wheelSoft("1", 1); - WeakReference wheelStrong = DI.wheelMultiMappedModule().wheelStrong("1", 1); - - //When - DI.gcNothing(); - - // Then - assertNull(wheelFactory.get()); - assertNull(wheelWeak.get()); - assertNotNull(wheelSoft.get()); - assertNotNull(wheelStrong.get()); - } - - @Test - public void gcWindows() { - // Given - CarGcComponent DI = Stone.createComponent(CarGcComponent.class); - WeakReference wheelFactory = DI.wheelMultiMappedModule().wheelFactory("1", 1); - WeakReference wheelWeak = DI.wheelMultiMappedModule().wheelWeak("1", 1); - WeakReference wheelSoft = DI.wheelMultiMappedModule().wheelSoft("1", 1); - WeakReference wheelStrong = DI.wheelMultiMappedModule().wheelStrong("1", 1); - - //When - DI.gcWindows(); - - // Then - assertNull(wheelFactory.get()); - assertNull(wheelWeak.get()); - assertNotNull(wheelSoft.get()); - assertNotNull(wheelStrong.get()); - } - - @Test - public void gcWindowsAndWheels() { - // Given - CarGcComponent DI = Stone.createComponent(CarGcComponent.class); - WeakReference wheelFactory = DI.wheelMultiMappedModule().wheelFactory("1", 1); - WeakReference wheelWeak = DI.wheelMultiMappedModule().wheelWeak("1", 1); - WeakReference wheelSoft = DI.wheelMultiMappedModule().wheelSoft("1", 1); - WeakReference wheelStrong = DI.wheelMultiMappedModule().wheelStrong("1", 1); - - //When - DI.gcWindowsAndWheels(); - - // Then - assertNull(wheelFactory.get()); - assertNull(wheelWeak.get()); - assertNull(wheelSoft.get()); - assertNull(wheelStrong.get()); - } -} diff --git a/tests_wraps/src/test/java/com/github/klee0kai/stone/test/car/cachecontrol/gc/WheelReusableGcTests.java b/tests_wraps/src/test/java/com/github/klee0kai/stone/test/car/cachecontrol/gc/WheelReusableGcTests.java deleted file mode 100644 index beb77d3e..00000000 --- a/tests_wraps/src/test/java/com/github/klee0kai/stone/test/car/cachecontrol/gc/WheelReusableGcTests.java +++ /dev/null @@ -1,195 +0,0 @@ -package com.github.klee0kai.stone.test.car.cachecontrol.gc; - -import com.github.klee0kai.stone.Stone; -import com.github.klee0kai.test.car.di.cachecontrol.gc.CarGcComponent; -import org.junit.jupiter.api.Test; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotEquals; - -public class WheelReusableGcTests { - - @Test - public void gcAllTest() { - // Given - CarGcComponent DI = Stone.createComponent(CarGcComponent.class); - String wheelFactory1 = DI.wheelsModule().wheelFactory().get().uuid; - String wheelWeak1 = DI.wheelsModule().wheelWeak().get().uuid; - String wheelSoft1 = DI.wheelsModule().wheelSoft().get().uuid; - String wheelStrong1 = DI.wheelsModule().wheelStrong().get().uuid; - - //When - DI.gcAll(); - String wheelFactory2 = DI.wheelsModule().wheelFactory().get().uuid; - String wheelWeak2 = DI.wheelsModule().wheelWeak().get().uuid; - String wheelSoft2 = DI.wheelsModule().wheelSoft().get().uuid; - String wheelStrong2 = DI.wheelsModule().wheelStrong().get().uuid; - - // Then - assertNotEquals(wheelFactory1, wheelFactory2); - assertNotEquals(wheelWeak1, wheelWeak2); - assertNotEquals(wheelSoft1, wheelSoft2); - assertNotEquals(wheelStrong1, wheelStrong2); - } - - @Test - public void gcWeakTest() { - // Given - CarGcComponent DI = Stone.createComponent(CarGcComponent.class); - String wheelFactory1 = DI.wheelsModule().wheelFactory().get().uuid; - String wheelWeak1 = DI.wheelsModule().wheelWeak().get().uuid; - String wheelSoft1 = DI.wheelsModule().wheelSoft().get().uuid; - String wheelStrong1 = DI.wheelsModule().wheelStrong().get().uuid; - - //When - DI.gcWeak(); - String wheelFactory2 = DI.wheelsModule().wheelFactory().get().uuid; - String wheelWeak2 = DI.wheelsModule().wheelWeak().get().uuid; - String wheelSoft2 = DI.wheelsModule().wheelSoft().get().uuid; - String wheelStrong2 = DI.wheelsModule().wheelStrong().get().uuid; - - // Then - assertNotEquals(wheelFactory1, wheelFactory2); - assertNotEquals(wheelWeak1, wheelWeak2); - assertEquals(wheelSoft1, wheelSoft2); - assertEquals(wheelStrong1, wheelStrong2); - } - - @Test - public void gcSoftTest() { - // Given - CarGcComponent DI = Stone.createComponent(CarGcComponent.class); - String wheelFactory1 = DI.wheelsModule().wheelFactory().get().uuid; - String wheelWeak1 = DI.wheelsModule().wheelWeak().get().uuid; - String wheelSoft1 = DI.wheelsModule().wheelSoft().get().uuid; - String wheelStrong1 = DI.wheelsModule().wheelStrong().get().uuid; - - //When - DI.gcSoft(); - String wheelFactory2 = DI.wheelsModule().wheelFactory().get().uuid; - String wheelWeak2 = DI.wheelsModule().wheelWeak().get().uuid; - String wheelSoft2 = DI.wheelsModule().wheelSoft().get().uuid; - String wheelStrong2 = DI.wheelsModule().wheelStrong().get().uuid; - - // Then - assertNotEquals(wheelFactory1, wheelFactory2); - assertNotEquals(wheelWeak1, wheelWeak2); - assertNotEquals(wheelSoft1, wheelSoft2); - assertEquals(wheelStrong1, wheelStrong2); - } - - @Test - public void gcStrongTest() { - // Given - CarGcComponent DI = Stone.createComponent(CarGcComponent.class); - String wheelFactory1 = DI.wheelsModule().wheelFactory().get().uuid; - String wheelWeak1 = DI.wheelsModule().wheelWeak().get().uuid; - String wheelSoft1 = DI.wheelsModule().wheelSoft().get().uuid; - String wheelStrong1 = DI.wheelsModule().wheelStrong().get().uuid; - - //When - DI.gcStrong(); - String wheelFactory2 = DI.wheelsModule().wheelFactory().get().uuid; - String wheelWeak2 = DI.wheelsModule().wheelWeak().get().uuid; - String wheelSoft2 = DI.wheelsModule().wheelSoft().get().uuid; - String wheelStrong2 = DI.wheelsModule().wheelStrong().get().uuid; - - // Then - assertNotEquals(wheelFactory1, wheelFactory2); - assertNotEquals(wheelWeak1, wheelWeak2); - assertEquals(wheelSoft1, wheelSoft2); - assertNotEquals(wheelStrong1, wheelStrong2); - } - - @Test - public void gcWheelsTest() { - // Given - CarGcComponent DI = Stone.createComponent(CarGcComponent.class); - String wheelFactory1 = DI.wheelsModule().wheelFactory().get().uuid; - String wheelWeak1 = DI.wheelsModule().wheelWeak().get().uuid; - String wheelSoft1 = DI.wheelsModule().wheelSoft().get().uuid; - String wheelStrong1 = DI.wheelsModule().wheelStrong().get().uuid; - - //When - DI.gcWheels(); - String wheelFactory2 = DI.wheelsModule().wheelFactory().get().uuid; - String wheelWeak2 = DI.wheelsModule().wheelWeak().get().uuid; - String wheelSoft2 = DI.wheelsModule().wheelSoft().get().uuid; - String wheelStrong2 = DI.wheelsModule().wheelStrong().get().uuid; - - // Then - assertNotEquals(wheelFactory1, wheelFactory2); - assertNotEquals(wheelWeak1, wheelWeak2); - assertNotEquals(wheelSoft1, wheelSoft2); - assertNotEquals(wheelStrong1, wheelStrong2); - } - - @Test - public void gcNothing() { - // Given - CarGcComponent DI = Stone.createComponent(CarGcComponent.class); - String wheelFactory1 = DI.wheelsModule().wheelFactory().get().uuid; - String wheelWeak1 = DI.wheelsModule().wheelWeak().get().uuid; - String wheelSoft1 = DI.wheelsModule().wheelSoft().get().uuid; - String wheelStrong1 = DI.wheelsModule().wheelStrong().get().uuid; - - //When - DI.gcNothing(); - String wheelFactory2 = DI.wheelsModule().wheelFactory().get().uuid; - String wheelWeak2 = DI.wheelsModule().wheelWeak().get().uuid; - String wheelSoft2 = DI.wheelsModule().wheelSoft().get().uuid; - String wheelStrong2 = DI.wheelsModule().wheelStrong().get().uuid; - - // Then - assertNotEquals(wheelFactory1, wheelFactory2); - assertNotEquals(wheelWeak1, wheelWeak2); - assertEquals(wheelSoft1, wheelSoft2); - assertEquals(wheelStrong1, wheelStrong2); - } - - @Test - public void gcWindows() { - // Given - CarGcComponent DI = Stone.createComponent(CarGcComponent.class); - String wheelFactory1 = DI.wheelsModule().wheelFactory().get().uuid; - String wheelWeak1 = DI.wheelsModule().wheelWeak().get().uuid; - String wheelSoft1 = DI.wheelsModule().wheelSoft().get().uuid; - String wheelStrong1 = DI.wheelsModule().wheelStrong().get().uuid; - - //When - DI.gcWindows(); - String wheelFactory2 = DI.wheelsModule().wheelFactory().get().uuid; - String wheelWeak2 = DI.wheelsModule().wheelWeak().get().uuid; - String wheelSoft2 = DI.wheelsModule().wheelSoft().get().uuid; - String wheelStrong2 = DI.wheelsModule().wheelStrong().get().uuid; - - // Then - assertNotEquals(wheelFactory1, wheelFactory2); - assertNotEquals(wheelWeak1, wheelWeak2); - assertEquals(wheelSoft1, wheelSoft2); - assertEquals(wheelStrong1, wheelStrong2); - } - - @Test - public void gcWindowsAndWheels() { - // Given - CarGcComponent DI = Stone.createComponent(CarGcComponent.class); - String wheelFactory1 = DI.wheelsModule().wheelFactory().get().uuid; - String wheelWeak1 = DI.wheelsModule().wheelWeak().get().uuid; - String wheelSoft1 = DI.wheelsModule().wheelSoft().get().uuid; - String wheelStrong1 = DI.wheelsModule().wheelStrong().get().uuid; - - //When - DI.gcWindowsAndWheels(); - String wheelFactory2 = DI.wheelsModule().wheelFactory().get().uuid; - String wheelWeak2 = DI.wheelsModule().wheelWeak().get().uuid; - String wheelSoft2 = DI.wheelsModule().wheelSoft().get().uuid; - String wheelStrong2 = DI.wheelsModule().wheelStrong().get().uuid; - - // Then - assertNotEquals(wheelFactory1, wheelFactory2); - assertNotEquals(wheelWeak1, wheelWeak2); - assertNotEquals(wheelSoft1, wheelSoft2); - assertNotEquals(wheelStrong1, wheelStrong2); - } -} diff --git a/tests_wraps/src/test/java/com/github/klee0kai/stone/test/car/cachecontrol/gc/WindowGcTests.java b/tests_wraps/src/test/java/com/github/klee0kai/stone/test/car/cachecontrol/gc/WindowGcTests.java deleted file mode 100644 index e2fb3966..00000000 --- a/tests_wraps/src/test/java/com/github/klee0kai/stone/test/car/cachecontrol/gc/WindowGcTests.java +++ /dev/null @@ -1,217 +0,0 @@ -package com.github.klee0kai.stone.test.car.cachecontrol.gc; - -import com.github.klee0kai.stone.Stone; -import com.github.klee0kai.stone._hidden_.types.ListUtils; -import com.github.klee0kai.test.car.di.cachecontrol.gc.CarGcComponent; -import com.github.klee0kai.test.car.model.Window; -import org.junit.jupiter.api.Test; - -import java.lang.ref.WeakReference; -import java.util.List; - -import static org.junit.jupiter.api.Assertions.assertEquals; - -public class WindowGcTests { - - @Test - public void createWorkCorrect() { - // Given - CarGcComponent DI = Stone.createComponent(CarGcComponent.class); - - //When - List> windowsFactory = ListUtils.format(DI.windowsModule().windowFactory().get(), WeakReference::new); - List> windowWeak = ListUtils.format(DI.windowsModule().windowWeak().get(), WeakReference::new); - List> windowSoft = ListUtils.format(DI.windowsModule().windowSoft().get(), WeakReference::new); - List> windowStrong = ListUtils.format(DI.windowsModule().windowStrong().get(), WeakReference::new); - - //Then - assertEquals(3, nonNullCount(windowsFactory)); - assertEquals(3, nonNullCount(windowWeak)); - assertEquals(3, nonNullCount(windowSoft)); - assertEquals(3, nonNullCount(windowStrong)); - } - - @Test - public void createAfterGcWorkCorrect() { - // Given - CarGcComponent DI = Stone.createComponent(CarGcComponent.class); - DI.gcAll(); - - //When - List> windowsFactory = ListUtils.format(DI.windowsModule().windowFactory().get(), WeakReference::new); - List> windowWeak = ListUtils.format(DI.windowsModule().windowWeak().get(), WeakReference::new); - List> windowSoft = ListUtils.format(DI.windowsModule().windowSoft().get(), WeakReference::new); - List> windowStrong = ListUtils.format(DI.windowsModule().windowStrong().get(), WeakReference::new); - - //Then - assertEquals(3, nonNullCount(windowsFactory)); - assertEquals(3, nonNullCount(windowWeak)); - assertEquals(3, nonNullCount(windowSoft)); - assertEquals(3, nonNullCount(windowStrong)); - } - - @Test - public void gcAllTest() { - // Given - CarGcComponent DI = Stone.createComponent(CarGcComponent.class); - List> windowsFactory = ListUtils.format(DI.windowsModule().windowFactory().get(), WeakReference::new); - List> windowWeak = ListUtils.format(DI.windowsModule().windowWeak().get(), WeakReference::new); - List> windowSoft = ListUtils.format(DI.windowsModule().windowSoft().get(), WeakReference::new); - List> windowStrong = ListUtils.format(DI.windowsModule().windowStrong().get(), WeakReference::new); - - - //When - DI.gcAll(); - - // Then - assertEquals(0, nonNullCount(windowsFactory)); - assertEquals(0, nonNullCount(windowWeak)); - assertEquals(0, nonNullCount(windowSoft)); - assertEquals(0, nonNullCount(windowStrong)); - } - - @Test - public void gcWeakTest() { - // Given - CarGcComponent DI = Stone.createComponent(CarGcComponent.class); - List> windowsFactory = ListUtils.format(DI.windowsModule().windowFactory().get(), WeakReference::new); - List> windowWeak = ListUtils.format(DI.windowsModule().windowWeak().get(), WeakReference::new); - List> windowSoft = ListUtils.format(DI.windowsModule().windowSoft().get(), WeakReference::new); - List> windowStrong = ListUtils.format(DI.windowsModule().windowStrong().get(), WeakReference::new); - - //When - DI.gcWeak(); - - // Then - assertEquals(0, nonNullCount(windowsFactory)); - assertEquals(0, nonNullCount(windowWeak)); - assertEquals(3, nonNullCount(windowSoft)); - assertEquals(3, nonNullCount(windowStrong)); - } - - @Test - public void gcSoftTest() { - // Given - CarGcComponent DI = Stone.createComponent(CarGcComponent.class); - List> windowsFactory = ListUtils.format(DI.windowsModule().windowFactory().get(), WeakReference::new); - List> windowWeak = ListUtils.format(DI.windowsModule().windowWeak().get(), WeakReference::new); - List> windowSoft = ListUtils.format(DI.windowsModule().windowSoft().get(), WeakReference::new); - List> windowStrong = ListUtils.format(DI.windowsModule().windowStrong().get(), WeakReference::new); - - //When - DI.gcSoft(); - - // Then - assertEquals(0, nonNullCount(windowsFactory)); - assertEquals(0, nonNullCount(windowWeak)); - assertEquals(0, nonNullCount(windowSoft)); - assertEquals(3, nonNullCount(windowStrong)); - } - - @Test - public void gcStrongTest() { - // Given - CarGcComponent DI = Stone.createComponent(CarGcComponent.class); - List> windowsFactory = ListUtils.format(DI.windowsModule().windowFactory().get(), WeakReference::new); - List> windowWeak = ListUtils.format(DI.windowsModule().windowWeak().get(), WeakReference::new); - List> windowSoft = ListUtils.format(DI.windowsModule().windowSoft().get(), WeakReference::new); - List> windowStrong = ListUtils.format(DI.windowsModule().windowStrong().get(), WeakReference::new); - - //When - DI.gcStrong(); - - // Then - assertEquals(0, nonNullCount(windowsFactory)); - assertEquals(0, nonNullCount(windowWeak)); - assertEquals(3, nonNullCount(windowSoft)); - assertEquals(0, nonNullCount(windowStrong)); - } - - @Test - public void gcWindows() { - // Given - CarGcComponent DI = Stone.createComponent(CarGcComponent.class); - List> windowsFactory = ListUtils.format(DI.windowsModule().windowFactory().get(), WeakReference::new); - List> windowWeak = ListUtils.format(DI.windowsModule().windowWeak().get(), WeakReference::new); - List> windowSoft = ListUtils.format(DI.windowsModule().windowSoft().get(), WeakReference::new); - List> windowStrong = ListUtils.format(DI.windowsModule().windowStrong().get(), WeakReference::new); - - //When - DI.gcWindows(); - - // Then - assertEquals(0, nonNullCount(windowsFactory)); - assertEquals(0, nonNullCount(windowWeak)); - assertEquals(0, nonNullCount(windowSoft)); - assertEquals(0, nonNullCount(windowStrong)); - } - - @Test - public void gcWindowsAndWheels() { - // Given - CarGcComponent DI = Stone.createComponent(CarGcComponent.class); - List> windowsFactory = ListUtils.format(DI.windowsModule().windowFactory().get(), WeakReference::new); - List> windowWeak = ListUtils.format(DI.windowsModule().windowWeak().get(), WeakReference::new); - List> windowSoft = ListUtils.format(DI.windowsModule().windowSoft().get(), WeakReference::new); - List> windowStrong = ListUtils.format(DI.windowsModule().windowStrong().get(), WeakReference::new); - - //When - DI.gcWindowsAndWheels(); - - // Then - assertEquals(0, nonNullCount(windowsFactory)); - assertEquals(0, nonNullCount(windowWeak)); - assertEquals(0, nonNullCount(windowSoft)); - assertEquals(0, nonNullCount(windowStrong)); - } - - @Test - public void gcWheelsTest() { - // Given - CarGcComponent DI = Stone.createComponent(CarGcComponent.class); - List> windowsFactory = ListUtils.format(DI.windowsModule().windowFactory().get(), WeakReference::new); - List> windowWeak = ListUtils.format(DI.windowsModule().windowWeak().get(), WeakReference::new); - List> windowSoft = ListUtils.format(DI.windowsModule().windowSoft().get(), WeakReference::new); - List> windowStrong = ListUtils.format(DI.windowsModule().windowStrong().get(), WeakReference::new); - - - //When - DI.gcWheels(); - - // Then - assertEquals(0, nonNullCount(windowsFactory)); - assertEquals(0, nonNullCount(windowWeak)); - assertEquals(3, nonNullCount(windowSoft)); - assertEquals(3, nonNullCount(windowStrong)); - } - - @Test - public void gcNothing() { - // Given - CarGcComponent DI = Stone.createComponent(CarGcComponent.class); - List> windowsFactory = ListUtils.format(DI.windowsModule().windowFactory().get(), WeakReference::new); - List> windowWeak = ListUtils.format(DI.windowsModule().windowWeak().get(), WeakReference::new); - List> windowSoft = ListUtils.format(DI.windowsModule().windowSoft().get(), WeakReference::new); - List> windowStrong = ListUtils.format(DI.windowsModule().windowStrong().get(), WeakReference::new); - - //When - DI.gcNothing(); - - // Then - assertEquals(0, nonNullCount(windowsFactory)); - assertEquals(0, nonNullCount(windowWeak)); - assertEquals(3, nonNullCount(windowSoft)); - assertEquals(3, nonNullCount(windowStrong)); - } - - - private int nonNullCount(List> list) { - int count = 0; - for (int i = 0; i < list.size(); i++) { - if (list.get(i) != null && list.get(i).get() != null) count++; - } - return count; - } - - -} diff --git a/tests_wraps/src/test/java/com/github/klee0kai/stone/test/car/cachecontrol/gc/WindowMappedGcTests.java b/tests_wraps/src/test/java/com/github/klee0kai/stone/test/car/cachecontrol/gc/WindowMappedGcTests.java deleted file mode 100644 index d8481e6e..00000000 --- a/tests_wraps/src/test/java/com/github/klee0kai/stone/test/car/cachecontrol/gc/WindowMappedGcTests.java +++ /dev/null @@ -1,216 +0,0 @@ -package com.github.klee0kai.stone.test.car.cachecontrol.gc; - -import com.github.klee0kai.stone.Stone; -import com.github.klee0kai.stone._hidden_.types.ListUtils; -import com.github.klee0kai.test.car.di.cachecontrol.gc.CarGcComponent; -import com.github.klee0kai.test.car.model.Window; -import org.junit.jupiter.api.Test; - -import java.lang.ref.WeakReference; -import java.util.List; - -import static org.junit.jupiter.api.Assertions.assertEquals; - -public class WindowMappedGcTests { - - @Test - public void createWorkCorrect() { - // Given - CarGcComponent DI = Stone.createComponent(CarGcComponent.class); - - //When - List> windowsFactory = ListUtils.format(DI.windowsMappedModule().windowFactory("1").get(), WeakReference::new); - List> windowWeak = ListUtils.format(DI.windowsMappedModule().windowWeak("1").get(), WeakReference::new); - List> windowSoft = ListUtils.format(DI.windowsMappedModule().windowSoft("1").get(), WeakReference::new); - List> windowStrong = ListUtils.format(DI.windowsMappedModule().windowStrong("1").get(), WeakReference::new); - - //Then - assertEquals(3, nonNullCount(windowsFactory)); - assertEquals(3, nonNullCount(windowWeak)); - assertEquals(3, nonNullCount(windowSoft)); - assertEquals(3, nonNullCount(windowStrong)); - } - - @Test - public void createAfterGcWorkCorrect() { - // Given - CarGcComponent DI = Stone.createComponent(CarGcComponent.class); - DI.gcAll(); - - //When - List> windowsFactory = ListUtils.format(DI.windowsMappedModule().windowFactory("1").get(), WeakReference::new); - List> windowWeak = ListUtils.format(DI.windowsMappedModule().windowWeak("1").get(), WeakReference::new); - List> windowSoft = ListUtils.format(DI.windowsMappedModule().windowSoft("1").get(), WeakReference::new); - List> windowStrong = ListUtils.format(DI.windowsMappedModule().windowStrong("1").get(), WeakReference::new); - - //Then - assertEquals(3, nonNullCount(windowsFactory)); - assertEquals(3, nonNullCount(windowWeak)); - assertEquals(3, nonNullCount(windowSoft)); - assertEquals(3, nonNullCount(windowStrong)); - } - - @Test - public void gcAllTest() { - // Given - CarGcComponent DI = Stone.createComponent(CarGcComponent.class); - List> windowsFactory = ListUtils.format(DI.windowsMappedModule().windowFactory("1").get(), WeakReference::new); - List> windowWeak = ListUtils.format(DI.windowsMappedModule().windowWeak("1").get(), WeakReference::new); - List> windowSoft = ListUtils.format(DI.windowsMappedModule().windowSoft("1").get(), WeakReference::new); - List> windowStrong = ListUtils.format(DI.windowsMappedModule().windowStrong("1").get(), WeakReference::new); - - - //When - DI.gcAll(); - - // Then - assertEquals(0, nonNullCount(windowsFactory)); - assertEquals(0, nonNullCount(windowWeak)); - assertEquals(0, nonNullCount(windowSoft)); - assertEquals(0, nonNullCount(windowStrong)); - } - - @Test - public void gcWeakTest() { - // Given - CarGcComponent DI = Stone.createComponent(CarGcComponent.class); - List> windowsFactory = ListUtils.format(DI.windowsMappedModule().windowFactory("1").get(), WeakReference::new); - List> windowWeak = ListUtils.format(DI.windowsMappedModule().windowWeak("1").get(), WeakReference::new); - List> windowSoft = ListUtils.format(DI.windowsMappedModule().windowSoft("1").get(), WeakReference::new); - List> windowStrong = ListUtils.format(DI.windowsMappedModule().windowStrong("1").get(), WeakReference::new); - - //When - DI.gcWeak(); - - // Then - assertEquals(0, nonNullCount(windowsFactory)); - assertEquals(0, nonNullCount(windowWeak)); - assertEquals(3, nonNullCount(windowSoft)); - assertEquals(3, nonNullCount(windowStrong)); - } - - @Test - public void gcSoftTest() { - // Given - CarGcComponent DI = Stone.createComponent(CarGcComponent.class); - List> windowsFactory = ListUtils.format(DI.windowsMappedModule().windowFactory("1").get(), WeakReference::new); - List> windowWeak = ListUtils.format(DI.windowsMappedModule().windowWeak("1").get(), WeakReference::new); - List> windowSoft = ListUtils.format(DI.windowsMappedModule().windowSoft("1").get(), WeakReference::new); - List> windowStrong = ListUtils.format(DI.windowsMappedModule().windowStrong("1").get(), WeakReference::new); - - //When - DI.gcSoft(); - - // Then - assertEquals(0, nonNullCount(windowsFactory)); - assertEquals(0, nonNullCount(windowWeak)); - assertEquals(0, nonNullCount(windowSoft)); - assertEquals(3, nonNullCount(windowStrong)); - } - - @Test - public void gcStrongTest() { - // Given - CarGcComponent DI = Stone.createComponent(CarGcComponent.class); - List> windowsFactory = ListUtils.format(DI.windowsMappedModule().windowFactory("1").get(), WeakReference::new); - List> windowWeak = ListUtils.format(DI.windowsMappedModule().windowWeak("1").get(), WeakReference::new); - List> windowSoft = ListUtils.format(DI.windowsMappedModule().windowSoft("1").get(), WeakReference::new); - List> windowStrong = ListUtils.format(DI.windowsMappedModule().windowStrong("1").get(), WeakReference::new); - - //When - DI.gcStrong(); - - // Then - assertEquals(0, nonNullCount(windowsFactory)); - assertEquals(0, nonNullCount(windowWeak)); - assertEquals(3, nonNullCount(windowSoft)); - assertEquals(0, nonNullCount(windowStrong)); - } - - @Test - public void gcWindows() { - // Given - CarGcComponent DI = Stone.createComponent(CarGcComponent.class); - List> windowsFactory = ListUtils.format(DI.windowsMappedModule().windowFactory("1").get(), WeakReference::new); - List> windowWeak = ListUtils.format(DI.windowsMappedModule().windowWeak("1").get(), WeakReference::new); - List> windowSoft = ListUtils.format(DI.windowsMappedModule().windowSoft("1").get(), WeakReference::new); - List> windowStrong = ListUtils.format(DI.windowsMappedModule().windowStrong("1").get(), WeakReference::new); - - //When - DI.gcWindows(); - - // Then - assertEquals(0, nonNullCount(windowsFactory)); - assertEquals(0, nonNullCount(windowWeak)); - assertEquals(0, nonNullCount(windowSoft)); - assertEquals(0, nonNullCount(windowStrong)); - } - - @Test - public void gcWindowsAndWheels() { - // Given - CarGcComponent DI = Stone.createComponent(CarGcComponent.class); - List> windowsFactory = ListUtils.format(DI.windowsMappedModule().windowFactory("1").get(), WeakReference::new); - List> windowWeak = ListUtils.format(DI.windowsMappedModule().windowWeak("1").get(), WeakReference::new); - List> windowSoft = ListUtils.format(DI.windowsMappedModule().windowSoft("1").get(), WeakReference::new); - List> windowStrong = ListUtils.format(DI.windowsMappedModule().windowStrong("1").get(), WeakReference::new); - - //When - DI.gcWindowsAndWheels(); - - // Then - assertEquals(0, nonNullCount(windowsFactory)); - assertEquals(0, nonNullCount(windowWeak)); - assertEquals(0, nonNullCount(windowSoft)); - assertEquals(0, nonNullCount(windowStrong)); - } - - @Test - public void gcWheelsTest() { - // Given - CarGcComponent DI = Stone.createComponent(CarGcComponent.class); - List> windowsFactory = ListUtils.format(DI.windowsMappedModule().windowFactory("1").get(), WeakReference::new); - List> windowWeak = ListUtils.format(DI.windowsMappedModule().windowWeak("1").get(), WeakReference::new); - List> windowSoft = ListUtils.format(DI.windowsMappedModule().windowSoft("1").get(), WeakReference::new); - List> windowStrong = ListUtils.format(DI.windowsMappedModule().windowStrong("1").get(), WeakReference::new); - - - //When - DI.gcWheels(); - - // Then - assertEquals(0, nonNullCount(windowsFactory)); - assertEquals(0, nonNullCount(windowWeak)); - assertEquals(3, nonNullCount(windowSoft)); - assertEquals(3, nonNullCount(windowStrong)); - } - - @Test - public void gcNothing() { - // Given - CarGcComponent DI = Stone.createComponent(CarGcComponent.class); - List> windowsFactory = ListUtils.format(DI.windowsMappedModule().windowFactory("1").get(), WeakReference::new); - List> windowWeak = ListUtils.format(DI.windowsMappedModule().windowWeak("1").get(), WeakReference::new); - List> windowSoft = ListUtils.format(DI.windowsMappedModule().windowSoft("1").get(), WeakReference::new); - List> windowStrong = ListUtils.format(DI.windowsMappedModule().windowStrong("1").get(), WeakReference::new); - - //When - DI.gcNothing(); - - // Then - assertEquals(0, nonNullCount(windowsFactory)); - assertEquals(0, nonNullCount(windowWeak)); - assertEquals(3, nonNullCount(windowSoft)); - assertEquals(3, nonNullCount(windowStrong)); - } - - private int nonNullCount(List> list) { - int count = 0; - for (int i = 0; i < list.size(); i++) { - if (list.get(i) != null && list.get(i).get() != null) count++; - } - return count; - } - - -} diff --git a/tests_wraps/src/test/java/com/github/klee0kai/stone/test/car/cachecontrol/gc/WindowMappedPartialGcTests.java b/tests_wraps/src/test/java/com/github/klee0kai/stone/test/car/cachecontrol/gc/WindowMappedPartialGcTests.java deleted file mode 100644 index fa516a2f..00000000 --- a/tests_wraps/src/test/java/com/github/klee0kai/stone/test/car/cachecontrol/gc/WindowMappedPartialGcTests.java +++ /dev/null @@ -1,97 +0,0 @@ -package com.github.klee0kai.stone.test.car.cachecontrol.gc; - -import com.github.klee0kai.stone.Stone; -import com.github.klee0kai.stone._hidden_.types.ListUtils; -import com.github.klee0kai.test.car.di.cachecontrol.gc.CarGcComponent; -import com.github.klee0kai.test.car.model.Window; -import org.junit.jupiter.api.Test; - -import java.lang.ref.WeakReference; -import java.util.List; - -import static org.junit.jupiter.api.Assertions.*; - -public class WindowMappedPartialGcTests { - - @Test - public void createWorkCorrect() { - // Given - CarGcComponent DI = Stone.createComponent(CarGcComponent.class); - - //When - List> windowStrong1 = ListUtils.format(DI.windowsMappedModule().windowStrong("1").get(), WeakReference::new); - List> windowStrong2 = ListUtils.format(DI.windowsMappedModule().windowStrong("2").get(), WeakReference::new); - - //Then - assertEquals(3, nonNullCount(windowStrong1)); - assertEquals(3, nonNullCount(windowStrong2)); - } - - @Test - public void holdInListTest() { - // Given - CarGcComponent DI = Stone.createComponent(CarGcComponent.class); - List> windowStrong1 = ListUtils.format(DI.windowsMappedModule().windowStrong("1").get(), WeakReference::new); - List> windowStrong2 = ListUtils.format(DI.windowsMappedModule().windowStrong("2").get(), WeakReference::new); - Window holder1 = DI.windowsMappedModule().windowStrong("1").get().get(1); - Window holder2 = DI.windowsMappedModule().windowStrong("2").get().get(0); - - - //When - DI.gcAll(); - - // Then - assertNotNull(holder1); - assertNotNull(holder2); - assertEquals(1, nonNullCount(windowStrong1)); - assertEquals(1, nonNullCount(windowStrong2)); - assertNotNull(windowStrong1.get(1).get()); - assertNotNull(windowStrong2.get(0).get()); - } - - @Test - public void partialRecreateList1Test() { - // Given - CarGcComponent DI = Stone.createComponent(CarGcComponent.class); - List uids1 = ListUtils.format(DI.windowsMappedModule().windowStrong("1").get(), it -> it.uuid); - List uids2 = ListUtils.format(DI.windowsMappedModule().windowStrong("2").get(), it -> it.uuid); - List uids3 = ListUtils.format(DI.windowsMappedModule().windowStrong("3").get(), it -> it.uuid); - Window holder1 = DI.windowsMappedModule().windowStrong("1").get().get(0); - Window holder2 = DI.windowsMappedModule().windowStrong("2").get().get(1); - Window holder3 = DI.windowsMappedModule().windowStrong("3").get().get(2); - - - //When - DI.gcAll(); - List uids1Reused = ListUtils.format(DI.windowsMappedModule().windowStrong("1").get(), it -> it.uuid); - List uids2Reused = ListUtils.format(DI.windowsMappedModule().windowStrong("2").get(), it -> it.uuid); - List uids3Reused = ListUtils.format(DI.windowsMappedModule().windowStrong("3").get(), it -> it.uuid); - - - // Then - assertNotNull(holder1); - assertNotNull(holder2); - assertNotNull(holder3); - assertEquals(uids1.get(0), uids1Reused.get(0)); - assertNotEquals(uids1.get(1), uids1Reused.get(1)); - assertNotEquals(uids1.get(2), uids1Reused.get(2)); - - assertNotEquals(uids2.get(0), uids2Reused.get(0)); - assertEquals(uids2.get(1), uids2Reused.get(1)); - assertNotEquals(uids2.get(2), uids2Reused.get(2)); - - assertNotEquals(uids3.get(0), uids3Reused.get(0)); - assertNotEquals(uids3.get(1), uids3Reused.get(1)); - assertEquals(uids3.get(2), uids3Reused.get(2)); - } - - private int nonNullCount(List> list) { - int count = 0; - for (int i = 0; i < list.size(); i++) { - if (list.get(i) != null && list.get(i).get() != null) count++; - } - return count; - } - - -} diff --git a/tests_wraps/src/test/java/com/github/klee0kai/stone/test/car/cachecontrol/gc/WindowMappedReusableGcTests.java b/tests_wraps/src/test/java/com/github/klee0kai/stone/test/car/cachecontrol/gc/WindowMappedReusableGcTests.java deleted file mode 100644 index 19c2cd5e..00000000 --- a/tests_wraps/src/test/java/com/github/klee0kai/stone/test/car/cachecontrol/gc/WindowMappedReusableGcTests.java +++ /dev/null @@ -1,326 +0,0 @@ -package com.github.klee0kai.stone.test.car.cachecontrol.gc; - -import com.github.klee0kai.stone.Stone; -import com.github.klee0kai.stone._hidden_.types.ListUtils; -import com.github.klee0kai.test.car.di.cachecontrol.gc.CarGcComponent; -import org.junit.jupiter.api.Test; - -import java.util.List; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotEquals; - -public class WindowMappedReusableGcTests { - - @Test - public void createWorkCorrect() { - // Given - CarGcComponent DI = Stone.createComponent(CarGcComponent.class); - - //When - List windowsFactory1 = ListUtils.format(DI.windowsMappedModule().windowFactory("1").get(), it -> it.uuid); - List windowWeak1 = ListUtils.format(DI.windowsMappedModule().windowWeak("1").get(), it -> it.uuid); - List windowSoft1 = ListUtils.format(DI.windowsMappedModule().windowSoft("1").get(), it -> it.uuid); - List windowStrong1 = ListUtils.format(DI.windowsMappedModule().windowStrong("1").get(), it -> it.uuid); - List windowsFactory2 = ListUtils.format(DI.windowsMappedModule().windowFactory("2").get(), it -> it.uuid); - List windowWeak2 = ListUtils.format(DI.windowsMappedModule().windowWeak("2").get(), it -> it.uuid); - List windowSoft2 = ListUtils.format(DI.windowsMappedModule().windowSoft("2").get(), it -> it.uuid); - List windowStrong2 = ListUtils.format(DI.windowsMappedModule().windowStrong("2").get(), it -> it.uuid); - - //Then - assertNotEquals(windowsFactory1, windowsFactory2); - assertNotEquals(windowWeak1, windowWeak2); - assertNotEquals(windowSoft1, windowSoft2); - assertNotEquals(windowStrong1, windowStrong2); - } - - @Test - public void gcAllTest() { - // Given - CarGcComponent DI = Stone.createComponent(CarGcComponent.class); - List windowsFactory1 = ListUtils.format(DI.windowsMappedModule().windowFactory("1").get(), it -> it.uuid); - List windowWeak1 = ListUtils.format(DI.windowsMappedModule().windowWeak("1").get(), it -> it.uuid); - List windowSoft1 = ListUtils.format(DI.windowsMappedModule().windowSoft("1").get(), it -> it.uuid); - List windowStrong1 = ListUtils.format(DI.windowsMappedModule().windowStrong("1").get(), it -> it.uuid); - List windowsFactory2 = ListUtils.format(DI.windowsMappedModule().windowFactory("2").get(), it -> it.uuid); - List windowWeak2 = ListUtils.format(DI.windowsMappedModule().windowWeak("2").get(), it -> it.uuid); - List windowSoft2 = ListUtils.format(DI.windowsMappedModule().windowSoft("2").get(), it -> it.uuid); - List windowStrong2 = ListUtils.format(DI.windowsMappedModule().windowStrong("2").get(), it -> it.uuid); - - - //When - DI.gcAll(); - List windowsFactory1Reuse = ListUtils.format(DI.windowsMappedModule().windowFactory("1").get(), it -> it.uuid); - List windowWeak1Reuse = ListUtils.format(DI.windowsMappedModule().windowWeak("1").get(), it -> it.uuid); - List windowSoft1Reuse = ListUtils.format(DI.windowsMappedModule().windowSoft("1").get(), it -> it.uuid); - List windowStrong1Reuse = ListUtils.format(DI.windowsMappedModule().windowStrong("1").get(), it -> it.uuid); - List windowsFactory2Reuse = ListUtils.format(DI.windowsMappedModule().windowFactory("2").get(), it -> it.uuid); - List windowWeak2Reuse = ListUtils.format(DI.windowsMappedModule().windowWeak("2").get(), it -> it.uuid); - List windowSoft2Reuse = ListUtils.format(DI.windowsMappedModule().windowSoft("2").get(), it -> it.uuid); - List windowStrong2Reuse = ListUtils.format(DI.windowsMappedModule().windowStrong("2").get(), it -> it.uuid); - - // Then - assertNotEquals(windowsFactory1, windowsFactory1Reuse); - assertNotEquals(windowsFactory2, windowsFactory2Reuse); - assertNotEquals(windowWeak1, windowWeak1Reuse); - assertNotEquals(windowWeak2, windowWeak2Reuse); - assertNotEquals(windowSoft1, windowSoft1Reuse); - assertNotEquals(windowSoft2, windowSoft2Reuse); - assertNotEquals(windowStrong1, windowStrong1Reuse); - assertNotEquals(windowStrong2, windowStrong2Reuse); - } - - @Test - public void gcWeakTest() { - // Given - CarGcComponent DI = Stone.createComponent(CarGcComponent.class); - List windowsFactory1 = ListUtils.format(DI.windowsMappedModule().windowFactory("1").get(), it -> it.uuid); - List windowWeak1 = ListUtils.format(DI.windowsMappedModule().windowWeak("1").get(), it -> it.uuid); - List windowSoft1 = ListUtils.format(DI.windowsMappedModule().windowSoft("1").get(), it -> it.uuid); - List windowStrong1 = ListUtils.format(DI.windowsMappedModule().windowStrong("1").get(), it -> it.uuid); - List windowsFactory2 = ListUtils.format(DI.windowsMappedModule().windowFactory("2").get(), it -> it.uuid); - List windowWeak2 = ListUtils.format(DI.windowsMappedModule().windowWeak("2").get(), it -> it.uuid); - List windowSoft2 = ListUtils.format(DI.windowsMappedModule().windowSoft("2").get(), it -> it.uuid); - List windowStrong2 = ListUtils.format(DI.windowsMappedModule().windowStrong("2").get(), it -> it.uuid); - - - //When - DI.gcWeak(); - List windowsFactory1Reuse = ListUtils.format(DI.windowsMappedModule().windowFactory("1").get(), it -> it.uuid); - List windowWeak1Reuse = ListUtils.format(DI.windowsMappedModule().windowWeak("1").get(), it -> it.uuid); - List windowSoft1Reuse = ListUtils.format(DI.windowsMappedModule().windowSoft("1").get(), it -> it.uuid); - List windowStrong1Reuse = ListUtils.format(DI.windowsMappedModule().windowStrong("1").get(), it -> it.uuid); - List windowsFactory2Reuse = ListUtils.format(DI.windowsMappedModule().windowFactory("2").get(), it -> it.uuid); - List windowWeak2Reuse = ListUtils.format(DI.windowsMappedModule().windowWeak("2").get(), it -> it.uuid); - List windowSoft2Reuse = ListUtils.format(DI.windowsMappedModule().windowSoft("2").get(), it -> it.uuid); - List windowStrong2Reuse = ListUtils.format(DI.windowsMappedModule().windowStrong("2").get(), it -> it.uuid); - - // Then - assertNotEquals(windowsFactory1, windowsFactory1Reuse); - assertNotEquals(windowsFactory2, windowsFactory2Reuse); - assertNotEquals(windowWeak1, windowWeak1Reuse); - assertNotEquals(windowWeak2, windowWeak2Reuse); - assertEquals(windowSoft1, windowSoft1Reuse); - assertEquals(windowSoft2, windowSoft2Reuse); - assertEquals(windowStrong1, windowStrong1Reuse); - assertEquals(windowStrong2, windowStrong2Reuse); - } - - @Test - public void gcSoftTest() { - // Given - CarGcComponent DI = Stone.createComponent(CarGcComponent.class); - List windowsFactory1 = ListUtils.format(DI.windowsMappedModule().windowFactory("1").get(), it -> it.uuid); - List windowWeak1 = ListUtils.format(DI.windowsMappedModule().windowWeak("1").get(), it -> it.uuid); - List windowSoft1 = ListUtils.format(DI.windowsMappedModule().windowSoft("1").get(), it -> it.uuid); - List windowStrong1 = ListUtils.format(DI.windowsMappedModule().windowStrong("1").get(), it -> it.uuid); - List windowsFactory2 = ListUtils.format(DI.windowsMappedModule().windowFactory("2").get(), it -> it.uuid); - List windowWeak2 = ListUtils.format(DI.windowsMappedModule().windowWeak("2").get(), it -> it.uuid); - List windowSoft2 = ListUtils.format(DI.windowsMappedModule().windowSoft("2").get(), it -> it.uuid); - List windowStrong2 = ListUtils.format(DI.windowsMappedModule().windowStrong("2").get(), it -> it.uuid); - - - //When - DI.gcSoft(); - List windowsFactory1Reuse = ListUtils.format(DI.windowsMappedModule().windowFactory("1").get(), it -> it.uuid); - List windowWeak1Reuse = ListUtils.format(DI.windowsMappedModule().windowWeak("1").get(), it -> it.uuid); - List windowSoft1Reuse = ListUtils.format(DI.windowsMappedModule().windowSoft("1").get(), it -> it.uuid); - List windowStrong1Reuse = ListUtils.format(DI.windowsMappedModule().windowStrong("1").get(), it -> it.uuid); - List windowsFactory2Reuse = ListUtils.format(DI.windowsMappedModule().windowFactory("2").get(), it -> it.uuid); - List windowWeak2Reuse = ListUtils.format(DI.windowsMappedModule().windowWeak("2").get(), it -> it.uuid); - List windowSoft2Reuse = ListUtils.format(DI.windowsMappedModule().windowSoft("2").get(), it -> it.uuid); - List windowStrong2Reuse = ListUtils.format(DI.windowsMappedModule().windowStrong("2").get(), it -> it.uuid); - - // Then - assertNotEquals(windowsFactory1, windowsFactory1Reuse); - assertNotEquals(windowsFactory2, windowsFactory2Reuse); - assertNotEquals(windowWeak1, windowWeak1Reuse); - assertNotEquals(windowWeak2, windowWeak2Reuse); - assertNotEquals(windowSoft1, windowSoft1Reuse); - assertNotEquals(windowSoft2, windowSoft2Reuse); - assertEquals(windowStrong1, windowStrong1Reuse); - assertEquals(windowStrong2, windowStrong2Reuse); - } - - @Test - public void gcStrongTest() { - // Given - CarGcComponent DI = Stone.createComponent(CarGcComponent.class); - List windowsFactory1 = ListUtils.format(DI.windowsMappedModule().windowFactory("1").get(), it -> it.uuid); - List windowWeak1 = ListUtils.format(DI.windowsMappedModule().windowWeak("1").get(), it -> it.uuid); - List windowSoft1 = ListUtils.format(DI.windowsMappedModule().windowSoft("1").get(), it -> it.uuid); - List windowStrong1 = ListUtils.format(DI.windowsMappedModule().windowStrong("1").get(), it -> it.uuid); - List windowsFactory2 = ListUtils.format(DI.windowsMappedModule().windowFactory("2").get(), it -> it.uuid); - List windowWeak2 = ListUtils.format(DI.windowsMappedModule().windowWeak("2").get(), it -> it.uuid); - List windowSoft2 = ListUtils.format(DI.windowsMappedModule().windowSoft("2").get(), it -> it.uuid); - List windowStrong2 = ListUtils.format(DI.windowsMappedModule().windowStrong("2").get(), it -> it.uuid); - - - //When - DI.gcStrong(); - List windowsFactory1Reuse = ListUtils.format(DI.windowsMappedModule().windowFactory("1").get(), it -> it.uuid); - List windowWeak1Reuse = ListUtils.format(DI.windowsMappedModule().windowWeak("1").get(), it -> it.uuid); - List windowSoft1Reuse = ListUtils.format(DI.windowsMappedModule().windowSoft("1").get(), it -> it.uuid); - List windowStrong1Reuse = ListUtils.format(DI.windowsMappedModule().windowStrong("1").get(), it -> it.uuid); - List windowsFactory2Reuse = ListUtils.format(DI.windowsMappedModule().windowFactory("2").get(), it -> it.uuid); - List windowWeak2Reuse = ListUtils.format(DI.windowsMappedModule().windowWeak("2").get(), it -> it.uuid); - List windowSoft2Reuse = ListUtils.format(DI.windowsMappedModule().windowSoft("2").get(), it -> it.uuid); - List windowStrong2Reuse = ListUtils.format(DI.windowsMappedModule().windowStrong("2").get(), it -> it.uuid); - - // Then - assertNotEquals(windowsFactory1, windowsFactory1Reuse); - assertNotEquals(windowsFactory2, windowsFactory2Reuse); - assertNotEquals(windowWeak1, windowWeak1Reuse); - assertNotEquals(windowWeak2, windowWeak2Reuse); - assertEquals(windowSoft1, windowSoft1Reuse); - assertEquals(windowSoft2, windowSoft2Reuse); - assertNotEquals(windowStrong1, windowStrong1Reuse); - assertNotEquals(windowStrong2, windowStrong2Reuse); - } - - @Test - public void gcWindows() { - // Given - CarGcComponent DI = Stone.createComponent(CarGcComponent.class); - List windowsFactory1 = ListUtils.format(DI.windowsMappedModule().windowFactory("1").get(), it -> it.uuid); - List windowWeak1 = ListUtils.format(DI.windowsMappedModule().windowWeak("1").get(), it -> it.uuid); - List windowSoft1 = ListUtils.format(DI.windowsMappedModule().windowSoft("1").get(), it -> it.uuid); - List windowStrong1 = ListUtils.format(DI.windowsMappedModule().windowStrong("1").get(), it -> it.uuid); - List windowsFactory2 = ListUtils.format(DI.windowsMappedModule().windowFactory("2").get(), it -> it.uuid); - List windowWeak2 = ListUtils.format(DI.windowsMappedModule().windowWeak("2").get(), it -> it.uuid); - List windowSoft2 = ListUtils.format(DI.windowsMappedModule().windowSoft("2").get(), it -> it.uuid); - List windowStrong2 = ListUtils.format(DI.windowsMappedModule().windowStrong("2").get(), it -> it.uuid); - - - //When - DI.gcWindows(); - List windowsFactory1Reuse = ListUtils.format(DI.windowsMappedModule().windowFactory("1").get(), it -> it.uuid); - List windowWeak1Reuse = ListUtils.format(DI.windowsMappedModule().windowWeak("1").get(), it -> it.uuid); - List windowSoft1Reuse = ListUtils.format(DI.windowsMappedModule().windowSoft("1").get(), it -> it.uuid); - List windowStrong1Reuse = ListUtils.format(DI.windowsMappedModule().windowStrong("1").get(), it -> it.uuid); - List windowsFactory2Reuse = ListUtils.format(DI.windowsMappedModule().windowFactory("2").get(), it -> it.uuid); - List windowWeak2Reuse = ListUtils.format(DI.windowsMappedModule().windowWeak("2").get(), it -> it.uuid); - List windowSoft2Reuse = ListUtils.format(DI.windowsMappedModule().windowSoft("2").get(), it -> it.uuid); - List windowStrong2Reuse = ListUtils.format(DI.windowsMappedModule().windowStrong("2").get(), it -> it.uuid); - - // Then - assertNotEquals(windowsFactory1, windowsFactory1Reuse); - assertNotEquals(windowsFactory2, windowsFactory2Reuse); - assertNotEquals(windowWeak1, windowWeak1Reuse); - assertNotEquals(windowWeak2, windowWeak2Reuse); - assertNotEquals(windowSoft1, windowSoft1Reuse); - assertNotEquals(windowSoft2, windowSoft2Reuse); - assertNotEquals(windowStrong1, windowStrong1Reuse); - assertNotEquals(windowStrong2, windowStrong2Reuse); - } - - @Test - public void gcWindowsAndWheels() { - // Given - CarGcComponent DI = Stone.createComponent(CarGcComponent.class); - List windowsFactory1 = ListUtils.format(DI.windowsMappedModule().windowFactory("1").get(), it -> it.uuid); - List windowWeak1 = ListUtils.format(DI.windowsMappedModule().windowWeak("1").get(), it -> it.uuid); - List windowSoft1 = ListUtils.format(DI.windowsMappedModule().windowSoft("1").get(), it -> it.uuid); - List windowStrong1 = ListUtils.format(DI.windowsMappedModule().windowStrong("1").get(), it -> it.uuid); - List windowsFactory2 = ListUtils.format(DI.windowsMappedModule().windowFactory("2").get(), it -> it.uuid); - List windowWeak2 = ListUtils.format(DI.windowsMappedModule().windowWeak("2").get(), it -> it.uuid); - List windowSoft2 = ListUtils.format(DI.windowsMappedModule().windowSoft("2").get(), it -> it.uuid); - List windowStrong2 = ListUtils.format(DI.windowsMappedModule().windowStrong("2").get(), it -> it.uuid); - - - //When - DI.gcWindowsAndWheels(); - List windowsFactory1Reuse = ListUtils.format(DI.windowsMappedModule().windowFactory("1").get(), it -> it.uuid); - List windowWeak1Reuse = ListUtils.format(DI.windowsMappedModule().windowWeak("1").get(), it -> it.uuid); - List windowSoft1Reuse = ListUtils.format(DI.windowsMappedModule().windowSoft("1").get(), it -> it.uuid); - List windowStrong1Reuse = ListUtils.format(DI.windowsMappedModule().windowStrong("1").get(), it -> it.uuid); - List windowsFactory2Reuse = ListUtils.format(DI.windowsMappedModule().windowFactory("2").get(), it -> it.uuid); - List windowWeak2Reuse = ListUtils.format(DI.windowsMappedModule().windowWeak("2").get(), it -> it.uuid); - List windowSoft2Reuse = ListUtils.format(DI.windowsMappedModule().windowSoft("2").get(), it -> it.uuid); - List windowStrong2Reuse = ListUtils.format(DI.windowsMappedModule().windowStrong("2").get(), it -> it.uuid); - - // Then - assertNotEquals(windowsFactory1, windowsFactory1Reuse); - assertNotEquals(windowsFactory2, windowsFactory2Reuse); - assertNotEquals(windowWeak1, windowWeak1Reuse); - assertNotEquals(windowWeak2, windowWeak2Reuse); - assertNotEquals(windowSoft1, windowSoft1Reuse); - assertNotEquals(windowSoft2, windowSoft2Reuse); - assertNotEquals(windowStrong1, windowStrong1Reuse); - assertNotEquals(windowStrong2, windowStrong2Reuse); - } - - @Test - public void gcWheelsTest() { - // Given - CarGcComponent DI = Stone.createComponent(CarGcComponent.class); - List windowsFactory1 = ListUtils.format(DI.windowsMappedModule().windowFactory("1").get(), it -> it.uuid); - List windowWeak1 = ListUtils.format(DI.windowsMappedModule().windowWeak("1").get(), it -> it.uuid); - List windowSoft1 = ListUtils.format(DI.windowsMappedModule().windowSoft("1").get(), it -> it.uuid); - List windowStrong1 = ListUtils.format(DI.windowsMappedModule().windowStrong("1").get(), it -> it.uuid); - List windowsFactory2 = ListUtils.format(DI.windowsMappedModule().windowFactory("2").get(), it -> it.uuid); - List windowWeak2 = ListUtils.format(DI.windowsMappedModule().windowWeak("2").get(), it -> it.uuid); - List windowSoft2 = ListUtils.format(DI.windowsMappedModule().windowSoft("2").get(), it -> it.uuid); - List windowStrong2 = ListUtils.format(DI.windowsMappedModule().windowStrong("2").get(), it -> it.uuid); - - - //When - DI.gcWheels(); - List windowsFactory1Reuse = ListUtils.format(DI.windowsMappedModule().windowFactory("1").get(), it -> it.uuid); - List windowWeak1Reuse = ListUtils.format(DI.windowsMappedModule().windowWeak("1").get(), it -> it.uuid); - List windowSoft1Reuse = ListUtils.format(DI.windowsMappedModule().windowSoft("1").get(), it -> it.uuid); - List windowStrong1Reuse = ListUtils.format(DI.windowsMappedModule().windowStrong("1").get(), it -> it.uuid); - List windowsFactory2Reuse = ListUtils.format(DI.windowsMappedModule().windowFactory("2").get(), it -> it.uuid); - List windowWeak2Reuse = ListUtils.format(DI.windowsMappedModule().windowWeak("2").get(), it -> it.uuid); - List windowSoft2Reuse = ListUtils.format(DI.windowsMappedModule().windowSoft("2").get(), it -> it.uuid); - List windowStrong2Reuse = ListUtils.format(DI.windowsMappedModule().windowStrong("2").get(), it -> it.uuid); - - // Then - assertNotEquals(windowsFactory1, windowsFactory1Reuse); - assertNotEquals(windowsFactory2, windowsFactory2Reuse); - assertNotEquals(windowWeak1, windowWeak1Reuse); - assertNotEquals(windowWeak2, windowWeak2Reuse); - assertEquals(windowSoft1, windowSoft1Reuse); - assertEquals(windowSoft2, windowSoft2Reuse); - assertEquals(windowStrong1, windowStrong1Reuse); - assertEquals(windowStrong2, windowStrong2Reuse); - } - - @Test - public void gcNothing() { - // Given - CarGcComponent DI = Stone.createComponent(CarGcComponent.class); - List windowsFactory1 = ListUtils.format(DI.windowsMappedModule().windowFactory("1").get(), it -> it.uuid); - List windowWeak1 = ListUtils.format(DI.windowsMappedModule().windowWeak("1").get(), it -> it.uuid); - List windowSoft1 = ListUtils.format(DI.windowsMappedModule().windowSoft("1").get(), it -> it.uuid); - List windowStrong1 = ListUtils.format(DI.windowsMappedModule().windowStrong("1").get(), it -> it.uuid); - List windowsFactory2 = ListUtils.format(DI.windowsMappedModule().windowFactory("2").get(), it -> it.uuid); - List windowWeak2 = ListUtils.format(DI.windowsMappedModule().windowWeak("2").get(), it -> it.uuid); - List windowSoft2 = ListUtils.format(DI.windowsMappedModule().windowSoft("2").get(), it -> it.uuid); - List windowStrong2 = ListUtils.format(DI.windowsMappedModule().windowStrong("2").get(), it -> it.uuid); - - - //When - DI.gcNothing(); - List windowsFactory1Reuse = ListUtils.format(DI.windowsMappedModule().windowFactory("1").get(), it -> it.uuid); - List windowWeak1Reuse = ListUtils.format(DI.windowsMappedModule().windowWeak("1").get(), it -> it.uuid); - List windowSoft1Reuse = ListUtils.format(DI.windowsMappedModule().windowSoft("1").get(), it -> it.uuid); - List windowStrong1Reuse = ListUtils.format(DI.windowsMappedModule().windowStrong("1").get(), it -> it.uuid); - List windowsFactory2Reuse = ListUtils.format(DI.windowsMappedModule().windowFactory("2").get(), it -> it.uuid); - List windowWeak2Reuse = ListUtils.format(DI.windowsMappedModule().windowWeak("2").get(), it -> it.uuid); - List windowSoft2Reuse = ListUtils.format(DI.windowsMappedModule().windowSoft("2").get(), it -> it.uuid); - List windowStrong2Reuse = ListUtils.format(DI.windowsMappedModule().windowStrong("2").get(), it -> it.uuid); - - // Then - assertNotEquals(windowsFactory1, windowsFactory1Reuse); - assertNotEquals(windowsFactory2, windowsFactory2Reuse); - assertNotEquals(windowWeak1, windowWeak1Reuse); - assertNotEquals(windowWeak2, windowWeak2Reuse); - assertEquals(windowSoft1, windowSoft1Reuse); - assertEquals(windowSoft2, windowSoft2Reuse); - assertEquals(windowStrong1, windowStrong1Reuse); - assertEquals(windowStrong2, windowStrong2Reuse); - } - - -} diff --git a/tests_wraps/src/test/java/com/github/klee0kai/stone/test/car/cachecontrol/gc/WindowMultiMappedGcTests.java b/tests_wraps/src/test/java/com/github/klee0kai/stone/test/car/cachecontrol/gc/WindowMultiMappedGcTests.java deleted file mode 100644 index c9b368e6..00000000 --- a/tests_wraps/src/test/java/com/github/klee0kai/stone/test/car/cachecontrol/gc/WindowMultiMappedGcTests.java +++ /dev/null @@ -1,216 +0,0 @@ -package com.github.klee0kai.stone.test.car.cachecontrol.gc; - -import com.github.klee0kai.stone.Stone; -import com.github.klee0kai.stone._hidden_.types.ListUtils; -import com.github.klee0kai.test.car.di.cachecontrol.gc.CarGcComponent; -import com.github.klee0kai.test.car.model.Window; -import org.junit.jupiter.api.Test; - -import java.lang.ref.WeakReference; -import java.util.List; - -import static org.junit.jupiter.api.Assertions.assertEquals; - -public class WindowMultiMappedGcTests { - - @Test - public void createWorkCorrect() { - // Given - CarGcComponent DI = Stone.createComponent(CarGcComponent.class); - - //When - List> windowsFactory = ListUtils.format(DI.windowsMultiMappedModule().windowFactory(1, "1").get(), WeakReference::new); - List> windowWeak = ListUtils.format(DI.windowsMultiMappedModule().windowWeak(1, "1").get(), WeakReference::new); - List> windowSoft = ListUtils.format(DI.windowsMultiMappedModule().windowSoft(1, "1").get(), WeakReference::new); - List> windowStrong = ListUtils.format(DI.windowsMultiMappedModule().windowStrong(1, "1").get(), WeakReference::new); - - //Then - assertEquals(3, nonNullCount(windowsFactory)); - assertEquals(3, nonNullCount(windowWeak)); - assertEquals(3, nonNullCount(windowSoft)); - assertEquals(3, nonNullCount(windowStrong)); - } - - @Test - public void createAfterGcWorkCorrect() { - // Given - CarGcComponent DI = Stone.createComponent(CarGcComponent.class); - DI.gcAll(); - - //When - List> windowsFactory = ListUtils.format(DI.windowsMultiMappedModule().windowFactory(1, "1").get(), WeakReference::new); - List> windowWeak = ListUtils.format(DI.windowsMultiMappedModule().windowWeak(1, "1").get(), WeakReference::new); - List> windowSoft = ListUtils.format(DI.windowsMultiMappedModule().windowSoft(1, "1").get(), WeakReference::new); - List> windowStrong = ListUtils.format(DI.windowsMultiMappedModule().windowStrong(1, "1").get(), WeakReference::new); - - //Then - assertEquals(3, nonNullCount(windowsFactory)); - assertEquals(3, nonNullCount(windowWeak)); - assertEquals(3, nonNullCount(windowSoft)); - assertEquals(3, nonNullCount(windowStrong)); - } - - @Test - public void gcAllTest() { - // Given - CarGcComponent DI = Stone.createComponent(CarGcComponent.class); - List> windowsFactory = ListUtils.format(DI.windowsMultiMappedModule().windowFactory(1, "1").get(), WeakReference::new); - List> windowWeak = ListUtils.format(DI.windowsMultiMappedModule().windowWeak(1, "1").get(), WeakReference::new); - List> windowSoft = ListUtils.format(DI.windowsMultiMappedModule().windowSoft(1, "1").get(), WeakReference::new); - List> windowStrong = ListUtils.format(DI.windowsMultiMappedModule().windowStrong(1, "1").get(), WeakReference::new); - - - //When - DI.gcAll(); - - // Then - assertEquals(0, nonNullCount(windowsFactory)); - assertEquals(0, nonNullCount(windowWeak)); - assertEquals(0, nonNullCount(windowSoft)); - assertEquals(0, nonNullCount(windowStrong)); - } - - @Test - public void gcWeakTest() { - // Given - CarGcComponent DI = Stone.createComponent(CarGcComponent.class); - List> windowsFactory = ListUtils.format(DI.windowsMultiMappedModule().windowFactory(1, "1").get(), WeakReference::new); - List> windowWeak = ListUtils.format(DI.windowsMultiMappedModule().windowWeak(1, "1").get(), WeakReference::new); - List> windowSoft = ListUtils.format(DI.windowsMultiMappedModule().windowSoft(1, "1").get(), WeakReference::new); - List> windowStrong = ListUtils.format(DI.windowsMultiMappedModule().windowStrong(1, "1").get(), WeakReference::new); - - //When - DI.gcWeak(); - - // Then - assertEquals(0, nonNullCount(windowsFactory)); - assertEquals(0, nonNullCount(windowWeak)); - assertEquals(3, nonNullCount(windowSoft)); - assertEquals(3, nonNullCount(windowStrong)); - } - - @Test - public void gcSoftTest() { - // Given - CarGcComponent DI = Stone.createComponent(CarGcComponent.class); - List> windowsFactory = ListUtils.format(DI.windowsMultiMappedModule().windowFactory(1, "1").get(), WeakReference::new); - List> windowWeak = ListUtils.format(DI.windowsMultiMappedModule().windowWeak(1, "1").get(), WeakReference::new); - List> windowSoft = ListUtils.format(DI.windowsMultiMappedModule().windowSoft(1, "1").get(), WeakReference::new); - List> windowStrong = ListUtils.format(DI.windowsMultiMappedModule().windowStrong(1, "1").get(), WeakReference::new); - - //When - DI.gcSoft(); - - // Then - assertEquals(0, nonNullCount(windowsFactory)); - assertEquals(0, nonNullCount(windowWeak)); - assertEquals(0, nonNullCount(windowSoft)); - assertEquals(3, nonNullCount(windowStrong)); - } - - @Test - public void gcStrongTest() { - // Given - CarGcComponent DI = Stone.createComponent(CarGcComponent.class); - List> windowsFactory = ListUtils.format(DI.windowsMultiMappedModule().windowFactory(1, "1").get(), WeakReference::new); - List> windowWeak = ListUtils.format(DI.windowsMultiMappedModule().windowWeak(1, "1").get(), WeakReference::new); - List> windowSoft = ListUtils.format(DI.windowsMultiMappedModule().windowSoft(1, "1").get(), WeakReference::new); - List> windowStrong = ListUtils.format(DI.windowsMultiMappedModule().windowStrong(1, "1").get(), WeakReference::new); - - //When - DI.gcStrong(); - - // Then - assertEquals(0, nonNullCount(windowsFactory)); - assertEquals(0, nonNullCount(windowWeak)); - assertEquals(3, nonNullCount(windowSoft)); - assertEquals(0, nonNullCount(windowStrong)); - } - - @Test - public void gcWindows() { - // Given - CarGcComponent DI = Stone.createComponent(CarGcComponent.class); - List> windowsFactory = ListUtils.format(DI.windowsMultiMappedModule().windowFactory(1, "1").get(), WeakReference::new); - List> windowWeak = ListUtils.format(DI.windowsMultiMappedModule().windowWeak(1, "1").get(), WeakReference::new); - List> windowSoft = ListUtils.format(DI.windowsMultiMappedModule().windowSoft(1, "1").get(), WeakReference::new); - List> windowStrong = ListUtils.format(DI.windowsMultiMappedModule().windowStrong(1, "1").get(), WeakReference::new); - - //When - DI.gcWindows(); - - // Then - assertEquals(0, nonNullCount(windowsFactory)); - assertEquals(0, nonNullCount(windowWeak)); - assertEquals(0, nonNullCount(windowSoft)); - assertEquals(0, nonNullCount(windowStrong)); - } - - @Test - public void gcWindowsAndWheels() { - // Given - CarGcComponent DI = Stone.createComponent(CarGcComponent.class); - List> windowsFactory = ListUtils.format(DI.windowsMultiMappedModule().windowFactory(1, "1").get(), WeakReference::new); - List> windowWeak = ListUtils.format(DI.windowsMultiMappedModule().windowWeak(1, "1").get(), WeakReference::new); - List> windowSoft = ListUtils.format(DI.windowsMultiMappedModule().windowSoft(1, "1").get(), WeakReference::new); - List> windowStrong = ListUtils.format(DI.windowsMultiMappedModule().windowStrong(1, "1").get(), WeakReference::new); - - //When - DI.gcWindowsAndWheels(); - - // Then - assertEquals(0, nonNullCount(windowsFactory)); - assertEquals(0, nonNullCount(windowWeak)); - assertEquals(0, nonNullCount(windowSoft)); - assertEquals(0, nonNullCount(windowStrong)); - } - - @Test - public void gcWheelsTest() { - // Given - CarGcComponent DI = Stone.createComponent(CarGcComponent.class); - List> windowsFactory = ListUtils.format(DI.windowsMultiMappedModule().windowFactory(1, "1").get(), WeakReference::new); - List> windowWeak = ListUtils.format(DI.windowsMultiMappedModule().windowWeak(1, "1").get(), WeakReference::new); - List> windowSoft = ListUtils.format(DI.windowsMultiMappedModule().windowSoft(1, "1").get(), WeakReference::new); - List> windowStrong = ListUtils.format(DI.windowsMultiMappedModule().windowStrong(1, "1").get(), WeakReference::new); - - - //When - DI.gcWheels(); - - // Then - assertEquals(0, nonNullCount(windowsFactory)); - assertEquals(0, nonNullCount(windowWeak)); - assertEquals(3, nonNullCount(windowSoft)); - assertEquals(3, nonNullCount(windowStrong)); - } - - @Test - public void gcNothing() { - // Given - CarGcComponent DI = Stone.createComponent(CarGcComponent.class); - List> windowsFactory = ListUtils.format(DI.windowsMultiMappedModule().windowFactory(1, "1").get(), WeakReference::new); - List> windowWeak = ListUtils.format(DI.windowsMultiMappedModule().windowWeak(1, "1").get(), WeakReference::new); - List> windowSoft = ListUtils.format(DI.windowsMultiMappedModule().windowSoft(1, "1").get(), WeakReference::new); - List> windowStrong = ListUtils.format(DI.windowsMultiMappedModule().windowStrong(1, "1").get(), WeakReference::new); - - //When - DI.gcNothing(); - - // Then - assertEquals(0, nonNullCount(windowsFactory)); - assertEquals(0, nonNullCount(windowWeak)); - assertEquals(3, nonNullCount(windowSoft)); - assertEquals(3, nonNullCount(windowStrong)); - } - - private int nonNullCount(List> list) { - int count = 0; - for (int i = 0; i < list.size(); i++) { - if (list.get(i) != null && list.get(i).get() != null) count++; - } - return count; - } - - -} diff --git a/tests_wraps/src/test/java/com/github/klee0kai/stone/test/car/cachecontrol/gc/WindowMultiMappedPartialGcTests.java b/tests_wraps/src/test/java/com/github/klee0kai/stone/test/car/cachecontrol/gc/WindowMultiMappedPartialGcTests.java deleted file mode 100644 index 1cc53afd..00000000 --- a/tests_wraps/src/test/java/com/github/klee0kai/stone/test/car/cachecontrol/gc/WindowMultiMappedPartialGcTests.java +++ /dev/null @@ -1,97 +0,0 @@ -package com.github.klee0kai.stone.test.car.cachecontrol.gc; - -import com.github.klee0kai.stone.Stone; -import com.github.klee0kai.stone._hidden_.types.ListUtils; -import com.github.klee0kai.test.car.di.cachecontrol.gc.CarGcComponent; -import com.github.klee0kai.test.car.model.Window; -import org.junit.jupiter.api.Test; - -import java.lang.ref.WeakReference; -import java.util.List; - -import static org.junit.jupiter.api.Assertions.*; - -public class WindowMultiMappedPartialGcTests { - - @Test - public void createWorkCorrect() { - // Given - CarGcComponent DI = Stone.createComponent(CarGcComponent.class); - - //When - List> windowStrong1 = ListUtils.format(DI.windowsMultiMappedModule().windowStrong(1, "1").get(), WeakReference::new); - List> windowStrong2 = ListUtils.format(DI.windowsMultiMappedModule().windowStrong(1, "2").get(), WeakReference::new); - - //Then - assertEquals(3, nonNullCount(windowStrong1)); - assertEquals(3, nonNullCount(windowStrong2)); - } - - @Test - public void holdInListTest() { - // Given - CarGcComponent DI = Stone.createComponent(CarGcComponent.class); - List> windowStrong1 = ListUtils.format(DI.windowsMultiMappedModule().windowStrong(1, "1").get(), WeakReference::new); - List> windowStrong2 = ListUtils.format(DI.windowsMultiMappedModule().windowStrong(2, "2").get(), WeakReference::new); - Window holder1 = DI.windowsMultiMappedModule().windowStrong(1, "1").get().get(1); - Window holder2 = DI.windowsMultiMappedModule().windowStrong(2, "2").get().get(0); - - - //When - DI.gcAll(); - - // Then - assertNotNull(holder1); - assertNotNull(holder2); - assertEquals(1, nonNullCount(windowStrong1)); - assertEquals(1, nonNullCount(windowStrong2)); - assertNotNull(windowStrong1.get(1).get()); - assertNotNull(windowStrong2.get(0).get()); - } - - @Test - public void partialRecreateList1Test() { - // Given - CarGcComponent DI = Stone.createComponent(CarGcComponent.class); - List uids1 = ListUtils.format(DI.windowsMultiMappedModule().windowStrong(1, "1").get(), it -> it.uuid); - List uids2 = ListUtils.format(DI.windowsMultiMappedModule().windowStrong(1, "2").get(), it -> it.uuid); - List uids3 = ListUtils.format(DI.windowsMultiMappedModule().windowStrong(2, "1").get(), it -> it.uuid); - Window holder1 = DI.windowsMultiMappedModule().windowStrong(1, "1").get().get(0); - Window holder2 = DI.windowsMultiMappedModule().windowStrong(1, "2").get().get(1); - Window holder3 = DI.windowsMultiMappedModule().windowStrong(2, "1").get().get(2); - - - //When - DI.gcAll(); - List uids1Reused = ListUtils.format(DI.windowsMultiMappedModule().windowStrong(1, "1").get(), it -> it.uuid); - List uids2Reused = ListUtils.format(DI.windowsMultiMappedModule().windowStrong(1, "2").get(), it -> it.uuid); - List uids3Reused = ListUtils.format(DI.windowsMultiMappedModule().windowStrong(2, "1").get(), it -> it.uuid); - - - // Then - assertNotNull(holder1); - assertNotNull(holder2); - assertNotNull(holder3); - assertEquals(uids1.get(0), uids1Reused.get(0)); - assertNotEquals(uids1.get(1), uids1Reused.get(1)); - assertNotEquals(uids1.get(2), uids1Reused.get(2)); - - assertNotEquals(uids2.get(0), uids2Reused.get(0)); - assertEquals(uids2.get(1), uids2Reused.get(1)); - assertNotEquals(uids2.get(2), uids2Reused.get(2)); - - assertNotEquals(uids3.get(0), uids3Reused.get(0)); - assertNotEquals(uids3.get(1), uids3Reused.get(1)); - assertEquals(uids3.get(2), uids3Reused.get(2)); - } - - private int nonNullCount(List> list) { - int count = 0; - for (int i = 0; i < list.size(); i++) { - if (list.get(i) != null && list.get(i).get() != null) count++; - } - return count; - } - - -} diff --git a/tests_wraps/src/test/java/com/github/klee0kai/stone/test/car/cachecontrol/gc/WindowMultiMappedReusableGcTests.java b/tests_wraps/src/test/java/com/github/klee0kai/stone/test/car/cachecontrol/gc/WindowMultiMappedReusableGcTests.java deleted file mode 100644 index 69ab80b2..00000000 --- a/tests_wraps/src/test/java/com/github/klee0kai/stone/test/car/cachecontrol/gc/WindowMultiMappedReusableGcTests.java +++ /dev/null @@ -1,317 +0,0 @@ -package com.github.klee0kai.stone.test.car.cachecontrol.gc; - -import com.github.klee0kai.stone.Stone; -import com.github.klee0kai.stone._hidden_.types.ListUtils; -import com.github.klee0kai.test.car.di.cachecontrol.gc.CarGcComponent; -import org.junit.jupiter.api.Test; - -import java.util.List; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotEquals; - -public class WindowMultiMappedReusableGcTests { - - @Test - public void createWorkCorrect() { - // Given - CarGcComponent DI = Stone.createComponent(CarGcComponent.class); - - //When - List windowsFactory1 = ListUtils.format(DI.windowsMultiMappedModule().windowFactory(1, "1").get(), it -> it.uuid); - List windowWeak1 = ListUtils.format(DI.windowsMultiMappedModule().windowWeak(1, "1").get(), it -> it.uuid); - List windowSoft1 = ListUtils.format(DI.windowsMultiMappedModule().windowSoft(1, "1").get(), it -> it.uuid); - List windowStrong1 = ListUtils.format(DI.windowsMultiMappedModule().windowStrong(1, "1").get(), it -> it.uuid); - List windowsFactory2 = ListUtils.format(DI.windowsMultiMappedModule().windowFactory(1, "2").get(), it -> it.uuid); - List windowWeak2 = ListUtils.format(DI.windowsMultiMappedModule().windowWeak(2, "1").get(), it -> it.uuid); - List windowSoft2 = ListUtils.format(DI.windowsMultiMappedModule().windowSoft(2, "1").get(), it -> it.uuid); - List windowStrong2 = ListUtils.format(DI.windowsMultiMappedModule().windowStrong(1, "2").get(), it -> it.uuid); - - //Then - assertNotEquals(windowsFactory1, windowsFactory2); - assertNotEquals(windowWeak1, windowWeak2); - assertNotEquals(windowSoft1, windowSoft2); - assertNotEquals(windowStrong1, windowStrong2); - } - - @Test - public void gcAllTest() { - // Given - CarGcComponent DI = Stone.createComponent(CarGcComponent.class); - List windowsFactory1 = ListUtils.format(DI.windowsMultiMappedModule().windowFactory(1, "1").get(), it -> it.uuid); - List windowWeak1 = ListUtils.format(DI.windowsMultiMappedModule().windowWeak(1, "1").get(), it -> it.uuid); - List windowSoft1 = ListUtils.format(DI.windowsMultiMappedModule().windowSoft(1, "1").get(), it -> it.uuid); - List windowStrong1 = ListUtils.format(DI.windowsMultiMappedModule().windowStrong(1, "1").get(), it -> it.uuid); - List windowsFactory2 = ListUtils.format(DI.windowsMultiMappedModule().windowFactory(1, "2").get(), it -> it.uuid); - List windowWeak2 = ListUtils.format(DI.windowsMultiMappedModule().windowWeak(2, "1").get(), it -> it.uuid); - List windowSoft2 = ListUtils.format(DI.windowsMultiMappedModule().windowSoft(2, "1").get(), it -> it.uuid); - List windowStrong2 = ListUtils.format(DI.windowsMultiMappedModule().windowStrong(1, "2").get(), it -> it.uuid); - - //When - DI.gcAll(); - List windowsFactory1Reuse = ListUtils.format(DI.windowsMultiMappedModule().windowFactory(1, "1").get(), it -> it.uuid); - List windowWeak1Reuse = ListUtils.format(DI.windowsMultiMappedModule().windowWeak(1, "1").get(), it -> it.uuid); - List windowSoft1Reuse = ListUtils.format(DI.windowsMultiMappedModule().windowSoft(1, "1").get(), it -> it.uuid); - List windowStrong1Reuse = ListUtils.format(DI.windowsMultiMappedModule().windowStrong(1, "1").get(), it -> it.uuid); - List windowsFactory2Reuse = ListUtils.format(DI.windowsMultiMappedModule().windowFactory(1, "2").get(), it -> it.uuid); - List windowWeak2Reuse = ListUtils.format(DI.windowsMultiMappedModule().windowWeak(2, "1").get(), it -> it.uuid); - List windowSoft2Reuse = ListUtils.format(DI.windowsMultiMappedModule().windowSoft(2, "1").get(), it -> it.uuid); - List windowStrong2Reuse = ListUtils.format(DI.windowsMultiMappedModule().windowStrong(1, "2").get(), it -> it.uuid); - - // Then - assertNotEquals(windowsFactory1, windowsFactory1Reuse); - assertNotEquals(windowsFactory2, windowsFactory2Reuse); - assertNotEquals(windowWeak1, windowWeak1Reuse); - assertNotEquals(windowWeak2, windowWeak2Reuse); - assertNotEquals(windowSoft1, windowSoft1Reuse); - assertNotEquals(windowSoft2, windowSoft2Reuse); - assertNotEquals(windowStrong1, windowStrong1Reuse); - assertNotEquals(windowStrong2, windowStrong2Reuse); - } - - @Test - public void gcWeakTest() { - // Given - CarGcComponent DI = Stone.createComponent(CarGcComponent.class); - List windowsFactory1 = ListUtils.format(DI.windowsMultiMappedModule().windowFactory(1, "1").get(), it -> it.uuid); - List windowWeak1 = ListUtils.format(DI.windowsMultiMappedModule().windowWeak(1, "1").get(), it -> it.uuid); - List windowSoft1 = ListUtils.format(DI.windowsMultiMappedModule().windowSoft(1, "1").get(), it -> it.uuid); - List windowStrong1 = ListUtils.format(DI.windowsMultiMappedModule().windowStrong(1, "1").get(), it -> it.uuid); - List windowsFactory2 = ListUtils.format(DI.windowsMultiMappedModule().windowFactory(1, "2").get(), it -> it.uuid); - List windowWeak2 = ListUtils.format(DI.windowsMultiMappedModule().windowWeak(2, "1").get(), it -> it.uuid); - List windowSoft2 = ListUtils.format(DI.windowsMultiMappedModule().windowSoft(2, "1").get(), it -> it.uuid); - List windowStrong2 = ListUtils.format(DI.windowsMultiMappedModule().windowStrong(1, "2").get(), it -> it.uuid); - - //When - DI.gcWeak(); - List windowsFactory1Reuse = ListUtils.format(DI.windowsMultiMappedModule().windowFactory(1, "1").get(), it -> it.uuid); - List windowWeak1Reuse = ListUtils.format(DI.windowsMultiMappedModule().windowWeak(1, "1").get(), it -> it.uuid); - List windowSoft1Reuse = ListUtils.format(DI.windowsMultiMappedModule().windowSoft(1, "1").get(), it -> it.uuid); - List windowStrong1Reuse = ListUtils.format(DI.windowsMultiMappedModule().windowStrong(1, "1").get(), it -> it.uuid); - List windowsFactory2Reuse = ListUtils.format(DI.windowsMultiMappedModule().windowFactory(1, "2").get(), it -> it.uuid); - List windowWeak2Reuse = ListUtils.format(DI.windowsMultiMappedModule().windowWeak(2, "1").get(), it -> it.uuid); - List windowSoft2Reuse = ListUtils.format(DI.windowsMultiMappedModule().windowSoft(2, "1").get(), it -> it.uuid); - List windowStrong2Reuse = ListUtils.format(DI.windowsMultiMappedModule().windowStrong(1, "2").get(), it -> it.uuid); - - // Then - assertNotEquals(windowsFactory1, windowsFactory1Reuse); - assertNotEquals(windowsFactory2, windowsFactory2Reuse); - assertNotEquals(windowWeak1, windowWeak1Reuse); - assertNotEquals(windowWeak2, windowWeak2Reuse); - assertEquals(windowSoft1, windowSoft1Reuse); - assertEquals(windowSoft2, windowSoft2Reuse); - assertEquals(windowStrong1, windowStrong1Reuse); - assertEquals(windowStrong2, windowStrong2Reuse); - } - - @Test - public void gcSoftTest() { - // Given - CarGcComponent DI = Stone.createComponent(CarGcComponent.class); - List windowsFactory1 = ListUtils.format(DI.windowsMultiMappedModule().windowFactory(1, "1").get(), it -> it.uuid); - List windowWeak1 = ListUtils.format(DI.windowsMultiMappedModule().windowWeak(1, "1").get(), it -> it.uuid); - List windowSoft1 = ListUtils.format(DI.windowsMultiMappedModule().windowSoft(1, "1").get(), it -> it.uuid); - List windowStrong1 = ListUtils.format(DI.windowsMultiMappedModule().windowStrong(1, "1").get(), it -> it.uuid); - List windowsFactory2 = ListUtils.format(DI.windowsMultiMappedModule().windowFactory(1, "2").get(), it -> it.uuid); - List windowWeak2 = ListUtils.format(DI.windowsMultiMappedModule().windowWeak(2, "1").get(), it -> it.uuid); - List windowSoft2 = ListUtils.format(DI.windowsMultiMappedModule().windowSoft(2, "1").get(), it -> it.uuid); - List windowStrong2 = ListUtils.format(DI.windowsMultiMappedModule().windowStrong(1, "2").get(), it -> it.uuid); - - //When - DI.gcSoft(); - List windowsFactory1Reuse = ListUtils.format(DI.windowsMultiMappedModule().windowFactory(1, "1").get(), it -> it.uuid); - List windowWeak1Reuse = ListUtils.format(DI.windowsMultiMappedModule().windowWeak(1, "1").get(), it -> it.uuid); - List windowSoft1Reuse = ListUtils.format(DI.windowsMultiMappedModule().windowSoft(1, "1").get(), it -> it.uuid); - List windowStrong1Reuse = ListUtils.format(DI.windowsMultiMappedModule().windowStrong(1, "1").get(), it -> it.uuid); - List windowsFactory2Reuse = ListUtils.format(DI.windowsMultiMappedModule().windowFactory(1, "2").get(), it -> it.uuid); - List windowWeak2Reuse = ListUtils.format(DI.windowsMultiMappedModule().windowWeak(2, "1").get(), it -> it.uuid); - List windowSoft2Reuse = ListUtils.format(DI.windowsMultiMappedModule().windowSoft(2, "1").get(), it -> it.uuid); - List windowStrong2Reuse = ListUtils.format(DI.windowsMultiMappedModule().windowStrong(1, "2").get(), it -> it.uuid); - - // Then - assertNotEquals(windowsFactory1, windowsFactory1Reuse); - assertNotEquals(windowsFactory2, windowsFactory2Reuse); - assertNotEquals(windowWeak1, windowWeak1Reuse); - assertNotEquals(windowWeak2, windowWeak2Reuse); - assertNotEquals(windowSoft1, windowSoft1Reuse); - assertNotEquals(windowSoft2, windowSoft2Reuse); - assertEquals(windowStrong1, windowStrong1Reuse); - assertEquals(windowStrong2, windowStrong2Reuse); - } - - @Test - public void gcStrongTest() { - // Given - CarGcComponent DI = Stone.createComponent(CarGcComponent.class); - List windowsFactory1 = ListUtils.format(DI.windowsMultiMappedModule().windowFactory(1, "1").get(), it -> it.uuid); - List windowWeak1 = ListUtils.format(DI.windowsMultiMappedModule().windowWeak(1, "1").get(), it -> it.uuid); - List windowSoft1 = ListUtils.format(DI.windowsMultiMappedModule().windowSoft(1, "1").get(), it -> it.uuid); - List windowStrong1 = ListUtils.format(DI.windowsMultiMappedModule().windowStrong(1, "1").get(), it -> it.uuid); - List windowsFactory2 = ListUtils.format(DI.windowsMultiMappedModule().windowFactory(1, "2").get(), it -> it.uuid); - List windowWeak2 = ListUtils.format(DI.windowsMultiMappedModule().windowWeak(2, "1").get(), it -> it.uuid); - List windowSoft2 = ListUtils.format(DI.windowsMultiMappedModule().windowSoft(2, "1").get(), it -> it.uuid); - List windowStrong2 = ListUtils.format(DI.windowsMultiMappedModule().windowStrong(1, "2").get(), it -> it.uuid); - - //When - DI.gcStrong(); - List windowsFactory1Reuse = ListUtils.format(DI.windowsMultiMappedModule().windowFactory(1, "1").get(), it -> it.uuid); - List windowWeak1Reuse = ListUtils.format(DI.windowsMultiMappedModule().windowWeak(1, "1").get(), it -> it.uuid); - List windowSoft1Reuse = ListUtils.format(DI.windowsMultiMappedModule().windowSoft(1, "1").get(), it -> it.uuid); - List windowStrong1Reuse = ListUtils.format(DI.windowsMultiMappedModule().windowStrong(1, "1").get(), it -> it.uuid); - List windowsFactory2Reuse = ListUtils.format(DI.windowsMultiMappedModule().windowFactory(1, "2").get(), it -> it.uuid); - List windowWeak2Reuse = ListUtils.format(DI.windowsMultiMappedModule().windowWeak(2, "1").get(), it -> it.uuid); - List windowSoft2Reuse = ListUtils.format(DI.windowsMultiMappedModule().windowSoft(2, "1").get(), it -> it.uuid); - List windowStrong2Reuse = ListUtils.format(DI.windowsMultiMappedModule().windowStrong(1, "2").get(), it -> it.uuid); - - // Then - assertNotEquals(windowsFactory1, windowsFactory1Reuse); - assertNotEquals(windowsFactory2, windowsFactory2Reuse); - assertNotEquals(windowWeak1, windowWeak1Reuse); - assertNotEquals(windowWeak2, windowWeak2Reuse); - assertEquals(windowSoft1, windowSoft1Reuse); - assertEquals(windowSoft2, windowSoft2Reuse); - assertNotEquals(windowStrong1, windowStrong1Reuse); - assertNotEquals(windowStrong2, windowStrong2Reuse); - } - - @Test - public void gcWindows() { - // Given - CarGcComponent DI = Stone.createComponent(CarGcComponent.class); - List windowsFactory1 = ListUtils.format(DI.windowsMultiMappedModule().windowFactory(1, "1").get(), it -> it.uuid); - List windowWeak1 = ListUtils.format(DI.windowsMultiMappedModule().windowWeak(1, "1").get(), it -> it.uuid); - List windowSoft1 = ListUtils.format(DI.windowsMultiMappedModule().windowSoft(1, "1").get(), it -> it.uuid); - List windowStrong1 = ListUtils.format(DI.windowsMultiMappedModule().windowStrong(1, "1").get(), it -> it.uuid); - List windowsFactory2 = ListUtils.format(DI.windowsMultiMappedModule().windowFactory(1, "2").get(), it -> it.uuid); - List windowWeak2 = ListUtils.format(DI.windowsMultiMappedModule().windowWeak(2, "1").get(), it -> it.uuid); - List windowSoft2 = ListUtils.format(DI.windowsMultiMappedModule().windowSoft(2, "1").get(), it -> it.uuid); - List windowStrong2 = ListUtils.format(DI.windowsMultiMappedModule().windowStrong(1, "2").get(), it -> it.uuid); - - //When - DI.gcWindows(); - List windowsFactory1Reuse = ListUtils.format(DI.windowsMultiMappedModule().windowFactory(1, "1").get(), it -> it.uuid); - List windowWeak1Reuse = ListUtils.format(DI.windowsMultiMappedModule().windowWeak(1, "1").get(), it -> it.uuid); - List windowSoft1Reuse = ListUtils.format(DI.windowsMultiMappedModule().windowSoft(1, "1").get(), it -> it.uuid); - List windowStrong1Reuse = ListUtils.format(DI.windowsMultiMappedModule().windowStrong(1, "1").get(), it -> it.uuid); - List windowsFactory2Reuse = ListUtils.format(DI.windowsMultiMappedModule().windowFactory(1, "2").get(), it -> it.uuid); - List windowWeak2Reuse = ListUtils.format(DI.windowsMultiMappedModule().windowWeak(2, "1").get(), it -> it.uuid); - List windowSoft2Reuse = ListUtils.format(DI.windowsMultiMappedModule().windowSoft(2, "1").get(), it -> it.uuid); - List windowStrong2Reuse = ListUtils.format(DI.windowsMultiMappedModule().windowStrong(1, "2").get(), it -> it.uuid); - - // Then - assertNotEquals(windowsFactory1, windowsFactory1Reuse); - assertNotEquals(windowsFactory2, windowsFactory2Reuse); - assertNotEquals(windowWeak1, windowWeak1Reuse); - assertNotEquals(windowWeak2, windowWeak2Reuse); - assertNotEquals(windowSoft1, windowSoft1Reuse); - assertNotEquals(windowSoft2, windowSoft2Reuse); - assertNotEquals(windowStrong1, windowStrong1Reuse); - assertNotEquals(windowStrong2, windowStrong2Reuse); - } - - @Test - public void gcWindowsAndWheels() { - // Given - CarGcComponent DI = Stone.createComponent(CarGcComponent.class); - List windowsFactory1 = ListUtils.format(DI.windowsMultiMappedModule().windowFactory(1, "1").get(), it -> it.uuid); - List windowWeak1 = ListUtils.format(DI.windowsMultiMappedModule().windowWeak(1, "1").get(), it -> it.uuid); - List windowSoft1 = ListUtils.format(DI.windowsMultiMappedModule().windowSoft(1, "1").get(), it -> it.uuid); - List windowStrong1 = ListUtils.format(DI.windowsMultiMappedModule().windowStrong(1, "1").get(), it -> it.uuid); - List windowsFactory2 = ListUtils.format(DI.windowsMultiMappedModule().windowFactory(1, "2").get(), it -> it.uuid); - List windowWeak2 = ListUtils.format(DI.windowsMultiMappedModule().windowWeak(2, "1").get(), it -> it.uuid); - List windowSoft2 = ListUtils.format(DI.windowsMultiMappedModule().windowSoft(2, "1").get(), it -> it.uuid); - List windowStrong2 = ListUtils.format(DI.windowsMultiMappedModule().windowStrong(1, "2").get(), it -> it.uuid); - - //When - DI.gcWindowsAndWheels(); - List windowsFactory1Reuse = ListUtils.format(DI.windowsMultiMappedModule().windowFactory(1, "1").get(), it -> it.uuid); - List windowWeak1Reuse = ListUtils.format(DI.windowsMultiMappedModule().windowWeak(1, "1").get(), it -> it.uuid); - List windowSoft1Reuse = ListUtils.format(DI.windowsMultiMappedModule().windowSoft(1, "1").get(), it -> it.uuid); - List windowStrong1Reuse = ListUtils.format(DI.windowsMultiMappedModule().windowStrong(1, "1").get(), it -> it.uuid); - List windowsFactory2Reuse = ListUtils.format(DI.windowsMultiMappedModule().windowFactory(1, "2").get(), it -> it.uuid); - List windowWeak2Reuse = ListUtils.format(DI.windowsMultiMappedModule().windowWeak(2, "1").get(), it -> it.uuid); - List windowSoft2Reuse = ListUtils.format(DI.windowsMultiMappedModule().windowSoft(2, "1").get(), it -> it.uuid); - List windowStrong2Reuse = ListUtils.format(DI.windowsMultiMappedModule().windowStrong(1, "2").get(), it -> it.uuid); - - // Then - assertNotEquals(windowsFactory1, windowsFactory1Reuse); - assertNotEquals(windowsFactory2, windowsFactory2Reuse); - assertNotEquals(windowWeak1, windowWeak1Reuse); - assertNotEquals(windowWeak2, windowWeak2Reuse); - assertNotEquals(windowSoft1, windowSoft1Reuse); - assertNotEquals(windowSoft2, windowSoft2Reuse); - assertNotEquals(windowStrong1, windowStrong1Reuse); - assertNotEquals(windowStrong2, windowStrong2Reuse); - } - - @Test - public void gcWheelsTest() { - // Given - CarGcComponent DI = Stone.createComponent(CarGcComponent.class); - List windowsFactory1 = ListUtils.format(DI.windowsMultiMappedModule().windowFactory(1, "1").get(), it -> it.uuid); - List windowWeak1 = ListUtils.format(DI.windowsMultiMappedModule().windowWeak(1, "1").get(), it -> it.uuid); - List windowSoft1 = ListUtils.format(DI.windowsMultiMappedModule().windowSoft(1, "1").get(), it -> it.uuid); - List windowStrong1 = ListUtils.format(DI.windowsMultiMappedModule().windowStrong(1, "1").get(), it -> it.uuid); - List windowsFactory2 = ListUtils.format(DI.windowsMultiMappedModule().windowFactory(1, "2").get(), it -> it.uuid); - List windowWeak2 = ListUtils.format(DI.windowsMultiMappedModule().windowWeak(2, "1").get(), it -> it.uuid); - List windowSoft2 = ListUtils.format(DI.windowsMultiMappedModule().windowSoft(2, "1").get(), it -> it.uuid); - List windowStrong2 = ListUtils.format(DI.windowsMultiMappedModule().windowStrong(1, "2").get(), it -> it.uuid); - - //When - DI.gcWheels(); - List windowsFactory1Reuse = ListUtils.format(DI.windowsMultiMappedModule().windowFactory(1, "1").get(), it -> it.uuid); - List windowWeak1Reuse = ListUtils.format(DI.windowsMultiMappedModule().windowWeak(1, "1").get(), it -> it.uuid); - List windowSoft1Reuse = ListUtils.format(DI.windowsMultiMappedModule().windowSoft(1, "1").get(), it -> it.uuid); - List windowStrong1Reuse = ListUtils.format(DI.windowsMultiMappedModule().windowStrong(1, "1").get(), it -> it.uuid); - List windowsFactory2Reuse = ListUtils.format(DI.windowsMultiMappedModule().windowFactory(1, "2").get(), it -> it.uuid); - List windowWeak2Reuse = ListUtils.format(DI.windowsMultiMappedModule().windowWeak(2, "1").get(), it -> it.uuid); - List windowSoft2Reuse = ListUtils.format(DI.windowsMultiMappedModule().windowSoft(2, "1").get(), it -> it.uuid); - List windowStrong2Reuse = ListUtils.format(DI.windowsMultiMappedModule().windowStrong(1, "2").get(), it -> it.uuid); - - // Then - assertNotEquals(windowsFactory1, windowsFactory1Reuse); - assertNotEquals(windowsFactory2, windowsFactory2Reuse); - assertNotEquals(windowWeak1, windowWeak1Reuse); - assertNotEquals(windowWeak2, windowWeak2Reuse); - assertEquals(windowSoft1, windowSoft1Reuse); - assertEquals(windowSoft2, windowSoft2Reuse); - assertEquals(windowStrong1, windowStrong1Reuse); - assertEquals(windowStrong2, windowStrong2Reuse); - } - - @Test - public void gcNothing() { - // Given - CarGcComponent DI = Stone.createComponent(CarGcComponent.class); - List windowsFactory1 = ListUtils.format(DI.windowsMultiMappedModule().windowFactory(1, "1").get(), it -> it.uuid); - List windowWeak1 = ListUtils.format(DI.windowsMultiMappedModule().windowWeak(1, "1").get(), it -> it.uuid); - List windowSoft1 = ListUtils.format(DI.windowsMultiMappedModule().windowSoft(1, "1").get(), it -> it.uuid); - List windowStrong1 = ListUtils.format(DI.windowsMultiMappedModule().windowStrong(1, "1").get(), it -> it.uuid); - List windowsFactory2 = ListUtils.format(DI.windowsMultiMappedModule().windowFactory(1, "2").get(), it -> it.uuid); - List windowWeak2 = ListUtils.format(DI.windowsMultiMappedModule().windowWeak(2, "1").get(), it -> it.uuid); - List windowSoft2 = ListUtils.format(DI.windowsMultiMappedModule().windowSoft(2, "1").get(), it -> it.uuid); - List windowStrong2 = ListUtils.format(DI.windowsMultiMappedModule().windowStrong(1, "2").get(), it -> it.uuid); - - //When - DI.gcNothing(); - List windowsFactory1Reuse = ListUtils.format(DI.windowsMultiMappedModule().windowFactory(1, "1").get(), it -> it.uuid); - List windowWeak1Reuse = ListUtils.format(DI.windowsMultiMappedModule().windowWeak(1, "1").get(), it -> it.uuid); - List windowSoft1Reuse = ListUtils.format(DI.windowsMultiMappedModule().windowSoft(1, "1").get(), it -> it.uuid); - List windowStrong1Reuse = ListUtils.format(DI.windowsMultiMappedModule().windowStrong(1, "1").get(), it -> it.uuid); - List windowsFactory2Reuse = ListUtils.format(DI.windowsMultiMappedModule().windowFactory(1, "2").get(), it -> it.uuid); - List windowWeak2Reuse = ListUtils.format(DI.windowsMultiMappedModule().windowWeak(2, "1").get(), it -> it.uuid); - List windowSoft2Reuse = ListUtils.format(DI.windowsMultiMappedModule().windowSoft(2, "1").get(), it -> it.uuid); - List windowStrong2Reuse = ListUtils.format(DI.windowsMultiMappedModule().windowStrong(1, "2").get(), it -> it.uuid); - - // Then - assertNotEquals(windowsFactory1, windowsFactory1Reuse); - assertNotEquals(windowsFactory2, windowsFactory2Reuse); - assertNotEquals(windowWeak1, windowWeak1Reuse); - assertNotEquals(windowWeak2, windowWeak2Reuse); - assertEquals(windowSoft1, windowSoft1Reuse); - assertEquals(windowSoft2, windowSoft2Reuse); - assertEquals(windowStrong1, windowStrong1Reuse); - assertEquals(windowStrong2, windowStrong2Reuse); - } - -} diff --git a/tests_wraps/src/test/java/com/github/klee0kai/stone/test/car/cachecontrol/gc/WindowPartialGcTests.java b/tests_wraps/src/test/java/com/github/klee0kai/stone/test/car/cachecontrol/gc/WindowPartialGcTests.java deleted file mode 100644 index 6c84ed49..00000000 --- a/tests_wraps/src/test/java/com/github/klee0kai/stone/test/car/cachecontrol/gc/WindowPartialGcTests.java +++ /dev/null @@ -1,114 +0,0 @@ -package com.github.klee0kai.stone.test.car.cachecontrol.gc; - -import com.github.klee0kai.stone.Stone; -import com.github.klee0kai.stone._hidden_.types.ListUtils; -import com.github.klee0kai.test.car.di.cachecontrol.gc.CarGcComponent; -import com.github.klee0kai.test.car.model.Window; -import org.junit.jupiter.api.Test; - -import java.lang.ref.WeakReference; -import java.util.List; - -import static org.junit.jupiter.api.Assertions.*; - -public class WindowPartialGcTests { - - @Test - public void createWorkCorrect() { - // Given - CarGcComponent DI = Stone.createComponent(CarGcComponent.class); - - //When - List> windowStrong = ListUtils.format(DI.windowsModule().windowStrong().get(), WeakReference::new); - - //Then - assertEquals(3, nonNullCount(windowStrong)); - } - - @Test - public void holdInListTest() { - // Given - CarGcComponent DI = Stone.createComponent(CarGcComponent.class); - List> windowStrong = ListUtils.format(DI.windowsModule().windowStrong().get(), WeakReference::new); - Window holder = DI.windowsModule().windowStrong().get().get(1); - - - //When - DI.gcAll(); - - // Then - assertNotNull(holder); - assertEquals(1, nonNullCount(windowStrong)); - assertNotNull(windowStrong.get(1).get()); - } - - @Test - public void partialRecreateList1Test() { - // Given - CarGcComponent DI = Stone.createComponent(CarGcComponent.class); - List uids1 = ListUtils.format(DI.windowsModule().windowStrong().get(), it -> it.uuid); - Window holder = DI.windowsModule().windowStrong().get().get(0); - - - //When - DI.gcAll(); - List uids2 = ListUtils.format(DI.windowsModule().windowStrong().get(), it -> it.uuid); - - - // Then - assertNotNull(holder); - assertEquals(uids1.get(0), uids2.get(0)); - assertNotEquals(uids1.get(1), uids2.get(1)); - assertNotEquals(uids1.get(2), uids2.get(2)); - } - - @Test - public void partialRecreateList2Test() { - // Given - CarGcComponent DI = Stone.createComponent(CarGcComponent.class); - List uids1 = ListUtils.format(DI.windowsModule().windowStrong().get(), it -> it.uuid); - Window holder = DI.windowsModule().windowStrong().get().get(1); - - - //When - DI.gcAll(); - List uids2 = ListUtils.format(DI.windowsModule().windowStrong().get(), it -> it.uuid); - - - // Then - assertNotNull(holder); - assertNotEquals(uids1.get(0), uids2.get(0)); - assertEquals(uids1.get(1), uids2.get(1)); - assertNotEquals(uids1.get(2), uids2.get(2)); - } - - @Test - public void partialRecreateList3Test() { - // Given - CarGcComponent DI = Stone.createComponent(CarGcComponent.class); - List uids1 = ListUtils.format(DI.windowsModule().windowStrong().get(), it -> it.uuid); - Window holder = DI.windowsModule().windowStrong().get().get(2); - - - //When - DI.gcAll(); - List uids2 = ListUtils.format(DI.windowsModule().windowStrong().get(), it -> it.uuid); - - - // Then - assertNotNull(holder); - assertNotEquals(uids1.get(0), uids2.get(0)); - assertNotEquals(uids1.get(1), uids2.get(1)); - assertEquals(uids1.get(2), uids2.get(2)); - } - - private int nonNullCount(List> list) { - int count = 0; - for (int i = 0; i < list.size(); i++) { - if (list.get(i) != null && list.get(i).get() != null) count++; - } - return count; - } - - -} diff --git a/tests_wraps/src/test/java/com/github/klee0kai/stone/test/car/cachecontrol/swcache/BumperSwitchCacheTests.java b/tests_wraps/src/test/java/com/github/klee0kai/stone/test/car/cachecontrol/swcache/BumperSwitchCacheTests.java deleted file mode 100644 index d936c315..00000000 --- a/tests_wraps/src/test/java/com/github/klee0kai/stone/test/car/cachecontrol/swcache/BumperSwitchCacheTests.java +++ /dev/null @@ -1,226 +0,0 @@ -package com.github.klee0kai.stone.test.car.cachecontrol.swcache; - -import com.github.klee0kai.stone.Stone; -import com.github.klee0kai.stone._hidden_.types.ListUtils; -import com.github.klee0kai.test.car.di.cachecontrol.swcache.CarSwCacheComponent; -import com.github.klee0kai.test.car.model.Bumper; -import org.junit.jupiter.api.Test; - -import java.lang.ref.WeakReference; -import java.util.List; - -import static org.junit.jupiter.api.Assertions.assertEquals; - -public class BumperSwitchCacheTests { - - @Test - public void allWeakTest() { - // Given - CarSwCacheComponent DI = Stone.createComponent(CarSwCacheComponent.class); - List> bumperFactory = ListUtils.format(DI.bumpersModule().bumperFactory(), WeakReference::new); - List> bumperWeak = ListUtils.format(DI.bumpersModule().bumperWeak(), WeakReference::new); - List> bumperSoft = ListUtils.format(DI.bumpersModule().bumperSoft(), WeakReference::new); - List> bumperStrong = ListUtils.format(DI.bumpersModule().bumperStrong(), WeakReference::new); - - //When - DI.allWeak(); - System.gc(); - - // Then - assertEquals(0, nonNullCount(bumperFactory)); - assertEquals(0, nonNullCount(bumperWeak)); - assertEquals(0, nonNullCount(bumperSoft)); - assertEquals(0, nonNullCount(bumperStrong)); - } - - @Test - public void weakToStrongTest() { - // Given - CarSwCacheComponent DI = Stone.createComponent(CarSwCacheComponent.class); - List> bumperFactory = ListUtils.format(DI.bumpersModule().bumperFactory(), WeakReference::new); - List> bumperWeak = ListUtils.format(DI.bumpersModule().bumperWeak(), WeakReference::new); - List> bumperSoft = ListUtils.format(DI.bumpersModule().bumperSoft(), WeakReference::new); - List> bumperStrong = ListUtils.format(DI.bumpersModule().bumperStrong(), WeakReference::new); - - //When - DI.weakToStrongFewMillis(); - System.gc(); - - // Then - assertEquals(0, nonNullCount(bumperFactory)); - assertEquals(3, nonNullCount(bumperWeak)); - assertEquals(3, nonNullCount(bumperSoft)); - assertEquals(3, nonNullCount(bumperStrong)); - } - - @Test - public void weakToStrongAfterFewMillisTest() throws InterruptedException { - // Given - CarSwCacheComponent DI = Stone.createComponent(CarSwCacheComponent.class); - List> bumperFactory = ListUtils.format(DI.bumpersModule().bumperFactory(), WeakReference::new); - List> bumperWeak = ListUtils.format(DI.bumpersModule().bumperWeak(), WeakReference::new); - List> bumperSoft = ListUtils.format(DI.bumpersModule().bumperSoft(), WeakReference::new); - List> bumperStrong = ListUtils.format(DI.bumpersModule().bumperStrong(), WeakReference::new); - - //When - DI.weakToStrongFewMillis(); - Thread.sleep(150); - System.gc(); - - // Then - assertEquals(0, nonNullCount(bumperFactory)); - assertEquals(0, nonNullCount(bumperWeak)); - assertEquals(3, nonNullCount(bumperSoft)); - assertEquals(3, nonNullCount(bumperStrong)); - } - - @Test - public void softToWeakTest() { - // Given - CarSwCacheComponent DI = Stone.createComponent(CarSwCacheComponent.class); - List> bumperFactory = ListUtils.format(DI.bumpersModule().bumperFactory(), WeakReference::new); - List> bumperWeak = ListUtils.format(DI.bumpersModule().bumperWeak(), WeakReference::new); - List> bumperSoft = ListUtils.format(DI.bumpersModule().bumperSoft(), WeakReference::new); - List> bumperStrong = ListUtils.format(DI.bumpersModule().bumperStrong(), WeakReference::new); - - //When - DI.softToWeak(); - System.gc(); - - // Then - assertEquals(0, nonNullCount(bumperFactory)); - assertEquals(0, nonNullCount(bumperWeak)); - assertEquals(0, nonNullCount(bumperSoft)); - assertEquals(3, nonNullCount(bumperStrong)); - } - - @Test - public void strongToWeakTest() { - // Given - CarSwCacheComponent DI = Stone.createComponent(CarSwCacheComponent.class); - List> bumperFactory = ListUtils.format(DI.bumpersModule().bumperFactory(), WeakReference::new); - List> bumperWeak = ListUtils.format(DI.bumpersModule().bumperWeak(), WeakReference::new); - List> bumperSoft = ListUtils.format(DI.bumpersModule().bumperSoft(), WeakReference::new); - List> bumperStrong = ListUtils.format(DI.bumpersModule().bumperStrong(), WeakReference::new); - - //When - DI.strongToWeak(); - System.gc(); - - // Then - assertEquals(0, nonNullCount(bumperFactory)); - assertEquals(0, nonNullCount(bumperWeak)); - assertEquals(3, nonNullCount(bumperSoft)); - assertEquals(0, nonNullCount(bumperStrong)); - } - - @Test - public void bumpersToWeakTest() { - // Given - CarSwCacheComponent DI = Stone.createComponent(CarSwCacheComponent.class); - List> bumperFactory = ListUtils.format(DI.bumpersModule().bumperFactory(), WeakReference::new); - List> bumperWeak = ListUtils.format(DI.bumpersModule().bumperWeak(), WeakReference::new); - List> bumperSoft = ListUtils.format(DI.bumpersModule().bumperSoft(), WeakReference::new); - List> bumperStrong = ListUtils.format(DI.bumpersModule().bumperStrong(), WeakReference::new); - - //When - DI.bumpersToWeak(); - System.gc(); - - // Then - assertEquals(0, nonNullCount(bumperFactory)); - assertEquals(0, nonNullCount(bumperWeak)); - assertEquals(0, nonNullCount(bumperSoft)); - assertEquals(0, nonNullCount(bumperStrong)); - } - - @Test - public void redBumpersToWeakTest() { - // Given - CarSwCacheComponent DI = Stone.createComponent(CarSwCacheComponent.class); - List> bumperFactory = ListUtils.format(DI.bumpersModule().bumperFactory(), WeakReference::new); - List> bumperWeak = ListUtils.format(DI.bumpersModule().bumperWeak(), WeakReference::new); - List> bumperSoft = ListUtils.format(DI.bumpersModule().bumperSoft(), WeakReference::new); - List> bumperStrong = ListUtils.format(DI.bumpersModule().bumperStrong(), WeakReference::new); - - //When - DI.redBumpersToWeak(); - System.gc(); - - // Then - assertEquals(0, nonNullCount(bumperFactory)); - assertEquals(0, nonNullCount(bumperWeak)); - assertEquals(3, nonNullCount(bumperSoft)); - assertEquals(0, nonNullCount(bumperStrong)); - } - - @Test - public void redBumpersToWeak2Test() { - // Given - CarSwCacheComponent DI = Stone.createComponent(CarSwCacheComponent.class); - List> bumperFactory = ListUtils.format(DI.bumpersModule().bumperFactory(), WeakReference::new); - List> bumperWeak = ListUtils.format(DI.bumpersModule().bumperWeak(), WeakReference::new); - List> bumperSoft = ListUtils.format(DI.bumpersModule().bumperSoft(), WeakReference::new); - List> bumperStrong = ListUtils.format(DI.bumpersModule().bumperStrong(), WeakReference::new); - - //When - DI.redBumpersToWeak2(); - System.gc(); - - // Then - assertEquals(0, nonNullCount(bumperFactory)); - assertEquals(0, nonNullCount(bumperWeak)); - assertEquals(3, nonNullCount(bumperSoft)); - assertEquals(0, nonNullCount(bumperStrong)); - } - - @Test - public void wheelsToWeakTest() { - // Given - CarSwCacheComponent DI = Stone.createComponent(CarSwCacheComponent.class); - List> bumperFactory = ListUtils.format(DI.bumpersModule().bumperFactory(), WeakReference::new); - List> bumperWeak = ListUtils.format(DI.bumpersModule().bumperWeak(), WeakReference::new); - List> bumperSoft = ListUtils.format(DI.bumpersModule().bumperSoft(), WeakReference::new); - List> bumperStrong = ListUtils.format(DI.bumpersModule().bumperStrong(), WeakReference::new); - - - //When - DI.wheelsToWeak(); - System.gc(); - - // Then - assertEquals(0, nonNullCount(bumperFactory)); - assertEquals(0, nonNullCount(bumperWeak)); - assertEquals(3, nonNullCount(bumperSoft)); - assertEquals(3, nonNullCount(bumperStrong)); - } - - @Test - public void nothingToWeakTest() { - // Given - CarSwCacheComponent DI = Stone.createComponent(CarSwCacheComponent.class); - List> bumperFactory = ListUtils.format(DI.bumpersModule().bumperFactory(), WeakReference::new); - List> bumperWeak = ListUtils.format(DI.bumpersModule().bumperWeak(), WeakReference::new); - List> bumperSoft = ListUtils.format(DI.bumpersModule().bumperSoft(), WeakReference::new); - List> bumperStrong = ListUtils.format(DI.bumpersModule().bumperStrong(), WeakReference::new); - - //When - DI.nothingToWeak(); - System.gc(); - - // Then - assertEquals(0, nonNullCount(bumperFactory)); - assertEquals(0, nonNullCount(bumperWeak)); - assertEquals(3, nonNullCount(bumperSoft)); - assertEquals(3, nonNullCount(bumperStrong)); - } - - private int nonNullCount(List> list) { - int count = 0; - for (int i = 0; i < list.size(); i++) { - if (list.get(i) != null && list.get(i).get() != null) count++; - } - return count; - } - -} diff --git a/tests_wraps/src/test/java/com/github/klee0kai/stone/test/car/cachecontrol/swcache/WheelSwitchCacheTests.java b/tests_wraps/src/test/java/com/github/klee0kai/stone/test/car/cachecontrol/swcache/WheelSwitchCacheTests.java deleted file mode 100644 index 3a32976f..00000000 --- a/tests_wraps/src/test/java/com/github/klee0kai/stone/test/car/cachecontrol/swcache/WheelSwitchCacheTests.java +++ /dev/null @@ -1,238 +0,0 @@ -package com.github.klee0kai.stone.test.car.cachecontrol.swcache; - -import com.github.klee0kai.stone.Stone; -import com.github.klee0kai.test.car.di.cachecontrol.swcache.CarSwCacheComponent; -import com.github.klee0kai.test.car.model.Wheel; -import org.junit.jupiter.api.Test; - -import java.lang.ref.WeakReference; - -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertNull; - -public class WheelSwitchCacheTests { - - @Test - public void allWeakTest() { - // Given - CarSwCacheComponent DI = Stone.createComponent(CarSwCacheComponent.class); - WeakReference wheelFactory = DI.wheelsModule().wheelFactory(); - WeakReference wheelWeak = DI.wheelsModule().wheelWeak(); - WeakReference wheelSoft = DI.wheelsModule().wheelSoft(); - WeakReference wheelStrong = DI.wheelsModule().wheelStrong(); - - //When - DI.allWeak(); - System.gc(); - - // Then - assertNull(wheelFactory.get()); - assertNull(wheelWeak.get()); - assertNull(wheelSoft.get()); - assertNull(wheelStrong.get()); - } - - @Test - public void weakToStrongTest() { - // Given - CarSwCacheComponent DI = Stone.createComponent(CarSwCacheComponent.class); - WeakReference wheelFactory = DI.wheelsModule().wheelFactory(); - WeakReference wheelWeak = DI.wheelsModule().wheelWeak(); - WeakReference wheelSoft = DI.wheelsModule().wheelSoft(); - WeakReference wheelStrong = DI.wheelsModule().wheelStrong(); - - //When - DI.weakToStrongFewMillis(); - System.gc(); - - // Then - assertNull(wheelFactory.get()); - assertNotNull(wheelWeak.get()); - assertNotNull(wheelSoft.get()); - assertNotNull(wheelStrong.get()); - } - - @Test - public void weakToStrongAfterFewMillisTest() throws InterruptedException { - // Given - CarSwCacheComponent DI = Stone.createComponent(CarSwCacheComponent.class); - WeakReference wheelFactory = DI.wheelsModule().wheelFactory(); - WeakReference wheelWeak = DI.wheelsModule().wheelWeak(); - WeakReference wheelSoft = DI.wheelsModule().wheelSoft(); - WeakReference wheelStrong = DI.wheelsModule().wheelStrong(); - - //When - DI.weakToStrongFewMillis(); - Thread.sleep(150); - System.gc(); - - - // Then - assertNull(wheelFactory.get()); - assertNull(wheelWeak.get()); - assertNotNull(wheelSoft.get()); - assertNotNull(wheelStrong.get()); - } - - @Test - public void weakToSoftTest() { - // Given - CarSwCacheComponent DI = Stone.createComponent(CarSwCacheComponent.class); - WeakReference wheelFactory = DI.wheelsModule().wheelFactory(); - WeakReference wheelWeak = DI.wheelsModule().wheelWeak(); - WeakReference wheelSoft = DI.wheelsModule().wheelSoft(); - WeakReference wheelStrong = DI.wheelsModule().wheelStrong(); - - //When - DI.weakToSoftFewMillis(); - System.gc(); - - // Then - assertNull(wheelFactory.get()); - assertNotNull(wheelWeak.get()); - assertNotNull(wheelSoft.get()); - assertNotNull(wheelStrong.get()); - } - - @Test - public void weakToSoftAfterFewMillisTest() throws InterruptedException { - // Given - CarSwCacheComponent DI = Stone.createComponent(CarSwCacheComponent.class); - WeakReference wheelFactory = DI.wheelsModule().wheelFactory(); - WeakReference wheelWeak = DI.wheelsModule().wheelWeak(); - WeakReference wheelSoft = DI.wheelsModule().wheelSoft(); - WeakReference wheelStrong = DI.wheelsModule().wheelStrong(); - - //When - DI.weakToSoftFewMillis(); - Thread.sleep(150); - System.gc(); - - - // Then - assertNull(wheelFactory.get()); - assertNull(wheelWeak.get()); - assertNotNull(wheelSoft.get()); - assertNotNull(wheelStrong.get()); - } - - @Test - public void softToWeakTest() { - // Given - CarSwCacheComponent DI = Stone.createComponent(CarSwCacheComponent.class); - WeakReference wheelFactory = DI.wheelsModule().wheelFactory(); - WeakReference wheelWeak = DI.wheelsModule().wheelWeak(); - WeakReference wheelSoft = DI.wheelsModule().wheelSoft(); - WeakReference wheelStrong = DI.wheelsModule().wheelStrong(); - - //When - DI.softToWeak(); - System.gc(); - - // Then - assertNull(wheelFactory.get()); - assertNull(wheelWeak.get()); - assertNull(wheelSoft.get()); - assertNotNull(wheelStrong.get()); - } - - @Test - public void strongToWeakTest() { - // Given - CarSwCacheComponent DI = Stone.createComponent(CarSwCacheComponent.class); - WeakReference wheelFactory = DI.wheelsModule().wheelFactory(); - WeakReference wheelWeak = DI.wheelsModule().wheelWeak(); - WeakReference wheelSoft = DI.wheelsModule().wheelSoft(); - WeakReference wheelStrong = DI.wheelsModule().wheelStrong(); - - //When - DI.strongToWeak(); - System.gc(); - - // Then - assertNull(wheelFactory.get()); - assertNull(wheelWeak.get()); - assertNotNull(wheelSoft.get()); - assertNull(wheelStrong.get()); - } - - @Test - public void wheelsToWeakTest() { - // Given - CarSwCacheComponent DI = Stone.createComponent(CarSwCacheComponent.class); - WeakReference wheelFactory = DI.wheelsModule().wheelFactory(); - WeakReference wheelWeak = DI.wheelsModule().wheelWeak(); - WeakReference wheelSoft = DI.wheelsModule().wheelSoft(); - WeakReference wheelStrong = DI.wheelsModule().wheelStrong(); - - //When - DI.wheelsToWeak(); - System.gc(); - - // Then - assertNull(wheelFactory.get()); - assertNull(wheelWeak.get()); - assertNull(wheelSoft.get()); - assertNull(wheelStrong.get()); - } - - @Test - public void nothinToWeakTest() { - // Given - CarSwCacheComponent DI = Stone.createComponent(CarSwCacheComponent.class); - WeakReference wheelFactory = DI.wheelsModule().wheelFactory(); - WeakReference wheelWeak = DI.wheelsModule().wheelWeak(); - WeakReference wheelSoft = DI.wheelsModule().wheelSoft(); - WeakReference wheelStrong = DI.wheelsModule().wheelStrong(); - - //When - DI.nothingToWeak(); - System.gc(); - - // Then - assertNull(wheelFactory.get()); - assertNull(wheelWeak.get()); - assertNotNull(wheelSoft.get()); - assertNotNull(wheelStrong.get()); - } - - @Test - public void windowsToWeakTest() { - // Given - CarSwCacheComponent DI = Stone.createComponent(CarSwCacheComponent.class); - WeakReference wheelFactory = DI.wheelsModule().wheelFactory(); - WeakReference wheelWeak = DI.wheelsModule().wheelWeak(); - WeakReference wheelSoft = DI.wheelsModule().wheelSoft(); - WeakReference wheelStrong = DI.wheelsModule().wheelStrong(); - - //When - DI.windowsToWeak(); - System.gc(); - - // Then - assertNull(wheelFactory.get()); - assertNull(wheelWeak.get()); - assertNotNull(wheelSoft.get()); - assertNotNull(wheelStrong.get()); - } - - @Test - public void windowAndWheelsToWeak() { - // Given - CarSwCacheComponent DI = Stone.createComponent(CarSwCacheComponent.class); - WeakReference wheelFactory = DI.wheelsModule().wheelFactory(); - WeakReference wheelWeak = DI.wheelsModule().wheelWeak(); - WeakReference wheelSoft = DI.wheelsModule().wheelSoft(); - WeakReference wheelStrong = DI.wheelsModule().wheelStrong(); - - //When - DI.windowsAndWheelsToWeak(); - System.gc(); - - // Then - assertNull(wheelFactory.get()); - assertNull(wheelWeak.get()); - assertNull(wheelSoft.get()); - assertNull(wheelStrong.get()); - } -} diff --git a/tests_wraps/src/test/java/com/github/klee0kai/stone/test/car/cachecontrol/swcache/WindowMappedSwitchCacheTests.java b/tests_wraps/src/test/java/com/github/klee0kai/stone/test/car/cachecontrol/swcache/WindowMappedSwitchCacheTests.java deleted file mode 100644 index 00f6f639..00000000 --- a/tests_wraps/src/test/java/com/github/klee0kai/stone/test/car/cachecontrol/swcache/WindowMappedSwitchCacheTests.java +++ /dev/null @@ -1,250 +0,0 @@ - -package com.github.klee0kai.stone.test.car.cachecontrol.swcache; - -import com.github.klee0kai.stone.Stone; -import com.github.klee0kai.stone._hidden_.types.ListUtils; -import com.github.klee0kai.test.car.di.cachecontrol.swcache.CarSwCacheComponent; -import com.github.klee0kai.test.car.model.Window; -import org.junit.jupiter.api.Test; - -import java.lang.ref.WeakReference; -import java.util.List; - -import static org.junit.jupiter.api.Assertions.assertEquals; - -public class WindowMappedSwitchCacheTests { - - @Test - public void allWeakTest() { - // Given - CarSwCacheComponent DI = Stone.createComponent(CarSwCacheComponent.class); - List> windowsFactory = ListUtils.format(DI.windowsMappedModule().windowFactory("1").get(), WeakReference::new); - List> windowWeak = ListUtils.format(DI.windowsMappedModule().windowWeak("1").get(), WeakReference::new); - List> windowSoft = ListUtils.format(DI.windowsMappedModule().windowSoft("1").get(), WeakReference::new); - List> windowStrong = ListUtils.format(DI.windowsMappedModule().windowStrong("1").get(), WeakReference::new); - - - //When - DI.allWeak(); - System.gc(); - - // Then - assertEquals(0, nonNullCount(windowsFactory)); - assertEquals(0, nonNullCount(windowWeak)); - assertEquals(0, nonNullCount(windowSoft)); - assertEquals(0, nonNullCount(windowStrong)); - } - - @Test - public void weakToStrongTest() { - // Given - CarSwCacheComponent DI = Stone.createComponent(CarSwCacheComponent.class); - List> windowsFactory = ListUtils.format(DI.windowsMappedModule().windowFactory("1").get(), WeakReference::new); - List> windowWeak = ListUtils.format(DI.windowsMappedModule().windowWeak("1").get(), WeakReference::new); - List> windowSoft = ListUtils.format(DI.windowsMappedModule().windowSoft("1").get(), WeakReference::new); - List> windowStrong = ListUtils.format(DI.windowsMappedModule().windowStrong("1").get(), WeakReference::new); - - //When - DI.weakToStrongFewMillis(); - System.gc(); - - // Then - assertEquals(0, nonNullCount(windowsFactory)); - assertEquals(3, nonNullCount(windowWeak)); - assertEquals(3, nonNullCount(windowSoft)); - assertEquals(3, nonNullCount(windowStrong)); - } - - @Test - public void weakToStrongAfterFewMillisTest() throws InterruptedException { - // Given - CarSwCacheComponent DI = Stone.createComponent(CarSwCacheComponent.class); - List> windowsFactory = ListUtils.format(DI.windowsMappedModule().windowFactory("1").get(), WeakReference::new); - List> windowWeak = ListUtils.format(DI.windowsMappedModule().windowWeak("1").get(), WeakReference::new); - List> windowSoft = ListUtils.format(DI.windowsMappedModule().windowSoft("1").get(), WeakReference::new); - List> windowStrong = ListUtils.format(DI.windowsMappedModule().windowStrong("1").get(), WeakReference::new); - - //When - DI.weakToStrongFewMillis(); - Thread.sleep(150); - System.gc(); - - // Then - assertEquals(0, nonNullCount(windowsFactory)); - assertEquals(0, nonNullCount(windowWeak)); - assertEquals(3, nonNullCount(windowSoft)); - assertEquals(3, nonNullCount(windowStrong)); - } - - @Test - public void weakToSoftTest() { - // Given - CarSwCacheComponent DI = Stone.createComponent(CarSwCacheComponent.class); - List> windowsFactory = ListUtils.format(DI.windowsMappedModule().windowFactory("1").get(), WeakReference::new); - List> windowWeak = ListUtils.format(DI.windowsMappedModule().windowWeak("1").get(), WeakReference::new); - List> windowSoft = ListUtils.format(DI.windowsMappedModule().windowSoft("1").get(), WeakReference::new); - List> windowStrong = ListUtils.format(DI.windowsMappedModule().windowStrong("1").get(), WeakReference::new); - - //When - DI.weakToSoftFewMillis(); - System.gc(); - - // Then - assertEquals(0, nonNullCount(windowsFactory)); - assertEquals(3, nonNullCount(windowWeak)); - assertEquals(3, nonNullCount(windowSoft)); - assertEquals(3, nonNullCount(windowStrong)); - } - - @Test - public void weakToSoftAfterFewMillisTest() throws InterruptedException { - // Given - CarSwCacheComponent DI = Stone.createComponent(CarSwCacheComponent.class); - List> windowsFactory = ListUtils.format(DI.windowsMappedModule().windowFactory("1").get(), WeakReference::new); - List> windowWeak = ListUtils.format(DI.windowsMappedModule().windowWeak("1").get(), WeakReference::new); - List> windowSoft = ListUtils.format(DI.windowsMappedModule().windowSoft("1").get(), WeakReference::new); - List> windowStrong = ListUtils.format(DI.windowsMappedModule().windowStrong("1").get(), WeakReference::new); - - //When - DI.weakToSoftFewMillis(); - Thread.sleep(150); - System.gc(); - - // Then - assertEquals(0, nonNullCount(windowsFactory)); - assertEquals(0, nonNullCount(windowWeak)); - assertEquals(3, nonNullCount(windowSoft)); - assertEquals(3, nonNullCount(windowStrong)); - } - - @Test - public void softToWeakTest() { - // Given - CarSwCacheComponent DI = Stone.createComponent(CarSwCacheComponent.class); - List> windowsFactory = ListUtils.format(DI.windowsMappedModule().windowFactory("1").get(), WeakReference::new); - List> windowWeak = ListUtils.format(DI.windowsMappedModule().windowWeak("1").get(), WeakReference::new); - List> windowSoft = ListUtils.format(DI.windowsMappedModule().windowSoft("1").get(), WeakReference::new); - List> windowStrong = ListUtils.format(DI.windowsMappedModule().windowStrong("1").get(), WeakReference::new); - - //When - DI.softToWeak(); - System.gc(); - - // Then - assertEquals(0, nonNullCount(windowsFactory)); - assertEquals(0, nonNullCount(windowWeak)); - assertEquals(0, nonNullCount(windowSoft)); - assertEquals(3, nonNullCount(windowStrong)); - } - - @Test - public void strongToWeakTest() { - // Given - CarSwCacheComponent DI = Stone.createComponent(CarSwCacheComponent.class); - List> windowsFactory = ListUtils.format(DI.windowsMappedModule().windowFactory("1").get(), WeakReference::new); - List> windowWeak = ListUtils.format(DI.windowsMappedModule().windowWeak("1").get(), WeakReference::new); - List> windowSoft = ListUtils.format(DI.windowsMappedModule().windowSoft("1").get(), WeakReference::new); - List> windowStrong = ListUtils.format(DI.windowsMappedModule().windowStrong("1").get(), WeakReference::new); - - //When - DI.strongToWeak(); - System.gc(); - - // Then - assertEquals(0, nonNullCount(windowsFactory)); - assertEquals(0, nonNullCount(windowWeak)); - assertEquals(3, nonNullCount(windowSoft)); - assertEquals(0, nonNullCount(windowStrong)); - } - - @Test - public void windowsToWeakTest() { - // Given - CarSwCacheComponent DI = Stone.createComponent(CarSwCacheComponent.class); - List> windowsFactory = ListUtils.format(DI.windowsMappedModule().windowFactory("1").get(), WeakReference::new); - List> windowWeak = ListUtils.format(DI.windowsMappedModule().windowWeak("1").get(), WeakReference::new); - List> windowSoft = ListUtils.format(DI.windowsMappedModule().windowSoft("1").get(), WeakReference::new); - List> windowStrong = ListUtils.format(DI.windowsMappedModule().windowStrong("1").get(), WeakReference::new); - - //When - DI.windowsToWeak(); - System.gc(); - - // Then - assertEquals(0, nonNullCount(windowsFactory)); - assertEquals(0, nonNullCount(windowWeak)); - assertEquals(0, nonNullCount(windowSoft)); - assertEquals(0, nonNullCount(windowStrong)); - } - - @Test - public void windowsAndWheelsToWeakTest() { - // Given - CarSwCacheComponent DI = Stone.createComponent(CarSwCacheComponent.class); - List> windowsFactory = ListUtils.format(DI.windowsMappedModule().windowFactory("1").get(), WeakReference::new); - List> windowWeak = ListUtils.format(DI.windowsMappedModule().windowWeak("1").get(), WeakReference::new); - List> windowSoft = ListUtils.format(DI.windowsMappedModule().windowSoft("1").get(), WeakReference::new); - List> windowStrong = ListUtils.format(DI.windowsMappedModule().windowStrong("1").get(), WeakReference::new); - - //When - DI.windowsAndWheelsToWeak(); - System.gc(); - - // Then - assertEquals(0, nonNullCount(windowsFactory)); - assertEquals(0, nonNullCount(windowWeak)); - assertEquals(0, nonNullCount(windowSoft)); - assertEquals(0, nonNullCount(windowStrong)); - } - - @Test - public void wheelsToWeakTest() { - // Given - CarSwCacheComponent DI = Stone.createComponent(CarSwCacheComponent.class); - List> windowsFactory = ListUtils.format(DI.windowsMappedModule().windowFactory("1").get(), WeakReference::new); - List> windowWeak = ListUtils.format(DI.windowsMappedModule().windowWeak("1").get(), WeakReference::new); - List> windowSoft = ListUtils.format(DI.windowsMappedModule().windowSoft("1").get(), WeakReference::new); - List> windowStrong = ListUtils.format(DI.windowsMappedModule().windowStrong("1").get(), WeakReference::new); - - - //When - DI.wheelsToWeak(); - System.gc(); - - // Then - assertEquals(0, nonNullCount(windowsFactory)); - assertEquals(0, nonNullCount(windowWeak)); - assertEquals(3, nonNullCount(windowSoft)); - assertEquals(3, nonNullCount(windowStrong)); - } - - @Test - public void nothingToWeakTest() { - // Given - CarSwCacheComponent DI = Stone.createComponent(CarSwCacheComponent.class); - List> windowsFactory = ListUtils.format(DI.windowsMappedModule().windowFactory("1").get(), WeakReference::new); - List> windowWeak = ListUtils.format(DI.windowsMappedModule().windowWeak("1").get(), WeakReference::new); - List> windowSoft = ListUtils.format(DI.windowsMappedModule().windowSoft("1").get(), WeakReference::new); - List> windowStrong = ListUtils.format(DI.windowsMappedModule().windowStrong("1").get(), WeakReference::new); - - //When - DI.nothingToWeak(); - System.gc(); - - // Then - assertEquals(0, nonNullCount(windowsFactory)); - assertEquals(0, nonNullCount(windowWeak)); - assertEquals(3, nonNullCount(windowSoft)); - assertEquals(3, nonNullCount(windowStrong)); - } - - private int nonNullCount(List> list) { - int count = 0; - for (int i = 0; i < list.size(); i++) { - if (list.get(i) != null && list.get(i).get() != null) count++; - } - return count; - } - - -} diff --git a/tests_wraps/src/test/java/com/github/klee0kai/stone/test/car/cachecontrol/swcache/WindowMultiMappedSwitchCacheTests.java b/tests_wraps/src/test/java/com/github/klee0kai/stone/test/car/cachecontrol/swcache/WindowMultiMappedSwitchCacheTests.java deleted file mode 100644 index 02e5b806..00000000 --- a/tests_wraps/src/test/java/com/github/klee0kai/stone/test/car/cachecontrol/swcache/WindowMultiMappedSwitchCacheTests.java +++ /dev/null @@ -1,248 +0,0 @@ -package com.github.klee0kai.stone.test.car.cachecontrol.swcache; - -import com.github.klee0kai.stone.Stone; -import com.github.klee0kai.stone._hidden_.types.ListUtils; -import com.github.klee0kai.test.car.di.cachecontrol.swcache.CarSwCacheComponent; -import com.github.klee0kai.test.car.model.Window; -import org.junit.jupiter.api.Test; - -import java.lang.ref.WeakReference; -import java.util.List; - -import static org.junit.jupiter.api.Assertions.assertEquals; - -public class WindowMultiMappedSwitchCacheTests { - - @Test - public void allWeakTest() { - // Given - CarSwCacheComponent DI = Stone.createComponent(CarSwCacheComponent.class); - List> windowsFactory = ListUtils.format(DI.windowsMultiMappedModule().windowFactory(1, "1").get(), WeakReference::new); - List> windowWeak = ListUtils.format(DI.windowsMultiMappedModule().windowWeak(1, "1").get(), WeakReference::new); - List> windowSoft = ListUtils.format(DI.windowsMultiMappedModule().windowSoft(1, "1").get(), WeakReference::new); - List> windowStrong = ListUtils.format(DI.windowsMultiMappedModule().windowStrong(1, "1").get(), WeakReference::new); - - - //When - DI.allWeak(); - System.gc(); - - // Then - assertEquals(0, nonNullCount(windowsFactory)); - assertEquals(0, nonNullCount(windowWeak)); - assertEquals(0, nonNullCount(windowSoft)); - assertEquals(0, nonNullCount(windowStrong)); - } - - @Test - public void weakToStrongTest() { - // Given - CarSwCacheComponent DI = Stone.createComponent(CarSwCacheComponent.class); - List> windowsFactory = ListUtils.format(DI.windowsMultiMappedModule().windowFactory(1, "1").get(), WeakReference::new); - List> windowWeak = ListUtils.format(DI.windowsMultiMappedModule().windowWeak(1, "1").get(), WeakReference::new); - List> windowSoft = ListUtils.format(DI.windowsMultiMappedModule().windowSoft(1, "1").get(), WeakReference::new); - List> windowStrong = ListUtils.format(DI.windowsMultiMappedModule().windowStrong(1, "1").get(), WeakReference::new); - - //When - DI.weakToStrongFewMillis(); - System.gc(); - - // Then - assertEquals(0, nonNullCount(windowsFactory)); - assertEquals(3, nonNullCount(windowWeak)); - assertEquals(3, nonNullCount(windowSoft)); - assertEquals(3, nonNullCount(windowStrong)); - } - - @Test - public void weakToStrongAfterFewMillisTest() throws InterruptedException { - // Given - CarSwCacheComponent DI = Stone.createComponent(CarSwCacheComponent.class); - List> windowsFactory = ListUtils.format(DI.windowsMultiMappedModule().windowFactory(1, "1").get(), WeakReference::new); - List> windowWeak = ListUtils.format(DI.windowsMultiMappedModule().windowWeak(1, "1").get(), WeakReference::new); - List> windowSoft = ListUtils.format(DI.windowsMultiMappedModule().windowSoft(1, "1").get(), WeakReference::new); - List> windowStrong = ListUtils.format(DI.windowsMultiMappedModule().windowStrong(1, "1").get(), WeakReference::new); - - //When - DI.weakToStrongFewMillis(); - Thread.sleep(150); - System.gc(); - - // Then - assertEquals(0, nonNullCount(windowsFactory)); - assertEquals(0, nonNullCount(windowWeak)); - assertEquals(3, nonNullCount(windowSoft)); - assertEquals(3, nonNullCount(windowStrong)); - } - - @Test - public void weakToSoftTest() { - // Given - CarSwCacheComponent DI = Stone.createComponent(CarSwCacheComponent.class); - List> windowsFactory = ListUtils.format(DI.windowsMultiMappedModule().windowFactory(1, "1").get(), WeakReference::new); - List> windowWeak = ListUtils.format(DI.windowsMultiMappedModule().windowWeak(1, "1").get(), WeakReference::new); - List> windowSoft = ListUtils.format(DI.windowsMultiMappedModule().windowSoft(1, "1").get(), WeakReference::new); - List> windowStrong = ListUtils.format(DI.windowsMultiMappedModule().windowStrong(1, "1").get(), WeakReference::new); - - //When - DI.weakToSoftFewMillis(); - System.gc(); - - // Then - assertEquals(0, nonNullCount(windowsFactory)); - assertEquals(3, nonNullCount(windowWeak)); - assertEquals(3, nonNullCount(windowSoft)); - assertEquals(3, nonNullCount(windowStrong)); - } - - @Test - public void weakToSoftAfterFewMillisTest() throws InterruptedException { - // Given - CarSwCacheComponent DI = Stone.createComponent(CarSwCacheComponent.class); - List> windowsFactory = ListUtils.format(DI.windowsMultiMappedModule().windowFactory(1, "1").get(), WeakReference::new); - List> windowWeak = ListUtils.format(DI.windowsMultiMappedModule().windowWeak(1, "1").get(), WeakReference::new); - List> windowSoft = ListUtils.format(DI.windowsMultiMappedModule().windowSoft(1, "1").get(), WeakReference::new); - List> windowStrong = ListUtils.format(DI.windowsMultiMappedModule().windowStrong(1, "1").get(), WeakReference::new); - - //When - DI.weakToSoftFewMillis(); - Thread.sleep(150); - System.gc(); - - // Then - assertEquals(0, nonNullCount(windowsFactory)); - assertEquals(0, nonNullCount(windowWeak)); - assertEquals(3, nonNullCount(windowSoft)); - assertEquals(3, nonNullCount(windowStrong)); - } - - @Test - public void softToWeakTest() { - // Given - CarSwCacheComponent DI = Stone.createComponent(CarSwCacheComponent.class); - List> windowsFactory = ListUtils.format(DI.windowsMultiMappedModule().windowFactory(1, "1").get(), WeakReference::new); - List> windowWeak = ListUtils.format(DI.windowsMultiMappedModule().windowWeak(1, "1").get(), WeakReference::new); - List> windowSoft = ListUtils.format(DI.windowsMultiMappedModule().windowSoft(1, "1").get(), WeakReference::new); - List> windowStrong = ListUtils.format(DI.windowsMultiMappedModule().windowStrong(1, "1").get(), WeakReference::new); - - //When - DI.softToWeak(); - System.gc(); - - // Then - assertEquals(0, nonNullCount(windowsFactory)); - assertEquals(0, nonNullCount(windowWeak)); - assertEquals(0, nonNullCount(windowSoft)); - assertEquals(3, nonNullCount(windowStrong)); - } - - @Test - public void strongToWeakTest() { - // Given - CarSwCacheComponent DI = Stone.createComponent(CarSwCacheComponent.class); - List> windowsFactory = ListUtils.format(DI.windowsMultiMappedModule().windowFactory(1, "1").get(), WeakReference::new); - List> windowWeak = ListUtils.format(DI.windowsMultiMappedModule().windowWeak(1, "1").get(), WeakReference::new); - List> windowSoft = ListUtils.format(DI.windowsMultiMappedModule().windowSoft(1, "1").get(), WeakReference::new); - List> windowStrong = ListUtils.format(DI.windowsMultiMappedModule().windowStrong(1, "1").get(), WeakReference::new); - - //When - DI.strongToWeak(); - System.gc(); - - // Then - assertEquals(0, nonNullCount(windowsFactory)); - assertEquals(0, nonNullCount(windowWeak)); - assertEquals(3, nonNullCount(windowSoft)); - assertEquals(0, nonNullCount(windowStrong)); - } - - @Test - public void windowsToWeakTest() { - // Given - CarSwCacheComponent DI = Stone.createComponent(CarSwCacheComponent.class); - List> windowsFactory = ListUtils.format(DI.windowsMultiMappedModule().windowFactory(1, "1").get(), WeakReference::new); - List> windowWeak = ListUtils.format(DI.windowsMultiMappedModule().windowWeak(1, "1").get(), WeakReference::new); - List> windowSoft = ListUtils.format(DI.windowsMultiMappedModule().windowSoft(1, "1").get(), WeakReference::new); - List> windowStrong = ListUtils.format(DI.windowsMultiMappedModule().windowStrong(1, "1").get(), WeakReference::new); - - //When - DI.windowsToWeak(); - System.gc(); - - // Then - assertEquals(0, nonNullCount(windowsFactory)); - assertEquals(0, nonNullCount(windowWeak)); - assertEquals(0, nonNullCount(windowSoft)); - assertEquals(0, nonNullCount(windowStrong)); - } - - @Test - public void windowAndWheelsToWeakTest() { - // Given - CarSwCacheComponent DI = Stone.createComponent(CarSwCacheComponent.class); - List> windowsFactory = ListUtils.format(DI.windowsMultiMappedModule().windowFactory(1, "1").get(), WeakReference::new); - List> windowWeak = ListUtils.format(DI.windowsMultiMappedModule().windowWeak(1, "1").get(), WeakReference::new); - List> windowSoft = ListUtils.format(DI.windowsMultiMappedModule().windowSoft(1, "1").get(), WeakReference::new); - List> windowStrong = ListUtils.format(DI.windowsMultiMappedModule().windowStrong(1, "1").get(), WeakReference::new); - - //When - DI.windowsAndWheelsToWeak(); - System.gc(); - - // Then - assertEquals(0, nonNullCount(windowsFactory)); - assertEquals(0, nonNullCount(windowWeak)); - assertEquals(0, nonNullCount(windowSoft)); - assertEquals(0, nonNullCount(windowStrong)); - } - - @Test - public void wheelToWeakTest() { - // Given - CarSwCacheComponent DI = Stone.createComponent(CarSwCacheComponent.class); - List> windowsFactory = ListUtils.format(DI.windowsMultiMappedModule().windowFactory(1, "1").get(), WeakReference::new); - List> windowWeak = ListUtils.format(DI.windowsMultiMappedModule().windowWeak(1, "1").get(), WeakReference::new); - List> windowSoft = ListUtils.format(DI.windowsMultiMappedModule().windowSoft(1, "1").get(), WeakReference::new); - List> windowStrong = ListUtils.format(DI.windowsMultiMappedModule().windowStrong(1, "1").get(), WeakReference::new); - - - //When - DI.wheelsToWeak(); - System.gc(); - - // Then - assertEquals(0, nonNullCount(windowsFactory)); - assertEquals(0, nonNullCount(windowWeak)); - assertEquals(3, nonNullCount(windowSoft)); - assertEquals(3, nonNullCount(windowStrong)); - } - - @Test - public void weakNothingTest() { - // Given - CarSwCacheComponent DI = Stone.createComponent(CarSwCacheComponent.class); - List> windowsFactory = ListUtils.format(DI.windowsMultiMappedModule().windowFactory(1, "1").get(), WeakReference::new); - List> windowWeak = ListUtils.format(DI.windowsMultiMappedModule().windowWeak(1, "1").get(), WeakReference::new); - List> windowSoft = ListUtils.format(DI.windowsMultiMappedModule().windowSoft(1, "1").get(), WeakReference::new); - List> windowStrong = ListUtils.format(DI.windowsMultiMappedModule().windowStrong(1, "1").get(), WeakReference::new); - - //When - DI.nothingToWeak(); - System.gc(); - - // Then - assertEquals(0, nonNullCount(windowsFactory)); - assertEquals(0, nonNullCount(windowWeak)); - assertEquals(3, nonNullCount(windowSoft)); - assertEquals(3, nonNullCount(windowStrong)); - } - - private int nonNullCount(List> list) { - int count = 0; - for (int i = 0; i < list.size(); i++) { - if (list.get(i) != null && list.get(i).get() != null) count++; - } - return count; - } - -} diff --git a/tests_wraps/src/test/java/com/github/klee0kai/stone/test/car/cachecontrol/swcache/WindowSwitchCacheTests.java b/tests_wraps/src/test/java/com/github/klee0kai/stone/test/car/cachecontrol/swcache/WindowSwitchCacheTests.java deleted file mode 100644 index 12ee9036..00000000 --- a/tests_wraps/src/test/java/com/github/klee0kai/stone/test/car/cachecontrol/swcache/WindowSwitchCacheTests.java +++ /dev/null @@ -1,208 +0,0 @@ -package com.github.klee0kai.stone.test.car.cachecontrol.swcache; - -import com.github.klee0kai.stone.Stone; -import com.github.klee0kai.stone._hidden_.types.ListUtils; -import com.github.klee0kai.test.car.di.cachecontrol.swcache.CarSwCacheComponent; -import com.github.klee0kai.test.car.model.Window; -import org.junit.jupiter.api.Test; - -import java.lang.ref.WeakReference; -import java.util.List; - -import static org.junit.jupiter.api.Assertions.assertEquals; - -public class WindowSwitchCacheTests { - - @Test - public void allWeakTest() { - // Given - CarSwCacheComponent DI = Stone.createComponent(CarSwCacheComponent.class); - List> windowsFactory = ListUtils.format(DI.windowsModule().windowFactory().get(), WeakReference::new); - List> windowWeak = ListUtils.format(DI.windowsModule().windowWeak().get(), WeakReference::new); - List> windowSoft = ListUtils.format(DI.windowsModule().windowSoft().get(), WeakReference::new); - List> windowStrong = ListUtils.format(DI.windowsModule().windowStrong().get(), WeakReference::new); - - - //When - DI.allWeak(); - System.gc(); - - // Then - assertEquals(0, nonNullCount(windowsFactory)); - assertEquals(0, nonNullCount(windowWeak)); - assertEquals(0, nonNullCount(windowSoft)); - assertEquals(0, nonNullCount(windowStrong)); - } - - @Test - public void weakToStrongTest() { - // Given - CarSwCacheComponent DI = Stone.createComponent(CarSwCacheComponent.class); - List> windowsFactory = ListUtils.format(DI.windowsModule().windowFactory().get(), WeakReference::new); - List> windowWeak = ListUtils.format(DI.windowsModule().windowWeak().get(), WeakReference::new); - List> windowSoft = ListUtils.format(DI.windowsModule().windowSoft().get(), WeakReference::new); - List> windowStrong = ListUtils.format(DI.windowsModule().windowStrong().get(), WeakReference::new); - - //When - DI.weakToStrongFewMillis(); - System.gc(); - - // Then - assertEquals(0, nonNullCount(windowsFactory)); - assertEquals(3, nonNullCount(windowWeak)); - assertEquals(3, nonNullCount(windowSoft)); - assertEquals(3, nonNullCount(windowStrong)); - } - - @Test - public void weakToStrongAfterFewMillisTest() throws InterruptedException { - // Given - CarSwCacheComponent DI = Stone.createComponent(CarSwCacheComponent.class); - List> windowsFactory = ListUtils.format(DI.windowsModule().windowFactory().get(), WeakReference::new); - List> windowWeak = ListUtils.format(DI.windowsModule().windowWeak().get(), WeakReference::new); - List> windowSoft = ListUtils.format(DI.windowsModule().windowSoft().get(), WeakReference::new); - List> windowStrong = ListUtils.format(DI.windowsModule().windowStrong().get(), WeakReference::new); - - //When - DI.weakToStrongFewMillis(); - Thread.sleep(150); - System.gc(); - - // Then - assertEquals(0, nonNullCount(windowsFactory)); - assertEquals(0, nonNullCount(windowWeak)); - assertEquals(3, nonNullCount(windowSoft)); - assertEquals(3, nonNullCount(windowStrong)); - } - - @Test - public void softToWeakTest() { - // Given - CarSwCacheComponent DI = Stone.createComponent(CarSwCacheComponent.class); - List> windowsFactory = ListUtils.format(DI.windowsModule().windowFactory().get(), WeakReference::new); - List> windowWeak = ListUtils.format(DI.windowsModule().windowWeak().get(), WeakReference::new); - List> windowSoft = ListUtils.format(DI.windowsModule().windowSoft().get(), WeakReference::new); - List> windowStrong = ListUtils.format(DI.windowsModule().windowStrong().get(), WeakReference::new); - - //When - DI.softToWeak(); - System.gc(); - - // Then - assertEquals(0, nonNullCount(windowsFactory)); - assertEquals(0, nonNullCount(windowWeak)); - assertEquals(0, nonNullCount(windowSoft)); - assertEquals(3, nonNullCount(windowStrong)); - } - - @Test - public void strongToWeakTest() { - // Given - CarSwCacheComponent DI = Stone.createComponent(CarSwCacheComponent.class); - List> windowsFactory = ListUtils.format(DI.windowsModule().windowFactory().get(), WeakReference::new); - List> windowWeak = ListUtils.format(DI.windowsModule().windowWeak().get(), WeakReference::new); - List> windowSoft = ListUtils.format(DI.windowsModule().windowSoft().get(), WeakReference::new); - List> windowStrong = ListUtils.format(DI.windowsModule().windowStrong().get(), WeakReference::new); - - //When - DI.strongToWeak(); - System.gc(); - - // Then - assertEquals(0, nonNullCount(windowsFactory)); - assertEquals(0, nonNullCount(windowWeak)); - assertEquals(3, nonNullCount(windowSoft)); - assertEquals(0, nonNullCount(windowStrong)); - } - - @Test - public void windowsToWeakTest() { - // Given - CarSwCacheComponent DI = Stone.createComponent(CarSwCacheComponent.class); - List> windowsFactory = ListUtils.format(DI.windowsModule().windowFactory().get(), WeakReference::new); - List> windowWeak = ListUtils.format(DI.windowsModule().windowWeak().get(), WeakReference::new); - List> windowSoft = ListUtils.format(DI.windowsModule().windowSoft().get(), WeakReference::new); - List> windowStrong = ListUtils.format(DI.windowsModule().windowStrong().get(), WeakReference::new); - - //When - DI.windowsToWeak(); - System.gc(); - - // Then - assertEquals(0, nonNullCount(windowsFactory)); - assertEquals(0, nonNullCount(windowWeak)); - assertEquals(0, nonNullCount(windowSoft)); - assertEquals(0, nonNullCount(windowStrong)); - } - - @Test - public void windowsAndWheelsToWeakTest() { - // Given - CarSwCacheComponent DI = Stone.createComponent(CarSwCacheComponent.class); - List> windowsFactory = ListUtils.format(DI.windowsModule().windowFactory().get(), WeakReference::new); - List> windowWeak = ListUtils.format(DI.windowsModule().windowWeak().get(), WeakReference::new); - List> windowSoft = ListUtils.format(DI.windowsModule().windowSoft().get(), WeakReference::new); - List> windowStrong = ListUtils.format(DI.windowsModule().windowStrong().get(), WeakReference::new); - - //When - DI.windowsAndWheelsToWeak(); - System.gc(); - - // Then - assertEquals(0, nonNullCount(windowsFactory)); - assertEquals(0, nonNullCount(windowWeak)); - assertEquals(0, nonNullCount(windowSoft)); - assertEquals(0, nonNullCount(windowStrong)); - } - - @Test - public void wheelsToWeakTest() { - // Given - CarSwCacheComponent DI = Stone.createComponent(CarSwCacheComponent.class); - List> windowsFactory = ListUtils.format(DI.windowsModule().windowFactory().get(), WeakReference::new); - List> windowWeak = ListUtils.format(DI.windowsModule().windowWeak().get(), WeakReference::new); - List> windowSoft = ListUtils.format(DI.windowsModule().windowSoft().get(), WeakReference::new); - List> windowStrong = ListUtils.format(DI.windowsModule().windowStrong().get(), WeakReference::new); - - - //When - DI.wheelsToWeak(); - System.gc(); - - // Then - assertEquals(0, nonNullCount(windowsFactory)); - assertEquals(0, nonNullCount(windowWeak)); - assertEquals(3, nonNullCount(windowSoft)); - assertEquals(3, nonNullCount(windowStrong)); - } - - @Test - public void weakNothingTest() { - // Given - CarSwCacheComponent DI = Stone.createComponent(CarSwCacheComponent.class); - List> windowsFactory = ListUtils.format(DI.windowsModule().windowFactory().get(), WeakReference::new); - List> windowWeak = ListUtils.format(DI.windowsModule().windowWeak().get(), WeakReference::new); - List> windowSoft = ListUtils.format(DI.windowsModule().windowSoft().get(), WeakReference::new); - List> windowStrong = ListUtils.format(DI.windowsModule().windowStrong().get(), WeakReference::new); - - //When - DI.nothingToWeak(); - System.gc(); - - // Then - assertEquals(0, nonNullCount(windowsFactory)); - assertEquals(0, nonNullCount(windowWeak)); - assertEquals(3, nonNullCount(windowSoft)); - assertEquals(3, nonNullCount(windowStrong)); - } - - private int nonNullCount(List> list) { - int count = 0; - for (int i = 0; i < list.size(); i++) { - if (list.get(i) != null && list.get(i).get() != null) count++; - } - return count; - } - - -} diff --git a/tests_wraps/src/test/java/com/github/klee0kai/stone/test/car/inject/CarInjectMethodTests.java b/tests_wraps/src/test/java/com/github/klee0kai/stone/test/car/inject/CarInjectMethodTests.java deleted file mode 100644 index fe4c7b3c..00000000 --- a/tests_wraps/src/test/java/com/github/klee0kai/stone/test/car/inject/CarInjectMethodTests.java +++ /dev/null @@ -1,152 +0,0 @@ -package com.github.klee0kai.stone.test.car.inject; - -import com.github.klee0kai.stone.Stone; -import com.github.klee0kai.stone._hidden_.types.ListUtils; -import com.github.klee0kai.test.car.di.inject.CarInjectComponent; -import com.github.klee0kai.test.car.model.*; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; - -import java.util.HashSet; -import java.util.Set; - -import static org.junit.jupiter.api.Assertions.*; - -public class CarInjectMethodTests { - - @BeforeEach - public void init() { - Bumper.createCount = 0; - Window.createCount = 0; - Wheel.createCount = 0; - Car.createCount = 0; - } - - @Test - void carInjectTest() { - //Given - CarInjectComponent DI = Stone.createComponent(CarInjectComponent.class); - - //When - CarInject carInject = new CarInject(); - DI.inject(carInject); - - // Then - assertEquals(2, Bumper.createCount, "Bumpers created from list"); - assertNotNull(carInject.bumperFromMethod.uuid); - assertNotNull(carInject.wheelFromMethod.uuid); - assertNotNull(carInject.windowFromMethod.uuid); - } - - @Test - void carInjectReusableTest() { - //Given - CarInjectComponent DI = Stone.createComponent(CarInjectComponent.class); - - //When - CarInject carInject1 = new CarInject(); - CarInject carInject2 = new CarInject(); - DI.inject(carInject1); - DI.inject(carInject2); - - - // Then - assertEquals(2, Bumper.createCount, "Bumpers created from list. And reused"); - assertEquals(carInject1.bumperFromMethod.uuid, carInject2.bumperFromMethod.uuid, "should cache"); - assertEquals(carInject1.wheelFromMethod.uuid, carInject2.wheelFromMethod.uuid, "should cache "); - assertNotEquals(carInject1.windowFromMethod.uuid, carInject2.windowFromMethod.uuid, "provide via Provider. No caching"); - } - - - @Test - void carInjectListTest() { - //Given - CarInjectComponent DI = Stone.createComponent(CarInjectComponent.class); - - //When - CarInjectLists carInject = new CarInjectLists(); - DI.inject(carInject); - - // Then - assertEquals(2, Bumper.createCount); - assertEquals(5, Wheel.createCount); - assertEquals(8, Window.createCount, "Windows created for fields and method"); - assertEquals(2, carInject.bumpersMethodFrom.size()); - assertEquals(5, carInject.wheelsMethodFrom.size()); - assertEquals(4, carInject.windowsMethodFrom.size()); - for (Bumper b : carInject.bumpersMethodFrom) assertNotNull(b.uuid); - Set bumperUids = new HashSet<>(ListUtils.format(carInject.bumpersMethodFrom, it -> it.uuid)); - assertEquals(2, bumperUids.size()); - for (Wheel w : carInject.wheelsMethodFrom) assertNotNull(w.uuid); - Set wheelsUid = new HashSet<>(ListUtils.format(carInject.wheels, it -> it.uuid)); - assertEquals(5, wheelsUid.size()); - for (Window w : carInject.windowsMethodFrom) assertNotNull(w.uuid); - Set windowUids = new HashSet<>(ListUtils.format(carInject.windows, it -> it.uuid)); - assertEquals(4, windowUids.size()); - } - - @Test - void carInjectListReusableTest() { - //Given - CarInjectComponent DI = Stone.createComponent(CarInjectComponent.class); - - //When - CarInjectLists carInject1 = new CarInjectLists(); - CarInjectLists carInject2 = new CarInjectLists(); - DI.inject(carInject1); - DI.inject(carInject2); - - // Then - assertEquals(2, carInject1.bumpersMethodFrom.size()); - assertEquals(5, carInject1.wheelsMethodFrom.size()); - assertEquals(4, carInject1.windowsMethodFrom.size()); - for (int i = 0; i < 2; i++) - assertEquals(carInject1.bumpersMethodFrom.get(i).uuid, carInject2.bumpersMethodFrom.get(i).uuid); - for (int i = 0; i < 2; i++) - assertEquals(carInject1.wheelsMethodFrom.get(i).uuid, carInject2.wheelsMethodFrom.get(i).uuid); - Set windowUids = new HashSet<>(); - for (int i = 0; i < 4; i++) windowUids.add(carInject1.windowsMethodFrom.get(i).uuid); - for (int i = 0; i < 4; i++) windowUids.add(carInject2.windowsMethodFrom.get(i).uuid); - assertEquals(8, windowUids.size()); - } - - - @Test - void carInjectProviderTest() { - //Given - CarInjectComponent DI = Stone.createComponent(CarInjectComponent.class); - - //When - CarInjectProvider carInject = new CarInjectProvider(); - DI.inject(carInject); - - // Then - assertEquals(0, Bumper.createCount, "Provide non used"); - assertNotNull(carInject.bumperFromMethod.get().uuid); - assertNotNull(carInject.wheelFromMethod.get().uuid); - assertNotNull(carInject.windowFromMethod.get().getValue().uuid); - assertEquals(2, Bumper.createCount, "Bumpers created from list"); - } - - - @Test - void carInjectProvideReusableTest() { - //Given - CarInjectComponent DI = Stone.createComponent(CarInjectComponent.class); - - //When - CarInjectProvider carInject1 = new CarInjectProvider(); - CarInjectProvider carInject2 = new CarInjectProvider(); - DI.inject(carInject1); - DI.inject(carInject2); - - - // Then - assertEquals(0, Bumper.createCount, "Provider non used"); - assertEquals(carInject1.bumperFromMethod.get().uuid, carInject2.bumperFromMethod.get().uuid, "should cache"); - assertEquals(carInject1.wheelFromMethod.get().uuid, carInject2.wheelFromMethod.get().uuid, "should cache "); - assertNotEquals(carInject1.windowFromMethod.get().getValue().uuid, carInject2.windowFromMethod.get().getValue().uuid, "provide via Provider. No caching"); - assertEquals(2, Bumper.createCount, "Bumpers created from list. And reused"); - } - -} diff --git a/tests_wraps/src/test/java/com/github/klee0kai/stone/test/car/inject/CarInjectMixedTests.java b/tests_wraps/src/test/java/com/github/klee0kai/stone/test/car/inject/CarInjectMixedTests.java deleted file mode 100644 index 01f7b6d3..00000000 --- a/tests_wraps/src/test/java/com/github/klee0kai/stone/test/car/inject/CarInjectMixedTests.java +++ /dev/null @@ -1,89 +0,0 @@ -package com.github.klee0kai.stone.test.car.inject; - -import com.github.klee0kai.stone.Stone; -import com.github.klee0kai.test.car.di.inject.CarInjectComponent; -import com.github.klee0kai.test.car.model.*; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; - -import java.util.HashSet; -import java.util.Set; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotEquals; - -public class CarInjectMixedTests { - - @BeforeEach - public void init() { - Bumper.createCount = 0; - Window.createCount = 0; - Wheel.createCount = 0; - Car.createCount = 0; - } - - @Test - void carInjectReusableTest() { - //Given - CarInjectComponent DI = Stone.createComponent(CarInjectComponent.class); - - //When - CarInject carInject1 = new CarInject(); - CarInject carInject2 = new CarInject(); - DI.inject(carInject1); - DI.inject(carInject2); - - - // Then - assertEquals(2, Bumper.createCount, "Bumpers created from list. And reused"); - assertEquals(carInject1.bumperFromMethod.uuid, carInject2.bumper.uuid, "should cache"); - assertEquals(carInject1.wheelFromMethod.uuid, carInject2.wheel.uuid, "should cache "); - assertNotEquals(carInject1.windowFromMethod.uuid, carInject2.window.uuid, "provide via Provider. No caching"); - } - - - @Test - void carInjectListReusableTest() { - //Given - CarInjectComponent DI = Stone.createComponent(CarInjectComponent.class); - - //When - CarInjectLists carInject1 = new CarInjectLists(); - CarInjectLists carInject2 = new CarInjectLists(); - DI.inject(carInject1); - DI.inject(carInject2); - - // Then - assertEquals(2, carInject1.bumpers.size()); - assertEquals(5, carInject1.wheels.size()); - assertEquals(4, carInject1.windows.size()); - for (int i = 0; i < 2; i++) assertEquals(carInject1.bumpersMethodFrom.get(i).uuid, carInject2.bumpers.get(i).uuid); - for (int i = 0; i < 2; i++) assertEquals(carInject1.wheelsMethodFrom.get(i).uuid, carInject2.wheels.get(i).uuid); - Set windowUids = new HashSet<>(); - for (int i = 0; i < 4; i++) windowUids.add(carInject1.windowsMethodFrom.get(i).uuid); - for (int i = 0; i < 4; i++) windowUids.add(carInject2.windows.get(i).uuid); - assertEquals(8, windowUids.size()); - } - - - @Test - void carInjectProvideReusableTest() { - //Given - CarInjectComponent DI = Stone.createComponent(CarInjectComponent.class); - - //When - CarInjectProvider carInject1 = new CarInjectProvider(); - CarInjectProvider carInject2 = new CarInjectProvider(); - DI.inject(carInject1); - DI.inject(carInject2); - - - // Then - assertEquals(0, Bumper.createCount, "Provider non used"); - assertEquals(carInject1.bumperFromMethod.get().uuid, carInject2.bumper.get().uuid, "should cache"); - assertEquals(carInject1.wheelFromMethod.get().uuid, carInject2.wheel.get().uuid, "should cache "); - assertNotEquals(carInject1.windowFromMethod.get().getValue().uuid, carInject2.window.get().getValue().uuid, "provide via Provider. No caching"); - assertEquals(2, Bumper.createCount, "Bumpers created from list. And reused"); - } - -} diff --git a/tests_wraps/src/test/java/com/github/klee0kai/stone/test/car/inject/CarInjectTests.java b/tests_wraps/src/test/java/com/github/klee0kai/stone/test/car/inject/CarInjectTests.java deleted file mode 100644 index 3c316272..00000000 --- a/tests_wraps/src/test/java/com/github/klee0kai/stone/test/car/inject/CarInjectTests.java +++ /dev/null @@ -1,150 +0,0 @@ -package com.github.klee0kai.stone.test.car.inject; - -import com.github.klee0kai.stone.Stone; -import com.github.klee0kai.stone._hidden_.types.ListUtils; -import com.github.klee0kai.test.car.di.inject.CarInjectComponent; -import com.github.klee0kai.test.car.model.*; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; - -import java.util.HashSet; -import java.util.Set; - -import static org.junit.jupiter.api.Assertions.*; - -public class CarInjectTests { - - @BeforeEach - public void init() { - Bumper.createCount = 0; - Window.createCount = 0; - Wheel.createCount = 0; - Car.createCount = 0; - } - - @Test - void carInjectTest() { - //Given - CarInjectComponent DI = Stone.createComponent(CarInjectComponent.class); - - //When - CarInject carInject = new CarInject(); - DI.inject(carInject); - - // Then - assertEquals(2, Bumper.createCount, "Bumpers created from list"); - assertNotNull(carInject.bumper.uuid); - assertNotNull(carInject.wheel.uuid); - assertNotNull(carInject.window.uuid); - } - - @Test - void carInjectReusableTest() { - //Given - CarInjectComponent DI = Stone.createComponent(CarInjectComponent.class); - - //When - CarInject carInject1 = new CarInject(); - CarInject carInject2 = new CarInject(); - DI.inject(carInject1); - DI.inject(carInject2); - - - // Then - assertEquals(2, Bumper.createCount, "Bumpers created from list. And reused"); - assertEquals(carInject1.bumper.uuid, carInject2.bumper.uuid, "should cache"); - assertEquals(carInject1.wheel.uuid, carInject2.wheel.uuid, "should cache "); - assertNotEquals(carInject1.window.uuid, carInject2.window.uuid, "provide via Provider. No caching"); - } - - - @Test - void carInjectListTest() { - //Given - CarInjectComponent DI = Stone.createComponent(CarInjectComponent.class); - - //When - CarInjectLists carInject = new CarInjectLists(); - DI.inject(carInject); - - // Then - assertEquals(2, Bumper.createCount); - assertEquals(5, Wheel.createCount); - assertEquals(8, Window.createCount,"Window created for fields and method"); - assertEquals(2, carInject.bumpers.size()); - assertEquals(5, carInject.wheels.size()); - assertEquals(4, carInject.windows.size()); - for (Bumper b : carInject.bumpers) assertNotNull(b.uuid); - Set bumperUids = new HashSet<>(ListUtils.format(carInject.bumpers, it -> it.uuid)); - assertEquals(2, bumperUids.size()); - for (Wheel w : carInject.wheels) assertNotNull(w.uuid); - Set wheelsUid = new HashSet<>(ListUtils.format(carInject.wheels, it -> it.uuid)); - assertEquals(5, wheelsUid.size()); - for (Window w : carInject.windows) assertNotNull(w.uuid); - Set windowUids = new HashSet<>(ListUtils.format(carInject.windows, it -> it.uuid)); - assertEquals(4, windowUids.size()); - } - - @Test - void carInjectListReusableTest() { - //Given - CarInjectComponent DI = Stone.createComponent(CarInjectComponent.class); - - //When - CarInjectLists carInject1 = new CarInjectLists(); - CarInjectLists carInject2 = new CarInjectLists(); - DI.inject(carInject1); - DI.inject(carInject2); - - // Then - assertEquals(2, carInject1.bumpers.size()); - assertEquals(5, carInject1.wheels.size()); - assertEquals(4, carInject1.windows.size()); - for (int i = 0; i < 2; i++) assertEquals(carInject1.bumpers.get(i).uuid, carInject2.bumpers.get(i).uuid); - for (int i = 0; i < 2; i++) assertEquals(carInject1.wheels.get(i).uuid, carInject2.wheels.get(i).uuid); - Set windowUids = new HashSet<>(); - for (int i = 0; i < 4; i++) windowUids.add(carInject1.windows.get(i).uuid); - for (int i = 0; i < 4; i++) windowUids.add(carInject2.windows.get(i).uuid); - assertEquals(8, windowUids.size()); - } - - - @Test - void carInjectProviderTest() { - //Given - CarInjectComponent DI = Stone.createComponent(CarInjectComponent.class); - - //When - CarInjectProvider carInject = new CarInjectProvider(); - DI.inject(carInject); - - // Then - assertEquals(0, Bumper.createCount, "Provide non used"); - assertNotNull(carInject.bumper.get().uuid); - assertNotNull(carInject.wheel.get().uuid); - assertNotNull(carInject.window.get().getValue().uuid); - assertEquals(2, Bumper.createCount, "Bumpers created from list"); - } - - - @Test - void carInjectProvideReusableTest() { - //Given - CarInjectComponent DI = Stone.createComponent(CarInjectComponent.class); - - //When - CarInjectProvider carInject1 = new CarInjectProvider(); - CarInjectProvider carInject2 = new CarInjectProvider(); - DI.inject(carInject1); - DI.inject(carInject2); - - - // Then - assertEquals(0, Bumper.createCount, "Provider non used"); - assertEquals(carInject1.bumper.get().uuid, carInject2.bumper.get().uuid, "should cache"); - assertEquals(carInject1.wheel.get().uuid, carInject2.wheel.get().uuid, "should cache "); - assertNotEquals(carInject1.window.get().getValue().uuid, carInject2.window.get().getValue().uuid, "provide via Provider. No caching"); - assertEquals(2, Bumper.createCount, "Bumpers created from list. And reused"); - } - -} diff --git a/tests_wraps/src/test/java/com/github/klee0kai/stone/test/car/inject/CarProtectInjectedTests.java b/tests_wraps/src/test/java/com/github/klee0kai/stone/test/car/inject/CarProtectInjectedTests.java deleted file mode 100644 index 70898b23..00000000 --- a/tests_wraps/src/test/java/com/github/klee0kai/stone/test/car/inject/CarProtectInjectedTests.java +++ /dev/null @@ -1,91 +0,0 @@ -package com.github.klee0kai.stone.test.car.inject; - -import com.github.klee0kai.stone.Stone; -import com.github.klee0kai.stone._hidden_.types.ListUtils; -import com.github.klee0kai.test.car.di.inject.CarInjectComponent; -import com.github.klee0kai.test.car.model.CarInject; -import com.github.klee0kai.test.car.model.CarInjectLists; -import com.github.klee0kai.test.car.model.CarInjectProvider; -import org.junit.jupiter.api.Test; - -import java.util.List; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotEquals; - -public class CarProtectInjectedTests { - - @Test - void carProtectInjectedTest() { - //Given - CarInjectComponent DI = Stone.createComponent(CarInjectComponent.class); - - //When - CarInject carInject = new CarInject(); - DI.inject(carInject); - String bumperUid = carInject.bumper.uuid; - String wheelUid = carInject.wheel.uuid; - String windowUid = carInject.window.uuid; - DI.protect(carInject); - carInject = null; - System.gc(); - carInject = new CarInject(); - DI.inject(carInject); - - - // Then - assertEquals(bumperUid, carInject.bumper.uuid, "Providing with caching"); - assertEquals(wheelUid, carInject.wheel.uuid, "Providing with caching"); - assertNotEquals(windowUid, carInject.window.uuid, "Providing without caching"); - } - - - @Test - void carProtectListInjectedTest() { - CarInjectComponent DI = Stone.createComponent(CarInjectComponent.class); - - //When - CarInjectLists carInject = new CarInjectLists(); - DI.inject(carInject); - List bumperUids = ListUtils.format(carInject.bumpers, it -> it.uuid); - List wheelUids = ListUtils.format(carInject.wheels, it -> it.uuid); - List windowUids = ListUtils.format(carInject.windows, it -> it.uuid); - DI.protect(carInject); - carInject = null; - System.gc(); - carInject = new CarInjectLists(); - DI.inject(carInject); - - - // Then - assertEquals(bumperUids, ListUtils.format(carInject.bumpers, it -> it.uuid), "Providing with caching"); - assertEquals(wheelUids, ListUtils.format(carInject.wheels, it -> it.uuid), "Providing with caching"); - assertNotEquals(windowUids, ListUtils.format(carInject.windows, it -> it.uuid), "Providing without caching"); - } - - @Test - void carProtectProviderTest() { - //Given - CarInjectComponent DI = Stone.createComponent(CarInjectComponent.class); - - //When - CarInjectProvider carInject = new CarInjectProvider(); - DI.inject(carInject); - String bumperUid = carInject.bumper.get().uuid; - String wheelUid = carInject.wheel.get().uuid; - String windowUid = carInject.window.get().getValue().uuid; - DI.protect(carInject); - carInject = null; - System.gc(); - carInject = new CarInjectProvider(); - DI.inject(carInject); - - - // Then - assertEquals(bumperUid, carInject.bumper.get().uuid, "Lazy Provider caching and can be protected"); - assertNotEquals(wheelUid, carInject.wheel.get().uuid, "Ref is non caching and non should protect"); - assertNotEquals(windowUid, carInject.window.get().getValue().uuid, "LazyProvide non support caching. Non should protect"); - } - - -} diff --git a/tests_wraps/src/test/java/com/github/klee0kai/stone/test/car/muti/MultiCachedProvideTest.java b/tests_wraps/src/test/java/com/github/klee0kai/stone/test/car/muti/MultiCachedProvideTest.java deleted file mode 100644 index 6fa15526..00000000 --- a/tests_wraps/src/test/java/com/github/klee0kai/stone/test/car/muti/MultiCachedProvideTest.java +++ /dev/null @@ -1,209 +0,0 @@ -package com.github.klee0kai.stone.test.car.muti; - -import com.github.klee0kai.stone.Stone; -import com.github.klee0kai.stone._hidden_.types.ListUtils; -import com.github.klee0kai.stone.wrappers.Ref; -import com.github.klee0kai.test.car.di.lists.cached.CarMultiCachedComponent; -import com.github.klee0kai.test.car.model.Bumper; -import com.github.klee0kai.test.car.model.Car; -import com.github.klee0kai.test.car.model.Wheel; -import com.github.klee0kai.test.car.model.Window; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; - -import javax.inject.Provider; -import java.lang.ref.WeakReference; -import java.util.HashSet; -import java.util.List; -import java.util.Set; - -import static org.junit.jupiter.api.Assertions.*; - -public class MultiCachedProvideTest { - - @BeforeEach - public void init() { - Bumper.createCount = 0; - Window.createCount = 0; - Wheel.createCount = 0; - Car.createCount = 0; - } - - @Test - public void firstBumperFromCollection() { - //Given - CarMultiCachedComponent DI = Stone.createComponent(CarMultiCachedComponent.class); - - //When - assertEquals(0, Bumper.createCount); - Ref bumperProvide = DI.singleBumper(); - - //Then - assertEquals(0, Bumper.createCount); - Bumper bumper = bumperProvide.get(); - assertEquals(2, Bumper.createCount, "Bumper created via list"); - assertNotNull(bumper.uuid); - } - - @Test - public void cachedBumperFromCollection() { - //Given - CarMultiCachedComponent DI = Stone.createComponent(CarMultiCachedComponent.class); - - //When - Ref bumperProvide = DI.singleBumper(); - Bumper bumper1 = bumperProvide.get(); - Bumper bumper2 = bumperProvide.get(); - Bumper bumper3 = DI.singleBumper().get(); - - //Then - assertEquals(2, Bumper.createCount, "Bumper created via list. Cached"); - assertNotNull(bumper1.uuid); - assertEquals(bumper1.uuid, bumper2.uuid); - assertEquals(bumper1.uuid, bumper3.uuid); - } - - @Test - public void fourWheelsAndSpare() { - //Given - CarMultiCachedComponent DI = Stone.createComponent(CarMultiCachedComponent.class); - - //When - assertEquals(0, Wheel.createCount); - List>> wheelsProviderList = DI.wheels(); - - //Then - // assertEquals(0, Wheel.createCount); // each item wrapping in list not delayed - List wheels = ListUtils.format(wheelsProviderList, it -> it.get().get()); - assertEquals(5, Wheel.createCount); - assertEquals(5, wheels.size()); - for (Wheel w : wheels) assertNotNull(w.uuid); - Set wheelsUid = new HashSet<>(ListUtils.format(wheels, it -> it.uuid)); - assertEquals(5, wheelsUid.size()); - } - - @Test - public void fourWheelsAndSpareCached() { - //Given - CarMultiCachedComponent DI = Stone.createComponent(CarMultiCachedComponent.class); - - //When - List>> wheelsProviderList = DI.wheels(); - List wheels1 = ListUtils.format(wheelsProviderList, it -> it.get().get()); - List wheels2 = ListUtils.format(wheelsProviderList, it -> it.get().get()); - List wheels3 = ListUtils.format(DI.wheels(), it -> it.get().get()); - - // Then - assertEquals(5, Wheel.createCount, "wheel lists should cached"); - List wheelsUuid1 = ListUtils.format(wheels1, it -> it.uuid); - List wheelsUuid2 = ListUtils.format(wheels2, it -> it.uuid); - List wheelsUuid3 = ListUtils.format(wheels3, it -> it.uuid); - assertEquals(wheelsUuid1, wheelsUuid2); - assertEquals(wheelsUuid1, wheelsUuid3); - } - - @Test - public void oneWheelFromList() { - //Given - CarMultiCachedComponent DI = Stone.createComponent(CarMultiCachedComponent.class); - - //When - Wheel wheel1 = DI.wheel(); - Wheel wheel2 = DI.wheel(); - - //Then - assertNotNull(wheel1.uuid); - assertEquals(wheel1.uuid, wheel2.uuid); - } - - @Test - public void allWindowsInCar() { - //Given - CarMultiCachedComponent DI = Stone.createComponent(CarMultiCachedComponent.class); - - //When - assertEquals(0, Window.createCount); - List> windows = DI.windows(); - - //Then - assertEquals(4, Window.createCount); - assertEquals(1, windows.size()); - assertEquals(4, windows.get(0).size()); - for (Window w : windows.get(0)) assertNotNull(w.uuid); - Set windowUuid = new HashSet<>(ListUtils.format(windows.get(0), it -> it.uuid)); - assertEquals(4, windowUuid.size()); - } - - @Test - public void allWindowsInCarFactory() { - //Given - CarMultiCachedComponent DI = Stone.createComponent(CarMultiCachedComponent.class); - - //When - assertEquals(0, Window.createCount); - List> windows1 = DI.windows(); - List> windows2 = DI.windows(); - - //Then - assertEquals(8, Window.createCount, "Windows creating over provide wrappers. Should recreate each time"); - } - - @Test - public void allWindowsInCarProvideWrapper() { - //Given - CarMultiCachedComponent DI = Stone.createComponent(CarMultiCachedComponent.class); - - //When - assertEquals(0, Window.createCount); - List>> windows = DI.windowsProviding(); - - //Then - assertEquals(0, Window.createCount, "Provider non used."); - assertEquals(1, windows.size()); - assertEquals(4, windows.get(0).get().size()); - assertEquals(4, Window.createCount, "Provider used. Windows created"); - for (Window w : windows.get(0).get()) assertNotNull(w.uuid); - Set windowUuid = new HashSet<>(ListUtils.format(windows.get(0).get(), it -> it.uuid)); - assertEquals(4, windowUuid.size()); - } - - @Test - public void createCarsWithDeps() { - //Given - CarMultiCachedComponent DI = Stone.createComponent(CarMultiCachedComponent.class); - - //When - assertEquals(0, Car.createCount); - List car = DI.cars(); - - //Then - assertEquals(2, Car.createCount); - assertNotEquals(car.get(0).uuid, car.get(1).uuid); - assertNotNull(car.get(0).bumpers); - assertNotNull(car.get(0).wheels); - assertNotNull(car.get(0).windows); - assertNotNull(car.get(1).bumpers); - assertNotNull(car.get(1).wheels); - assertNotNull(car.get(1).windows); - assertNotEquals(car.get(0).windows.size(), car.get(1).windows.size(), "Red use single deps and Blue car use listed deps"); - } - - @Test - public void cacheCreatedCar() { - //Given - CarMultiCachedComponent DI = Stone.createComponent(CarMultiCachedComponent.class); - - //When - assertEquals(0, Car.createCount); - List car1 = DI.cars(); - List car2 = DI.cars(); - - //Then - assertEquals(2, Car.createCount); - assertEquals(car1.size(), car2.size()); - assertEquals(car1.get(0).uuid, car2.get(0).uuid); - assertEquals(car1.get(1).uuid, car2.get(1).uuid); - } - - -} diff --git a/tests_wraps/src/test/java/com/github/klee0kai/stone/test/car/muti/MultiProvideTest.java b/tests_wraps/src/test/java/com/github/klee0kai/stone/test/car/muti/MultiProvideTest.java deleted file mode 100644 index 1fdcd408..00000000 --- a/tests_wraps/src/test/java/com/github/klee0kai/stone/test/car/muti/MultiProvideTest.java +++ /dev/null @@ -1,206 +0,0 @@ -package com.github.klee0kai.stone.test.car.muti; - -import com.github.klee0kai.stone.Stone; -import com.github.klee0kai.stone._hidden_.types.ListUtils; -import com.github.klee0kai.stone.wrappers.Ref; -import com.github.klee0kai.test.car.di.lists.factory.CarMultiComponent; -import com.github.klee0kai.test.car.model.Bumper; -import com.github.klee0kai.test.car.model.Car; -import com.github.klee0kai.test.car.model.Wheel; -import com.github.klee0kai.test.car.model.Window; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; - -import javax.inject.Provider; -import java.lang.ref.WeakReference; -import java.util.HashSet; -import java.util.List; -import java.util.Set; - -import static org.junit.jupiter.api.Assertions.*; - -public class MultiProvideTest { - - @BeforeEach - public void init() { - Bumper.createCount = 0; - Window.createCount = 0; - Wheel.createCount = 0; - Car.createCount = 0; - } - - @Test - public void firstBumperFromCollection() { - //Given - CarMultiComponent DI = Stone.createComponent(CarMultiComponent.class); - - //When - assertEquals(0, Bumper.createCount); - Ref bumperProvide = DI.singleBumper(); - - //Then - assertEquals(0, Bumper.createCount); - Bumper bumper = bumperProvide.get(); - assertEquals(2, Bumper.createCount, "Bumper created via list"); - assertNotNull(bumper.uuid); - } - - @Test - public void factoryBumperFromCollection() { - //Given - CarMultiComponent DI = Stone.createComponent(CarMultiComponent.class); - - //When - Ref bumperProvide = DI.singleBumper(); - Bumper bumper1 = bumperProvide.get(); - Bumper bumper2 = bumperProvide.get(); - Bumper bumper3 = DI.singleBumper().get(); - - //Then - assertEquals(6, Bumper.createCount, "Factory creating"); - assertNotNull(bumper1.uuid); - assertNotEquals(bumper1.uuid, bumper2.uuid); - assertNotEquals(bumper1.uuid, bumper3.uuid); - } - - @Test - public void fourWheelsAndSpare() { - //Given - CarMultiComponent DI = Stone.createComponent(CarMultiComponent.class); - - //When - assertEquals(0, Wheel.createCount); - List>> wheelsProviderList = DI.wheels(); - - //Then - // assertEquals(0, Wheel.createCount); // each item wrapping in list not delayed - List wheels = ListUtils.format(wheelsProviderList, it -> it.get().get()); - assertEquals(5, Wheel.createCount); - assertEquals(5, wheels.size()); - for (Wheel w : wheels) assertNotNull(w.uuid); - Set wheelsUid = new HashSet<>(ListUtils.format(wheels, it -> it.uuid)); - assertEquals(5, wheelsUid.size()); - } - - @Test - public void fourWheelsAndSpareFactory() { - //Given - CarMultiComponent DI = Stone.createComponent(CarMultiComponent.class); - - //When - List>> wheelsProviderList = DI.wheels(); - List wheels1 = ListUtils.format(wheelsProviderList, it -> it.get().get()); - List wheels2 = ListUtils.format(DI.wheels(), it -> it.get().get()); - - // Then - assertEquals(10, Wheel.createCount, "wheel lists should factory recreated"); - List wheelsUuid1 = ListUtils.format(wheels1, it -> it.uuid); - List wheelsUuid2 = ListUtils.format(wheels2, it -> it.uuid); - assertNotEquals(wheelsUuid1, wheelsUuid2); - } - - @Test - public void oneWheelFromList() { - //Given - CarMultiComponent DI = Stone.createComponent(CarMultiComponent.class); - - //When - Wheel wheel1 = DI.wheel(); - Wheel wheel2 = DI.wheel(); - - //Then - assertNotNull(wheel1.uuid); - assertNotEquals(wheel1.uuid, wheel2.uuid); - } - - @Test - public void allWindowsInCar() { - //Given - CarMultiComponent DI = Stone.createComponent(CarMultiComponent.class); - - //When - assertEquals(0, Window.createCount); - List> windows = DI.windows(); - - //Then - assertEquals(4, Window.createCount); - assertEquals(1, windows.size()); - assertEquals(4, windows.get(0).size()); - for (Window w : windows.get(0)) assertNotNull(w.uuid); - Set windowUuid = new HashSet<>(ListUtils.format(windows.get(0), it -> it.uuid)); - assertEquals(4, windowUuid.size()); - } - - @Test - public void allWindowsInCarFactory() { - //Given - CarMultiComponent DI = Stone.createComponent(CarMultiComponent.class); - - //When - assertEquals(0, Window.createCount); - List> windows1 = DI.windows(); - List> windows2 = DI.windows(); - - //Then - assertEquals(8, Window.createCount, "Windows creating over provide wrappers. Should recreate each time"); - } - - @Test - public void allWindowsInCarProvideWrapper() { - //Given - CarMultiComponent DI = Stone.createComponent(CarMultiComponent.class); - - //When - assertEquals(0, Window.createCount); - List>> windows = DI.windowsProviding(); - - //Then - assertEquals(0, Window.createCount, "Provider non used."); - assertEquals(1, windows.size()); - assertEquals(4, windows.get(0).get().size()); - assertEquals(4, Window.createCount, "Provider used. Windows created"); - for (Window w : windows.get(0).get()) assertNotNull(w.uuid); - Set windowUuid = new HashSet<>(ListUtils.format(windows.get(0).get(), it -> it.uuid)); - assertEquals(4, windowUuid.size()); - } - - @Test - public void createCarsWithDeps() { - //Given - CarMultiComponent DI = Stone.createComponent(CarMultiComponent.class); - - //When - assertEquals(0, Car.createCount); - List car = DI.cars(); - - //Then - assertEquals(2, Car.createCount); - assertNotEquals(car.get(0).uuid, car.get(1).uuid); - assertNotNull(car.get(0).bumpers); - assertNotNull(car.get(0).wheels); - assertNotNull(car.get(0).windows); - assertNotNull(car.get(1).bumpers); - assertNotNull(car.get(1).wheels); - assertNotNull(car.get(1).windows); - assertNotEquals(car.get(0).windows.size(), car.get(1).windows.size(), "Red use single deps and Blue car use listed deps"); - } - - @Test - public void factoryCreatedCar() { - //Given - CarMultiComponent DI = Stone.createComponent(CarMultiComponent.class); - - //When - assertEquals(0, Car.createCount); - List car1 = DI.cars(); - List car2 = DI.cars(); - - //Then - assertEquals(4, Car.createCount); - assertEquals(car1.size(), car2.size()); - assertNotEquals(car1.get(0).uuid, car2.get(0).uuid); - assertNotEquals(car1.get(1).uuid, car2.get(1).uuid); - } - - -} diff --git a/tests_wraps/src/test/java/com/github/klee0kai/stone/test/car/qualifiers/CarInjectAllMethodsWithQualifiersTest.java b/tests_wraps/src/test/java/com/github/klee0kai/stone/test/car/qualifiers/CarInjectAllMethodsWithQualifiersTest.java deleted file mode 100644 index 6559de1e..00000000 --- a/tests_wraps/src/test/java/com/github/klee0kai/stone/test/car/qualifiers/CarInjectAllMethodsWithQualifiersTest.java +++ /dev/null @@ -1,204 +0,0 @@ -package com.github.klee0kai.stone.test.car.qualifiers; - -import com.github.klee0kai.stone.Stone; -import com.github.klee0kai.stone._hidden_.types.ListUtils; -import com.github.klee0kai.test.car.di.qualifiers.CarQComponent; -import com.github.klee0kai.test.car.model.Car; -import com.github.klee0kai.test.car.model.CarsInjectQualifiers; -import org.junit.jupiter.api.Test; - -import java.util.List; -import java.util.Objects; - -import static org.junit.jupiter.api.Assertions.assertEquals; - -public class CarInjectAllMethodsWithQualifiersTest { - - @Test - void namedEmptyProvideTest() { - //Given - CarQComponent DI = Stone.createComponent(CarQComponent.class); - CarsInjectQualifiers carInject = new CarsInjectQualifiers(); - - //When - DI.inject(carInject); - List filtered = ListUtils.filter(carInject.methodAllCars, (i, it) -> Objects.equals(it.qualifier, "named_empty")); - Car car = filtered.get(0); - - //Then - assertEquals(1, filtered.size()); - assertEquals("simple", car.bumpers.get(0).qualifier); - assertEquals(5, car.wheels.size(), "four wheel +1"); - } - - @Test - void namedAProvideTest() { - //Given - CarQComponent DI = Stone.createComponent(CarQComponent.class); - CarsInjectQualifiers carInject = new CarsInjectQualifiers(); - - //When - DI.inject(carInject); - List filtered = ListUtils.filter(carInject.methodAllCars, (i, it) -> Objects.equals(it.qualifier, "named_a")); - Car car = filtered.get(0); - - //Then - assertEquals(1, filtered.size()); - assertEquals("reinforced", car.bumpers.get(0).qualifier); - assertEquals(5, car.wheels.size(), "four wheel +1"); - } - - @Test - void carMyQualifierProvideTest() { - //Given - CarQComponent DI = Stone.createComponent(CarQComponent.class); - CarsInjectQualifiers carInject = new CarsInjectQualifiers(); - - //When - DI.inject(carInject); - List filtered = ListUtils.filter(carInject.methodAllCars, (i, it) -> Objects.equals(it.qualifier, "my_qualifier")); - Car car = filtered.get(0); - - //Then - assertEquals(1, filtered.size()); - assertEquals("simple", car.bumpers.get(0).qualifier); - assertEquals(5, car.wheels.size(), "four wheel +1"); - } - - @Test - void carMyQualifierStringProvideTest() { - //Given - CarQComponent DI = Stone.createComponent(CarQComponent.class); - CarsInjectQualifiers carInject = new CarsInjectQualifiers(); - - //When - DI.inject(carInject); - List filtered = ListUtils.filter(carInject.methodAllCars, (i, it) -> Objects.equals(it.qualifier, "my_qualifier_with_string")); - Car car = filtered.get(0); - - //Then - assertEquals(1, filtered.size()); - assertEquals("simple", car.bumpers.get(0).qualifier); - assertEquals(5, car.wheels.size(), "four wheel +1"); - } - - @Test - void carMyQualifierStringAProvideTest() { - //Given - CarQComponent DI = Stone.createComponent(CarQComponent.class); - CarsInjectQualifiers carInject = new CarsInjectQualifiers(); - - //When - DI.inject(carInject); - List filtered = ListUtils.filter(carInject.methodAllCars, (i, it) -> Objects.equals(it.qualifier, "my_qualifier_a")); - Car car = filtered.get(0); - - //Then - assertEquals(1, filtered.size()); - assertEquals("reinforced", car.bumpers.get(0).qualifier); - assertEquals(4, car.wheels.size(), "four wheel +1"); - } - - @Test - void carMyQualifierStringBProvideTest() { - //Given - CarQComponent DI = Stone.createComponent(CarQComponent.class); - CarsInjectQualifiers carInject = new CarsInjectQualifiers(); - - //When - DI.inject(carInject); - List filtered = ListUtils.filter(carInject.methodAllCars, (i, it) -> Objects.equals(it.qualifier, "my_qualifier_b")); - Car car = filtered.get(0); - - //Then - assertEquals(1, filtered.size()); - assertEquals("simple", car.bumpers.get(0).qualifier); - assertEquals(5, car.wheels.size(), "four wheel +1"); - } - - @Test - void carMyQualifierMultiProvideTest() { - //Given - CarQComponent DI = Stone.createComponent(CarQComponent.class); - CarsInjectQualifiers carInject = new CarsInjectQualifiers(); - - //When - DI.inject(carInject); - List filtered = ListUtils.filter(carInject.methodAllCars, (i, it) -> Objects.equals(it.qualifier, "qualifier_multi")); - Car car = filtered.get(0); - - //Then - assertEquals(1, filtered.size()); - assertEquals("simple", car.bumpers.get(0).qualifier); - assertEquals(4, car.wheels.size()); - } - - @Test - void carMyQualifierMultiA1ProvideTest() { - //Given - CarQComponent DI = Stone.createComponent(CarQComponent.class); - CarsInjectQualifiers carInject = new CarsInjectQualifiers(); - - //When - DI.inject(carInject); - List filtered = ListUtils.filter(carInject.methodAllCars, (i, it) -> Objects.equals(it.qualifier, "qualifier_multi_a1")); - Car car = filtered.get(0); - - //Then - assertEquals(1, filtered.size()); - assertEquals("simple", car.bumpers.get(0).qualifier); - assertEquals(5, car.wheels.size(), "four wheel +1"); - } - - - @Test - void carMyQualifierMultiA2ProvideTest() { - //Given - CarQComponent DI = Stone.createComponent(CarQComponent.class); - CarsInjectQualifiers carInject = new CarsInjectQualifiers(); - - //When - DI.inject(carInject); - List filtered = ListUtils.filter(carInject.methodAllCars, (i, it) -> Objects.equals(it.qualifier, "qualifier_multi_a2")); - Car car = filtered.get(0); - - //Then - assertEquals(1, filtered.size()); - assertEquals("reinforced", car.bumpers.get(0).qualifier); - assertEquals(4, car.wheels.size()); - } - - @Test - void carMyQualifierMultiA2HardProvideTest() { - //Given - CarQComponent DI = Stone.createComponent(CarQComponent.class); - CarsInjectQualifiers carInject = new CarsInjectQualifiers(); - - //When - DI.inject(carInject); - List filtered = ListUtils.filter(carInject.methodAllCars, (i, it) -> Objects.equals(it.qualifier, "qualifier_multi_a2_hard")); - Car car = filtered.get(0); - - //Then - assertEquals(1, filtered.size()); - assertEquals("simple", car.bumpers.get(0).qualifier); - assertEquals(4, car.wheels.size()); - } - - @Test - void allCarsProvideTest() { - //Given - CarQComponent DI = Stone.createComponent(CarQComponent.class); - CarsInjectQualifiers carInject = new CarsInjectQualifiers(); - - //When - DI.inject(carInject); - - //Then - assertEquals(14, carInject.methodAllCars.size()); - assertEquals(1, ListUtils.filter(carInject.methodAllCars, (i, it) -> Objects.equals(it.qualifier, "my_qualifier_a")).size()); - assertEquals(1, ListUtils.filter(carInject.methodAllCars, (i, it) -> Objects.equals(it.qualifier, "qualifier_multi_a2")).size()); - assertEquals(1, ListUtils.filter(carInject.methodAllCars, (i, it) -> Objects.equals(it.qualifier, "qualifier_multi_a2_hard")).size()); - } - -} diff --git a/tests_wraps/src/test/java/com/github/klee0kai/stone/test/car/qualifiers/CarInjectAllWithQualifiersTest.java b/tests_wraps/src/test/java/com/github/klee0kai/stone/test/car/qualifiers/CarInjectAllWithQualifiersTest.java deleted file mode 100644 index 7d167752..00000000 --- a/tests_wraps/src/test/java/com/github/klee0kai/stone/test/car/qualifiers/CarInjectAllWithQualifiersTest.java +++ /dev/null @@ -1,204 +0,0 @@ -package com.github.klee0kai.stone.test.car.qualifiers; - -import com.github.klee0kai.stone.Stone; -import com.github.klee0kai.stone._hidden_.types.ListUtils; -import com.github.klee0kai.test.car.di.qualifiers.CarQComponent; -import com.github.klee0kai.test.car.model.Car; -import com.github.klee0kai.test.car.model.CarsInjectQualifiers; -import org.junit.jupiter.api.Test; - -import java.util.List; -import java.util.Objects; - -import static org.junit.jupiter.api.Assertions.assertEquals; - -public class CarInjectAllWithQualifiersTest { - - @Test - void namedEmptyProvideTest() { - //Given - CarQComponent DI = Stone.createComponent(CarQComponent.class); - CarsInjectQualifiers carInject = new CarsInjectQualifiers(); - - //When - DI.inject(carInject); - List filtered = ListUtils.filter(carInject.allCars, (i, it) -> Objects.equals(it.qualifier, "named_empty")); - Car car = filtered.get(0); - - //Then - assertEquals(1, filtered.size()); - assertEquals("simple", car.bumpers.get(0).qualifier); - assertEquals(5, car.wheels.size(), "four wheel +1"); - } - - @Test - void namedAProvideTest() { - //Given - CarQComponent DI = Stone.createComponent(CarQComponent.class); - CarsInjectQualifiers carInject = new CarsInjectQualifiers(); - - //When - DI.inject(carInject); - List filtered = ListUtils.filter(carInject.allCars, (i, it) -> Objects.equals(it.qualifier, "named_a")); - Car car = filtered.get(0); - - //Then - assertEquals(1, filtered.size()); - assertEquals("reinforced", car.bumpers.get(0).qualifier); - assertEquals(5, car.wheels.size(), "four wheel +1"); - } - - @Test - void carMyQualifierProvideTest() { - //Given - CarQComponent DI = Stone.createComponent(CarQComponent.class); - CarsInjectQualifiers carInject = new CarsInjectQualifiers(); - - //When - DI.inject(carInject); - List filtered = ListUtils.filter(carInject.allCars, (i, it) -> Objects.equals(it.qualifier, "my_qualifier")); - Car car = filtered.get(0); - - //Then - assertEquals(1, filtered.size()); - assertEquals("simple", car.bumpers.get(0).qualifier); - assertEquals(5, car.wheels.size(), "four wheel +1"); - } - - @Test - void carMyQualifierStringProvideTest() { - //Given - CarQComponent DI = Stone.createComponent(CarQComponent.class); - CarsInjectQualifiers carInject = new CarsInjectQualifiers(); - - //When - DI.inject(carInject); - List filtered = ListUtils.filter(carInject.allCars, (i, it) -> Objects.equals(it.qualifier, "my_qualifier_with_string")); - Car car = filtered.get(0); - - //Then - assertEquals(1, filtered.size()); - assertEquals("simple", car.bumpers.get(0).qualifier); - assertEquals(5, car.wheels.size(), "four wheel +1"); - } - - @Test - void carMyQualifierStringAProvideTest() { - //Given - CarQComponent DI = Stone.createComponent(CarQComponent.class); - CarsInjectQualifiers carInject = new CarsInjectQualifiers(); - - //When - DI.inject(carInject); - List filtered = ListUtils.filter(carInject.allCars, (i, it) -> Objects.equals(it.qualifier, "my_qualifier_a")); - Car car = filtered.get(0); - - //Then - assertEquals(1, filtered.size()); - assertEquals("reinforced", car.bumpers.get(0).qualifier); - assertEquals(4, car.wheels.size(), "four wheel +1"); - } - - @Test - void carMyQualifierStringBProvideTest() { - //Given - CarQComponent DI = Stone.createComponent(CarQComponent.class); - CarsInjectQualifiers carInject = new CarsInjectQualifiers(); - - //When - DI.inject(carInject); - List filtered = ListUtils.filter(carInject.allCars, (i, it) -> Objects.equals(it.qualifier, "my_qualifier_b")); - Car car = filtered.get(0); - - //Then - assertEquals(1, filtered.size()); - assertEquals("simple", car.bumpers.get(0).qualifier); - assertEquals(5, car.wheels.size(), "four wheel +1"); - } - - @Test - void carMyQualifierMultiProvideTest() { - //Given - CarQComponent DI = Stone.createComponent(CarQComponent.class); - CarsInjectQualifiers carInject = new CarsInjectQualifiers(); - - //When - DI.inject(carInject); - List filtered = ListUtils.filter(carInject.allCars, (i, it) -> Objects.equals(it.qualifier, "qualifier_multi")); - Car car = filtered.get(0); - - //Then - assertEquals(1, filtered.size()); - assertEquals("simple", car.bumpers.get(0).qualifier); - assertEquals(4, car.wheels.size()); - } - - @Test - void carMyQualifierMultiA1ProvideTest() { - //Given - CarQComponent DI = Stone.createComponent(CarQComponent.class); - CarsInjectQualifiers carInject = new CarsInjectQualifiers(); - - //When - DI.inject(carInject); - List filtered = ListUtils.filter(carInject.allCars, (i, it) -> Objects.equals(it.qualifier, "qualifier_multi_a1")); - Car car = filtered.get(0); - - //Then - assertEquals(1, filtered.size()); - assertEquals("simple", car.bumpers.get(0).qualifier); - assertEquals(5, car.wheels.size(), "four wheel +1"); - } - - - @Test - void carMyQualifierMultiA2ProvideTest() { - //Given - CarQComponent DI = Stone.createComponent(CarQComponent.class); - CarsInjectQualifiers carInject = new CarsInjectQualifiers(); - - //When - DI.inject(carInject); - List filtered = ListUtils.filter(carInject.allCars, (i, it) -> Objects.equals(it.qualifier, "qualifier_multi_a2")); - Car car = filtered.get(0); - - //Then - assertEquals(1, filtered.size()); - assertEquals("reinforced", car.bumpers.get(0).qualifier); - assertEquals(4, car.wheels.size()); - } - - @Test - void carMyQualifierMultiA2HardProvideTest() { - //Given - CarQComponent DI = Stone.createComponent(CarQComponent.class); - CarsInjectQualifiers carInject = new CarsInjectQualifiers(); - - //When - DI.inject(carInject); - List filtered = ListUtils.filter(carInject.allCars, (i, it) -> Objects.equals(it.qualifier, "qualifier_multi_a2_hard")); - Car car = filtered.get(0); - - //Then - assertEquals(1, filtered.size()); - assertEquals("simple", car.bumpers.get(0).qualifier); - assertEquals(4, car.wheels.size()); - } - - @Test - void allCarsProvideTest() { - //Given - CarQComponent DI = Stone.createComponent(CarQComponent.class); - CarsInjectQualifiers carInject = new CarsInjectQualifiers(); - - //When - DI.inject(carInject); - - //Then - assertEquals(14, carInject.allCars.size()); - assertEquals(1, ListUtils.filter(carInject.allCars, (i, it) -> Objects.equals(it.qualifier, "my_qualifier_a")).size()); - assertEquals(1, ListUtils.filter(carInject.allCars, (i, it) -> Objects.equals(it.qualifier, "qualifier_multi_a2")).size()); - assertEquals(1, ListUtils.filter(carInject.allCars, (i, it) -> Objects.equals(it.qualifier, "qualifier_multi_a2_hard")).size()); - } - -} diff --git a/tests_wraps/src/test/java/com/github/klee0kai/stone/test/car/qualifiers/CarInjectMethodWithQualifiersTest.java b/tests_wraps/src/test/java/com/github/klee0kai/stone/test/car/qualifiers/CarInjectMethodWithQualifiersTest.java deleted file mode 100644 index 353c3951..00000000 --- a/tests_wraps/src/test/java/com/github/klee0kai/stone/test/car/qualifiers/CarInjectMethodWithQualifiersTest.java +++ /dev/null @@ -1,222 +0,0 @@ -package com.github.klee0kai.stone.test.car.qualifiers; - -import com.github.klee0kai.stone.Stone; -import com.github.klee0kai.stone._hidden_.types.ListUtils; -import com.github.klee0kai.test.car.di.qualifiers.CarQComponent; -import com.github.klee0kai.test.car.model.Car; -import com.github.klee0kai.test.car.model.CarsInjectQualifiers; -import org.junit.jupiter.api.Test; - -import java.util.Objects; - -import static org.junit.jupiter.api.Assertions.assertEquals; - -public class CarInjectMethodWithQualifiersTest { - - @Test - void namedEmptyProvideTest() { - //Given - CarQComponent DI = Stone.createComponent(CarQComponent.class); - CarsInjectQualifiers carInject = new CarsInjectQualifiers(); - - //When - DI.inject(carInject); - Car car = carInject.methodCarNamedEmpty; - - //Then - assertEquals("named_empty", car.qualifier); - assertEquals("simple", car.bumpers.get(0).qualifier); - assertEquals(5, car.wheels.size(), "four wheel +1"); - } - - @Test - void namedAProvideTest() { - //Given - CarQComponent DI = Stone.createComponent(CarQComponent.class); - CarsInjectQualifiers carInject = new CarsInjectQualifiers(); - - //When - DI.inject(carInject); - Car car = carInject.methodCarNamedA; - - //Then - assertEquals("named_a", car.qualifier); - assertEquals("reinforced", car.bumpers.get(0).qualifier); - assertEquals(5, car.wheels.size(), "four wheel +1"); - } - - @Test - void carMyQualifierProvideTest() { - //Given - CarQComponent DI = Stone.createComponent(CarQComponent.class); - CarsInjectQualifiers carInject = new CarsInjectQualifiers(); - - //When - DI.inject(carInject); - Car car = carInject.methodCarMyQualifier; - - //Then - assertEquals("my_qualifier", car.qualifier); - assertEquals("simple", car.bumpers.get(0).qualifier); - assertEquals(5, car.wheels.size(), "four wheel +1"); - } - - @Test - void carMyQualifierStringProvideTest() { - //Given - CarQComponent DI = Stone.createComponent(CarQComponent.class); - CarsInjectQualifiers carInject = new CarsInjectQualifiers(); - - //When - DI.inject(carInject); - Car car = carInject.methodCarMyQualifierString; - - //Then - assertEquals("my_qualifier_with_string", car.qualifier); - assertEquals("simple", car.bumpers.get(0).qualifier); - assertEquals(5, car.wheels.size(), "four wheel +1"); - } - - @Test - void carMyQualifierStringAProvideTest() { - //Given - CarQComponent DI = Stone.createComponent(CarQComponent.class); - CarsInjectQualifiers carInject = new CarsInjectQualifiers(); - - //When - DI.inject(carInject); - Car car = carInject.methodCarMyQualifierA; - - //Then - assertEquals("my_qualifier_a", car.qualifier); - assertEquals("reinforced", car.bumpers.get(0).qualifier); - assertEquals(4, car.wheels.size(), "four wheel +1"); - } - - @Test - void carMyQualifierStringBProvideTest() { - //Given - CarQComponent DI = Stone.createComponent(CarQComponent.class); - CarsInjectQualifiers carInject = new CarsInjectQualifiers(); - - //When - DI.inject(carInject); - Car car = carInject.methodCarMyQualifierB; - - //Then - assertEquals("my_qualifier_b", car.qualifier); - assertEquals("simple", car.bumpers.get(0).qualifier); - assertEquals(5, car.wheels.size(), "four wheel +1"); - } - - @Test - void carMyQualifierMultiProvideTest() { - //Given - CarQComponent DI = Stone.createComponent(CarQComponent.class); - CarsInjectQualifiers carInject = new CarsInjectQualifiers(); - - //When - DI.inject(carInject); - Car car = carInject.methodCarMyQualifierMulti; - - //Then - assertEquals("qualifier_multi", car.qualifier); - assertEquals("simple", car.bumpers.get(0).qualifier); - assertEquals(4, car.wheels.size()); - } - - @Test - void carMyQualifierMultiA1ProvideTest() { - //Given - CarQComponent DI = Stone.createComponent(CarQComponent.class); - CarsInjectQualifiers carInject = new CarsInjectQualifiers(); - - //When - DI.inject(carInject); - Car car = carInject.methodCarMyQualifierMultiA1; - - //Then - assertEquals("qualifier_multi_a1", car.qualifier); - assertEquals("simple", car.bumpers.get(0).qualifier); - assertEquals(5, car.wheels.size(), "four wheel +1"); - } - - - @Test - void carMyQualifierMultiA2ProvideTest() { - //Given - CarQComponent DI = Stone.createComponent(CarQComponent.class); - CarsInjectQualifiers carInject = new CarsInjectQualifiers(); - - //When - DI.inject(carInject); - Car car = carInject.methodCarMyQualifierMultiA2; - - //Then - assertEquals("qualifier_multi_a2", car.qualifier); - assertEquals("reinforced", car.bumpers.get(0).qualifier); - assertEquals(4, car.wheels.size()); - } - - @Test - void carMyQualifierMultiA2HardProvideTest() { - //Given - CarQComponent DI = Stone.createComponent(CarQComponent.class); - CarsInjectQualifiers carInject = new CarsInjectQualifiers(); - - //When - DI.inject(carInject); - Car car = carInject.methodCarMyQualifierMultiA2Hard; - - //Then - assertEquals("qualifier_multi_a2_hard", car.qualifier); - assertEquals("simple", car.bumpers.get(0).qualifier); - assertEquals(4, car.wheels.size()); - } - - @Test - void allCarsProvideTest() { - //Given - CarQComponent DI = Stone.createComponent(CarQComponent.class); - CarsInjectQualifiers carInject = new CarsInjectQualifiers(); - - //When - DI.inject(carInject); - - //Then - assertEquals(14, carInject.methodAllCars.size()); - assertEquals(1, ListUtils.filter(carInject.methodAllCars, (i, it) -> Objects.equals(it.qualifier, "my_qualifier_a")).size()); - assertEquals(1, ListUtils.filter(carInject.methodAllCars, (i, it) -> Objects.equals(it.qualifier, "qualifier_multi_a2")).size()); - assertEquals(1, ListUtils.filter(carInject.methodAllCars, (i, it) -> Objects.equals(it.qualifier, "qualifier_multi_a2_hard")).size()); - } - - - @Test - void provideCarsNamedEmptyTest() { - //Given - CarQComponent DI = Stone.createComponent(CarQComponent.class); - CarsInjectQualifiers carInject = new CarsInjectQualifiers(); - - //When - DI.inject(carInject); - - //Then - assertEquals(1, carInject.methodCarsNamedEmpty.size()); - assertEquals("named_empty", carInject.methodCarsNamedEmpty.get(0).qualifier); - } - - @Test - void carsMyQualifierMultiA2HardTest() { - //Given - CarQComponent DI = Stone.createComponent(CarQComponent.class); - CarsInjectQualifiers carInject = new CarsInjectQualifiers(); - - //When - DI.inject(carInject); - - //Then - assertEquals(1, carInject.methodCarsMyQualifierMultiA2Hard.size()); - assertEquals("qualifier_multi_a2_hard", carInject.methodCarsMyQualifierMultiA2Hard.get(0).qualifier); - } - -} diff --git a/tests_wraps/src/test/java/com/github/klee0kai/stone/test/car/qualifiers/CarInjectWithQualifiersTest.java b/tests_wraps/src/test/java/com/github/klee0kai/stone/test/car/qualifiers/CarInjectWithQualifiersTest.java deleted file mode 100644 index 44cd3cb7..00000000 --- a/tests_wraps/src/test/java/com/github/klee0kai/stone/test/car/qualifiers/CarInjectWithQualifiersTest.java +++ /dev/null @@ -1,222 +0,0 @@ -package com.github.klee0kai.stone.test.car.qualifiers; - -import com.github.klee0kai.stone.Stone; -import com.github.klee0kai.stone._hidden_.types.ListUtils; -import com.github.klee0kai.test.car.di.qualifiers.CarQComponent; -import com.github.klee0kai.test.car.model.Car; -import com.github.klee0kai.test.car.model.CarsInjectQualifiers; -import org.junit.jupiter.api.Test; - -import java.util.Objects; - -import static org.junit.jupiter.api.Assertions.assertEquals; - -public class CarInjectWithQualifiersTest { - - @Test - void namedEmptyProvideTest() { - //Given - CarQComponent DI = Stone.createComponent(CarQComponent.class); - CarsInjectQualifiers carInject = new CarsInjectQualifiers(); - - //When - DI.inject(carInject); - Car car = carInject.carNamedEmpty; - - //Then - assertEquals("named_empty", car.qualifier); - assertEquals("simple", car.bumpers.get(0).qualifier); - assertEquals(5, car.wheels.size(), "four wheel +1"); - } - - @Test - void namedAProvideTest() { - //Given - CarQComponent DI = Stone.createComponent(CarQComponent.class); - CarsInjectQualifiers carInject = new CarsInjectQualifiers(); - - //When - DI.inject(carInject); - Car car = carInject.carNamedA; - - //Then - assertEquals("named_a", car.qualifier); - assertEquals("reinforced", car.bumpers.get(0).qualifier); - assertEquals(5, car.wheels.size(), "four wheel +1"); - } - - @Test - void carMyQualifierProvideTest() { - //Given - CarQComponent DI = Stone.createComponent(CarQComponent.class); - CarsInjectQualifiers carInject = new CarsInjectQualifiers(); - - //When - DI.inject(carInject); - Car car = carInject.carMyQualifier; - - //Then - assertEquals("my_qualifier", car.qualifier); - assertEquals("simple", car.bumpers.get(0).qualifier); - assertEquals(5, car.wheels.size(), "four wheel +1"); - } - - @Test - void carMyQualifierStringProvideTest() { - //Given - CarQComponent DI = Stone.createComponent(CarQComponent.class); - CarsInjectQualifiers carInject = new CarsInjectQualifiers(); - - //When - DI.inject(carInject); - Car car = carInject.carMyQualifierString; - - //Then - assertEquals("my_qualifier_with_string", car.qualifier); - assertEquals("simple", car.bumpers.get(0).qualifier); - assertEquals(5, car.wheels.size(), "four wheel +1"); - } - - @Test - void carMyQualifierStringAProvideTest() { - //Given - CarQComponent DI = Stone.createComponent(CarQComponent.class); - CarsInjectQualifiers carInject = new CarsInjectQualifiers(); - - //When - DI.inject(carInject); - Car car = carInject.carMyQualifierA; - - //Then - assertEquals("my_qualifier_a", car.qualifier); - assertEquals("reinforced", car.bumpers.get(0).qualifier); - assertEquals(4, car.wheels.size(), "four wheel +1"); - } - - @Test - void carMyQualifierStringBProvideTest() { - //Given - CarQComponent DI = Stone.createComponent(CarQComponent.class); - CarsInjectQualifiers carInject = new CarsInjectQualifiers(); - - //When - DI.inject(carInject); - Car car = carInject.carMyQualifierB; - - //Then - assertEquals("my_qualifier_b", car.qualifier); - assertEquals("simple", car.bumpers.get(0).qualifier); - assertEquals(5, car.wheels.size(), "four wheel +1"); - } - - @Test - void carMyQualifierMultiProvideTest() { - //Given - CarQComponent DI = Stone.createComponent(CarQComponent.class); - CarsInjectQualifiers carInject = new CarsInjectQualifiers(); - - //When - DI.inject(carInject); - Car car = carInject.carMyQualifierMulti; - - //Then - assertEquals("qualifier_multi", car.qualifier); - assertEquals("simple", car.bumpers.get(0).qualifier); - assertEquals(4, car.wheels.size()); - } - - @Test - void carMyQualifierMultiA1ProvideTest() { - //Given - CarQComponent DI = Stone.createComponent(CarQComponent.class); - CarsInjectQualifiers carInject = new CarsInjectQualifiers(); - - //When - DI.inject(carInject); - Car car = carInject.carMyQualifierMultiA1; - - //Then - assertEquals("qualifier_multi_a1", car.qualifier); - assertEquals("simple", car.bumpers.get(0).qualifier); - assertEquals(5, car.wheels.size(), "four wheel +1"); - } - - - @Test - void carMyQualifierMultiA2ProvideTest() { - //Given - CarQComponent DI = Stone.createComponent(CarQComponent.class); - CarsInjectQualifiers carInject = new CarsInjectQualifiers(); - - //When - DI.inject(carInject); - Car car = carInject.carMyQualifierMultiA2; - - //Then - assertEquals("qualifier_multi_a2", car.qualifier); - assertEquals("reinforced", car.bumpers.get(0).qualifier); - assertEquals(4, car.wheels.size()); - } - - @Test - void carMyQualifierMultiA2HardProvideTest() { - //Given - CarQComponent DI = Stone.createComponent(CarQComponent.class); - CarsInjectQualifiers carInject = new CarsInjectQualifiers(); - - //When - DI.inject(carInject); - Car car = carInject.carMyQualifierMultiA2Hard; - - //Then - assertEquals("qualifier_multi_a2_hard", car.qualifier); - assertEquals("simple", car.bumpers.get(0).qualifier); - assertEquals(4, car.wheels.size()); - } - - @Test - void allCarsProvideTest() { - //Given - CarQComponent DI = Stone.createComponent(CarQComponent.class); - CarsInjectQualifiers carInject = new CarsInjectQualifiers(); - - //When - DI.inject(carInject); - - //Then - assertEquals(14, carInject.allCars.size()); - assertEquals(1, ListUtils.filter(carInject.allCars, (i, it) -> Objects.equals(it.qualifier, "my_qualifier_a")).size()); - assertEquals(1, ListUtils.filter(carInject.allCars, (i, it) -> Objects.equals(it.qualifier, "qualifier_multi_a2")).size()); - assertEquals(1, ListUtils.filter(carInject.allCars, (i, it) -> Objects.equals(it.qualifier, "qualifier_multi_a2_hard")).size()); - } - - - @Test - void provideCarsNamedEmptyTest() { - //Given - CarQComponent DI = Stone.createComponent(CarQComponent.class); - CarsInjectQualifiers carInject = new CarsInjectQualifiers(); - - //When - DI.inject(carInject); - - //Then - assertEquals(1, carInject.carsNamedEmpty.size()); - assertEquals("named_empty", carInject.carsNamedEmpty.get(0).qualifier); - } - - @Test - void carsMyQualifierMultiA2HardTest() { - //Given - CarQComponent DI = Stone.createComponent(CarQComponent.class); - CarsInjectQualifiers carInject = new CarsInjectQualifiers(); - - //When - DI.inject(carInject); - - //Then - assertEquals(1, carInject.carsMyQualifierMultiA2Hard.size()); - assertEquals("qualifier_multi_a2_hard", carInject.carsMyQualifierMultiA2Hard.get(0).qualifier); - } - -} diff --git a/tests_wraps/src/test/java/com/github/klee0kai/stone/test/car/qualifiers/CarProvideAllWithQualifiersTests.java b/tests_wraps/src/test/java/com/github/klee0kai/stone/test/car/qualifiers/CarProvideAllWithQualifiersTests.java deleted file mode 100644 index b0a34893..00000000 --- a/tests_wraps/src/test/java/com/github/klee0kai/stone/test/car/qualifiers/CarProvideAllWithQualifiersTests.java +++ /dev/null @@ -1,193 +0,0 @@ -package com.github.klee0kai.stone.test.car.qualifiers; - -import com.github.klee0kai.stone.Stone; -import com.github.klee0kai.stone._hidden_.types.ListUtils; -import com.github.klee0kai.test.car.di.qualifiers.CarQComponent; -import com.github.klee0kai.test.car.model.Car; -import org.junit.jupiter.api.Test; - -import java.util.List; -import java.util.Objects; - -import static org.junit.jupiter.api.Assertions.assertEquals; - -public class CarProvideAllWithQualifiersTests { - - @Test - void namedEmptyProvideTest() { - //Given - CarQComponent DI = Stone.createComponent(CarQComponent.class); - List cars = DI.allCars(); - - //When - List filtered = ListUtils.filter(cars, (i, it) -> Objects.equals(it.qualifier, "named_empty")); - Car car = filtered.get(0); - - //Then - assertEquals(1, filtered.size()); - assertEquals("simple", car.bumpers.get(0).qualifier); - assertEquals(5, car.wheels.size(), "four wheel +1"); - } - - @Test - void namedAProvideTest() { - //Given - CarQComponent DI = Stone.createComponent(CarQComponent.class); - List cars = DI.allCars(); - - //When - List filtered = ListUtils.filter(cars, (i, it) -> Objects.equals(it.qualifier, "named_a")); - Car car = filtered.get(0); - - //Then - assertEquals(1, filtered.size()); - assertEquals("reinforced", car.bumpers.get(0).qualifier); - assertEquals(5, car.wheels.size(), "four wheel +1"); - } - - @Test - void carMyQualifierProvideTest() { - //Given - CarQComponent DI = Stone.createComponent(CarQComponent.class); - List cars = DI.allCars(); - - //When - List filtered = ListUtils.filter(cars, (i, it) -> Objects.equals(it.qualifier, "my_qualifier")); - Car car = filtered.get(0); - - //Then - assertEquals(1, filtered.size()); - assertEquals("simple", car.bumpers.get(0).qualifier); - assertEquals(5, car.wheels.size(), "four wheel +1"); - } - - @Test - void carMyQualifierStringProvideTest() { - //Given - CarQComponent DI = Stone.createComponent(CarQComponent.class); - List cars = DI.allCars(); - - //When - List filtered = ListUtils.filter(cars, (i, it) -> Objects.equals(it.qualifier, "my_qualifier_with_string")); - Car car = filtered.get(0); - - //Then - assertEquals(1, filtered.size()); - assertEquals("simple", car.bumpers.get(0).qualifier); - assertEquals(5, car.wheels.size(), "four wheel +1"); - } - - @Test - void carMyQualifierStringAProvideTest() { - //Given - CarQComponent DI = Stone.createComponent(CarQComponent.class); - List cars = DI.allCars(); - - //When - List filtered = ListUtils.filter(cars, (i, it) -> Objects.equals(it.qualifier, "my_qualifier_a")); - Car car = filtered.get(0); - - //Then - assertEquals(1, filtered.size()); - assertEquals("reinforced", car.bumpers.get(0).qualifier); - assertEquals(4, car.wheels.size(), "four wheel +1"); - } - - @Test - void carMyQualifierStringBProvideTest() { - //Given - CarQComponent DI = Stone.createComponent(CarQComponent.class); - List cars = DI.allCars(); - - //When - List filtered = ListUtils.filter(cars, (i, it) -> Objects.equals(it.qualifier, "my_qualifier_b")); - Car car = filtered.get(0); - - //Then - assertEquals(1, filtered.size()); - assertEquals("simple", car.bumpers.get(0).qualifier); - assertEquals(5, car.wheels.size(), "four wheel +1"); - } - - @Test - void carMyQualifierMultiProvideTest() { - //Given - CarQComponent DI = Stone.createComponent(CarQComponent.class); - List cars = DI.allCars(); - - //When - List filtered = ListUtils.filter(cars, (i, it) -> Objects.equals(it.qualifier, "qualifier_multi")); - Car car = filtered.get(0); - - //Then - assertEquals(1, filtered.size()); - assertEquals("simple", car.bumpers.get(0).qualifier); - assertEquals(4, car.wheels.size()); - } - - @Test - void carMyQualifierMultiA1ProvideTest() { - //Given - CarQComponent DI = Stone.createComponent(CarQComponent.class); - List cars = DI.allCars(); - - //When - List filtered = ListUtils.filter(cars, (i, it) -> Objects.equals(it.qualifier, "qualifier_multi_a1")); - Car car = filtered.get(0); - - //Then - assertEquals(1, filtered.size()); - assertEquals("simple", car.bumpers.get(0).qualifier); - assertEquals(5, car.wheels.size(), "four wheel +1"); - } - - - @Test - void carMyQualifierMultiA2ProvideTest() { - //Given - CarQComponent DI = Stone.createComponent(CarQComponent.class); - List cars = DI.allCars(); - - //When - List filtered = ListUtils.filter(cars, (i, it) -> Objects.equals(it.qualifier, "qualifier_multi_a2")); - Car car = filtered.get(0); - - //Then - assertEquals(1, filtered.size()); - assertEquals("reinforced", car.bumpers.get(0).qualifier); - assertEquals(4, car.wheels.size()); - } - - @Test - void carMyQualifierMultiA2HardProvideTest() { - //Given - CarQComponent DI = Stone.createComponent(CarQComponent.class); - List cars = DI.allCars(); - - //When - List filtered = ListUtils.filter(cars, (i, it) -> Objects.equals(it.qualifier, "qualifier_multi_a2_hard")); - Car car = filtered.get(0); - - //Then - assertEquals(1, filtered.size()); - assertEquals("simple", car.bumpers.get(0).qualifier); - assertEquals(4, car.wheels.size()); - } - - @Test - void allCarsProvideTest() { - //Given - CarQComponent DI = Stone.createComponent(CarQComponent.class); - - //When - List cars = DI.allCars(); - - //Then - assertEquals(14, cars.size()); - assertEquals(1, ListUtils.filter(cars, (i, it) -> Objects.equals(it.qualifier, "my_qualifier_a")).size()); - assertEquals(1, ListUtils.filter(cars, (i, it) -> Objects.equals(it.qualifier, "qualifier_multi_a2")).size()); - assertEquals(1, ListUtils.filter(cars, (i, it) -> Objects.equals(it.qualifier, "qualifier_multi_a2_hard")).size()); - } - - -} diff --git a/tests_wraps/src/test/java/com/github/klee0kai/stone/test/car/qualifiers/CarProvideWithQualifiersTests.java b/tests_wraps/src/test/java/com/github/klee0kai/stone/test/car/qualifiers/CarProvideWithQualifiersTests.java deleted file mode 100644 index 57ba98ed..00000000 --- a/tests_wraps/src/test/java/com/github/klee0kai/stone/test/car/qualifiers/CarProvideWithQualifiersTests.java +++ /dev/null @@ -1,153 +0,0 @@ -package com.github.klee0kai.stone.test.car.qualifiers; - -import com.github.klee0kai.stone.Stone; -import com.github.klee0kai.test.car.di.qualifiers.CarQComponent; -import com.github.klee0kai.test.car.model.Car; -import org.junit.jupiter.api.Test; - -import static org.junit.jupiter.api.Assertions.assertEquals; - -public class CarProvideWithQualifiersTests { - - @Test - void namedEmptyProvideTest() { - //Given - CarQComponent DI = Stone.createComponent(CarQComponent.class); - - //When - Car car = DI.carNamedEmpty(); - - //Then - assertEquals("named_empty", car.qualifier); - assertEquals("simple", car.bumpers.get(0).qualifier); - assertEquals(5, car.wheels.size(), "four wheel +1"); - } - - @Test - void namedAProvideTest() { - //Given - CarQComponent DI = Stone.createComponent(CarQComponent.class); - - //When - Car car = DI.carNameA(); - - //Then - assertEquals("named_a", car.qualifier); - assertEquals("reinforced", car.bumpers.get(0).qualifier); - assertEquals(5, car.wheels.size(), "four wheel +1"); - } - - @Test - void carMyQualifierProvideTest() { - //Given - CarQComponent DI = Stone.createComponent(CarQComponent.class); - - //When - Car car = DI.carMyQualifier(); - - //Then - assertEquals("my_qualifier", car.qualifier); - assertEquals("simple", car.bumpers.get(0).qualifier); - assertEquals(5, car.wheels.size(), "four wheel +1"); - } - - @Test - void carMyQualifierStringProvideTest() { - //Given - CarQComponent DI = Stone.createComponent(CarQComponent.class); - - //When - Car car = DI.carMyQualifierString(); - - //Then - assertEquals("my_qualifier_with_string", car.qualifier); - assertEquals("simple", car.bumpers.get(0).qualifier); - assertEquals(5, car.wheels.size(), "four wheel +1"); - } - - @Test - void carMyQualifierStringAProvideTest() { - //Given - CarQComponent DI = Stone.createComponent(CarQComponent.class); - - //When - Car car = DI.carMyQualifierStringA(); - - //Then - assertEquals("my_qualifier_a", car.qualifier); - assertEquals("reinforced", car.bumpers.get(0).qualifier); - assertEquals(4, car.wheels.size(), "four wheel +1"); - } - - @Test - void carMyQualifierStringBProvideTest() { - //Given - CarQComponent DI = Stone.createComponent(CarQComponent.class); - - //When - Car car = DI.carMyQualifierStringB(); - - //Then - assertEquals("my_qualifier_b", car.qualifier); - assertEquals("simple", car.bumpers.get(0).qualifier); - assertEquals(5, car.wheels.size(), "four wheel +1"); - } - - @Test - void carMyQualifierMultiProvideTest() { - //Given - CarQComponent DI = Stone.createComponent(CarQComponent.class); - - //When - Car car = DI.carMyQualifierMulti(); - - //Then - assertEquals("qualifier_multi", car.qualifier); - assertEquals("simple", car.bumpers.get(0).qualifier); - assertEquals(4, car.wheels.size()); - } - - @Test - void carMyQualifierMultiA1ProvideTest() { - //Given - CarQComponent DI = Stone.createComponent(CarQComponent.class); - - //When - Car car = DI.carMyQualifierMultiA1(); - - //Then - assertEquals("qualifier_multi_a1", car.qualifier); - assertEquals("simple", car.bumpers.get(0).qualifier); - assertEquals(5, car.wheels.size(), "four wheel +1"); - } - - - @Test - void carMyQualifierMultiA2ProvideTest() { - //Given - CarQComponent DI = Stone.createComponent(CarQComponent.class); - - //When - Car car = DI.carMyQualifierMultiA2(); - - //Then - assertEquals("qualifier_multi_a2", car.qualifier); - assertEquals("reinforced", car.bumpers.get(0).qualifier); - assertEquals(4, car.wheels.size()); - } - - @Test - void carMyQualifierMultiA2HardProvideTest() { - //Given - CarQComponent DI = Stone.createComponent(CarQComponent.class); - - //When - Car car = DI.carMyQualifierMultiA2Hard(); - - //Then - assertEquals("qualifier_multi_a2_hard", car.qualifier); - assertEquals("simple", car.bumpers.get(0).qualifier); - assertEquals(4, car.wheels.size()); - } - -} diff --git a/tests_wraps/src/test/java/com/github/klee0kai/stone/test/car/wrapper/CarSingleWrapperTests.java b/tests_wraps/src/test/java/com/github/klee0kai/stone/test/car/wrapper/CarSingleWrapperTests.java deleted file mode 100644 index 1deaf45e..00000000 --- a/tests_wraps/src/test/java/com/github/klee0kai/stone/test/car/wrapper/CarSingleWrapperTests.java +++ /dev/null @@ -1,234 +0,0 @@ -package com.github.klee0kai.stone.test.car.wrapper; - -import com.github.klee0kai.stone.Stone; -import com.github.klee0kai.stone.wrappers.AsyncProvide; -import com.github.klee0kai.stone.wrappers.LazyProvide; -import com.github.klee0kai.test.car.di.wrapped.create.CarWrappedCreateComponent; -import com.github.klee0kai.test.car.model.Bumper; -import com.github.klee0kai.test.car.model.Car; -import com.github.klee0kai.test.car.model.Wheel; -import com.github.klee0kai.test.car.model.Window; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; - -import javax.inject.Provider; -import java.lang.ref.WeakReference; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotNull; - -public class CarSingleWrapperTests { - - @BeforeEach - public void init() { - Bumper.createCount = 0; - Window.createCount = 0; - Wheel.createCount = 0; - Car.createCount = 0; - } - - @Test - public void wheelSimpleTest() { - //Given - CarWrappedCreateComponent DI = Stone.createComponent(CarWrappedCreateComponent.class); - - //When - Wheel wheel1 = DI.wheel(); - Wheel wheel2 = DI.wheel(); - - // Then - assertEquals(1, Wheel.createCount); - assertNotNull(wheel1.uuid); - assertEquals(wheel1.uuid, wheel2.uuid); - } - - @Test - public void wheelProvideTest() { - //Given - CarWrappedCreateComponent DI = Stone.createComponent(CarWrappedCreateComponent.class); - - //When - Provider wheel1 = DI.wheelProvide(); - Provider wheel2 = DI.wheelProvide(); - - // Then - assertNotNull(wheel1.get().uuid); - assertEquals(wheel1.get().uuid, wheel2.get().uuid); - assertEquals(1, Wheel.createCount); - } - - @Test - public void wheelLazyTest() { - //Given - CarWrappedCreateComponent DI = Stone.createComponent(CarWrappedCreateComponent.class); - - //When - LazyProvide wheel1 = DI.wheelLazy(); - LazyProvide wheel2 = DI.wheelLazy(); - - // Then - assertNotNull(wheel1.get().uuid); - assertEquals(wheel1.get().uuid, wheel2.get().uuid); - assertEquals(1, Wheel.createCount); - } - - - @Test - public void wheelWeakTest() { - //Given - CarWrappedCreateComponent DI = Stone.createComponent(CarWrappedCreateComponent.class); - - //When - WeakReference wheel1 = DI.wheelWeak(); - WeakReference wheel2 = DI.wheelWeak(); - - // Then - assertEquals(1, Wheel.createCount); - assertNotNull(wheel1.get().uuid); - assertEquals(wheel1.get().uuid, wheel2.get().uuid); - } - - - @Test - public void wheelProvideWeakTest() { - //Given - CarWrappedCreateComponent DI = Stone.createComponent(CarWrappedCreateComponent.class); - - //When - Provider> wheel1 = DI.whellProviderWeak(); - Provider> wheel2 = DI.whellProviderWeak(); - - // Then - assertNotNull(wheel1.get().get().uuid); - assertEquals(wheel1.get().get().uuid, wheel2.get().get().uuid); - assertEquals(1, Wheel.createCount); - } - - - @Test - public void wheelLazyProvideWeakTest() { - //Given - CarWrappedCreateComponent DI = Stone.createComponent(CarWrappedCreateComponent.class); - - //When - LazyProvide>> wheel1 = DI.whellLazyProviderWeak(); - LazyProvide>> wheel2 = DI.whellLazyProviderWeak(); - - // Then - assertNotNull(wheel1.get().get().get().uuid); - assertEquals(wheel1.get().get().get().uuid, wheel2.get().get().get().uuid); - assertEquals(1, Wheel.createCount); - } - - - @Test - public void wheelProviderTest() { - //Given - CarWrappedCreateComponent DI = Stone.createComponent(CarWrappedCreateComponent.class); - - //When - Provider wheel1 = DI.whellProvider(); - Provider wheel2 = DI.whellProvider(); - - // Then - assertNotNull(wheel1.get().uuid); - assertEquals(wheel1.get().uuid, wheel2.get().uuid); - assertEquals(1, Wheel.createCount); - } - - - @Test - public void carLazyTest() { - //Given - CarWrappedCreateComponent DI = Stone.createComponent(CarWrappedCreateComponent.class); - - //When - LazyProvide car1 = DI.carLazy(); - LazyProvide car2 = DI.carLazy(); - - // Then - assertEquals(0, Car.createCount); - assertNotNull(car1.get().uuid); - assertEquals(car1.get().uuid, car2.get().uuid); - assertEquals(1, Car.createCount); - } - - @Test - public void carAsyncTest() { - //Given - CarWrappedCreateComponent DI = Stone.createComponent(CarWrappedCreateComponent.class); - - //When - AsyncProvide car1 = DI.carAsync(); - AsyncProvide car2 = DI.carAsync(); - - // Then - assertNotNull(car1.get().uuid); - assertEquals(car1.get().uuid, car2.get().uuid); - assertEquals(1, Car.createCount); - } - - - @Test - public void carProvideTest() { - //Given - CarWrappedCreateComponent DI = Stone.createComponent(CarWrappedCreateComponent.class); - - //When - Provider car1 = DI.carProvider(); - Provider car2 = DI.carProvider(); - - // Then - assertEquals(0, Car.createCount); - assertNotNull(car1.get().uuid); - assertEquals(car1.get().uuid, car2.get().uuid); - assertEquals(1, Car.createCount); - } - - - @Test - public void carWeakTest() { - //Given - CarWrappedCreateComponent DI = Stone.createComponent(CarWrappedCreateComponent.class); - - //When - WeakReference car1 = DI.carWeak(); - WeakReference car2 = DI.carWeak(); - - // Then - assertEquals(1, Car.createCount); - assertNotNull(car1.get().uuid); - assertEquals(car1.get().uuid, car2.get().uuid); - } - - @Test - public void windowTest() { - //Given - CarWrappedCreateComponent DI = Stone.createComponent(CarWrappedCreateComponent.class); - - //When - Window window1 = DI.window(); - Window window2 = DI.window(); - - // Then - assertEquals(1, Window.createCount); - assertNotNull(window1.uuid); - assertEquals(window1.uuid, window2.uuid); - } - - @Test - public void carTest() { - //Given - CarWrappedCreateComponent DI = Stone.createComponent(CarWrappedCreateComponent.class); - - //When - Car car1 = DI.car(); - Car car2 = DI.car(); - - // Then - assertEquals(1, Car.createCount); - assertNotNull(car1.uuid); - assertEquals(car1.uuid, car2.uuid); - } - -} diff --git a/tests_wraps/src/test/java/com/github/klee0kai/stone/test/car/wrapper/CurCustomWrapperTests.java b/tests_wraps/src/test/java/com/github/klee0kai/stone/test/car/wrapper/CurCustomWrapperTests.java deleted file mode 100644 index df7db54d..00000000 --- a/tests_wraps/src/test/java/com/github/klee0kai/stone/test/car/wrapper/CurCustomWrapperTests.java +++ /dev/null @@ -1,89 +0,0 @@ -package com.github.klee0kai.stone.test.car.wrapper; - -import com.github.klee0kai.stone.Stone; -import com.github.klee0kai.test.car.di.wrapped.custom.CarCustomWrappersComponent; -import com.github.klee0kai.test.car.di.wrapped.custom.wrappers.CarLazy; -import com.github.klee0kai.test.car.di.wrapped.custom.wrappers.CarProvide; -import com.github.klee0kai.test.car.di.wrapped.custom.wrappers.CarRef; -import com.github.klee0kai.test.car.model.Car; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; - -import static org.junit.jupiter.api.Assertions.*; - -public class CurCustomWrapperTests { - - @BeforeEach - public void init() { - Car.createCount = 0; - } - - @Test - public void carTest() { - //Given - CarCustomWrappersComponent DI = Stone.createComponent(CarCustomWrappersComponent.class); - - //When - Car car1 = DI.car(); - Car car2 = DI.car(); - - // Then - assertEquals(2, Car.createCount); - assertNotNull(car1.uuid); - assertNotEquals(car1.uuid, car2.uuid, "factory create"); - } - - - @Test - public void carLayTest() { - //Given - CarCustomWrappersComponent DI = Stone.createComponent(CarCustomWrappersComponent.class); - - //When - CarLazy car1 = DI.carLazy(); - CarLazy car2 = DI.carLazy(); - - // Then - assertEquals(0, Car.createCount); - assertNotNull(car1.getValue().uuid); - assertEquals(car1.getValue().uuid, car1.getValue().uuid); - assertNotEquals(car1.getValue().uuid, car2.getValue().uuid); - assertEquals(2, Car.createCount); - } - - @Test - public void carProvideTest() { - //Given - CarCustomWrappersComponent DI = Stone.createComponent(CarCustomWrappersComponent.class); - - //When - CarProvide car1 = DI.carProvide(); - CarProvide car2 = DI.carProvide(); - - // Then - assertEquals(0, Car.createCount); - assertNotNull(car1.getValue().uuid); - assertNotEquals(car1.getValue().uuid, car1.getValue().uuid); - assertNotEquals(car1.getValue().uuid, car2.getValue().uuid); - assertEquals(5, Car.createCount, "getValue has been called 5 times"); - } - - - @Test - public void carRefTest() { - //Given - CarCustomWrappersComponent DI = Stone.createComponent(CarCustomWrappersComponent.class); - - //When - CarRef car1 = DI.carRef(); - CarRef car2 = DI.carRef(); - - // Then - assertEquals(2, Car.createCount); - assertNotNull(car1.getValue().uuid); - assertNotEquals(car1.getValue().uuid, car2.getValue().uuid); - assertEquals(car1.getValue().uuid, car1.getValue().uuid); - } - - -} diff --git a/tests_wraps_kotlin/build.gradle.kts b/tests_wraps_kotlin/build.gradle.kts index 5925044e..5948c0ca 100644 --- a/tests_wraps_kotlin/build.gradle.kts +++ b/tests_wraps_kotlin/build.gradle.kts @@ -1,6 +1,6 @@ plugins { alias(libs.plugins.kotlin.jvm) - alias(libs.plugins.kotlin.kapt) + alias(libs.plugins.kotlin.ksp) } tasks.test { @@ -10,8 +10,8 @@ tasks.test { dependencies { implementation(project(":tests")) - implementation(project(":kotlin_lib")) - kapt(project(":stone_processor")) + implementation(project(":stone_multiplatform")) + ksp(project(":stone_ksp")) testImplementation(libs.bundles.junit) } diff --git a/tests_wraps_kotlin/src/main/kotlin/com/github/klee0kai/test/boxed/di/inject/CarBoxedInjectModule.kt b/tests_wraps_kotlin/src/main/kotlin/com/github/klee0kai/test/boxed/di/inject/CarBoxedInjectModule.kt index 1fa659f5..896a7d58 100644 --- a/tests_wraps_kotlin/src/main/kotlin/com/github/klee0kai/test/boxed/di/inject/CarBoxedInjectModule.kt +++ b/tests_wraps_kotlin/src/main/kotlin/com/github/klee0kai/test/boxed/di/inject/CarBoxedInjectModule.kt @@ -2,13 +2,12 @@ package com.github.klee0kai.test.boxed.di.inject import com.github.klee0kai.stone.annotations.module.Module import com.github.klee0kai.stone.annotations.module.Provide -import com.github.klee0kai.stone.wrappers.Ref +import com.github.klee0kai.stone.weakref.Ref import com.github.klee0kai.test.boxed.model.CarBox import com.github.klee0kai.test.car.model.Bumper import com.github.klee0kai.test.car.model.Wheel import com.github.klee0kai.test.car.model.Window import java.lang.ref.WeakReference -import java.util.* import javax.inject.Named import javax.inject.Provider diff --git a/tests_wraps_kotlin/src/main/kotlin/com/github/klee0kai/test/boxed/model/CarBoxedInjectProvider.kt b/tests_wraps_kotlin/src/main/kotlin/com/github/klee0kai/test/boxed/model/CarBoxedInjectProvider.kt index 9050208b..c1d53681 100644 --- a/tests_wraps_kotlin/src/main/kotlin/com/github/klee0kai/test/boxed/model/CarBoxedInjectProvider.kt +++ b/tests_wraps_kotlin/src/main/kotlin/com/github/klee0kai/test/boxed/model/CarBoxedInjectProvider.kt @@ -1,7 +1,7 @@ package com.github.klee0kai.test.boxed.model +import com.github.klee0kai.stone.weakref.Ref import com.github.klee0kai.stone.wrappers.LazyProvide -import com.github.klee0kai.stone.wrappers.Ref import com.github.klee0kai.test.car.di.wrapped.custom.wrappers.CarLazy import com.github.klee0kai.test.car.model.Bumper import com.github.klee0kai.test.car.model.Wheel diff --git a/tests_wraps_kotlin/src/main/kotlin/com/github/klee0kai/test/car/di/bestOf/both/BothCarModule.kt b/tests_wraps_kotlin/src/main/kotlin/com/github/klee0kai/test/car/di/bestOf/both/BothCarModule.kt index ab5ed2db..802675e1 100644 --- a/tests_wraps_kotlin/src/main/kotlin/com/github/klee0kai/test/car/di/bestOf/both/BothCarModule.kt +++ b/tests_wraps_kotlin/src/main/kotlin/com/github/klee0kai/test/car/di/bestOf/both/BothCarModule.kt @@ -2,7 +2,7 @@ package com.github.klee0kai.test.car.di.bestOf.both import com.github.klee0kai.stone.annotations.module.Module import com.github.klee0kai.stone.annotations.module.Provide -import com.github.klee0kai.stone.wrappers.Ref +import com.github.klee0kai.stone.weakref.Ref import com.github.klee0kai.test.car.model.Bumper import com.github.klee0kai.test.car.model.Car import com.github.klee0kai.test.car.model.Wheel diff --git a/tests_wraps_kotlin/src/main/kotlin/com/github/klee0kai/test/car/di/bindinstance/simple/CarBindComponent.kt b/tests_wraps_kotlin/src/main/kotlin/com/github/klee0kai/test/car/di/bindinstance/simple/CarBindComponent.kt index e0014f85..749dfb85 100644 --- a/tests_wraps_kotlin/src/main/kotlin/com/github/klee0kai/test/car/di/bindinstance/simple/CarBindComponent.kt +++ b/tests_wraps_kotlin/src/main/kotlin/com/github/klee0kai/test/car/di/bindinstance/simple/CarBindComponent.kt @@ -2,7 +2,7 @@ package com.github.klee0kai.test.car.di.bindinstance.simple import com.github.klee0kai.stone.annotations.component.Component import com.github.klee0kai.stone.annotations.module.BindInstance -import com.github.klee0kai.stone.wrappers.Ref +import com.github.klee0kai.stone.weakref.Ref import com.github.klee0kai.test.car.model.Bumper import com.github.klee0kai.test.car.model.Wheel import com.github.klee0kai.test.car.model.Window diff --git a/tests_wraps_kotlin/src/main/kotlin/com/github/klee0kai/test/car/di/inject/CarInjectModule.kt b/tests_wraps_kotlin/src/main/kotlin/com/github/klee0kai/test/car/di/inject/CarInjectModule.kt index d8deec3d..3e629553 100644 --- a/tests_wraps_kotlin/src/main/kotlin/com/github/klee0kai/test/car/di/inject/CarInjectModule.kt +++ b/tests_wraps_kotlin/src/main/kotlin/com/github/klee0kai/test/car/di/inject/CarInjectModule.kt @@ -2,7 +2,7 @@ package com.github.klee0kai.test.car.di.inject import com.github.klee0kai.stone.annotations.module.Module import com.github.klee0kai.stone.annotations.module.Provide -import com.github.klee0kai.stone.wrappers.Ref +import com.github.klee0kai.stone.weakref.Ref import com.github.klee0kai.test.car.model.Bumper import com.github.klee0kai.test.car.model.Wheel import com.github.klee0kai.test.car.model.Window diff --git a/tests_wraps_kotlin/src/main/kotlin/com/github/klee0kai/test/car/di/lists/cached/CarMultiCachedComponent.kt b/tests_wraps_kotlin/src/main/kotlin/com/github/klee0kai/test/car/di/lists/cached/CarMultiCachedComponent.kt index 69c15f5f..12096c04 100644 --- a/tests_wraps_kotlin/src/main/kotlin/com/github/klee0kai/test/car/di/lists/cached/CarMultiCachedComponent.kt +++ b/tests_wraps_kotlin/src/main/kotlin/com/github/klee0kai/test/car/di/lists/cached/CarMultiCachedComponent.kt @@ -1,7 +1,7 @@ package com.github.klee0kai.test.car.di.lists.cached import com.github.klee0kai.stone.annotations.component.Component -import com.github.klee0kai.stone.wrappers.Ref +import com.github.klee0kai.stone.weakref.Ref import com.github.klee0kai.test.car.model.Bumper import com.github.klee0kai.test.car.model.Car import com.github.klee0kai.test.car.model.Wheel diff --git a/tests_wraps_kotlin/src/main/kotlin/com/github/klee0kai/test/car/di/lists/cached/CarMultiCachedModule.kt b/tests_wraps_kotlin/src/main/kotlin/com/github/klee0kai/test/car/di/lists/cached/CarMultiCachedModule.kt index 2c9cf63a..2212081b 100644 --- a/tests_wraps_kotlin/src/main/kotlin/com/github/klee0kai/test/car/di/lists/cached/CarMultiCachedModule.kt +++ b/tests_wraps_kotlin/src/main/kotlin/com/github/klee0kai/test/car/di/lists/cached/CarMultiCachedModule.kt @@ -2,6 +2,7 @@ package com.github.klee0kai.test.car.di.lists.cached import com.github.klee0kai.stone.annotations.module.Module import com.github.klee0kai.stone.annotations.module.Provide +import com.github.klee0kai.stone.weakref.Ref import com.github.klee0kai.stone.wrappers.Ref import com.github.klee0kai.test.car.model.Bumper import com.github.klee0kai.test.car.model.Car diff --git a/tests_wraps_kotlin/src/main/kotlin/com/github/klee0kai/test/car/di/lists/factory/CarMultiComponent.kt b/tests_wraps_kotlin/src/main/kotlin/com/github/klee0kai/test/car/di/lists/factory/CarMultiComponent.kt index 5c72f8aa..ad8d04ad 100644 --- a/tests_wraps_kotlin/src/main/kotlin/com/github/klee0kai/test/car/di/lists/factory/CarMultiComponent.kt +++ b/tests_wraps_kotlin/src/main/kotlin/com/github/klee0kai/test/car/di/lists/factory/CarMultiComponent.kt @@ -1,7 +1,7 @@ package com.github.klee0kai.test.car.di.lists.factory -import com.github.klee0kai.stone.annotations.component.* -import com.github.klee0kai.stone.wrappers.Ref +import com.github.klee0kai.stone.annotations.component.Component +import com.github.klee0kai.stone.weakref.Ref import com.github.klee0kai.test.car.model.Bumper import com.github.klee0kai.test.car.model.Car import com.github.klee0kai.test.car.model.Wheel diff --git a/tests_wraps_kotlin/src/main/kotlin/com/github/klee0kai/test/car/di/lists/factory/CarMultiModule.kt b/tests_wraps_kotlin/src/main/kotlin/com/github/klee0kai/test/car/di/lists/factory/CarMultiModule.kt index a436f006..a82cbd97 100644 --- a/tests_wraps_kotlin/src/main/kotlin/com/github/klee0kai/test/car/di/lists/factory/CarMultiModule.kt +++ b/tests_wraps_kotlin/src/main/kotlin/com/github/klee0kai/test/car/di/lists/factory/CarMultiModule.kt @@ -2,7 +2,7 @@ package com.github.klee0kai.test.car.di.lists.factory import com.github.klee0kai.stone.annotations.module.Module import com.github.klee0kai.stone.annotations.module.Provide -import com.github.klee0kai.stone.wrappers.Ref +import com.github.klee0kai.stone.weakref.Ref import com.github.klee0kai.test.car.model.Bumper import com.github.klee0kai.test.car.model.Car import com.github.klee0kai.test.car.model.Wheel diff --git a/tests_wraps_kotlin/src/main/kotlin/com/github/klee0kai/test/car/di/qualifiers/CarQPModule.kt b/tests_wraps_kotlin/src/main/kotlin/com/github/klee0kai/test/car/di/qualifiers/CarQPModule.kt index e871ed2f..0ed5d2fb 100644 --- a/tests_wraps_kotlin/src/main/kotlin/com/github/klee0kai/test/car/di/qualifiers/CarQPModule.kt +++ b/tests_wraps_kotlin/src/main/kotlin/com/github/klee0kai/test/car/di/qualifiers/CarQPModule.kt @@ -2,7 +2,7 @@ package com.github.klee0kai.test.car.di.qualifiers import com.github.klee0kai.stone.annotations.module.Module import com.github.klee0kai.stone.annotations.module.Provide -import com.github.klee0kai.stone.wrappers.Ref +import com.github.klee0kai.stone.weakref.Ref import com.github.klee0kai.test.car.di.qualifiers.qualifiers.BumperQualifier import com.github.klee0kai.test.car.di.qualifiers.qualifiers.WheelCount import com.github.klee0kai.test.car.model.Bumper From 23488f25c619d23b2bd43d5920c7e123bdbf84e7 Mon Sep 17 00:00:00 2001 From: klee0kai Date: Sat, 20 Dec 2025 22:55:19 +0100 Subject: [PATCH 080/122] wrappers support processor --- .../klee0kai/thekey/stone/ksp/Processor.kt | 6 +- .../thekey/stone/ksp/exceptions/WrapExt.kt | 11 +++ .../ksp/helpers/ComponentDeclarationExt.kt | 16 +--- .../helpers/annotations/ComponentAnnMirror.kt | 19 +++++ .../ksp/helpers/invokecall/InvokeCall.kt | 56 ++++++------- .../ksp/helpers/invokecall/ModulesGraph.kt | 8 +- .../stone/ksp/helpers/wrap/WrapHelper.kt | 6 +- .../ksp/target/component/ComponentGraphExt.kt | 83 ++++++++++++++++++- .../target/component/GenComponentProcessor.kt | 1 - .../wrapper/GenWrappersSupportProcessor.kt | 81 ++++++++++++++++++ .../stone/wrappers/KotlinWrappersStone.kt | 2 +- .../wrappers/creators/ProviderWrapper.kt | 2 +- .../di/inject/CarBoxedInjectComponent.kt | 7 +- .../car/di/lists/factory/CarMultiComponent.kt | 10 ++- .../test/car/di/qualifiers/CarQCModule.kt | 1 + .../create/CarWrappedCreateComponent.kt | 4 +- .../car/di/wrapped/custom/wrappers/CarLazy.kt | 2 +- .../custom/wrappers/CarProviderWrapper.kt | 25 ++++-- .../test/car/model/CarInjectProvider.kt | 2 +- 19 files changed, 267 insertions(+), 75 deletions(-) create mode 100644 stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/wrapper/GenWrappersSupportProcessor.kt diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/Processor.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/Processor.kt index 37fe009c..ecd32fb2 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/Processor.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/Processor.kt @@ -13,6 +13,7 @@ import com.github.klee0kai.thekey.stone.ksp.target.hiddenmodule.GenHiddenModuleP import com.github.klee0kai.thekey.stone.ksp.target.module.GenModuleCacheControlProcessor import com.github.klee0kai.thekey.stone.ksp.target.module.GenModuleFactoryProcessor import com.github.klee0kai.thekey.stone.ksp.target.module.GenModuleProcessor +import com.github.klee0kai.thekey.stone.ksp.target.wrapper.GenWrappersSupportProcessor import com.google.devtools.ksp.containingFile import com.google.devtools.ksp.processing.CodeGenerator import com.google.devtools.ksp.processing.KSPLogger @@ -63,7 +64,7 @@ class Processor( // force changes // debug = true -// debugPkgFilter = "com.github.klee0kai.test_ext.inject.di.base_phone" +// debugPkgFilter = "com.github.klee0kai.test.car.di.qualifiers" } @@ -74,6 +75,7 @@ class Processor( GenModuleProcessor(), GenHiddenModuleProcessor(), GenHiddenModuleCacheControlProcessor(), + GenWrappersSupportProcessor(), GenComponentProcessor(), ) @@ -147,7 +149,7 @@ class Processor( message = e.message ?: "", symbol = e.findLastErrorElement(), ) - throw e + throw e } } diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/exceptions/WrapExt.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/exceptions/WrapExt.kt index b765c01d..9c69bc76 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/exceptions/WrapExt.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/exceptions/WrapExt.kt @@ -2,6 +2,7 @@ package com.github.klee0kai.thekey.stone.ksp.exceptions import com.google.devtools.ksp.symbol.KSFunctionDeclaration import com.google.devtools.ksp.symbol.KSNode +import com.google.devtools.ksp.symbol.KSType inline fun T.wrapKsNoteInfo( ksNode: KSNode?, @@ -26,4 +27,14 @@ fun Sequence.forEachFun( action(idx, func) } } +} + +fun Sequence.forEachType( + action: (index: Int, KSType) -> Unit +) { + forEachIndexed { idx, type -> + wrapKsNoteInfo(type.declaration) { + action(idx, type) + } + } } \ No newline at end of file diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/ComponentDeclarationExt.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/ComponentDeclarationExt.kt index 4cb6185d..0449ac6a 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/ComponentDeclarationExt.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/ComponentDeclarationExt.kt @@ -17,8 +17,6 @@ import com.google.devtools.ksp.processing.Resolver import com.google.devtools.ksp.symbol.* import com.squareup.kotlinpoet.ClassName import com.squareup.kotlinpoet.asClassName -import com.squareup.kotlinpoet.ksp.toClassName -import com.squareup.kotlinpoet.ksp.toTypeName fun Resolver.findComponentForModuleOrDep( moduleCl: ClassName, @@ -90,20 +88,12 @@ val KSAnnotated.qualifierAnnotations: Sequence ) return annotations.filter { funAnnotation -> - standardQualifierAnnotations.any { funAnnotation.annotationType.resolve().declaration.isType(it) } - || funAnnotation.annotationType.resolve().annotations.any { annotationOfAnnotation -> - annotationOfAnnotation.annotationType.resolve().declaration.isType(Qualifier::class) + standardQualifierAnnotations.any { funAnnotation.annotationType.resolveAlias().declaration.isType(it) } + || funAnnotation.annotationType.resolveAlias().declaration.annotations.any { annotationOfAnnotation -> + annotationOfAnnotation.annotationType.resolveAlias().declaration.isType(Qualifier::class) } } } -fun KSAnnotation.isSameAsQualifier( - ann: KSAnnotation -): Boolean { - if (annotationType.resolve().toClassName() != ann.annotationType.resolve().toTypeName()) return false - val annArguments1 = arguments.map { it.name?.asString() to it.value }.sortedBy { it.first } - val annArguments2 = ann.arguments.map { it.name?.asString() to it.value }.sortedBy { it.first } - return annArguments1 == annArguments2 -} diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/annotations/ComponentAnnMirror.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/annotations/ComponentAnnMirror.kt index 445b16af..15b9d5b6 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/annotations/ComponentAnnMirror.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/annotations/ComponentAnnMirror.kt @@ -18,6 +18,10 @@ class ComponentAnnMirror( val wrapperProviders: List, ) +class WrapperCreatorAnnMirror( + val wrappers: List, +) + fun KSAnnotated.annotations( className: ClassName, ): Sequence = annotations @@ -88,3 +92,18 @@ fun KSAnnotated.findComponentAnnotation( wrapperProviders = wrapperProviders, ) } + +@Suppress("UNCHECKED_CAST") +fun KSAnnotated.findWrapperCreatorAnnotation( +): Sequence = annotations + .filter { it.annotationType.resolve().toTypeName() == WrappersCreator::class.asClassName() } + .map { compAnn -> + val wrappers = compAnn.arguments + .firstOrNull { it.name?.asString() == "wrappers" } + ?.value as? List + ?: emptyList() + + WrapperCreatorAnnMirror( + wrappers = wrappers, + ) + } diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/invokecall/InvokeCall.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/invokecall/InvokeCall.kt index 8165ad57..ea8de150 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/invokecall/InvokeCall.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/invokecall/InvokeCall.kt @@ -5,6 +5,7 @@ import com.github.klee0kai.thekey.stone.ksp.helpers.invokecall.model.FieldDetail import com.github.klee0kai.thekey.stone.ksp.helpers.invokecall.model.MethodDetail import com.github.klee0kai.thekey.stone.ksp.helpers.invokecall.model.QualifierAnn import com.github.klee0kai.thekey.stone.ksp.helpers.wrap.WrapHelper +import com.github.klee0kai.thekey.stone.ksp.poet.codeBlock import com.github.klee0kai.thekey.stone.ksp.utils.LocalFieldName import com.squareup.kotlinpoet.CodeBlock import com.squareup.kotlinpoet.ParameterizedTypeName.Companion.parameterizedBy @@ -60,11 +61,11 @@ class InvokeCall( for (invokeSequence in invokeSequenceVariants) { for (m in invokeSequence) { argsTypes.addAll( - m.args.map { + m.args.map { arg -> ProvideDep( methodName = null, - typeName = wrapHelper.listWrapTypeIfNeed(it.type), - qualifierAnns = m.qualifierAnns.toSet(), + typeName = wrapHelper.listWrapTypeIfNeed(arg.type), + qualifierAnns = arg.qualifierAnns.toSet(), ) }) } @@ -125,51 +126,42 @@ class InvokeCall( fun invokeAllToList( declaredFields: List, - ): CodeBlock { + ): CodeBlock = codeBlock { val provType = List::class.asClassName().parameterizedBy(resultType()) val listFieldName: String = LocalFieldName.genLocalFieldName() - - val builder = CodeBlock.builder() - - builder.add( + add( "%T{ %L -> \n", ProvideBuilder::class.asClassName().parameterizedBy(resultType()), listFieldName, ) - - builder.add(CodeBlock.of("buildList<%T>{ \n", resultType())) for (sequence in invokeSequenceVariants) { val invokeCall = InvokeCall.fromSequence(wrapHelper, sequence) val seqCodeBlock = invokeCall.invokeCode(declaredFields) if (wrapHelper.isList(invokeCall.rawReturnType())) { - builder - .add(listFieldName) - .add(".addAll(") - .add( - wrapHelper.transform( - invokeCall.rawReturnType(), - provType, - seqCodeBlock - ) + add( + "%L.addAll( %L );\n", + listFieldName, + wrapHelper.transform( + invokeCall.rawReturnType(), + provType, + seqCodeBlock ) - .add(");\n") + ) } else { - builder - .add(listFieldName) - .add(".add(") - .add( - wrapHelper.transform( - invokeCall.rawReturnType(), - resultType(), - seqCodeBlock - ) + add( + "%L.add( %L );\n", + listFieldName, + wrapHelper.transform( + invokeCall.rawReturnType(), + resultType(), + seqCodeBlock ) - .add(");\n") + ) } } - builder.add(" }.all() ") - return builder.build() + + add(" }.all();\n") } diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/invokecall/ModulesGraph.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/invokecall/ModulesGraph.kt index ab773bbd..7d1ce6ce 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/invokecall/ModulesGraph.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/invokecall/ModulesGraph.kt @@ -401,12 +401,8 @@ class ModulesGraph( val invokeCalls = provideTypeCodes.getOrDefault(typeName, null) if (invokeCalls == null || invokeCalls.isEmpty()) return null - var filtered = if (!listVariants || !qualifierAnns.isEmpty()) { - invokeCalls.filter { - it.qualifierAnnotations(false) == qualifierAnns - } - } else { - invokeCalls + var filtered = invokeCalls.filter { + it.qualifierAnnotations(false) == qualifierAnns } filtered = if (provideMethodName != null) { diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/wrap/WrapHelper.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/wrap/WrapHelper.kt index 63e74c84..0c59f2c9 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/wrap/WrapHelper.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/wrap/WrapHelper.kt @@ -108,8 +108,8 @@ class WrapHelper { if (providingType == wannaType) return code var codeBuilder = CodeBlock.builder().add(code) - val wrapPathNames = LinkedList(allParamTypes(wannaType)) - val unwrapPathNames = LinkedList(allParamTypes(providingType)) + val wrapPathNames = LinkedList(allParamTypes(wannaType)) + val unwrapPathNames = LinkedList(allParamTypes(providingType)) wrapPathNames.reverse() while (!wrapPathNames.isEmpty() && !unwrapPathNames.isEmpty() @@ -298,7 +298,7 @@ class WrapHelper { }, unwrap = { or, nullable -> CodeBlock.builder() - .add("%L.first( %L )", or) + .add("%L.first( )", or) .build() }, inListFormat = { originalListType, originalListCode, itemTransformFun -> diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/component/ComponentGraphExt.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/component/ComponentGraphExt.kt index ccaabc76..3674b799 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/component/ComponentGraphExt.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/component/ComponentGraphExt.kt @@ -1,17 +1,94 @@ package com.github.klee0kai.thekey.stone.ksp.target.component +import com.github.klee0kai.stone.wrappers.creators.CircleWrapper +import com.github.klee0kai.stone.wrappers.creators.ProviderWrapper +import com.github.klee0kai.stone.wrappers.creators.Wrapper +import com.github.klee0kai.thekey.stone.ksp.exceptions.IncorrectSignatureException import com.github.klee0kai.thekey.stone.ksp.helpers.allIdentifierTypes +import com.github.klee0kai.thekey.stone.ksp.helpers.allParentDeclarations import com.github.klee0kai.thekey.stone.ksp.helpers.annotations.findComponentAnnotation +import com.github.klee0kai.thekey.stone.ksp.helpers.annotations.findWrapperCreatorAnnotation import com.github.klee0kai.thekey.stone.ksp.helpers.invokecall.ModulesGraph +import com.github.klee0kai.thekey.stone.ksp.helpers.wrap.ClassNameUtils import com.github.klee0kai.thekey.stone.ksp.helpers.wrap.WrapHelper -import com.github.klee0kai.thekey.stone.ksp.ksp.getAllMethods +import com.github.klee0kai.thekey.stone.ksp.helpers.wrap.WrapType +import com.github.klee0kai.thekey.stone.ksp.helpers.wrapperStoneClName +import com.github.klee0kai.thekey.stone.ksp.ksp.isType +import com.github.klee0kai.thekey.stone.ksp.poet.codeBlock +import com.github.klee0kai.thekey.stone.ksp.target.wrapper.GenWrappersSupportProcessor.Companion.provideWrappersGlFieldPrefixName import com.google.devtools.ksp.symbol.KSClassDeclaration +import com.squareup.kotlinpoet.ksp.toTypeName fun KSClassDeclaration.collectWrapHelper( ): WrapHelper { val wrapHelper = WrapHelper() - val wrapperProviders = findComponentAnnotation().flatMap { it.wrapperProviders } - // TODO + val wrapperProviders = allParentDeclarations + .filter { it.findComponentAnnotation().any() } + .flatMap { parentComponentCl -> + parentComponentCl.findComponentAnnotation().firstOrNull()?.wrapperProviders ?: emptyList() + } + + val wrapperCreatorClName = wrapperStoneClName + wrapperProviders.forEachIndexed { index, provideWrappersCl -> + val name = provideWrappersGlFieldPrefixName + index + val provideWrappersClDecl = provideWrappersCl.declaration as? KSClassDeclaration ?: return@forEachIndexed + val isSimpleWrapper = provideWrappersClDecl.allParentDeclarations.any { it.isType(Wrapper::class) } + val isAsyncWrapper = provideWrappersClDecl.allParentDeclarations.any { it.isType(ProviderWrapper::class) } + val isCycleWrapper = provideWrappersClDecl.allParentDeclarations.any { it.isType(CircleWrapper::class) } + val wrappers = provideWrappersClDecl.findWrapperCreatorAnnotation() + .firstOrNull()?.wrappers ?: return@forEachIndexed + + for (wrapper in wrappers) { + val rawTypeName = ClassNameUtils.rawTypeOf(wrapper.toTypeName()) + wrapHelper.support( + WrapType( + isNoCachingWrapper = !isAsyncWrapper, + typeName = rawTypeName, + wrap = { or, nullable -> + codeBlock { + if (isSimpleWrapper) { + add( + "%T.%L.wrap( %T::class , %L )", + wrapperCreatorClName, + name, + rawTypeName, + or, + ) + } else if (isAsyncWrapper || isCycleWrapper) { + add( + "%T.%L.wrap( %T::class , { %L } )", + wrapperCreatorClName, + name, + rawTypeName, + or, + ) + } else { + throw IncorrectSignatureException("Type Transform non support to ${wrapper.toTypeName()}") + } + } + }, + unwrap = { or, nullable -> + codeBlock { + val paramType = wrapHelper.paramType(wrapper.toTypeName()) + + if (isCycleWrapper) { + add( + "%T.%L.unwrap( %T::class , %T::class, %L )", + wrapperCreatorClName, + name, + rawTypeName, + paramType, + or + ) + } else { + throw IncorrectSignatureException("Type Transform non support to ${wrapper.toTypeName()}") + } + } + } + ) + ) + } + } return wrapHelper } diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/component/GenComponentProcessor.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/component/GenComponentProcessor.kt index 4e5bdedc..f2664b71 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/component/GenComponentProcessor.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/component/GenComponentProcessor.kt @@ -407,7 +407,6 @@ class GenComponentProcessor : TargetFileProcessor { modulesGraph: ModulesGraph, ) { val identifierTypes = componentCl.allIdentifierTypes.toList() - val idArguments = method.parameters.identifierParameters(identifierTypes) val lifeCycleOwnerArg = method.parameters.lifeCycleParameter() val injectableArguments = method.parameters.notIdentifierParameters(identifierTypes) if (injectableArguments.isEmpty()) { diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/wrapper/GenWrappersSupportProcessor.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/wrapper/GenWrappersSupportProcessor.kt new file mode 100644 index 00000000..759ab690 --- /dev/null +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/wrapper/GenWrappersSupportProcessor.kt @@ -0,0 +1,81 @@ +package com.github.klee0kai.thekey.stone.ksp.target.wrapper + +import com.github.klee0kai.stone.annotations.component.Component +import com.github.klee0kai.thekey.stone.ksp.exceptions.forEachType +import com.github.klee0kai.thekey.stone.ksp.helpers.allParentDeclarations +import com.github.klee0kai.thekey.stone.ksp.helpers.annotations.findComponentAnnotation +import com.github.klee0kai.thekey.stone.ksp.helpers.wrapperStoneClName +import com.github.klee0kai.thekey.stone.ksp.ksp.arch.GenSpec +import com.github.klee0kai.thekey.stone.ksp.ksp.arch.SymbolsToProcess +import com.github.klee0kai.thekey.stone.ksp.ksp.arch.TargetFileProcessor +import com.github.klee0kai.thekey.stone.ksp.poet.genFileSpec +import com.github.klee0kai.thekey.stone.ksp.poet.genLibComment +import com.github.klee0kai.thekey.stone.ksp.poet.genObject +import com.github.klee0kai.thekey.stone.ksp.poet.genProperty +import com.google.devtools.ksp.containingFile +import com.google.devtools.ksp.processing.KSPLogger +import com.google.devtools.ksp.processing.Resolver +import com.google.devtools.ksp.symbol.KSAnnotated +import com.google.devtools.ksp.symbol.KSClassDeclaration +import com.squareup.kotlinpoet.asClassName +import com.squareup.kotlinpoet.ksp.toClassName +import com.google.devtools.ksp.processing.Dependencies as KspDependencies + + +class GenWrappersSupportProcessor : TargetFileProcessor { + + companion object { + val provideWrappersGlFieldPrefixName = "__wrapperCreator" + + + val allReserveMethodNames = listOf( + provideWrappersGlFieldPrefixName, + ) + } + + + override suspend fun findSymbolsToProcess( + resolver: Resolver + ) = SymbolsToProcess( + symbolsForProcessing = resolver + .getSymbolsWithAnnotation(Component::class.asClassName().canonicalName) + .toList(), + symbolsForReprocessing = emptyList(), + ) + + override suspend fun process( + validSymbol: KSAnnotated, + resolver: Resolver, + options: Map, + logger: KSPLogger + ): GenSpec? { + val fileOwner = validSymbol.containingFile ?: return null + val componentCl = validSymbol as? KSClassDeclaration ?: return null + val wrapperProviders = componentCl.allParentDeclarations + .filter { it.findComponentAnnotation().any() } + .flatMap { parentComponentCl -> + parentComponentCl.findComponentAnnotation().firstOrNull()?.wrapperProviders ?: emptyList() + } + + val wrapperCreatorClName = componentCl.wrapperStoneClName + val fileSpec = genFileSpec(wrapperCreatorClName.packageName, wrapperCreatorClName.simpleName) { + genLibComment() + + genObject(wrapperCreatorClName) { + wrapperProviders.forEachType { index, provideWrappersCl -> + val name = provideWrappersGlFieldPrefixName + index + + genProperty(name, provideWrappersCl.toClassName()) { + initializer("%T()", provideWrappersCl.toClassName()) + } + } + } + } + + return GenSpec( + fileSpec = fileSpec, + // https://kotlinlang.org/docs/ksp-incremental.html + dependencies = KspDependencies(aggregating = false, fileOwner), + ) + } +} \ No newline at end of file diff --git a/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/wrappers/KotlinWrappersStone.kt b/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/wrappers/KotlinWrappersStone.kt index 15e42b06..ef690663 100644 --- a/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/wrappers/KotlinWrappersStone.kt +++ b/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/wrappers/KotlinWrappersStone.kt @@ -13,7 +13,7 @@ import kotlin.reflect.KClass open class KotlinWrappersStone : ProviderWrapper { override fun wrap( - wrapperCl: KClass?, + wrapperCl: KClass, originalProvider: Provider? ): Wr? { return when { diff --git a/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/wrappers/creators/ProviderWrapper.kt b/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/wrappers/creators/ProviderWrapper.kt index 7e58b9e6..63716d8e 100644 --- a/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/wrappers/creators/ProviderWrapper.kt +++ b/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/wrappers/creators/ProviderWrapper.kt @@ -13,5 +13,5 @@ interface ProviderWrapper { * @param type of providing original object * @return wrapped object provider */ - fun wrap(wrapperCl: KClass?, originalProvider: Provider?): Wr? + fun wrap(wrapperCl: KClass, originalProvider: Provider?): Wr? } diff --git a/tests_wraps_kotlin/src/main/kotlin/com/github/klee0kai/test/boxed/di/inject/CarBoxedInjectComponent.kt b/tests_wraps_kotlin/src/main/kotlin/com/github/klee0kai/test/boxed/di/inject/CarBoxedInjectComponent.kt index 38f97b93..7cd6fcc7 100644 --- a/tests_wraps_kotlin/src/main/kotlin/com/github/klee0kai/test/boxed/di/inject/CarBoxedInjectComponent.kt +++ b/tests_wraps_kotlin/src/main/kotlin/com/github/klee0kai/test/boxed/di/inject/CarBoxedInjectComponent.kt @@ -5,8 +5,13 @@ import com.github.klee0kai.stone.annotations.component.ProtectInjected import com.github.klee0kai.test.boxed.model.CarBoxedInject import com.github.klee0kai.test.boxed.model.CarBoxedInjectLists import com.github.klee0kai.test.boxed.model.CarBoxedInjectProvider +import com.github.klee0kai.test.car.di.wrapped.custom.wrappers.CarProviderWrapper -@Component +@Component( + wrapperProviders = [ + CarProviderWrapper::class, + ] +) abstract class CarBoxedInjectComponent { protected abstract fun module(): CarBoxedInjectModule abstract fun inject(carInject: CarBoxedInject) diff --git a/tests_wraps_kotlin/src/main/kotlin/com/github/klee0kai/test/car/di/lists/factory/CarMultiComponent.kt b/tests_wraps_kotlin/src/main/kotlin/com/github/klee0kai/test/car/di/lists/factory/CarMultiComponent.kt index ad8d04ad..99c938b2 100644 --- a/tests_wraps_kotlin/src/main/kotlin/com/github/klee0kai/test/car/di/lists/factory/CarMultiComponent.kt +++ b/tests_wraps_kotlin/src/main/kotlin/com/github/klee0kai/test/car/di/lists/factory/CarMultiComponent.kt @@ -12,13 +12,21 @@ import javax.inject.Provider @Component interface CarMultiComponent { + fun module(): CarMultiModule? + fun singleBumper(): Ref? + fun wheels(): List?>?>? + fun wheel(): Wheel? + fun windows(): List?>? + fun windowsProviding(): List?>?>? - fun cars(): List? + + // TODO The behavior is not obvious. We plan to redo it. + // fun cars(): List? @Named("blueCar") fun blueCar(): Provider? diff --git a/tests_wraps_kotlin/src/main/kotlin/com/github/klee0kai/test/car/di/qualifiers/CarQCModule.kt b/tests_wraps_kotlin/src/main/kotlin/com/github/klee0kai/test/car/di/qualifiers/CarQCModule.kt index 994cafe9..424cb5c4 100644 --- a/tests_wraps_kotlin/src/main/kotlin/com/github/klee0kai/test/car/di/qualifiers/CarQCModule.kt +++ b/tests_wraps_kotlin/src/main/kotlin/com/github/klee0kai/test/car/di/qualifiers/CarQCModule.kt @@ -14,6 +14,7 @@ import javax.inject.Provider @Module open class CarQCModule { + @Provide(cache = Provide.CacheType.Factory) open fun carSimple(wheel: Wheel?, @BumperQualifier bumper: Bumper?, window: Window?): Car { return Car(bumper, wheel, window) diff --git a/tests_wraps_kotlin/src/main/kotlin/com/github/klee0kai/test/car/di/wrapped/create/CarWrappedCreateComponent.kt b/tests_wraps_kotlin/src/main/kotlin/com/github/klee0kai/test/car/di/wrapped/create/CarWrappedCreateComponent.kt index cba31f86..311ae748 100644 --- a/tests_wraps_kotlin/src/main/kotlin/com/github/klee0kai/test/car/di/wrapped/create/CarWrappedCreateComponent.kt +++ b/tests_wraps_kotlin/src/main/kotlin/com/github/klee0kai/test/car/di/wrapped/create/CarWrappedCreateComponent.kt @@ -1,7 +1,7 @@ package com.github.klee0kai.test.car.di.wrapped.create import com.github.klee0kai.stone.annotations.component.Component -import com.github.klee0kai.stone.wrappers.AsyncProvide +import com.github.klee0kai.stone.wrappers.AsyncCoroutineProvide import com.github.klee0kai.stone.wrappers.LazyProvide import com.github.klee0kai.test.car.model.Car import com.github.klee0kai.test.car.model.Wheel @@ -24,5 +24,5 @@ interface CarWrappedCreateComponent { fun carWeak(): WeakReference? fun window(): Window? fun car(): Car? - fun carAsync(): AsyncProvide? + fun carAsync(): AsyncCoroutineProvide? } diff --git a/tests_wraps_kotlin/src/main/kotlin/com/github/klee0kai/test/car/di/wrapped/custom/wrappers/CarLazy.kt b/tests_wraps_kotlin/src/main/kotlin/com/github/klee0kai/test/car/di/wrapped/custom/wrappers/CarLazy.kt index 277a0578..ca3df125 100644 --- a/tests_wraps_kotlin/src/main/kotlin/com/github/klee0kai/test/car/di/wrapped/custom/wrappers/CarLazy.kt +++ b/tests_wraps_kotlin/src/main/kotlin/com/github/klee0kai/test/car/di/wrapped/custom/wrappers/CarLazy.kt @@ -1,6 +1,6 @@ package com.github.klee0kai.test.car.di.wrapped.custom.wrappers -import com.github.klee0kai.stone.wrappers.Ref +import com.github.klee0kai.stone.weakref.Ref class CarLazy(private val call: Ref) { var value: T? = null diff --git a/tests_wraps_kotlin/src/main/kotlin/com/github/klee0kai/test/car/di/wrapped/custom/wrappers/CarProviderWrapper.kt b/tests_wraps_kotlin/src/main/kotlin/com/github/klee0kai/test/car/di/wrapped/custom/wrappers/CarProviderWrapper.kt index d879b581..c78eb2e3 100644 --- a/tests_wraps_kotlin/src/main/kotlin/com/github/klee0kai/test/car/di/wrapped/custom/wrappers/CarProviderWrapper.kt +++ b/tests_wraps_kotlin/src/main/kotlin/com/github/klee0kai/test/car/di/wrapped/custom/wrappers/CarProviderWrapper.kt @@ -1,17 +1,28 @@ package com.github.klee0kai.test.car.di.wrapped.custom.wrappers import com.github.klee0kai.stone.annotations.wrappers.WrappersCreator +import com.github.klee0kai.stone.weakref.Provider import com.github.klee0kai.stone.wrappers.creators.ProviderWrapper -import javax.inject.Provider +import kotlin.reflect.KClass @WrappersCreator(wrappers = [CarLazy::class, CarProvide::class]) class CarProviderWrapper : ProviderWrapper { - override fun wrap(wrapperCl: Class, originalProvider: Provider): Wr { - if (wrapperCl == CarLazy::class.java) { - return CarLazy { originalProvider.get() } as Wr + + override fun wrap( + wrapperCl: KClass, + originalProvider: Provider?, + ): Wr? { + return when (wrapperCl) { + CarLazy::class -> { + CarLazy { originalProvider?.get() } as Wr + } + + CarProvide::class -> { + CarProvide { originalProvider?.get() } as Wr + } + + else -> null } - return if (wrapperCl == CarProvide::class.java) { - CarProvide { originalProvider.get() } as Wr - } else null as Wr } + } diff --git a/tests_wraps_kotlin/src/main/kotlin/com/github/klee0kai/test/car/model/CarInjectProvider.kt b/tests_wraps_kotlin/src/main/kotlin/com/github/klee0kai/test/car/model/CarInjectProvider.kt index cf21fadc..6f60c8c9 100644 --- a/tests_wraps_kotlin/src/main/kotlin/com/github/klee0kai/test/car/model/CarInjectProvider.kt +++ b/tests_wraps_kotlin/src/main/kotlin/com/github/klee0kai/test/car/model/CarInjectProvider.kt @@ -1,7 +1,7 @@ package com.github.klee0kai.test.car.model +import com.github.klee0kai.stone.weakref.Ref import com.github.klee0kai.stone.wrappers.LazyProvide -import com.github.klee0kai.stone.wrappers.Ref import com.github.klee0kai.test.car.di.wrapped.custom.wrappers.CarLazy import javax.inject.Inject From eaf1791e80e60e858d319666bb9217b0f0655181 Mon Sep 17 00:00:00 2001 From: klee0kai Date: Sat, 20 Dec 2025 23:38:21 +0100 Subject: [PATCH 081/122] design wrapHelpers --- .../helpers/annotations/ComponentAnnMirror.kt | 7 ++ .../stone/ksp/helpers/wrap/ClassNameUtils.kt | 5 +- .../ksp/target/component/ComponentGraphExt.kt | 83 ++++++------------- .../target/component/GenComponentProcessor.kt | 1 + .../stone/annotations/component/Component.kt | 29 +------ .../annotations/wrappers/WrappersHelper.kt | 8 ++ .../di/inject/CarBoxedInjectComponent.kt | 8 +- .../test/boxed/di/inject/CarBoxedWrapper.kt | 19 +++++ .../test/car/di/inject/CarInjectComponent.kt | 4 +- .../custom/CarCustomWrappersComponent.kt | 5 +- .../custom/wrappers/CarProviderWrapper.kt | 28 ------- .../wrapped/custom/wrappers/CarRefWrapper.kt | 11 +++ .../di/wrapped/custom/wrappers/CarWrapper.kt | 13 --- 13 files changed, 90 insertions(+), 131 deletions(-) create mode 100644 stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/annotations/wrappers/WrappersHelper.kt create mode 100644 tests_wraps_kotlin/src/main/kotlin/com/github/klee0kai/test/boxed/di/inject/CarBoxedWrapper.kt delete mode 100644 tests_wraps_kotlin/src/main/kotlin/com/github/klee0kai/test/car/di/wrapped/custom/wrappers/CarProviderWrapper.kt create mode 100644 tests_wraps_kotlin/src/main/kotlin/com/github/klee0kai/test/car/di/wrapped/custom/wrappers/CarRefWrapper.kt delete mode 100644 tests_wraps_kotlin/src/main/kotlin/com/github/klee0kai/test/car/di/wrapped/custom/wrappers/CarWrapper.kt diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/annotations/ComponentAnnMirror.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/annotations/ComponentAnnMirror.kt index 15b9d5b6..f4d7c6dd 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/annotations/ComponentAnnMirror.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/annotations/ComponentAnnMirror.kt @@ -16,6 +16,7 @@ import com.squareup.kotlinpoet.ksp.toTypeName class ComponentAnnMirror( val identifiers: List, val wrapperProviders: List, + val wrapperHelpers: List, ) class WrapperCreatorAnnMirror( @@ -87,9 +88,15 @@ fun KSAnnotated.findComponentAnnotation( ?.value as? List ?: emptyList() + val wrapperHelpers = compAnn.arguments + .firstOrNull { it.name?.asString() == "wrapperHelpers" } + ?.value as? List + ?: emptyList() + ComponentAnnMirror( identifiers = identifiers, wrapperProviders = wrapperProviders, + wrapperHelpers = wrapperHelpers, ) } diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/wrap/ClassNameUtils.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/wrap/ClassNameUtils.kt index 9b0184fd..c94e9ecc 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/wrap/ClassNameUtils.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/wrap/ClassNameUtils.kt @@ -68,4 +68,7 @@ object ClassNameUtils { } -} \ No newline at end of file +} + + +fun TypeName.rawType(): TypeName = ClassNameUtils.rawTypeOf(this) \ No newline at end of file diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/component/ComponentGraphExt.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/component/ComponentGraphExt.kt index 3674b799..517dd6fa 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/component/ComponentGraphExt.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/component/ComponentGraphExt.kt @@ -1,88 +1,57 @@ package com.github.klee0kai.thekey.stone.ksp.target.component -import com.github.klee0kai.stone.wrappers.creators.CircleWrapper -import com.github.klee0kai.stone.wrappers.creators.ProviderWrapper -import com.github.klee0kai.stone.wrappers.creators.Wrapper -import com.github.klee0kai.thekey.stone.ksp.exceptions.IncorrectSignatureException +import com.github.klee0kai.thekey.stone.ksp.exceptions.forEachFun import com.github.klee0kai.thekey.stone.ksp.helpers.allIdentifierTypes import com.github.klee0kai.thekey.stone.ksp.helpers.allParentDeclarations import com.github.klee0kai.thekey.stone.ksp.helpers.annotations.findComponentAnnotation -import com.github.klee0kai.thekey.stone.ksp.helpers.annotations.findWrapperCreatorAnnotation import com.github.klee0kai.thekey.stone.ksp.helpers.invokecall.ModulesGraph -import com.github.klee0kai.thekey.stone.ksp.helpers.wrap.ClassNameUtils import com.github.klee0kai.thekey.stone.ksp.helpers.wrap.WrapHelper import com.github.klee0kai.thekey.stone.ksp.helpers.wrap.WrapType -import com.github.klee0kai.thekey.stone.ksp.helpers.wrapperStoneClName -import com.github.klee0kai.thekey.stone.ksp.ksp.isType +import com.github.klee0kai.thekey.stone.ksp.ksp.getAllMethods +import com.github.klee0kai.thekey.stone.ksp.ksp.resolveAlias import com.github.klee0kai.thekey.stone.ksp.poet.codeBlock -import com.github.klee0kai.thekey.stone.ksp.target.wrapper.GenWrappersSupportProcessor.Companion.provideWrappersGlFieldPrefixName import com.google.devtools.ksp.symbol.KSClassDeclaration -import com.squareup.kotlinpoet.ksp.toTypeName +import com.squareup.kotlinpoet.ksp.toClassName fun KSClassDeclaration.collectWrapHelper( ): WrapHelper { val wrapHelper = WrapHelper() - val wrapperProviders = allParentDeclarations + val wrapperHelpers = allParentDeclarations .filter { it.findComponentAnnotation().any() } .flatMap { parentComponentCl -> - parentComponentCl.findComponentAnnotation().firstOrNull()?.wrapperProviders ?: emptyList() + parentComponentCl.findComponentAnnotation().firstOrNull()?.wrapperHelpers ?: emptyList() } - val wrapperCreatorClName = wrapperStoneClName - wrapperProviders.forEachIndexed { index, provideWrappersCl -> - val name = provideWrappersGlFieldPrefixName + index - val provideWrappersClDecl = provideWrappersCl.declaration as? KSClassDeclaration ?: return@forEachIndexed - val isSimpleWrapper = provideWrappersClDecl.allParentDeclarations.any { it.isType(Wrapper::class) } - val isAsyncWrapper = provideWrappersClDecl.allParentDeclarations.any { it.isType(ProviderWrapper::class) } - val isCycleWrapper = provideWrappersClDecl.allParentDeclarations.any { it.isType(CircleWrapper::class) } - val wrappers = provideWrappersClDecl.findWrapperCreatorAnnotation() - .firstOrNull()?.wrappers ?: return@forEachIndexed + wrapperHelpers.forEachIndexed { _, wrapperHelperCl -> + val wrapperHelperClDec = wrapperHelperCl.declaration as? KSClassDeclaration ?: return@forEachIndexed + val methods = wrapperHelperClDec.getAllMethods(false, false, "") + methods.forEachFun { funIdx, m -> + val inputType = (m.parameters.firstOrNull() + ?.type?.resolveAlias() + ?.declaration as? KSClassDeclaration) + ?.toClassName() ?: return@forEachFun + + val outputType = (m.returnType?.resolveAlias() + ?.declaration as? KSClassDeclaration) + ?.toClassName() ?: return@forEachFun - for (wrapper in wrappers) { - val rawTypeName = ClassNameUtils.rawTypeOf(wrapper.toTypeName()) wrapHelper.support( WrapType( - isNoCachingWrapper = !isAsyncWrapper, - typeName = rawTypeName, + isNoCachingWrapper = false, + typeName = outputType, wrap = { or, nullable -> codeBlock { - if (isSimpleWrapper) { - add( - "%T.%L.wrap( %T::class , %L )", - wrapperCreatorClName, - name, - rawTypeName, - or, - ) - } else if (isAsyncWrapper || isCycleWrapper) { - add( - "%T.%L.wrap( %T::class , { %L } )", - wrapperCreatorClName, - name, - rawTypeName, - or, - ) - } else { - throw IncorrectSignatureException("Type Transform non support to ${wrapper.toTypeName()}") - } + add( + "%T.%L( %L )", + wrapperHelperClDec.toClassName(), + m.simpleName.asString(), + or, + ) } }, unwrap = { or, nullable -> codeBlock { - val paramType = wrapHelper.paramType(wrapper.toTypeName()) - if (isCycleWrapper) { - add( - "%T.%L.unwrap( %T::class , %T::class, %L )", - wrapperCreatorClName, - name, - rawTypeName, - paramType, - or - ) - } else { - throw IncorrectSignatureException("Type Transform non support to ${wrapper.toTypeName()}") - } } } ) diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/component/GenComponentProcessor.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/component/GenComponentProcessor.kt index f2664b71..ea609be1 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/component/GenComponentProcessor.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/component/GenComponentProcessor.kt @@ -436,6 +436,7 @@ class GenComponentProcessor : TargetFileProcessor { ) if (provideCode == null) { + wrapHelper.nonWrappedType(injectField.type.resolve().toTypeName()) throw ObjectNotProvidedException( message = "Error provide type ${injectField.type.resolve().toTypeName()}. " + "Required in ${injectableCl.toClassName()}.${injectField.simpleName.asString()}", diff --git a/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/annotations/component/Component.kt b/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/annotations/component/Component.kt index 59e29fe1..de749644 100644 --- a/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/annotations/component/Component.kt +++ b/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/annotations/component/Component.kt @@ -230,31 +230,10 @@ annotation class Component( * If no identifier is specified when providing the object, it will be null instead. */ val identifiers: Array> = [], + + /** - * The library allows you to provide objects in wrappers. - * Various wrappers allow, for example, to perform lazy or asynchronous providingF of objects, - * or not to keep cached objects in DI. - * Wrapping also allows you to render several different objects into one list. - * - * - * The library contains a sufficient set of provider wrappers. - * However, if that's not enough, you can implement your own wrapping implementation - * class-based: `ProviderWrapper` and `Wrapper`. - * It is enough to override these classes, and use the `@WrappersCreator` annotation - * to list the wrappers implemented in this class. - *
`ㅤ@WrappersCreator(wrappers = {CarRef.class})
-     * public class CarWrapper implements Wrapper {
-     *
-     * ㅤ@Override
-     * public  Wr wrap(Class wrapperCl, T original) {
-     * if (wrapperCl.equals(CarRef.class)) {
-     * return (Wr) new CarRef<>(original);
-     *
-     * }
-     * return null;
-     * }
-     * }
-    `
* + * TODO Kdoc */ - val wrapperProviders: Array> = [] + val wrapperHelpers: Array> = [], ) diff --git a/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/annotations/wrappers/WrappersHelper.kt b/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/annotations/wrappers/WrappersHelper.kt new file mode 100644 index 00000000..9a3fb207 --- /dev/null +++ b/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/annotations/wrappers/WrappersHelper.kt @@ -0,0 +1,8 @@ +package com.github.klee0kai.stone.annotations.wrappers + +/** + * Type transform helper + */ +@Retention(AnnotationRetention.BINARY) +@Target(AnnotationTarget.CLASS) +annotation class WrappersHelper diff --git a/tests_wraps_kotlin/src/main/kotlin/com/github/klee0kai/test/boxed/di/inject/CarBoxedInjectComponent.kt b/tests_wraps_kotlin/src/main/kotlin/com/github/klee0kai/test/boxed/di/inject/CarBoxedInjectComponent.kt index 7cd6fcc7..e1ebd59b 100644 --- a/tests_wraps_kotlin/src/main/kotlin/com/github/klee0kai/test/boxed/di/inject/CarBoxedInjectComponent.kt +++ b/tests_wraps_kotlin/src/main/kotlin/com/github/klee0kai/test/boxed/di/inject/CarBoxedInjectComponent.kt @@ -5,15 +5,15 @@ import com.github.klee0kai.stone.annotations.component.ProtectInjected import com.github.klee0kai.test.boxed.model.CarBoxedInject import com.github.klee0kai.test.boxed.model.CarBoxedInjectLists import com.github.klee0kai.test.boxed.model.CarBoxedInjectProvider -import com.github.klee0kai.test.car.di.wrapped.custom.wrappers.CarProviderWrapper @Component( - wrapperProviders = [ - CarProviderWrapper::class, + wrapperHelpers = [ + CarBoxedWrapper::class, ] ) abstract class CarBoxedInjectComponent { - protected abstract fun module(): CarBoxedInjectModule + + abstract fun module(): CarBoxedInjectModule abstract fun inject(carInject: CarBoxedInject) abstract fun inject(carInject: CarBoxedInjectLists) abstract fun inject(carInject: CarBoxedInjectProvider) diff --git a/tests_wraps_kotlin/src/main/kotlin/com/github/klee0kai/test/boxed/di/inject/CarBoxedWrapper.kt b/tests_wraps_kotlin/src/main/kotlin/com/github/klee0kai/test/boxed/di/inject/CarBoxedWrapper.kt new file mode 100644 index 00000000..aa8d775c --- /dev/null +++ b/tests_wraps_kotlin/src/main/kotlin/com/github/klee0kai/test/boxed/di/inject/CarBoxedWrapper.kt @@ -0,0 +1,19 @@ +package com.github.klee0kai.test.boxed.di.inject + +import com.github.klee0kai.stone.annotations.wrappers.WrappersHelper +import com.github.klee0kai.stone.weakref.Provider +import com.github.klee0kai.test.car.di.wrapped.custom.wrappers.CarLazy +import com.github.klee0kai.test.car.di.wrapped.custom.wrappers.CarProvide + +@WrappersHelper +object CarBoxedWrapper { + + fun transformToCarLay( + origin: Provider, + ): CarLazy = CarLazy { origin.get() } + + fun transformToCarProvide( + origin: Provider, + ): CarProvide = CarProvide { origin.get() } + +} \ No newline at end of file diff --git a/tests_wraps_kotlin/src/main/kotlin/com/github/klee0kai/test/car/di/inject/CarInjectComponent.kt b/tests_wraps_kotlin/src/main/kotlin/com/github/klee0kai/test/car/di/inject/CarInjectComponent.kt index 32803c19..3b1888e1 100644 --- a/tests_wraps_kotlin/src/main/kotlin/com/github/klee0kai/test/car/di/inject/CarInjectComponent.kt +++ b/tests_wraps_kotlin/src/main/kotlin/com/github/klee0kai/test/car/di/inject/CarInjectComponent.kt @@ -2,12 +2,12 @@ package com.github.klee0kai.test.car.di.inject import com.github.klee0kai.stone.annotations.component.Component import com.github.klee0kai.stone.annotations.component.ProtectInjected -import com.github.klee0kai.test.car.di.wrapped.custom.wrappers.CarProviderWrapper +import com.github.klee0kai.test.boxed.di.inject.CarBoxedWrapper import com.github.klee0kai.test.car.model.CarInject import com.github.klee0kai.test.car.model.CarInjectLists import com.github.klee0kai.test.car.model.CarInjectProvider -@Component(wrapperProviders = [CarProviderWrapper::class]) +@Component(wrapperHelpers = [CarBoxedWrapper::class]) abstract class CarInjectComponent { protected abstract fun module(): CarInjectModule? abstract fun inject(carInject: CarInject?) diff --git a/tests_wraps_kotlin/src/main/kotlin/com/github/klee0kai/test/car/di/wrapped/custom/CarCustomWrappersComponent.kt b/tests_wraps_kotlin/src/main/kotlin/com/github/klee0kai/test/car/di/wrapped/custom/CarCustomWrappersComponent.kt index aefc8436..20514261 100644 --- a/tests_wraps_kotlin/src/main/kotlin/com/github/klee0kai/test/car/di/wrapped/custom/CarCustomWrappersComponent.kt +++ b/tests_wraps_kotlin/src/main/kotlin/com/github/klee0kai/test/car/di/wrapped/custom/CarCustomWrappersComponent.kt @@ -1,10 +1,13 @@ package com.github.klee0kai.test.car.di.wrapped.custom import com.github.klee0kai.stone.annotations.component.Component +import com.github.klee0kai.test.boxed.di.inject.CarBoxedWrapper import com.github.klee0kai.test.car.di.wrapped.custom.wrappers.* import com.github.klee0kai.test.car.model.Car -@Component(wrapperProviders = [CarProviderWrapper::class, CarWrapper::class]) +@Component( + wrapperHelpers = [CarBoxedWrapper::class, CarRefWrapper::class], +) interface CarCustomWrappersComponent { fun module(): CarCustomWrapperModule? fun car(): Car? diff --git a/tests_wraps_kotlin/src/main/kotlin/com/github/klee0kai/test/car/di/wrapped/custom/wrappers/CarProviderWrapper.kt b/tests_wraps_kotlin/src/main/kotlin/com/github/klee0kai/test/car/di/wrapped/custom/wrappers/CarProviderWrapper.kt deleted file mode 100644 index c78eb2e3..00000000 --- a/tests_wraps_kotlin/src/main/kotlin/com/github/klee0kai/test/car/di/wrapped/custom/wrappers/CarProviderWrapper.kt +++ /dev/null @@ -1,28 +0,0 @@ -package com.github.klee0kai.test.car.di.wrapped.custom.wrappers - -import com.github.klee0kai.stone.annotations.wrappers.WrappersCreator -import com.github.klee0kai.stone.weakref.Provider -import com.github.klee0kai.stone.wrappers.creators.ProviderWrapper -import kotlin.reflect.KClass - -@WrappersCreator(wrappers = [CarLazy::class, CarProvide::class]) -class CarProviderWrapper : ProviderWrapper { - - override fun wrap( - wrapperCl: KClass, - originalProvider: Provider?, - ): Wr? { - return when (wrapperCl) { - CarLazy::class -> { - CarLazy { originalProvider?.get() } as Wr - } - - CarProvide::class -> { - CarProvide { originalProvider?.get() } as Wr - } - - else -> null - } - } - -} diff --git a/tests_wraps_kotlin/src/main/kotlin/com/github/klee0kai/test/car/di/wrapped/custom/wrappers/CarRefWrapper.kt b/tests_wraps_kotlin/src/main/kotlin/com/github/klee0kai/test/car/di/wrapped/custom/wrappers/CarRefWrapper.kt new file mode 100644 index 00000000..5539a793 --- /dev/null +++ b/tests_wraps_kotlin/src/main/kotlin/com/github/klee0kai/test/car/di/wrapped/custom/wrappers/CarRefWrapper.kt @@ -0,0 +1,11 @@ +package com.github.klee0kai.test.car.di.wrapped.custom.wrappers + +import com.github.klee0kai.stone.weakref.Provider + +object CarRefWrapper { + + fun transformToCarRef( + origin: Provider, + ): CarRef = CarRef(origin.get()) + +} \ No newline at end of file diff --git a/tests_wraps_kotlin/src/main/kotlin/com/github/klee0kai/test/car/di/wrapped/custom/wrappers/CarWrapper.kt b/tests_wraps_kotlin/src/main/kotlin/com/github/klee0kai/test/car/di/wrapped/custom/wrappers/CarWrapper.kt deleted file mode 100644 index f8108905..00000000 --- a/tests_wraps_kotlin/src/main/kotlin/com/github/klee0kai/test/car/di/wrapped/custom/wrappers/CarWrapper.kt +++ /dev/null @@ -1,13 +0,0 @@ -package com.github.klee0kai.test.car.di.wrapped.custom.wrappers - -import com.github.klee0kai.stone.annotations.wrappers.WrappersCreator -import com.github.klee0kai.stone.wrappers.creators.Wrapper - -@WrappersCreator(wrappers = [CarRef::class]) -class CarWrapper : Wrapper { - override fun wrap(wrapperCl: Class, original: T): Wr { - return if (wrapperCl == CarRef::class.java) { - CarRef(original) as Wr - } else null as Wr - } -} From 3261b9d61db66c8be93cfe683be5aa6889063264 Mon Sep 17 00:00:00 2001 From: klee0kai Date: Sun, 21 Dec 2025 01:27:31 +0100 Subject: [PATCH 082/122] short wrappers fixs --- .../thekey/stone/ksp/target/component/ComponentGraphExt.kt | 2 +- .../stone/__hidden__/types/holders/SingleItemHolder.kt | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/component/ComponentGraphExt.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/component/ComponentGraphExt.kt index 517dd6fa..e8c44d66 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/component/ComponentGraphExt.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/component/ComponentGraphExt.kt @@ -42,7 +42,7 @@ fun KSClassDeclaration.collectWrapHelper( wrap = { or, nullable -> codeBlock { add( - "%T.%L( %L )", + "%T.%L{ %L }", wrapperHelperClDec.toClassName(), m.simpleName.asString(), or, diff --git a/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/__hidden__/types/holders/SingleItemHolder.kt b/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/__hidden__/types/holders/SingleItemHolder.kt index 7f5a84d9..e1ad933e 100644 --- a/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/__hidden__/types/holders/SingleItemHolder.kt +++ b/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/__hidden__/types/holders/SingleItemHolder.kt @@ -27,9 +27,9 @@ class SingleItemHolder( else -> null } - fun getList(): List? = when (curRefType) { + fun getList(): List? = when (curRefType) { StoneRefType.ListObject -> refHolder as MutableList? - StoneRefType.ListWeakObject, StoneRefType.ListSoftObject -> (refHolder as MutableList?>?)?.map { it?.get() } + StoneRefType.ListWeakObject, StoneRefType.ListSoftObject -> (refHolder as MutableList?>?)?.mapNotNull { it?.get() } else -> null } From f7d47beed95eb6233085833a7805f41cab71e27e Mon Sep 17 00:00:00 2001 From: klee0kai Date: Sun, 21 Dec 2025 10:44:19 +0100 Subject: [PATCH 083/122] wrappers at module factory --- .../klee0kai/thekey/stone/ksp/Processor.kt | 2 +- .../helpers/annotations/ComponentAnnMirror.kt | 29 +++------------ .../module/GenModuleFactoryProcessor.kt | 37 ++++++++++++++----- .../ksp/target/module/GenModuleProcessor.kt | 4 +- .../annotations/wrappers/WrappersCreator.kt | 19 ---------- .../stone/wrappers/KotlinWrappersStone.kt | 25 ------------- .../stone/wrappers/creators/CircleWrapper.kt | 17 --------- .../wrappers/creators/ProviderWrapper.kt | 17 --------- .../stone/wrappers/creators/Wrapper.kt | 16 -------- .../test/car/di/qualifiers/CarQPModule.kt | 2 +- 10 files changed, 38 insertions(+), 130 deletions(-) delete mode 100644 stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/annotations/wrappers/WrappersCreator.kt delete mode 100644 stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/wrappers/KotlinWrappersStone.kt delete mode 100644 stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/wrappers/creators/CircleWrapper.kt delete mode 100644 stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/wrappers/creators/ProviderWrapper.kt delete mode 100644 stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/wrappers/creators/Wrapper.kt diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/Processor.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/Processor.kt index ecd32fb2..338c5fe7 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/Processor.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/Processor.kt @@ -64,7 +64,7 @@ class Processor( // force changes // debug = true -// debugPkgFilter = "com.github.klee0kai.test.car.di.qualifiers" +// debugPkgFilter = "com.github.klee0kai.test.di.wire" } diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/annotations/ComponentAnnMirror.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/annotations/ComponentAnnMirror.kt index f4d7c6dd..c5d9920c 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/annotations/ComponentAnnMirror.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/annotations/ComponentAnnMirror.kt @@ -5,7 +5,7 @@ import com.github.klee0kai.stone.annotations.dependencies.Dependencies import com.github.klee0kai.stone.annotations.module.BindInstance import com.github.klee0kai.stone.annotations.module.Module import com.github.klee0kai.stone.annotations.module.Provide -import com.github.klee0kai.stone.annotations.wrappers.WrappersCreator +import com.github.klee0kai.stone.annotations.wrappers.WrappersHelper import com.google.devtools.ksp.symbol.KSAnnotated import com.google.devtools.ksp.symbol.KSAnnotation import com.google.devtools.ksp.symbol.KSType @@ -19,10 +19,6 @@ class ComponentAnnMirror( val wrapperHelpers: List, ) -class WrapperCreatorAnnMirror( - val wrappers: List, -) - fun KSAnnotated.annotations( className: ClassName, ): Sequence = annotations @@ -38,6 +34,9 @@ fun KSAnnotated.anyAnnotation( fun KSAnnotated.stoneControlAnnotations( ): Sequence = anyAnnotation( Component::class.asClassName(), + WrappersHelper::class.asClassName(), + Module::class.asClassName(), + Dependencies::class.asClassName(), ExtendOf::class.asClassName(), ModuleOriginFactory::class.asClassName(), ProtectInjected::class.asClassName(), @@ -46,10 +45,8 @@ fun KSAnnotated.stoneControlAnnotations( Init::class.asClassName(), BindInstance::class.asClassName(), Provide::class.asClassName(), - Module::class.asClassName(), - Dependencies::class.asClassName(), - WrappersCreator::class.asClassName(), -) + + ) fun KSAnnotated.hasOnlyAnnotation( @@ -100,17 +97,3 @@ fun KSAnnotated.findComponentAnnotation( ) } -@Suppress("UNCHECKED_CAST") -fun KSAnnotated.findWrapperCreatorAnnotation( -): Sequence = annotations - .filter { it.annotationType.resolve().toTypeName() == WrappersCreator::class.asClassName() } - .map { compAnn -> - val wrappers = compAnn.arguments - .firstOrNull { it.name?.asString() == "wrappers" } - ?.value as? List - ?: emptyList() - - WrapperCreatorAnnMirror( - wrappers = wrappers, - ) - } diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/module/GenModuleFactoryProcessor.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/module/GenModuleFactoryProcessor.kt index 1eca5073..c7dc49ab 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/module/GenModuleFactoryProcessor.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/module/GenModuleFactoryProcessor.kt @@ -7,6 +7,9 @@ import com.github.klee0kai.stone.annotations.module.BindInstance import com.github.klee0kai.stone.annotations.module.Module import com.github.klee0kai.thekey.stone.ksp.exceptions.forEachFun import com.github.klee0kai.thekey.stone.ksp.helpers.factoryStoneClName +import com.github.klee0kai.thekey.stone.ksp.helpers.findComponentForModuleOrDep +import com.github.klee0kai.thekey.stone.ksp.helpers.wrap.WrapHelper +import com.github.klee0kai.thekey.stone.ksp.helpers.wrap.rawType import com.github.klee0kai.thekey.stone.ksp.ksp.arch.GenSpec import com.github.klee0kai.thekey.stone.ksp.ksp.arch.SymbolsToProcess import com.github.klee0kai.thekey.stone.ksp.ksp.arch.TargetFileProcessor @@ -18,9 +21,11 @@ import com.github.klee0kai.thekey.stone.ksp.poet.genClass import com.github.klee0kai.thekey.stone.ksp.poet.genFileSpec import com.github.klee0kai.thekey.stone.ksp.poet.genLibComment import com.github.klee0kai.thekey.stone.ksp.poet.genOverrideFun +import com.github.klee0kai.thekey.stone.ksp.target.component.collectWrapHelper import com.google.devtools.ksp.KspExperimental import com.google.devtools.ksp.containingFile import com.google.devtools.ksp.getAnnotationsByType +import com.google.devtools.ksp.getClassDeclarationByName import com.google.devtools.ksp.processing.Dependencies import com.google.devtools.ksp.processing.KSPLogger import com.google.devtools.ksp.processing.Resolver @@ -28,9 +33,11 @@ import com.google.devtools.ksp.symbol.ClassKind import com.google.devtools.ksp.symbol.KSAnnotated import com.google.devtools.ksp.symbol.KSClassDeclaration import com.google.devtools.ksp.symbol.Modifier +import com.squareup.kotlinpoet.CodeBlock import com.squareup.kotlinpoet.KModifier import com.squareup.kotlinpoet.asClassName import com.squareup.kotlinpoet.ksp.toClassName +import com.squareup.kotlinpoet.ksp.toTypeName class GenModuleFactoryProcessor : TargetFileProcessor { @@ -53,11 +60,12 @@ class GenModuleFactoryProcessor : TargetFileProcessor { val fileOwner = validSymbol.containingFile ?: return null val moduleCl = validSymbol as? KSClassDeclaration ?: return null - val moduleAnn = moduleCl.getAnnotationsByType(Module::class) - .firstOrNull() ?: return null + val componentCl = resolver.findComponentForModuleOrDep(moduleCl.toClassName()) + .firstOrNull() - val genFactoryClassName = moduleCl.factoryStoneClName + val wrapHelper = componentCl?.collectWrapHelper() ?: WrapHelper() + val genFactoryClassName = moduleCl.factoryStoneClName val fileSpec = genFileSpec(genFactoryClassName.packageName, fileName = genFactoryClassName.simpleName) { genLibComment() @@ -73,13 +81,15 @@ class GenModuleFactoryProcessor : TargetFileProcessor { validSymbol.getAllMethods(false, false, "") .forEachFun { _, function -> if (!function.modifiers.contains(Modifier.ABSTRACT) && moduleCl.classKind != ClassKind.INTERFACE) return@forEachFun - val returnCl = function.returnType?.resolveAlias() - ?.declaration as? KSClassDeclaration ?: return@forEachFun + val returnType = function.returnType?.toTypeName() ?: return@forEachFun + val nonWrappedType = wrapHelper.nonWrappedType(returnType) + val nonWrappedClDec = resolver.getClassDeclarationByName(nonWrappedType.rawType().toString()) + val bindInstanceAnn = function.getAnnotationsByType(BindInstance::class) .firstOrNull() val constructorFun by lazy { - returnCl.findConstructor( + nonWrappedClDec?.findConstructor( parameters = function.parameters.map { it.type.resolveAlias() }) } @@ -94,10 +104,17 @@ class GenModuleFactoryProcessor : TargetFileProcessor { } constructorFun != null -> { - addStatement( - "return %T( %L )", - returnCl.toClassName(), - constructorFun!!.joinInvokeArguments(function.parameters), + addCode( + "return %L", + wrapHelper.transform( + providingType = nonWrappedType, + wannaType = returnType, + CodeBlock.of( + "%T( %L )", + nonWrappedType, + constructorFun!!.joinInvokeArguments(function.parameters), + ) + ) ) } diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/module/GenModuleProcessor.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/module/GenModuleProcessor.kt index b22fc6ef..1d205bb3 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/module/GenModuleProcessor.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/module/GenModuleProcessor.kt @@ -26,6 +26,7 @@ import com.github.klee0kai.thekey.stone.ksp.ksp.arch.SymbolsToProcess import com.github.klee0kai.thekey.stone.ksp.ksp.arch.TargetFileProcessor import com.github.klee0kai.thekey.stone.ksp.ksp.getAllMethods import com.github.klee0kai.thekey.stone.ksp.poet.* +import com.github.klee0kai.thekey.stone.ksp.target.component.collectWrapHelper import com.google.devtools.ksp.KspExperimental import com.google.devtools.ksp.containingFile import com.google.devtools.ksp.getAllSuperTypes @@ -93,6 +94,8 @@ class GenModuleProcessor : TargetFileProcessor { val componentCl = resolver.findComponentForModuleOrDep(moduleCl.toClassName()) .firstOrNull() + val wrapHelper = componentCl?.collectWrapHelper() ?: WrapHelper() + val identifierTypes = componentCl ?.allIdentifierTypes?.toList() ?: emptyList() @@ -103,7 +106,6 @@ class GenModuleProcessor : TargetFileProcessor { val genModuleClassName = moduleCl.moduleStoneClName - val wrapHelper = WrapHelper() val fileSpec = genFileSpec(genModuleClassName.packageName, genModuleClassName.simpleName) { genLibComment() diff --git a/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/annotations/wrappers/WrappersCreator.kt b/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/annotations/wrappers/WrappersCreator.kt deleted file mode 100644 index 612ff828..00000000 --- a/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/annotations/wrappers/WrappersCreator.kt +++ /dev/null @@ -1,19 +0,0 @@ -package com.github.klee0kai.stone.annotations.wrappers - -import kotlin.reflect.KClass - -/** - * Provide custom wrappers creator, class - * - * - * Should implement [Wrapper] or [ProviderWrapper] or [CircleWrapper] - * and declare custom wrappers in annotation - */ -@Retention(AnnotationRetention.BINARY) -@Target(AnnotationTarget.CLASS) -annotation class WrappersCreator( - /** - * Custom Wrappers, can be provided - */ - val wrappers: Array> = [] -) diff --git a/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/wrappers/KotlinWrappersStone.kt b/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/wrappers/KotlinWrappersStone.kt deleted file mode 100644 index ef690663..00000000 --- a/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/wrappers/KotlinWrappersStone.kt +++ /dev/null @@ -1,25 +0,0 @@ -package com.github.klee0kai.stone.wrappers - -import com.github.klee0kai.stone.annotations.wrappers.WrappersCreator -import com.github.klee0kai.stone.weakref.Provider -import com.github.klee0kai.stone.wrappers.creators.ProviderWrapper -import kotlin.reflect.KClass - -@WrappersCreator( - wrappers = [ - Lazy::class, - ] -) -open class KotlinWrappersStone : ProviderWrapper { - - override fun wrap( - wrapperCl: KClass, - originalProvider: Provider? - ): Wr? { - return when { - wrapperCl == Lazy::class -> lazy { originalProvider?.get() } as Wr - else -> null - } - } - -} \ No newline at end of file diff --git a/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/wrappers/creators/CircleWrapper.kt b/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/wrappers/creators/CircleWrapper.kt deleted file mode 100644 index da1e0107..00000000 --- a/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/wrappers/creators/CircleWrapper.kt +++ /dev/null @@ -1,17 +0,0 @@ -package com.github.klee0kai.stone.wrappers.creators - -import kotlin.reflect.KClass - -interface CircleWrapper : ProviderWrapper { - /** - * UnProvide wrapped object. - * - * @param wrapperCl type of wrapper - * @param objectType original provide object type - * @param wrapper wrapper to unwrap - * @param type of wrapper - * @param type of providing original object - * @return wrapped object provider - */ - fun unwrap(wrapperCl: KClass?, objectType: KClass?, wrapper: Wr?): T? -} diff --git a/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/wrappers/creators/ProviderWrapper.kt b/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/wrappers/creators/ProviderWrapper.kt deleted file mode 100644 index 63716d8e..00000000 --- a/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/wrappers/creators/ProviderWrapper.kt +++ /dev/null @@ -1,17 +0,0 @@ -package com.github.klee0kai.stone.wrappers.creators - -import com.github.klee0kai.stone.weakref.Provider -import kotlin.reflect.KClass - -interface ProviderWrapper { - /** - * Provide wrapped object. - * - * @param wrapperCl type of wrapper - * @param originalProvider original object provider - * @param type of wrapper - * @param type of providing original object - * @return wrapped object provider - */ - fun wrap(wrapperCl: KClass, originalProvider: Provider?): Wr? -} diff --git a/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/wrappers/creators/Wrapper.kt b/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/wrappers/creators/Wrapper.kt deleted file mode 100644 index 61ed7fe2..00000000 --- a/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/wrappers/creators/Wrapper.kt +++ /dev/null @@ -1,16 +0,0 @@ -package com.github.klee0kai.stone.wrappers.creators - -import kotlin.reflect.KClass - -interface Wrapper { - /** - * Provide wrapped object. - * - * @param wrapperCl type of wrapper - * @param original original object - * @param type of wrapper - * @param type of providing original object - * @return wrapped object provider - */ - fun wrap(wrapperCl: KClass?, original: T?): Wr? -} diff --git a/tests_wraps_kotlin/src/main/kotlin/com/github/klee0kai/test/car/di/qualifiers/CarQPModule.kt b/tests_wraps_kotlin/src/main/kotlin/com/github/klee0kai/test/car/di/qualifiers/CarQPModule.kt index 0ed5d2fb..c3300466 100644 --- a/tests_wraps_kotlin/src/main/kotlin/com/github/klee0kai/test/car/di/qualifiers/CarQPModule.kt +++ b/tests_wraps_kotlin/src/main/kotlin/com/github/klee0kai/test/car/di/qualifiers/CarQPModule.kt @@ -18,7 +18,7 @@ abstract class CarQPModule { @WheelCount(count = 4) @Provide(cache = Provide.CacheType.Factory) open fun fourWheel(): List { - return Arrays.asList(Wheel(), Wheel(), Wheel(), Wheel()) + return listOf(Wheel(), Wheel(), Wheel(), Wheel()) } @BumperQualifier(type = BumperQualifier.BumperType.Simple) From 944e36c9a2ecb6d38277379468c16eea1ffc92dc Mon Sep 17 00:00:00 2001 From: klee0kai Date: Sun, 21 Dec 2025 12:29:21 +0100 Subject: [PATCH 084/122] correct module gen --- .../klee0kai/thekey/stone/ksp/Processor.kt | 4 +- .../stone/ksp/helpers/wrap/WrapHelper.kt | 44 +++++++------ .../thekey/stone/ksp/poet/FunSpecDsl.kt | 1 + .../module/GenModuleCacheControlProcessor.kt | 8 ++- .../ksp/target/module/GenModuleProcessor.kt | 23 ++++--- .../boxed/di/inject/CarBoxedInjectModule.kt | 1 + .../di/lists/cached/CarMultiCachedModule.kt | 1 - .../test/car/di/qualifiers/CarQCModule.kt | 66 +++++++++++-------- .../di/wrapped/custom/wrappers/CarProvide.kt | 2 +- .../com/github/klee0kai/test/car/model/Car.kt | 2 +- 10 files changed, 86 insertions(+), 66 deletions(-) diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/Processor.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/Processor.kt index 338c5fe7..d0dace51 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/Processor.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/Processor.kt @@ -63,8 +63,8 @@ class Processor( debugPkgFilter = options["debugPkgFilter"] // force changes -// debug = true -// debugPkgFilter = "com.github.klee0kai.test.di.wire" + debug = true + debugPkgFilter = "com.github.klee0kai.test.car.di.bindinstance.simple" } diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/wrap/WrapHelper.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/wrap/WrapHelper.kt index 0c59f2c9..1e3b51d3 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/wrap/WrapHelper.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/wrap/WrapHelper.kt @@ -181,7 +181,7 @@ class WrapHelper { Reference::class, )) { val wrapper = cl.asClassName() - val creator = if (cl != Reference::class.java) wrapper else WeakReference::class.asClassName() + val creator = if (cl != Reference::class) wrapper else WeakReference::class.asClassName() val wrapType = WrapType( typeName = wrapper, @@ -282,40 +282,46 @@ class WrapHelper { support(wrapType) } - var index = 0 - for (cl in listOf(LinkedList::class, ArrayList::class, MutableList::class, MutableCollection::class)) { + for (cl in listOf( + LinkedList::class, + ArrayList::class, + List::class, + Collection::class, + )) { val wrapper = cl.asClassName() - val needConstructor = listOf(LinkedList::class, ArrayList::class).contains(cl) - val createType = if (index++ <= 0) wrapper else ArrayList::class.asClassName() + val constructor = when (cl) { + LinkedList::class, ArrayList::class -> wrapper + else -> null + } val wrapType = WrapType( typeName = wrapper, wrap = { or, nullable -> val builder = CodeBlock.builder() builder.add("listOfNotNull( %L ) ", or) - if (needConstructor) builder.add(".let { %T(it) }", createType) + if (constructor != null) builder.add("?.let { %T(it) }", constructor) builder.build() }, unwrap = { or, nullable -> CodeBlock.builder() - .add("%L.first( )", or) + .add("%L?.first( )", or) .build() }, inListFormat = { originalListType, originalListCode, itemTransformFun -> - val builder = CodeBlock.builder() - val isListNeedConstructor = - needConstructor && rawTypeOf(wrapper) != rawTypeOf(originalListType) + codeBlock { + val itemTransform = itemTransformFun.formatCode(CodeBlock.of("it"), nullable = false) + if (itemTransform.toString() == "it") { + //no transforms + add(originalListCode) + } else { + add("%L?.map{ it -> %L }", originalListCode, itemTransform) + } - val itemTransform = itemTransformFun.formatCode(CodeBlock.of("it"), nullable = false) - if (itemTransform.toString() == "it") { - //no transforms - builder.add(originalListCode) - } else { - builder.add("%L.map{ it -> %L }", originalListCode, itemTransform) + if (rawTypeOf(wrapper) != rawTypeOf(originalListType)) { + if (constructor != null) add("?.let { %T(it) }", constructor) + else add("?.toList()") + } } - - if (isListNeedConstructor) builder.add(".let { %T(it) }", createType) - builder.build() }, ) diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/poet/FunSpecDsl.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/poet/FunSpecDsl.kt index 0d75e132..75c53e90 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/poet/FunSpecDsl.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/poet/FunSpecDsl.kt @@ -12,6 +12,7 @@ fun CodeBlock.Builder.controlFlow( beginControlFlow(controlFlow, *args) .add(CodeBlock.builder().apply(block).build()) .endControlFlow() + .add("\n") } @PoetDsl diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/module/GenModuleCacheControlProcessor.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/module/GenModuleCacheControlProcessor.kt index 49d4bc1b..a2b0aaf6 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/module/GenModuleCacheControlProcessor.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/module/GenModuleCacheControlProcessor.kt @@ -7,11 +7,14 @@ import com.github.klee0kai.stone.__hidden__.SwitchCacheParam import com.github.klee0kai.stone.annotations.module.Module import com.github.klee0kai.thekey.stone.ksp.exceptions.forEachFun import com.github.klee0kai.thekey.stone.ksp.helpers.* +import com.github.klee0kai.thekey.stone.ksp.helpers.wrap.WrapHelper import com.github.klee0kai.thekey.stone.ksp.ksp.arch.GenSpec import com.github.klee0kai.thekey.stone.ksp.ksp.arch.SymbolsToProcess import com.github.klee0kai.thekey.stone.ksp.ksp.arch.TargetFileProcessor import com.github.klee0kai.thekey.stone.ksp.ksp.getAllMethods +import com.github.klee0kai.thekey.stone.ksp.ksp.resolveAlias import com.github.klee0kai.thekey.stone.ksp.poet.* +import com.github.klee0kai.thekey.stone.ksp.target.component.collectWrapHelper import com.google.devtools.ksp.KspExperimental import com.google.devtools.ksp.containingFile import com.google.devtools.ksp.processing.Dependencies @@ -49,6 +52,7 @@ class GenModuleCacheControlProcessor : TargetFileProcessor { val componentCl = resolver.findComponentForModuleOrDep(moduleCl.toClassName()) .firstOrNull() + val wrapHelper = componentCl?.collectWrapHelper() ?: WrapHelper() val identifierTypes = componentCl ?.allIdentifierTypes?.toList() @@ -85,6 +89,8 @@ class GenModuleCacheControlProcessor : TargetFileProcessor { val methods = validSymbol.getAllMethods(includeObjectMethods = false, allowDoubles = false, "") methods.forEachFun { _, function -> val idArguments = function.parameters.identifierParameters(identifierTypes) + val returnType = function.returnType?.resolveAlias()?.toTypeName() ?: return@forEachFun + val cacheControlType = wrapHelper.listWrapTypeIfNeed(returnType).copy(nullable = true) genOverrideFun(function) { modifiers.remove(KModifier.OVERRIDE) @@ -92,7 +98,7 @@ class GenModuleCacheControlProcessor : TargetFileProcessor { } genFun(function.cacheControlMethodName) { modifiers.add(KModifier.ABSTRACT) - returns(returnType = function.returnType!!.resolve().toTypeName().copy(nullable = true)) + returns(returnType = cacheControlType) addParameter("__action", CacheAction::class) idArguments.forEach { addParameter(it.name!!.asString(), it.type.resolve().toTypeName()) diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/module/GenModuleProcessor.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/module/GenModuleProcessor.kt index 1d205bb3..94350c2f 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/module/GenModuleProcessor.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/module/GenModuleProcessor.kt @@ -158,15 +158,15 @@ class GenModuleProcessor : TargetFileProcessor { with(itemHolderCodeHelper) { genCacheField() - codeBlocks.bindMethodBody.apply { - add( - "if (or::class == %T::class) {\n", - rawTypeOf(nonWrappedType), - ) - add(codeSetCachedValue(CodeBlock.of("or as? %T", nonWrappedType), false)) - add("\n") - add("%L = true\n", appliedLocalFieldName) - add("}\n") + if (!isListReturnType) { + codeBlocks.bindMethodBody.controlFlow( + "if (or::class == %T::class) {", + rawTypeOf(nonWrappedType) + ) { + add(codeSetCachedValue(CodeBlock.of("or as? %T", nonWrappedType), false)) + addStatement("") + addStatement("%L = true\n", appliedLocalFieldName) + } } } @@ -292,7 +292,6 @@ class GenModuleProcessor : TargetFileProcessor { endControlFlow(); } - addCode("return ") addCode( wrapHelper.transform( @@ -370,10 +369,10 @@ class GenModuleProcessor : TargetFileProcessor { wrapHelper: WrapHelper, ) { val returnType = function.returnType?.resolve()?.toTypeName() ?: return - val cacheControlType = wrapHelper.listWrapTypeIfNeed(returnType) + val cacheControlType = wrapHelper.listWrapTypeIfNeed(returnType).copy(nullable = true) genFun(function.cacheControlMethodName) { modifiers.add(KModifier.OVERRIDE) - returns(returnType.copy(nullable = true)) + returns(cacheControlType.copy(nullable = true)) addParameter("__action", CacheAction::class) idArguments.forEach { addParameter(it.name!!.asString(), it.type.resolve().toTypeName()) diff --git a/tests_wraps_kotlin/src/main/kotlin/com/github/klee0kai/test/boxed/di/inject/CarBoxedInjectModule.kt b/tests_wraps_kotlin/src/main/kotlin/com/github/klee0kai/test/boxed/di/inject/CarBoxedInjectModule.kt index 896a7d58..8b530b06 100644 --- a/tests_wraps_kotlin/src/main/kotlin/com/github/klee0kai/test/boxed/di/inject/CarBoxedInjectModule.kt +++ b/tests_wraps_kotlin/src/main/kotlin/com/github/klee0kai/test/boxed/di/inject/CarBoxedInjectModule.kt @@ -13,6 +13,7 @@ import javax.inject.Provider @Module open class CarBoxedInjectModule { + @Named("fourWheels") @Provide(cache = Provide.CacheType.Weak) open fun fourWheels(): List> { diff --git a/tests_wraps_kotlin/src/main/kotlin/com/github/klee0kai/test/car/di/lists/cached/CarMultiCachedModule.kt b/tests_wraps_kotlin/src/main/kotlin/com/github/klee0kai/test/car/di/lists/cached/CarMultiCachedModule.kt index 2212081b..92cd88a4 100644 --- a/tests_wraps_kotlin/src/main/kotlin/com/github/klee0kai/test/car/di/lists/cached/CarMultiCachedModule.kt +++ b/tests_wraps_kotlin/src/main/kotlin/com/github/klee0kai/test/car/di/lists/cached/CarMultiCachedModule.kt @@ -3,7 +3,6 @@ package com.github.klee0kai.test.car.di.lists.cached import com.github.klee0kai.stone.annotations.module.Module import com.github.klee0kai.stone.annotations.module.Provide import com.github.klee0kai.stone.weakref.Ref -import com.github.klee0kai.stone.wrappers.Ref import com.github.klee0kai.test.car.model.Bumper import com.github.klee0kai.test.car.model.Car import com.github.klee0kai.test.car.model.Wheel diff --git a/tests_wraps_kotlin/src/main/kotlin/com/github/klee0kai/test/car/di/qualifiers/CarQCModule.kt b/tests_wraps_kotlin/src/main/kotlin/com/github/klee0kai/test/car/di/qualifiers/CarQCModule.kt index 424cb5c4..f2474e8a 100644 --- a/tests_wraps_kotlin/src/main/kotlin/com/github/klee0kai/test/car/di/qualifiers/CarQCModule.kt +++ b/tests_wraps_kotlin/src/main/kotlin/com/github/klee0kai/test/car/di/qualifiers/CarQCModule.kt @@ -39,13 +39,21 @@ open class CarQCModule { } @Provide(cache = Provide.CacheType.Factory) - open fun carList(@BumperQualifier bumper: List?, wheel: List?, window: List?): Car { + open fun carList( + @BumperQualifier bumper: List, + wheel: List, + window: List, + ): Car { return Car(bumper, wheel, window) } @Named @Provide(cache = Provide.CacheType.Factory) - open fun carNamedEmpty(@BumperQualifier bumper: List?, wheel: List?, window: List?): Car { + open fun carNamedEmpty( + @BumperQualifier bumper: List, + wheel: List, + window: List + ): Car { val car = Car(bumper, wheel, window) car.qualifier = "named_empty" return car @@ -54,9 +62,9 @@ open class CarQCModule { @Named("a") @Provide(cache = Provide.CacheType.Factory) open fun carNamedA( - @BumperQualifier(type = BumperQualifier.BumperType.Reinforced) bumper: List?, - wheel: List?, - window: List? + @BumperQualifier(type = BumperQualifier.BumperType.Reinforced) bumper: List, + wheel: List, + window: List ): Car { val car = Car(bumper, wheel, window) car.qualifier = "named_a" @@ -66,9 +74,9 @@ open class CarQCModule { @MyQualifier @Provide(cache = Provide.CacheType.Factory) open fun carMyQualifier( - @BumperQualifier bumper: List?, - wheel: List?, - window: List? + @BumperQualifier bumper: List, + wheel: List, + window: List ): Car { val car = Car(bumper, wheel, window) car.qualifier = "my_qualifier" @@ -78,9 +86,9 @@ open class CarQCModule { @MyQualifierWithString @Provide(cache = Provide.CacheType.Factory) open fun carIdQualifier( - @BumperQualifier bumper: List?, - wheel: List?, - window: List? + @BumperQualifier bumper: List, + wheel: List, + window: List ): Car { val car = Car(bumper, wheel, window) car.qualifier = "my_qualifier_with_string" @@ -90,9 +98,9 @@ open class CarQCModule { @MyQualifierWithString(id = "a") @Provide(cache = Provide.CacheType.Factory) open fun carIdQualifierA( - @BumperQualifier(type = BumperQualifier.BumperType.Reinforced) bumper: List?, - @WheelCount(count = 4) wheel: List?, - window: List? + @BumperQualifier(type = BumperQualifier.BumperType.Reinforced) bumper: List, + @WheelCount(count = 4) wheel: List, + window: List ): Car { val car = Car(bumper, wheel, window) car.qualifier = "my_qualifier_a" @@ -102,9 +110,9 @@ open class CarQCModule { @MyQualifierWithString(id = "b") @Provide(cache = Provide.CacheType.Factory) open fun carIdQualifierB( - @BumperQualifier bumper: List?, - wheel: List?, - window: List? + @BumperQualifier bumper: List, + wheel: List, + window: List ): Car { val car = Car(bumper, wheel, window) car.qualifier = "my_qualifier_b" @@ -114,9 +122,9 @@ open class CarQCModule { @MyQualifierMulti @Provide(cache = Provide.CacheType.Factory) open fun carQualifierMulti( - @BumperQualifier bumper: List?, - @WheelCount(count = 4) wheel: List?, - window: List? + @BumperQualifier bumper: List, + @WheelCount(count = 4) wheel: List, + window: List ): Car { val car = Car(bumper, wheel, window) car.qualifier = "qualifier_multi" @@ -126,9 +134,9 @@ open class CarQCModule { @MyQualifierMulti(id = "a", indx = 1) @Provide(cache = Provide.CacheType.Factory) open fun carQualifierMultiA1( - @BumperQualifier bumper: List?, - wheel: List?, - window: List? + @BumperQualifier bumper: List, + wheel: List, + window: List ): Car { val car = Car(bumper, wheel, window) car.qualifier = "qualifier_multi_a1" @@ -138,9 +146,9 @@ open class CarQCModule { @MyQualifierMulti(id = "a", indx = 2) @Provide(cache = Provide.CacheType.Factory) open fun carQualifierMultiA2( - @BumperQualifier(type = BumperQualifier.BumperType.Reinforced) bumper: List?, - @WheelCount(count = 4) wheel: List?, - window: List? + @BumperQualifier(type = BumperQualifier.BumperType.Reinforced) bumper: List, + @WheelCount(count = 4) wheel: List, + window: List ): Car { val car = Car(bumper, wheel, window) car.qualifier = "qualifier_multi_a2" @@ -150,9 +158,9 @@ open class CarQCModule { @MyQualifierMulti(id = "a", indx = 2, type = MyQualifierMulti.Type.HARD) @Provide(cache = Provide.CacheType.Factory) open fun carQualifierMultiA2Hard( - @BumperQualifier(type = BumperQualifier.BumperType.Simple) bumper: List?, - @WheelCount(count = 4) wheel: List?, - window: List? + @BumperQualifier(type = BumperQualifier.BumperType.Simple) bumper: List, + @WheelCount(count = 4) wheel: List, + window: List ): Car { val car = Car(bumper, wheel, window) car.qualifier = "qualifier_multi_a2_hard" diff --git a/tests_wraps_kotlin/src/main/kotlin/com/github/klee0kai/test/car/di/wrapped/custom/wrappers/CarProvide.kt b/tests_wraps_kotlin/src/main/kotlin/com/github/klee0kai/test/car/di/wrapped/custom/wrappers/CarProvide.kt index e1463f38..18bdaa7a 100644 --- a/tests_wraps_kotlin/src/main/kotlin/com/github/klee0kai/test/car/di/wrapped/custom/wrappers/CarProvide.kt +++ b/tests_wraps_kotlin/src/main/kotlin/com/github/klee0kai/test/car/di/wrapped/custom/wrappers/CarProvide.kt @@ -1,6 +1,6 @@ package com.github.klee0kai.test.car.di.wrapped.custom.wrappers -import com.github.klee0kai.stone.wrappers.Ref +import com.github.klee0kai.stone.weakref.Ref class CarProvide(private val call: Ref) { val value: T diff --git a/tests_wraps_kotlin/src/main/kotlin/com/github/klee0kai/test/car/model/Car.kt b/tests_wraps_kotlin/src/main/kotlin/com/github/klee0kai/test/car/model/Car.kt index 0502ad57..0e7707b6 100644 --- a/tests_wraps_kotlin/src/main/kotlin/com/github/klee0kai/test/car/model/Car.kt +++ b/tests_wraps_kotlin/src/main/kotlin/com/github/klee0kai/test/car/model/Car.kt @@ -21,7 +21,7 @@ class Car { windows = listOf(window) } - constructor(bumpers: List?, wheels: List?, windows: List?) { + constructor(bumpers: List, wheels: List, windows: List) { createCount++ this.bumpers = bumpers this.wheels = wheels From 9199a33d5b3a46f298408aa42dd16db27ac64649 Mon Sep 17 00:00:00 2001 From: klee0kai Date: Sun, 21 Dec 2025 12:47:45 +0100 Subject: [PATCH 085/122] short fixs --- .../com/github/klee0kai/thekey/stone/ksp/Processor.kt | 4 ++-- .../stone/ksp/target/component/ComponentGraphExt.kt | 2 +- .../thekey/stone/ksp/target/module/GenModuleProcessor.kt | 9 ++++++--- .../stone/__hidden__/types/holders/MapItemHolder.kt | 7 +++++-- .../klee0kai/test/car/di/inject/CarInjectComponent.kt | 3 ++- .../test/car/di/lists/cached/CarMultiCachedModule.kt | 2 +- .../klee0kai/test/car/di/lists/factory/CarMultiModule.kt | 2 +- 7 files changed, 18 insertions(+), 11 deletions(-) diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/Processor.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/Processor.kt index d0dace51..3389e645 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/Processor.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/Processor.kt @@ -63,8 +63,8 @@ class Processor( debugPkgFilter = options["debugPkgFilter"] // force changes - debug = true - debugPkgFilter = "com.github.klee0kai.test.car.di.bindinstance.simple" +// debug = true +// debugPkgFilter = "com.github.klee0kai.test.boxed.di.inject" } diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/component/ComponentGraphExt.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/component/ComponentGraphExt.kt index e8c44d66..3b9ef18d 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/component/ComponentGraphExt.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/component/ComponentGraphExt.kt @@ -42,7 +42,7 @@ fun KSClassDeclaration.collectWrapHelper( wrap = { or, nullable -> codeBlock { add( - "%T.%L{ %L }", + "%T.%L{ %L!! }", wrapperHelperClDec.toClassName(), m.simpleName.asString(), or, diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/module/GenModuleProcessor.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/module/GenModuleProcessor.kt index 94350c2f..99762bd7 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/module/GenModuleProcessor.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/module/GenModuleProcessor.kt @@ -25,6 +25,7 @@ import com.github.klee0kai.thekey.stone.ksp.ksp.arch.GenSpec import com.github.klee0kai.thekey.stone.ksp.ksp.arch.SymbolsToProcess import com.github.klee0kai.thekey.stone.ksp.ksp.arch.TargetFileProcessor import com.github.klee0kai.thekey.stone.ksp.ksp.getAllMethods +import com.github.klee0kai.thekey.stone.ksp.ksp.resolveAlias import com.github.klee0kai.thekey.stone.ksp.poet.* import com.github.klee0kai.thekey.stone.ksp.target.component.collectWrapHelper import com.google.devtools.ksp.KspExperimental @@ -195,8 +196,10 @@ class GenModuleProcessor : TargetFileProcessor { } genFun(function.cacheControlMethodName) { modifiers.add(KModifier.OVERRIDE) - val returnType = function.returnType?.resolve()?.toTypeName() - returnType?.let { returns(returnType.copy(nullable = true)) } + val cacheControlType = function.returnType?.resolveAlias() + ?.toTypeName() + ?.let { wrapHelper.listWrapTypeIfNeed(it).copy(nullable = true) } + cacheControlType?.let { returns(cacheControlType) } addParameter("__action", CacheAction::class) idArguments.forEach { addParameter(it.name!!.asString(), it.type.resolve().toTypeName()) @@ -368,7 +371,7 @@ class GenModuleProcessor : TargetFileProcessor { itemHolderCodeHelper: ItemHolderCodeHelper, wrapHelper: WrapHelper, ) { - val returnType = function.returnType?.resolve()?.toTypeName() ?: return + val returnType = function.returnType?.resolveAlias()?.toTypeName() ?: return val cacheControlType = wrapHelper.listWrapTypeIfNeed(returnType).copy(nullable = true) genFun(function.cacheControlMethodName) { modifiers.add(KModifier.OVERRIDE) diff --git a/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/__hidden__/types/holders/MapItemHolder.kt b/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/__hidden__/types/holders/MapItemHolder.kt index 468665ca..77799c73 100644 --- a/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/__hidden__/types/holders/MapItemHolder.kt +++ b/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/__hidden__/types/holders/MapItemHolder.kt @@ -36,11 +36,14 @@ class MapItemHolder( fun getList( key: Key?, - ): List? { + ): List? { val holder = refMap[key] ?: return null return when (curRefType) { StoneRefType.ListObject -> holder as MutableList? - StoneRefType.ListWeakObject, StoneRefType.ListSoftObject -> (holder as MutableList?>?)?.map { it?.get() } + StoneRefType.ListWeakObject, StoneRefType.ListSoftObject -> { + (holder as MutableList?>?)?.mapNotNull { it?.get() } + } + else -> null } } diff --git a/tests_wraps_kotlin/src/main/kotlin/com/github/klee0kai/test/car/di/inject/CarInjectComponent.kt b/tests_wraps_kotlin/src/main/kotlin/com/github/klee0kai/test/car/di/inject/CarInjectComponent.kt index 3b1888e1..62a47ff1 100644 --- a/tests_wraps_kotlin/src/main/kotlin/com/github/klee0kai/test/car/di/inject/CarInjectComponent.kt +++ b/tests_wraps_kotlin/src/main/kotlin/com/github/klee0kai/test/car/di/inject/CarInjectComponent.kt @@ -9,7 +9,8 @@ import com.github.klee0kai.test.car.model.CarInjectProvider @Component(wrapperHelpers = [CarBoxedWrapper::class]) abstract class CarInjectComponent { - protected abstract fun module(): CarInjectModule? + + abstract fun module(): CarInjectModule? abstract fun inject(carInject: CarInject?) abstract fun inject(carInject: CarInjectLists?) abstract fun inject(carInject: CarInjectProvider?) diff --git a/tests_wraps_kotlin/src/main/kotlin/com/github/klee0kai/test/car/di/lists/cached/CarMultiCachedModule.kt b/tests_wraps_kotlin/src/main/kotlin/com/github/klee0kai/test/car/di/lists/cached/CarMultiCachedModule.kt index 92cd88a4..9e8db5b8 100644 --- a/tests_wraps_kotlin/src/main/kotlin/com/github/klee0kai/test/car/di/lists/cached/CarMultiCachedModule.kt +++ b/tests_wraps_kotlin/src/main/kotlin/com/github/klee0kai/test/car/di/lists/cached/CarMultiCachedModule.kt @@ -46,5 +46,5 @@ abstract class CarMultiCachedModule { abstract fun redCar(bumper: Bumper?, wheel: Wheel?, window: Window?): List? @Provide(cache = Provide.CacheType.Weak) - abstract fun blueCar(bumpers: List?, wheels: List?, windows: List?): Car? + abstract fun blueCar(bumpers: List, wheels: List, windows: List): Car? } diff --git a/tests_wraps_kotlin/src/main/kotlin/com/github/klee0kai/test/car/di/lists/factory/CarMultiModule.kt b/tests_wraps_kotlin/src/main/kotlin/com/github/klee0kai/test/car/di/lists/factory/CarMultiModule.kt index a82cbd97..83166833 100644 --- a/tests_wraps_kotlin/src/main/kotlin/com/github/klee0kai/test/car/di/lists/factory/CarMultiModule.kt +++ b/tests_wraps_kotlin/src/main/kotlin/com/github/klee0kai/test/car/di/lists/factory/CarMultiModule.kt @@ -48,5 +48,5 @@ abstract class CarMultiModule { @Named("blueCar") @Provide(cache = Provide.CacheType.Factory) - abstract fun blueCar(bumpers: List?, wheels: List?, windows: List?): Car? + abstract fun blueCar(bumpers: List, wheels: List, windows: List): Car? } From 3baa2c1d4f95e8ddd96c75a8f196437ede8a80c6 Mon Sep 17 00:00:00 2001 From: klee0kai Date: Sun, 21 Dec 2025 14:17:33 +0100 Subject: [PATCH 086/122] migrate to component constructor --- .../boxed/inject/CarBoxedInjectMethodTests.kt | 20 ++-- .../test/boxed/inject/CarBoxedInjectTests.kt | 19 ++-- .../inject/CarBoxedProtectInjectedTests.kt | 14 +-- .../bindinstance/simple/BindBumperTests.kt | 14 +-- .../bindinstance/simple/BindWheelRefTests.kt | 14 +-- .../car/bindinstance/simple/BindWheelTests.kt | 15 ++- .../simple/BindWindowCollectionRefTests.kt | 18 +-- .../simple/BindWindowCollectionTests.kt | 14 +-- .../bindinstance/simple/BindWindowTests.kt | 12 +- .../kotlin/test/car/bluecar/BlueCarTest.kt | 16 +-- .../cachecontrol/gc/BumperGcResusableTests.kt | 22 ++-- .../test/car/cachecontrol/gc/BumperGcTests.kt | 24 ++-- .../test/car/cachecontrol/gc/WheelGcTests.kt | 26 +++-- .../car/cachecontrol/gc/WheelMappedGcTests.kt | 24 ++-- .../gc/WheelMultiMappedGcTests.kt | 24 ++-- .../cachecontrol/gc/WheelReusableGcTests.kt | 20 ++-- .../test/car/cachecontrol/gc/WindowGcTests.kt | 24 ++-- .../cachecontrol/gc/WindowMappedGcTests.kt | 24 ++-- .../gc/WindowMappedPartialGcTests.kt | 10 +- .../gc/WindowMappedReusableGcTests.kt | 22 ++-- .../gc/WindowMultiMappedGcTests.kt | 24 ++-- .../gc/WindowMultiMappedPartialGcTests.kt | 10 +- .../gc/WindowMultiMappedReusableGcTests.kt | 22 ++-- .../cachecontrol/gc/WindowPartialGcTests.kt | 14 +-- .../swcache/BumperSwitchCacheTests.kt | 24 ++-- .../swcache/WheelSwitchCacheTests.kt | 26 ++--- .../swcache/WindowMappedSwitchCacheTests.kt | 26 ++--- .../WindowMultiMappedSwitchCacheTests.kt | 26 ++--- .../swcache/WindowSwitchCacheTests.kt | 22 ++-- .../test/car/inject/CarInjectMethodTests.kt | 19 ++-- .../test/car/inject/CarInjectMixedTests.kt | 10 +- .../kotlin/test/car/inject/CarInjectTests.kt | 18 ++- .../car/inject/CarProtectInjectedTests.kt | 11 +- .../test/car/muti/MultiCachedProvideTest.kt | 30 ++--- .../kotlin/test/car/muti/MultiProvideTest.kt | 103 +++++++++--------- .../CarInjectAllMethodsWithQualifiersTest.kt | 28 +++-- .../CarInjectAllWithQualifiersTest.kt | 26 ++--- .../CarInjectMethodWithQualifiersTest.kt | 30 ++--- .../qualifiers/CarInjectWithQualifiersTest.kt | 30 ++--- .../CarProvideAllWithQualifiersTests.kt | 26 ++--- .../CarProvideWithQualifiersTests.kt | 24 ++-- .../test/car/wrapper/CarSingleWrapperTests.kt | 33 +++--- .../test/car/wrapper/CurCustomWrapperTests.kt | 11 +- 43 files changed, 473 insertions(+), 496 deletions(-) diff --git a/tests_wraps_kotlin/src/test/kotlin/com/github/klee0kai/stone/kotlin/test/boxed/inject/CarBoxedInjectMethodTests.kt b/tests_wraps_kotlin/src/test/kotlin/com/github/klee0kai/stone/kotlin/test/boxed/inject/CarBoxedInjectMethodTests.kt index ba2ad823..de4c9a6e 100644 --- a/tests_wraps_kotlin/src/test/kotlin/com/github/klee0kai/stone/kotlin/test/boxed/inject/CarBoxedInjectMethodTests.kt +++ b/tests_wraps_kotlin/src/test/kotlin/com/github/klee0kai/stone/kotlin/test/boxed/inject/CarBoxedInjectMethodTests.kt @@ -1,7 +1,6 @@ package com.github.klee0kai.stone.kotlin.test.boxed.inject -import com.github.klee0kai.stone.Stone -import com.github.klee0kai.test.boxed.di.inject.CarBoxedInjectComponent +import com.github.klee0kai.test.boxed.di.inject.CarBoxedInjectComponentStoneComponent import com.github.klee0kai.test.boxed.model.CarBoxedInject import com.github.klee0kai.test.boxed.model.CarBoxedInjectLists import com.github.klee0kai.test.boxed.model.CarBoxedInjectProvider @@ -26,7 +25,7 @@ class CarBoxedInjectMethodTests { @Test fun carInjectTest() { //Given - val DI = Stone.createComponent(CarBoxedInjectComponent::class.java) + val DI = CarBoxedInjectComponentStoneComponent() //When val carInject = CarBoxedInject() @@ -42,9 +41,7 @@ class CarBoxedInjectMethodTests { @Test fun carInjectReusableTest() { //Given - val DI = Stone.createComponent( - CarBoxedInjectComponent::class.java - ) + val DI = CarBoxedInjectComponentStoneComponent() //When val carInject1 = CarBoxedInject() @@ -75,7 +72,7 @@ class CarBoxedInjectMethodTests { @Test fun carInjectListTest() { //Given - val DI = Stone.createComponent(CarBoxedInjectComponent::class.java) + val DI = CarBoxedInjectComponentStoneComponent() //When val carInject = CarBoxedInjectLists() @@ -102,7 +99,7 @@ class CarBoxedInjectMethodTests { @Test fun carInjectListReusableTest() { //Given - val DI = Stone.createComponent(CarBoxedInjectComponent::class.java) + val DI = CarBoxedInjectComponentStoneComponent() //When val carInject1 = CarBoxedInjectLists() @@ -131,7 +128,7 @@ class CarBoxedInjectMethodTests { @Test fun carInjectProviderTest() { //Given - val DI = Stone.createComponent(CarBoxedInjectComponent::class.java) + val DI = CarBoxedInjectComponentStoneComponent() //When val carInject = CarBoxedInjectProvider() @@ -148,9 +145,8 @@ class CarBoxedInjectMethodTests { @Test fun carInjectProvideReusableTest() { //Given - val DI = Stone.createComponent( - CarBoxedInjectComponent::class.java - ) + val DI = CarBoxedInjectComponentStoneComponent() + //When val carInject1 = CarBoxedInjectProvider() diff --git a/tests_wraps_kotlin/src/test/kotlin/com/github/klee0kai/stone/kotlin/test/boxed/inject/CarBoxedInjectTests.kt b/tests_wraps_kotlin/src/test/kotlin/com/github/klee0kai/stone/kotlin/test/boxed/inject/CarBoxedInjectTests.kt index ae86668e..fa82e950 100644 --- a/tests_wraps_kotlin/src/test/kotlin/com/github/klee0kai/stone/kotlin/test/boxed/inject/CarBoxedInjectTests.kt +++ b/tests_wraps_kotlin/src/test/kotlin/com/github/klee0kai/stone/kotlin/test/boxed/inject/CarBoxedInjectTests.kt @@ -1,7 +1,6 @@ package com.github.klee0kai.stone.kotlin.test.boxed.inject -import com.github.klee0kai.stone.Stone -import com.github.klee0kai.test.boxed.di.inject.CarBoxedInjectComponent +import com.github.klee0kai.test.boxed.di.inject.CarBoxedInjectComponentStoneComponent import com.github.klee0kai.test.boxed.model.CarBoxedInject import com.github.klee0kai.test.boxed.model.CarBoxedInjectLists import com.github.klee0kai.test.boxed.model.CarBoxedInjectProvider @@ -25,7 +24,7 @@ class CarBoxedInjectTests { @Test fun carInjectTest() { //Given - val DI = Stone.createComponent(CarBoxedInjectComponent::class.java) + val DI = CarBoxedInjectComponentStoneComponent() //When val carInject = CarBoxedInject() @@ -41,9 +40,7 @@ class CarBoxedInjectTests { @Test fun carInjectReusableTest() { //Given - val DI = Stone.createComponent( - CarBoxedInjectComponent::class.java - ) + val DI = CarBoxedInjectComponentStoneComponent() //When val carInject1 = CarBoxedInject() @@ -66,9 +63,7 @@ class CarBoxedInjectTests { @Test fun carInjectListTest() { //Given - val DI = Stone.createComponent( - CarBoxedInjectComponent::class.java - ) + val DI = CarBoxedInjectComponentStoneComponent() //When val carInject = CarBoxedInjectLists() @@ -95,7 +90,7 @@ class CarBoxedInjectTests { @Test fun carInjectListReusableTest() { //Given - val DI = Stone.createComponent(CarBoxedInjectComponent::class.java) + val DI = CarBoxedInjectComponentStoneComponent() //When val carInject1 = CarBoxedInjectLists() @@ -118,7 +113,7 @@ class CarBoxedInjectTests { @Test fun carInjectProviderTest() { //Given - val DI = Stone.createComponent(CarBoxedInjectComponent::class.java) + val DI = CarBoxedInjectComponentStoneComponent() //When val carInject = CarBoxedInjectProvider() @@ -135,7 +130,7 @@ class CarBoxedInjectTests { @Test fun carInjectProvideReusableTest() { //Given - val DI = Stone.createComponent(CarBoxedInjectComponent::class.java) + val DI = CarBoxedInjectComponentStoneComponent() //When val carInject1 = CarBoxedInjectProvider() diff --git a/tests_wraps_kotlin/src/test/kotlin/com/github/klee0kai/stone/kotlin/test/boxed/inject/CarBoxedProtectInjectedTests.kt b/tests_wraps_kotlin/src/test/kotlin/com/github/klee0kai/stone/kotlin/test/boxed/inject/CarBoxedProtectInjectedTests.kt index b54d9d69..41946ec8 100644 --- a/tests_wraps_kotlin/src/test/kotlin/com/github/klee0kai/stone/kotlin/test/boxed/inject/CarBoxedProtectInjectedTests.kt +++ b/tests_wraps_kotlin/src/test/kotlin/com/github/klee0kai/stone/kotlin/test/boxed/inject/CarBoxedProtectInjectedTests.kt @@ -1,7 +1,6 @@ package com.github.klee0kai.stone.kotlin.test.boxed.inject -import com.github.klee0kai.stone.Stone -import com.github.klee0kai.test.boxed.di.inject.CarBoxedInjectComponent +import com.github.klee0kai.test.boxed.di.inject.CarBoxedInjectComponentStoneComponent import com.github.klee0kai.test.boxed.model.CarBoxedInject import com.github.klee0kai.test.boxed.model.CarBoxedInjectLists import com.github.klee0kai.test.boxed.model.CarBoxedInjectProvider @@ -12,8 +11,9 @@ import org.junit.jupiter.api.Test class CarBoxedProtectInjectedTests { @Test fun carProtectInjectedTest() { + //Given - val DI = Stone.createComponent(CarBoxedInjectComponent::class.java) + val DI = CarBoxedInjectComponentStoneComponent() //When var carInject: CarBoxedInject? @@ -37,9 +37,7 @@ class CarBoxedProtectInjectedTests { @Test fun carProtectListInjectedTest() { - val DI = Stone.createComponent( - CarBoxedInjectComponent::class.java - ) + val DI = CarBoxedInjectComponentStoneComponent() //When var carInject: CarBoxedInjectLists? = CarBoxedInjectLists() @@ -63,9 +61,7 @@ class CarBoxedProtectInjectedTests { @Test fun carProtectProviderTest() { //Given - val DI = Stone.createComponent( - CarBoxedInjectComponent::class.java - ) + val DI = CarBoxedInjectComponentStoneComponent() //When var carInject: CarBoxedInjectProvider? = CarBoxedInjectProvider() diff --git a/tests_wraps_kotlin/src/test/kotlin/com/github/klee0kai/stone/kotlin/test/car/bindinstance/simple/BindBumperTests.kt b/tests_wraps_kotlin/src/test/kotlin/com/github/klee0kai/stone/kotlin/test/car/bindinstance/simple/BindBumperTests.kt index 6929c467..c9356759 100644 --- a/tests_wraps_kotlin/src/test/kotlin/com/github/klee0kai/stone/kotlin/test/car/bindinstance/simple/BindBumperTests.kt +++ b/tests_wraps_kotlin/src/test/kotlin/com/github/klee0kai/stone/kotlin/test/car/bindinstance/simple/BindBumperTests.kt @@ -1,17 +1,17 @@ package com.github.klee0kai.stone.kotlin.test.car.bindinstance.simple -import com.github.klee0kai.stone.Stone -import com.github.klee0kai.test.car.di.bindinstance.simple.CarBindComponent +import com.github.klee0kai.test.car.di.bindinstance.simple.CarBindComponentStoneComponent import com.github.klee0kai.test.car.model.Bumper import org.junit.jupiter.api.Assertions.assertEquals import org.junit.jupiter.api.Assertions.assertNull import org.junit.jupiter.api.Test class BindBumperTests { + @Test fun noBindTest() { //Given - val DI = Stone.createComponent(CarBindComponent::class.java) + val DI = CarBindComponentStoneComponent() //Then assertNull(DI.module().bumper()) @@ -22,9 +22,7 @@ class BindBumperTests { @Test fun nullBindTest() { //Given - val DI = Stone.createComponent( - CarBindComponent::class.java - ) + val DI = CarBindComponentStoneComponent() //When DI.bindBumper(null) @@ -38,7 +36,7 @@ class BindBumperTests { @Test fun bindWheelSimpleTest() { //Given - val DI = Stone.createComponent(CarBindComponent::class.java) + val DI = CarBindComponentStoneComponent() //When val bumper = Bumper() @@ -54,7 +52,7 @@ class BindBumperTests { @Test fun rebindWheelSimpleTest() { //Given - val DI = Stone.createComponent(CarBindComponent::class.java) + val DI = CarBindComponentStoneComponent() DI.bindBumper { Bumper() } //When diff --git a/tests_wraps_kotlin/src/test/kotlin/com/github/klee0kai/stone/kotlin/test/car/bindinstance/simple/BindWheelRefTests.kt b/tests_wraps_kotlin/src/test/kotlin/com/github/klee0kai/stone/kotlin/test/car/bindinstance/simple/BindWheelRefTests.kt index 01eea9a8..f11d5fdf 100644 --- a/tests_wraps_kotlin/src/test/kotlin/com/github/klee0kai/stone/kotlin/test/car/bindinstance/simple/BindWheelRefTests.kt +++ b/tests_wraps_kotlin/src/test/kotlin/com/github/klee0kai/stone/kotlin/test/car/bindinstance/simple/BindWheelRefTests.kt @@ -1,7 +1,6 @@ package com.github.klee0kai.stone.kotlin.test.car.bindinstance.simple -import com.github.klee0kai.stone.Stone -import com.github.klee0kai.test.car.di.bindinstance.simple.CarBindComponent +import com.github.klee0kai.test.car.di.bindinstance.simple.CarBindComponentStoneComponent import com.github.klee0kai.test.car.model.Wheel import org.junit.jupiter.api.Assertions.assertEquals import org.junit.jupiter.api.Assertions.assertNull @@ -9,10 +8,11 @@ import org.junit.jupiter.api.Test import java.lang.ref.WeakReference class BindWheelRefTests { + @Test fun noBindTest() { //Given - val DI = Stone.createComponent(CarBindComponent::class.java) + val DI = CarBindComponentStoneComponent() //Then assertNull(DI.module().wheel()) @@ -24,7 +24,7 @@ class BindWheelRefTests { @Test fun nullBindTest() { //Given - val DI = Stone.createComponent(CarBindComponent::class.java) + val DI = CarBindComponentStoneComponent() //When DI.bindWheelRef(null) @@ -39,7 +39,7 @@ class BindWheelRefTests { @Test fun nullRefBindTest() { //Given - val DI = Stone.createComponent(CarBindComponent::class.java) + val DI = CarBindComponentStoneComponent() //When DI.bindWheelRef(WeakReference(null)) @@ -54,7 +54,7 @@ class BindWheelRefTests { @Test fun bindWheelSimpleTest() { //Given - val DI = Stone.createComponent(CarBindComponent::class.java) + val DI = CarBindComponentStoneComponent() //When val wheel = Wheel() @@ -71,7 +71,7 @@ class BindWheelRefTests { @Test fun rebindWheelSimpleTest() { //Given - val DI = Stone.createComponent(CarBindComponent::class.java) + val DI = CarBindComponentStoneComponent() DI.bindWheel(Wheel()) //When diff --git a/tests_wraps_kotlin/src/test/kotlin/com/github/klee0kai/stone/kotlin/test/car/bindinstance/simple/BindWheelTests.kt b/tests_wraps_kotlin/src/test/kotlin/com/github/klee0kai/stone/kotlin/test/car/bindinstance/simple/BindWheelTests.kt index f6bcc790..21355255 100644 --- a/tests_wraps_kotlin/src/test/kotlin/com/github/klee0kai/stone/kotlin/test/car/bindinstance/simple/BindWheelTests.kt +++ b/tests_wraps_kotlin/src/test/kotlin/com/github/klee0kai/stone/kotlin/test/car/bindinstance/simple/BindWheelTests.kt @@ -1,17 +1,17 @@ package com.github.klee0kai.stone.kotlin.test.car.bindinstance.simple -import com.github.klee0kai.stone.Stone -import com.github.klee0kai.test.car.di.bindinstance.simple.CarBindComponent +import com.github.klee0kai.test.car.di.bindinstance.simple.CarBindComponentStoneComponent import com.github.klee0kai.test.car.model.Wheel import org.junit.jupiter.api.Assertions.assertEquals import org.junit.jupiter.api.Assertions.assertNull import org.junit.jupiter.api.Test class BindWheelTests { + @Test fun noBindTest() { //Given - val DI = Stone.createComponent(CarBindComponent::class.java) + val DI = CarBindComponentStoneComponent() //Then assertNull(DI.module()!!.wheel()) @@ -23,7 +23,7 @@ class BindWheelTests { @Test fun nullBindTest() { //Given - val DI = Stone.createComponent(CarBindComponent::class.java) + val DI = CarBindComponentStoneComponent() //When DI.bindWheel(null) @@ -38,9 +38,8 @@ class BindWheelTests { @Test fun bindWheelSimpleTest() { //Given - val DI = Stone.createComponent( - CarBindComponent::class.java - ) + val DI = CarBindComponentStoneComponent() + //When val wheel = Wheel() @@ -57,7 +56,7 @@ class BindWheelTests { @Test fun rebindWheelSimpleTest() { //Given - val DI = Stone.createComponent(CarBindComponent::class.java) + val DI = CarBindComponentStoneComponent() DI.bindWheel(Wheel()) //When diff --git a/tests_wraps_kotlin/src/test/kotlin/com/github/klee0kai/stone/kotlin/test/car/bindinstance/simple/BindWindowCollectionRefTests.kt b/tests_wraps_kotlin/src/test/kotlin/com/github/klee0kai/stone/kotlin/test/car/bindinstance/simple/BindWindowCollectionRefTests.kt index 5a2c26cd..ccfa015e 100644 --- a/tests_wraps_kotlin/src/test/kotlin/com/github/klee0kai/stone/kotlin/test/car/bindinstance/simple/BindWindowCollectionRefTests.kt +++ b/tests_wraps_kotlin/src/test/kotlin/com/github/klee0kai/stone/kotlin/test/car/bindinstance/simple/BindWindowCollectionRefTests.kt @@ -1,7 +1,6 @@ package com.github.klee0kai.stone.kotlin.test.car.bindinstance.simple -import com.github.klee0kai.stone.Stone -import com.github.klee0kai.test.car.di.bindinstance.simple.CarBindComponent +import com.github.klee0kai.test.car.di.bindinstance.simple.CarBindComponentStoneComponent import com.github.klee0kai.test.car.model.Window import org.junit.jupiter.api.Assertions import org.junit.jupiter.api.Assertions.assertEquals @@ -10,10 +9,11 @@ import java.lang.ref.WeakReference import java.util.* class BindWindowCollectionRefTests { + @Test fun bindWindowSimpleTest() { //Given - val DI = Stone.createComponent(CarBindComponent::class.java) + val DI = CarBindComponentStoneComponent() //When val window = Window() @@ -29,7 +29,7 @@ class BindWindowCollectionRefTests { @Test fun bindWindowListTest() { //Given - val DI = Stone.createComponent(CarBindComponent::class.java) + val DI = CarBindComponentStoneComponent() //When val window1 = Window() @@ -48,7 +48,7 @@ class BindWindowCollectionRefTests { @Test fun rebindWindowSimpleTest() { //Given - val DI = Stone.createComponent(CarBindComponent::class.java) + val DI = CarBindComponentStoneComponent() DI.bindWindow(Window()) //When @@ -65,7 +65,7 @@ class BindWindowCollectionRefTests { @Test fun rebindWindowListTest() { //Given - val DI = Stone.createComponent(CarBindComponent::class.java) + val DI = CarBindComponentStoneComponent() DI.bindWindow(Window()) //When @@ -85,7 +85,7 @@ class BindWindowCollectionRefTests { @Test fun rebindWindowSimple2Test() { //Given - val DI = Stone.createComponent(CarBindComponent::class.java) + val DI = CarBindComponentStoneComponent() DI.bindWindowRefs(listOf(WeakReference(Window()))) //When @@ -102,7 +102,7 @@ class BindWindowCollectionRefTests { @Test fun unbindWindowEmptyListTest() { //Given - val DI = Stone.createComponent(CarBindComponent::class.java) + val DI = CarBindComponentStoneComponent() DI.bindWindowRefs(Arrays.asList(WeakReference(Window()), WeakReference(Window()))) //When @@ -117,7 +117,7 @@ class BindWindowCollectionRefTests { @Test fun unbindWindowListRefTest() { //Given - val DI = Stone.createComponent(CarBindComponent::class.java) + val DI = CarBindComponentStoneComponent() DI.bindWindowRefs(listOf(WeakReference(Window()), WeakReference(Window()))) //When diff --git a/tests_wraps_kotlin/src/test/kotlin/com/github/klee0kai/stone/kotlin/test/car/bindinstance/simple/BindWindowCollectionTests.kt b/tests_wraps_kotlin/src/test/kotlin/com/github/klee0kai/stone/kotlin/test/car/bindinstance/simple/BindWindowCollectionTests.kt index 42823b3d..3d81784d 100644 --- a/tests_wraps_kotlin/src/test/kotlin/com/github/klee0kai/stone/kotlin/test/car/bindinstance/simple/BindWindowCollectionTests.kt +++ b/tests_wraps_kotlin/src/test/kotlin/com/github/klee0kai/stone/kotlin/test/car/bindinstance/simple/BindWindowCollectionTests.kt @@ -1,16 +1,16 @@ package com.github.klee0kai.stone.kotlin.test.car.bindinstance.simple -import com.github.klee0kai.stone.Stone -import com.github.klee0kai.test.car.di.bindinstance.simple.CarBindComponent +import com.github.klee0kai.test.car.di.bindinstance.simple.CarBindComponentStoneComponent import com.github.klee0kai.test.car.model.Window import org.junit.jupiter.api.Assertions.assertEquals import org.junit.jupiter.api.Test class BindWindowCollectionTests { + @Test fun bindWindowSimpleTest() { //Given - val DI = Stone.createComponent(CarBindComponent::class.java) + val DI = CarBindComponentStoneComponent() //When val window = Window() @@ -26,7 +26,7 @@ class BindWindowCollectionTests { @Test fun bindWindowListTest() { //Given - val DI = Stone.createComponent(CarBindComponent::class.java) + val DI = CarBindComponentStoneComponent() //When val window1 = Window() @@ -45,7 +45,7 @@ class BindWindowCollectionTests { @Test fun rebindWindowSimpleTest() { //Given - val DI = Stone.createComponent(CarBindComponent::class.java) + val DI = CarBindComponentStoneComponent() DI.bindWindow(Window()) //When @@ -62,7 +62,7 @@ class BindWindowCollectionTests { @Test fun rebindWindowListTest() { //Given - val DI = Stone.createComponent(CarBindComponent::class.java) + val DI = CarBindComponentStoneComponent() DI.bindWindow(Window()) //When @@ -82,7 +82,7 @@ class BindWindowCollectionTests { @Test fun rebindWindowSimple2Test() { //Given - val DI = Stone.createComponent(CarBindComponent::class.java) + val DI = CarBindComponentStoneComponent() DI.bindWindows(listOf(Window())) //When diff --git a/tests_wraps_kotlin/src/test/kotlin/com/github/klee0kai/stone/kotlin/test/car/bindinstance/simple/BindWindowTests.kt b/tests_wraps_kotlin/src/test/kotlin/com/github/klee0kai/stone/kotlin/test/car/bindinstance/simple/BindWindowTests.kt index 4383cdd4..1fcaf314 100644 --- a/tests_wraps_kotlin/src/test/kotlin/com/github/klee0kai/stone/kotlin/test/car/bindinstance/simple/BindWindowTests.kt +++ b/tests_wraps_kotlin/src/test/kotlin/com/github/klee0kai/stone/kotlin/test/car/bindinstance/simple/BindWindowTests.kt @@ -1,17 +1,17 @@ package com.github.klee0kai.stone.kotlin.test.car.bindinstance.simple -import com.github.klee0kai.stone.Stone -import com.github.klee0kai.test.car.di.bindinstance.simple.CarBindComponent +import com.github.klee0kai.test.car.di.bindinstance.simple.CarBindComponentStoneComponent import com.github.klee0kai.test.car.model.Window import org.junit.jupiter.api.Assertions.assertEquals import org.junit.jupiter.api.Assertions.assertNull import org.junit.jupiter.api.Test class BindWindowTests { + @Test fun noBindTest() { //Given - val DI = Stone.createComponent(CarBindComponent::class.java) + val DI = CarBindComponentStoneComponent() //Then assertNull(DI.module().windows()) @@ -22,7 +22,7 @@ class BindWindowTests { @Test fun nullBindTest() { //Given - val DI = Stone.createComponent(CarBindComponent::class.java) + val DI = CarBindComponentStoneComponent() //When DI.bindWindow(null) @@ -36,7 +36,7 @@ class BindWindowTests { @Test fun bindWindowSimpleTest() { //Given - val DI = Stone.createComponent(CarBindComponent::class.java) + val DI = CarBindComponentStoneComponent() //When val window = Window() @@ -52,7 +52,7 @@ class BindWindowTests { @Test fun rebindWindowSimpleTest() { //Given - val DI = Stone.createComponent(CarBindComponent::class.java) + val DI = CarBindComponentStoneComponent() DI.bindWindow(Window()) //When diff --git a/tests_wraps_kotlin/src/test/kotlin/com/github/klee0kai/stone/kotlin/test/car/bluecar/BlueCarTest.kt b/tests_wraps_kotlin/src/test/kotlin/com/github/klee0kai/stone/kotlin/test/car/bluecar/BlueCarTest.kt index bd231216..11365a4a 100644 --- a/tests_wraps_kotlin/src/test/kotlin/com/github/klee0kai/stone/kotlin/test/car/bluecar/BlueCarTest.kt +++ b/tests_wraps_kotlin/src/test/kotlin/com/github/klee0kai/stone/kotlin/test/car/bluecar/BlueCarTest.kt @@ -1,9 +1,8 @@ package com.github.klee0kai.stone.kotlin.test.car.bluecar -import com.github.klee0kai.stone.Stone -import com.github.klee0kai.test.car.di.bestOf.blue.BlueCarComponent -import com.github.klee0kai.test.car.di.bestOf.both.BothCarComponent -import com.github.klee0kai.test.car.di.bestOf.red.RedCarComponent +import com.github.klee0kai.test.car.di.bestOf.blue.BlueCarComponentStoneComponent +import com.github.klee0kai.test.car.di.bestOf.both.BothCarComponentStoneComponent +import com.github.klee0kai.test.car.di.bestOf.red.RedCarComponentStoneComponent import com.github.klee0kai.test.car.model.Bumper import com.github.klee0kai.test.car.model.Car import com.github.klee0kai.test.car.model.Wheel @@ -14,6 +13,7 @@ import org.junit.jupiter.api.BeforeEach import org.junit.jupiter.api.Test class BlueCarTest { + @BeforeEach fun init() { Bumper.createCount = 0 @@ -25,7 +25,7 @@ class BlueCarTest { @Test fun blueCarComponent() { //Given - val DI = Stone.createComponent(BlueCarComponent::class.java) + val DI = BlueCarComponentStoneComponent() //When assertEquals(0, Car.createCount) @@ -42,7 +42,7 @@ class BlueCarTest { @Test fun createBlueCar() { //Given - val DI = Stone.createComponent(BothCarComponent::class.java) + val DI = BothCarComponentStoneComponent() //When assertEquals(0, Car.createCount) @@ -59,7 +59,7 @@ class BlueCarTest { @Test fun redCarComponent() { //Given - val DI = Stone.createComponent(RedCarComponent::class.java) + val DI = RedCarComponentStoneComponent() //When assertEquals(0, Car.createCount) @@ -76,7 +76,7 @@ class BlueCarTest { @Test fun createRedCar() { //Given - val DI = Stone.createComponent(BothCarComponent::class.java) + val DI = BothCarComponentStoneComponent() //When assertEquals(0, Car.createCount) diff --git a/tests_wraps_kotlin/src/test/kotlin/com/github/klee0kai/stone/kotlin/test/car/cachecontrol/gc/BumperGcResusableTests.kt b/tests_wraps_kotlin/src/test/kotlin/com/github/klee0kai/stone/kotlin/test/car/cachecontrol/gc/BumperGcResusableTests.kt index 0c8ab1d3..2df100b9 100644 --- a/tests_wraps_kotlin/src/test/kotlin/com/github/klee0kai/stone/kotlin/test/car/cachecontrol/gc/BumperGcResusableTests.kt +++ b/tests_wraps_kotlin/src/test/kotlin/com/github/klee0kai/stone/kotlin/test/car/cachecontrol/gc/BumperGcResusableTests.kt @@ -1,17 +1,17 @@ package com.github.klee0kai.stone.kotlin.test.car.cachecontrol.gc -import com.github.klee0kai.stone.Stone import com.github.klee0kai.stone.kotlin.test.utils.KotlinUtils.resetKotlinRegisters -import com.github.klee0kai.test.car.di.cachecontrol.gc.CarGcComponent +import com.github.klee0kai.test.car.di.cachecontrol.gc.CarGcComponentStoneComponent import org.junit.jupiter.api.Assertions.assertEquals import org.junit.jupiter.api.Assertions.assertNotEquals import org.junit.jupiter.api.Test class BumperGcResusableTests { + @Test fun gcAllTest() { // Given - val DI = Stone.createComponent(CarGcComponent::class.java) + val DI = CarGcComponentStoneComponent() val bumperFactoryUids1 = DI.bumpersModule()!!.bumperFactory().map { it.uuid } val bumperWeakUids1 = DI.bumpersModule()!!.bumperWeak().map { it.uuid } val bumperSoftUids1 = DI.bumpersModule()!!.bumperSoft().map { it.uuid } @@ -35,7 +35,7 @@ class BumperGcResusableTests { @Test fun gcWeakTest() { // Given - val DI = Stone.createComponent(CarGcComponent::class.java) + val DI = CarGcComponentStoneComponent() val bumperFactoryUids1 = DI.bumpersModule()!!.bumperFactory().map { it.uuid } val bumperWeakUids1 = DI.bumpersModule()!!.bumperWeak().map { it.uuid } val bumperSoftUids1 = DI.bumpersModule()!!.bumperSoft().map { it.uuid } @@ -60,7 +60,7 @@ class BumperGcResusableTests { @Test fun gcSoftTest() { // Given - val DI = Stone.createComponent(CarGcComponent::class.java) + val DI = CarGcComponentStoneComponent() val bumperFactoryUids1 = DI.bumpersModule()!!.bumperFactory().map { it.uuid } val bumperWeakUids1 = DI.bumpersModule()!!.bumperWeak().map { it.uuid } val bumperSoftUids1 = DI.bumpersModule()!!.bumperSoft().map { it.uuid } @@ -84,7 +84,7 @@ class BumperGcResusableTests { @Test fun gcStrongTest() { // Given - val DI = Stone.createComponent(CarGcComponent::class.java) + val DI = CarGcComponentStoneComponent() val bumperFactoryUids1 = DI.bumpersModule()!!.bumperFactory().map { it.uuid } val bumperWeakUids1 = DI.bumpersModule()!!.bumperWeak().map { it.uuid } val bumperSoftUids1 = DI.bumpersModule()!!.bumperSoft().map { it.uuid } @@ -108,7 +108,7 @@ class BumperGcResusableTests { @Test fun gcBumpers() { // Given - val DI = Stone.createComponent(CarGcComponent::class.java) + val DI = CarGcComponentStoneComponent() val bumperFactoryUids1 = DI.bumpersModule()!!.bumperFactory().map { it.uuid } val bumperWeakUids1 = DI.bumpersModule()!!.bumperWeak().map { it.uuid } val bumperSoftUids1 = DI.bumpersModule()!!.bumperSoft().map { it.uuid } @@ -132,7 +132,7 @@ class BumperGcResusableTests { @Test fun gcRedBumpers() { // Given - val DI = Stone.createComponent(CarGcComponent::class.java) + val DI = CarGcComponentStoneComponent() val bumperFactoryUids1 = DI.bumpersModule()!!.bumperFactory().map { it.uuid } val bumperWeakUids1 = DI.bumpersModule()!!.bumperWeak().map { it.uuid } val bumperSoftUids1 = DI.bumpersModule()!!.bumperSoft().map { it.uuid } @@ -156,7 +156,7 @@ class BumperGcResusableTests { @Test fun gcRedBumpers2() { // Given - val DI = Stone.createComponent(CarGcComponent::class.java) + val DI = CarGcComponentStoneComponent() val bumperFactoryUids1 = DI.bumpersModule()!!.bumperFactory().map { it.uuid } val bumperWeakUids1 = DI.bumpersModule()!!.bumperWeak().map { it.uuid } val bumperSoftUids1 = DI.bumpersModule()!!.bumperSoft().map { it.uuid } @@ -180,7 +180,7 @@ class BumperGcResusableTests { @Test fun gcWheelsTest() { // Given - val DI = Stone.createComponent(CarGcComponent::class.java) + val DI = CarGcComponentStoneComponent() val bumperFactoryUids1 = DI.bumpersModule()!!.bumperFactory().map { it.uuid } val bumperWeakUids1 = DI.bumpersModule()!!.bumperWeak().map { it.uuid } val bumperSoftUids1 = DI.bumpersModule()!!.bumperSoft().map { it.uuid } @@ -204,7 +204,7 @@ class BumperGcResusableTests { @Test fun gcNothing() { // Given - val DI = Stone.createComponent(CarGcComponent::class.java) + val DI = CarGcComponentStoneComponent() val bumperFactoryUids1 = DI.bumpersModule()!!.bumperFactory().map { it.uuid } val bumperWeakUids1 = DI.bumpersModule()!!.bumperWeak().map { it.uuid } val bumperSoftUids1 = DI.bumpersModule()!!.bumperSoft().map { it.uuid } diff --git a/tests_wraps_kotlin/src/test/kotlin/com/github/klee0kai/stone/kotlin/test/car/cachecontrol/gc/BumperGcTests.kt b/tests_wraps_kotlin/src/test/kotlin/com/github/klee0kai/stone/kotlin/test/car/cachecontrol/gc/BumperGcTests.kt index 2cca68e2..5a8761c7 100644 --- a/tests_wraps_kotlin/src/test/kotlin/com/github/klee0kai/stone/kotlin/test/car/cachecontrol/gc/BumperGcTests.kt +++ b/tests_wraps_kotlin/src/test/kotlin/com/github/klee0kai/stone/kotlin/test/car/cachecontrol/gc/BumperGcTests.kt @@ -1,18 +1,18 @@ package com.github.klee0kai.stone.kotlin.test.car.cachecontrol.gc -import com.github.klee0kai.stone.Stone import com.github.klee0kai.stone.kotlin.test.utils.KotlinUtils.resetKotlinRegisters -import com.github.klee0kai.test.car.di.cachecontrol.gc.CarGcComponent +import com.github.klee0kai.test.car.di.cachecontrol.gc.CarGcComponentStoneComponent import com.github.klee0kai.test.car.model.Bumper import org.junit.jupiter.api.Assertions.assertEquals import org.junit.jupiter.api.Test import java.lang.ref.WeakReference class BumperGcTests { + @Test fun createWorkCorrect() { // Given - val DI = Stone.createComponent(CarGcComponent::class.java) + val DI = CarGcComponentStoneComponent() //When val bumperFactory = DI.bumpersModule()!!.bumperFactory().map { WeakReference(it) } @@ -30,7 +30,7 @@ class BumperGcTests { @Test fun gcAllTest() { // Given - val DI = Stone.createComponent(CarGcComponent::class.java) + val DI = CarGcComponentStoneComponent() val bumperFactory = DI.bumpersModule()!!.bumperFactory().map { WeakReference(it) } val bumperWeak = DI.bumpersModule()!!.bumperWeak().map { WeakReference(it) } val bumperSoft = DI.bumpersModule()!!.bumperSoft().map { WeakReference(it) } @@ -50,7 +50,7 @@ class BumperGcTests { @Test fun gcWeakTest() { // Given - val DI = Stone.createComponent(CarGcComponent::class.java) + val DI = CarGcComponentStoneComponent() val bumperFactory = DI.bumpersModule()!!.bumperFactory().map { WeakReference(it) } val bumperWeak = DI.bumpersModule()!!.bumperWeak().map { WeakReference(it) } val bumperSoft = DI.bumpersModule()!!.bumperSoft().map { WeakReference(it) } @@ -70,7 +70,7 @@ class BumperGcTests { @Test fun gcSoftTest() { // Given - val DI = Stone.createComponent(CarGcComponent::class.java) + val DI = CarGcComponentStoneComponent() val bumperFactory = DI.bumpersModule()!!.bumperFactory().map { WeakReference(it) } val bumperWeak = DI.bumpersModule()!!.bumperWeak().map { WeakReference(it) } val bumperSoft = DI.bumpersModule()!!.bumperSoft().map { WeakReference(it) } @@ -90,7 +90,7 @@ class BumperGcTests { @Test fun gcStrongTest() { // Given - val DI = Stone.createComponent(CarGcComponent::class.java) + val DI = CarGcComponentStoneComponent() val bumperFactory = DI.bumpersModule()!!.bumperFactory().map { WeakReference(it) } val bumperWeak = DI.bumpersModule()!!.bumperWeak().map { WeakReference(it) } val bumperSoft = DI.bumpersModule()!!.bumperSoft().map { WeakReference(it) } @@ -110,7 +110,7 @@ class BumperGcTests { @Test fun gcBumpers() { // Given - val DI = Stone.createComponent(CarGcComponent::class.java) + val DI = CarGcComponentStoneComponent() val bumperFactory = DI.bumpersModule()!!.bumperFactory().map { WeakReference(it) } val bumperWeak = DI.bumpersModule()!!.bumperWeak().map { WeakReference(it) } val bumperSoft = DI.bumpersModule()!!.bumperSoft().map { WeakReference(it) } @@ -130,7 +130,7 @@ class BumperGcTests { @Test fun gcRedBumpers() { // Given - val DI = Stone.createComponent(CarGcComponent::class.java) + val DI = CarGcComponentStoneComponent() val bumperFactory = DI.bumpersModule()!!.bumperFactory().map { WeakReference(it) } val bumperWeak = DI.bumpersModule()!!.bumperWeak().map { WeakReference(it) } val bumperSoft = DI.bumpersModule()!!.bumperSoft().map { WeakReference(it) } @@ -150,7 +150,7 @@ class BumperGcTests { @Test fun gcRedBumpers2() { // Given - val DI = Stone.createComponent(CarGcComponent::class.java) + val DI = CarGcComponentStoneComponent() val bumperFactory = DI.bumpersModule()!!.bumperFactory().map { WeakReference(it) } val bumperWeak = DI.bumpersModule()!!.bumperWeak().map { WeakReference(it) } val bumperSoft = DI.bumpersModule()!!.bumperSoft().map { WeakReference(it) } @@ -170,7 +170,7 @@ class BumperGcTests { @Test fun gcWheelsTest() { // Given - val DI = Stone.createComponent(CarGcComponent::class.java) + val DI = CarGcComponentStoneComponent() val bumperFactory = DI.bumpersModule()!!.bumperFactory().map { WeakReference(it) } val bumperWeak = DI.bumpersModule()!!.bumperWeak().map { WeakReference(it) } val bumperSoft = DI.bumpersModule()!!.bumperSoft().map { WeakReference(it) } @@ -191,7 +191,7 @@ class BumperGcTests { @Test fun gcNothing() { // Given - val DI = Stone.createComponent(CarGcComponent::class.java) + val DI = CarGcComponentStoneComponent() val bumperFactory = DI.bumpersModule()!!.bumperFactory().map { WeakReference(it) } val bumperWeak = DI.bumpersModule()!!.bumperWeak().map { WeakReference(it) } val bumperSoft = DI.bumpersModule()!!.bumperSoft().map { WeakReference(it) } diff --git a/tests_wraps_kotlin/src/test/kotlin/com/github/klee0kai/stone/kotlin/test/car/cachecontrol/gc/WheelGcTests.kt b/tests_wraps_kotlin/src/test/kotlin/com/github/klee0kai/stone/kotlin/test/car/cachecontrol/gc/WheelGcTests.kt index 229d462c..0c2212a2 100644 --- a/tests_wraps_kotlin/src/test/kotlin/com/github/klee0kai/stone/kotlin/test/car/cachecontrol/gc/WheelGcTests.kt +++ b/tests_wraps_kotlin/src/test/kotlin/com/github/klee0kai/stone/kotlin/test/car/cachecontrol/gc/WheelGcTests.kt @@ -1,16 +1,17 @@ package com.github.klee0kai.stone.kotlin.test.car.cachecontrol.gc -import com.github.klee0kai.stone.Stone -import com.github.klee0kai.test.car.di.cachecontrol.gc.CarGcComponent +import com.github.klee0kai.test.car.di.cachecontrol.gc.CarGcComponentStoneComponent import org.junit.jupiter.api.Assertions.assertNotNull import org.junit.jupiter.api.Assertions.assertNull import org.junit.jupiter.api.Test class WheelGcTests { + + @Test fun createWorkCorrect() { // Given - val DI = Stone.createComponent(CarGcComponent::class.java) + val DI = CarGcComponentStoneComponent() //When val wheelFactory = DI.wheelsModule().wheelFactory() @@ -28,7 +29,7 @@ class WheelGcTests { @Test fun createAfterGcWorkCorrect() { // Given - val DI = Stone.createComponent(CarGcComponent::class.java) + val DI = CarGcComponentStoneComponent() DI.gcAll() //When @@ -47,7 +48,7 @@ class WheelGcTests { @Test fun gcAllTest() { // Given - val DI = Stone.createComponent(CarGcComponent::class.java) + val DI = CarGcComponentStoneComponent() val wheelFactory = DI.wheelsModule().wheelFactory() val wheelWeak = DI.wheelsModule().wheelWeak() val wheelSoft = DI.wheelsModule().wheelSoft() @@ -66,7 +67,7 @@ class WheelGcTests { @Test fun gcWeakTest() { // Given - val DI = Stone.createComponent(CarGcComponent::class.java) + val DI = CarGcComponentStoneComponent() val wheelFactory = DI.wheelsModule().wheelFactory() val wheelWeak = DI.wheelsModule().wheelWeak() val wheelSoft = DI.wheelsModule().wheelSoft() @@ -85,7 +86,7 @@ class WheelGcTests { @Test fun gcSoftTest() { // Given - val DI = Stone.createComponent(CarGcComponent::class.java) + val DI = CarGcComponentStoneComponent() val wheelFactory = DI.wheelsModule().wheelFactory() val wheelWeak = DI.wheelsModule().wheelWeak() val wheelSoft = DI.wheelsModule().wheelSoft() @@ -104,7 +105,7 @@ class WheelGcTests { @Test fun gcStrongTest() { // Given - val DI = Stone.createComponent(CarGcComponent::class.java) + val DI = CarGcComponentStoneComponent() val wheelFactory = DI.wheelsModule().wheelFactory() val wheelWeak = DI.wheelsModule().wheelWeak() val wheelSoft = DI.wheelsModule().wheelSoft() @@ -123,7 +124,7 @@ class WheelGcTests { @Test fun gcWheelsTest() { // Given - val DI = Stone.createComponent(CarGcComponent::class.java) + val DI = CarGcComponentStoneComponent() val wheelFactory = DI.wheelsModule().wheelFactory() val wheelWeak = DI.wheelsModule().wheelWeak() val wheelSoft = DI.wheelsModule().wheelSoft() @@ -142,7 +143,7 @@ class WheelGcTests { @Test fun gcNothing() { // Given - val DI = Stone.createComponent(CarGcComponent::class.java) + val DI = CarGcComponentStoneComponent() val wheelFactory = DI.wheelsModule().wheelFactory() val wheelWeak = DI.wheelsModule().wheelWeak() val wheelSoft = DI.wheelsModule().wheelSoft() @@ -161,7 +162,7 @@ class WheelGcTests { @Test fun gcWindows() { // Given - val DI = Stone.createComponent(CarGcComponent::class.java) + val DI = CarGcComponentStoneComponent() val wheelFactory = DI.wheelsModule().wheelFactory() val wheelWeak = DI.wheelsModule().wheelWeak() val wheelSoft = DI.wheelsModule().wheelSoft() @@ -180,7 +181,7 @@ class WheelGcTests { @Test fun gcWindowsAndWheels() { // Given - val DI = Stone.createComponent(CarGcComponent::class.java) + val DI = CarGcComponentStoneComponent() val wheelFactory = DI.wheelsModule().wheelFactory() val wheelWeak = DI.wheelsModule().wheelWeak() val wheelSoft = DI.wheelsModule().wheelSoft() @@ -195,4 +196,5 @@ class WheelGcTests { assertNull(wheelSoft!!.get()) assertNull(wheelStrong!!.get()) } + } diff --git a/tests_wraps_kotlin/src/test/kotlin/com/github/klee0kai/stone/kotlin/test/car/cachecontrol/gc/WheelMappedGcTests.kt b/tests_wraps_kotlin/src/test/kotlin/com/github/klee0kai/stone/kotlin/test/car/cachecontrol/gc/WheelMappedGcTests.kt index 8cd4be89..9618b931 100644 --- a/tests_wraps_kotlin/src/test/kotlin/com/github/klee0kai/stone/kotlin/test/car/cachecontrol/gc/WheelMappedGcTests.kt +++ b/tests_wraps_kotlin/src/test/kotlin/com/github/klee0kai/stone/kotlin/test/car/cachecontrol/gc/WheelMappedGcTests.kt @@ -1,16 +1,16 @@ package com.github.klee0kai.stone.kotlin.test.car.cachecontrol.gc -import com.github.klee0kai.stone.Stone -import com.github.klee0kai.test.car.di.cachecontrol.gc.CarGcComponent +import com.github.klee0kai.test.car.di.cachecontrol.gc.CarGcComponentStoneComponent import org.junit.jupiter.api.Assertions.assertNotNull import org.junit.jupiter.api.Assertions.assertNull import org.junit.jupiter.api.Test class WheelMappedGcTests { + @Test fun createWorkCorrect() { // Given - val DI = Stone.createComponent(CarGcComponent::class.java) + val DI = CarGcComponentStoneComponent() //When val wheelFactory = DI.wheelMappedModule()!!.wheelFactory("1") @@ -28,7 +28,7 @@ class WheelMappedGcTests { @Test fun createAfterGcWorkCorrect() { // Given - val DI = Stone.createComponent(CarGcComponent::class.java) + val DI = CarGcComponentStoneComponent() DI.gcAll() //When @@ -47,7 +47,7 @@ class WheelMappedGcTests { @Test fun gcAllTest() { // Given - val DI = Stone.createComponent(CarGcComponent::class.java) + val DI = CarGcComponentStoneComponent() val wheelFactory = DI.wheelMappedModule()!!.wheelFactory("1") val wheelWeak = DI.wheelMappedModule()!!.wheelWeak("1") val wheelSoft = DI.wheelMappedModule()!!.wheelSoft("1") @@ -66,7 +66,7 @@ class WheelMappedGcTests { @Test fun gcWeakTest() { // Given - val DI = Stone.createComponent(CarGcComponent::class.java) + val DI = CarGcComponentStoneComponent() val wheelFactory = DI.wheelMappedModule()!!.wheelFactory("1") val wheelWeak = DI.wheelMappedModule()!!.wheelWeak("1") val wheelSoft = DI.wheelMappedModule()!!.wheelSoft("1") @@ -85,7 +85,7 @@ class WheelMappedGcTests { @Test fun gcSoftTest() { // Given - val DI = Stone.createComponent(CarGcComponent::class.java) + val DI = CarGcComponentStoneComponent() val wheelFactory = DI.wheelMappedModule()!!.wheelFactory("1") val wheelWeak = DI.wheelMappedModule()!!.wheelWeak("1") val wheelSoft = DI.wheelMappedModule()!!.wheelSoft("1") @@ -104,7 +104,7 @@ class WheelMappedGcTests { @Test fun gcStrongTest() { // Given - val DI = Stone.createComponent(CarGcComponent::class.java) + val DI = CarGcComponentStoneComponent() val wheelFactory = DI.wheelMappedModule()!!.wheelFactory("1") val wheelWeak = DI.wheelMappedModule()!!.wheelWeak("1") val wheelSoft = DI.wheelMappedModule()!!.wheelSoft("1") @@ -123,7 +123,7 @@ class WheelMappedGcTests { @Test fun gcWheelsTest() { // Given - val DI = Stone.createComponent(CarGcComponent::class.java) + val DI = CarGcComponentStoneComponent() val wheelFactory = DI.wheelMappedModule()!!.wheelFactory("1") val wheelWeak = DI.wheelMappedModule()!!.wheelWeak("1") val wheelSoft = DI.wheelMappedModule()!!.wheelSoft("1") @@ -142,7 +142,7 @@ class WheelMappedGcTests { @Test fun gcNothing() { // Given - val DI = Stone.createComponent(CarGcComponent::class.java) + val DI = CarGcComponentStoneComponent() val wheelFactory = DI.wheelMappedModule()!!.wheelFactory("1") val wheelWeak = DI.wheelMappedModule()!!.wheelWeak("1") val wheelSoft = DI.wheelMappedModule()!!.wheelSoft("1") @@ -161,7 +161,7 @@ class WheelMappedGcTests { @Test fun gcWindows() { // Given - val DI = Stone.createComponent(CarGcComponent::class.java) + val DI = CarGcComponentStoneComponent() val wheelFactory = DI.wheelMappedModule()!!.wheelFactory("1") val wheelWeak = DI.wheelMappedModule()!!.wheelWeak("1") val wheelSoft = DI.wheelMappedModule()!!.wheelSoft("1") @@ -180,7 +180,7 @@ class WheelMappedGcTests { @Test fun gcWindowsAndWheels() { // Given - val DI = Stone.createComponent(CarGcComponent::class.java) + val DI = CarGcComponentStoneComponent() val wheelFactory = DI.wheelMappedModule()!!.wheelFactory("1") val wheelWeak = DI.wheelMappedModule()!!.wheelWeak("1") val wheelSoft = DI.wheelMappedModule()!!.wheelSoft("1") diff --git a/tests_wraps_kotlin/src/test/kotlin/com/github/klee0kai/stone/kotlin/test/car/cachecontrol/gc/WheelMultiMappedGcTests.kt b/tests_wraps_kotlin/src/test/kotlin/com/github/klee0kai/stone/kotlin/test/car/cachecontrol/gc/WheelMultiMappedGcTests.kt index 70fcd344..7cc98ebb 100644 --- a/tests_wraps_kotlin/src/test/kotlin/com/github/klee0kai/stone/kotlin/test/car/cachecontrol/gc/WheelMultiMappedGcTests.kt +++ b/tests_wraps_kotlin/src/test/kotlin/com/github/klee0kai/stone/kotlin/test/car/cachecontrol/gc/WheelMultiMappedGcTests.kt @@ -1,16 +1,16 @@ package com.github.klee0kai.stone.kotlin.test.car.cachecontrol.gc -import com.github.klee0kai.stone.Stone -import com.github.klee0kai.test.car.di.cachecontrol.gc.CarGcComponent +import com.github.klee0kai.test.car.di.cachecontrol.gc.CarGcComponentStoneComponent import org.junit.jupiter.api.Assertions.assertNotNull import org.junit.jupiter.api.Assertions.assertNull import org.junit.jupiter.api.Test class WheelMultiMappedGcTests { + @Test fun createWorkCorrect() { // Given - val DI = Stone.createComponent(CarGcComponent::class.java) + val DI = CarGcComponentStoneComponent() //When val wheelFactory = DI.wheelMultiMappedModule().wheelFactory("1", Integer(1)) @@ -28,7 +28,7 @@ class WheelMultiMappedGcTests { @Test fun createAfterGcWorkCorrect() { // Given - val DI = Stone.createComponent(CarGcComponent::class.java) + val DI = CarGcComponentStoneComponent() DI.gcAll() //When @@ -47,7 +47,7 @@ class WheelMultiMappedGcTests { @Test fun gcAllTest() { // Given - val DI = Stone.createComponent(CarGcComponent::class.java) + val DI = CarGcComponentStoneComponent() val wheelFactory = DI.wheelMultiMappedModule().wheelFactory("1", Integer(1)) val wheelWeak = DI.wheelMultiMappedModule().wheelWeak("1", Integer(1)) val wheelSoft = DI.wheelMultiMappedModule().wheelSoft("1", Integer(1)) @@ -66,7 +66,7 @@ class WheelMultiMappedGcTests { @Test fun gcWeakTest() { // Given - val DI = Stone.createComponent(CarGcComponent::class.java) + val DI = CarGcComponentStoneComponent() val wheelFactory = DI.wheelMultiMappedModule().wheelFactory("1", Integer(1)) val wheelWeak = DI.wheelMultiMappedModule().wheelWeak("1", Integer(1)) val wheelSoft = DI.wheelMultiMappedModule().wheelSoft("1", Integer(1)) @@ -85,7 +85,7 @@ class WheelMultiMappedGcTests { @Test fun gcSoftTest() { // Given - val DI = Stone.createComponent(CarGcComponent::class.java) + val DI = CarGcComponentStoneComponent() val wheelFactory = DI.wheelMultiMappedModule().wheelFactory("1", Integer(1)) val wheelWeak = DI.wheelMultiMappedModule().wheelWeak("1", Integer(1)) val wheelSoft = DI.wheelMultiMappedModule().wheelSoft("1", Integer(1)) @@ -104,7 +104,7 @@ class WheelMultiMappedGcTests { @Test fun gcStrongTest() { // Given - val DI = Stone.createComponent(CarGcComponent::class.java) + val DI = CarGcComponentStoneComponent() val wheelFactory = DI.wheelMultiMappedModule().wheelFactory("1", Integer(1)) val wheelWeak = DI.wheelMultiMappedModule().wheelWeak("1", Integer(1)) val wheelSoft = DI.wheelMultiMappedModule().wheelSoft("1", Integer(1)) @@ -123,7 +123,7 @@ class WheelMultiMappedGcTests { @Test fun gcWheelsTest() { // Given - val DI = Stone.createComponent(CarGcComponent::class.java) + val DI = CarGcComponentStoneComponent() val wheelFactory = DI.wheelMultiMappedModule().wheelFactory("1", Integer(1)) val wheelWeak = DI.wheelMultiMappedModule().wheelWeak("1", Integer(1)) val wheelSoft = DI.wheelMultiMappedModule().wheelSoft("1", Integer(1)) @@ -142,7 +142,7 @@ class WheelMultiMappedGcTests { @Test fun gcNothing() { // Given - val DI = Stone.createComponent(CarGcComponent::class.java) + val DI = CarGcComponentStoneComponent() val wheelFactory = DI.wheelMultiMappedModule().wheelFactory("1", Integer(1)) val wheelWeak = DI.wheelMultiMappedModule().wheelWeak("1", Integer(1)) val wheelSoft = DI.wheelMultiMappedModule().wheelSoft("1", Integer(1)) @@ -161,7 +161,7 @@ class WheelMultiMappedGcTests { @Test fun gcWindows() { // Given - val DI = Stone.createComponent(CarGcComponent::class.java) + val DI = CarGcComponentStoneComponent() val wheelFactory = DI.wheelMultiMappedModule().wheelFactory("1", Integer(1)) val wheelWeak = DI.wheelMultiMappedModule().wheelWeak("1", Integer(1)) val wheelSoft = DI.wheelMultiMappedModule().wheelSoft("1", Integer(1)) @@ -180,7 +180,7 @@ class WheelMultiMappedGcTests { @Test fun gcWindowsAndWheels() { // Given - val DI = Stone.createComponent(CarGcComponent::class.java) + val DI = CarGcComponentStoneComponent() val wheelFactory = DI.wheelMultiMappedModule().wheelFactory("1", Integer(1)) val wheelWeak = DI.wheelMultiMappedModule().wheelWeak("1", Integer(1)) val wheelSoft = DI.wheelMultiMappedModule().wheelSoft("1", Integer(1)) diff --git a/tests_wraps_kotlin/src/test/kotlin/com/github/klee0kai/stone/kotlin/test/car/cachecontrol/gc/WheelReusableGcTests.kt b/tests_wraps_kotlin/src/test/kotlin/com/github/klee0kai/stone/kotlin/test/car/cachecontrol/gc/WheelReusableGcTests.kt index 25e87fda..929e0e6e 100644 --- a/tests_wraps_kotlin/src/test/kotlin/com/github/klee0kai/stone/kotlin/test/car/cachecontrol/gc/WheelReusableGcTests.kt +++ b/tests_wraps_kotlin/src/test/kotlin/com/github/klee0kai/stone/kotlin/test/car/cachecontrol/gc/WheelReusableGcTests.kt @@ -1,16 +1,16 @@ package com.github.klee0kai.stone.kotlin.test.car.cachecontrol.gc -import com.github.klee0kai.stone.Stone -import com.github.klee0kai.test.car.di.cachecontrol.gc.CarGcComponent +import com.github.klee0kai.test.car.di.cachecontrol.gc.CarGcComponentStoneComponent import org.junit.jupiter.api.Assertions.assertEquals import org.junit.jupiter.api.Assertions.assertNotEquals import org.junit.jupiter.api.Test class WheelReusableGcTests { + @Test fun gcAllTest() { // Given - val DI = Stone.createComponent(CarGcComponent::class.java) + val DI = CarGcComponentStoneComponent() val wheelFactory1 = DI.wheelsModule().wheelFactory()!!.get()!!.uuid val wheelWeak1 = DI.wheelsModule().wheelWeak()!!.get()!!.uuid val wheelSoft1 = DI.wheelsModule().wheelSoft()!!.get()!!.uuid @@ -33,7 +33,7 @@ class WheelReusableGcTests { @Test fun gcWeakTest() { // Given - val DI = Stone.createComponent(CarGcComponent::class.java) + val DI = CarGcComponentStoneComponent() val wheelFactory1 = DI.wheelsModule()!!.wheelFactory()!!.get()!!.uuid val wheelWeak1 = DI.wheelsModule()!!.wheelWeak()!!.get()!!.uuid val wheelSoft1 = DI.wheelsModule()!!.wheelSoft()!!.get()!!.uuid @@ -56,7 +56,7 @@ class WheelReusableGcTests { @Test fun gcSoftTest() { // Given - val DI = Stone.createComponent(CarGcComponent::class.java) + val DI = CarGcComponentStoneComponent() val wheelFactory1 = DI.wheelsModule()!!.wheelFactory()!!.get()!!.uuid val wheelWeak1 = DI.wheelsModule()!!.wheelWeak()!!.get()!!.uuid val wheelSoft1 = DI.wheelsModule()!!.wheelSoft()!!.get()!!.uuid @@ -79,7 +79,7 @@ class WheelReusableGcTests { @Test fun gcStrongTest() { // Given - val DI = Stone.createComponent(CarGcComponent::class.java) + val DI = CarGcComponentStoneComponent() val wheelFactory1 = DI.wheelsModule()!!.wheelFactory()!!.get()!!.uuid val wheelWeak1 = DI.wheelsModule()!!.wheelWeak()!!.get()!!.uuid val wheelSoft1 = DI.wheelsModule()!!.wheelSoft()!!.get()!!.uuid @@ -102,7 +102,7 @@ class WheelReusableGcTests { @Test fun gcWheelsTest() { // Given - val DI = Stone.createComponent(CarGcComponent::class.java) + val DI = CarGcComponentStoneComponent() val wheelFactory1 = DI.wheelsModule()!!.wheelFactory()!!.get()!!.uuid val wheelWeak1 = DI.wheelsModule()!!.wheelWeak()!!.get()!!.uuid val wheelSoft1 = DI.wheelsModule()!!.wheelSoft()!!.get()!!.uuid @@ -125,7 +125,7 @@ class WheelReusableGcTests { @Test fun gcNothing() { // Given - val DI = Stone.createComponent(CarGcComponent::class.java) + val DI = CarGcComponentStoneComponent() val wheelFactory1 = DI.wheelsModule()!!.wheelFactory()!!.get()!!.uuid val wheelWeak1 = DI.wheelsModule()!!.wheelWeak()!!.get()!!.uuid val wheelSoft1 = DI.wheelsModule()!!.wheelSoft()!!.get()!!.uuid @@ -148,7 +148,7 @@ class WheelReusableGcTests { @Test fun gcWindows() { // Given - val DI = Stone.createComponent(CarGcComponent::class.java) + val DI = CarGcComponentStoneComponent() val wheelFactory1 = DI.wheelsModule()!!.wheelFactory()!!.get()!!.uuid val wheelWeak1 = DI.wheelsModule()!!.wheelWeak()!!.get()!!.uuid val wheelSoft1 = DI.wheelsModule()!!.wheelSoft()!!.get()!!.uuid @@ -171,7 +171,7 @@ class WheelReusableGcTests { @Test fun gcWindowsAndWheels() { // Given - val DI = Stone.createComponent(CarGcComponent::class.java) + val DI = CarGcComponentStoneComponent() val wheelFactory1 = DI.wheelsModule()!!.wheelFactory()!!.get()!!.uuid val wheelWeak1 = DI.wheelsModule()!!.wheelWeak()!!.get()!!.uuid val wheelSoft1 = DI.wheelsModule()!!.wheelSoft()!!.get()!!.uuid diff --git a/tests_wraps_kotlin/src/test/kotlin/com/github/klee0kai/stone/kotlin/test/car/cachecontrol/gc/WindowGcTests.kt b/tests_wraps_kotlin/src/test/kotlin/com/github/klee0kai/stone/kotlin/test/car/cachecontrol/gc/WindowGcTests.kt index 1e636e5f..94c5972a 100644 --- a/tests_wraps_kotlin/src/test/kotlin/com/github/klee0kai/stone/kotlin/test/car/cachecontrol/gc/WindowGcTests.kt +++ b/tests_wraps_kotlin/src/test/kotlin/com/github/klee0kai/stone/kotlin/test/car/cachecontrol/gc/WindowGcTests.kt @@ -1,18 +1,18 @@ package com.github.klee0kai.stone.kotlin.test.car.cachecontrol.gc -import com.github.klee0kai.stone.Stone import com.github.klee0kai.stone.kotlin.test.utils.KotlinUtils.resetKotlinRegisters -import com.github.klee0kai.test.car.di.cachecontrol.gc.CarGcComponent +import com.github.klee0kai.test.car.di.cachecontrol.gc.CarGcComponentStoneComponent import com.github.klee0kai.test.car.model.Window import org.junit.jupiter.api.Assertions.assertEquals import org.junit.jupiter.api.Test import java.lang.ref.WeakReference class WindowGcTests { + @Test fun createWorkCorrect() { // Given - val DI = Stone.createComponent(CarGcComponent::class.java) + val DI = CarGcComponentStoneComponent() //When val windowsFactory = DI.windowsModule()!!.windowFactory().get()!!.map { WeakReference(it) } @@ -30,7 +30,7 @@ class WindowGcTests { @Test fun createAfterGcWorkCorrect() { // Given - val DI = Stone.createComponent(CarGcComponent::class.java) + val DI = CarGcComponentStoneComponent() DI.gcAll() //When @@ -49,7 +49,7 @@ class WindowGcTests { @Test fun gcAllTest() { // Given - val DI = Stone.createComponent(CarGcComponent::class.java) + val DI = CarGcComponentStoneComponent() val windowsFactory = DI.windowsModule()!!.windowFactory().get()!!.map { WeakReference(it) } val windowWeak = DI.windowsModule()!!.windowWeak().get()!!.map { WeakReference(it) } val windowSoft = DI.windowsModule()!!.windowSoft().get()!!.map { WeakReference(it) } @@ -70,7 +70,7 @@ class WindowGcTests { @Test fun gcWeakTest() { // Given - val DI = Stone.createComponent(CarGcComponent::class.java) + val DI = CarGcComponentStoneComponent() val windowsFactory = DI.windowsModule()!!.windowFactory().get()!!.map { WeakReference(it) } val windowWeak = DI.windowsModule()!!.windowWeak().get()!!.map { WeakReference(it) } val windowSoft = DI.windowsModule()!!.windowSoft().get()!!.map { WeakReference(it) } @@ -90,7 +90,7 @@ class WindowGcTests { @Test fun gcSoftTest() { // Given - val DI = Stone.createComponent(CarGcComponent::class.java) + val DI = CarGcComponentStoneComponent() val windowsFactory = DI.windowsModule()!!.windowFactory().get()!!.map { WeakReference(it) } val windowWeak = DI.windowsModule()!!.windowWeak().get()!!.map { WeakReference(it) } val windowSoft = DI.windowsModule()!!.windowSoft().get()!!.map { WeakReference(it) } @@ -110,7 +110,7 @@ class WindowGcTests { @Test fun gcStrongTest() { // Given - val DI = Stone.createComponent(CarGcComponent::class.java) + val DI = CarGcComponentStoneComponent() val windowsFactory = DI.windowsModule()!!.windowFactory().get()!!.map { WeakReference(it) } val windowWeak = DI.windowsModule()!!.windowWeak().get()!!.map { WeakReference(it) } val windowSoft = DI.windowsModule()!!.windowSoft().get()!!.map { WeakReference(it) } @@ -130,7 +130,7 @@ class WindowGcTests { @Test fun gcWindows() { // Given - val DI = Stone.createComponent(CarGcComponent::class.java) + val DI = CarGcComponentStoneComponent() val windowsFactory = DI.windowsModule()!!.windowFactory().get()!!.map { WeakReference(it) } val windowWeak = DI.windowsModule()!!.windowWeak().get()!!.map { WeakReference(it) } val windowSoft = DI.windowsModule()!!.windowSoft().get()!!.map { WeakReference(it) } @@ -150,7 +150,7 @@ class WindowGcTests { @Test fun gcWindowsAndWheels() { // Given - val DI = Stone.createComponent(CarGcComponent::class.java) + val DI = CarGcComponentStoneComponent() val windowsFactory = DI.windowsModule()!!.windowFactory().get()!!.map { WeakReference(it) } val windowWeak = DI.windowsModule()!!.windowWeak().get()!!.map { WeakReference(it) } val windowSoft = DI.windowsModule()!!.windowSoft().get()!!.map { WeakReference(it) } @@ -170,7 +170,7 @@ class WindowGcTests { @Test fun gcWheelsTest() { // Given - val DI = Stone.createComponent(CarGcComponent::class.java) + val DI = CarGcComponentStoneComponent() val windowsFactory = DI.windowsModule()!!.windowFactory().get()!!.map { WeakReference(it) } val windowWeak = DI.windowsModule()!!.windowWeak().get()!!.map { WeakReference(it) } val windowSoft = DI.windowsModule()!!.windowSoft().get()!!.map { WeakReference(it) } @@ -191,7 +191,7 @@ class WindowGcTests { @Test fun gcNothing() { // Given - val DI = Stone.createComponent(CarGcComponent::class.java) + val DI = CarGcComponentStoneComponent() val windowsFactory = DI.windowsModule()!!.windowFactory().get()!!.map { WeakReference(it) } val windowWeak = DI.windowsModule()!!.windowWeak().get()!!.map { WeakReference(it) } val windowSoft = DI.windowsModule()!!.windowSoft().get()!!.map { WeakReference(it) } diff --git a/tests_wraps_kotlin/src/test/kotlin/com/github/klee0kai/stone/kotlin/test/car/cachecontrol/gc/WindowMappedGcTests.kt b/tests_wraps_kotlin/src/test/kotlin/com/github/klee0kai/stone/kotlin/test/car/cachecontrol/gc/WindowMappedGcTests.kt index ea379d09..bbcc2b09 100644 --- a/tests_wraps_kotlin/src/test/kotlin/com/github/klee0kai/stone/kotlin/test/car/cachecontrol/gc/WindowMappedGcTests.kt +++ b/tests_wraps_kotlin/src/test/kotlin/com/github/klee0kai/stone/kotlin/test/car/cachecontrol/gc/WindowMappedGcTests.kt @@ -1,18 +1,18 @@ package com.github.klee0kai.stone.kotlin.test.car.cachecontrol.gc -import com.github.klee0kai.stone.Stone import com.github.klee0kai.stone.kotlin.test.utils.KotlinUtils.resetKotlinRegisters -import com.github.klee0kai.test.car.di.cachecontrol.gc.CarGcComponent +import com.github.klee0kai.test.car.di.cachecontrol.gc.CarGcComponentStoneComponent import com.github.klee0kai.test.car.model.Window import org.junit.jupiter.api.Assertions.assertEquals import org.junit.jupiter.api.Test import java.lang.ref.WeakReference class WindowMappedGcTests { + @Test fun createWorkCorrect() { // Given - val DI = Stone.createComponent(CarGcComponent::class.java) + val DI = CarGcComponentStoneComponent() //When val windowsFactory = DI.windowsMappedModule()!!.windowFactory("1").get()!!.map { WeakReference(it) } @@ -30,7 +30,7 @@ class WindowMappedGcTests { @Test fun createAfterGcWorkCorrect() { // Given - val DI = Stone.createComponent(CarGcComponent::class.java) + val DI = CarGcComponentStoneComponent() DI.gcAll() //When @@ -49,7 +49,7 @@ class WindowMappedGcTests { @Test fun gcAllTest() { // Given - val DI = Stone.createComponent(CarGcComponent::class.java) + val DI = CarGcComponentStoneComponent() val windowsFactory = DI.windowsMappedModule()!!.windowFactory("1").get()!!.map { WeakReference(it) } val windowWeak = DI.windowsMappedModule()!!.windowWeak("1").get()!!.map { WeakReference(it) } val windowSoft = DI.windowsMappedModule()!!.windowSoft("1").get()!!.map { WeakReference(it) } @@ -70,7 +70,7 @@ class WindowMappedGcTests { @Test fun gcWeakTest() { // Given - val DI = Stone.createComponent(CarGcComponent::class.java) + val DI = CarGcComponentStoneComponent() val windowsFactory = DI.windowsMappedModule()!!.windowFactory("1").get()!!.map { WeakReference(it) } val windowWeak = DI.windowsMappedModule()!!.windowWeak("1").get()!!.map { WeakReference(it) } val windowSoft = DI.windowsMappedModule()!!.windowSoft("1").get()!!.map { WeakReference(it) } @@ -90,7 +90,7 @@ class WindowMappedGcTests { @Test fun gcSoftTest() { // Given - val DI = Stone.createComponent(CarGcComponent::class.java) + val DI = CarGcComponentStoneComponent() val windowsFactory = DI.windowsMappedModule()!!.windowFactory("1").get()!!.map { WeakReference(it) } val windowWeak = DI.windowsMappedModule()!!.windowWeak("1").get()!!.map { WeakReference(it) } val windowSoft = DI.windowsMappedModule()!!.windowSoft("1").get()!!.map { WeakReference(it) } @@ -110,7 +110,7 @@ class WindowMappedGcTests { @Test fun gcStrongTest() { // Given - val DI = Stone.createComponent(CarGcComponent::class.java) + val DI = CarGcComponentStoneComponent() val windowsFactory = DI.windowsMappedModule()!!.windowFactory("1").get()!!.map { WeakReference(it) } val windowWeak = DI.windowsMappedModule()!!.windowWeak("1").get()!!.map { WeakReference(it) } val windowSoft = DI.windowsMappedModule()!!.windowSoft("1").get()!!.map { WeakReference(it) } @@ -130,7 +130,7 @@ class WindowMappedGcTests { @Test fun gcWindows() { // Given - val DI = Stone.createComponent(CarGcComponent::class.java) + val DI = CarGcComponentStoneComponent() val windowsFactory = DI.windowsMappedModule()!!.windowFactory("1").get()!!.map { WeakReference(it) } val windowWeak = DI.windowsMappedModule()!!.windowWeak("1").get()!!.map { WeakReference(it) } val windowSoft = DI.windowsMappedModule()!!.windowSoft("1").get()!!.map { WeakReference(it) } @@ -150,7 +150,7 @@ class WindowMappedGcTests { @Test fun gcWindowsAndWheels() { // Given - val DI = Stone.createComponent(CarGcComponent::class.java) + val DI = CarGcComponentStoneComponent() val windowsFactory = DI.windowsMappedModule()!!.windowFactory("1").get()!!.map { WeakReference(it) } val windowWeak = DI.windowsMappedModule()!!.windowWeak("1").get()!!.map { WeakReference(it) } val windowSoft = DI.windowsMappedModule()!!.windowSoft("1").get()!!.map { WeakReference(it) } @@ -170,7 +170,7 @@ class WindowMappedGcTests { @Test fun gcWheelsTest() { // Given - val DI = Stone.createComponent(CarGcComponent::class.java) + val DI = CarGcComponentStoneComponent() val windowsFactory = DI.windowsMappedModule()!!.windowFactory("1").get()!!.map { WeakReference(it) } val windowWeak = DI.windowsMappedModule()!!.windowWeak("1").get()!!.map { WeakReference(it) } val windowSoft = DI.windowsMappedModule()!!.windowSoft("1").get()!!.map { WeakReference(it) } @@ -191,7 +191,7 @@ class WindowMappedGcTests { @Test fun gcNothing() { // Given - val DI = Stone.createComponent(CarGcComponent::class.java) + val DI = CarGcComponentStoneComponent() val windowsFactory = DI.windowsMappedModule()!!.windowFactory("1").get()!!.map { WeakReference(it) } val windowWeak = DI.windowsMappedModule()!!.windowWeak("1").get()!!.map { WeakReference(it) } val windowSoft = DI.windowsMappedModule()!!.windowSoft("1").get()!!.map { WeakReference(it) } diff --git a/tests_wraps_kotlin/src/test/kotlin/com/github/klee0kai/stone/kotlin/test/car/cachecontrol/gc/WindowMappedPartialGcTests.kt b/tests_wraps_kotlin/src/test/kotlin/com/github/klee0kai/stone/kotlin/test/car/cachecontrol/gc/WindowMappedPartialGcTests.kt index a9b73c21..4c7b2416 100644 --- a/tests_wraps_kotlin/src/test/kotlin/com/github/klee0kai/stone/kotlin/test/car/cachecontrol/gc/WindowMappedPartialGcTests.kt +++ b/tests_wraps_kotlin/src/test/kotlin/com/github/klee0kai/stone/kotlin/test/car/cachecontrol/gc/WindowMappedPartialGcTests.kt @@ -1,18 +1,18 @@ package com.github.klee0kai.stone.kotlin.test.car.cachecontrol.gc -import com.github.klee0kai.stone.Stone import com.github.klee0kai.stone.kotlin.test.utils.KotlinUtils.resetKotlinRegisters -import com.github.klee0kai.test.car.di.cachecontrol.gc.CarGcComponent +import com.github.klee0kai.test.car.di.cachecontrol.gc.CarGcComponentStoneComponent import com.github.klee0kai.test.car.model.Window import org.junit.jupiter.api.Assertions.* import org.junit.jupiter.api.Test import java.lang.ref.WeakReference class WindowMappedPartialGcTests { + @Test fun createWorkCorrect() { // Given - val DI = Stone.createComponent(CarGcComponent::class.java) + val DI = CarGcComponentStoneComponent() //When val windowStrong1 = DI.windowsMappedModule()!!.windowStrong("1").get()!!.map { WeakReference(it) } @@ -26,7 +26,7 @@ class WindowMappedPartialGcTests { @Test fun holdInListTest() { // Given - val DI = Stone.createComponent(CarGcComponent::class.java) + val DI = CarGcComponentStoneComponent() val windowStrong1 = DI.windowsMappedModule()!!.windowStrong("1").get()!!.map { WeakReference(it) } val windowStrong2 = DI.windowsMappedModule()!!.windowStrong("2").get()!!.map { WeakReference(it) } val holder1 = DI.windowsMappedModule()!!.windowStrong("1").get()!![1] @@ -49,7 +49,7 @@ class WindowMappedPartialGcTests { @Test fun partialRecreateList1Test() { // Given - val DI = Stone.createComponent(CarGcComponent::class.java) + val DI = CarGcComponentStoneComponent() val uids1 = DI.windowsMappedModule()!!.windowStrong("1").get()!!.map { it.uuid } val uids2 = DI.windowsMappedModule()!!.windowStrong("2").get()!!.map { it.uuid } val uids3 = DI.windowsMappedModule()!!.windowStrong("3").get()!!.map { it.uuid } diff --git a/tests_wraps_kotlin/src/test/kotlin/com/github/klee0kai/stone/kotlin/test/car/cachecontrol/gc/WindowMappedReusableGcTests.kt b/tests_wraps_kotlin/src/test/kotlin/com/github/klee0kai/stone/kotlin/test/car/cachecontrol/gc/WindowMappedReusableGcTests.kt index a1f1b70c..14f08792 100644 --- a/tests_wraps_kotlin/src/test/kotlin/com/github/klee0kai/stone/kotlin/test/car/cachecontrol/gc/WindowMappedReusableGcTests.kt +++ b/tests_wraps_kotlin/src/test/kotlin/com/github/klee0kai/stone/kotlin/test/car/cachecontrol/gc/WindowMappedReusableGcTests.kt @@ -1,17 +1,17 @@ package com.github.klee0kai.stone.kotlin.test.car.cachecontrol.gc -import com.github.klee0kai.stone.Stone import com.github.klee0kai.stone.kotlin.test.utils.KotlinUtils.resetKotlinRegisters -import com.github.klee0kai.test.car.di.cachecontrol.gc.CarGcComponent +import com.github.klee0kai.test.car.di.cachecontrol.gc.CarGcComponentStoneComponent import org.junit.jupiter.api.Assertions.assertEquals import org.junit.jupiter.api.Assertions.assertNotEquals import org.junit.jupiter.api.Test class WindowMappedReusableGcTests { + @Test fun createWorkCorrect() { // Given - val DI = Stone.createComponent(CarGcComponent::class.java) + val DI = CarGcComponentStoneComponent() //When val windowsFactory1 = DI.windowsMappedModule()!!.windowFactory("1").get()!!.map { it.uuid } @@ -33,7 +33,7 @@ class WindowMappedReusableGcTests { @Test fun gcAllTest() { // Given - val DI = Stone.createComponent(CarGcComponent::class.java) + val DI = CarGcComponentStoneComponent() val windowsFactory1 = DI.windowsMappedModule()!!.windowFactory("1").get()!!.map { it.uuid } val windowWeak1 = DI.windowsMappedModule()!!.windowWeak("1").get()!!.map { it.uuid } val windowSoft1 = DI.windowsMappedModule()!!.windowSoft("1").get()!!.map { it.uuid } @@ -71,7 +71,7 @@ class WindowMappedReusableGcTests { @Test fun gcWeakTest() { // Given - val DI = Stone.createComponent(CarGcComponent::class.java) + val DI = CarGcComponentStoneComponent() val windowsFactory1 = DI.windowsMappedModule()!!.windowFactory("1").get()!!.map { it.uuid } val windowWeak1 = DI.windowsMappedModule()!!.windowWeak("1").get()!!.map { it.uuid } val windowSoft1 = DI.windowsMappedModule()!!.windowSoft("1").get()!!.map { it.uuid } @@ -108,7 +108,7 @@ class WindowMappedReusableGcTests { @Test fun gcSoftTest() { // Given - val DI = Stone.createComponent(CarGcComponent::class.java) + val DI = CarGcComponentStoneComponent() val windowsFactory1 = DI.windowsMappedModule()!!.windowFactory("1").get()!!.map { it.uuid } val windowWeak1 = DI.windowsMappedModule()!!.windowWeak("1").get()!!.map { it.uuid } val windowSoft1 = DI.windowsMappedModule()!!.windowSoft("1").get()!!.map { it.uuid } @@ -145,7 +145,7 @@ class WindowMappedReusableGcTests { @Test fun gcStrongTest() { // Given - val DI = Stone.createComponent(CarGcComponent::class.java) + val DI = CarGcComponentStoneComponent() val windowsFactory1 = DI.windowsMappedModule()!!.windowFactory("1").get()!!.map { it.uuid } val windowWeak1 = DI.windowsMappedModule()!!.windowWeak("1").get()!!.map { it.uuid } val windowSoft1 = DI.windowsMappedModule()!!.windowSoft("1").get()!!.map { it.uuid } @@ -182,7 +182,7 @@ class WindowMappedReusableGcTests { @Test fun gcWindows() { // Given - val DI = Stone.createComponent(CarGcComponent::class.java) + val DI = CarGcComponentStoneComponent() val windowsFactory1 = DI.windowsMappedModule()!!.windowFactory("1").get()!!.map { it.uuid } val windowWeak1 = DI.windowsMappedModule()!!.windowWeak("1").get()!!.map { it.uuid } val windowSoft1 = DI.windowsMappedModule()!!.windowSoft("1").get()!!.map { it.uuid } @@ -219,7 +219,7 @@ class WindowMappedReusableGcTests { @Test fun gcWindowsAndWheels() { // Given - val DI = Stone.createComponent(CarGcComponent::class.java) + val DI = CarGcComponentStoneComponent() val windowsFactory1 = DI.windowsMappedModule()!!.windowFactory("1").get()!!.map { it.uuid } val windowWeak1 = DI.windowsMappedModule()!!.windowWeak("1").get()!!.map { it.uuid } val windowSoft1 = DI.windowsMappedModule()!!.windowSoft("1").get()!!.map { it.uuid } @@ -256,7 +256,7 @@ class WindowMappedReusableGcTests { @Test fun gcWheelsTest() { // Given - val DI = Stone.createComponent(CarGcComponent::class.java) + val DI = CarGcComponentStoneComponent() val windowsFactory1 = DI.windowsMappedModule()!!.windowFactory("1").get()!!.map { it.uuid } val windowWeak1 = DI.windowsMappedModule()!!.windowWeak("1").get()!!.map { it.uuid } val windowSoft1 = DI.windowsMappedModule()!!.windowSoft("1").get()!!.map { it.uuid } @@ -293,7 +293,7 @@ class WindowMappedReusableGcTests { @Test fun gcNothing() { // Given - val DI = Stone.createComponent(CarGcComponent::class.java) + val DI = CarGcComponentStoneComponent() val windowsFactory1 = DI.windowsMappedModule()!!.windowFactory("1").get()!!.map { it.uuid } val windowWeak1 = DI.windowsMappedModule()!!.windowWeak("1").get()!!.map { it.uuid } val windowSoft1 = DI.windowsMappedModule()!!.windowSoft("1").get()!!.map { it.uuid } diff --git a/tests_wraps_kotlin/src/test/kotlin/com/github/klee0kai/stone/kotlin/test/car/cachecontrol/gc/WindowMultiMappedGcTests.kt b/tests_wraps_kotlin/src/test/kotlin/com/github/klee0kai/stone/kotlin/test/car/cachecontrol/gc/WindowMultiMappedGcTests.kt index 5fad1bab..e341b0fb 100644 --- a/tests_wraps_kotlin/src/test/kotlin/com/github/klee0kai/stone/kotlin/test/car/cachecontrol/gc/WindowMultiMappedGcTests.kt +++ b/tests_wraps_kotlin/src/test/kotlin/com/github/klee0kai/stone/kotlin/test/car/cachecontrol/gc/WindowMultiMappedGcTests.kt @@ -1,18 +1,18 @@ package com.github.klee0kai.stone.kotlin.test.car.cachecontrol.gc -import com.github.klee0kai.stone.Stone import com.github.klee0kai.stone.kotlin.test.utils.KotlinUtils.resetKotlinRegisters -import com.github.klee0kai.test.car.di.cachecontrol.gc.CarGcComponent +import com.github.klee0kai.test.car.di.cachecontrol.gc.CarGcComponentStoneComponent import com.github.klee0kai.test.car.model.Window import org.junit.jupiter.api.Assertions.assertEquals import org.junit.jupiter.api.Test import java.lang.ref.WeakReference class WindowMultiMappedGcTests { + @Test fun createWorkCorrect() { // Given - val DI = Stone.createComponent(CarGcComponent::class.java) + val DI = CarGcComponentStoneComponent() //When val windowsFactory = DI.windowsMultiMappedModule()!!.windowFactory(1, "1").get()!!.map { WeakReference(it) } @@ -30,7 +30,7 @@ class WindowMultiMappedGcTests { @Test fun createAfterGcWorkCorrect() { // Given - val DI = Stone.createComponent(CarGcComponent::class.java) + val DI = CarGcComponentStoneComponent() DI.gcAll() //When @@ -49,7 +49,7 @@ class WindowMultiMappedGcTests { @Test fun gcAllTest() { // Given - val DI = Stone.createComponent(CarGcComponent::class.java) + val DI = CarGcComponentStoneComponent() val windowsFactory = DI.windowsMultiMappedModule()!!.windowFactory(1, "1").get()!!.map { WeakReference(it) } val windowWeak = DI.windowsMultiMappedModule()!!.windowWeak(1, "1").get()!!.map { WeakReference(it) } val windowSoft = DI.windowsMultiMappedModule()!!.windowSoft(1, "1").get()!!.map { WeakReference(it) } @@ -70,7 +70,7 @@ class WindowMultiMappedGcTests { @Test fun gcWeakTest() { // Given - val DI = Stone.createComponent(CarGcComponent::class.java) + val DI = CarGcComponentStoneComponent() val windowsFactory = DI.windowsMultiMappedModule()!!.windowFactory(1, "1").get()!!.map { WeakReference(it) } val windowWeak = DI.windowsMultiMappedModule()!!.windowWeak(1, "1").get()!!.map { WeakReference(it) } val windowSoft = DI.windowsMultiMappedModule()!!.windowSoft(1, "1").get()!!.map { WeakReference(it) } @@ -90,7 +90,7 @@ class WindowMultiMappedGcTests { @Test fun gcSoftTest() { // Given - val DI = Stone.createComponent(CarGcComponent::class.java) + val DI = CarGcComponentStoneComponent() val windowsFactory = DI.windowsMultiMappedModule()!!.windowFactory(1, "1").get()!!.map { WeakReference(it) } val windowWeak = DI.windowsMultiMappedModule()!!.windowWeak(1, "1").get()!!.map { WeakReference(it) } val windowSoft = DI.windowsMultiMappedModule()!!.windowSoft(1, "1").get()!!.map { WeakReference(it) } @@ -110,7 +110,7 @@ class WindowMultiMappedGcTests { @Test fun gcStrongTest() { // Given - val DI = Stone.createComponent(CarGcComponent::class.java) + val DI = CarGcComponentStoneComponent() val windowsFactory = DI.windowsMultiMappedModule()!!.windowFactory(1, "1").get()!!.map { WeakReference(it) } val windowWeak = DI.windowsMultiMappedModule()!!.windowWeak(1, "1").get()!!.map { WeakReference(it) } val windowSoft = DI.windowsMultiMappedModule()!!.windowSoft(1, "1").get()!!.map { WeakReference(it) } @@ -130,7 +130,7 @@ class WindowMultiMappedGcTests { @Test fun gcWindows() { // Given - val DI = Stone.createComponent(CarGcComponent::class.java) + val DI = CarGcComponentStoneComponent() val windowsFactory = DI.windowsMultiMappedModule()!!.windowFactory(1, "1").get()!!.map { WeakReference(it) } val windowWeak = DI.windowsMultiMappedModule()!!.windowWeak(1, "1").get()!!.map { WeakReference(it) } val windowSoft = DI.windowsMultiMappedModule()!!.windowSoft(1, "1").get()!!.map { WeakReference(it) } @@ -150,7 +150,7 @@ class WindowMultiMappedGcTests { @Test fun gcWindowsAndWheels() { // Given - val DI = Stone.createComponent(CarGcComponent::class.java) + val DI = CarGcComponentStoneComponent() val windowsFactory = DI.windowsMultiMappedModule()!!.windowFactory(1, "1").get()!!.map { WeakReference(it) } val windowWeak = DI.windowsMultiMappedModule()!!.windowWeak(1, "1").get()!!.map { WeakReference(it) } val windowSoft = DI.windowsMultiMappedModule()!!.windowSoft(1, "1").get()!!.map { WeakReference(it) } @@ -170,7 +170,7 @@ class WindowMultiMappedGcTests { @Test fun gcWheelsTest() { // Given - val DI = Stone.createComponent(CarGcComponent::class.java) + val DI = CarGcComponentStoneComponent() val windowsFactory = DI.windowsMultiMappedModule()!!.windowFactory(1, "1").get()!!.map { WeakReference(it) } val windowWeak = DI.windowsMultiMappedModule()!!.windowWeak(1, "1").get()!!.map { WeakReference(it) } val windowSoft = DI.windowsMultiMappedModule()!!.windowSoft(1, "1").get()!!.map { WeakReference(it) } @@ -191,7 +191,7 @@ class WindowMultiMappedGcTests { @Test fun gcNothing() { // Given - val DI = Stone.createComponent(CarGcComponent::class.java) + val DI = CarGcComponentStoneComponent() val windowsFactory = DI.windowsMultiMappedModule()!!.windowFactory(1, "1").get()!!.map { WeakReference(it) } val windowWeak = DI.windowsMultiMappedModule()!!.windowWeak(1, "1").get()!!.map { WeakReference(it) } val windowSoft = DI.windowsMultiMappedModule()!!.windowSoft(1, "1").get()!!.map { WeakReference(it) } diff --git a/tests_wraps_kotlin/src/test/kotlin/com/github/klee0kai/stone/kotlin/test/car/cachecontrol/gc/WindowMultiMappedPartialGcTests.kt b/tests_wraps_kotlin/src/test/kotlin/com/github/klee0kai/stone/kotlin/test/car/cachecontrol/gc/WindowMultiMappedPartialGcTests.kt index f2b20fc0..35d649f2 100644 --- a/tests_wraps_kotlin/src/test/kotlin/com/github/klee0kai/stone/kotlin/test/car/cachecontrol/gc/WindowMultiMappedPartialGcTests.kt +++ b/tests_wraps_kotlin/src/test/kotlin/com/github/klee0kai/stone/kotlin/test/car/cachecontrol/gc/WindowMultiMappedPartialGcTests.kt @@ -1,18 +1,18 @@ package com.github.klee0kai.stone.kotlin.test.car.cachecontrol.gc -import com.github.klee0kai.stone.Stone import com.github.klee0kai.stone.kotlin.test.utils.KotlinUtils.resetKotlinRegisters -import com.github.klee0kai.test.car.di.cachecontrol.gc.CarGcComponent +import com.github.klee0kai.test.car.di.cachecontrol.gc.CarGcComponentStoneComponent import com.github.klee0kai.test.car.model.Window import org.junit.jupiter.api.Assertions.* import org.junit.jupiter.api.Test import java.lang.ref.WeakReference class WindowMultiMappedPartialGcTests { + @Test fun createWorkCorrect() { // Given - val DI = Stone.createComponent(CarGcComponent::class.java) + val DI = CarGcComponentStoneComponent() //When val windowStrong1 = DI.windowsMultiMappedModule()!!.windowStrong(1, "1").get()!!.map { WeakReference(it) } @@ -26,7 +26,7 @@ class WindowMultiMappedPartialGcTests { @Test fun holdInListTest() { // Given - val DI = Stone.createComponent(CarGcComponent::class.java) + val DI = CarGcComponentStoneComponent() val windowStrong1 = DI.windowsMultiMappedModule()!!.windowStrong(1, "1").get()!!.map { WeakReference(it) } val windowStrong2 = DI.windowsMultiMappedModule()!!.windowStrong(2, "2").get()!!.map { WeakReference(it) } val holder1 = DI.windowsMultiMappedModule()!!.windowStrong(1, "1").get()!![1] @@ -49,7 +49,7 @@ class WindowMultiMappedPartialGcTests { @Test fun partialRecreateList1Test() { // Given - val DI = Stone.createComponent(CarGcComponent::class.java) + val DI = CarGcComponentStoneComponent() val uids1 = DI.windowsMultiMappedModule()!!.windowStrong(1, "1").get()!!.map { it.uuid } val uids2 = DI.windowsMultiMappedModule()!!.windowStrong(1, "2").get()!!.map { it.uuid } val uids3 = DI.windowsMultiMappedModule()!!.windowStrong(2, "1").get()!!.map { it.uuid } diff --git a/tests_wraps_kotlin/src/test/kotlin/com/github/klee0kai/stone/kotlin/test/car/cachecontrol/gc/WindowMultiMappedReusableGcTests.kt b/tests_wraps_kotlin/src/test/kotlin/com/github/klee0kai/stone/kotlin/test/car/cachecontrol/gc/WindowMultiMappedReusableGcTests.kt index dde95596..f6922e63 100644 --- a/tests_wraps_kotlin/src/test/kotlin/com/github/klee0kai/stone/kotlin/test/car/cachecontrol/gc/WindowMultiMappedReusableGcTests.kt +++ b/tests_wraps_kotlin/src/test/kotlin/com/github/klee0kai/stone/kotlin/test/car/cachecontrol/gc/WindowMultiMappedReusableGcTests.kt @@ -1,17 +1,17 @@ package com.github.klee0kai.stone.kotlin.test.car.cachecontrol.gc -import com.github.klee0kai.stone.Stone import com.github.klee0kai.stone.kotlin.test.utils.KotlinUtils.resetKotlinRegisters -import com.github.klee0kai.test.car.di.cachecontrol.gc.CarGcComponent +import com.github.klee0kai.test.car.di.cachecontrol.gc.CarGcComponentStoneComponent import org.junit.jupiter.api.Assertions.assertEquals import org.junit.jupiter.api.Assertions.assertNotEquals import org.junit.jupiter.api.Test class WindowMultiMappedReusableGcTests { + @Test fun createWorkCorrect() { // Given - val DI = Stone.createComponent(CarGcComponent::class.java) + val DI = CarGcComponentStoneComponent() //When val windowsFactory1 = DI.windowsMultiMappedModule()!!.windowFactory(1, "1").get()!!.map { it.uuid } @@ -33,7 +33,7 @@ class WindowMultiMappedReusableGcTests { @Test fun gcAllTest() { // Given - val DI = Stone.createComponent(CarGcComponent::class.java) + val DI = CarGcComponentStoneComponent() val windowsFactory1 = DI.windowsMultiMappedModule()!!.windowFactory(1, "1").get()!!.map { it.uuid } val windowWeak1 = DI.windowsMultiMappedModule()!!.windowWeak(1, "1").get()!!.map { it.uuid } val windowSoft1 = DI.windowsMultiMappedModule()!!.windowSoft(1, "1").get()!!.map { it.uuid } @@ -71,7 +71,7 @@ class WindowMultiMappedReusableGcTests { @Test fun gcWeakTest() { // Given - val DI = Stone.createComponent(CarGcComponent::class.java) + val DI = CarGcComponentStoneComponent() val windowsFactory1 = DI.windowsMultiMappedModule()!!.windowFactory(1, "1").get()!!.map { it.uuid } val windowWeak1 = DI.windowsMultiMappedModule()!!.windowWeak(1, "1").get()!!.map { it.uuid } val windowSoft1 = DI.windowsMultiMappedModule()!!.windowSoft(1, "1").get()!!.map { it.uuid } @@ -107,7 +107,7 @@ class WindowMultiMappedReusableGcTests { @Test fun gcSoftTest() { // Given - val DI = Stone.createComponent(CarGcComponent::class.java) + val DI = CarGcComponentStoneComponent() val windowsFactory1 = DI.windowsMultiMappedModule()!!.windowFactory(1, "1").get()!!.map { it.uuid } val windowWeak1 = DI.windowsMultiMappedModule()!!.windowWeak(1, "1").get()!!.map { it.uuid } val windowSoft1 = DI.windowsMultiMappedModule()!!.windowSoft(1, "1").get()!!.map { it.uuid } @@ -143,7 +143,7 @@ class WindowMultiMappedReusableGcTests { @Test fun gcStrongTest() { // Given - val DI = Stone.createComponent(CarGcComponent::class.java) + val DI = CarGcComponentStoneComponent() val windowsFactory1 = DI.windowsMultiMappedModule()!!.windowFactory(1, "1").get()!!.map { it.uuid } val windowWeak1 = DI.windowsMultiMappedModule()!!.windowWeak(1, "1").get()!!.map { it.uuid } val windowSoft1 = DI.windowsMultiMappedModule()!!.windowSoft(1, "1").get()!!.map { it.uuid } @@ -179,7 +179,7 @@ class WindowMultiMappedReusableGcTests { @Test fun gcWindows() { // Given - val DI = Stone.createComponent(CarGcComponent::class.java) + val DI = CarGcComponentStoneComponent() val windowsFactory1 = DI.windowsMultiMappedModule()!!.windowFactory(1, "1").get()!!.map { it.uuid } val windowWeak1 = DI.windowsMultiMappedModule()!!.windowWeak(1, "1").get()!!.map { it.uuid } val windowSoft1 = DI.windowsMultiMappedModule()!!.windowSoft(1, "1").get()!!.map { it.uuid } @@ -215,7 +215,7 @@ class WindowMultiMappedReusableGcTests { @Test fun gcWindowsAndWheels() { // Given - val DI = Stone.createComponent(CarGcComponent::class.java) + val DI = CarGcComponentStoneComponent() val windowsFactory1 = DI.windowsMultiMappedModule()!!.windowFactory(1, "1").get()!!.map { it.uuid } val windowWeak1 = DI.windowsMultiMappedModule()!!.windowWeak(1, "1").get()!!.map { it.uuid } val windowSoft1 = DI.windowsMultiMappedModule()!!.windowSoft(1, "1").get()!!.map { it.uuid } @@ -251,7 +251,7 @@ class WindowMultiMappedReusableGcTests { @Test fun gcWheelsTest() { // Given - val DI = Stone.createComponent(CarGcComponent::class.java) + val DI = CarGcComponentStoneComponent() val windowsFactory1 = DI.windowsMultiMappedModule()!!.windowFactory(1, "1").get()!!.map { it.uuid } val windowWeak1 = DI.windowsMultiMappedModule()!!.windowWeak(1, "1").get()!!.map { it.uuid } val windowSoft1 = DI.windowsMultiMappedModule()!!.windowSoft(1, "1").get()!!.map { it.uuid } @@ -287,7 +287,7 @@ class WindowMultiMappedReusableGcTests { @Test fun gcNothing() { // Given - val DI = Stone.createComponent(CarGcComponent::class.java) + val DI = CarGcComponentStoneComponent() val windowsFactory1 = DI.windowsMultiMappedModule()!!.windowFactory(1, "1").get()!!.map { it.uuid } val windowWeak1 = DI.windowsMultiMappedModule()!!.windowWeak(1, "1").get()!!.map { it.uuid } val windowSoft1 = DI.windowsMultiMappedModule()!!.windowSoft(1, "1").get()!!.map { it.uuid } diff --git a/tests_wraps_kotlin/src/test/kotlin/com/github/klee0kai/stone/kotlin/test/car/cachecontrol/gc/WindowPartialGcTests.kt b/tests_wraps_kotlin/src/test/kotlin/com/github/klee0kai/stone/kotlin/test/car/cachecontrol/gc/WindowPartialGcTests.kt index de650258..ccb12e01 100644 --- a/tests_wraps_kotlin/src/test/kotlin/com/github/klee0kai/stone/kotlin/test/car/cachecontrol/gc/WindowPartialGcTests.kt +++ b/tests_wraps_kotlin/src/test/kotlin/com/github/klee0kai/stone/kotlin/test/car/cachecontrol/gc/WindowPartialGcTests.kt @@ -1,18 +1,18 @@ package com.github.klee0kai.stone.kotlin.test.car.cachecontrol.gc -import com.github.klee0kai.stone.Stone import com.github.klee0kai.stone.kotlin.test.utils.KotlinUtils.resetKotlinRegisters -import com.github.klee0kai.test.car.di.cachecontrol.gc.CarGcComponent +import com.github.klee0kai.test.car.di.cachecontrol.gc.CarGcComponentStoneComponent import com.github.klee0kai.test.car.model.Window import org.junit.jupiter.api.Assertions.* import org.junit.jupiter.api.Test import java.lang.ref.WeakReference class WindowPartialGcTests { + @Test fun createWorkCorrect() { // Given - val DI = Stone.createComponent(CarGcComponent::class.java) + val DI = CarGcComponentStoneComponent() //When val windowStrong = DI.windowsModule()!!.windowStrong().get()!!.map { WeakReference(it) } @@ -24,7 +24,7 @@ class WindowPartialGcTests { @Test fun holdInListTest() { // Given - val DI = Stone.createComponent(CarGcComponent::class.java) + val DI = CarGcComponentStoneComponent() val windowStrong = DI.windowsModule()!!.windowStrong().get()!!.map { WeakReference(it) } val holder = DI.windowsModule()!!.windowStrong().get()!![1] @@ -42,7 +42,7 @@ class WindowPartialGcTests { @Test fun partialRecreateList1Test() { // Given - val DI = Stone.createComponent(CarGcComponent::class.java) + val DI = CarGcComponentStoneComponent() val uids1 = DI.windowsModule()!!.windowStrong().get()!!.map { it.uuid } val holder = DI.windowsModule()!!.windowStrong().get()!![0] @@ -63,7 +63,7 @@ class WindowPartialGcTests { @Test fun partialRecreateList2Test() { // Given - val DI = Stone.createComponent(CarGcComponent::class.java) + val DI = CarGcComponentStoneComponent() val uids1 = DI.windowsModule()!!.windowStrong().get()!!.map { it.uuid } val holder = DI.windowsModule()!!.windowStrong().get()!![1] @@ -84,7 +84,7 @@ class WindowPartialGcTests { @Test fun partialRecreateList3Test() { // Given - val DI = Stone.createComponent(CarGcComponent::class.java) + val DI = CarGcComponentStoneComponent() val uids1 = DI.windowsModule()!!.windowStrong().get()!!.map { it.uuid } val holder = DI.windowsModule()!!.windowStrong().get()!![2] diff --git a/tests_wraps_kotlin/src/test/kotlin/com/github/klee0kai/stone/kotlin/test/car/cachecontrol/swcache/BumperSwitchCacheTests.kt b/tests_wraps_kotlin/src/test/kotlin/com/github/klee0kai/stone/kotlin/test/car/cachecontrol/swcache/BumperSwitchCacheTests.kt index a0787268..ea1a9983 100644 --- a/tests_wraps_kotlin/src/test/kotlin/com/github/klee0kai/stone/kotlin/test/car/cachecontrol/swcache/BumperSwitchCacheTests.kt +++ b/tests_wraps_kotlin/src/test/kotlin/com/github/klee0kai/stone/kotlin/test/car/cachecontrol/swcache/BumperSwitchCacheTests.kt @@ -1,18 +1,18 @@ package com.github.klee0kai.stone.kotlin.test.car.cachecontrol.swcache -import com.github.klee0kai.stone.Stone import com.github.klee0kai.stone.kotlin.test.utils.KotlinUtils.resetKotlinRegisters -import com.github.klee0kai.test.car.di.cachecontrol.swcache.CarSwCacheComponent +import com.github.klee0kai.test.car.di.cachecontrol.swcache.CarSwCacheComponentStoneComponent import com.github.klee0kai.test.car.model.Bumper import org.junit.jupiter.api.Assertions.assertEquals import org.junit.jupiter.api.Test import java.lang.ref.WeakReference class BumperSwitchCacheTests { + @Test fun allWeakTest() { // Given - val DI = Stone.createComponent(CarSwCacheComponent::class.java) + val DI = CarSwCacheComponentStoneComponent() val bumperFactory = DI.bumpersModule()!!.bumperFactory().map { WeakReference(it) } val bumperWeak = DI.bumpersModule()!!.bumperWeak().map { WeakReference(it) } val bumperSoft = DI.bumpersModule()!!.bumperSoft().map { WeakReference(it) } @@ -33,7 +33,7 @@ class BumperSwitchCacheTests { @Test fun weakToStrongTest() { // Given - val DI = Stone.createComponent(CarSwCacheComponent::class.java) + val DI = CarSwCacheComponentStoneComponent() val bumperFactory = DI.bumpersModule()!!.bumperFactory().map { WeakReference(it) } val bumperWeak = DI.bumpersModule()!!.bumperWeak().map { WeakReference(it) } val bumperSoft = DI.bumpersModule()!!.bumperSoft().map { WeakReference(it) } @@ -55,7 +55,7 @@ class BumperSwitchCacheTests { @Throws(InterruptedException::class) fun weakToStrongAfterFewMillisTest() { // Given - val DI = Stone.createComponent(CarSwCacheComponent::class.java) + val DI = CarSwCacheComponentStoneComponent() val bumperFactory = DI.bumpersModule()!!.bumperFactory().map { WeakReference(it) } val bumperWeak = DI.bumpersModule()!!.bumperWeak().map { WeakReference(it) } val bumperSoft = DI.bumpersModule()!!.bumperSoft().map { WeakReference(it) } @@ -77,7 +77,7 @@ class BumperSwitchCacheTests { @Test fun softToWeakTest() { // Given - val DI = Stone.createComponent(CarSwCacheComponent::class.java) + val DI = CarSwCacheComponentStoneComponent() val bumperFactory = DI.bumpersModule()!!.bumperFactory().map { WeakReference(it) } val bumperWeak = DI.bumpersModule()!!.bumperWeak().map { WeakReference(it) } val bumperSoft = DI.bumpersModule()!!.bumperSoft().map { WeakReference(it) } @@ -98,7 +98,7 @@ class BumperSwitchCacheTests { @Test fun strongToWeakTest() { // Given - val DI = Stone.createComponent(CarSwCacheComponent::class.java) + val DI = CarSwCacheComponentStoneComponent() val bumperFactory = DI.bumpersModule()!!.bumperFactory().map { WeakReference(it) } val bumperWeak = DI.bumpersModule()!!.bumperWeak().map { WeakReference(it) } val bumperSoft = DI.bumpersModule()!!.bumperSoft().map { WeakReference(it) } @@ -119,7 +119,7 @@ class BumperSwitchCacheTests { @Test fun bumpersToWeakTest() { // Given - val DI = Stone.createComponent(CarSwCacheComponent::class.java) + val DI = CarSwCacheComponentStoneComponent() val bumperFactory = DI.bumpersModule()!!.bumperFactory().map { WeakReference(it) } val bumperWeak = DI.bumpersModule()!!.bumperWeak().map { WeakReference(it) } val bumperSoft = DI.bumpersModule()!!.bumperSoft().map { WeakReference(it) } @@ -140,7 +140,7 @@ class BumperSwitchCacheTests { @Test fun redBumpersToWeakTest() { // Given - val DI = Stone.createComponent(CarSwCacheComponent::class.java) + val DI = CarSwCacheComponentStoneComponent() val bumperFactory = DI.bumpersModule()!!.bumperFactory().map { WeakReference(it) } val bumperWeak = DI.bumpersModule()!!.bumperWeak().map { WeakReference(it) } val bumperSoft = DI.bumpersModule()!!.bumperSoft().map { WeakReference(it) } @@ -161,7 +161,7 @@ class BumperSwitchCacheTests { @Test fun redBumpersToWeak2Test() { // Given - val DI = Stone.createComponent(CarSwCacheComponent::class.java) + val DI = CarSwCacheComponentStoneComponent() val bumperFactory = DI.bumpersModule()!!.bumperFactory().map { WeakReference(it) } val bumperWeak = DI.bumpersModule()!!.bumperWeak().map { WeakReference(it) } val bumperSoft = DI.bumpersModule()!!.bumperSoft().map { WeakReference(it) } @@ -182,7 +182,7 @@ class BumperSwitchCacheTests { @Test fun wheelsToWeakTest() { // Given - val DI = Stone.createComponent(CarSwCacheComponent::class.java) + val DI = CarSwCacheComponentStoneComponent() val bumperFactory = DI.bumpersModule()!!.bumperFactory().map { WeakReference(it) } val bumperWeak = DI.bumpersModule()!!.bumperWeak().map { WeakReference(it) } val bumperSoft = DI.bumpersModule()!!.bumperSoft().map { WeakReference(it) } @@ -204,7 +204,7 @@ class BumperSwitchCacheTests { @Test fun nothingToWeakTest() { // Given - val DI = Stone.createComponent(CarSwCacheComponent::class.java) + val DI = CarSwCacheComponentStoneComponent() val bumperFactory = DI.bumpersModule()!!.bumperFactory().map { WeakReference(it) } val bumperWeak = DI.bumpersModule()!!.bumperWeak().map { WeakReference(it) } val bumperSoft = DI.bumpersModule()!!.bumperSoft().map { WeakReference(it) } diff --git a/tests_wraps_kotlin/src/test/kotlin/com/github/klee0kai/stone/kotlin/test/car/cachecontrol/swcache/WheelSwitchCacheTests.kt b/tests_wraps_kotlin/src/test/kotlin/com/github/klee0kai/stone/kotlin/test/car/cachecontrol/swcache/WheelSwitchCacheTests.kt index 2d2613df..ad3964c5 100644 --- a/tests_wraps_kotlin/src/test/kotlin/com/github/klee0kai/stone/kotlin/test/car/cachecontrol/swcache/WheelSwitchCacheTests.kt +++ b/tests_wraps_kotlin/src/test/kotlin/com/github/klee0kai/stone/kotlin/test/car/cachecontrol/swcache/WheelSwitchCacheTests.kt @@ -1,16 +1,16 @@ package com.github.klee0kai.stone.kotlin.test.car.cachecontrol.swcache -import com.github.klee0kai.stone.Stone -import com.github.klee0kai.test.car.di.cachecontrol.swcache.CarSwCacheComponent +import com.github.klee0kai.test.car.di.cachecontrol.swcache.CarSwCacheComponentStoneComponent import org.junit.jupiter.api.Assertions.assertNotNull import org.junit.jupiter.api.Assertions.assertNull import org.junit.jupiter.api.Test class WheelSwitchCacheTests { + @Test fun allWeakTest() { // Given - val DI = Stone.createComponent(CarSwCacheComponent::class.java) + val DI = CarSwCacheComponentStoneComponent() val wheelFactory = DI.wheelsModule()!!.wheelFactory() val wheelWeak = DI.wheelsModule()!!.wheelWeak() val wheelSoft = DI.wheelsModule()!!.wheelSoft() @@ -30,7 +30,7 @@ class WheelSwitchCacheTests { @Test fun weakToStrongTest() { // Given - val DI = Stone.createComponent(CarSwCacheComponent::class.java) + val DI = CarSwCacheComponentStoneComponent() val wheelFactory = DI.wheelsModule()!!.wheelFactory() val wheelWeak = DI.wheelsModule()!!.wheelWeak() val wheelSoft = DI.wheelsModule()!!.wheelSoft() @@ -51,7 +51,7 @@ class WheelSwitchCacheTests { @Throws(InterruptedException::class) fun weakToStrongAfterFewMillisTest() { // Given - val DI = Stone.createComponent(CarSwCacheComponent::class.java) + val DI = CarSwCacheComponentStoneComponent() val wheelFactory = DI.wheelsModule()!!.wheelFactory() val wheelWeak = DI.wheelsModule()!!.wheelWeak() val wheelSoft = DI.wheelsModule()!!.wheelSoft() @@ -73,7 +73,7 @@ class WheelSwitchCacheTests { @Test fun weakToSoftTest() { // Given - val DI = Stone.createComponent(CarSwCacheComponent::class.java) + val DI = CarSwCacheComponentStoneComponent() val wheelFactory = DI.wheelsModule()!!.wheelFactory() val wheelWeak = DI.wheelsModule()!!.wheelWeak() val wheelSoft = DI.wheelsModule()!!.wheelSoft() @@ -94,7 +94,7 @@ class WheelSwitchCacheTests { @Throws(InterruptedException::class) fun weakToSoftAfterFewMillisTest() { // Given - val DI = Stone.createComponent(CarSwCacheComponent::class.java) + val DI = CarSwCacheComponentStoneComponent() val wheelFactory = DI.wheelsModule()!!.wheelFactory() val wheelWeak = DI.wheelsModule()!!.wheelWeak() val wheelSoft = DI.wheelsModule()!!.wheelSoft() @@ -116,7 +116,7 @@ class WheelSwitchCacheTests { @Test fun softToWeakTest() { // Given - val DI = Stone.createComponent(CarSwCacheComponent::class.java) + val DI = CarSwCacheComponentStoneComponent() val wheelFactory = DI.wheelsModule()!!.wheelFactory() val wheelWeak = DI.wheelsModule()!!.wheelWeak() val wheelSoft = DI.wheelsModule()!!.wheelSoft() @@ -136,7 +136,7 @@ class WheelSwitchCacheTests { @Test fun strongToWeakTest() { // Given - val DI = Stone.createComponent(CarSwCacheComponent::class.java) + val DI = CarSwCacheComponentStoneComponent() val wheelFactory = DI.wheelsModule()!!.wheelFactory() val wheelWeak = DI.wheelsModule()!!.wheelWeak() val wheelSoft = DI.wheelsModule()!!.wheelSoft() @@ -156,7 +156,7 @@ class WheelSwitchCacheTests { @Test fun wheelsToWeakTest() { // Given - val DI = Stone.createComponent(CarSwCacheComponent::class.java) + val DI = CarSwCacheComponentStoneComponent() val wheelFactory = DI.wheelsModule()!!.wheelFactory() val wheelWeak = DI.wheelsModule()!!.wheelWeak() val wheelSoft = DI.wheelsModule()!!.wheelSoft() @@ -176,7 +176,7 @@ class WheelSwitchCacheTests { @Test fun nothinToWeakTest() { // Given - val DI = Stone.createComponent(CarSwCacheComponent::class.java) + val DI = CarSwCacheComponentStoneComponent() val wheelFactory = DI.wheelsModule()!!.wheelFactory() val wheelWeak = DI.wheelsModule()!!.wheelWeak() val wheelSoft = DI.wheelsModule()!!.wheelSoft() @@ -196,7 +196,7 @@ class WheelSwitchCacheTests { @Test fun windowsToWeakTest() { // Given - val DI = Stone.createComponent(CarSwCacheComponent::class.java) + val DI = CarSwCacheComponentStoneComponent() val wheelFactory = DI.wheelsModule()!!.wheelFactory() val wheelWeak = DI.wheelsModule()!!.wheelWeak() val wheelSoft = DI.wheelsModule()!!.wheelSoft() @@ -216,7 +216,7 @@ class WheelSwitchCacheTests { @Test fun windowAndWheelsToWeak() { // Given - val DI = Stone.createComponent(CarSwCacheComponent::class.java) + val DI = CarSwCacheComponentStoneComponent() val wheelFactory = DI.wheelsModule()!!.wheelFactory() val wheelWeak = DI.wheelsModule()!!.wheelWeak() val wheelSoft = DI.wheelsModule()!!.wheelSoft() diff --git a/tests_wraps_kotlin/src/test/kotlin/com/github/klee0kai/stone/kotlin/test/car/cachecontrol/swcache/WindowMappedSwitchCacheTests.kt b/tests_wraps_kotlin/src/test/kotlin/com/github/klee0kai/stone/kotlin/test/car/cachecontrol/swcache/WindowMappedSwitchCacheTests.kt index ecc5b1cd..7ad2243e 100644 --- a/tests_wraps_kotlin/src/test/kotlin/com/github/klee0kai/stone/kotlin/test/car/cachecontrol/swcache/WindowMappedSwitchCacheTests.kt +++ b/tests_wraps_kotlin/src/test/kotlin/com/github/klee0kai/stone/kotlin/test/car/cachecontrol/swcache/WindowMappedSwitchCacheTests.kt @@ -1,18 +1,18 @@ package com.github.klee0kai.stone.kotlin.test.car.cachecontrol.swcache -import com.github.klee0kai.stone.Stone import com.github.klee0kai.stone.kotlin.test.utils.KotlinUtils.resetKotlinRegisters -import com.github.klee0kai.test.car.di.cachecontrol.swcache.CarSwCacheComponent +import com.github.klee0kai.test.car.di.cachecontrol.swcache.CarSwCacheComponentStoneComponent import com.github.klee0kai.test.car.model.Window import org.junit.jupiter.api.Assertions.assertEquals import org.junit.jupiter.api.Test import java.lang.ref.WeakReference class WindowMappedSwitchCacheTests { + @Test fun allWeakTest() { // Given - val DI = Stone.createComponent(CarSwCacheComponent::class.java) + val DI = CarSwCacheComponentStoneComponent() val windowsFactory = DI.windowsMappedModule()!!.windowFactory("1").get()!!.map { WeakReference(it) } val windowWeak = DI.windowsMappedModule()!!.windowWeak("1").get()!!.map { WeakReference(it) } val windowSoft = DI.windowsMappedModule()!!.windowSoft("1").get()!!.map { WeakReference(it) } @@ -34,7 +34,7 @@ class WindowMappedSwitchCacheTests { @Test fun weakToStrongTest() { // Given - val DI = Stone.createComponent(CarSwCacheComponent::class.java) + val DI = CarSwCacheComponentStoneComponent() val windowsFactory = DI.windowsMappedModule()!!.windowFactory("1").get()!!.map { WeakReference(it) } val windowWeak = DI.windowsMappedModule()!!.windowWeak("1").get()!!.map { WeakReference(it) } val windowSoft = DI.windowsMappedModule()!!.windowSoft("1").get()!!.map { WeakReference(it) } @@ -56,7 +56,7 @@ class WindowMappedSwitchCacheTests { @Throws(InterruptedException::class) fun weakToStrongAfterFewMillisTest() { // Given - val DI = Stone.createComponent(CarSwCacheComponent::class.java) + val DI = CarSwCacheComponentStoneComponent() val windowsFactory = DI.windowsMappedModule()!!.windowFactory("1").get()!!.map { WeakReference(it) } val windowWeak = DI.windowsMappedModule()!!.windowWeak("1").get()!!.map { WeakReference(it) } val windowSoft = DI.windowsMappedModule()!!.windowSoft("1").get()!!.map { WeakReference(it) } @@ -78,7 +78,7 @@ class WindowMappedSwitchCacheTests { @Test fun weakToSoftTest() { // Given - val DI = Stone.createComponent(CarSwCacheComponent::class.java) + val DI = CarSwCacheComponentStoneComponent() val windowsFactory = DI.windowsMappedModule()!!.windowFactory("1").get()!!.map { WeakReference(it) } val windowWeak = DI.windowsMappedModule()!!.windowWeak("1").get()!!.map { WeakReference(it) } val windowSoft = DI.windowsMappedModule()!!.windowSoft("1").get()!!.map { WeakReference(it) } @@ -100,7 +100,7 @@ class WindowMappedSwitchCacheTests { @Throws(InterruptedException::class) fun weakToSoftAfterFewMillisTest() { // Given - val DI = Stone.createComponent(CarSwCacheComponent::class.java) + val DI = CarSwCacheComponentStoneComponent() val windowsFactory = DI.windowsMappedModule()!!.windowFactory("1").get()!!.map { WeakReference(it) } val windowWeak = DI.windowsMappedModule()!!.windowWeak("1").get()!!.map { WeakReference(it) } val windowSoft = DI.windowsMappedModule()!!.windowSoft("1").get()!!.map { WeakReference(it) } @@ -122,7 +122,7 @@ class WindowMappedSwitchCacheTests { @Test fun softToWeakTest() { // Given - val DI = Stone.createComponent(CarSwCacheComponent::class.java) + val DI = CarSwCacheComponentStoneComponent() val windowsFactory = DI.windowsMappedModule()!!.windowFactory("1").get()!!.map { WeakReference(it) } val windowWeak = DI.windowsMappedModule()!!.windowWeak("1").get()!!.map { WeakReference(it) } val windowSoft = DI.windowsMappedModule()!!.windowSoft("1").get()!!.map { WeakReference(it) } @@ -143,7 +143,7 @@ class WindowMappedSwitchCacheTests { @Test fun strongToWeakTest() { // Given - val DI = Stone.createComponent(CarSwCacheComponent::class.java) + val DI = CarSwCacheComponentStoneComponent() val windowsFactory = DI.windowsMappedModule()!!.windowFactory("1").get()!!.map { WeakReference(it) } val windowWeak = DI.windowsMappedModule()!!.windowWeak("1").get()!!.map { WeakReference(it) } val windowSoft = DI.windowsMappedModule()!!.windowSoft("1").get()!!.map { WeakReference(it) } @@ -164,7 +164,7 @@ class WindowMappedSwitchCacheTests { @Test fun windowsToWeakTest() { // Given - val DI = Stone.createComponent(CarSwCacheComponent::class.java) + val DI = CarSwCacheComponentStoneComponent() val windowsFactory = DI.windowsMappedModule()!!.windowFactory("1").get()!!.map { WeakReference(it) } val windowWeak = DI.windowsMappedModule()!!.windowWeak("1").get()!!.map { WeakReference(it) } val windowSoft = DI.windowsMappedModule()!!.windowSoft("1").get()!!.map { WeakReference(it) } @@ -185,7 +185,7 @@ class WindowMappedSwitchCacheTests { @Test fun windowsAndWheelsToWeakTest() { // Given - val DI = Stone.createComponent(CarSwCacheComponent::class.java) + val DI = CarSwCacheComponentStoneComponent() val windowsFactory = DI.windowsMappedModule()!!.windowFactory("1").get()!!.map { WeakReference(it) } val windowWeak = DI.windowsMappedModule()!!.windowWeak("1").get()!!.map { WeakReference(it) } val windowSoft = DI.windowsMappedModule()!!.windowSoft("1").get()!!.map { WeakReference(it) } @@ -206,7 +206,7 @@ class WindowMappedSwitchCacheTests { @Test fun wheelsToWeakTest() { // Given - val DI = Stone.createComponent(CarSwCacheComponent::class.java) + val DI = CarSwCacheComponentStoneComponent() val windowsFactory = DI.windowsMappedModule()!!.windowFactory("1").get()!!.map { WeakReference(it) } val windowWeak = DI.windowsMappedModule()!!.windowWeak("1").get()!!.map { WeakReference(it) } val windowSoft = DI.windowsMappedModule()!!.windowSoft("1").get()!!.map { WeakReference(it) } @@ -228,7 +228,7 @@ class WindowMappedSwitchCacheTests { @Test fun nothingToWeakTest() { // Given - val DI = Stone.createComponent(CarSwCacheComponent::class.java) + val DI = CarSwCacheComponentStoneComponent() val windowsFactory = DI.windowsMappedModule()!!.windowFactory("1").get()!!.map { WeakReference(it) } val windowWeak = DI.windowsMappedModule()!!.windowWeak("1").get()!!.map { WeakReference(it) } val windowSoft = DI.windowsMappedModule()!!.windowSoft("1").get()!!.map { WeakReference(it) } diff --git a/tests_wraps_kotlin/src/test/kotlin/com/github/klee0kai/stone/kotlin/test/car/cachecontrol/swcache/WindowMultiMappedSwitchCacheTests.kt b/tests_wraps_kotlin/src/test/kotlin/com/github/klee0kai/stone/kotlin/test/car/cachecontrol/swcache/WindowMultiMappedSwitchCacheTests.kt index 69890d89..2c5a7ce9 100644 --- a/tests_wraps_kotlin/src/test/kotlin/com/github/klee0kai/stone/kotlin/test/car/cachecontrol/swcache/WindowMultiMappedSwitchCacheTests.kt +++ b/tests_wraps_kotlin/src/test/kotlin/com/github/klee0kai/stone/kotlin/test/car/cachecontrol/swcache/WindowMultiMappedSwitchCacheTests.kt @@ -1,18 +1,18 @@ package com.github.klee0kai.stone.kotlin.test.car.cachecontrol.swcache -import com.github.klee0kai.stone.Stone import com.github.klee0kai.stone.kotlin.test.utils.KotlinUtils.resetKotlinRegisters -import com.github.klee0kai.test.car.di.cachecontrol.swcache.CarSwCacheComponent +import com.github.klee0kai.test.car.di.cachecontrol.swcache.CarSwCacheComponentStoneComponent import com.github.klee0kai.test.car.model.Window import org.junit.jupiter.api.Assertions.assertEquals import org.junit.jupiter.api.Test import java.lang.ref.WeakReference class WindowMultiMappedSwitchCacheTests { + @Test fun allWeakTest() { // Given - val DI = Stone.createComponent(CarSwCacheComponent::class.java) + val DI = CarSwCacheComponentStoneComponent() val windowsFactory = DI.windowsMultiMappedModule()!!.windowFactory(1, "1").get()!!.map { WeakReference(it) } val windowWeak = DI.windowsMultiMappedModule()!!.windowWeak(1, "1").get()!!.map { WeakReference(it) } val windowSoft = DI.windowsMultiMappedModule()!!.windowSoft(1, "1").get()!!.map { WeakReference(it) } @@ -34,7 +34,7 @@ class WindowMultiMappedSwitchCacheTests { @Test fun weakToStrongTest() { // Given - val DI = Stone.createComponent(CarSwCacheComponent::class.java) + val DI = CarSwCacheComponentStoneComponent() val windowsFactory = DI.windowsMultiMappedModule()!!.windowFactory(1, "1").get()!!.map { WeakReference(it) } val windowWeak = DI.windowsMultiMappedModule()!!.windowWeak(1, "1").get()!!.map { WeakReference(it) } val windowSoft = DI.windowsMultiMappedModule()!!.windowSoft(1, "1").get()!!.map { WeakReference(it) } @@ -56,7 +56,7 @@ class WindowMultiMappedSwitchCacheTests { @Throws(InterruptedException::class) fun weakToStrongAfterFewMillisTest() { // Given - val DI = Stone.createComponent(CarSwCacheComponent::class.java) + val DI = CarSwCacheComponentStoneComponent() val windowsFactory = DI.windowsMultiMappedModule()!!.windowFactory(1, "1").get()!!.map { WeakReference(it) } val windowWeak = DI.windowsMultiMappedModule()!!.windowWeak(1, "1").get()!!.map { WeakReference(it) } val windowSoft = DI.windowsMultiMappedModule()!!.windowSoft(1, "1").get()!!.map { WeakReference(it) } @@ -78,7 +78,7 @@ class WindowMultiMappedSwitchCacheTests { @Test fun weakToSoftTest() { // Given - val DI = Stone.createComponent(CarSwCacheComponent::class.java) + val DI = CarSwCacheComponentStoneComponent() val windowsFactory = DI.windowsMultiMappedModule()!!.windowFactory(1, "1").get()!!.map { WeakReference(it) } val windowWeak = DI.windowsMultiMappedModule()!!.windowWeak(1, "1").get()!!.map { WeakReference(it) } val windowSoft = DI.windowsMultiMappedModule()!!.windowSoft(1, "1").get()!!.map { WeakReference(it) } @@ -100,7 +100,7 @@ class WindowMultiMappedSwitchCacheTests { @Throws(InterruptedException::class) fun weakToSoftAfterFewMillisTest() { // Given - val DI = Stone.createComponent(CarSwCacheComponent::class.java) + val DI = CarSwCacheComponentStoneComponent() val windowsFactory = DI.windowsMultiMappedModule()!!.windowFactory(1, "1").get()!!.map { WeakReference(it) } val windowWeak = DI.windowsMultiMappedModule()!!.windowWeak(1, "1").get()!!.map { WeakReference(it) } val windowSoft = DI.windowsMultiMappedModule()!!.windowSoft(1, "1").get()!!.map { WeakReference(it) } @@ -122,7 +122,7 @@ class WindowMultiMappedSwitchCacheTests { @Test fun softToWeakTest() { // Given - val DI = Stone.createComponent(CarSwCacheComponent::class.java) + val DI = CarSwCacheComponentStoneComponent() val windowsFactory = DI.windowsMultiMappedModule()!!.windowFactory(1, "1").get()!!.map { WeakReference(it) } val windowWeak = DI.windowsMultiMappedModule()!!.windowWeak(1, "1").get()!!.map { WeakReference(it) } val windowSoft = DI.windowsMultiMappedModule()!!.windowSoft(1, "1").get()!!.map { WeakReference(it) } @@ -143,7 +143,7 @@ class WindowMultiMappedSwitchCacheTests { @Test fun strongToWeakTest() { // Given - val DI = Stone.createComponent(CarSwCacheComponent::class.java) + val DI = CarSwCacheComponentStoneComponent() val windowsFactory = DI.windowsMultiMappedModule()!!.windowFactory(1, "1").get()!!.map { WeakReference(it) } val windowWeak = DI.windowsMultiMappedModule()!!.windowWeak(1, "1").get()!!.map { WeakReference(it) } val windowSoft = DI.windowsMultiMappedModule()!!.windowSoft(1, "1").get()!!.map { WeakReference(it) } @@ -164,7 +164,7 @@ class WindowMultiMappedSwitchCacheTests { @Test fun windowsToWeakTest() { // Given - val DI = Stone.createComponent(CarSwCacheComponent::class.java) + val DI = CarSwCacheComponentStoneComponent() val windowsFactory = DI.windowsMultiMappedModule()!!.windowFactory(1, "1").get()!!.map { WeakReference(it) } val windowWeak = DI.windowsMultiMappedModule()!!.windowWeak(1, "1").get()!!.map { WeakReference(it) } val windowSoft = DI.windowsMultiMappedModule()!!.windowSoft(1, "1").get()!!.map { WeakReference(it) } @@ -185,7 +185,7 @@ class WindowMultiMappedSwitchCacheTests { @Test fun windowAndWheelsToWeakTest() { // Given - val DI = Stone.createComponent(CarSwCacheComponent::class.java) + val DI = CarSwCacheComponentStoneComponent() val windowsFactory = DI.windowsMultiMappedModule()!!.windowFactory(1, "1").get()!!.map { WeakReference(it) } val windowWeak = DI.windowsMultiMappedModule()!!.windowWeak(1, "1").get()!!.map { WeakReference(it) } val windowSoft = DI.windowsMultiMappedModule()!!.windowSoft(1, "1").get()!!.map { WeakReference(it) } @@ -206,7 +206,7 @@ class WindowMultiMappedSwitchCacheTests { @Test fun wheelToWeakTest() { // Given - val DI = Stone.createComponent(CarSwCacheComponent::class.java) + val DI = CarSwCacheComponentStoneComponent() val windowsFactory = DI.windowsMultiMappedModule()!!.windowFactory(1, "1").get()!!.map { WeakReference(it) } val windowWeak = DI.windowsMultiMappedModule()!!.windowWeak(1, "1").get()!!.map { WeakReference(it) } val windowSoft = DI.windowsMultiMappedModule()!!.windowSoft(1, "1").get()!!.map { WeakReference(it) } @@ -228,7 +228,7 @@ class WindowMultiMappedSwitchCacheTests { @Test fun weakNothingTest() { // Given - val DI = Stone.createComponent(CarSwCacheComponent::class.java) + val DI = CarSwCacheComponentStoneComponent() val windowsFactory = DI.windowsMultiMappedModule()!!.windowFactory(1, "1").get()!!.map { WeakReference(it) } val windowWeak = DI.windowsMultiMappedModule()!!.windowWeak(1, "1").get()!!.map { WeakReference(it) } val windowSoft = DI.windowsMultiMappedModule()!!.windowSoft(1, "1").get()!!.map { WeakReference(it) } diff --git a/tests_wraps_kotlin/src/test/kotlin/com/github/klee0kai/stone/kotlin/test/car/cachecontrol/swcache/WindowSwitchCacheTests.kt b/tests_wraps_kotlin/src/test/kotlin/com/github/klee0kai/stone/kotlin/test/car/cachecontrol/swcache/WindowSwitchCacheTests.kt index f5338d67..3678362c 100644 --- a/tests_wraps_kotlin/src/test/kotlin/com/github/klee0kai/stone/kotlin/test/car/cachecontrol/swcache/WindowSwitchCacheTests.kt +++ b/tests_wraps_kotlin/src/test/kotlin/com/github/klee0kai/stone/kotlin/test/car/cachecontrol/swcache/WindowSwitchCacheTests.kt @@ -1,18 +1,18 @@ package com.github.klee0kai.stone.kotlin.test.car.cachecontrol.swcache -import com.github.klee0kai.stone.Stone import com.github.klee0kai.stone.kotlin.test.utils.KotlinUtils.resetKotlinRegisters -import com.github.klee0kai.test.car.di.cachecontrol.swcache.CarSwCacheComponent +import com.github.klee0kai.test.car.di.cachecontrol.swcache.CarSwCacheComponentStoneComponent import com.github.klee0kai.test.car.model.Window import org.junit.jupiter.api.Assertions.assertEquals import org.junit.jupiter.api.Test import java.lang.ref.WeakReference class WindowSwitchCacheTests { + @Test fun allWeakTest() { // Given - val DI = Stone.createComponent(CarSwCacheComponent::class.java) + val DI = CarSwCacheComponentStoneComponent() val windowsFactory = DI.windowsModule()!!.windowFactory().get()!!.map { WeakReference(it) } val windowWeak = DI.windowsModule()!!.windowWeak().get()!!.map { WeakReference(it) } val windowSoft = DI.windowsModule()!!.windowSoft().get()!!.map { WeakReference(it) } @@ -34,7 +34,7 @@ class WindowSwitchCacheTests { @Test fun weakToStrongTest() { // Given - val DI = Stone.createComponent(CarSwCacheComponent::class.java) + val DI = CarSwCacheComponentStoneComponent() val windowsFactory = DI.windowsModule()!!.windowFactory().get()!!.map { WeakReference(it) } val windowWeak = DI.windowsModule()!!.windowWeak().get()!!.map { WeakReference(it) } val windowSoft = DI.windowsModule()!!.windowSoft().get()!!.map { WeakReference(it) } @@ -56,7 +56,7 @@ class WindowSwitchCacheTests { @Throws(InterruptedException::class) fun weakToStrongAfterFewMillisTest() { // Given - val DI = Stone.createComponent(CarSwCacheComponent::class.java) + val DI = CarSwCacheComponentStoneComponent() val windowsFactory = DI.windowsModule()!!.windowFactory().get()!!.map { WeakReference(it) } val windowWeak = DI.windowsModule()!!.windowWeak().get()!!.map { WeakReference(it) } val windowSoft = DI.windowsModule()!!.windowSoft().get()!!.map { WeakReference(it) } @@ -78,7 +78,7 @@ class WindowSwitchCacheTests { @Test fun softToWeakTest() { // Given - val DI = Stone.createComponent(CarSwCacheComponent::class.java) + val DI = CarSwCacheComponentStoneComponent() val windowsFactory = DI.windowsModule()!!.windowFactory().get()!!.map { WeakReference(it) } val windowWeak = DI.windowsModule()!!.windowWeak().get()!!.map { WeakReference(it) } val windowSoft = DI.windowsModule()!!.windowSoft().get()!!.map { WeakReference(it) } @@ -99,7 +99,7 @@ class WindowSwitchCacheTests { @Test fun strongToWeakTest() { // Given - val DI = Stone.createComponent(CarSwCacheComponent::class.java) + val DI = CarSwCacheComponentStoneComponent() val windowsFactory = DI.windowsModule()!!.windowFactory().get()!!.map { WeakReference(it) } val windowWeak = DI.windowsModule()!!.windowWeak().get()!!.map { WeakReference(it) } val windowSoft = DI.windowsModule()!!.windowSoft().get()!!.map { WeakReference(it) } @@ -120,7 +120,7 @@ class WindowSwitchCacheTests { @Test fun windowsToWeakTest() { // Given - val DI = Stone.createComponent(CarSwCacheComponent::class.java) + val DI = CarSwCacheComponentStoneComponent() val windowsFactory = DI.windowsModule()!!.windowFactory().get()!!.map { WeakReference(it) } val windowWeak = DI.windowsModule()!!.windowWeak().get()!!.map { WeakReference(it) } val windowSoft = DI.windowsModule()!!.windowSoft().get()!!.map { WeakReference(it) } @@ -141,7 +141,7 @@ class WindowSwitchCacheTests { @Test fun windowsAndWheelsToWeakTest() { // Given - val DI = Stone.createComponent(CarSwCacheComponent::class.java) + val DI = CarSwCacheComponentStoneComponent() val windowsFactory = DI.windowsModule()!!.windowFactory().get()!!.map { WeakReference(it) } val windowWeak = DI.windowsModule()!!.windowWeak().get()!!.map { WeakReference(it) } val windowSoft = DI.windowsModule()!!.windowSoft().get()!!.map { WeakReference(it) } @@ -162,7 +162,7 @@ class WindowSwitchCacheTests { @Test fun wheelsToWeakTest() { // Given - val DI = Stone.createComponent(CarSwCacheComponent::class.java) + val DI = CarSwCacheComponentStoneComponent() val windowsFactory = DI.windowsModule()!!.windowFactory().get()!!.map { WeakReference(it) } val windowWeak = DI.windowsModule()!!.windowWeak().get()!!.map { WeakReference(it) } val windowSoft = DI.windowsModule()!!.windowSoft().get()!!.map { WeakReference(it) } @@ -184,7 +184,7 @@ class WindowSwitchCacheTests { @Test fun weakNothingTest() { // Given - val DI = Stone.createComponent(CarSwCacheComponent::class.java) + val DI = CarSwCacheComponentStoneComponent() val windowsFactory = DI.windowsModule()!!.windowFactory().get()!!.map { WeakReference(it) } val windowWeak = DI.windowsModule()!!.windowWeak().get()!!.map { WeakReference(it) } val windowSoft = DI.windowsModule()!!.windowSoft().get()!!.map { WeakReference(it) } diff --git a/tests_wraps_kotlin/src/test/kotlin/com/github/klee0kai/stone/kotlin/test/car/inject/CarInjectMethodTests.kt b/tests_wraps_kotlin/src/test/kotlin/com/github/klee0kai/stone/kotlin/test/car/inject/CarInjectMethodTests.kt index ba976271..58ec2dea 100644 --- a/tests_wraps_kotlin/src/test/kotlin/com/github/klee0kai/stone/kotlin/test/car/inject/CarInjectMethodTests.kt +++ b/tests_wraps_kotlin/src/test/kotlin/com/github/klee0kai/stone/kotlin/test/car/inject/CarInjectMethodTests.kt @@ -1,14 +1,13 @@ package com.github.klee0kai.stone.kotlin.test.car.inject -import com.github.klee0kai.stone.Stone -import com.github.klee0kai.test.car.di.inject.CarInjectComponent +import com.github.klee0kai.test.car.di.inject.CarInjectComponentStoneComponent import com.github.klee0kai.test.car.model.* -import org.junit.jupiter.api.Assertions import org.junit.jupiter.api.Assertions.* import org.junit.jupiter.api.BeforeEach import org.junit.jupiter.api.Test class CarInjectMethodTests { + @BeforeEach fun init() { Bumper.createCount = 0 @@ -20,7 +19,7 @@ class CarInjectMethodTests { @Test fun carInjectTest() { //Given - val DI = Stone.createComponent(CarInjectComponent::class.java) + val DI = CarInjectComponentStoneComponent() //When val carInject = CarInject() @@ -36,7 +35,7 @@ class CarInjectMethodTests { @Test fun carInjectReusableTest() { //Given - val DI = Stone.createComponent(CarInjectComponent::class.java) + val DI = CarInjectComponentStoneComponent() //When val carInject1 = CarInject() @@ -59,7 +58,7 @@ class CarInjectMethodTests { @Test fun carInjectListTest() { //Given - val DI = Stone.createComponent(CarInjectComponent::class.java) + val DI = CarInjectComponentStoneComponent() //When val carInject = CarInjectLists() @@ -86,7 +85,7 @@ class CarInjectMethodTests { @Test fun carInjectListReusableTest() { //Given - val DI = Stone.createComponent(CarInjectComponent::class.java) + val DI = CarInjectComponentStoneComponent() //When val carInject1 = CarInjectLists() @@ -115,7 +114,7 @@ class CarInjectMethodTests { @Test fun carInjectProviderTest() { //Given - val DI = Stone.createComponent(CarInjectComponent::class.java) + val DI = CarInjectComponentStoneComponent() //When val carInject = CarInjectProvider() @@ -132,7 +131,7 @@ class CarInjectMethodTests { @Test fun carInjectProvideReusableTest() { //Given - val DI = Stone.createComponent(CarInjectComponent::class.java) + val DI = CarInjectComponentStoneComponent() //When val carInject1 = CarInjectProvider() @@ -153,7 +152,7 @@ class CarInjectMethodTests { carInject2.wheelFromMethod!!.get().uuid, "should cache " ) - Assertions.assertNotEquals( + assertNotEquals( carInject1.windowFromMethod!!.get().value!!.uuid, carInject2.windowFromMethod!!.get().value!!.uuid, "provide via Provider. No caching" diff --git a/tests_wraps_kotlin/src/test/kotlin/com/github/klee0kai/stone/kotlin/test/car/inject/CarInjectMixedTests.kt b/tests_wraps_kotlin/src/test/kotlin/com/github/klee0kai/stone/kotlin/test/car/inject/CarInjectMixedTests.kt index fba7ac40..03ffcad1 100644 --- a/tests_wraps_kotlin/src/test/kotlin/com/github/klee0kai/stone/kotlin/test/car/inject/CarInjectMixedTests.kt +++ b/tests_wraps_kotlin/src/test/kotlin/com/github/klee0kai/stone/kotlin/test/car/inject/CarInjectMixedTests.kt @@ -1,7 +1,6 @@ package com.github.klee0kai.stone.kotlin.test.car.inject -import com.github.klee0kai.stone.Stone -import com.github.klee0kai.test.car.di.inject.CarInjectComponent +import com.github.klee0kai.test.car.di.inject.CarInjectComponentStoneComponent import com.github.klee0kai.test.car.model.* import org.junit.jupiter.api.Assertions.assertEquals import org.junit.jupiter.api.Assertions.assertNotEquals @@ -9,6 +8,7 @@ import org.junit.jupiter.api.BeforeEach import org.junit.jupiter.api.Test class CarInjectMixedTests { + @BeforeEach fun init() { Bumper.createCount = 0 @@ -20,7 +20,7 @@ class CarInjectMixedTests { @Test fun carInjectReusableTest() { //Given - val DI = Stone.createComponent(CarInjectComponent::class.java) + val DI = CarInjectComponentStoneComponent() //When val carInject1 = CarInject() @@ -43,7 +43,7 @@ class CarInjectMixedTests { @Test fun carInjectListReusableTest() { //Given - val DI = Stone.createComponent(CarInjectComponent::class.java) + val DI = CarInjectComponentStoneComponent() //When val carInject1 = CarInjectLists() @@ -66,7 +66,7 @@ class CarInjectMixedTests { @Test fun carInjectProvideReusableTest() { //Given - val DI = Stone.createComponent(CarInjectComponent::class.java) + val DI = CarInjectComponentStoneComponent() //When val carInject1 = CarInjectProvider() diff --git a/tests_wraps_kotlin/src/test/kotlin/com/github/klee0kai/stone/kotlin/test/car/inject/CarInjectTests.kt b/tests_wraps_kotlin/src/test/kotlin/com/github/klee0kai/stone/kotlin/test/car/inject/CarInjectTests.kt index 283bf024..138a5653 100644 --- a/tests_wraps_kotlin/src/test/kotlin/com/github/klee0kai/stone/kotlin/test/car/inject/CarInjectTests.kt +++ b/tests_wraps_kotlin/src/test/kotlin/com/github/klee0kai/stone/kotlin/test/car/inject/CarInjectTests.kt @@ -1,13 +1,13 @@ package com.github.klee0kai.stone.kotlin.test.car.inject -import com.github.klee0kai.stone.Stone -import com.github.klee0kai.test.car.di.inject.CarInjectComponent +import com.github.klee0kai.test.car.di.inject.CarInjectComponentStoneComponent import com.github.klee0kai.test.car.model.* import org.junit.jupiter.api.Assertions.* import org.junit.jupiter.api.BeforeEach import org.junit.jupiter.api.Test class CarInjectTests { + @BeforeEach fun init() { Bumper.createCount = 0 @@ -19,7 +19,7 @@ class CarInjectTests { @Test fun carInjectTest() { //Given - val DI = Stone.createComponent(CarInjectComponent::class.java) + val DI = CarInjectComponentStoneComponent() //When val carInject = CarInject() @@ -35,7 +35,7 @@ class CarInjectTests { @Test fun carInjectReusableTest() { //Given - val DI = Stone.createComponent(CarInjectComponent::class.java) + val DI = CarInjectComponentStoneComponent() //When val carInject1 = CarInject() @@ -58,7 +58,7 @@ class CarInjectTests { @Test fun carInjectListTest() { //Given - val DI = Stone.createComponent(CarInjectComponent::class.java) + val DI = CarInjectComponentStoneComponent() //When val carInject = CarInjectLists() @@ -85,7 +85,7 @@ class CarInjectTests { @Test fun carInjectListReusableTest() { //Given - val DI = Stone.createComponent(CarInjectComponent::class.java) + val DI = CarInjectComponentStoneComponent() //When val carInject1 = CarInjectLists() @@ -108,7 +108,7 @@ class CarInjectTests { @Test fun carInjectProviderTest() { //Given - val DI = Stone.createComponent(CarInjectComponent::class.java) + val DI = CarInjectComponentStoneComponent() //When val carInject = CarInjectProvider() @@ -125,9 +125,7 @@ class CarInjectTests { @Test fun carInjectProvideReusableTest() { //Given - val DI = Stone.createComponent( - CarInjectComponent::class.java - ) + val DI = CarInjectComponentStoneComponent() //When val carInject1 = CarInjectProvider() diff --git a/tests_wraps_kotlin/src/test/kotlin/com/github/klee0kai/stone/kotlin/test/car/inject/CarProtectInjectedTests.kt b/tests_wraps_kotlin/src/test/kotlin/com/github/klee0kai/stone/kotlin/test/car/inject/CarProtectInjectedTests.kt index dedaf190..f5386374 100644 --- a/tests_wraps_kotlin/src/test/kotlin/com/github/klee0kai/stone/kotlin/test/car/inject/CarProtectInjectedTests.kt +++ b/tests_wraps_kotlin/src/test/kotlin/com/github/klee0kai/stone/kotlin/test/car/inject/CarProtectInjectedTests.kt @@ -1,7 +1,6 @@ package com.github.klee0kai.stone.kotlin.test.car.inject -import com.github.klee0kai.stone.Stone -import com.github.klee0kai.test.car.di.inject.CarInjectComponent +import com.github.klee0kai.test.car.di.inject.CarInjectComponentStoneComponent import com.github.klee0kai.test.car.model.CarInject import com.github.klee0kai.test.car.model.CarInjectLists import com.github.klee0kai.test.car.model.CarInjectProvider @@ -10,10 +9,11 @@ import org.junit.jupiter.api.Assertions.assertNotEquals import org.junit.jupiter.api.Test class CarProtectInjectedTests { + @Test fun carProtectInjectedTest() { //Given - val DI = Stone.createComponent(CarInjectComponent::class.java) + val DI = CarInjectComponentStoneComponent() //When var carInject: CarInject? = CarInject() @@ -36,7 +36,7 @@ class CarProtectInjectedTests { @Test fun carProtectListInjectedTest() { - val DI = Stone.createComponent(CarInjectComponent::class.java) + val DI = CarInjectComponentStoneComponent() //When var carInject: CarInjectLists? = CarInjectLists() @@ -72,7 +72,7 @@ class CarProtectInjectedTests { @Test fun carProtectProviderTest() { //Given - val DI = Stone.createComponent(CarInjectComponent::class.java) + val DI = CarInjectComponentStoneComponent() //When var carInject: CarInjectProvider? = CarInjectProvider() @@ -96,4 +96,5 @@ class CarProtectInjectedTests { "LazyProvide non support caching. Non should protect" ) } + } diff --git a/tests_wraps_kotlin/src/test/kotlin/com/github/klee0kai/stone/kotlin/test/car/muti/MultiCachedProvideTest.kt b/tests_wraps_kotlin/src/test/kotlin/com/github/klee0kai/stone/kotlin/test/car/muti/MultiCachedProvideTest.kt index 822948d3..bb4aa7cd 100644 --- a/tests_wraps_kotlin/src/test/kotlin/com/github/klee0kai/stone/kotlin/test/car/muti/MultiCachedProvideTest.kt +++ b/tests_wraps_kotlin/src/test/kotlin/com/github/klee0kai/stone/kotlin/test/car/muti/MultiCachedProvideTest.kt @@ -1,7 +1,6 @@ package com.github.klee0kai.stone.kotlin.test.car.muti -import com.github.klee0kai.stone.Stone -import com.github.klee0kai.test.car.di.lists.cached.CarMultiCachedComponent +import com.github.klee0kai.test.car.di.lists.cached.CarMultiCachedComponentStoneComponent import com.github.klee0kai.test.car.model.Bumper import com.github.klee0kai.test.car.model.Car import com.github.klee0kai.test.car.model.Wheel @@ -13,6 +12,7 @@ import org.junit.jupiter.api.BeforeEach import org.junit.jupiter.api.Test class MultiCachedProvideTest { + @BeforeEach fun init() { Bumper.createCount = 0 @@ -24,9 +24,7 @@ class MultiCachedProvideTest { @Test fun firstBumperFromCollection() { //Given - val DI = Stone.createComponent( - CarMultiCachedComponent::class.java - ) + val DI = CarMultiCachedComponentStoneComponent() //When assertEquals(0, Bumper.createCount) @@ -42,9 +40,7 @@ class MultiCachedProvideTest { @Test fun cachedBumperFromCollection() { //Given - val DI = Stone.createComponent( - CarMultiCachedComponent::class.java - ) + val DI = CarMultiCachedComponentStoneComponent() //When val bumperProvide = DI.singleBumper() @@ -62,9 +58,7 @@ class MultiCachedProvideTest { @Test fun fourWheelsAndSpare() { //Given - val DI = Stone.createComponent( - CarMultiCachedComponent::class.java - ) + val DI = CarMultiCachedComponentStoneComponent() //When assertEquals(0, Wheel.createCount) @@ -83,7 +77,7 @@ class MultiCachedProvideTest { @Test fun fourWheelsAndSpareCached() { //Given - val DI = Stone.createComponent(CarMultiCachedComponent::class.java) + val DI = CarMultiCachedComponentStoneComponent() //When val wheelsProviderList = DI.wheels() @@ -103,7 +97,7 @@ class MultiCachedProvideTest { @Test fun oneWheelFromList() { //Given - val DI = Stone.createComponent(CarMultiCachedComponent::class.java) + val DI = CarMultiCachedComponentStoneComponent() //When val wheel1 = DI.wheel() @@ -117,7 +111,7 @@ class MultiCachedProvideTest { @Test fun allWindowsInCar() { //Given - val DI = Stone.createComponent(CarMultiCachedComponent::class.java) + val DI = CarMultiCachedComponentStoneComponent() //When assertEquals(0, Window.createCount) @@ -135,7 +129,7 @@ class MultiCachedProvideTest { @Test fun allWindowsInCarFactory() { //Given - val DI = Stone.createComponent(CarMultiCachedComponent::class.java) + val DI = CarMultiCachedComponentStoneComponent() //When assertEquals(0, Window.createCount) @@ -153,7 +147,7 @@ class MultiCachedProvideTest { @Test fun allWindowsInCarProvideWrapper() { //Given - val DI = Stone.createComponent(CarMultiCachedComponent::class.java) + val DI = CarMultiCachedComponentStoneComponent() //When assertEquals(0, Window.createCount) @@ -172,7 +166,7 @@ class MultiCachedProvideTest { @Test fun createCarsWithDeps() { //Given - val DI = Stone.createComponent(CarMultiCachedComponent::class.java) + val DI = CarMultiCachedComponentStoneComponent() //When assertEquals(0, Car.createCount) @@ -197,7 +191,7 @@ class MultiCachedProvideTest { @Test fun cacheCreatedCar() { //Given - val DI = Stone.createComponent(CarMultiCachedComponent::class.java) + val DI = CarMultiCachedComponentStoneComponent() //When assertEquals(0, Car.createCount) diff --git a/tests_wraps_kotlin/src/test/kotlin/com/github/klee0kai/stone/kotlin/test/car/muti/MultiProvideTest.kt b/tests_wraps_kotlin/src/test/kotlin/com/github/klee0kai/stone/kotlin/test/car/muti/MultiProvideTest.kt index 29fa82a3..02b82bf1 100644 --- a/tests_wraps_kotlin/src/test/kotlin/com/github/klee0kai/stone/kotlin/test/car/muti/MultiProvideTest.kt +++ b/tests_wraps_kotlin/src/test/kotlin/com/github/klee0kai/stone/kotlin/test/car/muti/MultiProvideTest.kt @@ -1,7 +1,6 @@ package com.github.klee0kai.stone.kotlin.test.car.muti -import com.github.klee0kai.stone.Stone -import com.github.klee0kai.test.car.di.lists.factory.CarMultiComponent +import com.github.klee0kai.test.car.di.lists.factory.CarMultiComponentStoneComponent import com.github.klee0kai.test.car.model.Bumper import com.github.klee0kai.test.car.model.Car import com.github.klee0kai.test.car.model.Wheel @@ -11,6 +10,7 @@ import org.junit.jupiter.api.BeforeEach import org.junit.jupiter.api.Test class MultiProvideTest { + @BeforeEach fun init() { Bumper.createCount = 0 @@ -22,7 +22,7 @@ class MultiProvideTest { @Test fun firstBumperFromCollection() { //Given - val DI = Stone.createComponent(CarMultiComponent::class.java) + val DI = CarMultiComponentStoneComponent() //When assertEquals(0, Bumper.createCount) @@ -38,7 +38,7 @@ class MultiProvideTest { @Test fun factoryBumperFromCollection() { //Given - val DI = Stone.createComponent(CarMultiComponent::class.java) + val DI = CarMultiComponentStoneComponent() //When val bumperProvide = DI.singleBumper() @@ -56,7 +56,7 @@ class MultiProvideTest { @Test fun fourWheelsAndSpare() { //Given - val DI = Stone.createComponent(CarMultiComponent::class.java) + val DI = CarMultiComponentStoneComponent() //When assertEquals(0, Wheel.createCount) @@ -75,7 +75,7 @@ class MultiProvideTest { @Test fun fourWheelsAndSpareFactory() { //Given - val DI = Stone.createComponent(CarMultiComponent::class.java) + val DI = CarMultiComponentStoneComponent() //When val wheelsProviderList = DI.wheels() @@ -92,7 +92,7 @@ class MultiProvideTest { @Test fun oneWheelFromList() { //Given - val DI = Stone.createComponent(CarMultiComponent::class.java) + val DI = CarMultiComponentStoneComponent() //When val wheel1 = DI.wheel() @@ -106,7 +106,7 @@ class MultiProvideTest { @Test fun allWindowsInCar() { //Given - val DI = Stone.createComponent(CarMultiComponent::class.java) + val DI = CarMultiComponentStoneComponent() //When assertEquals(0, Window.createCount) @@ -124,7 +124,7 @@ class MultiProvideTest { @Test fun allWindowsInCarFactory() { //Given - val DI = Stone.createComponent(CarMultiComponent::class.java) + val DI = CarMultiComponentStoneComponent() //When assertEquals(0, Window.createCount) @@ -142,7 +142,7 @@ class MultiProvideTest { @Test fun allWindowsInCarProvideWrapper() { //Given - val DI = Stone.createComponent(CarMultiComponent::class.java) + val DI = CarMultiComponentStoneComponent() //When assertEquals(0, Window.createCount) @@ -158,45 +158,46 @@ class MultiProvideTest { assertEquals(4, windowUuid.size) } - @Test - fun createCarsWithDeps() { - //Given - val DI = Stone.createComponent(CarMultiComponent::class.java) - - //When - assertEquals(0, Car.createCount) - val car = DI.cars() - - //Then - assertEquals(2, Car.createCount) - assertNotEquals(car!![0]!!.uuid, car[1]!!.uuid) - assertNotNull(car[0]!!.bumpers) - assertNotNull(car[0]!!.wheels) - assertNotNull(car[0]!!.windows) - assertNotNull(car[1]!!.bumpers) - assertNotNull(car[1]!!.wheels) - assertNotNull(car[1]!!.windows) - assertNotEquals( - car[0]!!.windows!!.size, - car[1]!!.windows!!.size, - "Red use single deps and Blue car use listed deps" - ) - } - - @Test - fun factoryCreatedCar() { - //Given - val DI = Stone.createComponent(CarMultiComponent::class.java) - - //When - assertEquals(0, Car.createCount) - val car1 = DI.cars() - val car2 = DI.cars() - - //Then - assertEquals(4, Car.createCount) - assertEquals(car1!!.size, car2!!.size) - assertNotEquals(car1[0]!!.uuid, car2[0]!!.uuid) - assertNotEquals(car1[1]!!.uuid, car2[1]!!.uuid) - } +// TODO The behavior is not obvious. We plan to redo it. +// @Test +// fun createCarsWithDeps() { +// //Given +// val DI = CarMultiComponentStoneComponent() +// +// //When +// assertEquals(0, Car.createCount) +// val car = DI.cars() +// +// //Then +// assertEquals(2, Car.createCount) +// assertNotEquals(car!![0]!!.uuid, car[1]!!.uuid) +// assertNotNull(car[0]!!.bumpers) +// assertNotNull(car[0]!!.wheels) +// assertNotNull(car[0]!!.windows) +// assertNotNull(car[1]!!.bumpers) +// assertNotNull(car[1]!!.wheels) +// assertNotNull(car[1]!!.windows) +// assertNotEquals( +// car[0]!!.windows!!.size, +// car[1]!!.windows!!.size, +// "Red use single deps and Blue car use listed deps" +// ) +// } +// +// @Test +// fun factoryCreatedCar() { +// //Given +// val DI = CarMultiComponentStoneComponent() +// +// //When +// assertEquals(0, Car.createCount) +// val car1 = DI.cars() +// val car2 = DI.cars() +// +// //Then +// assertEquals(4, Car.createCount) +// assertEquals(car1!!.size, car2!!.size) +// assertNotEquals(car1[0]!!.uuid, car2[0]!!.uuid) +// assertNotEquals(car1[1]!!.uuid, car2[1]!!.uuid) +// } } diff --git a/tests_wraps_kotlin/src/test/kotlin/com/github/klee0kai/stone/kotlin/test/car/qualifiers/CarInjectAllMethodsWithQualifiersTest.kt b/tests_wraps_kotlin/src/test/kotlin/com/github/klee0kai/stone/kotlin/test/car/qualifiers/CarInjectAllMethodsWithQualifiersTest.kt index 37a9f301..c6d915e0 100644 --- a/tests_wraps_kotlin/src/test/kotlin/com/github/klee0kai/stone/kotlin/test/car/qualifiers/CarInjectAllMethodsWithQualifiersTest.kt +++ b/tests_wraps_kotlin/src/test/kotlin/com/github/klee0kai/stone/kotlin/test/car/qualifiers/CarInjectAllMethodsWithQualifiersTest.kt @@ -1,17 +1,17 @@ package com.github.klee0kai.stone.kotlin.test.car.qualifiers -import com.github.klee0kai.stone.Stone -import com.github.klee0kai.test.car.di.qualifiers.CarQComponent +import com.github.klee0kai.test.car.di.qualifiers.CarQComponentStoneComponent import com.github.klee0kai.test.car.model.Car import com.github.klee0kai.test.car.model.CarsInjectQualifiers import org.junit.jupiter.api.Assertions.assertEquals import org.junit.jupiter.api.Test class CarInjectAllMethodsWithQualifiersTest { + @Test fun namedEmptyProvideTest() { //Given - val DI = Stone.createComponent(CarQComponent::class.java) + val DI = CarQComponentStoneComponent() val carInject = CarsInjectQualifiers() //When @@ -28,9 +28,7 @@ class CarInjectAllMethodsWithQualifiersTest { @Test fun namedAProvideTest() { //Given - val DI = Stone.createComponent( - CarQComponent::class.java - ) + val DI = CarQComponentStoneComponent() val carInject = CarsInjectQualifiers() //When @@ -47,7 +45,7 @@ class CarInjectAllMethodsWithQualifiersTest { @Test fun carMyQualifierProvideTest() { //Given - val DI = Stone.createComponent(CarQComponent::class.java) + val DI = CarQComponentStoneComponent() val carInject = CarsInjectQualifiers() //When @@ -65,7 +63,7 @@ class CarInjectAllMethodsWithQualifiersTest { @Test fun carMyQualifierStringProvideTest() { //Given - val DI = Stone.createComponent(CarQComponent::class.java) + val DI = CarQComponentStoneComponent() val carInject = CarsInjectQualifiers() //When @@ -82,7 +80,7 @@ class CarInjectAllMethodsWithQualifiersTest { @Test fun carMyQualifierStringAProvideTest() { //Given - val DI = Stone.createComponent(CarQComponent::class.java) + val DI = CarQComponentStoneComponent() val carInject = CarsInjectQualifiers() //When @@ -99,7 +97,7 @@ class CarInjectAllMethodsWithQualifiersTest { @Test fun carMyQualifierStringBProvideTest() { //Given - val DI = Stone.createComponent(CarQComponent::class.java) + val DI = CarQComponentStoneComponent() val carInject = CarsInjectQualifiers() //When @@ -116,7 +114,7 @@ class CarInjectAllMethodsWithQualifiersTest { @Test fun carMyQualifierMultiProvideTest() { //Given - val DI = Stone.createComponent(CarQComponent::class.java) + val DI = CarQComponentStoneComponent() val carInject = CarsInjectQualifiers() //When @@ -133,7 +131,7 @@ class CarInjectAllMethodsWithQualifiersTest { @Test fun carMyQualifierMultiA1ProvideTest() { //Given - val DI = Stone.createComponent(CarQComponent::class.java) + val DI = CarQComponentStoneComponent() val carInject = CarsInjectQualifiers() //When @@ -150,7 +148,7 @@ class CarInjectAllMethodsWithQualifiersTest { @Test fun carMyQualifierMultiA2ProvideTest() { //Given - val DI = Stone.createComponent(CarQComponent::class.java) + val DI = CarQComponentStoneComponent() val carInject = CarsInjectQualifiers() //When @@ -167,7 +165,7 @@ class CarInjectAllMethodsWithQualifiersTest { @Test fun carMyQualifierMultiA2HardProvideTest() { //Given - val DI = Stone.createComponent(CarQComponent::class.java) + val DI = CarQComponentStoneComponent() val carInject = CarsInjectQualifiers() //When @@ -184,7 +182,7 @@ class CarInjectAllMethodsWithQualifiersTest { @Test fun allCarsProvideTest() { //Given - val DI = Stone.createComponent(CarQComponent::class.java) + val DI = CarQComponentStoneComponent() val carInject = CarsInjectQualifiers() //When diff --git a/tests_wraps_kotlin/src/test/kotlin/com/github/klee0kai/stone/kotlin/test/car/qualifiers/CarInjectAllWithQualifiersTest.kt b/tests_wraps_kotlin/src/test/kotlin/com/github/klee0kai/stone/kotlin/test/car/qualifiers/CarInjectAllWithQualifiersTest.kt index df34b80f..86e75083 100644 --- a/tests_wraps_kotlin/src/test/kotlin/com/github/klee0kai/stone/kotlin/test/car/qualifiers/CarInjectAllWithQualifiersTest.kt +++ b/tests_wraps_kotlin/src/test/kotlin/com/github/klee0kai/stone/kotlin/test/car/qualifiers/CarInjectAllWithQualifiersTest.kt @@ -1,17 +1,17 @@ package com.github.klee0kai.stone.kotlin.test.car.qualifiers -import com.github.klee0kai.stone.Stone -import com.github.klee0kai.test.car.di.qualifiers.CarQComponent +import com.github.klee0kai.test.car.di.qualifiers.CarQComponentStoneComponent import com.github.klee0kai.test.car.model.Car import com.github.klee0kai.test.car.model.CarsInjectQualifiers import org.junit.jupiter.api.Assertions.assertEquals import org.junit.jupiter.api.Test class CarInjectAllWithQualifiersTest { + @Test fun namedEmptyProvideTest() { //Given - val DI = Stone.createComponent(CarQComponent::class.java) + val DI = CarQComponentStoneComponent() val carInject = CarsInjectQualifiers() //When @@ -28,7 +28,7 @@ class CarInjectAllWithQualifiersTest { @Test fun namedAProvideTest() { //Given - val DI = Stone.createComponent(CarQComponent::class.java) + val DI = CarQComponentStoneComponent() val carInject = CarsInjectQualifiers() //When @@ -45,7 +45,7 @@ class CarInjectAllWithQualifiersTest { @Test fun carMyQualifierProvideTest() { //Given - val DI = Stone.createComponent(CarQComponent::class.java) + val DI = CarQComponentStoneComponent() val carInject = CarsInjectQualifiers() //When @@ -62,7 +62,7 @@ class CarInjectAllWithQualifiersTest { @Test fun carMyQualifierStringProvideTest() { //Given - val DI = Stone.createComponent(CarQComponent::class.java) + val DI = CarQComponentStoneComponent() val carInject = CarsInjectQualifiers() //When @@ -79,7 +79,7 @@ class CarInjectAllWithQualifiersTest { @Test fun carMyQualifierStringAProvideTest() { //Given - val DI = Stone.createComponent(CarQComponent::class.java) + val DI = CarQComponentStoneComponent() val carInject = CarsInjectQualifiers() //When @@ -96,7 +96,7 @@ class CarInjectAllWithQualifiersTest { @Test fun carMyQualifierStringBProvideTest() { //Given - val DI = Stone.createComponent(CarQComponent::class.java) + val DI = CarQComponentStoneComponent() val carInject = CarsInjectQualifiers() //When @@ -113,7 +113,7 @@ class CarInjectAllWithQualifiersTest { @Test fun carMyQualifierMultiProvideTest() { //Given - val DI = Stone.createComponent(CarQComponent::class.java) + val DI = CarQComponentStoneComponent() val carInject = CarsInjectQualifiers() //When @@ -130,7 +130,7 @@ class CarInjectAllWithQualifiersTest { @Test fun carMyQualifierMultiA1ProvideTest() { //Given - val DI = Stone.createComponent(CarQComponent::class.java) + val DI = CarQComponentStoneComponent() val carInject = CarsInjectQualifiers() //When @@ -147,7 +147,7 @@ class CarInjectAllWithQualifiersTest { @Test fun carMyQualifierMultiA2ProvideTest() { //Given - val DI = Stone.createComponent(CarQComponent::class.java) + val DI = CarQComponentStoneComponent() val carInject = CarsInjectQualifiers() //When @@ -164,7 +164,7 @@ class CarInjectAllWithQualifiersTest { @Test fun carMyQualifierMultiA2HardProvideTest() { //Given - val DI = Stone.createComponent(CarQComponent::class.java) + val DI = CarQComponentStoneComponent() val carInject = CarsInjectQualifiers() //When @@ -181,7 +181,7 @@ class CarInjectAllWithQualifiersTest { @Test fun allCarsProvideTest() { //Given - val DI = Stone.createComponent(CarQComponent::class.java) + val DI = CarQComponentStoneComponent() val carInject = CarsInjectQualifiers() //When diff --git a/tests_wraps_kotlin/src/test/kotlin/com/github/klee0kai/stone/kotlin/test/car/qualifiers/CarInjectMethodWithQualifiersTest.kt b/tests_wraps_kotlin/src/test/kotlin/com/github/klee0kai/stone/kotlin/test/car/qualifiers/CarInjectMethodWithQualifiersTest.kt index 73f0365f..e100bb94 100644 --- a/tests_wraps_kotlin/src/test/kotlin/com/github/klee0kai/stone/kotlin/test/car/qualifiers/CarInjectMethodWithQualifiersTest.kt +++ b/tests_wraps_kotlin/src/test/kotlin/com/github/klee0kai/stone/kotlin/test/car/qualifiers/CarInjectMethodWithQualifiersTest.kt @@ -1,16 +1,16 @@ package com.github.klee0kai.stone.kotlin.test.car.qualifiers -import com.github.klee0kai.stone.Stone -import com.github.klee0kai.test.car.di.qualifiers.CarQComponent +import com.github.klee0kai.test.car.di.qualifiers.CarQComponentStoneComponent import com.github.klee0kai.test.car.model.CarsInjectQualifiers import org.junit.jupiter.api.Assertions.assertEquals import org.junit.jupiter.api.Test class CarInjectMethodWithQualifiersTest { + @Test fun namedEmptyProvideTest() { //Given - val DI = Stone.createComponent(CarQComponent::class.java) + val DI = CarQComponentStoneComponent() val carInject = CarsInjectQualifiers() //When @@ -26,7 +26,7 @@ class CarInjectMethodWithQualifiersTest { @Test fun namedAProvideTest() { //Given - val DI = Stone.createComponent(CarQComponent::class.java) + val DI = CarQComponentStoneComponent() val carInject = CarsInjectQualifiers() //When @@ -42,7 +42,7 @@ class CarInjectMethodWithQualifiersTest { @Test fun carMyQualifierProvideTest() { //Given - val DI = Stone.createComponent(CarQComponent::class.java) + val DI = CarQComponentStoneComponent() val carInject = CarsInjectQualifiers() //When @@ -58,7 +58,7 @@ class CarInjectMethodWithQualifiersTest { @Test fun carMyQualifierStringProvideTest() { //Given - val DI = Stone.createComponent(CarQComponent::class.java) + val DI = CarQComponentStoneComponent() val carInject = CarsInjectQualifiers() //When @@ -74,7 +74,7 @@ class CarInjectMethodWithQualifiersTest { @Test fun carMyQualifierStringAProvideTest() { //Given - val DI = Stone.createComponent(CarQComponent::class.java) + val DI = CarQComponentStoneComponent() val carInject = CarsInjectQualifiers() //When @@ -90,7 +90,7 @@ class CarInjectMethodWithQualifiersTest { @Test fun carMyQualifierStringBProvideTest() { //Given - val DI = Stone.createComponent(CarQComponent::class.java) + val DI = CarQComponentStoneComponent() val carInject = CarsInjectQualifiers() //When @@ -106,7 +106,7 @@ class CarInjectMethodWithQualifiersTest { @Test fun carMyQualifierMultiProvideTest() { //Given - val DI = Stone.createComponent(CarQComponent::class.java) + val DI = CarQComponentStoneComponent() val carInject = CarsInjectQualifiers() //When @@ -122,7 +122,7 @@ class CarInjectMethodWithQualifiersTest { @Test fun carMyQualifierMultiA1ProvideTest() { //Given - val DI = Stone.createComponent(CarQComponent::class.java) + val DI = CarQComponentStoneComponent() val carInject = CarsInjectQualifiers() //When @@ -138,7 +138,7 @@ class CarInjectMethodWithQualifiersTest { @Test fun carMyQualifierMultiA2ProvideTest() { //Given - val DI = Stone.createComponent(CarQComponent::class.java) + val DI = CarQComponentStoneComponent() val carInject = CarsInjectQualifiers() //When @@ -154,7 +154,7 @@ class CarInjectMethodWithQualifiersTest { @Test fun carMyQualifierMultiA2HardProvideTest() { //Given - val DI = Stone.createComponent(CarQComponent::class.java) + val DI = CarQComponentStoneComponent() val carInject = CarsInjectQualifiers() //When @@ -170,7 +170,7 @@ class CarInjectMethodWithQualifiersTest { @Test fun allCarsProvideTest() { //Given - val DI = Stone.createComponent(CarQComponent::class.java) + val DI = CarQComponentStoneComponent() val carInject = CarsInjectQualifiers() //When @@ -195,7 +195,7 @@ class CarInjectMethodWithQualifiersTest { @Test fun provideCarsNamedEmptyTest() { //Given - val DI = Stone.createComponent(CarQComponent::class.java) + val DI = CarQComponentStoneComponent() val carInject = CarsInjectQualifiers() //When @@ -209,7 +209,7 @@ class CarInjectMethodWithQualifiersTest { @Test fun carsMyQualifierMultiA2HardTest() { //Given - val DI = Stone.createComponent(CarQComponent::class.java) + val DI = CarQComponentStoneComponent() val carInject = CarsInjectQualifiers() //When diff --git a/tests_wraps_kotlin/src/test/kotlin/com/github/klee0kai/stone/kotlin/test/car/qualifiers/CarInjectWithQualifiersTest.kt b/tests_wraps_kotlin/src/test/kotlin/com/github/klee0kai/stone/kotlin/test/car/qualifiers/CarInjectWithQualifiersTest.kt index 1b2311c4..c7941508 100644 --- a/tests_wraps_kotlin/src/test/kotlin/com/github/klee0kai/stone/kotlin/test/car/qualifiers/CarInjectWithQualifiersTest.kt +++ b/tests_wraps_kotlin/src/test/kotlin/com/github/klee0kai/stone/kotlin/test/car/qualifiers/CarInjectWithQualifiersTest.kt @@ -1,16 +1,16 @@ package com.github.klee0kai.stone.kotlin.test.car.qualifiers -import com.github.klee0kai.stone.Stone -import com.github.klee0kai.test.car.di.qualifiers.CarQComponent +import com.github.klee0kai.test.car.di.qualifiers.CarQComponentStoneComponent import com.github.klee0kai.test.car.model.CarsInjectQualifiers import org.junit.jupiter.api.Assertions.assertEquals import org.junit.jupiter.api.Test class CarInjectWithQualifiersTest { + @Test fun namedEmptyProvideTest() { //Given - val DI = Stone.createComponent(CarQComponent::class.java) + val DI = CarQComponentStoneComponent() val carInject = CarsInjectQualifiers() //When @@ -26,7 +26,7 @@ class CarInjectWithQualifiersTest { @Test fun namedAProvideTest() { //Given - val DI = Stone.createComponent(CarQComponent::class.java) + val DI = CarQComponentStoneComponent() val carInject = CarsInjectQualifiers() //When @@ -42,7 +42,7 @@ class CarInjectWithQualifiersTest { @Test fun carMyQualifierProvideTest() { //Given - val DI = Stone.createComponent(CarQComponent::class.java) + val DI = CarQComponentStoneComponent() val carInject = CarsInjectQualifiers() //When @@ -58,7 +58,7 @@ class CarInjectWithQualifiersTest { @Test fun carMyQualifierStringProvideTest() { //Given - val DI = Stone.createComponent(CarQComponent::class.java) + val DI = CarQComponentStoneComponent() val carInject = CarsInjectQualifiers() //When @@ -74,7 +74,7 @@ class CarInjectWithQualifiersTest { @Test fun carMyQualifierStringAProvideTest() { //Given - val DI = Stone.createComponent(CarQComponent::class.java) + val DI = CarQComponentStoneComponent() val carInject = CarsInjectQualifiers() //When @@ -90,7 +90,7 @@ class CarInjectWithQualifiersTest { @Test fun carMyQualifierStringBProvideTest() { //Given - val DI = Stone.createComponent(CarQComponent::class.java) + val DI = CarQComponentStoneComponent() val carInject = CarsInjectQualifiers() //When @@ -106,7 +106,7 @@ class CarInjectWithQualifiersTest { @Test fun carMyQualifierMultiProvideTest() { //Given - val DI = Stone.createComponent(CarQComponent::class.java) + val DI = CarQComponentStoneComponent() val carInject = CarsInjectQualifiers() //When @@ -122,7 +122,7 @@ class CarInjectWithQualifiersTest { @Test fun carMyQualifierMultiA1ProvideTest() { //Given - val DI = Stone.createComponent(CarQComponent::class.java) + val DI = CarQComponentStoneComponent() val carInject = CarsInjectQualifiers() //When @@ -138,7 +138,7 @@ class CarInjectWithQualifiersTest { @Test fun carMyQualifierMultiA2ProvideTest() { //Given - val DI = Stone.createComponent(CarQComponent::class.java) + val DI = CarQComponentStoneComponent() val carInject = CarsInjectQualifiers() //When @@ -154,7 +154,7 @@ class CarInjectWithQualifiersTest { @Test fun carMyQualifierMultiA2HardProvideTest() { //Given - val DI = Stone.createComponent(CarQComponent::class.java) + val DI = CarQComponentStoneComponent() val carInject = CarsInjectQualifiers() //When @@ -170,7 +170,7 @@ class CarInjectWithQualifiersTest { @Test fun allCarsProvideTest() { //Given - val DI = Stone.createComponent(CarQComponent::class.java) + val DI = CarQComponentStoneComponent() val carInject = CarsInjectQualifiers() //When @@ -195,7 +195,7 @@ class CarInjectWithQualifiersTest { @Test fun provideCarsNamedEmptyTest() { //Given - val DI = Stone.createComponent(CarQComponent::class.java) + val DI = CarQComponentStoneComponent() val carInject = CarsInjectQualifiers() //When @@ -209,7 +209,7 @@ class CarInjectWithQualifiersTest { @Test fun carsMyQualifierMultiA2HardTest() { //Given - val DI = Stone.createComponent(CarQComponent::class.java) + val DI = CarQComponentStoneComponent() val carInject = CarsInjectQualifiers() //When diff --git a/tests_wraps_kotlin/src/test/kotlin/com/github/klee0kai/stone/kotlin/test/car/qualifiers/CarProvideAllWithQualifiersTests.kt b/tests_wraps_kotlin/src/test/kotlin/com/github/klee0kai/stone/kotlin/test/car/qualifiers/CarProvideAllWithQualifiersTests.kt index d73e0adc..6d008be7 100644 --- a/tests_wraps_kotlin/src/test/kotlin/com/github/klee0kai/stone/kotlin/test/car/qualifiers/CarProvideAllWithQualifiersTests.kt +++ b/tests_wraps_kotlin/src/test/kotlin/com/github/klee0kai/stone/kotlin/test/car/qualifiers/CarProvideAllWithQualifiersTests.kt @@ -1,16 +1,16 @@ package com.github.klee0kai.stone.kotlin.test.car.qualifiers -import com.github.klee0kai.stone.Stone -import com.github.klee0kai.test.car.di.qualifiers.CarQComponent +import com.github.klee0kai.test.car.di.qualifiers.CarQComponentStoneComponent import com.github.klee0kai.test.car.model.Car import org.junit.jupiter.api.Assertions.assertEquals import org.junit.jupiter.api.Test class CarProvideAllWithQualifiersTests { + @Test fun namedEmptyProvideTest() { //Given - val DI = Stone.createComponent(CarQComponent::class.java) + val DI = CarQComponentStoneComponent() val cars = DI.allCars() //When @@ -26,7 +26,7 @@ class CarProvideAllWithQualifiersTests { @Test fun namedAProvideTest() { //Given - val DI = Stone.createComponent(CarQComponent::class.java) + val DI = CarQComponentStoneComponent() val cars = DI.allCars() //When @@ -42,7 +42,7 @@ class CarProvideAllWithQualifiersTests { @Test fun carMyQualifierProvideTest() { //Given - val DI = Stone.createComponent(CarQComponent::class.java) + val DI = CarQComponentStoneComponent() val cars = DI.allCars() //When @@ -58,7 +58,7 @@ class CarProvideAllWithQualifiersTests { @Test fun carMyQualifierStringProvideTest() { //Given - val DI = Stone.createComponent(CarQComponent::class.java) + val DI = CarQComponentStoneComponent() val cars = DI.allCars() //When @@ -74,7 +74,7 @@ class CarProvideAllWithQualifiersTests { @Test fun carMyQualifierStringAProvideTest() { //Given - val DI = Stone.createComponent(CarQComponent::class.java) + val DI = CarQComponentStoneComponent() val cars = DI.allCars() //When @@ -90,7 +90,7 @@ class CarProvideAllWithQualifiersTests { @Test fun carMyQualifierStringBProvideTest() { //Given - val DI = Stone.createComponent(CarQComponent::class.java) + val DI = CarQComponentStoneComponent() val cars = DI.allCars() //When @@ -106,7 +106,7 @@ class CarProvideAllWithQualifiersTests { @Test fun carMyQualifierMultiProvideTest() { //Given - val DI = Stone.createComponent(CarQComponent::class.java) + val DI = CarQComponentStoneComponent() val cars = DI.allCars() //When @@ -122,7 +122,7 @@ class CarProvideAllWithQualifiersTests { @Test fun carMyQualifierMultiA1ProvideTest() { //Given - val DI = Stone.createComponent(CarQComponent::class.java) + val DI = CarQComponentStoneComponent() val cars = DI.allCars() //When @@ -138,7 +138,7 @@ class CarProvideAllWithQualifiersTests { @Test fun carMyQualifierMultiA2ProvideTest() { //Given - val DI = Stone.createComponent(CarQComponent::class.java) + val DI = CarQComponentStoneComponent() val cars = DI.allCars() //When @@ -154,7 +154,7 @@ class CarProvideAllWithQualifiersTests { @Test fun carMyQualifierMultiA2HardProvideTest() { //Given - val DI = Stone.createComponent(CarQComponent::class.java) + val DI = CarQComponentStoneComponent() val cars = DI.allCars() //When @@ -170,7 +170,7 @@ class CarProvideAllWithQualifiersTests { @Test fun allCarsProvideTest() { //Given - val DI = Stone.createComponent(CarQComponent::class.java) + val DI = CarQComponentStoneComponent() //When val cars = DI.allCars() diff --git a/tests_wraps_kotlin/src/test/kotlin/com/github/klee0kai/stone/kotlin/test/car/qualifiers/CarProvideWithQualifiersTests.kt b/tests_wraps_kotlin/src/test/kotlin/com/github/klee0kai/stone/kotlin/test/car/qualifiers/CarProvideWithQualifiersTests.kt index 96a5a704..b5d658fd 100644 --- a/tests_wraps_kotlin/src/test/kotlin/com/github/klee0kai/stone/kotlin/test/car/qualifiers/CarProvideWithQualifiersTests.kt +++ b/tests_wraps_kotlin/src/test/kotlin/com/github/klee0kai/stone/kotlin/test/car/qualifiers/CarProvideWithQualifiersTests.kt @@ -1,15 +1,15 @@ package com.github.klee0kai.stone.kotlin.test.car.qualifiers -import com.github.klee0kai.stone.Stone -import com.github.klee0kai.test.car.di.qualifiers.CarQComponent +import com.github.klee0kai.test.car.di.qualifiers.CarQComponentStoneComponent import org.junit.jupiter.api.Assertions.assertEquals import org.junit.jupiter.api.Test class CarProvideWithQualifiersTests { + @Test fun namedEmptyProvideTest() { //Given - val DI = Stone.createComponent(CarQComponent::class.java) + val DI = CarQComponentStoneComponent() //When val car = DI.carNamedEmpty() @@ -23,7 +23,7 @@ class CarProvideWithQualifiersTests { @Test fun namedAProvideTest() { //Given - val DI = Stone.createComponent(CarQComponent::class.java) + val DI = CarQComponentStoneComponent() //When val car = DI.carNameA() @@ -37,7 +37,7 @@ class CarProvideWithQualifiersTests { @Test fun carMyQualifierProvideTest() { //Given - val DI = Stone.createComponent(CarQComponent::class.java) + val DI = CarQComponentStoneComponent() //When val car = DI.carMyQualifier() @@ -51,7 +51,7 @@ class CarProvideWithQualifiersTests { @Test fun carMyQualifierStringProvideTest() { //Given - val DI = Stone.createComponent(CarQComponent::class.java) + val DI = CarQComponentStoneComponent() //When val car = DI.carMyQualifierString() @@ -65,7 +65,7 @@ class CarProvideWithQualifiersTests { @Test fun carMyQualifierStringAProvideTest() { //Given - val DI = Stone.createComponent(CarQComponent::class.java) + val DI = CarQComponentStoneComponent() //When val car = DI.carMyQualifierStringA() @@ -79,7 +79,7 @@ class CarProvideWithQualifiersTests { @Test fun carMyQualifierStringBProvideTest() { //Given - val DI = Stone.createComponent(CarQComponent::class.java) + val DI = CarQComponentStoneComponent() //When val car = DI.carMyQualifierStringB() @@ -93,7 +93,7 @@ class CarProvideWithQualifiersTests { @Test fun carMyQualifierMultiProvideTest() { //Given - val DI = Stone.createComponent(CarQComponent::class.java) + val DI = CarQComponentStoneComponent() //When val car = DI.carMyQualifierMulti() @@ -107,7 +107,7 @@ class CarProvideWithQualifiersTests { @Test fun carMyQualifierMultiA1ProvideTest() { //Given - val DI = Stone.createComponent(CarQComponent::class.java) + val DI = CarQComponentStoneComponent() //When val car = DI.carMyQualifierMultiA1() @@ -121,7 +121,7 @@ class CarProvideWithQualifiersTests { @Test fun carMyQualifierMultiA2ProvideTest() { //Given - val DI = Stone.createComponent(CarQComponent::class.java) + val DI = CarQComponentStoneComponent() //When val car = DI.carMyQualifierMultiA2() @@ -135,7 +135,7 @@ class CarProvideWithQualifiersTests { @Test fun carMyQualifierMultiA2HardProvideTest() { //Given - val DI = Stone.createComponent(CarQComponent::class.java) + val DI = CarQComponentStoneComponent() //When val car = DI.carMyQualifierMultiA2Hard() diff --git a/tests_wraps_kotlin/src/test/kotlin/com/github/klee0kai/stone/kotlin/test/car/wrapper/CarSingleWrapperTests.kt b/tests_wraps_kotlin/src/test/kotlin/com/github/klee0kai/stone/kotlin/test/car/wrapper/CarSingleWrapperTests.kt index 65260d3f..f98b968e 100644 --- a/tests_wraps_kotlin/src/test/kotlin/com/github/klee0kai/stone/kotlin/test/car/wrapper/CarSingleWrapperTests.kt +++ b/tests_wraps_kotlin/src/test/kotlin/com/github/klee0kai/stone/kotlin/test/car/wrapper/CarSingleWrapperTests.kt @@ -1,17 +1,18 @@ package com.github.klee0kai.stone.kotlin.test.car.wrapper -import com.github.klee0kai.stone.Stone -import com.github.klee0kai.test.car.di.wrapped.create.CarWrappedCreateComponent +import com.github.klee0kai.test.car.di.wrapped.create.CarWrappedCreateComponentStoneComponent import com.github.klee0kai.test.car.model.Bumper import com.github.klee0kai.test.car.model.Car import com.github.klee0kai.test.car.model.Wheel import com.github.klee0kai.test.car.model.Window +import kotlinx.coroutines.runBlocking import org.junit.jupiter.api.Assertions.assertEquals import org.junit.jupiter.api.Assertions.assertNotNull import org.junit.jupiter.api.BeforeEach import org.junit.jupiter.api.Test class CarSingleWrapperTests { + @BeforeEach fun init() { Bumper.createCount = 0 @@ -23,7 +24,7 @@ class CarSingleWrapperTests { @Test fun wheelSimpleTest() { //Given - val DI = Stone.createComponent(CarWrappedCreateComponent::class.java) + val DI = CarWrappedCreateComponentStoneComponent() //When val wheel1 = DI.wheel() @@ -38,7 +39,7 @@ class CarSingleWrapperTests { @Test fun wheelProvideTest() { //Given - val DI = Stone.createComponent(CarWrappedCreateComponent::class.java) + val DI = CarWrappedCreateComponentStoneComponent() //When val wheel1 = DI.wheelProvide() @@ -53,7 +54,7 @@ class CarSingleWrapperTests { @Test fun wheelLazyTest() { //Given - val DI = Stone.createComponent(CarWrappedCreateComponent::class.java) + val DI = CarWrappedCreateComponentStoneComponent() //When val wheel1 = DI.wheelLazy() @@ -68,7 +69,7 @@ class CarSingleWrapperTests { @Test fun wheelWeakTest() { //Given - val DI = Stone.createComponent(CarWrappedCreateComponent::class.java) + val DI = CarWrappedCreateComponentStoneComponent() //When val wheel1 = DI.wheelWeak() @@ -83,7 +84,7 @@ class CarSingleWrapperTests { @Test fun wheelProvideWeakTest() { //Given - val DI = Stone.createComponent(CarWrappedCreateComponent::class.java) + val DI = CarWrappedCreateComponentStoneComponent() //When val wheel1 = DI.whellProviderWeak() @@ -98,7 +99,7 @@ class CarSingleWrapperTests { @Test fun wheelLazyProvideWeakTest() { //Given - val DI = Stone.createComponent(CarWrappedCreateComponent::class.java) + val DI = CarWrappedCreateComponentStoneComponent() //When val wheel1 = DI.whellLazyProviderWeak() @@ -116,7 +117,7 @@ class CarSingleWrapperTests { @Test fun wheelProviderTest() { //Given - val DI = Stone.createComponent(CarWrappedCreateComponent::class.java) + val DI = CarWrappedCreateComponentStoneComponent() //When val wheel1 = DI.whellProvider() @@ -131,7 +132,7 @@ class CarSingleWrapperTests { @Test fun carLazyTest() { //Given - val DI = Stone.createComponent(CarWrappedCreateComponent::class.java) + val DI = CarWrappedCreateComponentStoneComponent() //When val car1 = DI.carLazy() @@ -145,9 +146,9 @@ class CarSingleWrapperTests { } @Test - fun carAsyncTest() { + fun carAsyncTest() = runBlocking { //Given - val DI = Stone.createComponent(CarWrappedCreateComponent::class.java) + val DI = CarWrappedCreateComponentStoneComponent() //When val car1 = DI.carAsync() @@ -162,7 +163,7 @@ class CarSingleWrapperTests { @Test fun carProvideTest() { //Given - val DI = Stone.createComponent(CarWrappedCreateComponent::class.java) + val DI = CarWrappedCreateComponentStoneComponent() //When val car1 = DI.carProvider() @@ -178,7 +179,7 @@ class CarSingleWrapperTests { @Test fun carWeakTest() { //Given - val DI = Stone.createComponent(CarWrappedCreateComponent::class.java) + val DI = CarWrappedCreateComponentStoneComponent() //When val car1 = DI.carWeak() @@ -193,7 +194,7 @@ class CarSingleWrapperTests { @Test fun windowTest() { //Given - val DI = Stone.createComponent(CarWrappedCreateComponent::class.java) + val DI = CarWrappedCreateComponentStoneComponent() //When val window1 = DI.window() @@ -208,7 +209,7 @@ class CarSingleWrapperTests { @Test fun carTest() { //Given - val DI = Stone.createComponent(CarWrappedCreateComponent::class.java) + val DI = CarWrappedCreateComponentStoneComponent() //When val car1 = DI.car() diff --git a/tests_wraps_kotlin/src/test/kotlin/com/github/klee0kai/stone/kotlin/test/car/wrapper/CurCustomWrapperTests.kt b/tests_wraps_kotlin/src/test/kotlin/com/github/klee0kai/stone/kotlin/test/car/wrapper/CurCustomWrapperTests.kt index 300ed1fb..c616b49b 100644 --- a/tests_wraps_kotlin/src/test/kotlin/com/github/klee0kai/stone/kotlin/test/car/wrapper/CurCustomWrapperTests.kt +++ b/tests_wraps_kotlin/src/test/kotlin/com/github/klee0kai/stone/kotlin/test/car/wrapper/CurCustomWrapperTests.kt @@ -1,7 +1,6 @@ package com.github.klee0kai.stone.kotlin.test.car.wrapper -import com.github.klee0kai.stone.Stone -import com.github.klee0kai.test.car.di.wrapped.custom.CarCustomWrappersComponent +import com.github.klee0kai.test.car.di.wrapped.custom.CarCustomWrappersComponentStoneComponent import com.github.klee0kai.test.car.model.Car import org.junit.jupiter.api.Assertions.* import org.junit.jupiter.api.BeforeEach @@ -16,7 +15,7 @@ class CurCustomWrapperTests { @Test fun carTest() { //Given - val DI = Stone.createComponent(CarCustomWrappersComponent::class.java) + val DI = CarCustomWrappersComponentStoneComponent() //When val car1 = DI.car() @@ -31,7 +30,7 @@ class CurCustomWrapperTests { @Test fun carLayTest() { //Given - val DI = Stone.createComponent(CarCustomWrappersComponent::class.java) + val DI = CarCustomWrappersComponentStoneComponent() //When val car1 = DI.carLazy() @@ -48,7 +47,7 @@ class CurCustomWrapperTests { @Test fun carProvideTest() { //Given - val DI = Stone.createComponent(CarCustomWrappersComponent::class.java) + val DI = CarCustomWrappersComponentStoneComponent() //When val car1 = DI.carProvide() @@ -65,7 +64,7 @@ class CurCustomWrapperTests { @Test fun carRefTest() { //Given - val DI = Stone.createComponent(CarCustomWrappersComponent::class.java) + val DI = CarCustomWrappersComponentStoneComponent() //When val car1 = DI.carRef() From 0d677cd57766bdaaaebdca765b12479669c74148 Mon Sep 17 00:00:00 2001 From: klee0kai Date: Sun, 21 Dec 2025 16:43:44 +0100 Subject: [PATCH 087/122] implement ignore qualifier annotation --- .../klee0kai/thekey/stone/ksp/Processor.kt | 2 +- .../ksp/helpers/ComponentDeclarationExt.kt | 4 +- .../ksp/helpers/invokecall/InvokeCall.kt | 8 +- .../ksp/helpers/invokecall/ModulesGraph.kt | 33 ++++---- .../helpers/invokecall/model/FieldDetail.kt | 5 ++ .../helpers/invokecall/model/QualifierAnn.kt | 4 +- .../target/component/GenComponentProcessor.kt | 1 - .../thekey/stone/ksp/utils/LocalFieldName.kt | 2 +- .../annotations/qualifier/IgnoreQualifier.kt | 16 ++++ .../car/di/lists/factory/CarMultiComponent.kt | 5 +- .../car/di/lists/factory/CarMultiModule.kt | 7 +- .../kotlin/test/car/muti/MultiProvideTest.kt | 84 +++++++++---------- 12 files changed, 103 insertions(+), 68 deletions(-) create mode 100644 stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/annotations/qualifier/IgnoreQualifier.kt diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/Processor.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/Processor.kt index 3389e645..c0c04f57 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/Processor.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/Processor.kt @@ -64,7 +64,7 @@ class Processor( // force changes // debug = true -// debugPkgFilter = "com.github.klee0kai.test.boxed.di.inject" +// debugPkgFilter = "com.github.klee0kai.test.car.di.lists.factory" } diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/ComponentDeclarationExt.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/ComponentDeclarationExt.kt index 0449ac6a..7f50fe8c 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/ComponentDeclarationExt.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/ComponentDeclarationExt.kt @@ -3,6 +3,7 @@ package com.github.klee0kai.thekey.stone.ksp.helpers import com.github.klee0kai.stone.annotations.component.* +import com.github.klee0kai.stone.annotations.qualifier.IgnoreQualifier import com.github.klee0kai.stone.lifecycle.StoneLifeCycleOwner import com.github.klee0kai.stone.weakref.Named import com.github.klee0kai.stone.weakref.Qualifier @@ -84,7 +85,8 @@ val KSAnnotated.scopeAnnotations: Sequence val KSAnnotated.qualifierAnnotations: Sequence get() { val standardQualifierAnnotations = listOf( - Named::class + Named::class, + IgnoreQualifier::class, ) return annotations.filter { funAnnotation -> diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/invokecall/InvokeCall.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/invokecall/InvokeCall.kt index ea8de150..09dfdafe 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/invokecall/InvokeCall.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/invokecall/InvokeCall.kt @@ -4,6 +4,7 @@ import com.github.klee0kai.stone.__hidden__.provide.ProvideBuilder import com.github.klee0kai.thekey.stone.ksp.helpers.invokecall.model.FieldDetail import com.github.klee0kai.thekey.stone.ksp.helpers.invokecall.model.MethodDetail import com.github.klee0kai.thekey.stone.ksp.helpers.invokecall.model.QualifierAnn +import com.github.klee0kai.thekey.stone.ksp.helpers.invokecall.model.anyIgnoreQualifier import com.github.klee0kai.thekey.stone.ksp.helpers.wrap.WrapHelper import com.github.klee0kai.thekey.stone.ksp.poet.codeBlock import com.github.klee0kai.thekey.stone.ksp.utils.LocalFieldName @@ -174,12 +175,15 @@ class InvokeCall( wrapHelper.nonWrappedType(f.type) == wrapHelper.nonWrappedType(arg.type) } var field = if (isWannaList) typeFields.firstOrNull { f -> - wrapHelper.isList(f.type) && f.qualifierAnns == arg.qualifierAnns + wrapHelper.isList(f.type) + && (arg.qualifierAnns.anyIgnoreQualifier() || arg.qualifierAnns == f.qualifierAnns) } else null if (field == null) { //non list - field = typeFields.firstOrNull { f -> f.qualifierAnns == arg.qualifierAnns } + field = typeFields.firstOrNull { f -> + (arg.qualifierAnns.anyIgnoreQualifier() || arg.qualifierAnns == f.qualifierAnns) + } } if (field != null) { diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/invokecall/ModulesGraph.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/invokecall/ModulesGraph.kt index 7d1ce6ce..a9e8d7fa 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/invokecall/ModulesGraph.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/invokecall/ModulesGraph.kt @@ -6,6 +6,7 @@ import com.github.klee0kai.stone.__hidden__.CacheAction import com.github.klee0kai.stone.__hidden__.provide.ProvideBuilder import com.github.klee0kai.stone.annotations.module.BindInstance import com.github.klee0kai.stone.annotations.module.Provide +import com.github.klee0kai.stone.annotations.qualifier.IgnoreQualifier import com.github.klee0kai.stone.weakref.Ref import com.github.klee0kai.thekey.stone.ksp.exceptions.* import com.github.klee0kai.thekey.stone.ksp.helpers.cacheControlMethodName @@ -173,9 +174,8 @@ class ModulesGraph( ) ) val provideTypeInvokes = provideInvokesWithDeps(provideDeps.iterator().next()) - if (provideTypeInvokes == null || provideTypeInvokes.isEmpty()) { - return null - } + if (provideTypeInvokes.isNullOrEmpty()) return null + for (provideTypeInvoke in provideTypeInvokes) provideDeps.addAll(provideTypeInvoke.argDeps()) if (provideTypeInvokes.size == 1 && !wrapHelper.isList(returnType)) { val invokeCall = provideTypeInvokes.first().best() @@ -193,7 +193,7 @@ class ModulesGraph( val localVariables = LinkedList(declaredFields) val codeBlock = CodeBlock.builder() - codeBlock.add("%T{ %L -> \n", provideBuilder, listFieldName) + codeBlock.add("%T{ %L -> \n", provideBuilder, listFieldName) for (inv in provideTypeInvokes) { val isCacheProvide = inv.flags.provideObjectCached @@ -208,7 +208,7 @@ class ModulesGraph( var singleDepField = FieldDetail( name = genLocalFieldName(), type = inv.resultType(), - qualifierAnns = inv.qualifierAnnotations(true) + qualifierAnns = inv.qualifierAnnotations(false) ) val listDepField = FieldDetail( name = genLocalFieldName(), @@ -217,7 +217,7 @@ class ModulesGraph( inv.resultType() ) ), - qualifierAnns = inv.qualifierAnnotations(true) + qualifierAnns = inv.qualifierAnnotations(false) ) if (isSingleDepRequired) { @@ -360,13 +360,14 @@ class ModulesGraph( } provideTypeInvokes.add(invokeCall) - provideTypeInvokes = LinkedList( - provideTypeInvokes.removeDoubles { it1, it2 -> - it1.resultType() == it2.resultType() - && it1.qualifierAnnotations(true) == it2.qualifierAnnotations(true) - } - ) } + + provideTypeInvokes = LinkedList( + provideTypeInvokes.removeDoubles { it1, it2 -> + it1.resultType() == it2.resultType() + && it1.qualifierAnnotations(crossing = false) == it2.qualifierAnnotations(crossing = false) + } + ) provideTypeInvokes.reverse() return provideTypeInvokes } @@ -401,10 +402,13 @@ class ModulesGraph( val invokeCalls = provideTypeCodes.getOrDefault(typeName, null) if (invokeCalls == null || invokeCalls.isEmpty()) return null - var filtered = invokeCalls.filter { - it.qualifierAnnotations(false) == qualifierAnns + var filtered = invokeCalls.toList() + if (qualifierAnns.none { it.typeName == IgnoreQualifier::class.asClassName() }) { + filtered = invokeCalls.filter { it.qualifierAnnotations(false) == qualifierAnns } } + + filtered = if (provideMethodName != null) { filtered.filter { provideMethodName == it.bestSequence().last().methodName } } else filtered @@ -420,7 +424,6 @@ class ModulesGraph( } companion object { - const val SIMPLE_PROVIDE_OPTIMIZING: Boolean = true const val MAX_PROVIDE_RESOLVE_COUNT: Int = 10000 } diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/invokecall/model/FieldDetail.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/invokecall/model/FieldDetail.kt index 4d382ee2..f5b408c4 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/invokecall/model/FieldDetail.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/invokecall/model/FieldDetail.kt @@ -1,9 +1,11 @@ package com.github.klee0kai.thekey.stone.ksp.helpers.invokecall.model +import com.github.klee0kai.stone.annotations.qualifier.IgnoreQualifier import com.github.klee0kai.thekey.stone.ksp.helpers.qualifierAnnotations import com.github.klee0kai.thekey.stone.ksp.ksp.resolveAlias import com.google.devtools.ksp.symbol.KSValueParameter import com.squareup.kotlinpoet.TypeName +import com.squareup.kotlinpoet.asClassName import com.squareup.kotlinpoet.ksp.toTypeName data class FieldDetail( @@ -24,4 +26,7 @@ fun KSValueParameter.toFieldDetail() = FieldDetail( qualifierAnns = qualifierAnnotations.map { it.toQualifierAnn() }.toSet(), ) +fun Set.anyIgnoreQualifier( +): Boolean = any { it.typeName == IgnoreQualifier::class.asClassName() } + diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/invokecall/model/QualifierAnn.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/invokecall/model/QualifierAnn.kt index 5eda056b..28305ed4 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/invokecall/model/QualifierAnn.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/invokecall/model/QualifierAnn.kt @@ -5,12 +5,12 @@ import com.squareup.kotlinpoet.TypeName import com.squareup.kotlinpoet.ksp.toClassName data class QualifierAnn( - var qualifierClStr: TypeName, + var typeName: TypeName, var values: Map = mapOf(), ) fun KSAnnotation.toQualifierAnn( ) = QualifierAnn( - qualifierClStr = annotationType.resolve().toClassName(), + typeName = annotationType.resolve().toClassName(), values = arguments.map { it.name?.asString()!! to it.value }.groupBy { it.first }, ) diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/component/GenComponentProcessor.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/component/GenComponentProcessor.kt index ea609be1..bfcb9437 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/component/GenComponentProcessor.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/component/GenComponentProcessor.kt @@ -97,7 +97,6 @@ class GenComponentProcessor : TargetFileProcessor { val fileOwner = validSymbol.containingFile ?: return null val componentCl = validSymbol as? KSClassDeclaration ?: return null - val identifierTypes = componentCl.allIdentifierTypes.toList() val wrapHelper = componentCl.collectWrapHelper() val modulesGraph = componentCl.collectComponentGraph() val delayedCodeBlocks = DelayedCodeBlocks() diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/utils/LocalFieldName.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/utils/LocalFieldName.kt index bf02f63e..80c94406 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/utils/LocalFieldName.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/utils/LocalFieldName.kt @@ -2,5 +2,5 @@ package com.github.klee0kai.thekey.stone.ksp.utils object LocalFieldName { private var localVariableIndx: Long = 0 - fun genLocalFieldName() = "_lc" + localVariableIndx++ + fun genLocalFieldName() = "lc" + localVariableIndx++ } \ No newline at end of file diff --git a/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/annotations/qualifier/IgnoreQualifier.kt b/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/annotations/qualifier/IgnoreQualifier.kt new file mode 100644 index 00000000..6aef2315 --- /dev/null +++ b/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/annotations/qualifier/IgnoreQualifier.kt @@ -0,0 +1,16 @@ +package com.github.klee0kai.stone.annotations.qualifier + + +/** + * TODO kdoc + */ +@Retention(AnnotationRetention.BINARY) +@Target( + AnnotationTarget.FUNCTION, + AnnotationTarget.PROPERTY_GETTER, + AnnotationTarget.PROPERTY_SETTER, + AnnotationTarget.VALUE_PARAMETER, +) +@MustBeDocumented +annotation class IgnoreQualifier + diff --git a/tests_wraps_kotlin/src/main/kotlin/com/github/klee0kai/test/car/di/lists/factory/CarMultiComponent.kt b/tests_wraps_kotlin/src/main/kotlin/com/github/klee0kai/test/car/di/lists/factory/CarMultiComponent.kt index 99c938b2..ced07628 100644 --- a/tests_wraps_kotlin/src/main/kotlin/com/github/klee0kai/test/car/di/lists/factory/CarMultiComponent.kt +++ b/tests_wraps_kotlin/src/main/kotlin/com/github/klee0kai/test/car/di/lists/factory/CarMultiComponent.kt @@ -1,6 +1,7 @@ package com.github.klee0kai.test.car.di.lists.factory import com.github.klee0kai.stone.annotations.component.Component +import com.github.klee0kai.stone.annotations.qualifier.IgnoreQualifier import com.github.klee0kai.stone.weakref.Ref import com.github.klee0kai.test.car.model.Bumper import com.github.klee0kai.test.car.model.Car @@ -25,8 +26,8 @@ interface CarMultiComponent { fun windowsProviding(): List?>?>? - // TODO The behavior is not obvious. We plan to redo it. - // fun cars(): List? + @IgnoreQualifier + fun cars(): List? @Named("blueCar") fun blueCar(): Provider? diff --git a/tests_wraps_kotlin/src/main/kotlin/com/github/klee0kai/test/car/di/lists/factory/CarMultiModule.kt b/tests_wraps_kotlin/src/main/kotlin/com/github/klee0kai/test/car/di/lists/factory/CarMultiModule.kt index 83166833..53eb2eef 100644 --- a/tests_wraps_kotlin/src/main/kotlin/com/github/klee0kai/test/car/di/lists/factory/CarMultiModule.kt +++ b/tests_wraps_kotlin/src/main/kotlin/com/github/klee0kai/test/car/di/lists/factory/CarMultiModule.kt @@ -2,6 +2,7 @@ package com.github.klee0kai.test.car.di.lists.factory import com.github.klee0kai.stone.annotations.module.Module import com.github.klee0kai.stone.annotations.module.Provide +import com.github.klee0kai.stone.annotations.qualifier.IgnoreQualifier import com.github.klee0kai.stone.weakref.Ref import com.github.klee0kai.test.car.model.Bumper import com.github.klee0kai.test.car.model.Car @@ -48,5 +49,9 @@ abstract class CarMultiModule { @Named("blueCar") @Provide(cache = Provide.CacheType.Factory) - abstract fun blueCar(bumpers: List, wheels: List, windows: List): Car? + abstract fun blueCar( + bumpers: List, + wheels: List, + @IgnoreQualifier windows: List, + ): Car? } diff --git a/tests_wraps_kotlin/src/test/kotlin/com/github/klee0kai/stone/kotlin/test/car/muti/MultiProvideTest.kt b/tests_wraps_kotlin/src/test/kotlin/com/github/klee0kai/stone/kotlin/test/car/muti/MultiProvideTest.kt index 02b82bf1..32926a9b 100644 --- a/tests_wraps_kotlin/src/test/kotlin/com/github/klee0kai/stone/kotlin/test/car/muti/MultiProvideTest.kt +++ b/tests_wraps_kotlin/src/test/kotlin/com/github/klee0kai/stone/kotlin/test/car/muti/MultiProvideTest.kt @@ -158,46 +158,46 @@ class MultiProvideTest { assertEquals(4, windowUuid.size) } -// TODO The behavior is not obvious. We plan to redo it. -// @Test -// fun createCarsWithDeps() { -// //Given -// val DI = CarMultiComponentStoneComponent() -// -// //When -// assertEquals(0, Car.createCount) -// val car = DI.cars() -// -// //Then -// assertEquals(2, Car.createCount) -// assertNotEquals(car!![0]!!.uuid, car[1]!!.uuid) -// assertNotNull(car[0]!!.bumpers) -// assertNotNull(car[0]!!.wheels) -// assertNotNull(car[0]!!.windows) -// assertNotNull(car[1]!!.bumpers) -// assertNotNull(car[1]!!.wheels) -// assertNotNull(car[1]!!.windows) -// assertNotEquals( -// car[0]!!.windows!!.size, -// car[1]!!.windows!!.size, -// "Red use single deps and Blue car use listed deps" -// ) -// } -// -// @Test -// fun factoryCreatedCar() { -// //Given -// val DI = CarMultiComponentStoneComponent() -// -// //When -// assertEquals(0, Car.createCount) -// val car1 = DI.cars() -// val car2 = DI.cars() -// -// //Then -// assertEquals(4, Car.createCount) -// assertEquals(car1!!.size, car2!!.size) -// assertNotEquals(car1[0]!!.uuid, car2[0]!!.uuid) -// assertNotEquals(car1[1]!!.uuid, car2[1]!!.uuid) -// } + @Test + fun createCarsWithDeps() { + //Given + val DI = CarMultiComponentStoneComponent() + + //When + assertEquals(0, Car.createCount) + val car = DI.cars() + + //Then + assertEquals(2, Car.createCount) + assertNotEquals(car!![0]!!.uuid, car[1]!!.uuid) + assertNotNull(car[0]!!.bumpers) + assertNotNull(car[0]!!.wheels) + assertNotNull(car[0]!!.windows) + assertNotNull(car[1]!!.bumpers) + assertNotNull(car[1]!!.wheels) + assertNotNull(car[1]!!.windows) + + assertNotEquals( + car[0]!!.windows!!.size, + car[1]!!.windows!!.size, + "Red use single deps and Blue car use listed deps" + ) + } + + @Test + fun factoryCreatedCar() { + //Given + val DI = CarMultiComponentStoneComponent() + + //When + assertEquals(0, Car.createCount) + val car1 = DI.cars() + val car2 = DI.cars() + + //Then + assertEquals(4, Car.createCount) + assertEquals(car1!!.size, car2!!.size) + assertNotEquals(car1[0]!!.uuid, car2[0]!!.uuid) + assertNotEquals(car1[1]!!.uuid, car2[1]!!.uuid) + } } From e0f4a36913a878adde1a939ed2ef18c5e297c331 Mon Sep 17 00:00:00 2001 From: klee0kai Date: Sun, 21 Dec 2025 16:49:36 +0100 Subject: [PATCH 088/122] using ignore qualifier annotation --- .../annotations/qualifier/IgnoreQualifier.kt | 1 + .../test/boxed/model/CarBoxedInjectLists.kt | 19 +++++++++++++++++-- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/annotations/qualifier/IgnoreQualifier.kt b/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/annotations/qualifier/IgnoreQualifier.kt index 6aef2315..9d9989b5 100644 --- a/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/annotations/qualifier/IgnoreQualifier.kt +++ b/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/annotations/qualifier/IgnoreQualifier.kt @@ -9,6 +9,7 @@ package com.github.klee0kai.stone.annotations.qualifier AnnotationTarget.FUNCTION, AnnotationTarget.PROPERTY_GETTER, AnnotationTarget.PROPERTY_SETTER, + AnnotationTarget.PROPERTY, AnnotationTarget.VALUE_PARAMETER, ) @MustBeDocumented diff --git a/tests_wraps_kotlin/src/main/kotlin/com/github/klee0kai/test/boxed/model/CarBoxedInjectLists.kt b/tests_wraps_kotlin/src/main/kotlin/com/github/klee0kai/test/boxed/model/CarBoxedInjectLists.kt index 3c50b078..a5111551 100644 --- a/tests_wraps_kotlin/src/main/kotlin/com/github/klee0kai/test/boxed/model/CarBoxedInjectLists.kt +++ b/tests_wraps_kotlin/src/main/kotlin/com/github/klee0kai/test/boxed/model/CarBoxedInjectLists.kt @@ -1,28 +1,43 @@ package com.github.klee0kai.test.boxed.model +import com.github.klee0kai.stone.annotations.qualifier.IgnoreQualifier import com.github.klee0kai.test.car.model.Bumper import com.github.klee0kai.test.car.model.Wheel import com.github.klee0kai.test.car.model.Window import javax.inject.Inject class CarBoxedInjectLists { + @Inject + @IgnoreQualifier var bumpers: List>? = null @Inject + @IgnoreQualifier var wheels: List>? = null @Inject + @IgnoreQualifier var windows: List>? = null - var bumpersMethodFrom: List>? = null + var wheelsMethodFrom: List>? = null + var windowsMethodFrom: List>? = null @Inject - fun init(bumpers: List>?, wheels: List>?, windows: List>?) { + fun init( + @IgnoreQualifier + bumpers: List>?, + + @IgnoreQualifier + wheels: List>?, + + @IgnoreQualifier + windows: List>?, + ) { bumpersMethodFrom = bumpers wheelsMethodFrom = wheels windowsMethodFrom = windows From 9bb579554f830acd8a9c2206d03742a99eb72547 Mon Sep 17 00:00:00 2001 From: klee0kai Date: Sun, 4 Jan 2026 23:04:15 +0100 Subject: [PATCH 089/122] correct protect injected tests --- .../klee0kai/thekey/stone/ksp/Processor.kt | 2 +- .../stone/ksp/helpers/wrap/WrapHelper.kt | 3 ++- .../target/component/GenComponentProcessor.kt | 26 +++++++++---------- .../di/compfactory/CompFactoryComponent.kt | 1 - .../test/boxed/model/CarBoxedInject.kt | 1 + .../boxed/model/CarBoxedInjectProvider.kt | 1 + 6 files changed, 18 insertions(+), 16 deletions(-) diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/Processor.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/Processor.kt index c0c04f57..3389e645 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/Processor.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/Processor.kt @@ -64,7 +64,7 @@ class Processor( // force changes // debug = true -// debugPkgFilter = "com.github.klee0kai.test.car.di.lists.factory" +// debugPkgFilter = "com.github.klee0kai.test.boxed.di.inject" } diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/wrap/WrapHelper.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/wrap/WrapHelper.kt index 1e3b51d3..18ffa8e3 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/wrap/WrapHelper.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/wrap/WrapHelper.kt @@ -248,7 +248,7 @@ class WrapHelper { LazyProvide::class, AsyncCoroutineProvide::class )) { - val isNoCachingWrapper = cl != LazyProvide::class.java && cl != AsyncCoroutineProvide::class + val isNoCachingWrapper = cl != LazyProvide::class && cl != AsyncCoroutineProvide::class val wrapper = cl.asClassName() val wrapType = WrapType( @@ -296,6 +296,7 @@ class WrapHelper { val wrapType = WrapType( typeName = wrapper, + isNoCachingWrapper = false, wrap = { or, nullable -> val builder = CodeBlock.builder() builder.add("listOfNotNull( %L ) ", or) diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/component/GenComponentProcessor.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/component/GenComponentProcessor.kt index bfcb9437..ec244736 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/component/GenComponentProcessor.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/component/GenComponentProcessor.kt @@ -417,7 +417,7 @@ class GenComponentProcessor : TargetFileProcessor { genOverrideFun(method) { for (injectableField in injectableArguments) { - val injectableCl = injectableField.type.resolve().declaration as? KSClassDeclaration + val injectableCl = injectableField.type.resolveAlias().declaration as? KSClassDeclaration ?: throw IncorrectSignatureException( message = "parameter must be a class", element = injectableField, @@ -429,15 +429,15 @@ class GenComponentProcessor : TargetFileProcessor { val provideCode = modulesGraph.codeProvideType( methodName = null, - returnType = injectField.type.resolve().toTypeName(), + returnType = injectField.type.resolveAlias().toTypeName(), qualifierAnns = injectField.qualifierAnnotations.map { it.toQualifierAnn() }.toSet(), declaredFields = method.parameters.map { it.toFieldDetail() }, ) if (provideCode == null) { - wrapHelper.nonWrappedType(injectField.type.resolve().toTypeName()) + wrapHelper.nonWrappedType(injectField.type.resolveAlias().toTypeName()) throw ObjectNotProvidedException( - message = "Error provide type ${injectField.type.resolve().toTypeName()}. " + + message = "Error provide type ${injectField.type.resolveAlias().toTypeName()}. " + "Required in ${injectableCl.toClassName()}.${injectField.simpleName.asString()}", element = method, ) @@ -458,14 +458,14 @@ class GenComponentProcessor : TargetFileProcessor { for (injectField in injectMethod.parameters) { val provideCode = modulesGraph.codeProvideType( null, - injectField.type.resolve().toTypeName(), + injectField.type.resolveAlias().toTypeName(), injectField.qualifierAnnotations.map { it.toQualifierAnn() }.toSet(), method.parameters.map { it.toFieldDetail() }, ) if (provideCode == null) { throw ObjectNotProvidedException( - message = "Error provide type ${injectField.type.resolve().toTypeName()}. " + + message = "Error provide type ${injectField.type.resolveAlias().toTypeName()}. " + "Required in ${injectableCl.toClassName()}.${injectMethod.simpleName.asString()}", element = method, ) @@ -485,7 +485,7 @@ class GenComponentProcessor : TargetFileProcessor { //protect by lifecycle owner for (injectableField in injectableArguments) { - val injectableCl = injectableField.type.resolve().declaration as? KSClassDeclaration + val injectableCl = injectableField.type.resolveAlias().declaration as? KSClassDeclaration ?: throw IncorrectSignatureException( message = "parameter must be a class", element = injectableField, @@ -501,11 +501,10 @@ class GenComponentProcessor : TargetFileProcessor { ) for (injectField in injectableCl.getAllProperties()) { if (!injectField.anyAnnotation(Inject::class.asClassName()).any()) continue - if (wrapHelper.isNonCachingWrapper( - injectField.type.resolve().toClassName() - ) - ) //nothing to protect + if (wrapHelper.isNonCachingWrapper(injectField.type.resolveAlias().toClassName())) { + //nothing to protect continue + } emptyCode = false subscrCode.addStatement( @@ -550,7 +549,7 @@ class GenComponentProcessor : TargetFileProcessor { genOverrideFun(method) { for (injectableField in injectableArguments) { - val injectableCl = injectableField.type.resolve().declaration as? KSClassDeclaration + val injectableCl = injectableField.type.resolveAlias().declaration as? KSClassDeclaration ?: throw IncorrectSignatureException( message = "parameter must be a class", element = injectableField, @@ -559,7 +558,8 @@ class GenComponentProcessor : TargetFileProcessor { for (injectField in injectableCl.getAllProperties()) { if (!injectField.anyAnnotation(Inject::class.asClassName()).any()) continue - if (wrapHelper.isNonCachingWrapper(injectField.type.resolve().toTypeName())) { //nothing to protect + if (wrapHelper.isNonCachingWrapper(injectField.type.resolveAlias().toTypeName())) { + //nothing to protect continue } diff --git a/tests_kotlin/src/main/kotlin/com/github/klee0kai/test_kotlin/di/compfactory/CompFactoryComponent.kt b/tests_kotlin/src/main/kotlin/com/github/klee0kai/test_kotlin/di/compfactory/CompFactoryComponent.kt index 29777a38..6f1b4fc5 100644 --- a/tests_kotlin/src/main/kotlin/com/github/klee0kai/test_kotlin/di/compfactory/CompFactoryComponent.kt +++ b/tests_kotlin/src/main/kotlin/com/github/klee0kai/test_kotlin/di/compfactory/CompFactoryComponent.kt @@ -10,7 +10,6 @@ import com.github.klee0kai.test.di.base_phone.identifiers.RamSize RamSize::class, PhoneOsType::class, PhoneOsVersion::class ], - wrapperProviders = [] ) interface CompFactoryComponent : ICompFactoryWrappersComponent { diff --git a/tests_wraps_kotlin/src/main/kotlin/com/github/klee0kai/test/boxed/model/CarBoxedInject.kt b/tests_wraps_kotlin/src/main/kotlin/com/github/klee0kai/test/boxed/model/CarBoxedInject.kt index dde9e8fd..62044d0b 100644 --- a/tests_wraps_kotlin/src/main/kotlin/com/github/klee0kai/test/boxed/model/CarBoxedInject.kt +++ b/tests_wraps_kotlin/src/main/kotlin/com/github/klee0kai/test/boxed/model/CarBoxedInject.kt @@ -6,6 +6,7 @@ import com.github.klee0kai.test.car.model.Window import javax.inject.Inject class CarBoxedInject { + @Inject lateinit var bumper: CarBox diff --git a/tests_wraps_kotlin/src/main/kotlin/com/github/klee0kai/test/boxed/model/CarBoxedInjectProvider.kt b/tests_wraps_kotlin/src/main/kotlin/com/github/klee0kai/test/boxed/model/CarBoxedInjectProvider.kt index c1d53681..bc1cd8ec 100644 --- a/tests_wraps_kotlin/src/main/kotlin/com/github/klee0kai/test/boxed/model/CarBoxedInjectProvider.kt +++ b/tests_wraps_kotlin/src/main/kotlin/com/github/klee0kai/test/boxed/model/CarBoxedInjectProvider.kt @@ -9,6 +9,7 @@ import com.github.klee0kai.test.car.model.Window import javax.inject.Inject class CarBoxedInjectProvider { + @Inject var bumper: LazyProvide>? = null From d62531502d7485ceb425d15af92d57f0fe57ec69 Mon Sep 17 00:00:00 2001 From: klee0kai Date: Tue, 6 Jan 2026 14:53:58 +0100 Subject: [PATCH 090/122] complex processing of nullable types during transformation --- .../ksp/helpers/ComponentDeclarationExt.kt | 22 +-- .../ksp/helpers/invokecall/InvokeCall.kt | 2 +- .../ksp/helpers/invokecall/ModulesGraph.kt | 10 +- .../helpers/invokecall/model/FieldDetail.kt | 4 +- .../stone/ksp/helpers/wrap/FormatSimple.kt | 38 +++- .../stone/ksp/helpers/wrap/WrapHelper.kt | 173 +++++++++--------- .../thekey/stone/ksp/helpers/wrap/WrapType.kt | 8 +- .../stone/ksp/ksp/KSClassDeclarationExt.kt | 6 +- .../stone/ksp/ksp/KSFunctionDeclarationExt.kt | 2 +- .../ksp/target/component/ComponentGraphExt.kt | 10 +- .../target/component/ComponentsMethodsExt.kt | 6 +- .../target/component/GenComponentProcessor.kt | 21 ++- .../module/GenModuleCacheControlProcessor.kt | 4 +- .../module/GenModuleFactoryProcessor.kt | 4 +- .../ksp/target/module/GenModuleProcessor.kt | 12 +- .../github/klee0kai/test/mowgli/MoonSky.kt | 1 + .../bindinstance/simple/CarBindComponent.kt | 11 +- .../di/bindinstance/simple/CarBindModule.kt | 7 +- .../bindinstance/simple/BindBumperTests.kt | 6 +- .../bindinstance/simple/BindWheelRefTests.kt | 2 +- .../car/bindinstance/simple/BindWheelTests.kt | 4 +- .../simple/BindWindowCollectionRefTests.kt | 2 +- .../simple/BindWindowCollectionTests.kt | 2 +- .../bindinstance/simple/BindWindowTests.kt | 4 +- 24 files changed, 208 insertions(+), 153 deletions(-) diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/ComponentDeclarationExt.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/ComponentDeclarationExt.kt index 7f50fe8c..d19a5c18 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/ComponentDeclarationExt.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/ComponentDeclarationExt.kt @@ -12,7 +12,7 @@ import com.github.klee0kai.thekey.stone.ksp.helpers.annotations.findComponentAnn import com.github.klee0kai.thekey.stone.ksp.ksp.isAnyType import com.github.klee0kai.thekey.stone.ksp.ksp.isChildOf import com.github.klee0kai.thekey.stone.ksp.ksp.isType -import com.github.klee0kai.thekey.stone.ksp.ksp.resolveAlias +import com.github.klee0kai.thekey.stone.ksp.ksp.resolveNotNullable import com.google.devtools.ksp.KspExperimental import com.google.devtools.ksp.processing.Resolver import com.google.devtools.ksp.symbol.* @@ -33,7 +33,7 @@ fun Resolver.findComponentForModuleOrDep( val KSClassDeclaration.allParentDeclarations: Sequence get() = (sequenceOf(this) - + superTypes.mapNotNull { it.resolveAlias().declaration as? KSClassDeclaration }) + + superTypes.mapNotNull { it.resolveNotNullable().declaration as? KSClassDeclaration }) val KSClassDeclaration.allIdentifierTypes: Sequence get() = allParentDeclarations @@ -42,14 +42,14 @@ val KSClassDeclaration.allIdentifierTypes: Sequence fun List.identifierParameters( allIdentifierTypes: List, -) = filter { it.type.resolveAlias() in allIdentifierTypes } +) = filter { it.type.resolveNotNullable() in allIdentifierTypes } fun List.notIdentifierParameters( allIdentifierTypes: List, -) = filter { it.type.resolveAlias() !in allIdentifierTypes } +) = filter { it.type.resolveNotNullable() !in allIdentifierTypes } fun List.lifeCycleParameter() = firstOrNull { - (it.type.resolveAlias().declaration as? KSClassDeclaration) + (it.type.resolveNotNullable().declaration as? KSClassDeclaration) ?.isChildOf(StoneLifeCycleOwner::class.asClassName()) == true } @@ -71,9 +71,9 @@ val KSAnnotated.scopeAnnotations: Sequence ) return annotations.filter { funAnnotation -> - standardScopeAnnotations.any { funAnnotation.annotationType.resolveAlias().declaration.isType(it) } - || funAnnotation.annotationType.resolveAlias().declaration.annotations.any { annotationOfAnnotation -> - annotationOfAnnotation.annotationType.resolveAlias().declaration.isAnyType( + standardScopeAnnotations.any { funAnnotation.annotationType.resolveNotNullable().declaration.isType(it) } + || funAnnotation.annotationType.resolveNotNullable().declaration.annotations.any { annotationOfAnnotation -> + annotationOfAnnotation.annotationType.resolveNotNullable().declaration.isAnyType( GcScopeAnnotation::class, Scope::class, javax.inject.Scope::class @@ -90,9 +90,9 @@ val KSAnnotated.qualifierAnnotations: Sequence ) return annotations.filter { funAnnotation -> - standardQualifierAnnotations.any { funAnnotation.annotationType.resolveAlias().declaration.isType(it) } - || funAnnotation.annotationType.resolveAlias().declaration.annotations.any { annotationOfAnnotation -> - annotationOfAnnotation.annotationType.resolveAlias().declaration.isType(Qualifier::class) + standardQualifierAnnotations.any { funAnnotation.annotationType.resolveNotNullable().declaration.isType(it) } + || funAnnotation.annotationType.resolveNotNullable().declaration.annotations.any { annotationOfAnnotation -> + annotationOfAnnotation.annotationType.resolveNotNullable().declaration.isType(Qualifier::class) } } } diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/invokecall/InvokeCall.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/invokecall/InvokeCall.kt index 09dfdafe..8565509f 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/invokecall/InvokeCall.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/invokecall/InvokeCall.kt @@ -155,7 +155,7 @@ class InvokeCall( listFieldName, wrapHelper.transform( invokeCall.rawReturnType(), - resultType(), + resultType().copy(nullable = true), seqCodeBlock ) ) diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/invokecall/ModulesGraph.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/invokecall/ModulesGraph.kt index a9e8d7fa..e677d9b8 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/invokecall/ModulesGraph.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/invokecall/ModulesGraph.kt @@ -17,7 +17,7 @@ import com.github.klee0kai.thekey.stone.ksp.helpers.qualifierAnnotations import com.github.klee0kai.thekey.stone.ksp.helpers.wrap.WrapHelper import com.github.klee0kai.thekey.stone.ksp.ksp.getAllMethods import com.github.klee0kai.thekey.stone.ksp.ksp.isNotPrimitive -import com.github.klee0kai.thekey.stone.ksp.ksp.resolveAlias +import com.github.klee0kai.thekey.stone.ksp.ksp.resolveNotNullable import com.github.klee0kai.thekey.stone.ksp.target.component.* import com.github.klee0kai.thekey.stone.ksp.utils.LocalFieldName.genLocalFieldName import com.github.klee0kai.thekey.stone.ksp.utils.RecursiveDetector @@ -58,13 +58,13 @@ class ModulesGraph( .filter { it.isModuleProvideMethod || it.isDepsProvideMethod } .forEachFun { _, moduleProvideMethod -> - val module = moduleProvideMethod.returnType?.resolveAlias() + val module = moduleProvideMethod.returnType?.resolveNotNullable() ?.declaration as? KSClassDeclaration ?: return@forEachFun for (m in module.getAllMethods(includeObjectMethods = false, allowDoubles = true, "")) { - if (m.returnType?.resolveAlias()?.isNotPrimitive == false) continue + if (m.returnType?.resolveNotNullable()?.isNotPrimitive == false) continue - val returnType = m.returnType?.resolveAlias()?.toTypeName() ?: continue + val returnType = m.returnType?.resolveNotNullable()?.toTypeName() ?: continue val provTypeName = wrapHelper.nonWrappedType(returnType) val isCached = m.getAnnotationsByType(Provide::class) .firstOrNull()?.cache !in listOf(Provide.CacheType.Factory, null) @@ -278,7 +278,7 @@ class ModulesGraph( listFieldName, wrapHelper.transform( singleDepField.type, - providingType, + providingType.copy(nullable = true), CodeBlock.of(singleDepField.name) ) ) diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/invokecall/model/FieldDetail.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/invokecall/model/FieldDetail.kt index f5b408c4..e4a89620 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/invokecall/model/FieldDetail.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/invokecall/model/FieldDetail.kt @@ -2,7 +2,7 @@ package com.github.klee0kai.thekey.stone.ksp.helpers.invokecall.model import com.github.klee0kai.stone.annotations.qualifier.IgnoreQualifier import com.github.klee0kai.thekey.stone.ksp.helpers.qualifierAnnotations -import com.github.klee0kai.thekey.stone.ksp.ksp.resolveAlias +import com.github.klee0kai.thekey.stone.ksp.ksp.resolveNotNullable import com.google.devtools.ksp.symbol.KSValueParameter import com.squareup.kotlinpoet.TypeName import com.squareup.kotlinpoet.asClassName @@ -22,7 +22,7 @@ fun FieldDetail.Companion.simple(name: String, type: TypeName) = FieldDetail(nam fun KSValueParameter.toFieldDetail() = FieldDetail( name = name?.asString() ?: "it", - type = type.resolveAlias().toTypeName().copy(nullable = false), + type = type.resolveNotNullable().toTypeName().copy(nullable = false), qualifierAnns = qualifierAnnotations.map { it.toQualifierAnn() }.toSet(), ) diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/wrap/FormatSimple.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/wrap/FormatSimple.kt index 9d523339..2324b215 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/wrap/FormatSimple.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/wrap/FormatSimple.kt @@ -11,6 +11,42 @@ fun interface FormatSimple { */ fun formatCode( or: CodeBlock, - nullable: Boolean, ): CodeBlock + + +} + + +fun interface UnwrapFun { + + /** + * @param code code witch return original type + * @return code witch return wanna type + */ + fun formatCode( + or: CodeBlock, + srcNullable: Boolean, + targetNullable: Boolean, + ): CodeBlock + + } + + +fun interface WrapFun { + + /** + * @param code code witch return original type + * @return code witch return wanna type + */ + fun formatCode( + or: CodeBlock, + srcNullable: Boolean, + targetNullable: Boolean, + targetArgTypeNullable: Boolean, + ): CodeBlock + + +} + + diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/wrap/WrapHelper.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/wrap/WrapHelper.kt index 18ffa8e3..52ec9e5a 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/wrap/WrapHelper.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/wrap/WrapHelper.kt @@ -39,14 +39,6 @@ class WrapHelper { return false } - fun isAsyncProvider(typeName: TypeName): Boolean { - for (t in allParamTypes(typeName)) { - val wrapType = wrapTypes.get(rawTypeOf(t)) - if (wrapType != null && wrapType.isAsyncProvider) return true - } - return false - } - fun isList(typeName: TypeName): Boolean = allParamTypes(typeName).any { val wrapType = wrapTypes.get(rawTypeOf(it)) wrapType != null && wrapType.isList @@ -113,22 +105,24 @@ class WrapHelper { wrapPathNames.reverse() while (!wrapPathNames.isEmpty() && !unwrapPathNames.isEmpty() - && rawTypeOf(unwrapPathNames.last()) == rawTypeOf(wrapPathNames.first()) + && unwrapPathNames.last().rawType() == wrapPathNames.first().rawType() ) { unwrapPathNames.pollLast() wrapPathNames.pollFirst() } val wrapTypeFormat: (TypeName) -> WrapType = { it: TypeName -> - wrapTypes[rawTypeOf(it)] + wrapTypes[it.rawType()] ?: throw StoneException(message = "Type Transform non support $providingType -> $wannaType") } - val unwrapPath = LinkedList(unwrapPathNames.map(wrapTypeFormat)) - val wrapPath = LinkedList(wrapPathNames.map(wrapTypeFormat)) + val unwrapPath = LinkedList(unwrapPathNames.map { wrapTypeFormat(it).copy(typeName = it) }) + val wrapPath = LinkedList(wrapPathNames.map { wrapTypeFormat(it).copy(typeName = it) }) + + var currentNullable = providingType.isNullable while (!unwrapPath.isEmpty()) { - val unwrapType = unwrapPath[0] + val unwrapType = unwrapPath.first() if (unwrapType.isList) { val wrapListIndex = wrapPath.indexOfFirst { it.isList } if (wrapListIndex >= 0) { @@ -139,7 +133,7 @@ class WrapHelper { codeBuilder = wrapListType.inListFormat!!.formatCode( originalListType = unwrapType.typeName, or = codeBuilder.build(), - itemTransformFun = { listItemCode, nullable -> + itemTransformFun = { listItemCode -> transform(unWrapItemType, wrapItemType, listItemCode) } ).toBuilder() @@ -153,21 +147,37 @@ class WrapHelper { break } } - codeBuilder = unwrapType.unwrap.formatCode(codeBuilder.build(), unwrapType.typeName.isNullable) - .toBuilder() - unwrapPath.pollFirst() unwrapPathNames.pollFirst() + + currentNullable = (unwrapPath.firstOrNull()?.typeName + ?: wrapPath.firstOrNull()?.typeName + ?: wannaType).isNullable + + codeBuilder = unwrapType.unwrap.formatCode( + or = codeBuilder.build(), + srcNullable = unwrapType.typeName.isNullable, + targetNullable = currentNullable + ).toBuilder() } while (!wrapPath.isEmpty()) { - codeBuilder = wrapPath[0].wrap.formatCode(codeBuilder.build(), wrapPath[0].typeName.isNullable) - .toBuilder() + val wrapType = wrapPath.first() wrapPath.pollFirst() wrapPathNames.pollFirst() + + codeBuilder = wrapType.wrap.formatCode( + codeBuilder.build(), + srcNullable = currentNullable, + targetNullable = wrapType.typeName.isNullable, + targetArgTypeNullable = paramType(wrapType.typeName).isNullable, + ).toBuilder() + + currentNullable = wrapType.typeName.isNullable } - if (!wannaType.isNullable) { + + if (currentNullable && !wannaType.isNullable) { codeBuilder.add("!!") } @@ -186,21 +196,21 @@ class WrapHelper { val wrapType = WrapType( typeName = wrapper, isNoCachingWrapper = false, - wrap = { or, nullable -> + wrap = { or, srcNullable, targetNullable, argTypeNullable -> codeBlock { - if (nullable) { - add("%T( %L )", creator, or) - } else { - add("%T( %L!! )", creator, or) + when { + !srcNullable || argTypeNullable -> add("%T( %L )", creator, or) + targetNullable -> add("%L?.let{ %T( it ) }", or, creator) + else -> add("%T( %L!! )", creator, or) } } }, - unwrap = { or, nullable -> + unwrap = { or, srcNullable, targetNullable -> codeBlock { - if (nullable) { - add("%L?.get()", or) - } else { - add("%L!!.get()", or) + when { + !srcNullable && targetNullable -> add("%L.get()", or) + targetNullable -> add("%L?.get()", or) + else -> add("%L!!.get()!!", or) } } } @@ -215,26 +225,21 @@ class WrapHelper { val wrapType = WrapType( typeName = wrapper, isNoCachingWrapper = false, - isAsyncProvider = true, - wrap = { or, nullable -> - if (nullable) { - CodeBlock.of( - "lazy{ %L } ", - or, - ) - } else { - CodeBlock.of( - "lazy{ %L!! } ", - or, - ) + wrap = { or, srcNullable, targetNullable, argTypeNullable -> + codeBlock { + when { + !srcNullable || argTypeNullable -> add("lazy{ %L } ", or) + else -> add("lazy{ %L!! } ", or) + } } - }, - unwrap = { or, nullable -> - if (nullable) { - CodeBlock.of("%L?.value", or) - } else { - CodeBlock.of("%L!!.value", or) + unwrap = { or, srcNullable, targetNullable -> + codeBlock { + when { + !srcNullable -> add("%L.value", or) + targetNullable -> add("%L?.value", or) + else -> add("%L!!.value", or) + } } }, ) @@ -254,28 +259,21 @@ class WrapHelper { val wrapType = WrapType( typeName = wrapper, isNoCachingWrapper = isNoCachingWrapper, - isAsyncProvider = true, - wrap = { or, nullable -> - if (nullable) { - CodeBlock.of( - "%T{ %L } ", - wrapper, - or, - ) - } else { - CodeBlock.of( - "%T{ %L!! } ", - wrapper, - or, - ) + wrap = { or, srcNullable, targetNullable, argTypeNullable -> + codeBlock { + when { + !srcNullable || argTypeNullable -> add("%T{ %L }", wrapper, or) + else -> add("%T{ %L!! } ", wrapper, or) + } } - }, - unwrap = { or, nullable -> - if (nullable) { - CodeBlock.of("%L?.get()", or) - } else { - CodeBlock.of("%L!!.get()", or) + unwrap = { or, srcNullable, targetNullable -> + codeBlock { + when { + !srcNullable && !targetNullable -> add("%L.get()", or) + targetNullable -> add("%L?.get()", or) + else -> add("%L!!.get()!!", or) + } } }, ) @@ -297,30 +295,41 @@ class WrapHelper { val wrapType = WrapType( typeName = wrapper, isNoCachingWrapper = false, - wrap = { or, nullable -> - val builder = CodeBlock.builder() - builder.add("listOfNotNull( %L ) ", or) - if (constructor != null) builder.add("?.let { %T(it) }", constructor) - builder.build() + wrap = { or, srcNullable, targetNullable, _ -> + codeBlock { + add("listOfNotNull( %L ) ", or) + when { + constructor != null && targetNullable -> add("?.let { %T(it) }", constructor) + constructor != null && !targetNullable -> add("!!.let { %T(it) }", constructor) + } + + } }, - unwrap = { or, nullable -> - CodeBlock.builder() - .add("%L?.first( )", or) - .build() + unwrap = { or, srcNullable, targetNullable -> + codeBlock { + when { + !srcNullable -> add("%L.first()", or) + targetNullable -> add("%L?.first()", or) + else -> add("%L!!.first()", or) + } + } }, inListFormat = { originalListType, originalListCode, itemTransformFun -> codeBlock { - val itemTransform = itemTransformFun.formatCode(CodeBlock.of("it"), nullable = false) + val itemTransform = itemTransformFun.formatCode(CodeBlock.of("it")) if (itemTransform.toString() == "it") { //no transforms add(originalListCode) } else { - add("%L?.map{ it -> %L }", originalListCode, itemTransform) + add("%L!!.map{ it -> %L }", originalListCode, itemTransform) } - if (rawTypeOf(wrapper) != rawTypeOf(originalListType)) { - if (constructor != null) add("?.let { %T(it) }", constructor) - else add("?.toList()") + if (wrapper.rawType() != originalListType.rawType()) { + if (constructor != null) { + add("!!.let { %T(it) }", constructor) + } else { + add("!!.toList()") + } } } }, diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/wrap/WrapType.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/wrap/WrapType.kt index fb3072d0..f4e01da7 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/wrap/WrapType.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/wrap/WrapType.kt @@ -2,13 +2,13 @@ package com.github.klee0kai.thekey.stone.ksp.helpers.wrap import com.squareup.kotlinpoet.TypeName -class WrapType( +data class WrapType( val typeName: TypeName, - val unwrap: FormatSimple, - val wrap: FormatSimple, - val isAsyncProvider: Boolean = true, + val unwrap: UnwrapFun, + val wrap: WrapFun, val isNoCachingWrapper: Boolean = true, val inListFormat: FormatInList? = null, ) { val isList: Boolean get() = inListFormat != null } + diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/ksp/KSClassDeclarationExt.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/ksp/KSClassDeclarationExt.kt index d82b356a..8d6f80b5 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/ksp/KSClassDeclarationExt.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/ksp/KSClassDeclarationExt.kt @@ -11,7 +11,9 @@ import com.squareup.kotlinpoet.ksp.toClassNameOrNull import kotlin.reflect.KClass -fun KSTypeReference.resolveAlias(): KSType = resolve().makeNotNullable().unwrapAlias() +fun KSTypeReference.resolveAlias(): KSType = resolve().unwrapAlias() + +fun KSTypeReference.resolveNotNullable(): KSType = resolve().makeNotNullable().unwrapAlias() fun KSType.unwrapAlias(): KSType { var current: KSType = this @@ -28,7 +30,7 @@ fun KSClassDeclaration.findConstructor( ): KSFunctionDeclaration? = getDeclaredFunctions() .filter { function -> function.simpleName.asString() == "" - && function.parameters.all { it.type.resolveAlias() in parameters || it.hasDefault } + && function.parameters.all { it.type.resolveNotNullable() in parameters || it.hasDefault } }.maxByOrNull { it.parameters.size } fun KSDeclaration.isAnyType( diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/ksp/KSFunctionDeclarationExt.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/ksp/KSFunctionDeclarationExt.kt index 0183dcfb..f546e830 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/ksp/KSFunctionDeclarationExt.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/ksp/KSFunctionDeclarationExt.kt @@ -25,7 +25,7 @@ fun KSFunctionDeclaration.joinInvokeArguments( ): String { return parameters.mapNotNull { parameter -> val availableVariable = availableVariables - .firstOrNull { it.type.resolveAlias() == parameter.type.resolveAlias() } + .firstOrNull { it.type.resolveNotNullable() == parameter.type.resolveNotNullable() } if (availableVariable != null) { val notNullablePostFix = if (availableVariable.type.resolve().isMarkedNullable && !parameter.type.resolve().isMarkedNullable diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/component/ComponentGraphExt.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/component/ComponentGraphExt.kt index 3b9ef18d..97b4b8ca 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/component/ComponentGraphExt.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/component/ComponentGraphExt.kt @@ -8,7 +8,7 @@ import com.github.klee0kai.thekey.stone.ksp.helpers.invokecall.ModulesGraph import com.github.klee0kai.thekey.stone.ksp.helpers.wrap.WrapHelper import com.github.klee0kai.thekey.stone.ksp.helpers.wrap.WrapType import com.github.klee0kai.thekey.stone.ksp.ksp.getAllMethods -import com.github.klee0kai.thekey.stone.ksp.ksp.resolveAlias +import com.github.klee0kai.thekey.stone.ksp.ksp.resolveNotNullable import com.github.klee0kai.thekey.stone.ksp.poet.codeBlock import com.google.devtools.ksp.symbol.KSClassDeclaration import com.squareup.kotlinpoet.ksp.toClassName @@ -27,11 +27,11 @@ fun KSClassDeclaration.collectWrapHelper( val methods = wrapperHelperClDec.getAllMethods(false, false, "") methods.forEachFun { funIdx, m -> val inputType = (m.parameters.firstOrNull() - ?.type?.resolveAlias() + ?.type?.resolveNotNullable() ?.declaration as? KSClassDeclaration) ?.toClassName() ?: return@forEachFun - val outputType = (m.returnType?.resolveAlias() + val outputType = (m.returnType?.resolveNotNullable() ?.declaration as? KSClassDeclaration) ?.toClassName() ?: return@forEachFun @@ -39,7 +39,7 @@ fun KSClassDeclaration.collectWrapHelper( WrapType( isNoCachingWrapper = false, typeName = outputType, - wrap = { or, nullable -> + wrap = { or, srcNullable, targetNullable, argTypeNullable -> codeBlock { add( "%T.%L{ %L!! }", @@ -49,7 +49,7 @@ fun KSClassDeclaration.collectWrapHelper( ) } }, - unwrap = { or, nullable -> + unwrap = { or, srcNullable, targetNullable -> codeBlock { } diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/component/ComponentsMethodsExt.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/component/ComponentsMethodsExt.kt index 9839f595..476f1790 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/component/ComponentsMethodsExt.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/component/ComponentsMethodsExt.kt @@ -13,7 +13,7 @@ import com.github.klee0kai.thekey.stone.ksp.helpers.scopeAnnotations import com.github.klee0kai.thekey.stone.ksp.ksp.isClassReturn import com.github.klee0kai.thekey.stone.ksp.ksp.isNotPrimitive import com.github.klee0kai.thekey.stone.ksp.ksp.isUnit -import com.github.klee0kai.thekey.stone.ksp.ksp.resolveAlias +import com.github.klee0kai.thekey.stone.ksp.ksp.resolveNotNullable import com.github.klee0kai.thekey.stone.ksp.target.module.GenModuleProcessor import com.google.devtools.ksp.getAllSuperTypes import com.google.devtools.ksp.symbol.KSClassDeclaration @@ -165,7 +165,7 @@ fun KSFunctionDeclaration.isExtOfMethod( ) } val argumentType = parameters.firstOrNull()?.type - ?.resolveAlias()?.declaration as? KSClassDeclaration + ?.resolveNotNullable()?.declaration as? KSClassDeclaration ?: throw IncorrectSignatureException( message = "${simpleName.asString()} must have only one parameter of Component instance", element = this, @@ -201,7 +201,7 @@ val KSFunctionDeclaration.isBindInstanceMethod: BindInstanceType? ) } checkMethodNameBusy() - val parameterIsNotPrimitive = parameters.first().type.resolveAlias().isNotPrimitive + val parameterIsNotPrimitive = parameters.first().type.resolveNotNullable().isNotPrimitive when { parameterIsNotPrimitive diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/component/GenComponentProcessor.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/component/GenComponentProcessor.kt index ec244736..97c915f8 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/component/GenComponentProcessor.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/component/GenComponentProcessor.kt @@ -27,6 +27,7 @@ import com.github.klee0kai.thekey.stone.ksp.ksp.arch.SymbolsToProcess import com.github.klee0kai.thekey.stone.ksp.ksp.arch.TargetFileProcessor import com.github.klee0kai.thekey.stone.ksp.ksp.getAllMethods import com.github.klee0kai.thekey.stone.ksp.ksp.resolveAlias +import com.github.klee0kai.thekey.stone.ksp.ksp.resolveNotNullable import com.github.klee0kai.thekey.stone.ksp.poet.* import com.github.klee0kai.thekey.stone.ksp.target.module.GenModuleProcessor import com.google.devtools.ksp.KspExperimental @@ -293,7 +294,7 @@ class GenComponentProcessor : TargetFileProcessor { method: KSFunctionDeclaration, modulesGraph: ModulesGraph, ) { - val returnType = method.returnType?.resolve()?.toTypeName() ?: return + val returnType = method.returnType?.resolveAlias()?.toTypeName() ?: return val codeBlock = modulesGraph.codeProvideType( methodName = null, @@ -323,10 +324,10 @@ class GenComponentProcessor : TargetFileProcessor { modulesGraph: ModulesGraph, wrapHelper: WrapHelper, ) { - val returnType = method.returnType?.resolve()?.toTypeName() ?: return + val returnType = method.returnType?.resolveAlias()?.toTypeName() ?: return val identifierTypes = componentCl.allIdentifierTypes.toList() - val setValueArg = method.parameters.firstOrNull { it.type.resolveAlias() !in identifierTypes } + val setValueArg = method.parameters.firstOrNull { it.type.resolveNotNullable() !in identifierTypes } ?: throw IncorrectSignatureException( message = "Bind instance method must have bind instance arcgument", element = method, @@ -417,7 +418,7 @@ class GenComponentProcessor : TargetFileProcessor { genOverrideFun(method) { for (injectableField in injectableArguments) { - val injectableCl = injectableField.type.resolveAlias().declaration as? KSClassDeclaration + val injectableCl = injectableField.type.resolveNotNullable().declaration as? KSClassDeclaration ?: throw IncorrectSignatureException( message = "parameter must be a class", element = injectableField, @@ -435,9 +436,9 @@ class GenComponentProcessor : TargetFileProcessor { ) if (provideCode == null) { - wrapHelper.nonWrappedType(injectField.type.resolveAlias().toTypeName()) + wrapHelper.nonWrappedType(injectField.type.resolveNotNullable().toTypeName()) throw ObjectNotProvidedException( - message = "Error provide type ${injectField.type.resolveAlias().toTypeName()}. " + + message = "Error provide type ${injectField.type.resolveNotNullable().toTypeName()}. " + "Required in ${injectableCl.toClassName()}.${injectField.simpleName.asString()}", element = method, ) @@ -485,7 +486,7 @@ class GenComponentProcessor : TargetFileProcessor { //protect by lifecycle owner for (injectableField in injectableArguments) { - val injectableCl = injectableField.type.resolveAlias().declaration as? KSClassDeclaration + val injectableCl = injectableField.type.resolveNotNullable().declaration as? KSClassDeclaration ?: throw IncorrectSignatureException( message = "parameter must be a class", element = injectableField, @@ -501,7 +502,7 @@ class GenComponentProcessor : TargetFileProcessor { ) for (injectField in injectableCl.getAllProperties()) { if (!injectField.anyAnnotation(Inject::class.asClassName()).any()) continue - if (wrapHelper.isNonCachingWrapper(injectField.type.resolveAlias().toClassName())) { + if (wrapHelper.isNonCachingWrapper(injectField.type.resolveNotNullable().toClassName())) { //nothing to protect continue } @@ -549,7 +550,7 @@ class GenComponentProcessor : TargetFileProcessor { genOverrideFun(method) { for (injectableField in injectableArguments) { - val injectableCl = injectableField.type.resolveAlias().declaration as? KSClassDeclaration + val injectableCl = injectableField.type.resolveNotNullable().declaration as? KSClassDeclaration ?: throw IncorrectSignatureException( message = "parameter must be a class", element = injectableField, @@ -558,7 +559,7 @@ class GenComponentProcessor : TargetFileProcessor { for (injectField in injectableCl.getAllProperties()) { if (!injectField.anyAnnotation(Inject::class.asClassName()).any()) continue - if (wrapHelper.isNonCachingWrapper(injectField.type.resolveAlias().toTypeName())) { + if (wrapHelper.isNonCachingWrapper(injectField.type.resolveNotNullable().toTypeName())) { //nothing to protect continue } diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/module/GenModuleCacheControlProcessor.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/module/GenModuleCacheControlProcessor.kt index a2b0aaf6..b465f292 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/module/GenModuleCacheControlProcessor.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/module/GenModuleCacheControlProcessor.kt @@ -12,7 +12,7 @@ import com.github.klee0kai.thekey.stone.ksp.ksp.arch.GenSpec import com.github.klee0kai.thekey.stone.ksp.ksp.arch.SymbolsToProcess import com.github.klee0kai.thekey.stone.ksp.ksp.arch.TargetFileProcessor import com.github.klee0kai.thekey.stone.ksp.ksp.getAllMethods -import com.github.klee0kai.thekey.stone.ksp.ksp.resolveAlias +import com.github.klee0kai.thekey.stone.ksp.ksp.resolveNotNullable import com.github.klee0kai.thekey.stone.ksp.poet.* import com.github.klee0kai.thekey.stone.ksp.target.component.collectWrapHelper import com.google.devtools.ksp.KspExperimental @@ -89,7 +89,7 @@ class GenModuleCacheControlProcessor : TargetFileProcessor { val methods = validSymbol.getAllMethods(includeObjectMethods = false, allowDoubles = false, "") methods.forEachFun { _, function -> val idArguments = function.parameters.identifierParameters(identifierTypes) - val returnType = function.returnType?.resolveAlias()?.toTypeName() ?: return@forEachFun + val returnType = function.returnType?.resolveNotNullable()?.toTypeName() ?: return@forEachFun val cacheControlType = wrapHelper.listWrapTypeIfNeed(returnType).copy(nullable = true) genOverrideFun(function) { diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/module/GenModuleFactoryProcessor.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/module/GenModuleFactoryProcessor.kt index c7dc49ab..c0ed2806 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/module/GenModuleFactoryProcessor.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/module/GenModuleFactoryProcessor.kt @@ -16,7 +16,7 @@ import com.github.klee0kai.thekey.stone.ksp.ksp.arch.TargetFileProcessor import com.github.klee0kai.thekey.stone.ksp.ksp.findConstructor import com.github.klee0kai.thekey.stone.ksp.ksp.getAllMethods import com.github.klee0kai.thekey.stone.ksp.ksp.joinInvokeArguments -import com.github.klee0kai.thekey.stone.ksp.ksp.resolveAlias +import com.github.klee0kai.thekey.stone.ksp.ksp.resolveNotNullable import com.github.klee0kai.thekey.stone.ksp.poet.genClass import com.github.klee0kai.thekey.stone.ksp.poet.genFileSpec import com.github.klee0kai.thekey.stone.ksp.poet.genLibComment @@ -90,7 +90,7 @@ class GenModuleFactoryProcessor : TargetFileProcessor { val constructorFun by lazy { nonWrappedClDec?.findConstructor( - parameters = function.parameters.map { it.type.resolveAlias() }) + parameters = function.parameters.map { it.type.resolveNotNullable() }) } genOverrideFun(function) { diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/module/GenModuleProcessor.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/module/GenModuleProcessor.kt index 99762bd7..0a2ddf58 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/module/GenModuleProcessor.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/module/GenModuleProcessor.kt @@ -25,7 +25,7 @@ import com.github.klee0kai.thekey.stone.ksp.ksp.arch.GenSpec import com.github.klee0kai.thekey.stone.ksp.ksp.arch.SymbolsToProcess import com.github.klee0kai.thekey.stone.ksp.ksp.arch.TargetFileProcessor import com.github.klee0kai.thekey.stone.ksp.ksp.getAllMethods -import com.github.klee0kai.thekey.stone.ksp.ksp.resolveAlias +import com.github.klee0kai.thekey.stone.ksp.ksp.resolveNotNullable import com.github.klee0kai.thekey.stone.ksp.poet.* import com.github.klee0kai.thekey.stone.ksp.target.component.collectWrapHelper import com.google.devtools.ksp.KspExperimental @@ -196,7 +196,7 @@ class GenModuleProcessor : TargetFileProcessor { } genFun(function.cacheControlMethodName) { modifiers.add(KModifier.OVERRIDE) - val cacheControlType = function.returnType?.resolveAlias() + val cacheControlType = function.returnType?.resolveNotNullable() ?.toTypeName() ?.let { wrapHelper.listWrapTypeIfNeed(it).copy(nullable = true) } cacheControlType?.let { returns(cacheControlType) } @@ -298,12 +298,11 @@ class GenModuleProcessor : TargetFileProcessor { addCode("return ") addCode( wrapHelper.transform( - wrapHelper.listWrapTypeIfNeed(returnType), + wrapHelper.listWrapTypeIfNeed(returnType).copy(nullable = true), returnType, itemHolderCodeHelper.codeGetCachedValue(), ) ) - addStatement(" as %T", returnType) } } @@ -356,12 +355,11 @@ class GenModuleProcessor : TargetFileProcessor { addCode("return ") addCode( wrapHelper.transform( - wrapHelper.listWrapTypeIfNeed(returnType), + wrapHelper.listWrapTypeIfNeed(returnType).copy(nullable = true), returnType, itemHolderCodeHelper.codeGetCachedValue(), ) ) - addCode(" as %T", returnType) } } @@ -371,7 +369,7 @@ class GenModuleProcessor : TargetFileProcessor { itemHolderCodeHelper: ItemHolderCodeHelper, wrapHelper: WrapHelper, ) { - val returnType = function.returnType?.resolveAlias()?.toTypeName() ?: return + val returnType = function.returnType?.resolveNotNullable()?.toTypeName() ?: return val cacheControlType = wrapHelper.listWrapTypeIfNeed(returnType).copy(nullable = true) genFun(function.cacheControlMethodName) { modifiers.add(KModifier.OVERRIDE) diff --git a/tests/src/main/java/com/github/klee0kai/test/mowgli/MoonSky.kt b/tests/src/main/java/com/github/klee0kai/test/mowgli/MoonSky.kt index 3216be01..06ba8815 100644 --- a/tests/src/main/java/com/github/klee0kai/test/mowgli/MoonSky.kt +++ b/tests/src/main/java/com/github/klee0kai/test/mowgli/MoonSky.kt @@ -4,6 +4,7 @@ import com.github.klee0kai.test.mowgli.galaxy.* import javax.inject.Inject class MoonSky { + @JvmField @Inject var star: IStar? = null diff --git a/tests_wraps_kotlin/src/main/kotlin/com/github/klee0kai/test/car/di/bindinstance/simple/CarBindComponent.kt b/tests_wraps_kotlin/src/main/kotlin/com/github/klee0kai/test/car/di/bindinstance/simple/CarBindComponent.kt index 749dfb85..5ec89188 100644 --- a/tests_wraps_kotlin/src/main/kotlin/com/github/klee0kai/test/car/di/bindinstance/simple/CarBindComponent.kt +++ b/tests_wraps_kotlin/src/main/kotlin/com/github/klee0kai/test/car/di/bindinstance/simple/CarBindComponent.kt @@ -31,11 +31,18 @@ interface CarBindComponent { @BindInstance fun bindWindowRefs(window: Collection>) - fun provideWheel(): Wheel + fun provideWheel(): Wheel? + fun provideWheelRef(): Reference? + fun provideWheels(): List?>? + fun provideBumper(): Ref? + fun provideBumpers(): List? - fun provideWindow(): Window + + fun provideWindow(): Window? + fun provideWindows(): Collection? + } diff --git a/tests_wraps_kotlin/src/main/kotlin/com/github/klee0kai/test/car/di/bindinstance/simple/CarBindModule.kt b/tests_wraps_kotlin/src/main/kotlin/com/github/klee0kai/test/car/di/bindinstance/simple/CarBindModule.kt index b7c8fbb5..0ca7ef1c 100644 --- a/tests_wraps_kotlin/src/main/kotlin/com/github/klee0kai/test/car/di/bindinstance/simple/CarBindModule.kt +++ b/tests_wraps_kotlin/src/main/kotlin/com/github/klee0kai/test/car/di/bindinstance/simple/CarBindModule.kt @@ -9,12 +9,13 @@ import java.lang.ref.WeakReference @Module interface CarBindModule { + @BindInstance - fun wheel(): Wheel + fun wheel(): Wheel? @BindInstance - fun bumper(): WeakReference + fun bumper(): WeakReference? @BindInstance - fun windows(): WeakReference> + fun windows(): WeakReference>? } diff --git a/tests_wraps_kotlin/src/test/kotlin/com/github/klee0kai/stone/kotlin/test/car/bindinstance/simple/BindBumperTests.kt b/tests_wraps_kotlin/src/test/kotlin/com/github/klee0kai/stone/kotlin/test/car/bindinstance/simple/BindBumperTests.kt index c9356759..76746653 100644 --- a/tests_wraps_kotlin/src/test/kotlin/com/github/klee0kai/stone/kotlin/test/car/bindinstance/simple/BindBumperTests.kt +++ b/tests_wraps_kotlin/src/test/kotlin/com/github/klee0kai/stone/kotlin/test/car/bindinstance/simple/BindBumperTests.kt @@ -15,7 +15,7 @@ class BindBumperTests { //Then assertNull(DI.module().bumper()) - assertNull(DI.provideBumper()!!.get()) + assertNull(DI.provideBumper()?.get()) assertEquals(0, DI.provideBumpers()!!.size) } @@ -28,8 +28,8 @@ class BindBumperTests { DI.bindBumper(null) //Then - assertNull(DI.module()!!.bumper()) - assertNull(DI.provideBumper()!!.get()) + assertNull(DI.module().bumper()) + assertNull(DI.provideBumper()?.get()) assertEquals(0, DI.provideBumpers()!!.size) } diff --git a/tests_wraps_kotlin/src/test/kotlin/com/github/klee0kai/stone/kotlin/test/car/bindinstance/simple/BindWheelRefTests.kt b/tests_wraps_kotlin/src/test/kotlin/com/github/klee0kai/stone/kotlin/test/car/bindinstance/simple/BindWheelRefTests.kt index f11d5fdf..d22041a9 100644 --- a/tests_wraps_kotlin/src/test/kotlin/com/github/klee0kai/stone/kotlin/test/car/bindinstance/simple/BindWheelRefTests.kt +++ b/tests_wraps_kotlin/src/test/kotlin/com/github/klee0kai/stone/kotlin/test/car/bindinstance/simple/BindWheelRefTests.kt @@ -45,7 +45,7 @@ class BindWheelRefTests { DI.bindWheelRef(WeakReference(null)) //Then - assertNull(DI.module()!!.wheel()) + assertNull(DI.module().wheel()) assertNull(DI.provideWheel()) assertNull(DI.provideWheelRef()) assertEquals(0, DI.provideWheels()!!.size) diff --git a/tests_wraps_kotlin/src/test/kotlin/com/github/klee0kai/stone/kotlin/test/car/bindinstance/simple/BindWheelTests.kt b/tests_wraps_kotlin/src/test/kotlin/com/github/klee0kai/stone/kotlin/test/car/bindinstance/simple/BindWheelTests.kt index 21355255..ffa93c63 100644 --- a/tests_wraps_kotlin/src/test/kotlin/com/github/klee0kai/stone/kotlin/test/car/bindinstance/simple/BindWheelTests.kt +++ b/tests_wraps_kotlin/src/test/kotlin/com/github/klee0kai/stone/kotlin/test/car/bindinstance/simple/BindWheelTests.kt @@ -47,7 +47,7 @@ class BindWheelTests { //Then assertEquals(wheel.uuid, DI.module().wheel()!!.uuid) - assertEquals(wheel.uuid, DI.provideWheel().uuid) + assertEquals(wheel.uuid, DI.provideWheel()?.uuid) assertEquals(wheel.uuid, DI.provideWheelRef()!!.get()!!.uuid) assertEquals(1, DI.provideWheels()!!.size) assertEquals(wheel.uuid, DI.provideWheels()!![0]!!.get()!!.uuid) @@ -65,7 +65,7 @@ class BindWheelTests { //Then assertEquals(wheel.uuid, DI.module().wheel()!!.uuid) - assertEquals(wheel.uuid, DI.provideWheel().uuid) + assertEquals(wheel.uuid, DI.provideWheel()?.uuid) assertEquals(wheel.uuid, DI.provideWheelRef()!!.get()!!.uuid) assertEquals(1, DI.provideWheels()!!.size) assertEquals(wheel.uuid, DI.provideWheels()!![0]!!.get()!!.uuid) diff --git a/tests_wraps_kotlin/src/test/kotlin/com/github/klee0kai/stone/kotlin/test/car/bindinstance/simple/BindWindowCollectionRefTests.kt b/tests_wraps_kotlin/src/test/kotlin/com/github/klee0kai/stone/kotlin/test/car/bindinstance/simple/BindWindowCollectionRefTests.kt index ccfa015e..0b0db8fe 100644 --- a/tests_wraps_kotlin/src/test/kotlin/com/github/klee0kai/stone/kotlin/test/car/bindinstance/simple/BindWindowCollectionRefTests.kt +++ b/tests_wraps_kotlin/src/test/kotlin/com/github/klee0kai/stone/kotlin/test/car/bindinstance/simple/BindWindowCollectionRefTests.kt @@ -21,7 +21,7 @@ class BindWindowCollectionRefTests { //Then assertEquals(window.uuid, DI.module().windows()!!.get()!![0]!!.uuid) - assertEquals(window.uuid, DI.provideWindow().uuid) + assertEquals(window.uuid, DI.provideWindow()?.uuid) assertEquals(1, DI.provideWindows()!!.size) assertEquals(window.uuid, ArrayList(DI.provideWindows())[0]!!.uuid) } diff --git a/tests_wraps_kotlin/src/test/kotlin/com/github/klee0kai/stone/kotlin/test/car/bindinstance/simple/BindWindowCollectionTests.kt b/tests_wraps_kotlin/src/test/kotlin/com/github/klee0kai/stone/kotlin/test/car/bindinstance/simple/BindWindowCollectionTests.kt index 3d81784d..69ce283c 100644 --- a/tests_wraps_kotlin/src/test/kotlin/com/github/klee0kai/stone/kotlin/test/car/bindinstance/simple/BindWindowCollectionTests.kt +++ b/tests_wraps_kotlin/src/test/kotlin/com/github/klee0kai/stone/kotlin/test/car/bindinstance/simple/BindWindowCollectionTests.kt @@ -18,7 +18,7 @@ class BindWindowCollectionTests { //Then assertEquals(window.uuid, DI.module().windows()!!.get()!![0]!!.uuid) - assertEquals(window.uuid, DI.provideWindow().uuid) + assertEquals(window.uuid, DI.provideWindow()?.uuid) assertEquals(1, DI.provideWindows()!!.size) assertEquals(window.uuid, ArrayList(DI.provideWindows())[0]!!.uuid) } diff --git a/tests_wraps_kotlin/src/test/kotlin/com/github/klee0kai/stone/kotlin/test/car/bindinstance/simple/BindWindowTests.kt b/tests_wraps_kotlin/src/test/kotlin/com/github/klee0kai/stone/kotlin/test/car/bindinstance/simple/BindWindowTests.kt index 1fcaf314..64d2577d 100644 --- a/tests_wraps_kotlin/src/test/kotlin/com/github/klee0kai/stone/kotlin/test/car/bindinstance/simple/BindWindowTests.kt +++ b/tests_wraps_kotlin/src/test/kotlin/com/github/klee0kai/stone/kotlin/test/car/bindinstance/simple/BindWindowTests.kt @@ -44,7 +44,7 @@ class BindWindowTests { //Then assertEquals(window.uuid, DI.module().windows()!!.get()!![0]!!.uuid) - assertEquals(window.uuid, DI.provideWindow().uuid) + assertEquals(window.uuid, DI.provideWindow()?.uuid) assertEquals(1, DI.provideWindows()!!.size) assertEquals(window.uuid, ArrayList(DI.provideWindows())[0]!!.uuid) } @@ -61,7 +61,7 @@ class BindWindowTests { //Then assertEquals(window.uuid, DI.module().windows()!!.get()!![0]!!.uuid) - assertEquals(window.uuid, DI.provideWindow().uuid) + assertEquals(window.uuid, DI.provideWindow()?.uuid) assertEquals(1, DI.provideWindows()!!.size) assertEquals(window.uuid, ArrayList(DI.provideWindows())[0]!!.uuid) } From a7d70054a1a949d0f4cbb9264af148ddab286565 Mon Sep 17 00:00:00 2001 From: klee0kai Date: Tue, 6 Jan 2026 16:18:23 +0100 Subject: [PATCH 091/122] add Ignore Qualifier to the new pattern --- .../klee0kai/thekey/stone/ksp/Processor.kt | 2 +- .../stone/ksp/helpers/wrap/WrapHelper.kt | 19 ++++++------ .../target/component/GenComponentProcessor.kt | 3 +- .../test/car/di/bestOf/both/BothCarModule.kt | 17 +++++++++-- .../lists/cached/CarMultiCachedComponent.kt | 11 +++++++ .../car/di/lists/factory/CarMultiComponent.kt | 3 ++ .../test/car/di/qualifiers/CarQCModule.kt | 30 ++++++++++--------- .../test/car/di/qualifiers/CarQComponent.kt | 5 +++- .../create/CarWrappedCreateComponent.kt | 13 ++++++++ .../com/github/klee0kai/test/car/model/Car.kt | 6 +++- .../klee0kai/test/car/model/CarInjectLists.kt | 14 ++++++++- .../test/car/wrapper/CarSingleWrapperTests.kt | 2 ++ 12 files changed, 94 insertions(+), 31 deletions(-) diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/Processor.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/Processor.kt index 3389e645..648a1b8d 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/Processor.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/Processor.kt @@ -64,7 +64,7 @@ class Processor( // force changes // debug = true -// debugPkgFilter = "com.github.klee0kai.test.boxed.di.inject" +// debugPkgFilter = "com.github.klee0kai.test.car.di.bindinstance.simple" } diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/wrap/WrapHelper.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/wrap/WrapHelper.kt index 52ec9e5a..672fdc9a 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/wrap/WrapHelper.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/wrap/WrapHelper.kt @@ -95,7 +95,6 @@ class WrapHelper { providingType: TypeName, wannaType: TypeName, code: CodeBlock - ): CodeBlock { if (providingType == wannaType) return code @@ -150,9 +149,10 @@ class WrapHelper { unwrapPath.pollFirst() unwrapPathNames.pollFirst() - currentNullable = (unwrapPath.firstOrNull()?.typeName - ?: wrapPath.firstOrNull()?.typeName - ?: wannaType).isNullable + currentNullable = ( + wrapPath.firstOrNull()?.typeName?.let { paramType(it) } + ?: wannaType) + .isNullable codeBuilder = unwrapType.unwrap.formatCode( or = codeBuilder.build(), @@ -199,7 +199,7 @@ class WrapHelper { wrap = { or, srcNullable, targetNullable, argTypeNullable -> codeBlock { when { - !srcNullable || argTypeNullable -> add("%T( %L )", creator, or) + !srcNullable -> add("%T( %L )", creator, or) targetNullable -> add("%L?.let{ %T( it ) }", or, creator) else -> add("%T( %L!! )", creator, or) } @@ -208,7 +208,6 @@ class WrapHelper { unwrap = { or, srcNullable, targetNullable -> codeBlock { when { - !srcNullable && targetNullable -> add("%L.get()", or) targetNullable -> add("%L?.get()", or) else -> add("%L!!.get()!!", or) } @@ -236,8 +235,8 @@ class WrapHelper { unwrap = { or, srcNullable, targetNullable -> codeBlock { when { - !srcNullable -> add("%L.value", or) targetNullable -> add("%L?.value", or) + !srcNullable -> add("%L.value", or) else -> add("%L!!.value", or) } } @@ -270,8 +269,8 @@ class WrapHelper { unwrap = { or, srcNullable, targetNullable -> codeBlock { when { - !srcNullable && !targetNullable -> add("%L.get()", or) targetNullable -> add("%L?.get()", or) + !srcNullable -> add("%L.get()", or) else -> add("%L!!.get()!!", or) } } @@ -308,8 +307,8 @@ class WrapHelper { unwrap = { or, srcNullable, targetNullable -> codeBlock { when { + targetNullable -> add("%L?.firstOrNull()", or) !srcNullable -> add("%L.first()", or) - targetNullable -> add("%L?.first()", or) else -> add("%L!!.first()", or) } } @@ -321,7 +320,7 @@ class WrapHelper { //no transforms add(originalListCode) } else { - add("%L!!.map{ it -> %L }", originalListCode, itemTransform) + add("( %L?.map{ it -> %L } ?: emptyList() )", originalListCode, itemTransform) } if (wrapper.rawType() != originalListType.rawType()) { diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/component/GenComponentProcessor.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/component/GenComponentProcessor.kt index 97c915f8..bd2981e0 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/component/GenComponentProcessor.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/component/GenComponentProcessor.kt @@ -29,6 +29,7 @@ import com.github.klee0kai.thekey.stone.ksp.ksp.getAllMethods import com.github.klee0kai.thekey.stone.ksp.ksp.resolveAlias import com.github.klee0kai.thekey.stone.ksp.ksp.resolveNotNullable import com.github.klee0kai.thekey.stone.ksp.poet.* +import com.github.klee0kai.thekey.stone.ksp.target.component.GenComponentProcessor.DelayedCodeBlocks import com.github.klee0kai.thekey.stone.ksp.target.module.GenModuleProcessor import com.google.devtools.ksp.KspExperimental import com.google.devtools.ksp.containingFile @@ -347,7 +348,7 @@ class GenComponentProcessor : TargetFileProcessor { val isListCache = wrapHelper.isList(cacheControlInvoke!!.rawReturnType()) val cacheControlType = if (isListCache) { - List::class.asClassName().parameterizedBy(nonWrappedBindType).copy(nullable = true) + List::class.asClassName().parameterizedBy(nonWrappedBindType.copy(nullable = true)) } else { nonWrappedBindType.copy(nullable = true) } diff --git a/tests_wraps_kotlin/src/main/kotlin/com/github/klee0kai/test/car/di/bestOf/both/BothCarModule.kt b/tests_wraps_kotlin/src/main/kotlin/com/github/klee0kai/test/car/di/bestOf/both/BothCarModule.kt index 802675e1..d6f89edb 100644 --- a/tests_wraps_kotlin/src/main/kotlin/com/github/klee0kai/test/car/di/bestOf/both/BothCarModule.kt +++ b/tests_wraps_kotlin/src/main/kotlin/com/github/klee0kai/test/car/di/bestOf/both/BothCarModule.kt @@ -2,6 +2,7 @@ package com.github.klee0kai.test.car.di.bestOf.both import com.github.klee0kai.stone.annotations.module.Module import com.github.klee0kai.stone.annotations.module.Provide +import com.github.klee0kai.stone.annotations.qualifier.IgnoreQualifier import com.github.klee0kai.stone.weakref.Ref import com.github.klee0kai.test.car.model.Bumper import com.github.klee0kai.test.car.model.Car @@ -14,6 +15,7 @@ import javax.inject.Provider @Module abstract class BothCarModule { + @Provide(cache = Provide.CacheType.Weak) open fun fourWheels(): List { return Arrays.asList(Wheel(), Wheel(), Wheel(), Wheel()) @@ -43,9 +45,20 @@ abstract class BothCarModule { @Named("redCar") @Provide(cache = Provide.CacheType.Weak) - abstract fun redCar(bumper: Bumper, wheel: Wheel, window: Window): List + abstract fun redCar( + bumper: Bumper, + wheel: Wheel, + window: Window, + ): List @Named("blueCar") @Provide(cache = Provide.CacheType.Weak) - abstract fun blueCar(bumpers: List, wheels: List, windows: List): Car + abstract fun blueCar( + @IgnoreQualifier + bumpers: List, + @IgnoreQualifier + wheels: List, + @IgnoreQualifier + windows: List, + ): Car } diff --git a/tests_wraps_kotlin/src/main/kotlin/com/github/klee0kai/test/car/di/lists/cached/CarMultiCachedComponent.kt b/tests_wraps_kotlin/src/main/kotlin/com/github/klee0kai/test/car/di/lists/cached/CarMultiCachedComponent.kt index 12096c04..97ae618b 100644 --- a/tests_wraps_kotlin/src/main/kotlin/com/github/klee0kai/test/car/di/lists/cached/CarMultiCachedComponent.kt +++ b/tests_wraps_kotlin/src/main/kotlin/com/github/klee0kai/test/car/di/lists/cached/CarMultiCachedComponent.kt @@ -1,6 +1,7 @@ package com.github.klee0kai.test.car.di.lists.cached import com.github.klee0kai.stone.annotations.component.Component +import com.github.klee0kai.stone.annotations.qualifier.IgnoreQualifier import com.github.klee0kai.stone.weakref.Ref import com.github.klee0kai.test.car.model.Bumper import com.github.klee0kai.test.car.model.Car @@ -11,11 +12,21 @@ import javax.inject.Provider @Component interface CarMultiCachedComponent { + fun cachedModule(): CarMultiCachedModule? + fun singleBumper(): Ref? + + @IgnoreQualifier fun wheels(): List?>?>? + fun wheel(): Wheel? + + @IgnoreQualifier fun windows(): List?>? + + @IgnoreQualifier fun windowsProviding(): List?>?>? + fun cars(): List? } diff --git a/tests_wraps_kotlin/src/main/kotlin/com/github/klee0kai/test/car/di/lists/factory/CarMultiComponent.kt b/tests_wraps_kotlin/src/main/kotlin/com/github/klee0kai/test/car/di/lists/factory/CarMultiComponent.kt index ced07628..edd5d595 100644 --- a/tests_wraps_kotlin/src/main/kotlin/com/github/klee0kai/test/car/di/lists/factory/CarMultiComponent.kt +++ b/tests_wraps_kotlin/src/main/kotlin/com/github/klee0kai/test/car/di/lists/factory/CarMultiComponent.kt @@ -18,12 +18,15 @@ interface CarMultiComponent { fun singleBumper(): Ref? + @IgnoreQualifier fun wheels(): List?>?>? fun wheel(): Wheel? + @IgnoreQualifier fun windows(): List?>? + @IgnoreQualifier fun windowsProviding(): List?>?>? @IgnoreQualifier diff --git a/tests_wraps_kotlin/src/main/kotlin/com/github/klee0kai/test/car/di/qualifiers/CarQCModule.kt b/tests_wraps_kotlin/src/main/kotlin/com/github/klee0kai/test/car/di/qualifiers/CarQCModule.kt index f2474e8a..13550568 100644 --- a/tests_wraps_kotlin/src/main/kotlin/com/github/klee0kai/test/car/di/qualifiers/CarQCModule.kt +++ b/tests_wraps_kotlin/src/main/kotlin/com/github/klee0kai/test/car/di/qualifiers/CarQCModule.kt @@ -2,6 +2,7 @@ package com.github.klee0kai.test.car.di.qualifiers import com.github.klee0kai.stone.annotations.module.Module import com.github.klee0kai.stone.annotations.module.Provide +import com.github.klee0kai.stone.annotations.qualifier.IgnoreQualifier import com.github.klee0kai.test.car.di.qualifiers.qualifiers.* import com.github.klee0kai.test.car.model.Bumper import com.github.klee0kai.test.car.model.Car @@ -63,8 +64,8 @@ open class CarQCModule { @Provide(cache = Provide.CacheType.Factory) open fun carNamedA( @BumperQualifier(type = BumperQualifier.BumperType.Reinforced) bumper: List, - wheel: List, - window: List + @IgnoreQualifier wheel: List, + @IgnoreQualifier window: List ): Car { val car = Car(bumper, wheel, window) car.qualifier = "named_a" @@ -75,8 +76,8 @@ open class CarQCModule { @Provide(cache = Provide.CacheType.Factory) open fun carMyQualifier( @BumperQualifier bumper: List, - wheel: List, - window: List + @IgnoreQualifier wheel: List, + @IgnoreQualifier window: List ): Car { val car = Car(bumper, wheel, window) car.qualifier = "my_qualifier" @@ -88,7 +89,7 @@ open class CarQCModule { open fun carIdQualifier( @BumperQualifier bumper: List, wheel: List, - window: List + @IgnoreQualifier window: List ): Car { val car = Car(bumper, wheel, window) car.qualifier = "my_qualifier_with_string" @@ -98,9 +99,10 @@ open class CarQCModule { @MyQualifierWithString(id = "a") @Provide(cache = Provide.CacheType.Factory) open fun carIdQualifierA( - @BumperQualifier(type = BumperQualifier.BumperType.Reinforced) bumper: List, + @BumperQualifier(type = BumperQualifier.BumperType.Reinforced) + bumper: List, @WheelCount(count = 4) wheel: List, - window: List + @IgnoreQualifier window: List ): Car { val car = Car(bumper, wheel, window) car.qualifier = "my_qualifier_a" @@ -111,8 +113,8 @@ open class CarQCModule { @Provide(cache = Provide.CacheType.Factory) open fun carIdQualifierB( @BumperQualifier bumper: List, - wheel: List, - window: List + @IgnoreQualifier wheel: List, + @IgnoreQualifier window: List, ): Car { val car = Car(bumper, wheel, window) car.qualifier = "my_qualifier_b" @@ -124,7 +126,7 @@ open class CarQCModule { open fun carQualifierMulti( @BumperQualifier bumper: List, @WheelCount(count = 4) wheel: List, - window: List + @IgnoreQualifier window: List ): Car { val car = Car(bumper, wheel, window) car.qualifier = "qualifier_multi" @@ -135,8 +137,8 @@ open class CarQCModule { @Provide(cache = Provide.CacheType.Factory) open fun carQualifierMultiA1( @BumperQualifier bumper: List, - wheel: List, - window: List + @IgnoreQualifier wheel: List, + @IgnoreQualifier window: List ): Car { val car = Car(bumper, wheel, window) car.qualifier = "qualifier_multi_a1" @@ -148,7 +150,7 @@ open class CarQCModule { open fun carQualifierMultiA2( @BumperQualifier(type = BumperQualifier.BumperType.Reinforced) bumper: List, @WheelCount(count = 4) wheel: List, - window: List + @IgnoreQualifier window: List, ): Car { val car = Car(bumper, wheel, window) car.qualifier = "qualifier_multi_a2" @@ -160,7 +162,7 @@ open class CarQCModule { open fun carQualifierMultiA2Hard( @BumperQualifier(type = BumperQualifier.BumperType.Simple) bumper: List, @WheelCount(count = 4) wheel: List, - window: List + @IgnoreQualifier window: List ): Car { val car = Car(bumper, wheel, window) car.qualifier = "qualifier_multi_a2_hard" diff --git a/tests_wraps_kotlin/src/main/kotlin/com/github/klee0kai/test/car/di/qualifiers/CarQComponent.kt b/tests_wraps_kotlin/src/main/kotlin/com/github/klee0kai/test/car/di/qualifiers/CarQComponent.kt index 673057f2..5cd316b0 100644 --- a/tests_wraps_kotlin/src/main/kotlin/com/github/klee0kai/test/car/di/qualifiers/CarQComponent.kt +++ b/tests_wraps_kotlin/src/main/kotlin/com/github/klee0kai/test/car/di/qualifiers/CarQComponent.kt @@ -1,6 +1,7 @@ package com.github.klee0kai.test.car.di.qualifiers -import com.github.klee0kai.stone.annotations.component.* +import com.github.klee0kai.stone.annotations.component.Component +import com.github.klee0kai.stone.annotations.qualifier.IgnoreQualifier import com.github.klee0kai.test.car.di.qualifiers.qualifiers.MyQualifier import com.github.klee0kai.test.car.di.qualifiers.qualifiers.MyQualifierMulti import com.github.klee0kai.test.car.di.qualifiers.qualifiers.MyQualifierWithString @@ -42,6 +43,8 @@ interface CarQComponent { @MyQualifierMulti(type = MyQualifierMulti.Type.HARD, indx = 2, id = "a") fun carMyQualifierMultiA2Hard(): Car? + + @IgnoreQualifier fun allCars(): List? @Named diff --git a/tests_wraps_kotlin/src/main/kotlin/com/github/klee0kai/test/car/di/wrapped/create/CarWrappedCreateComponent.kt b/tests_wraps_kotlin/src/main/kotlin/com/github/klee0kai/test/car/di/wrapped/create/CarWrappedCreateComponent.kt index 311ae748..1afa774a 100644 --- a/tests_wraps_kotlin/src/main/kotlin/com/github/klee0kai/test/car/di/wrapped/create/CarWrappedCreateComponent.kt +++ b/tests_wraps_kotlin/src/main/kotlin/com/github/klee0kai/test/car/di/wrapped/create/CarWrappedCreateComponent.kt @@ -12,17 +12,30 @@ import javax.inject.Provider @Component interface CarWrappedCreateComponent { fun factory(): CarWrappedCreateModule? + fun wheel(): Wheel? + fun wheelProvide(): Provider? + fun wheelLazy(): LazyProvide? + fun wheelWeak(): WeakReference? + fun whellProviderWeak(): Provider?>? + fun whellLazyProviderWeak(): LazyProvide?>?>? + fun whellProvider(): Provider? + fun carLazy(): LazyProvide? + fun carProvider(): Provider? + fun carWeak(): WeakReference? + fun window(): Window? + fun car(): Car? + fun carAsync(): AsyncCoroutineProvide? } diff --git a/tests_wraps_kotlin/src/main/kotlin/com/github/klee0kai/test/car/model/Car.kt b/tests_wraps_kotlin/src/main/kotlin/com/github/klee0kai/test/car/model/Car.kt index 0e7707b6..cfed4b6f 100644 --- a/tests_wraps_kotlin/src/main/kotlin/com/github/klee0kai/test/car/model/Car.kt +++ b/tests_wraps_kotlin/src/main/kotlin/com/github/klee0kai/test/car/model/Car.kt @@ -1,13 +1,17 @@ package com.github.klee0kai.test.car.model +import com.github.klee0kai.stone.annotations.qualifier.IgnoreQualifier import java.util.* class Car { var uuid = UUID.randomUUID().toString() var bumpers: List? + var wheels: List? + var windows: List? + var qualifier: String? = null constructor( @@ -21,7 +25,7 @@ class Car { windows = listOf(window) } - constructor(bumpers: List, wheels: List, windows: List) { + constructor(bumpers: List, wheels: List, windows: List) { createCount++ this.bumpers = bumpers this.wheels = wheels diff --git a/tests_wraps_kotlin/src/main/kotlin/com/github/klee0kai/test/car/model/CarInjectLists.kt b/tests_wraps_kotlin/src/main/kotlin/com/github/klee0kai/test/car/model/CarInjectLists.kt index f136d87c..9de7e4e4 100644 --- a/tests_wraps_kotlin/src/main/kotlin/com/github/klee0kai/test/car/model/CarInjectLists.kt +++ b/tests_wraps_kotlin/src/main/kotlin/com/github/klee0kai/test/car/model/CarInjectLists.kt @@ -1,15 +1,20 @@ package com.github.klee0kai.test.car.model +import com.github.klee0kai.stone.annotations.qualifier.IgnoreQualifier import javax.inject.Inject class CarInjectLists { + @Inject + @IgnoreQualifier var bumpers: List? = null @Inject + @IgnoreQualifier var wheels: List? = null @Inject + @IgnoreQualifier var windows: List? = null @@ -18,7 +23,14 @@ class CarInjectLists { var windowsMethodFrom: List? = null @Inject - fun init(bumpers: List?, wheels: List?, windows: List?) { + fun init( + @IgnoreQualifier + bumpers: List?, + @IgnoreQualifier + wheels: List?, + @IgnoreQualifier + windows: List?, + ) { bumpersMethodFrom = bumpers wheelsMethodFrom = wheels windowsMethodFrom = windows diff --git a/tests_wraps_kotlin/src/test/kotlin/com/github/klee0kai/stone/kotlin/test/car/wrapper/CarSingleWrapperTests.kt b/tests_wraps_kotlin/src/test/kotlin/com/github/klee0kai/stone/kotlin/test/car/wrapper/CarSingleWrapperTests.kt index f98b968e..e87372df 100644 --- a/tests_wraps_kotlin/src/test/kotlin/com/github/klee0kai/stone/kotlin/test/car/wrapper/CarSingleWrapperTests.kt +++ b/tests_wraps_kotlin/src/test/kotlin/com/github/klee0kai/stone/kotlin/test/car/wrapper/CarSingleWrapperTests.kt @@ -5,11 +5,13 @@ import com.github.klee0kai.test.car.model.Bumper import com.github.klee0kai.test.car.model.Car import com.github.klee0kai.test.car.model.Wheel import com.github.klee0kai.test.car.model.Window +import kotlinx.coroutines.delay import kotlinx.coroutines.runBlocking import org.junit.jupiter.api.Assertions.assertEquals import org.junit.jupiter.api.Assertions.assertNotNull import org.junit.jupiter.api.BeforeEach import org.junit.jupiter.api.Test +import kotlin.time.Duration.Companion.milliseconds class CarSingleWrapperTests { From a971614281da777e222f64553929c1f1c7434952 Mon Sep 17 00:00:00 2001 From: klee0kai Date: Wed, 7 Jan 2026 20:56:46 +0100 Subject: [PATCH 092/122] fix qualifier processing --- .../klee0kai/thekey/stone/ksp/Processor.kt | 2 +- .../ksp/helpers/invokecall/InvokeCall.kt | 46 +++++++------------ .../ksp/helpers/invokecall/ModulesGraph.kt | 27 ++++++++--- .../helpers/invokecall/model/QualifierAnn.kt | 18 ++++++++ .../stone/ksp/helpers/wrap/WrapHelper.kt | 10 ++-- .../ksp/target/module/GenModuleProcessor.kt | 18 ++++++-- .../__hidden__/coroutines/CoroutinesExt.kt | 9 ++++ .../__hidden__/types/holders/MapItemHolder.kt | 18 +++++++- .../types/holders/SingleItemHolder.kt | 12 ++++- .../coroutines/CoroutinesExt.jvm.kt | 14 ++++++ .../coroutines/CoroutinesExt.linux.kt | 5 ++ .../coroutines/CoroutinesExt.native.kt | 12 +++++ .../coroutines/CoroutinesExt.web.kt | 8 ++++ .../test/di/techfactory/TechFactoryModule.kt | 1 + .../car/di/cachecontrol/gc/WindowGcModule.kt | 2 +- .../lists/cached/CarMultiCachedComponent.kt | 2 +- .../di/lists/cached/CarMultiCachedModule.kt | 15 ++++-- .../car/di/lists/factory/CarMultiComponent.kt | 2 +- .../test/car/di/qualifiers/CarQCModule.kt | 4 +- .../test/car/di/qualifiers/CarQComponent.kt | 5 +- .../com/github/klee0kai/test/car/model/Car.kt | 1 - .../test/car/model/CarsInjectQualifiers.kt | 5 +- .../cachecontrol/gc/WindowPartialGcTests.kt | 6 +-- .../test/car/muti/MultiCachedProvideTest.kt | 3 +- .../CarInjectAllMethodsWithQualifiersTest.kt | 2 +- 25 files changed, 181 insertions(+), 66 deletions(-) create mode 100644 stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/__hidden__/coroutines/CoroutinesExt.kt create mode 100644 stone_multiplatform/src/jvmMain/java/com/github/klee0kai/stone/__hidden__/coroutines/CoroutinesExt.jvm.kt create mode 100644 stone_multiplatform/src/linuxMain/kotlin/com/github/klee0kai/stone/__hidden__/coroutines/CoroutinesExt.linux.kt create mode 100644 stone_multiplatform/src/nativeMain/kotlin/com/github/klee0kai/stone/__hidden__/coroutines/CoroutinesExt.native.kt create mode 100644 stone_multiplatform/src/webMain/kotlin/com/github/klee0kai/stone/__hidden__/coroutines/CoroutinesExt.web.kt diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/Processor.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/Processor.kt index 648a1b8d..ecd32fb2 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/Processor.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/Processor.kt @@ -64,7 +64,7 @@ class Processor( // force changes // debug = true -// debugPkgFilter = "com.github.klee0kai.test.car.di.bindinstance.simple" +// debugPkgFilter = "com.github.klee0kai.test.car.di.qualifiers" } diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/invokecall/InvokeCall.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/invokecall/InvokeCall.kt index 8565509f..b29e3aa2 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/invokecall/InvokeCall.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/invokecall/InvokeCall.kt @@ -4,7 +4,6 @@ import com.github.klee0kai.stone.__hidden__.provide.ProvideBuilder import com.github.klee0kai.thekey.stone.ksp.helpers.invokecall.model.FieldDetail import com.github.klee0kai.thekey.stone.ksp.helpers.invokecall.model.MethodDetail import com.github.klee0kai.thekey.stone.ksp.helpers.invokecall.model.QualifierAnn -import com.github.klee0kai.thekey.stone.ksp.helpers.invokecall.model.anyIgnoreQualifier import com.github.klee0kai.thekey.stone.ksp.helpers.wrap.WrapHelper import com.github.klee0kai.thekey.stone.ksp.poet.codeBlock import com.github.klee0kai.thekey.stone.ksp.utils.LocalFieldName @@ -25,6 +24,7 @@ import java.util.* class InvokeCall( var wrapHelper: WrapHelper, val invokeSequenceVariants: List>, + val qualifierAnnotations: Set, val flags: InvokeProvideFlags = InvokeProvideFlags(), ) { @@ -32,26 +32,6 @@ class InvokeCall( fun bestSequence(): List = invokeSequenceVariants[0] - fun qualifierAnnotations( - crossing: Boolean, - ): Set { - val allQualifiersLists = LinkedList>() - for (variant in invokeSequenceVariants) { - val qualifiers = HashSet() - for (m in variant) qualifiers.addAll(m.qualifierAnns) - allQualifiersLists.add(qualifiers) - } - if (allQualifiersLists.isEmpty()) return mutableSetOf() - - val allQualifiers = allQualifiersLists[0] - if (crossing) { - for (q in allQualifiersLists) allQualifiers.retainAll(q) - } else { - for (q in allQualifiersLists) allQualifiers.addAll(q) - } - return allQualifiers - } - /** * Using arguments in invoke sequence * @@ -86,7 +66,11 @@ class InvokeCall( return invokeSequence[invokeSequence.size - 1].returnType } - fun best() = InvokeCall.fromSequence(wrapHelper, bestSequence()) + fun best() = InvokeCall.fromSequence( + wrapHelper, + callSequence = bestSequence(), + qualifierAnnotations = qualifierAnnotations, + ) /** * Generate invoke code bloke @@ -136,7 +120,7 @@ class InvokeCall( listFieldName, ) for (sequence in invokeSequenceVariants) { - val invokeCall = InvokeCall.fromSequence(wrapHelper, sequence) + val invokeCall = InvokeCall.fromSequence(wrapHelper, sequence, qualifierAnnotations = qualifierAnnotations) val seqCodeBlock = invokeCall.invokeCode(declaredFields) if (wrapHelper.isList(invokeCall.rawReturnType())) { @@ -174,15 +158,14 @@ class InvokeCall( val typeFields = envFields.filter { f -> wrapHelper.nonWrappedType(f.type) == wrapHelper.nonWrappedType(arg.type) } - var field = if (isWannaList) typeFields.firstOrNull { f -> - wrapHelper.isList(f.type) - && (arg.qualifierAnns.anyIgnoreQualifier() || arg.qualifierAnns == f.qualifierAnns) + var field = if (isWannaList) typeFields.lastOrNull { f -> + wrapHelper.isList(f.type) && (arg.qualifierAnns == f.qualifierAnns) } else null if (field == null) { //non list field = typeFields.firstOrNull { f -> - (arg.qualifierAnns.anyIgnoreQualifier() || arg.qualifierAnns == f.qualifierAnns) + (arg.qualifierAnns == f.qualifierAnns) } } @@ -197,7 +180,7 @@ class InvokeCall( override fun toString(): String { val builder = StringBuilder() if (invokeSequenceVariants.size <= 1) { - for (qualifierAnn in qualifierAnnotations(false)) { + for (qualifierAnn in qualifierAnnotations) { builder.append(qualifierAnn.toString()) .append(" ") } @@ -234,19 +217,24 @@ class InvokeCall( fun InvokeCall.Companion.fromSequence( wrapHelper: WrapHelper, callSequence: List, + qualifierAnnotations: Set? = null, flags: InvokeProvideFlags = InvokeProvideFlags(), ) = InvokeCall( wrapHelper = wrapHelper, invokeSequenceVariants = listOf(callSequence), flags = flags, + qualifierAnnotations = qualifierAnnotations ?: callSequence.lastOrNull()?.qualifierAnns ?: emptySet() + ) fun InvokeCall.Companion.fromVariants( wrapHelper: WrapHelper, variants: List, + qualifierAnnotations: Set, ) = InvokeCall( wrapHelper = wrapHelper, invokeSequenceVariants = variants.flatMap { it.invokeSequenceVariants }, - flags = variants.fold(InvokeProvideFlags()) { acc, value -> acc.merge(value.flags) } + flags = variants.fold(InvokeProvideFlags()) { acc, value -> acc.merge(value.flags) }, + qualifierAnnotations = qualifierAnnotations, ) \ No newline at end of file diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/invokecall/ModulesGraph.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/invokecall/ModulesGraph.kt index e677d9b8..707f13d9 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/invokecall/ModulesGraph.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/invokecall/ModulesGraph.kt @@ -208,7 +208,7 @@ class ModulesGraph( var singleDepField = FieldDetail( name = genLocalFieldName(), type = inv.resultType(), - qualifierAnns = inv.qualifierAnnotations(false) + qualifierAnns = inv.qualifierAnnotations ) val listDepField = FieldDetail( name = genLocalFieldName(), @@ -217,11 +217,12 @@ class ModulesGraph( inv.resultType() ) ), - qualifierAnns = inv.qualifierAnnotations(false) + qualifierAnns = inv.qualifierAnnotations ) if (isSingleDepRequired) { if (isCacheProvide) { + codeBlock.add("// 1 ${inv.qualifierAnnotations.joinToString(",") { it.logString() }} \n") codeBlock.add("val %L = ", singleDepField.name) .add( wrapHelper.transform( @@ -238,6 +239,7 @@ class ModulesGraph( singleDepField = singleDepField .copy(type = Ref::class.asClassName().parameterizedBy(inv.resultType())) + codeBlock.add("// 2 ${inv.qualifierAnnotations.joinToString(",") { it.logString() }} \n") codeBlock.add("val %L = %T{ ", singleDepField.name, Ref::class) .add( wrapHelper.transform( @@ -253,6 +255,7 @@ class ModulesGraph( } if (isListDepRequired) { + codeBlock.add("// 3 ${inv.qualifierAnnotations.joinToString(",") { it.logString() }} \n") codeBlock.add("val %L = %T{ ", listDepField.name, listDepField.type) .add(inv.invokeAllToList(localVariables)) .addStatement(" } ") @@ -362,10 +365,14 @@ class ModulesGraph( provideTypeInvokes.add(invokeCall) } + if (provideTypeInvokes.filter { it.resultType() == provideDep.typeName } + .groupBy { it.qualifierAnnotations }.size > 1) { + throw StoneException("internal arch error") + } provideTypeInvokes = LinkedList( provideTypeInvokes.removeDoubles { it1, it2 -> it1.resultType() == it2.resultType() - && it1.qualifierAnnotations(crossing = false) == it2.qualifierAnnotations(crossing = false) + && it1.qualifierAnnotations == it2.qualifierAnnotations } ) provideTypeInvokes.reverse() @@ -404,11 +411,9 @@ class ModulesGraph( var filtered = invokeCalls.toList() if (qualifierAnns.none { it.typeName == IgnoreQualifier::class.asClassName() }) { - filtered = invokeCalls.filter { it.qualifierAnnotations(false) == qualifierAnns } + filtered = invokeCalls.filter { it.qualifierAnnotations == qualifierAnns } } - - filtered = if (provideMethodName != null) { filtered.filter { provideMethodName == it.bestSequence().last().methodName } } else filtered @@ -420,7 +425,15 @@ class ModulesGraph( filtered.joinToString(" and ") ) } - return if (!filtered.isEmpty()) InvokeCall.fromVariants(wrapHelper, variants = filtered.toList()) else null + return if (!filtered.isEmpty()) { + InvokeCall.fromVariants( + wrapHelper, + variants = filtered.toList(), + qualifierAnnotations = qualifierAnns, + ) + } else { + null + } } companion object { diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/invokecall/model/QualifierAnn.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/invokecall/model/QualifierAnn.kt index 28305ed4..542245e6 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/invokecall/model/QualifierAnn.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/invokecall/model/QualifierAnn.kt @@ -1,16 +1,34 @@ package com.github.klee0kai.thekey.stone.ksp.helpers.invokecall.model +import com.github.klee0kai.stone.annotations.qualifier.IgnoreQualifier import com.google.devtools.ksp.symbol.KSAnnotation +import com.squareup.kotlinpoet.ClassName import com.squareup.kotlinpoet.TypeName +import com.squareup.kotlinpoet.asTypeName import com.squareup.kotlinpoet.ksp.toClassName data class QualifierAnn( var typeName: TypeName, var values: Map = mapOf(), +) { + companion object; +} + +fun QualifierAnn.Companion.ignoreQualifier( +) = QualifierAnn( + typeName = IgnoreQualifier::class.asTypeName(), + values = emptyMap(), ) + fun KSAnnotation.toQualifierAnn( ) = QualifierAnn( typeName = annotationType.resolve().toClassName(), values = arguments.map { it.name?.asString()!! to it.value }.groupBy { it.first }, ) + +fun QualifierAnn.logString(): String { + val type = (typeName as? ClassName)?.simpleName ?: typeName + val value = values.values.joinToString(",") + return "${type}( $values )" +} \ No newline at end of file diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/wrap/WrapHelper.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/wrap/WrapHelper.kt index 672fdc9a..c8da8585 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/wrap/WrapHelper.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/wrap/WrapHelper.kt @@ -294,12 +294,14 @@ class WrapHelper { val wrapType = WrapType( typeName = wrapper, isNoCachingWrapper = false, - wrap = { or, srcNullable, targetNullable, _ -> + wrap = { or, srcNullable, targetNullable, argTypeNullable -> codeBlock { - add("listOfNotNull( %L ) ", or) when { - constructor != null && targetNullable -> add("?.let { %T(it) }", constructor) - constructor != null && !targetNullable -> add("!!.let { %T(it) }", constructor) + constructor != null && targetNullable -> add("%L?.let { %T(it) }", or, constructor) + targetNullable -> add("%L?.let { listOfNotNull( it ) }", or) + constructor != null && argTypeNullable -> add("%L!!.let { %T(it) }", or, constructor) + constructor != null -> add("%L!!.let { %T(it!!) }", or, constructor) + else -> add("listOfNotNull( %L )", or) } } diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/module/GenModuleProcessor.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/module/GenModuleProcessor.kt index 0a2ddf58..466024d4 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/module/GenModuleProcessor.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/module/GenModuleProcessor.kt @@ -111,6 +111,8 @@ class GenModuleProcessor : TargetFileProcessor { val fileSpec = genFileSpec(genModuleClassName.packageName, genModuleClassName.simpleName) { genLibComment() + addImport("com.github.klee0kai.stone.__hidden__.coroutines", "syncIfAvailable") + genClass(genModuleClassName) { if (moduleCl.classKind == ClassKind.INTERFACE) { addSuperinterface(moduleCl.toClassName()) @@ -267,6 +269,7 @@ class GenModuleProcessor : TargetFileProcessor { val setValueArg = function.parameters.firstOrNull { it.type.resolve().toTypeName() == returnType } genOverrideFun(function) { + beginControlFlow("return syncIfAvailable(%L.mutex)", overridedModuleFieldName) addStatement( "val cached = %L.get()?.%L( %T.getValueAction, %L ) ", overridedModuleFieldName, @@ -274,7 +277,7 @@ class GenModuleProcessor : TargetFileProcessor { CacheAction::class.asClassName(), idArguments.joinToString(", ") { it.name!!.asString() }, ) - addCode("if ( cached != null ) return ") + addCode("if ( cached != null ) return@syncIfAvailable ") addCode( wrapHelper.transform( providingType = wrapHelper.listWrapTypeIfNeed(returnType), @@ -295,7 +298,7 @@ class GenModuleProcessor : TargetFileProcessor { endControlFlow(); } - addCode("return ") + addCode("return@syncIfAvailable ") addCode( wrapHelper.transform( wrapHelper.listWrapTypeIfNeed(returnType).copy(nullable = true), @@ -303,6 +306,7 @@ class GenModuleProcessor : TargetFileProcessor { itemHolderCodeHelper.codeGetCachedValue(), ) ) + endControlFlow() } } @@ -314,6 +318,7 @@ class GenModuleProcessor : TargetFileProcessor { ) { val returnType = function.returnType?.resolve()?.toTypeName() ?: return genOverrideFun(function) { + beginControlFlow("return syncIfAvailable(%L.mutex)", overridedModuleFieldName) addStatement( "val cached = %L.get()?.%L( %T.getValueAction, %L ) ", overridedModuleFieldName, @@ -321,7 +326,7 @@ class GenModuleProcessor : TargetFileProcessor { CacheAction::class.asClassName(), idArguments.joinToString(", ") { it.name!!.asString() }, ) - addCode("if (cached != null ) return ") + addCode("if (cached != null ) return@syncIfAvailable ") addCode( wrapHelper.transform( wrapHelper.listWrapTypeIfNeed(returnType), @@ -352,7 +357,7 @@ class GenModuleProcessor : TargetFileProcessor { ) ) addCode("\n") - addCode("return ") + addCode("return@syncIfAvailable ") addCode( wrapHelper.transform( wrapHelper.listWrapTypeIfNeed(returnType).copy(nullable = true), @@ -360,6 +365,7 @@ class GenModuleProcessor : TargetFileProcessor { itemHolderCodeHelper.codeGetCachedValue(), ) ) + endControlFlow() } } @@ -379,6 +385,7 @@ class GenModuleProcessor : TargetFileProcessor { addParameter(it.name!!.asString(), it.type.resolve().toTypeName()) } + beginControlFlow("return syncIfAvailable(%L.mutex)", overridedModuleFieldName) addStatement( "%L.get()?.%L( __action, %L ) ", overridedModuleFieldName, @@ -415,8 +422,9 @@ class GenModuleProcessor : TargetFileProcessor { addStatement("null -> Unit") endControlFlow() - addCode("return ") + addCode("return@syncIfAvailable ") addCode(codeBlock = itemHolderCodeHelper.codeGetCachedValue()) + endControlFlow() } } diff --git a/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/__hidden__/coroutines/CoroutinesExt.kt b/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/__hidden__/coroutines/CoroutinesExt.kt new file mode 100644 index 00000000..6a0c067d --- /dev/null +++ b/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/__hidden__/coroutines/CoroutinesExt.kt @@ -0,0 +1,9 @@ +package com.github.klee0kai.stone.__hidden__.coroutines + +import kotlinx.coroutines.sync.Mutex + +expect fun T.syncIfAvailable( + mutex: Mutex, + block: T.() -> R +): R + diff --git a/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/__hidden__/types/holders/MapItemHolder.kt b/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/__hidden__/types/holders/MapItemHolder.kt index 77799c73..34c65a35 100644 --- a/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/__hidden__/types/holders/MapItemHolder.kt +++ b/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/__hidden__/types/holders/MapItemHolder.kt @@ -48,6 +48,20 @@ class MapItemHolder( } } + fun getListNullable( + key: Key?, + ): List? { + val holder = refMap[key] ?: return null + return when (curRefType) { + StoneRefType.ListObject -> holder as MutableList? + StoneRefType.ListWeakObject, StoneRefType.ListSoftObject -> { + (holder as MutableList?>?)?.map { it?.get() } + } + + else -> null + } + } + fun set( key: Key?, onlyIfNull: Boolean, @@ -118,7 +132,7 @@ class MapItemHolder( if (curRefType == refType) return if (defType.isList) { val listMap: HashMap?> = HashMap() - for (key in refMap.keys) listMap[key] = getList(key) + for (key in refMap.keys) listMap[key] = getListNullable(key) curRefType = refType.forList() for (key in listMap.keys) setList(key, onlyIfNull = false) { listMap[key] } } else { @@ -151,7 +165,7 @@ class MapItemHolder( } } else { for (key in keys) { - val list = getList(key) + val list = getListNullable(key) if (list?.none { it != null } == true) { refMap.remove(key) } diff --git a/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/__hidden__/types/holders/SingleItemHolder.kt b/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/__hidden__/types/holders/SingleItemHolder.kt index e1ad933e..2df577d4 100644 --- a/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/__hidden__/types/holders/SingleItemHolder.kt +++ b/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/__hidden__/types/holders/SingleItemHolder.kt @@ -7,13 +7,15 @@ import com.github.klee0kai.stone.weakref.Ref import kotlinx.atomicfu.atomic import kotlinx.coroutines.delay import kotlinx.coroutines.launch +import kotlinx.coroutines.sync.Mutex /** * Stone Private class */ @Suppress("UNCHECKED_CAST") class SingleItemHolder( - private val defType: StoneRefType + private val defType: StoneRefType, + val mutex: Mutex = Mutex(), ) { private var curRefType: StoneRefType = defType @@ -33,6 +35,12 @@ class SingleItemHolder( else -> null } + fun getListNullable(): List? = when (curRefType) { + StoneRefType.ListObject -> refHolder as MutableList? + StoneRefType.ListWeakObject, StoneRefType.ListSoftObject -> (refHolder as MutableList?>?)?.map { it?.get() } + else -> null + } + fun set( onlyIfNull: Boolean, @@ -100,7 +108,7 @@ class SingleItemHolder( ) { if (curRefType == refType) return if (defType.isList) { - val ob = this.getList() + val ob = this.getListNullable() curRefType = refType.forList() setList(onlyIfNull = false) { ob } } else { diff --git a/stone_multiplatform/src/jvmMain/java/com/github/klee0kai/stone/__hidden__/coroutines/CoroutinesExt.jvm.kt b/stone_multiplatform/src/jvmMain/java/com/github/klee0kai/stone/__hidden__/coroutines/CoroutinesExt.jvm.kt new file mode 100644 index 00000000..c9b841e6 --- /dev/null +++ b/stone_multiplatform/src/jvmMain/java/com/github/klee0kai/stone/__hidden__/coroutines/CoroutinesExt.jvm.kt @@ -0,0 +1,14 @@ +package com.github.klee0kai.stone.__hidden__.coroutines + +import kotlinx.coroutines.runBlocking +import kotlinx.coroutines.sync.Mutex +import kotlinx.coroutines.sync.withLock + +actual fun T.syncIfAvailable( + mutex: Mutex, + block: T.() -> R, +): R = runBlocking { + mutex.withLock { + block() + } +} diff --git a/stone_multiplatform/src/linuxMain/kotlin/com/github/klee0kai/stone/__hidden__/coroutines/CoroutinesExt.linux.kt b/stone_multiplatform/src/linuxMain/kotlin/com/github/klee0kai/stone/__hidden__/coroutines/CoroutinesExt.linux.kt new file mode 100644 index 00000000..d68e16a4 --- /dev/null +++ b/stone_multiplatform/src/linuxMain/kotlin/com/github/klee0kai/stone/__hidden__/coroutines/CoroutinesExt.linux.kt @@ -0,0 +1,5 @@ +package com.github.klee0kai.stone.__hidden__.coroutines + +actual fun T.syncIfAvailable(mutex: kotlinx.coroutines.sync.Mutex, block: T.() -> R): R { + TODO("Not yet implemented") +} \ No newline at end of file diff --git a/stone_multiplatform/src/nativeMain/kotlin/com/github/klee0kai/stone/__hidden__/coroutines/CoroutinesExt.native.kt b/stone_multiplatform/src/nativeMain/kotlin/com/github/klee0kai/stone/__hidden__/coroutines/CoroutinesExt.native.kt new file mode 100644 index 00000000..4683ce56 --- /dev/null +++ b/stone_multiplatform/src/nativeMain/kotlin/com/github/klee0kai/stone/__hidden__/coroutines/CoroutinesExt.native.kt @@ -0,0 +1,12 @@ +package com.github.klee0kai.stone.__hidden__.coroutines + +import kotlinx.coroutines.sync.Mutex + +actual fun T.syncIfAvailable( + mutex: Mutex, + block: T.() -> R +): R = block() + +actual fun T.syncIfAvailable(mutex: kotlinx.coroutines.sync.Mutex, block: T.() -> R): R { + TODO("Not yet implemented") +} \ No newline at end of file diff --git a/stone_multiplatform/src/webMain/kotlin/com/github/klee0kai/stone/__hidden__/coroutines/CoroutinesExt.web.kt b/stone_multiplatform/src/webMain/kotlin/com/github/klee0kai/stone/__hidden__/coroutines/CoroutinesExt.web.kt new file mode 100644 index 00000000..4a4df1b0 --- /dev/null +++ b/stone_multiplatform/src/webMain/kotlin/com/github/klee0kai/stone/__hidden__/coroutines/CoroutinesExt.web.kt @@ -0,0 +1,8 @@ +package com.github.klee0kai.stone.__hidden__.coroutines + +import kotlinx.coroutines.sync.Mutex + +actual fun T.syncIfAvailable( + mutex: Mutex, + block: T.() -> R, +): R = block() diff --git a/tests/src/main/java/com/github/klee0kai/test/di/techfactory/TechFactoryModule.kt b/tests/src/main/java/com/github/klee0kai/test/di/techfactory/TechFactoryModule.kt index 87645488..14e0c428 100644 --- a/tests/src/main/java/com/github/klee0kai/test/di/techfactory/TechFactoryModule.kt +++ b/tests/src/main/java/com/github/klee0kai/test/di/techfactory/TechFactoryModule.kt @@ -14,6 +14,7 @@ import javax.inject.Named @Module interface TechFactoryModule { + @Provide(cache = Provide.CacheType.Factory) fun battery(): Battery? diff --git a/tests_wraps_kotlin/src/main/kotlin/com/github/klee0kai/test/car/di/cachecontrol/gc/WindowGcModule.kt b/tests_wraps_kotlin/src/main/kotlin/com/github/klee0kai/test/car/di/cachecontrol/gc/WindowGcModule.kt index 4d0b538e..88153e63 100644 --- a/tests_wraps_kotlin/src/main/kotlin/com/github/klee0kai/test/car/di/cachecontrol/gc/WindowGcModule.kt +++ b/tests_wraps_kotlin/src/main/kotlin/com/github/klee0kai/test/car/di/cachecontrol/gc/WindowGcModule.kt @@ -30,6 +30,6 @@ open class WindowGcModule { @GcWindowScope @Provide(cache = Provide.CacheType.Strong) open fun windowStrong(): WeakReference> { - return WeakReference(Arrays.asList(Window(), Window(), Window())) + return WeakReference(listOf(Window(), Window(), Window())) } } diff --git a/tests_wraps_kotlin/src/main/kotlin/com/github/klee0kai/test/car/di/lists/cached/CarMultiCachedComponent.kt b/tests_wraps_kotlin/src/main/kotlin/com/github/klee0kai/test/car/di/lists/cached/CarMultiCachedComponent.kt index 97ae618b..2c4e8d4b 100644 --- a/tests_wraps_kotlin/src/main/kotlin/com/github/klee0kai/test/car/di/lists/cached/CarMultiCachedComponent.kt +++ b/tests_wraps_kotlin/src/main/kotlin/com/github/klee0kai/test/car/di/lists/cached/CarMultiCachedComponent.kt @@ -26,7 +26,7 @@ interface CarMultiCachedComponent { fun windows(): List?>? @IgnoreQualifier - fun windowsProviding(): List?>?>? + fun windowsProviding(): List?>?>? fun cars(): List? } diff --git a/tests_wraps_kotlin/src/main/kotlin/com/github/klee0kai/test/car/di/lists/cached/CarMultiCachedModule.kt b/tests_wraps_kotlin/src/main/kotlin/com/github/klee0kai/test/car/di/lists/cached/CarMultiCachedModule.kt index 9e8db5b8..e770e643 100644 --- a/tests_wraps_kotlin/src/main/kotlin/com/github/klee0kai/test/car/di/lists/cached/CarMultiCachedModule.kt +++ b/tests_wraps_kotlin/src/main/kotlin/com/github/klee0kai/test/car/di/lists/cached/CarMultiCachedModule.kt @@ -2,6 +2,7 @@ package com.github.klee0kai.test.car.di.lists.cached import com.github.klee0kai.stone.annotations.module.Module import com.github.klee0kai.stone.annotations.module.Provide +import com.github.klee0kai.stone.annotations.qualifier.IgnoreQualifier import com.github.klee0kai.stone.weakref.Ref import com.github.klee0kai.test.car.model.Bumper import com.github.klee0kai.test.car.model.Car @@ -39,12 +40,20 @@ abstract class CarMultiCachedModule { @Provide(cache = Provide.CacheType.Weak) open fun bumpers(): Collection { - return Arrays.asList(Bumper(), Bumper()) + return listOf(Bumper(), Bumper()) } @Provide(cache = Provide.CacheType.Weak) - abstract fun redCar(bumper: Bumper?, wheel: Wheel?, window: Window?): List? + abstract fun redCar( + bumper: Bumper?, + wheel: Wheel?, + window: Window?, + ): List? @Provide(cache = Provide.CacheType.Weak) - abstract fun blueCar(bumpers: List, wheels: List, windows: List): Car? + abstract fun blueCar( + @IgnoreQualifier bumpers: List, + @IgnoreQualifier wheels: List, + @IgnoreQualifier windows: List + ): Car? } diff --git a/tests_wraps_kotlin/src/main/kotlin/com/github/klee0kai/test/car/di/lists/factory/CarMultiComponent.kt b/tests_wraps_kotlin/src/main/kotlin/com/github/klee0kai/test/car/di/lists/factory/CarMultiComponent.kt index edd5d595..fe02e772 100644 --- a/tests_wraps_kotlin/src/main/kotlin/com/github/klee0kai/test/car/di/lists/factory/CarMultiComponent.kt +++ b/tests_wraps_kotlin/src/main/kotlin/com/github/klee0kai/test/car/di/lists/factory/CarMultiComponent.kt @@ -27,7 +27,7 @@ interface CarMultiComponent { fun windows(): List?>? @IgnoreQualifier - fun windowsProviding(): List?>?>? + fun windowsProviding(): List?>?>? @IgnoreQualifier fun cars(): List? diff --git a/tests_wraps_kotlin/src/main/kotlin/com/github/klee0kai/test/car/di/qualifiers/CarQCModule.kt b/tests_wraps_kotlin/src/main/kotlin/com/github/klee0kai/test/car/di/qualifiers/CarQCModule.kt index 13550568..c04e8e7d 100644 --- a/tests_wraps_kotlin/src/main/kotlin/com/github/klee0kai/test/car/di/qualifiers/CarQCModule.kt +++ b/tests_wraps_kotlin/src/main/kotlin/com/github/klee0kai/test/car/di/qualifiers/CarQCModule.kt @@ -52,7 +52,7 @@ open class CarQCModule { @Provide(cache = Provide.CacheType.Factory) open fun carNamedEmpty( @BumperQualifier bumper: List, - wheel: List, + @IgnoreQualifier wheel: List, window: List ): Car { val car = Car(bumper, wheel, window) @@ -88,7 +88,7 @@ open class CarQCModule { @Provide(cache = Provide.CacheType.Factory) open fun carIdQualifier( @BumperQualifier bumper: List, - wheel: List, + @IgnoreQualifier wheel: List, @IgnoreQualifier window: List ): Car { val car = Car(bumper, wheel, window) diff --git a/tests_wraps_kotlin/src/main/kotlin/com/github/klee0kai/test/car/di/qualifiers/CarQComponent.kt b/tests_wraps_kotlin/src/main/kotlin/com/github/klee0kai/test/car/di/qualifiers/CarQComponent.kt index 5cd316b0..61ba2c47 100644 --- a/tests_wraps_kotlin/src/main/kotlin/com/github/klee0kai/test/car/di/qualifiers/CarQComponent.kt +++ b/tests_wraps_kotlin/src/main/kotlin/com/github/klee0kai/test/car/di/qualifiers/CarQComponent.kt @@ -14,6 +14,8 @@ interface CarQComponent { fun module1(): CarQPModule? fun module2(): CarQCModule? + fun inject(carInject: CarsInjectQualifiers?) + @Named fun carNamedEmpty(): Car? @@ -52,5 +54,6 @@ interface CarQComponent { @MyQualifierMulti(type = MyQualifierMulti.Type.HARD, indx = 2, id = "a") fun carsMyQualifierMultiA2Hard(): List? - fun inject(carInject: CarsInjectQualifiers?) + + } diff --git a/tests_wraps_kotlin/src/main/kotlin/com/github/klee0kai/test/car/model/Car.kt b/tests_wraps_kotlin/src/main/kotlin/com/github/klee0kai/test/car/model/Car.kt index cfed4b6f..6a8deb2b 100644 --- a/tests_wraps_kotlin/src/main/kotlin/com/github/klee0kai/test/car/model/Car.kt +++ b/tests_wraps_kotlin/src/main/kotlin/com/github/klee0kai/test/car/model/Car.kt @@ -1,6 +1,5 @@ package com.github.klee0kai.test.car.model -import com.github.klee0kai.stone.annotations.qualifier.IgnoreQualifier import java.util.* class Car { diff --git a/tests_wraps_kotlin/src/main/kotlin/com/github/klee0kai/test/car/model/CarsInjectQualifiers.kt b/tests_wraps_kotlin/src/main/kotlin/com/github/klee0kai/test/car/model/CarsInjectQualifiers.kt index e2f6bb72..ce031d54 100644 --- a/tests_wraps_kotlin/src/main/kotlin/com/github/klee0kai/test/car/model/CarsInjectQualifiers.kt +++ b/tests_wraps_kotlin/src/main/kotlin/com/github/klee0kai/test/car/model/CarsInjectQualifiers.kt @@ -1,5 +1,6 @@ package com.github.klee0kai.test.car.model +import com.github.klee0kai.stone.annotations.qualifier.IgnoreQualifier import com.github.klee0kai.test.car.di.qualifiers.qualifiers.MyQualifier import com.github.klee0kai.test.car.di.qualifiers.qualifiers.MyQualifierMulti import com.github.klee0kai.test.car.di.qualifiers.qualifiers.MyQualifierWithString @@ -7,6 +8,7 @@ import javax.inject.Inject import javax.inject.Named class CarsInjectQualifiers { + @Inject @Named var carNamedEmpty: Car? = null @@ -48,6 +50,7 @@ class CarsInjectQualifiers { var carMyQualifierMultiA2Hard: Car? = null @Inject + @IgnoreQualifier var allCars: List? = null @Inject @@ -85,7 +88,7 @@ class CarsInjectQualifiers { @MyQualifierMulti(indx = 1, id = "a") carMyQualifierMultiA1: Car?, @MyQualifierMulti(indx = 2, id = "a") carMyQualifierMultiA2: Car?, @MyQualifierMulti(type = MyQualifierMulti.Type.HARD, id = "a", indx = 2) carMyQualifierMultiA2Hard: Car?, - allCars: List?, + @IgnoreQualifier allCars: List?, @Named carsNamedEmpty: List?, @MyQualifierMulti(type = MyQualifierMulti.Type.HARD, id = "a", indx = 2) carsMyQualifierMultiA2Hard: List? ) { diff --git a/tests_wraps_kotlin/src/test/kotlin/com/github/klee0kai/stone/kotlin/test/car/cachecontrol/gc/WindowPartialGcTests.kt b/tests_wraps_kotlin/src/test/kotlin/com/github/klee0kai/stone/kotlin/test/car/cachecontrol/gc/WindowPartialGcTests.kt index ccb12e01..ea77c92d 100644 --- a/tests_wraps_kotlin/src/test/kotlin/com/github/klee0kai/stone/kotlin/test/car/cachecontrol/gc/WindowPartialGcTests.kt +++ b/tests_wraps_kotlin/src/test/kotlin/com/github/klee0kai/stone/kotlin/test/car/cachecontrol/gc/WindowPartialGcTests.kt @@ -64,14 +64,14 @@ class WindowPartialGcTests { fun partialRecreateList2Test() { // Given val DI = CarGcComponentStoneComponent() - val uids1 = DI.windowsModule()!!.windowStrong().get()!!.map { it.uuid } - val holder = DI.windowsModule()!!.windowStrong().get()!![1] + val uids1 = DI.windowsModule().windowStrong().get()!!.map { it.uuid } + val holder = DI.windowsModule().windowStrong().get()!![1] //When resetKotlinRegisters() DI.gcAll() - val uids2 = DI.windowsModule()!!.windowStrong().get()!!.map { it.uuid } + val uids2 = DI.windowsModule().windowStrong().get()!!.map { it.uuid } // Then diff --git a/tests_wraps_kotlin/src/test/kotlin/com/github/klee0kai/stone/kotlin/test/car/muti/MultiCachedProvideTest.kt b/tests_wraps_kotlin/src/test/kotlin/com/github/klee0kai/stone/kotlin/test/car/muti/MultiCachedProvideTest.kt index bb4aa7cd..f0a48f44 100644 --- a/tests_wraps_kotlin/src/test/kotlin/com/github/klee0kai/stone/kotlin/test/car/muti/MultiCachedProvideTest.kt +++ b/tests_wraps_kotlin/src/test/kotlin/com/github/klee0kai/stone/kotlin/test/car/muti/MultiCachedProvideTest.kt @@ -7,6 +7,7 @@ import com.github.klee0kai.test.car.model.Wheel import com.github.klee0kai.test.car.model.Window import org.junit.jupiter.api.Assertions import org.junit.jupiter.api.Assertions.assertEquals +import org.junit.jupiter.api.Assertions.assertNotEquals import org.junit.jupiter.api.Assertions.assertNotNull import org.junit.jupiter.api.BeforeEach import org.junit.jupiter.api.Test @@ -181,7 +182,7 @@ class MultiCachedProvideTest { assertNotNull(car[1]!!.bumpers) assertNotNull(car[1]!!.wheels) assertNotNull(car[1]!!.windows) - Assertions.assertNotEquals( + assertNotEquals( car[0]!!.windows!!.size, car[1]!!.windows!!.size, "Red use single deps and Blue car use listed deps" diff --git a/tests_wraps_kotlin/src/test/kotlin/com/github/klee0kai/stone/kotlin/test/car/qualifiers/CarInjectAllMethodsWithQualifiersTest.kt b/tests_wraps_kotlin/src/test/kotlin/com/github/klee0kai/stone/kotlin/test/car/qualifiers/CarInjectAllMethodsWithQualifiersTest.kt index c6d915e0..0c8e88e0 100644 --- a/tests_wraps_kotlin/src/test/kotlin/com/github/klee0kai/stone/kotlin/test/car/qualifiers/CarInjectAllMethodsWithQualifiersTest.kt +++ b/tests_wraps_kotlin/src/test/kotlin/com/github/klee0kai/stone/kotlin/test/car/qualifiers/CarInjectAllMethodsWithQualifiersTest.kt @@ -91,7 +91,7 @@ class CarInjectAllMethodsWithQualifiersTest { //Then assertEquals(1, filtered.size) assertEquals("reinforced", car.bumpers!![0]!!.qualifier) - assertEquals(4, car.wheels!!.size, "four wheel +1") + assertEquals(4, car.wheels!!.size, "four wheel") } @Test From d145eb24482a2ac0699ef4fb5c96b614c528c2b5 Mon Sep 17 00:00:00 2001 From: klee0kai Date: Wed, 7 Jan 2026 21:18:41 +0100 Subject: [PATCH 093/122] finish migrate tests_wraps_kotlin --- .../com/github/klee0kai/thekey/stone/ksp/Processor.kt | 2 +- .../thekey/stone/ksp/helpers/invokecall/InvokeCall.kt | 4 ++-- .../thekey/stone/ksp/helpers/invokecall/ModulesGraph.kt | 4 ++-- .../stone/ksp/target/component/GenComponentProcessor.kt | 5 +++-- .../test/car/di/cachecontrol/gc/CarGcComponent.kt | 8 +++++++- 5 files changed, 15 insertions(+), 8 deletions(-) diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/Processor.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/Processor.kt index ecd32fb2..d4676c21 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/Processor.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/Processor.kt @@ -64,7 +64,7 @@ class Processor( // force changes // debug = true -// debugPkgFilter = "com.github.klee0kai.test.car.di.qualifiers" +// debugPkgFilter = "com.github.klee0kai.test.car.di.cachecontrol.gc" } diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/invokecall/InvokeCall.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/invokecall/InvokeCall.kt index b29e3aa2..0147daeb 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/invokecall/InvokeCall.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/invokecall/InvokeCall.kt @@ -125,11 +125,11 @@ class InvokeCall( if (wrapHelper.isList(invokeCall.rawReturnType())) { add( - "%L.addAll( %L );\n", + "%L.addAll( %L ?: emptyList() );\n", listFieldName, wrapHelper.transform( invokeCall.rawReturnType(), - provType, + provType.copy(nullable = true), seqCodeBlock ) ) diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/invokecall/ModulesGraph.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/invokecall/ModulesGraph.kt index 707f13d9..325999a3 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/invokecall/ModulesGraph.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/invokecall/ModulesGraph.kt @@ -267,11 +267,11 @@ class ModulesGraph( if (inv.resultType().copy(nullable = false) == providingType.copy(nullable = false)) { if (wrapHelper.isList(returnType)) { codeBlock.add( - "%L.addAll( %L )\n", + "%L.addAll( %L ?: emptyList() )\n", listFieldName, wrapHelper.transform( listDepField.type, - provideBuilderList, + provideBuilderList.copy(nullable = true), CodeBlock.of(listDepField.name) ) ) diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/component/GenComponentProcessor.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/component/GenComponentProcessor.kt index bd2981e0..8fd02f24 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/component/GenComponentProcessor.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/component/GenComponentProcessor.kt @@ -29,7 +29,6 @@ import com.github.klee0kai.thekey.stone.ksp.ksp.getAllMethods import com.github.klee0kai.thekey.stone.ksp.ksp.resolveAlias import com.github.klee0kai.thekey.stone.ksp.ksp.resolveNotNullable import com.github.klee0kai.thekey.stone.ksp.poet.* -import com.github.klee0kai.thekey.stone.ksp.target.component.GenComponentProcessor.DelayedCodeBlocks import com.github.klee0kai.thekey.stone.ksp.target.module.GenModuleProcessor import com.google.devtools.ksp.KspExperimental import com.google.devtools.ksp.containingFile @@ -348,7 +347,9 @@ class GenComponentProcessor : TargetFileProcessor { val isListCache = wrapHelper.isList(cacheControlInvoke!!.rawReturnType()) val cacheControlType = if (isListCache) { - List::class.asClassName().parameterizedBy(nonWrappedBindType.copy(nullable = true)) + List::class.asClassName() + .parameterizedBy(nonWrappedBindType.copy(nullable = true)) + .copy(nullable = true) } else { nonWrappedBindType.copy(nullable = true) } diff --git a/tests_wraps_kotlin/src/main/kotlin/com/github/klee0kai/test/car/di/cachecontrol/gc/CarGcComponent.kt b/tests_wraps_kotlin/src/main/kotlin/com/github/klee0kai/test/car/di/cachecontrol/gc/CarGcComponent.kt index 2981c0b9..37118e05 100644 --- a/tests_wraps_kotlin/src/main/kotlin/com/github/klee0kai/test/car/di/cachecontrol/gc/CarGcComponent.kt +++ b/tests_wraps_kotlin/src/main/kotlin/com/github/klee0kai/test/car/di/cachecontrol/gc/CarGcComponent.kt @@ -6,7 +6,13 @@ import com.github.klee0kai.test.car.di.cachecontrol.gc.scopes.GcBumperScope import com.github.klee0kai.test.car.di.cachecontrol.gc.scopes.GcWheelScope import com.github.klee0kai.test.car.di.cachecontrol.gc.scopes.GcWindowScope -@Component(identifiers = [String::class, Integer::class]) +@Component( + identifiers = [ + String::class, + Integer::class, + Int::class, + ] +) abstract class CarGcComponent { abstract fun bumpersModule(): BumperGcModule? abstract fun wheelsModule(): WheelGcModule From c74450813131a88ef59a5461a2eff33ab6c7caea Mon Sep 17 00:00:00 2001 From: klee0kai Date: Wed, 7 Jan 2026 23:21:55 +0100 Subject: [PATCH 094/122] migrate test_feature_core_deps --- .../target/component/ComponentsMethodsExt.kt | 3 ++- .../target/component/GenComponentProcessor.kt | 18 +++++++++++-- .../hiddenmodule/GenHiddenModuleProcessor.kt | 5 ++-- test_feature_core_deps/build.gradle.kts | 5 ++-- .../klee0kai/test/app/di/AppComponent.kt | 6 ++--- .../klee0kai/test/core/di/CoreComponent.kt | 12 ++++----- .../core/di/dependecies/BirdsDependencies.kt | 10 +++---- .../core/di/dependecies/TreesDependencies.kt | 4 +-- .../core/di/wrapper/CustomStoneProvide.kt | 3 ++- .../core/di/wrapper/CustomWrappersStone.kt | 27 ------------------- .../core/di/wrapper/StoneCustomWrapper.kt | 17 ++++++++++++ .../test/feature1/di/Feature1Component.kt | 8 +++--- .../di/dependencies/BerriesDependencies.kt | 8 +++--- .../klee0kai/stone/test/app/ExtCoreTests.kt | 12 ++++----- .../stone/test/feature1/Feature1Tests.kt | 12 ++++----- 15 files changed, 79 insertions(+), 71 deletions(-) delete mode 100644 test_feature_core_deps/src/main/java/com/github/klee0kai/test/core/di/wrapper/CustomWrappersStone.kt create mode 100644 test_feature_core_deps/src/main/java/com/github/klee0kai/test/core/di/wrapper/StoneCustomWrapper.kt diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/component/ComponentsMethodsExt.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/component/ComponentsMethodsExt.kt index 476f1790..d5357457 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/component/ComponentsMethodsExt.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/component/ComponentsMethodsExt.kt @@ -13,6 +13,7 @@ import com.github.klee0kai.thekey.stone.ksp.helpers.scopeAnnotations import com.github.klee0kai.thekey.stone.ksp.ksp.isClassReturn import com.github.klee0kai.thekey.stone.ksp.ksp.isNotPrimitive import com.github.klee0kai.thekey.stone.ksp.ksp.isUnit +import com.github.klee0kai.thekey.stone.ksp.ksp.resolveAlias import com.github.klee0kai.thekey.stone.ksp.ksp.resolveNotNullable import com.github.klee0kai.thekey.stone.ksp.target.module.GenModuleProcessor import com.google.devtools.ksp.getAllSuperTypes @@ -205,7 +206,7 @@ val KSFunctionDeclaration.isBindInstanceMethod: BindInstanceType? when { parameterIsNotPrimitive - && returnType?.resolve()?.toTypeName() == parameters.first().type.resolve().toTypeName() -> { + && returnType?.resolveNotNullable()?.toTypeName() == parameters.first().type.resolveNotNullable().toTypeName() -> { return BindInstanceType.BindInstanceAndProvide } diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/component/GenComponentProcessor.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/component/GenComponentProcessor.kt index 8fd02f24..31940563 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/component/GenComponentProcessor.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/component/GenComponentProcessor.kt @@ -156,7 +156,20 @@ class GenComponentProcessor : TargetFileProcessor { } m.isDepsProvideMethod -> { - //TODO + val depType = m.returnType!!.resolveNotNullable().toClassName() + genProperty(m.simpleName.asString(), depType.copy(nullable = true)) { + addModifiers(KModifier.PRIVATE) + mutable(true) + initializer("null") + } + genOverrideFun(m) { + returns(depType) + addStatement("return %L!!", m.simpleName.asString()) + } + + delayedCodeBlocks.initDepsMethodBody.addStatement( + "if (m is %T) this.%L = m", depType, m.simpleName.asString(), + ) } m.isModuleInitMethod -> { @@ -766,9 +779,10 @@ class GenComponentProcessor : TargetFileProcessor { ) } + addStatement("// bind instance methods ignore nullability checks ") for (bindInstMethod in bindInstanceAndProvideMethods) { addStatement( - "%L(protoComponent.%L(null))", + "runCatching{ %L(protoComponent.%L(null)) }", bindInstMethod.simpleName.asString(), bindInstMethod.simpleName.asString(), ) } diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/hiddenmodule/GenHiddenModuleProcessor.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/hiddenmodule/GenHiddenModuleProcessor.kt index c24cd008..4d4814d5 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/hiddenmodule/GenHiddenModuleProcessor.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/hiddenmodule/GenHiddenModuleProcessor.kt @@ -22,6 +22,7 @@ import com.github.klee0kai.thekey.stone.ksp.ksp.arch.GenSpec import com.github.klee0kai.thekey.stone.ksp.ksp.arch.SymbolsToProcess import com.github.klee0kai.thekey.stone.ksp.ksp.arch.TargetFileProcessor import com.github.klee0kai.thekey.stone.ksp.ksp.getAllMethods +import com.github.klee0kai.thekey.stone.ksp.ksp.resolveNotNullable import com.github.klee0kai.thekey.stone.ksp.poet.* import com.github.klee0kai.thekey.stone.ksp.target.component.BindInstanceType import com.github.klee0kai.thekey.stone.ksp.target.component.collectWrapHelper @@ -172,8 +173,8 @@ class GenHiddenModuleProcessor : TargetFileProcessor { itemHolderCodeHelper: ItemHolderCodeHelper, wrapHelper: WrapHelper, ) { - val returnType = function.returnType?.resolve()?.toTypeName() ?: return - val setValueArg = function.parameters.firstOrNull { it.type.resolve().toTypeName() == returnType } + val returnType = function.returnType?.resolveNotNullable()?.toTypeName() ?: return + val setValueArg = function.parameters.firstOrNull { it.type.resolveNotNullable().toTypeName() == returnType } genOverrideFun(function) { addStatement( diff --git a/test_feature_core_deps/build.gradle.kts b/test_feature_core_deps/build.gradle.kts index b01854ca..90417071 100644 --- a/test_feature_core_deps/build.gradle.kts +++ b/test_feature_core_deps/build.gradle.kts @@ -1,6 +1,7 @@ plugins { alias(libs.plugins.kotlin.jvm) alias(libs.plugins.kotlin.kapt) + alias(libs.plugins.kotlin.ksp) } tasks.test { @@ -8,8 +9,8 @@ tasks.test { } dependencies { - implementation(project(":kotlin_lib")) - kapt(project(":stone_processor")) + implementation(project(":stone_multiplatform")) + ksp(project(":stone_ksp")) testImplementation(libs.bundles.junit) } diff --git a/test_feature_core_deps/src/main/java/com/github/klee0kai/test/app/di/AppComponent.kt b/test_feature_core_deps/src/main/java/com/github/klee0kai/test/app/di/AppComponent.kt index 185ea23d..eca73ede 100644 --- a/test_feature_core_deps/src/main/java/com/github/klee0kai/test/app/di/AppComponent.kt +++ b/test_feature_core_deps/src/main/java/com/github/klee0kai/test/app/di/AppComponent.kt @@ -4,12 +4,12 @@ import com.github.klee0kai.stone.annotations.component.Component import com.github.klee0kai.stone.annotations.component.ExtendOf import com.github.klee0kai.test.app.di.dependencies.AppDependencyProvider import com.github.klee0kai.test.core.di.CoreComponent -import com.github.klee0kai.test.core.di.wrapper.CustomWrappersStone +import com.github.klee0kai.test.core.di.wrapper.StoneCustomWrapper @Component( - wrapperProviders = [ - CustomWrappersStone::class, + wrapperHelpers = [ + StoneCustomWrapper::class, ], ) // TODO https://github.com/klee0kai/stone/issues/116 diff --git a/test_feature_core_deps/src/main/java/com/github/klee0kai/test/core/di/CoreComponent.kt b/test_feature_core_deps/src/main/java/com/github/klee0kai/test/core/di/CoreComponent.kt index 9e83f26c..6be6d371 100644 --- a/test_feature_core_deps/src/main/java/com/github/klee0kai/test/core/di/CoreComponent.kt +++ b/test_feature_core_deps/src/main/java/com/github/klee0kai/test/core/di/CoreComponent.kt @@ -3,25 +3,25 @@ package com.github.klee0kai.test.core.di import com.github.klee0kai.stone.annotations.component.Component import com.github.klee0kai.stone.annotations.module.BindInstance import com.github.klee0kai.test.core.di.dependecies.CoreDepependenciesProvider -import com.github.klee0kai.test.core.di.wrapper.CustomWrappersStone +import com.github.klee0kai.test.core.di.wrapper.StoneCustomWrapper import com.github.klee0kai.test.core.forest.Alder import com.github.klee0kai.test.core.forest.Ash import com.github.klee0kai.test.core.forest.Beech @Component( - wrapperProviders = [ - CustomWrappersStone::class, + wrapperHelpers = [ + StoneCustomWrapper::class, ], ) interface CoreComponent : CoreComponentModules, CoreDepependenciesProvider { @BindInstance(cache = BindInstance.CacheType.Strong) - fun alder(alder: Alder): Alder + fun alder(alder: Alder?): Alder @BindInstance(cache = BindInstance.CacheType.Soft) - fun ash(alder: Ash): Ash + fun ash(alder: Ash?): Ash @BindInstance(cache = BindInstance.CacheType.Weak) - fun beech(alder: Beech): Beech + fun beech(alder: Beech?): Beech } \ No newline at end of file diff --git a/test_feature_core_deps/src/main/java/com/github/klee0kai/test/core/di/dependecies/BirdsDependencies.kt b/test_feature_core_deps/src/main/java/com/github/klee0kai/test/core/di/dependecies/BirdsDependencies.kt index 7209f7d3..96e61935 100644 --- a/test_feature_core_deps/src/main/java/com/github/klee0kai/test/core/di/dependecies/BirdsDependencies.kt +++ b/test_feature_core_deps/src/main/java/com/github/klee0kai/test/core/di/dependecies/BirdsDependencies.kt @@ -1,18 +1,18 @@ package com.github.klee0kai.test.core.di.dependecies -import com.github.klee0kai.stone.wrappers.AsyncProvide +import com.github.klee0kai.stone.wrappers.AsyncCoroutineProvide import com.github.klee0kai.test.core.birds.* import com.github.klee0kai.test.core.di.wrapper.CustomStoneProvide interface BirdsDependencies { - fun crow(): AsyncProvide + fun crow(): AsyncCoroutineProvide - fun duck(): AsyncProvide + fun duck(): AsyncCoroutineProvide - fun hen(): AsyncProvide + fun hen(): AsyncCoroutineProvide - fun pigeon(): AsyncProvide + fun pigeon(): AsyncCoroutineProvide fun sparrow(): CustomStoneProvide diff --git a/test_feature_core_deps/src/main/java/com/github/klee0kai/test/core/di/dependecies/TreesDependencies.kt b/test_feature_core_deps/src/main/java/com/github/klee0kai/test/core/di/dependecies/TreesDependencies.kt index 27dcdd83..3e960186 100644 --- a/test_feature_core_deps/src/main/java/com/github/klee0kai/test/core/di/dependecies/TreesDependencies.kt +++ b/test_feature_core_deps/src/main/java/com/github/klee0kai/test/core/di/dependecies/TreesDependencies.kt @@ -1,6 +1,6 @@ package com.github.klee0kai.test.core.di.dependecies -import com.github.klee0kai.stone.wrappers.AsyncProvide +import com.github.klee0kai.stone.wrappers.AsyncCoroutineProvide import com.github.klee0kai.stone.wrappers.LazyProvide import com.github.klee0kai.test.core.trees.Fir import com.github.klee0kai.test.core.trees.Palm @@ -8,7 +8,7 @@ import com.github.klee0kai.test.core.trees.Poplar interface TreesDependencies { - fun fir(): AsyncProvide + fun fir(): AsyncCoroutineProvide fun palm(): LazyProvide diff --git a/test_feature_core_deps/src/main/java/com/github/klee0kai/test/core/di/wrapper/CustomStoneProvide.kt b/test_feature_core_deps/src/main/java/com/github/klee0kai/test/core/di/wrapper/CustomStoneProvide.kt index ded87498..2510b13e 100644 --- a/test_feature_core_deps/src/main/java/com/github/klee0kai/test/core/di/wrapper/CustomStoneProvide.kt +++ b/test_feature_core_deps/src/main/java/com/github/klee0kai/test/core/di/wrapper/CustomStoneProvide.kt @@ -1,6 +1,7 @@ package com.github.klee0kai.test.core.di.wrapper -import com.github.klee0kai.stone.wrappers.Ref +import com.github.klee0kai.stone.weakref.Ref + class CustomStoneProvide(val call: Ref) { diff --git a/test_feature_core_deps/src/main/java/com/github/klee0kai/test/core/di/wrapper/CustomWrappersStone.kt b/test_feature_core_deps/src/main/java/com/github/klee0kai/test/core/di/wrapper/CustomWrappersStone.kt deleted file mode 100644 index 68419636..00000000 --- a/test_feature_core_deps/src/main/java/com/github/klee0kai/test/core/di/wrapper/CustomWrappersStone.kt +++ /dev/null @@ -1,27 +0,0 @@ -package com.github.klee0kai.test.core.di.wrapper - -import com.github.klee0kai.stone.annotations.wrappers.WrappersCreator -import com.github.klee0kai.stone.wrappers.creators.CircleWrapper -import javax.inject.Provider - -@WrappersCreator( - wrappers = [ - CustomStoneProvide::class - ] -) -class CustomWrappersStone : CircleWrapper { - - override fun wrap(wrapperCl: Class?, originalProvider: Provider?): Wr? { - return when { - wrapperCl == CustomStoneProvide::class.java -> CustomStoneProvide { originalProvider?.get() } as Wr - else -> null - } - } - - override fun unwrap(wrapperCl: Class?, objectType: Class?, wrapper: Wr): T? { - return when { - wrapperCl == CustomStoneProvide::class.java -> (wrapper as CustomStoneProvide).get() - else -> null - } - } -} \ No newline at end of file diff --git a/test_feature_core_deps/src/main/java/com/github/klee0kai/test/core/di/wrapper/StoneCustomWrapper.kt b/test_feature_core_deps/src/main/java/com/github/klee0kai/test/core/di/wrapper/StoneCustomWrapper.kt new file mode 100644 index 00000000..9ab278cf --- /dev/null +++ b/test_feature_core_deps/src/main/java/com/github/klee0kai/test/core/di/wrapper/StoneCustomWrapper.kt @@ -0,0 +1,17 @@ +package com.github.klee0kai.test.core.di.wrapper + +import com.github.klee0kai.stone.annotations.wrappers.WrappersHelper +import com.github.klee0kai.stone.weakref.Provider + +@WrappersHelper +object StoneCustomWrapper { + + fun transformToCustomWrapper( + origin: Provider, + ): CustomStoneProvide = CustomStoneProvide { origin.get() } + + fun transformFromCustomWrapper( + origin: CustomStoneProvide, + ): T = origin.get() + +} \ No newline at end of file diff --git a/test_feature_core_deps/src/main/java/com/github/klee0kai/test/feature1/di/Feature1Component.kt b/test_feature_core_deps/src/main/java/com/github/klee0kai/test/feature1/di/Feature1Component.kt index fd93d99d..24b7b094 100644 --- a/test_feature_core_deps/src/main/java/com/github/klee0kai/test/feature1/di/Feature1Component.kt +++ b/test_feature_core_deps/src/main/java/com/github/klee0kai/test/feature1/di/Feature1Component.kt @@ -4,14 +4,14 @@ import com.github.klee0kai.stone.annotations.component.Component import com.github.klee0kai.stone.annotations.component.Init import com.github.klee0kai.stone.annotations.component.ModuleOriginFactory import com.github.klee0kai.test.core.di.dependecies.CoreDepependenciesProvider -import com.github.klee0kai.test.core.di.wrapper.CustomWrappersStone +import com.github.klee0kai.test.core.di.wrapper.StoneCustomWrapper import com.github.klee0kai.test.feature1.di.dependencies.Feature1DependencyProvider import com.github.klee0kai.test.feature1.di.module.BerriesModule @Component( - wrapperProviders = [ - CustomWrappersStone::class, - ], + wrapperHelpers = [ + StoneCustomWrapper::class, + ] ) interface Feature1Component : Feature1DependencyProvider, CoreDepependenciesProvider { diff --git a/test_feature_core_deps/src/main/java/com/github/klee0kai/test/feature1/di/dependencies/BerriesDependencies.kt b/test_feature_core_deps/src/main/java/com/github/klee0kai/test/feature1/di/dependencies/BerriesDependencies.kt index c025c5db..ac07bec5 100644 --- a/test_feature_core_deps/src/main/java/com/github/klee0kai/test/feature1/di/dependencies/BerriesDependencies.kt +++ b/test_feature_core_deps/src/main/java/com/github/klee0kai/test/feature1/di/dependencies/BerriesDependencies.kt @@ -1,6 +1,6 @@ package com.github.klee0kai.test.feature1.di.dependencies -import com.github.klee0kai.stone.wrappers.AsyncProvide +import com.github.klee0kai.stone.wrappers.AsyncCoroutineProvide import com.github.klee0kai.test.core.di.wrapper.CustomStoneProvide import com.github.klee0kai.test.feature1.berries.* @@ -10,10 +10,10 @@ interface BerriesDependencies { fun cherry(): CustomStoneProvide - fun currant(): AsyncProvide + fun currant(): AsyncCoroutineProvide - fun raspberry(): AsyncProvide + fun raspberry(): AsyncCoroutineProvide - fun strawberry(): AsyncProvide + fun strawberry(): AsyncCoroutineProvide } \ No newline at end of file diff --git a/test_feature_core_deps/src/test/java/com/github/klee0kai/stone/test/app/ExtCoreTests.kt b/test_feature_core_deps/src/test/java/com/github/klee0kai/stone/test/app/ExtCoreTests.kt index 22ee3383..cf8c2919 100644 --- a/test_feature_core_deps/src/test/java/com/github/klee0kai/stone/test/app/ExtCoreTests.kt +++ b/test_feature_core_deps/src/test/java/com/github/klee0kai/stone/test/app/ExtCoreTests.kt @@ -1,18 +1,18 @@ package com.github.klee0kai.stone.test.app -import com.github.klee0kai.stone.Stone -import com.github.klee0kai.test.app.di.AppComponent -import com.github.klee0kai.test.core.di.CoreComponent +import com.github.klee0kai.test.app.di.AppComponentStoneComponent +import com.github.klee0kai.test.core.di.CoreComponentStoneComponent +import kotlinx.coroutines.runBlocking import org.junit.jupiter.api.Assertions.assertNotNull import org.junit.jupiter.api.Test class ExtCoreTests { @Test - fun extCoreTest() { + fun extCoreTest() = runBlocking { // Given - val coreDI = Stone.createComponent(CoreComponent::class.java) - val appDI = Stone.createComponent(AppComponent::class.java) + val coreDI = CoreComponentStoneComponent() + val appDI = AppComponentStoneComponent() // When appDI.ext(coreDI) diff --git a/test_feature_core_deps/src/test/java/com/github/klee0kai/stone/test/feature1/Feature1Tests.kt b/test_feature_core_deps/src/test/java/com/github/klee0kai/stone/test/feature1/Feature1Tests.kt index d892e7b3..54f8fd17 100644 --- a/test_feature_core_deps/src/test/java/com/github/klee0kai/stone/test/feature1/Feature1Tests.kt +++ b/test_feature_core_deps/src/test/java/com/github/klee0kai/stone/test/feature1/Feature1Tests.kt @@ -1,18 +1,18 @@ package com.github.klee0kai.stone.test.feature1 -import com.github.klee0kai.stone.Stone -import com.github.klee0kai.test.core.di.CoreComponent -import com.github.klee0kai.test.feature1.di.Feature1Component +import com.github.klee0kai.test.core.di.CoreComponentStoneComponent +import com.github.klee0kai.test.feature1.di.Feature1ComponentStoneComponent +import kotlinx.coroutines.runBlocking import org.junit.jupiter.api.Assertions.assertNotNull import org.junit.jupiter.api.Test class Feature1Tests { @Test - fun provideCoreDependenciesTests() { + fun provideCoreDependenciesTests() = runBlocking { // Given - val coreDI = Stone.createComponent(CoreComponent::class.java) - val featureDI = Stone.createComponent(Feature1Component::class.java) + val coreDI = CoreComponentStoneComponent() + val featureDI = Feature1ComponentStoneComponent() // When featureDI.initCoreDependencies(coreDI) From 39478a5f64493f4a6c760b313e20ec80892a0815 Mon Sep 17 00:00:00 2001 From: klee0kai Date: Sat, 17 Jan 2026 09:38:59 +0100 Subject: [PATCH 095/122] correct hidden module works --- .../hiddenmodule/GenHiddenModuleProcessor.kt | 19 ++++++++++++++----- .../ksp/target/module/GenModuleProcessor.kt | 4 +++- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/hiddenmodule/GenHiddenModuleProcessor.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/hiddenmodule/GenHiddenModuleProcessor.kt index 4d4814d5..b7535992 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/hiddenmodule/GenHiddenModuleProcessor.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/hiddenmodule/GenHiddenModuleProcessor.kt @@ -87,6 +87,8 @@ class GenHiddenModuleProcessor : TargetFileProcessor { val fileSpec = genFileSpec(genHiddenModuleCl.packageName, genHiddenModuleCl.simpleName) { genLibComment() + addImport("com.github.klee0kai.stone.__hidden__.coroutines", "syncIfAvailable") + genClass(genHiddenModuleCl) { addSuperinterface(IModule::class) componentCl.allParentDeclarations @@ -173,10 +175,13 @@ class GenHiddenModuleProcessor : TargetFileProcessor { itemHolderCodeHelper: ItemHolderCodeHelper, wrapHelper: WrapHelper, ) { - val returnType = function.returnType?.resolveNotNullable()?.toTypeName() ?: return - val setValueArg = function.parameters.firstOrNull { it.type.resolveNotNullable().toTypeName() == returnType } + val returnType = function.returnType?.resolve()?.toTypeName() ?: return + val setValueArg = function.parameters.firstOrNull { + it.type.resolveNotNullable().toTypeName() == function.returnType?.resolveNotNullable()?.toTypeName() + } genOverrideFun(function) { + beginControlFlow("return syncIfAvailable(%L.mutex)", overridedModuleFieldName) addStatement( "val cached = %L.get()?.%L( %T.getValueAction, %L ) ", overridedModuleFieldName, @@ -184,7 +189,7 @@ class GenHiddenModuleProcessor : TargetFileProcessor { CacheAction::class.asClassName(), idArguments.joinToString(", ") { it.name!!.asString() }, ) - addCode("if ( cached != null ) return ") + addCode("if ( cached != null ) return@syncIfAvailable ") addCode( wrapHelper.transform( providingType = wrapHelper.listWrapTypeIfNeed(returnType), @@ -206,7 +211,7 @@ class GenHiddenModuleProcessor : TargetFileProcessor { } - addCode("return ") + addCode("return@syncIfAvailable ") addCode( wrapHelper.transform( wrapHelper.listWrapTypeIfNeed(returnType), @@ -215,6 +220,7 @@ class GenHiddenModuleProcessor : TargetFileProcessor { ) ) addStatement(" as %T", returnType) + endControlFlow() } } @@ -235,6 +241,7 @@ class GenHiddenModuleProcessor : TargetFileProcessor { addParameter(it.name!!.asString(), it.type.resolve().toTypeName()) } + beginControlFlow("return syncIfAvailable(%L.mutex)", overridedModuleFieldName) addStatement( "%L.get()?.%L( __action, %L ) ", overridedModuleFieldName, @@ -271,8 +278,10 @@ class GenHiddenModuleProcessor : TargetFileProcessor { addStatement("null -> Unit") endControlFlow() - addCode("return ") + addCode("return@syncIfAvailable ") addCode(codeBlock = itemHolderCodeHelper.codeGetCachedValue()) + addStatement("") + endControlFlow() } } diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/module/GenModuleProcessor.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/module/GenModuleProcessor.kt index 466024d4..72deec18 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/module/GenModuleProcessor.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/module/GenModuleProcessor.kt @@ -266,7 +266,9 @@ class GenModuleProcessor : TargetFileProcessor { wrapHelper: WrapHelper, ) { val returnType = function.returnType?.resolve()?.toTypeName() ?: return - val setValueArg = function.parameters.firstOrNull { it.type.resolve().toTypeName() == returnType } + val setValueArg = function.parameters.firstOrNull { + it.type.resolveNotNullable().toTypeName() == function.returnType?.resolveNotNullable()?.toTypeName() + } genOverrideFun(function) { beginControlFlow("return syncIfAvailable(%L.mutex)", overridedModuleFieldName) From 2b8e023c459cad4f170634d95e9daa8bd187c81d Mon Sep 17 00:00:00 2001 From: klee0kai Date: Sat, 17 Jan 2026 09:56:05 +0100 Subject: [PATCH 096/122] Rename .java to .kt --- .../di/{ConsultingComponent.java => ConsultingComponent.kt} | 0 .../di/{ConsultingDependencies.java => ConsultingDependencies.kt} | 0 ...{ProvideDependenciesTests.java => ProvideDependenciesTests.kt} | 0 .../{PlanningRunInject2Tests.java => PlanningRunInject2Tests.kt} | 0 .../{PlanningRunInjectTests.java => PlanningRunInjectTests.kt} | 0 .../finance/accounting/{Accounting.java => Accounting.kt} | 0 .../finance/model/{BalanceInfo.java => BalanceInfo.kt} | 0 .../finance/model/{WorkCalendar.java => WorkCalendar.kt} | 0 .../finance/accounting/{AccountingImpl.java => AccountingImpl.kt} | 0 .../di/{AccountingComponent.java => AccountingComponent.kt} | 0 .../di/{AccountingDependencies.java => AccountingDependencies.kt} | 0 .../finance/di/{AccountingModule.java => AccountingModule.kt} | 0 .../finance/store/{AccountingStore.java => AccountingStore.kt} | 0 .../test_feature/hr/department/{Department.java => Department.kt} | 0 .../department/{SecurityDepartment.java => SecurityDepartment.kt} | 0 .../department/{SoftwareDepartment.java => SoftwareDepartment.kt} | 0 .../hr/department/{WorkingGroup.java => WorkingGroup.kt} | 0 .../hr/model/{DepartmentInfo.java => DepartmentInfo.kt} | 0 .../test_feature/hr/model/{EmployeeInfo.java => EmployeeInfo.kt} | 0 .../hr/model/{EmployeeStatus.java => EmployeeStatus.kt} | 0 .../hr/department/{DepartmentImpl.java => DepartmentImpl.kt} | 0 .../{SecurityDepartmentImpl.java => SecurityDepartmentImpl.kt} | 0 .../{SoftwareDepartmentImpl.java => SoftwareDepartmentImpl.kt} | 0 .../hr/di/{DepartmentsModule.java => DepartmentsModule.kt} | 0 .../stone/test_feature/hr/di/{HrComponent.java => HrComponent.kt} | 0 .../test_feature/hr/di/{HrDependencies.java => HrDependencies.kt} | 0 .../hr/store/{EmployeesStore.java => EmployeesStore.kt} | 0 .../planning/model/{ProjectInfo.java => ProjectInfo.kt} | 0 .../test_feature/planning/model/{TaskInfo.java => TaskInfo.kt} | 0 .../project/{BuildFactoryProject.java => BuildFactoryProject.kt} | 0 .../planning/project/{LogisticProject.java => LogisticProject.kt} | 0 .../test_feature/planning/project/{Project.java => Project.kt} | 0 .../test_feature/planning/{PlanningRun.java => PlanningRun.kt} | 0 .../planning/di/{PlanningComponent.java => PlanningComponent.kt} | 0 .../di/{PlanningDependencies.java => PlanningDependencies.kt} | 0 .../planning/di/{ProjectsModule.java => ProjectsModule.kt} | 0 .../{BuildFactoryProjectImpl.java => BuildFactoryProjectImpl.kt} | 0 .../project/{LogisticProjectImpl.java => LogisticProjectImpl.kt} | 0 .../planning/project/{ProjectImpl.java => ProjectImpl.kt} | 0 .../planning/store/{ProjectsStore.java => ProjectsStore.kt} | 0 40 files changed, 0 insertions(+), 0 deletions(-) rename test_feature/companies/consulting/src/main/java/com/github/klee0kai/stone/test_feature/consulting/di/{ConsultingComponent.java => ConsultingComponent.kt} (100%) rename test_feature/companies/consulting/src/main/java/com/github/klee0kai/stone/test_feature/consulting/di/{ConsultingDependencies.java => ConsultingDependencies.kt} (100%) rename test_feature/companies/consulting/src/test/java/com/github/klee0kai/stone/test_feature/consulting/dependencies/{ProvideDependenciesTests.java => ProvideDependenciesTests.kt} (100%) rename test_feature/companies/consulting/src/test/java/com/github/klee0kai/stone/test_feature/consulting/dependencies/inject/{PlanningRunInject2Tests.java => PlanningRunInject2Tests.kt} (100%) rename test_feature/companies/consulting/src/test/java/com/github/klee0kai/stone/test_feature/consulting/dependencies/inject/{PlanningRunInjectTests.java => PlanningRunInjectTests.kt} (100%) rename test_feature/finance/api/src/main/java/com/github/klee0kai/stone/test_feature/finance/accounting/{Accounting.java => Accounting.kt} (100%) rename test_feature/finance/api/src/main/java/com/github/klee0kai/stone/test_feature/finance/model/{BalanceInfo.java => BalanceInfo.kt} (100%) rename test_feature/finance/api/src/main/java/com/github/klee0kai/stone/test_feature/finance/model/{WorkCalendar.java => WorkCalendar.kt} (100%) rename test_feature/finance/impl/src/main/java/com/github/klee0kai/stone/test_feature/finance/accounting/{AccountingImpl.java => AccountingImpl.kt} (100%) rename test_feature/finance/impl/src/main/java/com/github/klee0kai/stone/test_feature/finance/di/{AccountingComponent.java => AccountingComponent.kt} (100%) rename test_feature/finance/impl/src/main/java/com/github/klee0kai/stone/test_feature/finance/di/{AccountingDependencies.java => AccountingDependencies.kt} (100%) rename test_feature/finance/impl/src/main/java/com/github/klee0kai/stone/test_feature/finance/di/{AccountingModule.java => AccountingModule.kt} (100%) rename test_feature/finance/impl/src/main/java/com/github/klee0kai/stone/test_feature/finance/store/{AccountingStore.java => AccountingStore.kt} (100%) rename test_feature/hr/api/src/main/java/com/github/klee0kai/stone/test_feature/hr/department/{Department.java => Department.kt} (100%) rename test_feature/hr/api/src/main/java/com/github/klee0kai/stone/test_feature/hr/department/{SecurityDepartment.java => SecurityDepartment.kt} (100%) rename test_feature/hr/api/src/main/java/com/github/klee0kai/stone/test_feature/hr/department/{SoftwareDepartment.java => SoftwareDepartment.kt} (100%) rename test_feature/hr/api/src/main/java/com/github/klee0kai/stone/test_feature/hr/department/{WorkingGroup.java => WorkingGroup.kt} (100%) rename test_feature/hr/api/src/main/java/com/github/klee0kai/stone/test_feature/hr/model/{DepartmentInfo.java => DepartmentInfo.kt} (100%) rename test_feature/hr/api/src/main/java/com/github/klee0kai/stone/test_feature/hr/model/{EmployeeInfo.java => EmployeeInfo.kt} (100%) rename test_feature/hr/api/src/main/java/com/github/klee0kai/stone/test_feature/hr/model/{EmployeeStatus.java => EmployeeStatus.kt} (100%) rename test_feature/hr/impl/src/main/java/com/github/klee0kai/stone/test_feature/hr/department/{DepartmentImpl.java => DepartmentImpl.kt} (100%) rename test_feature/hr/impl/src/main/java/com/github/klee0kai/stone/test_feature/hr/department/{SecurityDepartmentImpl.java => SecurityDepartmentImpl.kt} (100%) rename test_feature/hr/impl/src/main/java/com/github/klee0kai/stone/test_feature/hr/department/{SoftwareDepartmentImpl.java => SoftwareDepartmentImpl.kt} (100%) rename test_feature/hr/impl/src/main/java/com/github/klee0kai/stone/test_feature/hr/di/{DepartmentsModule.java => DepartmentsModule.kt} (100%) rename test_feature/hr/impl/src/main/java/com/github/klee0kai/stone/test_feature/hr/di/{HrComponent.java => HrComponent.kt} (100%) rename test_feature/hr/impl/src/main/java/com/github/klee0kai/stone/test_feature/hr/di/{HrDependencies.java => HrDependencies.kt} (100%) rename test_feature/hr/impl/src/main/java/com/github/klee0kai/stone/test_feature/hr/store/{EmployeesStore.java => EmployeesStore.kt} (100%) rename test_feature/planning/api/src/main/java/com/github/klee0kai/stone/test_feature/planning/model/{ProjectInfo.java => ProjectInfo.kt} (100%) rename test_feature/planning/api/src/main/java/com/github/klee0kai/stone/test_feature/planning/model/{TaskInfo.java => TaskInfo.kt} (100%) rename test_feature/planning/api/src/main/java/com/github/klee0kai/stone/test_feature/planning/project/{BuildFactoryProject.java => BuildFactoryProject.kt} (100%) rename test_feature/planning/api/src/main/java/com/github/klee0kai/stone/test_feature/planning/project/{LogisticProject.java => LogisticProject.kt} (100%) rename test_feature/planning/api/src/main/java/com/github/klee0kai/stone/test_feature/planning/project/{Project.java => Project.kt} (100%) rename test_feature/planning/impl/src/main/java/com/github/klee0kai/stone/test_feature/planning/{PlanningRun.java => PlanningRun.kt} (100%) rename test_feature/planning/impl/src/main/java/com/github/klee0kai/stone/test_feature/planning/di/{PlanningComponent.java => PlanningComponent.kt} (100%) rename test_feature/planning/impl/src/main/java/com/github/klee0kai/stone/test_feature/planning/di/{PlanningDependencies.java => PlanningDependencies.kt} (100%) rename test_feature/planning/impl/src/main/java/com/github/klee0kai/stone/test_feature/planning/di/{ProjectsModule.java => ProjectsModule.kt} (100%) rename test_feature/planning/impl/src/main/java/com/github/klee0kai/stone/test_feature/planning/project/{BuildFactoryProjectImpl.java => BuildFactoryProjectImpl.kt} (100%) rename test_feature/planning/impl/src/main/java/com/github/klee0kai/stone/test_feature/planning/project/{LogisticProjectImpl.java => LogisticProjectImpl.kt} (100%) rename test_feature/planning/impl/src/main/java/com/github/klee0kai/stone/test_feature/planning/project/{ProjectImpl.java => ProjectImpl.kt} (100%) rename test_feature/planning/impl/src/main/java/com/github/klee0kai/stone/test_feature/planning/store/{ProjectsStore.java => ProjectsStore.kt} (100%) diff --git a/test_feature/companies/consulting/src/main/java/com/github/klee0kai/stone/test_feature/consulting/di/ConsultingComponent.java b/test_feature/companies/consulting/src/main/java/com/github/klee0kai/stone/test_feature/consulting/di/ConsultingComponent.kt similarity index 100% rename from test_feature/companies/consulting/src/main/java/com/github/klee0kai/stone/test_feature/consulting/di/ConsultingComponent.java rename to test_feature/companies/consulting/src/main/java/com/github/klee0kai/stone/test_feature/consulting/di/ConsultingComponent.kt diff --git a/test_feature/companies/consulting/src/main/java/com/github/klee0kai/stone/test_feature/consulting/di/ConsultingDependencies.java b/test_feature/companies/consulting/src/main/java/com/github/klee0kai/stone/test_feature/consulting/di/ConsultingDependencies.kt similarity index 100% rename from test_feature/companies/consulting/src/main/java/com/github/klee0kai/stone/test_feature/consulting/di/ConsultingDependencies.java rename to test_feature/companies/consulting/src/main/java/com/github/klee0kai/stone/test_feature/consulting/di/ConsultingDependencies.kt diff --git a/test_feature/companies/consulting/src/test/java/com/github/klee0kai/stone/test_feature/consulting/dependencies/ProvideDependenciesTests.java b/test_feature/companies/consulting/src/test/java/com/github/klee0kai/stone/test_feature/consulting/dependencies/ProvideDependenciesTests.kt similarity index 100% rename from test_feature/companies/consulting/src/test/java/com/github/klee0kai/stone/test_feature/consulting/dependencies/ProvideDependenciesTests.java rename to test_feature/companies/consulting/src/test/java/com/github/klee0kai/stone/test_feature/consulting/dependencies/ProvideDependenciesTests.kt diff --git a/test_feature/companies/consulting/src/test/java/com/github/klee0kai/stone/test_feature/consulting/dependencies/inject/PlanningRunInject2Tests.java b/test_feature/companies/consulting/src/test/java/com/github/klee0kai/stone/test_feature/consulting/dependencies/inject/PlanningRunInject2Tests.kt similarity index 100% rename from test_feature/companies/consulting/src/test/java/com/github/klee0kai/stone/test_feature/consulting/dependencies/inject/PlanningRunInject2Tests.java rename to test_feature/companies/consulting/src/test/java/com/github/klee0kai/stone/test_feature/consulting/dependencies/inject/PlanningRunInject2Tests.kt diff --git a/test_feature/companies/consulting/src/test/java/com/github/klee0kai/stone/test_feature/consulting/dependencies/inject/PlanningRunInjectTests.java b/test_feature/companies/consulting/src/test/java/com/github/klee0kai/stone/test_feature/consulting/dependencies/inject/PlanningRunInjectTests.kt similarity index 100% rename from test_feature/companies/consulting/src/test/java/com/github/klee0kai/stone/test_feature/consulting/dependencies/inject/PlanningRunInjectTests.java rename to test_feature/companies/consulting/src/test/java/com/github/klee0kai/stone/test_feature/consulting/dependencies/inject/PlanningRunInjectTests.kt diff --git a/test_feature/finance/api/src/main/java/com/github/klee0kai/stone/test_feature/finance/accounting/Accounting.java b/test_feature/finance/api/src/main/java/com/github/klee0kai/stone/test_feature/finance/accounting/Accounting.kt similarity index 100% rename from test_feature/finance/api/src/main/java/com/github/klee0kai/stone/test_feature/finance/accounting/Accounting.java rename to test_feature/finance/api/src/main/java/com/github/klee0kai/stone/test_feature/finance/accounting/Accounting.kt diff --git a/test_feature/finance/api/src/main/java/com/github/klee0kai/stone/test_feature/finance/model/BalanceInfo.java b/test_feature/finance/api/src/main/java/com/github/klee0kai/stone/test_feature/finance/model/BalanceInfo.kt similarity index 100% rename from test_feature/finance/api/src/main/java/com/github/klee0kai/stone/test_feature/finance/model/BalanceInfo.java rename to test_feature/finance/api/src/main/java/com/github/klee0kai/stone/test_feature/finance/model/BalanceInfo.kt diff --git a/test_feature/finance/api/src/main/java/com/github/klee0kai/stone/test_feature/finance/model/WorkCalendar.java b/test_feature/finance/api/src/main/java/com/github/klee0kai/stone/test_feature/finance/model/WorkCalendar.kt similarity index 100% rename from test_feature/finance/api/src/main/java/com/github/klee0kai/stone/test_feature/finance/model/WorkCalendar.java rename to test_feature/finance/api/src/main/java/com/github/klee0kai/stone/test_feature/finance/model/WorkCalendar.kt diff --git a/test_feature/finance/impl/src/main/java/com/github/klee0kai/stone/test_feature/finance/accounting/AccountingImpl.java b/test_feature/finance/impl/src/main/java/com/github/klee0kai/stone/test_feature/finance/accounting/AccountingImpl.kt similarity index 100% rename from test_feature/finance/impl/src/main/java/com/github/klee0kai/stone/test_feature/finance/accounting/AccountingImpl.java rename to test_feature/finance/impl/src/main/java/com/github/klee0kai/stone/test_feature/finance/accounting/AccountingImpl.kt diff --git a/test_feature/finance/impl/src/main/java/com/github/klee0kai/stone/test_feature/finance/di/AccountingComponent.java b/test_feature/finance/impl/src/main/java/com/github/klee0kai/stone/test_feature/finance/di/AccountingComponent.kt similarity index 100% rename from test_feature/finance/impl/src/main/java/com/github/klee0kai/stone/test_feature/finance/di/AccountingComponent.java rename to test_feature/finance/impl/src/main/java/com/github/klee0kai/stone/test_feature/finance/di/AccountingComponent.kt diff --git a/test_feature/finance/impl/src/main/java/com/github/klee0kai/stone/test_feature/finance/di/AccountingDependencies.java b/test_feature/finance/impl/src/main/java/com/github/klee0kai/stone/test_feature/finance/di/AccountingDependencies.kt similarity index 100% rename from test_feature/finance/impl/src/main/java/com/github/klee0kai/stone/test_feature/finance/di/AccountingDependencies.java rename to test_feature/finance/impl/src/main/java/com/github/klee0kai/stone/test_feature/finance/di/AccountingDependencies.kt diff --git a/test_feature/finance/impl/src/main/java/com/github/klee0kai/stone/test_feature/finance/di/AccountingModule.java b/test_feature/finance/impl/src/main/java/com/github/klee0kai/stone/test_feature/finance/di/AccountingModule.kt similarity index 100% rename from test_feature/finance/impl/src/main/java/com/github/klee0kai/stone/test_feature/finance/di/AccountingModule.java rename to test_feature/finance/impl/src/main/java/com/github/klee0kai/stone/test_feature/finance/di/AccountingModule.kt diff --git a/test_feature/finance/impl/src/main/java/com/github/klee0kai/stone/test_feature/finance/store/AccountingStore.java b/test_feature/finance/impl/src/main/java/com/github/klee0kai/stone/test_feature/finance/store/AccountingStore.kt similarity index 100% rename from test_feature/finance/impl/src/main/java/com/github/klee0kai/stone/test_feature/finance/store/AccountingStore.java rename to test_feature/finance/impl/src/main/java/com/github/klee0kai/stone/test_feature/finance/store/AccountingStore.kt diff --git a/test_feature/hr/api/src/main/java/com/github/klee0kai/stone/test_feature/hr/department/Department.java b/test_feature/hr/api/src/main/java/com/github/klee0kai/stone/test_feature/hr/department/Department.kt similarity index 100% rename from test_feature/hr/api/src/main/java/com/github/klee0kai/stone/test_feature/hr/department/Department.java rename to test_feature/hr/api/src/main/java/com/github/klee0kai/stone/test_feature/hr/department/Department.kt diff --git a/test_feature/hr/api/src/main/java/com/github/klee0kai/stone/test_feature/hr/department/SecurityDepartment.java b/test_feature/hr/api/src/main/java/com/github/klee0kai/stone/test_feature/hr/department/SecurityDepartment.kt similarity index 100% rename from test_feature/hr/api/src/main/java/com/github/klee0kai/stone/test_feature/hr/department/SecurityDepartment.java rename to test_feature/hr/api/src/main/java/com/github/klee0kai/stone/test_feature/hr/department/SecurityDepartment.kt diff --git a/test_feature/hr/api/src/main/java/com/github/klee0kai/stone/test_feature/hr/department/SoftwareDepartment.java b/test_feature/hr/api/src/main/java/com/github/klee0kai/stone/test_feature/hr/department/SoftwareDepartment.kt similarity index 100% rename from test_feature/hr/api/src/main/java/com/github/klee0kai/stone/test_feature/hr/department/SoftwareDepartment.java rename to test_feature/hr/api/src/main/java/com/github/klee0kai/stone/test_feature/hr/department/SoftwareDepartment.kt diff --git a/test_feature/hr/api/src/main/java/com/github/klee0kai/stone/test_feature/hr/department/WorkingGroup.java b/test_feature/hr/api/src/main/java/com/github/klee0kai/stone/test_feature/hr/department/WorkingGroup.kt similarity index 100% rename from test_feature/hr/api/src/main/java/com/github/klee0kai/stone/test_feature/hr/department/WorkingGroup.java rename to test_feature/hr/api/src/main/java/com/github/klee0kai/stone/test_feature/hr/department/WorkingGroup.kt diff --git a/test_feature/hr/api/src/main/java/com/github/klee0kai/stone/test_feature/hr/model/DepartmentInfo.java b/test_feature/hr/api/src/main/java/com/github/klee0kai/stone/test_feature/hr/model/DepartmentInfo.kt similarity index 100% rename from test_feature/hr/api/src/main/java/com/github/klee0kai/stone/test_feature/hr/model/DepartmentInfo.java rename to test_feature/hr/api/src/main/java/com/github/klee0kai/stone/test_feature/hr/model/DepartmentInfo.kt diff --git a/test_feature/hr/api/src/main/java/com/github/klee0kai/stone/test_feature/hr/model/EmployeeInfo.java b/test_feature/hr/api/src/main/java/com/github/klee0kai/stone/test_feature/hr/model/EmployeeInfo.kt similarity index 100% rename from test_feature/hr/api/src/main/java/com/github/klee0kai/stone/test_feature/hr/model/EmployeeInfo.java rename to test_feature/hr/api/src/main/java/com/github/klee0kai/stone/test_feature/hr/model/EmployeeInfo.kt diff --git a/test_feature/hr/api/src/main/java/com/github/klee0kai/stone/test_feature/hr/model/EmployeeStatus.java b/test_feature/hr/api/src/main/java/com/github/klee0kai/stone/test_feature/hr/model/EmployeeStatus.kt similarity index 100% rename from test_feature/hr/api/src/main/java/com/github/klee0kai/stone/test_feature/hr/model/EmployeeStatus.java rename to test_feature/hr/api/src/main/java/com/github/klee0kai/stone/test_feature/hr/model/EmployeeStatus.kt diff --git a/test_feature/hr/impl/src/main/java/com/github/klee0kai/stone/test_feature/hr/department/DepartmentImpl.java b/test_feature/hr/impl/src/main/java/com/github/klee0kai/stone/test_feature/hr/department/DepartmentImpl.kt similarity index 100% rename from test_feature/hr/impl/src/main/java/com/github/klee0kai/stone/test_feature/hr/department/DepartmentImpl.java rename to test_feature/hr/impl/src/main/java/com/github/klee0kai/stone/test_feature/hr/department/DepartmentImpl.kt diff --git a/test_feature/hr/impl/src/main/java/com/github/klee0kai/stone/test_feature/hr/department/SecurityDepartmentImpl.java b/test_feature/hr/impl/src/main/java/com/github/klee0kai/stone/test_feature/hr/department/SecurityDepartmentImpl.kt similarity index 100% rename from test_feature/hr/impl/src/main/java/com/github/klee0kai/stone/test_feature/hr/department/SecurityDepartmentImpl.java rename to test_feature/hr/impl/src/main/java/com/github/klee0kai/stone/test_feature/hr/department/SecurityDepartmentImpl.kt diff --git a/test_feature/hr/impl/src/main/java/com/github/klee0kai/stone/test_feature/hr/department/SoftwareDepartmentImpl.java b/test_feature/hr/impl/src/main/java/com/github/klee0kai/stone/test_feature/hr/department/SoftwareDepartmentImpl.kt similarity index 100% rename from test_feature/hr/impl/src/main/java/com/github/klee0kai/stone/test_feature/hr/department/SoftwareDepartmentImpl.java rename to test_feature/hr/impl/src/main/java/com/github/klee0kai/stone/test_feature/hr/department/SoftwareDepartmentImpl.kt diff --git a/test_feature/hr/impl/src/main/java/com/github/klee0kai/stone/test_feature/hr/di/DepartmentsModule.java b/test_feature/hr/impl/src/main/java/com/github/klee0kai/stone/test_feature/hr/di/DepartmentsModule.kt similarity index 100% rename from test_feature/hr/impl/src/main/java/com/github/klee0kai/stone/test_feature/hr/di/DepartmentsModule.java rename to test_feature/hr/impl/src/main/java/com/github/klee0kai/stone/test_feature/hr/di/DepartmentsModule.kt diff --git a/test_feature/hr/impl/src/main/java/com/github/klee0kai/stone/test_feature/hr/di/HrComponent.java b/test_feature/hr/impl/src/main/java/com/github/klee0kai/stone/test_feature/hr/di/HrComponent.kt similarity index 100% rename from test_feature/hr/impl/src/main/java/com/github/klee0kai/stone/test_feature/hr/di/HrComponent.java rename to test_feature/hr/impl/src/main/java/com/github/klee0kai/stone/test_feature/hr/di/HrComponent.kt diff --git a/test_feature/hr/impl/src/main/java/com/github/klee0kai/stone/test_feature/hr/di/HrDependencies.java b/test_feature/hr/impl/src/main/java/com/github/klee0kai/stone/test_feature/hr/di/HrDependencies.kt similarity index 100% rename from test_feature/hr/impl/src/main/java/com/github/klee0kai/stone/test_feature/hr/di/HrDependencies.java rename to test_feature/hr/impl/src/main/java/com/github/klee0kai/stone/test_feature/hr/di/HrDependencies.kt diff --git a/test_feature/hr/impl/src/main/java/com/github/klee0kai/stone/test_feature/hr/store/EmployeesStore.java b/test_feature/hr/impl/src/main/java/com/github/klee0kai/stone/test_feature/hr/store/EmployeesStore.kt similarity index 100% rename from test_feature/hr/impl/src/main/java/com/github/klee0kai/stone/test_feature/hr/store/EmployeesStore.java rename to test_feature/hr/impl/src/main/java/com/github/klee0kai/stone/test_feature/hr/store/EmployeesStore.kt diff --git a/test_feature/planning/api/src/main/java/com/github/klee0kai/stone/test_feature/planning/model/ProjectInfo.java b/test_feature/planning/api/src/main/java/com/github/klee0kai/stone/test_feature/planning/model/ProjectInfo.kt similarity index 100% rename from test_feature/planning/api/src/main/java/com/github/klee0kai/stone/test_feature/planning/model/ProjectInfo.java rename to test_feature/planning/api/src/main/java/com/github/klee0kai/stone/test_feature/planning/model/ProjectInfo.kt diff --git a/test_feature/planning/api/src/main/java/com/github/klee0kai/stone/test_feature/planning/model/TaskInfo.java b/test_feature/planning/api/src/main/java/com/github/klee0kai/stone/test_feature/planning/model/TaskInfo.kt similarity index 100% rename from test_feature/planning/api/src/main/java/com/github/klee0kai/stone/test_feature/planning/model/TaskInfo.java rename to test_feature/planning/api/src/main/java/com/github/klee0kai/stone/test_feature/planning/model/TaskInfo.kt diff --git a/test_feature/planning/api/src/main/java/com/github/klee0kai/stone/test_feature/planning/project/BuildFactoryProject.java b/test_feature/planning/api/src/main/java/com/github/klee0kai/stone/test_feature/planning/project/BuildFactoryProject.kt similarity index 100% rename from test_feature/planning/api/src/main/java/com/github/klee0kai/stone/test_feature/planning/project/BuildFactoryProject.java rename to test_feature/planning/api/src/main/java/com/github/klee0kai/stone/test_feature/planning/project/BuildFactoryProject.kt diff --git a/test_feature/planning/api/src/main/java/com/github/klee0kai/stone/test_feature/planning/project/LogisticProject.java b/test_feature/planning/api/src/main/java/com/github/klee0kai/stone/test_feature/planning/project/LogisticProject.kt similarity index 100% rename from test_feature/planning/api/src/main/java/com/github/klee0kai/stone/test_feature/planning/project/LogisticProject.java rename to test_feature/planning/api/src/main/java/com/github/klee0kai/stone/test_feature/planning/project/LogisticProject.kt diff --git a/test_feature/planning/api/src/main/java/com/github/klee0kai/stone/test_feature/planning/project/Project.java b/test_feature/planning/api/src/main/java/com/github/klee0kai/stone/test_feature/planning/project/Project.kt similarity index 100% rename from test_feature/planning/api/src/main/java/com/github/klee0kai/stone/test_feature/planning/project/Project.java rename to test_feature/planning/api/src/main/java/com/github/klee0kai/stone/test_feature/planning/project/Project.kt diff --git a/test_feature/planning/impl/src/main/java/com/github/klee0kai/stone/test_feature/planning/PlanningRun.java b/test_feature/planning/impl/src/main/java/com/github/klee0kai/stone/test_feature/planning/PlanningRun.kt similarity index 100% rename from test_feature/planning/impl/src/main/java/com/github/klee0kai/stone/test_feature/planning/PlanningRun.java rename to test_feature/planning/impl/src/main/java/com/github/klee0kai/stone/test_feature/planning/PlanningRun.kt diff --git a/test_feature/planning/impl/src/main/java/com/github/klee0kai/stone/test_feature/planning/di/PlanningComponent.java b/test_feature/planning/impl/src/main/java/com/github/klee0kai/stone/test_feature/planning/di/PlanningComponent.kt similarity index 100% rename from test_feature/planning/impl/src/main/java/com/github/klee0kai/stone/test_feature/planning/di/PlanningComponent.java rename to test_feature/planning/impl/src/main/java/com/github/klee0kai/stone/test_feature/planning/di/PlanningComponent.kt diff --git a/test_feature/planning/impl/src/main/java/com/github/klee0kai/stone/test_feature/planning/di/PlanningDependencies.java b/test_feature/planning/impl/src/main/java/com/github/klee0kai/stone/test_feature/planning/di/PlanningDependencies.kt similarity index 100% rename from test_feature/planning/impl/src/main/java/com/github/klee0kai/stone/test_feature/planning/di/PlanningDependencies.java rename to test_feature/planning/impl/src/main/java/com/github/klee0kai/stone/test_feature/planning/di/PlanningDependencies.kt diff --git a/test_feature/planning/impl/src/main/java/com/github/klee0kai/stone/test_feature/planning/di/ProjectsModule.java b/test_feature/planning/impl/src/main/java/com/github/klee0kai/stone/test_feature/planning/di/ProjectsModule.kt similarity index 100% rename from test_feature/planning/impl/src/main/java/com/github/klee0kai/stone/test_feature/planning/di/ProjectsModule.java rename to test_feature/planning/impl/src/main/java/com/github/klee0kai/stone/test_feature/planning/di/ProjectsModule.kt diff --git a/test_feature/planning/impl/src/main/java/com/github/klee0kai/stone/test_feature/planning/project/BuildFactoryProjectImpl.java b/test_feature/planning/impl/src/main/java/com/github/klee0kai/stone/test_feature/planning/project/BuildFactoryProjectImpl.kt similarity index 100% rename from test_feature/planning/impl/src/main/java/com/github/klee0kai/stone/test_feature/planning/project/BuildFactoryProjectImpl.java rename to test_feature/planning/impl/src/main/java/com/github/klee0kai/stone/test_feature/planning/project/BuildFactoryProjectImpl.kt diff --git a/test_feature/planning/impl/src/main/java/com/github/klee0kai/stone/test_feature/planning/project/LogisticProjectImpl.java b/test_feature/planning/impl/src/main/java/com/github/klee0kai/stone/test_feature/planning/project/LogisticProjectImpl.kt similarity index 100% rename from test_feature/planning/impl/src/main/java/com/github/klee0kai/stone/test_feature/planning/project/LogisticProjectImpl.java rename to test_feature/planning/impl/src/main/java/com/github/klee0kai/stone/test_feature/planning/project/LogisticProjectImpl.kt diff --git a/test_feature/planning/impl/src/main/java/com/github/klee0kai/stone/test_feature/planning/project/ProjectImpl.java b/test_feature/planning/impl/src/main/java/com/github/klee0kai/stone/test_feature/planning/project/ProjectImpl.kt similarity index 100% rename from test_feature/planning/impl/src/main/java/com/github/klee0kai/stone/test_feature/planning/project/ProjectImpl.java rename to test_feature/planning/impl/src/main/java/com/github/klee0kai/stone/test_feature/planning/project/ProjectImpl.kt diff --git a/test_feature/planning/impl/src/main/java/com/github/klee0kai/stone/test_feature/planning/store/ProjectsStore.java b/test_feature/planning/impl/src/main/java/com/github/klee0kai/stone/test_feature/planning/store/ProjectsStore.kt similarity index 100% rename from test_feature/planning/impl/src/main/java/com/github/klee0kai/stone/test_feature/planning/store/ProjectsStore.java rename to test_feature/planning/impl/src/main/java/com/github/klee0kai/stone/test_feature/planning/store/ProjectsStore.kt From f6004a93c2c8c918c327ca4397b0ee59999365e6 Mon Sep 17 00:00:00 2001 From: klee0kai Date: Sat, 17 Jan 2026 09:56:05 +0100 Subject: [PATCH 097/122] migrate test_Feature to kotlin ksp --- .../companies/consulting/build.gradle.kts | 7 +- .../consulting/di/ConsultingComponent.kt | 26 ++++--- .../consulting/di/ConsultingDependencies.kt | 11 ++- .../dependencies/ProvideDependenciesTests.kt | 47 ++++++------- .../inject/PlanningRunInject2Tests.kt | 67 +++++++++---------- .../inject/PlanningRunInjectTests.kt | 67 +++++++++---------- test_feature/finance/api/build.gradle.kts | 2 +- .../finance/accounting/Accounting.kt | 10 +-- .../test_feature/finance/model/BalanceInfo.kt | 8 +-- .../finance/model/WorkCalendar.kt | 24 +++---- test_feature/finance/impl/build.gradle.kts | 7 +- .../finance/accounting/AccountingImpl.kt | 17 +++-- .../finance/di/AccountingComponent.kt | 16 ++--- .../finance/di/AccountingDependencies.kt | 22 +++--- .../finance/di/AccountingModule.kt | 19 +++--- .../finance/store/AccountingStore.kt | 5 +- test_feature/hr/api/build.gradle.kts | 2 +- .../test_feature/hr/department/Department.kt | 22 +++--- .../hr/department/SecurityDepartment.kt | 5 +- .../hr/department/SoftwareDepartment.kt | 5 +- .../hr/department/WorkingGroup.kt | 5 +- .../test_feature/hr/model/DepartmentInfo.kt | 13 ++-- .../test_feature/hr/model/EmployeeInfo.kt | 18 +++-- .../test_feature/hr/model/EmployeeStatus.kt | 4 +- test_feature/hr/impl/build.gradle.kts | 8 ++- .../hr/department/DepartmentImpl.kt | 38 ++++------- .../hr/department/SecurityDepartmentImpl.kt | 6 +- .../hr/department/SoftwareDepartmentImpl.kt | 6 +- .../test_feature/hr/di/DepartmentsModule.kt | 31 +++++---- .../stone/test_feature/hr/di/HrComponent.kt | 20 +++--- .../test_feature/hr/di/HrDependencies.kt | 9 +-- .../test_feature/hr/store/EmployeesStore.kt | 5 +- test_feature/planning/api/build.gradle.kts | 2 +- .../planning/model/ProjectInfo.kt | 5 +- .../test_feature/planning/model/TaskInfo.kt | 5 +- .../planning/project/BuildFactoryProject.kt | 5 +- .../planning/project/LogisticProject.kt | 5 +- .../test_feature/planning/project/Project.kt | 17 +++-- test_feature/planning/impl/build.gradle.kts | 7 +- .../test_feature/planning/PlanningRun.kt | 32 ++++----- .../planning/di/PlanningComponent.kt | 20 +++--- .../planning/di/PlanningDependencies.kt | 16 ++--- .../planning/di/ProjectsModule.kt | 31 ++++----- .../project/BuildFactoryProjectImpl.kt | 5 +- .../planning/project/LogisticProjectImpl.kt | 5 +- .../planning/project/ProjectImpl.kt | 34 ++++------ .../planning/store/ProjectsStore.kt | 5 +- 47 files changed, 332 insertions(+), 414 deletions(-) diff --git a/test_feature/companies/consulting/build.gradle.kts b/test_feature/companies/consulting/build.gradle.kts index 26e6aea2..ac46d45c 100644 --- a/test_feature/companies/consulting/build.gradle.kts +++ b/test_feature/companies/consulting/build.gradle.kts @@ -1,5 +1,6 @@ plugins { - java + alias(libs.plugins.kotlin.jvm) + alias(libs.plugins.kotlin.ksp) } group = "com.github.klee0kai.stone.test_feature.consulting" @@ -17,8 +18,8 @@ dependencies { implementation(project(":test_feature:finance:impl")) implementation(project(":test_feature:planning:impl")) - implementation(project(":stone_lib")) - annotationProcessor(project(":stone_processor")) + implementation(project(":stone_multiplatform")) + ksp(project(":stone_ksp")) testImplementation(libs.bundles.junit) } diff --git a/test_feature/companies/consulting/src/main/java/com/github/klee0kai/stone/test_feature/consulting/di/ConsultingComponent.kt b/test_feature/companies/consulting/src/main/java/com/github/klee0kai/stone/test_feature/consulting/di/ConsultingComponent.kt index 33ee98e9..d20a0a50 100644 --- a/test_feature/companies/consulting/src/main/java/com/github/klee0kai/stone/test_feature/consulting/di/ConsultingComponent.kt +++ b/test_feature/companies/consulting/src/main/java/com/github/klee0kai/stone/test_feature/consulting/di/ConsultingComponent.kt @@ -1,23 +1,21 @@ -package com.github.klee0kai.stone.test_feature.consulting.di; +package com.github.klee0kai.stone.test_feature.consulting.di -import com.github.klee0kai.stone.annotations.component.Component; -import com.github.klee0kai.stone.annotations.module.BindInstance; -import com.github.klee0kai.stone.test_feature.finance.di.AccountingModule; -import com.github.klee0kai.stone.test_feature.finance.model.WorkCalendar; -import com.github.klee0kai.stone.test_feature.hr.di.DepartmentsModule; -import com.github.klee0kai.stone.test_feature.planning.di.ProjectsModule; +import com.github.klee0kai.stone.annotations.component.Component +import com.github.klee0kai.stone.annotations.module.BindInstance +import com.github.klee0kai.stone.test_feature.finance.di.AccountingModule +import com.github.klee0kai.stone.test_feature.finance.model.WorkCalendar +import com.github.klee0kai.stone.test_feature.hr.di.DepartmentsModule +import com.github.klee0kai.stone.test_feature.planning.di.ProjectsModule @Component -public interface ConsultingComponent extends ConsultingDependencies { +interface ConsultingComponent : ConsultingDependencies { - DepartmentsModule departmentsModule(); + fun departmentsModule(): DepartmentsModule? - AccountingModule accountingModule(); + fun accountingModule(): AccountingModule? - ProjectsModule projectsModule(); + fun projectsModule(): ProjectsModule? @BindInstance(cache = BindInstance.CacheType.Strong) - WorkCalendar workCalendar(WorkCalendar workCalendar); - - + fun workCalendar(workCalendar: WorkCalendar?): WorkCalendar? } diff --git a/test_feature/companies/consulting/src/main/java/com/github/klee0kai/stone/test_feature/consulting/di/ConsultingDependencies.kt b/test_feature/companies/consulting/src/main/java/com/github/klee0kai/stone/test_feature/consulting/di/ConsultingDependencies.kt index 772aa65f..e2e1615b 100644 --- a/test_feature/companies/consulting/src/main/java/com/github/klee0kai/stone/test_feature/consulting/di/ConsultingDependencies.kt +++ b/test_feature/companies/consulting/src/main/java/com/github/klee0kai/stone/test_feature/consulting/di/ConsultingDependencies.kt @@ -1,8 +1,7 @@ -package com.github.klee0kai.stone.test_feature.consulting.di; +package com.github.klee0kai.stone.test_feature.consulting.di -import com.github.klee0kai.stone.test_feature.finance.di.AccountingDependencies; -import com.github.klee0kai.stone.test_feature.hr.di.HrDependencies; -import com.github.klee0kai.stone.test_feature.planning.di.PlanningDependencies; +import com.github.klee0kai.stone.test_feature.finance.di.AccountingDependencies +import com.github.klee0kai.stone.test_feature.hr.di.HrDependencies +import com.github.klee0kai.stone.test_feature.planning.di.PlanningDependencies -public interface ConsultingDependencies extends HrDependencies, PlanningDependencies, AccountingDependencies { -} +interface ConsultingDependencies : HrDependencies, PlanningDependencies, AccountingDependencies diff --git a/test_feature/companies/consulting/src/test/java/com/github/klee0kai/stone/test_feature/consulting/dependencies/ProvideDependenciesTests.kt b/test_feature/companies/consulting/src/test/java/com/github/klee0kai/stone/test_feature/consulting/dependencies/ProvideDependenciesTests.kt index ba1a8d84..6d04b583 100644 --- a/test_feature/companies/consulting/src/test/java/com/github/klee0kai/stone/test_feature/consulting/dependencies/ProvideDependenciesTests.kt +++ b/test_feature/companies/consulting/src/test/java/com/github/klee0kai/stone/test_feature/consulting/dependencies/ProvideDependenciesTests.kt @@ -1,44 +1,45 @@ -package com.github.klee0kai.stone.test_feature.consulting.dependencies; +package com.github.klee0kai.stone.test_feature.consulting.dependencies -import com.github.klee0kai.stone.Stone; -import com.github.klee0kai.stone.test_feature.consulting.di.ConsultingComponent; -import com.github.klee0kai.stone.test_feature.finance.di.AccountingComponent; -import com.github.klee0kai.stone.test_feature.hr.di.HrComponent; -import com.github.klee0kai.stone.test_feature.hr.di.HrDependencies; -import com.github.klee0kai.stone.test_feature.planning.project.LogisticProject; -import org.junit.jupiter.api.Test; +import com.github.klee0kai.stone.test_feature.consulting.di.ConsultingComponent +import com.github.klee0kai.stone.test_feature.consulting.di.ConsultingComponentStoneComponent +import com.github.klee0kai.stone.test_feature.finance.di.AccountingComponent +import com.github.klee0kai.stone.test_feature.finance.di.AccountingComponentStoneComponent +import com.github.klee0kai.stone.test_feature.hr.di.HrComponent +import com.github.klee0kai.stone.test_feature.hr.di.HrComponentStoneComponent +import com.github.klee0kai.stone.test_feature.planning.project.LogisticProject +import org.junit.jupiter.api.Assertions.assertEquals +import org.junit.jupiter.api.Test +import org.junit.jupiter.api.assertNotNull -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotNull; -public class ProvideDependenciesTests { +class ProvideDependenciesTests { @Test - void hrNoDepsTest() { + fun hrNoDepsTest() { //Given - ConsultingComponent appDI = Stone.createComponent(ConsultingComponent.class); - HrComponent featureDi = Stone.createComponent(HrComponent.class); + val appDI: ConsultingComponent = ConsultingComponentStoneComponent() + val featureDi: HrComponent = HrComponentStoneComponent() //When - featureDi.initDeps(appDI); + featureDi.initDeps(appDI) //Then - HrDependencies hrDeps = featureDi.hrDependencies(); - assertEquals(appDI, hrDeps); + val hrDeps = featureDi.hrDependencies() + assertEquals(appDI, hrDeps) } @Test - void provideLogisticProjectDepsTest() { + fun provideLogisticProjectDepsTest() { //Given - ConsultingComponent appDI = Stone.createComponent(ConsultingComponent.class); - AccountingComponent featureDi = Stone.createComponent(AccountingComponent.class); + val appDI: ConsultingComponent? = ConsultingComponentStoneComponent() + val featureDi: AccountingComponent = AccountingComponentStoneComponent() //When - featureDi.initDeps(appDI); + featureDi.initDeps(appDI) //Then - LogisticProject logisticProject = featureDi.dependencies().logisticProject(); - assertNotNull(logisticProject); + val logisticProject: LogisticProject? = featureDi.dependencies()?.logisticProject() + assertNotNull(logisticProject) } } diff --git a/test_feature/companies/consulting/src/test/java/com/github/klee0kai/stone/test_feature/consulting/dependencies/inject/PlanningRunInject2Tests.kt b/test_feature/companies/consulting/src/test/java/com/github/klee0kai/stone/test_feature/consulting/dependencies/inject/PlanningRunInject2Tests.kt index c36b60b6..efd6e2b3 100644 --- a/test_feature/companies/consulting/src/test/java/com/github/klee0kai/stone/test_feature/consulting/dependencies/inject/PlanningRunInject2Tests.kt +++ b/test_feature/companies/consulting/src/test/java/com/github/klee0kai/stone/test_feature/consulting/dependencies/inject/PlanningRunInject2Tests.kt @@ -1,54 +1,53 @@ -package com.github.klee0kai.stone.test_feature.consulting.dependencies.inject; +package com.github.klee0kai.stone.test_feature.consulting.dependencies.inject -import com.github.klee0kai.stone.Stone; -import com.github.klee0kai.stone.test_feature.consulting.di.ConsultingComponent; -import com.github.klee0kai.stone.test_feature.finance.model.WorkCalendar; -import com.github.klee0kai.stone.test_feature.planning.PlanningRun; -import com.github.klee0kai.stone.test_feature.planning.di.PlanningComponent; -import org.junit.jupiter.api.Test; +import com.github.klee0kai.stone.test_feature.consulting.di.ConsultingComponent +import com.github.klee0kai.stone.test_feature.consulting.di.ConsultingComponentStoneComponent +import com.github.klee0kai.stone.test_feature.finance.model.WorkCalendar +import com.github.klee0kai.stone.test_feature.planning.PlanningRun +import com.github.klee0kai.stone.test_feature.planning.di.PlanningComponent +import com.github.klee0kai.stone.test_feature.planning.di.PlanningComponentStoneComponent +import org.junit.jupiter.api.Assertions.assertEquals +import org.junit.jupiter.api.Test +import org.junit.jupiter.api.assertNotNull -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotNull; - -public class PlanningRunInject2Tests { +class PlanningRunInject2Tests { @Test - public void simpleInjectTest() { + fun simpleInjectTest() { //Given - ConsultingComponent di = Stone.createComponent(ConsultingComponent.class); - di.workCalendar(new WorkCalendar("test", 240, 8)); - PlanningComponent featureDi = Stone.createComponent(PlanningComponent.class); - featureDi.initDep(di); - PlanningRun planningRun = new PlanningRun(featureDi); + val di: ConsultingComponent = ConsultingComponentStoneComponent() + di.workCalendar(WorkCalendar("test", 240, 8)) + val featureDi: PlanningComponent = PlanningComponentStoneComponent() + featureDi.initDep(di) + val planningRun: PlanningRun = PlanningRun(featureDi) //When - planningRun.start(); + planningRun.start() //Then - assertNotNull(planningRun.logisticProject); - assertNotNull(planningRun.workCalendar); - assertNotNull(planningRun.securityDepartment); + assertNotNull(planningRun.logisticProject) + assertNotNull(planningRun.workCalendar) + assertNotNull(planningRun.securityDepartment) } @Test - public void commonComponentsInjectTest() { + fun commonComponentsInjectTest() { //Given - ConsultingComponent di = Stone.createComponent(ConsultingComponent.class); - di.workCalendar(new WorkCalendar("test", 240, 8)); - PlanningComponent featureDi = Stone.createComponent(PlanningComponent.class); - featureDi.initDep(di); - PlanningRun planningRun1 = new PlanningRun(featureDi); - PlanningRun planningRun2 = new PlanningRun(featureDi); + val di: ConsultingComponent = ConsultingComponentStoneComponent() + di.workCalendar(WorkCalendar("test", 240, 8)) + val featureDi: PlanningComponent = PlanningComponentStoneComponent() + featureDi.initDep(di) + val planningRun1 = PlanningRun(featureDi) + val planningRun2 = PlanningRun(featureDi) //When - planningRun1.start(); - planningRun2.start(); + planningRun1.start() + planningRun2.start() //Then - assertEquals(planningRun1.logisticProject.getId(), planningRun2.logisticProject.getId()); - assertEquals(planningRun1.securityDepartment.getId(), planningRun2.securityDepartment.getId()); - assertEquals(planningRun1.workCalendar.uuid, planningRun2.workCalendar.uuid); + assertEquals(planningRun1.logisticProject!!.id, planningRun2.logisticProject!!.id) + assertEquals(planningRun1.securityDepartment!!.id, planningRun2.securityDepartment!!.id) + assertEquals(planningRun1.workCalendar!!.uuid, planningRun2.workCalendar!!.uuid) } - } diff --git a/test_feature/companies/consulting/src/test/java/com/github/klee0kai/stone/test_feature/consulting/dependencies/inject/PlanningRunInjectTests.kt b/test_feature/companies/consulting/src/test/java/com/github/klee0kai/stone/test_feature/consulting/dependencies/inject/PlanningRunInjectTests.kt index b5b6e2bf..4e482b58 100644 --- a/test_feature/companies/consulting/src/test/java/com/github/klee0kai/stone/test_feature/consulting/dependencies/inject/PlanningRunInjectTests.kt +++ b/test_feature/companies/consulting/src/test/java/com/github/klee0kai/stone/test_feature/consulting/dependencies/inject/PlanningRunInjectTests.kt @@ -1,54 +1,53 @@ -package com.github.klee0kai.stone.test_feature.consulting.dependencies.inject; +package com.github.klee0kai.stone.test_feature.consulting.dependencies.inject -import com.github.klee0kai.stone.Stone; -import com.github.klee0kai.stone.test_feature.consulting.di.ConsultingComponent; -import com.github.klee0kai.stone.test_feature.finance.model.WorkCalendar; -import com.github.klee0kai.stone.test_feature.planning.PlanningRun; -import com.github.klee0kai.stone.test_feature.planning.di.PlanningComponent; -import org.junit.jupiter.api.Test; +import com.github.klee0kai.stone.test_feature.consulting.di.ConsultingComponent +import com.github.klee0kai.stone.test_feature.consulting.di.ConsultingComponentStoneComponent +import com.github.klee0kai.stone.test_feature.finance.model.WorkCalendar +import com.github.klee0kai.stone.test_feature.planning.PlanningRun +import com.github.klee0kai.stone.test_feature.planning.di.PlanningComponent +import com.github.klee0kai.stone.test_feature.planning.di.PlanningComponentStoneComponent +import org.junit.jupiter.api.Assertions.assertEquals +import org.junit.jupiter.api.Test +import org.junit.jupiter.api.assertNotNull -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotNull; - -public class PlanningRunInjectTests { +class PlanningRunInjectTests { @Test - public void simpleInjectTest() { + fun simpleInjectTest() { //Given - ConsultingComponent di = Stone.createComponent(ConsultingComponent.class); - di.workCalendar(new WorkCalendar("test", 240, 8)); - PlanningComponent featureDi = Stone.createComponent(PlanningComponent.class); - featureDi.initDep(di); - PlanningRun planningRun = new PlanningRun(featureDi); + val di: ConsultingComponent = ConsultingComponentStoneComponent() + di.workCalendar(WorkCalendar("test", 240, 8)) + val featureDi: PlanningComponent = PlanningComponentStoneComponent() + featureDi.initDep(di) + val planningRun: PlanningRun = PlanningRun(featureDi) //When - planningRun.start(); + planningRun.start() //Then - assertNotNull(planningRun.logisticProject); - assertNotNull(planningRun.workCalendar); - assertNotNull(planningRun.securityDepartment); + assertNotNull(planningRun.logisticProject) + assertNotNull(planningRun.workCalendar) + assertNotNull(planningRun.securityDepartment) } @Test - public void commonComponentsInjectTest() { + fun commonComponentsInjectTest() { //Given - ConsultingComponent di = Stone.createComponent(ConsultingComponent.class); - di.workCalendar(new WorkCalendar("test", 240, 8)); - PlanningComponent featureDi = Stone.createComponent(PlanningComponent.class); - featureDi.initDep(di); - PlanningRun planningRun1 = new PlanningRun(featureDi); - PlanningRun planningRun2 = new PlanningRun(featureDi); + val di: ConsultingComponent = ConsultingComponentStoneComponent() + di.workCalendar(WorkCalendar("test", 240, 8)) + val featureDi: PlanningComponent = PlanningComponentStoneComponent() + featureDi.initDep(di) + val planningRun1 = PlanningRun(featureDi) + val planningRun2 = PlanningRun(featureDi) //When - planningRun1.start(); - planningRun2.start(); + planningRun1.start() + planningRun2.start() //Then - assertEquals(planningRun1.logisticProject.getId(), planningRun2.logisticProject.getId()); - assertEquals(planningRun1.securityDepartment.getId(), planningRun2.securityDepartment.getId()); - assertEquals(planningRun1.workCalendar.uuid, planningRun2.workCalendar.uuid); + assertEquals(planningRun1.logisticProject!!.id, planningRun2.logisticProject!!.id) + assertEquals(planningRun1.securityDepartment!!.id, planningRun2.securityDepartment!!.id) + assertEquals(planningRun1.workCalendar!!.uuid, planningRun2.workCalendar!!.uuid) } - } diff --git a/test_feature/finance/api/build.gradle.kts b/test_feature/finance/api/build.gradle.kts index f0a4d6b9..921c79fa 100644 --- a/test_feature/finance/api/build.gradle.kts +++ b/test_feature/finance/api/build.gradle.kts @@ -1,5 +1,5 @@ plugins { - java + alias(libs.plugins.kotlin.jvm) } group = "com.github.klee0kai.stone.test_feature.finance" diff --git a/test_feature/finance/api/src/main/java/com/github/klee0kai/stone/test_feature/finance/accounting/Accounting.kt b/test_feature/finance/api/src/main/java/com/github/klee0kai/stone/test_feature/finance/accounting/Accounting.kt index 65d02ddb..26cd8414 100644 --- a/test_feature/finance/api/src/main/java/com/github/klee0kai/stone/test_feature/finance/accounting/Accounting.kt +++ b/test_feature/finance/api/src/main/java/com/github/klee0kai/stone/test_feature/finance/accounting/Accounting.kt @@ -1,11 +1,11 @@ -package com.github.klee0kai.stone.test_feature.finance.accounting; +package com.github.klee0kai.stone.test_feature.finance.accounting -import com.github.klee0kai.stone.test_feature.finance.model.BalanceInfo; +import com.github.klee0kai.stone.test_feature.finance.model.BalanceInfo -public interface Accounting { +interface Accounting { - BalanceInfo currentBalance(); + fun currentBalance(): BalanceInfo? - BalanceInfo plannedBalance(long days); + fun plannedBalance(days: Long): BalanceInfo? } diff --git a/test_feature/finance/api/src/main/java/com/github/klee0kai/stone/test_feature/finance/model/BalanceInfo.kt b/test_feature/finance/api/src/main/java/com/github/klee0kai/stone/test_feature/finance/model/BalanceInfo.kt index 5b33266e..f57bbd5e 100644 --- a/test_feature/finance/api/src/main/java/com/github/klee0kai/stone/test_feature/finance/model/BalanceInfo.kt +++ b/test_feature/finance/api/src/main/java/com/github/klee0kai/stone/test_feature/finance/model/BalanceInfo.kt @@ -1,7 +1,5 @@ -package com.github.klee0kai.stone.test_feature.finance.model; - -public class BalanceInfo { - - public Long balance; +package com.github.klee0kai.stone.test_feature.finance.model +class BalanceInfo { + var balance: Long? = null } diff --git a/test_feature/finance/api/src/main/java/com/github/klee0kai/stone/test_feature/finance/model/WorkCalendar.kt b/test_feature/finance/api/src/main/java/com/github/klee0kai/stone/test_feature/finance/model/WorkCalendar.kt index 3c621323..7a982028 100644 --- a/test_feature/finance/api/src/main/java/com/github/klee0kai/stone/test_feature/finance/model/WorkCalendar.kt +++ b/test_feature/finance/api/src/main/java/com/github/klee0kai/stone/test_feature/finance/model/WorkCalendar.kt @@ -1,19 +1,11 @@ -package com.github.klee0kai.stone.test_feature.finance.model; +package com.github.klee0kai.stone.test_feature.finance.model -import java.util.UUID; - -public class WorkCalendar { - - public final String uuid = UUID.randomUUID().toString(); - - public final String name; - public final int workDaysInYear; - public final int workHoursInDay; - - public WorkCalendar(String name, int workDaysInYear, int workHoursInDay) { - this.name = name; - this.workDaysInYear = workDaysInYear; - this.workHoursInDay = workHoursInDay; - } +import java.util.* +class WorkCalendar( + val name: String?, + val workDaysInYear: Int, + val workHoursInDay: Int, +) { + val uuid: String = UUID.randomUUID().toString() } diff --git a/test_feature/finance/impl/build.gradle.kts b/test_feature/finance/impl/build.gradle.kts index f7bf4a8b..bf9e4414 100644 --- a/test_feature/finance/impl/build.gradle.kts +++ b/test_feature/finance/impl/build.gradle.kts @@ -1,5 +1,6 @@ plugins { - java + alias(libs.plugins.kotlin.jvm) + alias(libs.plugins.kotlin.ksp) } group = "com.github.klee0kai.stone.test_feature.finance" @@ -13,7 +14,7 @@ dependencies { implementation(project(":test_feature:hr:api")) implementation(project(":test_feature:planning:api")) - implementation(project(":stone_lib")) - annotationProcessor(project(":stone_processor")) + implementation(project(":stone_multiplatform")) + ksp(project(":stone_ksp")) } diff --git a/test_feature/finance/impl/src/main/java/com/github/klee0kai/stone/test_feature/finance/accounting/AccountingImpl.kt b/test_feature/finance/impl/src/main/java/com/github/klee0kai/stone/test_feature/finance/accounting/AccountingImpl.kt index e40ea467..5853911a 100644 --- a/test_feature/finance/impl/src/main/java/com/github/klee0kai/stone/test_feature/finance/accounting/AccountingImpl.kt +++ b/test_feature/finance/impl/src/main/java/com/github/klee0kai/stone/test_feature/finance/accounting/AccountingImpl.kt @@ -1,15 +1,14 @@ -package com.github.klee0kai.stone.test_feature.finance.accounting; +package com.github.klee0kai.stone.test_feature.finance.accounting -import com.github.klee0kai.stone.test_feature.finance.model.BalanceInfo; +import com.github.klee0kai.stone.test_feature.finance.model.BalanceInfo -public class AccountingImpl implements Accounting { - @Override - public BalanceInfo currentBalance() { - return null; +class AccountingImpl : Accounting { + + override fun currentBalance(): BalanceInfo? { + return null } - @Override - public BalanceInfo plannedBalance(long days) { - return null; + override fun plannedBalance(days: Long): BalanceInfo? { + return null } } diff --git a/test_feature/finance/impl/src/main/java/com/github/klee0kai/stone/test_feature/finance/di/AccountingComponent.kt b/test_feature/finance/impl/src/main/java/com/github/klee0kai/stone/test_feature/finance/di/AccountingComponent.kt index e20014d6..fc64877a 100644 --- a/test_feature/finance/impl/src/main/java/com/github/klee0kai/stone/test_feature/finance/di/AccountingComponent.kt +++ b/test_feature/finance/impl/src/main/java/com/github/klee0kai/stone/test_feature/finance/di/AccountingComponent.kt @@ -1,16 +1,14 @@ -package com.github.klee0kai.stone.test_feature.finance.di; +package com.github.klee0kai.stone.test_feature.finance.di -import com.github.klee0kai.stone.annotations.component.Component; -import com.github.klee0kai.stone.annotations.component.Init; +import com.github.klee0kai.stone.annotations.component.Component +import com.github.klee0kai.stone.annotations.component.Init @Component -public interface AccountingComponent { +interface AccountingComponent { + fun dependencies(): AccountingDependencies? - AccountingDependencies dependencies(); - - AccountingModule accounting(); + fun accounting(): AccountingModule? @Init - void initDeps(AccountingDependencies deps); - + fun initDeps(deps: AccountingDependencies?) } diff --git a/test_feature/finance/impl/src/main/java/com/github/klee0kai/stone/test_feature/finance/di/AccountingDependencies.kt b/test_feature/finance/impl/src/main/java/com/github/klee0kai/stone/test_feature/finance/di/AccountingDependencies.kt index 4af33b25..68993b82 100644 --- a/test_feature/finance/impl/src/main/java/com/github/klee0kai/stone/test_feature/finance/di/AccountingDependencies.kt +++ b/test_feature/finance/impl/src/main/java/com/github/klee0kai/stone/test_feature/finance/di/AccountingDependencies.kt @@ -1,20 +1,20 @@ -package com.github.klee0kai.stone.test_feature.finance.di; +package com.github.klee0kai.stone.test_feature.finance.di -import com.github.klee0kai.stone.annotations.dependencies.Dependencies; -import com.github.klee0kai.stone.test_feature.hr.department.SecurityDepartment; -import com.github.klee0kai.stone.test_feature.hr.department.SoftwareDepartment; -import com.github.klee0kai.stone.test_feature.planning.project.BuildFactoryProject; -import com.github.klee0kai.stone.test_feature.planning.project.LogisticProject; +import com.github.klee0kai.stone.annotations.dependencies.Dependencies +import com.github.klee0kai.stone.test_feature.hr.department.SecurityDepartment +import com.github.klee0kai.stone.test_feature.hr.department.SoftwareDepartment +import com.github.klee0kai.stone.test_feature.planning.project.BuildFactoryProject +import com.github.klee0kai.stone.test_feature.planning.project.LogisticProject @Dependencies -public interface AccountingDependencies { +interface AccountingDependencies { - SecurityDepartment securityDepartment(); + fun securityDepartment(): SecurityDepartment? - SoftwareDepartment softwareDepartment(); + fun softwareDepartment(): SoftwareDepartment? - LogisticProject logisticProject(); + fun logisticProject(): LogisticProject? - BuildFactoryProject buildFactoryProject(); + fun buildFactoryProject(): BuildFactoryProject? } diff --git a/test_feature/finance/impl/src/main/java/com/github/klee0kai/stone/test_feature/finance/di/AccountingModule.kt b/test_feature/finance/impl/src/main/java/com/github/klee0kai/stone/test_feature/finance/di/AccountingModule.kt index ff8c0cef..25afa1d7 100644 --- a/test_feature/finance/impl/src/main/java/com/github/klee0kai/stone/test_feature/finance/di/AccountingModule.kt +++ b/test_feature/finance/impl/src/main/java/com/github/klee0kai/stone/test_feature/finance/di/AccountingModule.kt @@ -1,19 +1,18 @@ -package com.github.klee0kai.stone.test_feature.finance.di; +package com.github.klee0kai.stone.test_feature.finance.di -import com.github.klee0kai.stone.annotations.module.Module; -import com.github.klee0kai.stone.annotations.module.Provide; -import com.github.klee0kai.stone.test_feature.finance.accounting.Accounting; -import com.github.klee0kai.stone.test_feature.finance.store.AccountingStore; +import com.github.klee0kai.stone.annotations.module.Module +import com.github.klee0kai.stone.annotations.module.Provide +import com.github.klee0kai.stone.test_feature.finance.accounting.Accounting +import com.github.klee0kai.stone.test_feature.finance.store.AccountingStore @Module -public abstract class AccountingModule { +abstract class AccountingModule { @Provide(cache = Provide.CacheType.Soft) - public Accounting accounting() { - return null; + open fun accounting(): Accounting? { + return null } @Provide(cache = Provide.CacheType.Soft) - public abstract AccountingStore accountingStore(); - + abstract fun accountingStore(): AccountingStore? } diff --git a/test_feature/finance/impl/src/main/java/com/github/klee0kai/stone/test_feature/finance/store/AccountingStore.kt b/test_feature/finance/impl/src/main/java/com/github/klee0kai/stone/test_feature/finance/store/AccountingStore.kt index e8922639..97850742 100644 --- a/test_feature/finance/impl/src/main/java/com/github/klee0kai/stone/test_feature/finance/store/AccountingStore.kt +++ b/test_feature/finance/impl/src/main/java/com/github/klee0kai/stone/test_feature/finance/store/AccountingStore.kt @@ -1,4 +1,3 @@ -package com.github.klee0kai.stone.test_feature.finance.store; +package com.github.klee0kai.stone.test_feature.finance.store -public class AccountingStore { -} +class AccountingStore diff --git a/test_feature/hr/api/build.gradle.kts b/test_feature/hr/api/build.gradle.kts index 63a737e3..5bfa0fcb 100644 --- a/test_feature/hr/api/build.gradle.kts +++ b/test_feature/hr/api/build.gradle.kts @@ -1,5 +1,5 @@ plugins { - java + alias(libs.plugins.kotlin.jvm) } group = "com.github.klee0kai.stone.test_feature.hr" diff --git a/test_feature/hr/api/src/main/java/com/github/klee0kai/stone/test_feature/hr/department/Department.kt b/test_feature/hr/api/src/main/java/com/github/klee0kai/stone/test_feature/hr/department/Department.kt index 59f4c81c..3f227ccd 100644 --- a/test_feature/hr/api/src/main/java/com/github/klee0kai/stone/test_feature/hr/department/Department.kt +++ b/test_feature/hr/api/src/main/java/com/github/klee0kai/stone/test_feature/hr/department/Department.kt @@ -1,20 +1,16 @@ -package com.github.klee0kai.stone.test_feature.hr.department; +package com.github.klee0kai.stone.test_feature.hr.department -import com.github.klee0kai.stone.test_feature.hr.model.DepartmentInfo; -import com.github.klee0kai.stone.test_feature.hr.model.EmployeeInfo; +import com.github.klee0kai.stone.test_feature.hr.model.DepartmentInfo +import com.github.klee0kai.stone.test_feature.hr.model.EmployeeInfo -import java.util.List; +interface Department { + val id: String? -public interface Department { + val info: DepartmentInfo? - String getId(); + fun employers(): MutableList? - DepartmentInfo getInfo(); - - List employers(); - - void hireEmployee(EmployeeInfo employeeInfo); - - void fireEmployee(EmployeeInfo employeeInfo); + fun hireEmployee(employeeInfo: EmployeeInfo?) + fun fireEmployee(employeeInfo: EmployeeInfo?) } diff --git a/test_feature/hr/api/src/main/java/com/github/klee0kai/stone/test_feature/hr/department/SecurityDepartment.kt b/test_feature/hr/api/src/main/java/com/github/klee0kai/stone/test_feature/hr/department/SecurityDepartment.kt index 11ab549b..6b252486 100644 --- a/test_feature/hr/api/src/main/java/com/github/klee0kai/stone/test_feature/hr/department/SecurityDepartment.kt +++ b/test_feature/hr/api/src/main/java/com/github/klee0kai/stone/test_feature/hr/department/SecurityDepartment.kt @@ -1,4 +1,3 @@ -package com.github.klee0kai.stone.test_feature.hr.department; +package com.github.klee0kai.stone.test_feature.hr.department -public interface SecurityDepartment extends Department { -} +interface SecurityDepartment : Department diff --git a/test_feature/hr/api/src/main/java/com/github/klee0kai/stone/test_feature/hr/department/SoftwareDepartment.kt b/test_feature/hr/api/src/main/java/com/github/klee0kai/stone/test_feature/hr/department/SoftwareDepartment.kt index e27ef207..7725c0be 100644 --- a/test_feature/hr/api/src/main/java/com/github/klee0kai/stone/test_feature/hr/department/SoftwareDepartment.kt +++ b/test_feature/hr/api/src/main/java/com/github/klee0kai/stone/test_feature/hr/department/SoftwareDepartment.kt @@ -1,4 +1,3 @@ -package com.github.klee0kai.stone.test_feature.hr.department; +package com.github.klee0kai.stone.test_feature.hr.department -public interface SoftwareDepartment extends Department { -} +interface SoftwareDepartment : Department diff --git a/test_feature/hr/api/src/main/java/com/github/klee0kai/stone/test_feature/hr/department/WorkingGroup.kt b/test_feature/hr/api/src/main/java/com/github/klee0kai/stone/test_feature/hr/department/WorkingGroup.kt index 0646e7b6..67b30fd5 100644 --- a/test_feature/hr/api/src/main/java/com/github/klee0kai/stone/test_feature/hr/department/WorkingGroup.kt +++ b/test_feature/hr/api/src/main/java/com/github/klee0kai/stone/test_feature/hr/department/WorkingGroup.kt @@ -1,4 +1,3 @@ -package com.github.klee0kai.stone.test_feature.hr.department; +package com.github.klee0kai.stone.test_feature.hr.department -public interface WorkingGroup { -} +interface WorkingGroup diff --git a/test_feature/hr/api/src/main/java/com/github/klee0kai/stone/test_feature/hr/model/DepartmentInfo.kt b/test_feature/hr/api/src/main/java/com/github/klee0kai/stone/test_feature/hr/model/DepartmentInfo.kt index 4db30937..1379742b 100644 --- a/test_feature/hr/api/src/main/java/com/github/klee0kai/stone/test_feature/hr/model/DepartmentInfo.kt +++ b/test_feature/hr/api/src/main/java/com/github/klee0kai/stone/test_feature/hr/model/DepartmentInfo.kt @@ -1,12 +1,9 @@ -package com.github.klee0kai.stone.test_feature.hr.model; +package com.github.klee0kai.stone.test_feature.hr.model -public class DepartmentInfo { - - public Long id; - - public String name; - - public String description; +class DepartmentInfo { + var id: Long? = null + var name: String? = null + var description: String? = null } diff --git a/test_feature/hr/api/src/main/java/com/github/klee0kai/stone/test_feature/hr/model/EmployeeInfo.kt b/test_feature/hr/api/src/main/java/com/github/klee0kai/stone/test_feature/hr/model/EmployeeInfo.kt index 7429338d..08e435d0 100644 --- a/test_feature/hr/api/src/main/java/com/github/klee0kai/stone/test_feature/hr/model/EmployeeInfo.kt +++ b/test_feature/hr/api/src/main/java/com/github/klee0kai/stone/test_feature/hr/model/EmployeeInfo.kt @@ -1,13 +1,11 @@ -package com.github.klee0kai.stone.test_feature.hr.model; +package com.github.klee0kai.stone.test_feature.hr.model -public class EmployeeInfo { - - public Long id; - public Long departmentId; - - public String name; - public String position; - public Long salary; - public EmployeeStatus status; +class EmployeeInfo { + var id: Long? = null + var departmentId: Long? = null + var name: String? = null + var position: String? = null + var salary: Long? = null + var status: EmployeeStatus? = null } diff --git a/test_feature/hr/api/src/main/java/com/github/klee0kai/stone/test_feature/hr/model/EmployeeStatus.kt b/test_feature/hr/api/src/main/java/com/github/klee0kai/stone/test_feature/hr/model/EmployeeStatus.kt index 49a02cbe..c268a508 100644 --- a/test_feature/hr/api/src/main/java/com/github/klee0kai/stone/test_feature/hr/model/EmployeeStatus.kt +++ b/test_feature/hr/api/src/main/java/com/github/klee0kai/stone/test_feature/hr/model/EmployeeStatus.kt @@ -1,6 +1,6 @@ -package com.github.klee0kai.stone.test_feature.hr.model; +package com.github.klee0kai.stone.test_feature.hr.model -public enum EmployeeStatus { +enum class EmployeeStatus { TERM_CONTRACT, UNTERM_CONTRACT, FIRED, diff --git a/test_feature/hr/impl/build.gradle.kts b/test_feature/hr/impl/build.gradle.kts index 2717d94a..6b3e7a92 100644 --- a/test_feature/hr/impl/build.gradle.kts +++ b/test_feature/hr/impl/build.gradle.kts @@ -1,5 +1,6 @@ plugins { - java + alias(libs.plugins.kotlin.jvm) + alias(libs.plugins.kotlin.ksp) } group = "com.github.klee0kai.stone.test_feature.hr" @@ -11,7 +12,8 @@ tasks.test { dependencies { implementation(project(":test_feature:hr:api")) - implementation(project(":stone_lib")) - annotationProcessor(project(":stone_processor")) + implementation(project(":stone_multiplatform")) + ksp(project(":stone_ksp")) + } diff --git a/test_feature/hr/impl/src/main/java/com/github/klee0kai/stone/test_feature/hr/department/DepartmentImpl.kt b/test_feature/hr/impl/src/main/java/com/github/klee0kai/stone/test_feature/hr/department/DepartmentImpl.kt index 56c1a3a8..75a512a3 100644 --- a/test_feature/hr/impl/src/main/java/com/github/klee0kai/stone/test_feature/hr/department/DepartmentImpl.kt +++ b/test_feature/hr/impl/src/main/java/com/github/klee0kai/stone/test_feature/hr/department/DepartmentImpl.kt @@ -1,37 +1,23 @@ -package com.github.klee0kai.stone.test_feature.hr.department; +package com.github.klee0kai.stone.test_feature.hr.department -import com.github.klee0kai.stone.test_feature.hr.model.DepartmentInfo; -import com.github.klee0kai.stone.test_feature.hr.model.EmployeeInfo; +import com.github.klee0kai.stone.test_feature.hr.model.DepartmentInfo +import com.github.klee0kai.stone.test_feature.hr.model.EmployeeInfo +import java.util.* -import java.util.List; -import java.util.UUID; +open class DepartmentImpl : Department { + var uuid: String? = UUID.randomUUID().toString() -public class DepartmentImpl implements Department { + override val id: String? get() = uuid - public String uuid = UUID.randomUUID().toString(); + override val info: DepartmentInfo? get() = null - @Override - public String getId() { - return uuid; + override fun employers(): MutableList? { + return null } - @Override - public DepartmentInfo getInfo() { - return null; + override fun hireEmployee(employeeInfo: EmployeeInfo?) { } - @Override - public List employers() { - return null; - } - - @Override - public void hireEmployee(EmployeeInfo employeeInfo) { - - } - - @Override - public void fireEmployee(EmployeeInfo employeeInfo) { - + override fun fireEmployee(employeeInfo: EmployeeInfo?) { } } diff --git a/test_feature/hr/impl/src/main/java/com/github/klee0kai/stone/test_feature/hr/department/SecurityDepartmentImpl.kt b/test_feature/hr/impl/src/main/java/com/github/klee0kai/stone/test_feature/hr/department/SecurityDepartmentImpl.kt index 609d087d..b3d94fab 100644 --- a/test_feature/hr/impl/src/main/java/com/github/klee0kai/stone/test_feature/hr/department/SecurityDepartmentImpl.kt +++ b/test_feature/hr/impl/src/main/java/com/github/klee0kai/stone/test_feature/hr/department/SecurityDepartmentImpl.kt @@ -1,5 +1,3 @@ -package com.github.klee0kai.stone.test_feature.hr.department; +package com.github.klee0kai.stone.test_feature.hr.department -public class SecurityDepartmentImpl extends DepartmentImpl implements SecurityDepartment { - -} +class SecurityDepartmentImpl : DepartmentImpl(), SecurityDepartment diff --git a/test_feature/hr/impl/src/main/java/com/github/klee0kai/stone/test_feature/hr/department/SoftwareDepartmentImpl.kt b/test_feature/hr/impl/src/main/java/com/github/klee0kai/stone/test_feature/hr/department/SoftwareDepartmentImpl.kt index 38bd4ce4..f25e212f 100644 --- a/test_feature/hr/impl/src/main/java/com/github/klee0kai/stone/test_feature/hr/department/SoftwareDepartmentImpl.kt +++ b/test_feature/hr/impl/src/main/java/com/github/klee0kai/stone/test_feature/hr/department/SoftwareDepartmentImpl.kt @@ -1,5 +1,3 @@ -package com.github.klee0kai.stone.test_feature.hr.department; +package com.github.klee0kai.stone.test_feature.hr.department -public class SoftwareDepartmentImpl extends DepartmentImpl implements SoftwareDepartment { - -} +class SoftwareDepartmentImpl : DepartmentImpl(), SoftwareDepartment diff --git a/test_feature/hr/impl/src/main/java/com/github/klee0kai/stone/test_feature/hr/di/DepartmentsModule.kt b/test_feature/hr/impl/src/main/java/com/github/klee0kai/stone/test_feature/hr/di/DepartmentsModule.kt index 9bfbc306..8c48ef98 100644 --- a/test_feature/hr/impl/src/main/java/com/github/klee0kai/stone/test_feature/hr/di/DepartmentsModule.kt +++ b/test_feature/hr/impl/src/main/java/com/github/klee0kai/stone/test_feature/hr/di/DepartmentsModule.kt @@ -1,30 +1,29 @@ -package com.github.klee0kai.stone.test_feature.hr.di; +package com.github.klee0kai.stone.test_feature.hr.di -import com.github.klee0kai.stone.annotations.module.Module; -import com.github.klee0kai.stone.annotations.module.Provide; -import com.github.klee0kai.stone.test_feature.hr.department.SecurityDepartment; -import com.github.klee0kai.stone.test_feature.hr.department.SecurityDepartmentImpl; -import com.github.klee0kai.stone.test_feature.hr.department.SoftwareDepartment; -import com.github.klee0kai.stone.test_feature.hr.department.SoftwareDepartmentImpl; -import com.github.klee0kai.stone.test_feature.hr.store.EmployeesStore; +import com.github.klee0kai.stone.annotations.module.Module +import com.github.klee0kai.stone.annotations.module.Provide +import com.github.klee0kai.stone.test_feature.hr.department.SecurityDepartment +import com.github.klee0kai.stone.test_feature.hr.department.SecurityDepartmentImpl +import com.github.klee0kai.stone.test_feature.hr.department.SoftwareDepartment +import com.github.klee0kai.stone.test_feature.hr.department.SoftwareDepartmentImpl +import com.github.klee0kai.stone.test_feature.hr.store.EmployeesStore @Module -public class DepartmentsModule { +interface DepartmentsModule { @Provide(cache = Provide.CacheType.Strong) - public EmployeesStore employeesStore() { - return new EmployeesStore(); + fun employeesStore(): EmployeesStore { + return EmployeesStore() } @Provide(cache = Provide.CacheType.Soft) - public SecurityDepartment securityDepartment() { - return new SecurityDepartmentImpl(); + fun securityDepartment(): SecurityDepartment { + return SecurityDepartmentImpl() } @Provide(cache = Provide.CacheType.Soft) - public SoftwareDepartment softwareDepartment() { - return new SoftwareDepartmentImpl(); + fun softwareDepartment(): SoftwareDepartment { + return SoftwareDepartmentImpl() } - } diff --git a/test_feature/hr/impl/src/main/java/com/github/klee0kai/stone/test_feature/hr/di/HrComponent.kt b/test_feature/hr/impl/src/main/java/com/github/klee0kai/stone/test_feature/hr/di/HrComponent.kt index 7158c96f..2ef05b22 100644 --- a/test_feature/hr/impl/src/main/java/com/github/klee0kai/stone/test_feature/hr/di/HrComponent.kt +++ b/test_feature/hr/impl/src/main/java/com/github/klee0kai/stone/test_feature/hr/di/HrComponent.kt @@ -1,19 +1,17 @@ -package com.github.klee0kai.stone.test_feature.hr.di; +package com.github.klee0kai.stone.test_feature.hr.di -import com.github.klee0kai.stone.annotations.component.Component; -import com.github.klee0kai.stone.annotations.component.Init; -import com.github.klee0kai.stone.test_feature.hr.store.EmployeesStore; +import com.github.klee0kai.stone.annotations.component.Component +import com.github.klee0kai.stone.annotations.component.Init +import com.github.klee0kai.stone.test_feature.hr.store.EmployeesStore @Component -public interface HrComponent { +interface HrComponent { + fun departmentsModule(): DepartmentsModule? - DepartmentsModule departmentsModule(); + fun hrDependencies(): HrDependencies? - HrDependencies hrDependencies(); - - EmployeesStore employeesStore(); + fun employeesStore(): EmployeesStore? @Init - void initDeps(HrDependencies deps); - + fun initDeps(deps: HrDependencies?) } diff --git a/test_feature/hr/impl/src/main/java/com/github/klee0kai/stone/test_feature/hr/di/HrDependencies.kt b/test_feature/hr/impl/src/main/java/com/github/klee0kai/stone/test_feature/hr/di/HrDependencies.kt index 94b3c326..1927ce85 100644 --- a/test_feature/hr/impl/src/main/java/com/github/klee0kai/stone/test_feature/hr/di/HrDependencies.kt +++ b/test_feature/hr/impl/src/main/java/com/github/klee0kai/stone/test_feature/hr/di/HrDependencies.kt @@ -1,9 +1,6 @@ -package com.github.klee0kai.stone.test_feature.hr.di; +package com.github.klee0kai.stone.test_feature.hr.di -import com.github.klee0kai.stone.annotations.dependencies.Dependencies; +import com.github.klee0kai.stone.annotations.dependencies.Dependencies @Dependencies -public interface HrDependencies { - - -} +interface HrDependencies diff --git a/test_feature/hr/impl/src/main/java/com/github/klee0kai/stone/test_feature/hr/store/EmployeesStore.kt b/test_feature/hr/impl/src/main/java/com/github/klee0kai/stone/test_feature/hr/store/EmployeesStore.kt index 2fb22d13..e3efc06f 100644 --- a/test_feature/hr/impl/src/main/java/com/github/klee0kai/stone/test_feature/hr/store/EmployeesStore.kt +++ b/test_feature/hr/impl/src/main/java/com/github/klee0kai/stone/test_feature/hr/store/EmployeesStore.kt @@ -1,4 +1,3 @@ -package com.github.klee0kai.stone.test_feature.hr.store; +package com.github.klee0kai.stone.test_feature.hr.store -public class EmployeesStore { -} +class EmployeesStore diff --git a/test_feature/planning/api/build.gradle.kts b/test_feature/planning/api/build.gradle.kts index f421159e..f1f36e5d 100644 --- a/test_feature/planning/api/build.gradle.kts +++ b/test_feature/planning/api/build.gradle.kts @@ -1,5 +1,5 @@ plugins { - java + alias(libs.plugins.kotlin.jvm) } group = "com.github.klee0kai.stone.test_feature.planning" diff --git a/test_feature/planning/api/src/main/java/com/github/klee0kai/stone/test_feature/planning/model/ProjectInfo.kt b/test_feature/planning/api/src/main/java/com/github/klee0kai/stone/test_feature/planning/model/ProjectInfo.kt index 45149b2a..1081f23f 100644 --- a/test_feature/planning/api/src/main/java/com/github/klee0kai/stone/test_feature/planning/model/ProjectInfo.kt +++ b/test_feature/planning/api/src/main/java/com/github/klee0kai/stone/test_feature/planning/model/ProjectInfo.kt @@ -1,4 +1,3 @@ -package com.github.klee0kai.stone.test_feature.planning.model; +package com.github.klee0kai.stone.test_feature.planning.model -public class ProjectInfo { -} +class ProjectInfo diff --git a/test_feature/planning/api/src/main/java/com/github/klee0kai/stone/test_feature/planning/model/TaskInfo.kt b/test_feature/planning/api/src/main/java/com/github/klee0kai/stone/test_feature/planning/model/TaskInfo.kt index 4f914eb3..e675da01 100644 --- a/test_feature/planning/api/src/main/java/com/github/klee0kai/stone/test_feature/planning/model/TaskInfo.kt +++ b/test_feature/planning/api/src/main/java/com/github/klee0kai/stone/test_feature/planning/model/TaskInfo.kt @@ -1,4 +1,3 @@ -package com.github.klee0kai.stone.test_feature.planning.model; +package com.github.klee0kai.stone.test_feature.planning.model -public class TaskInfo { -} +class TaskInfo diff --git a/test_feature/planning/api/src/main/java/com/github/klee0kai/stone/test_feature/planning/project/BuildFactoryProject.kt b/test_feature/planning/api/src/main/java/com/github/klee0kai/stone/test_feature/planning/project/BuildFactoryProject.kt index e9dee39a..e8fdc0fc 100644 --- a/test_feature/planning/api/src/main/java/com/github/klee0kai/stone/test_feature/planning/project/BuildFactoryProject.kt +++ b/test_feature/planning/api/src/main/java/com/github/klee0kai/stone/test_feature/planning/project/BuildFactoryProject.kt @@ -1,4 +1,3 @@ -package com.github.klee0kai.stone.test_feature.planning.project; +package com.github.klee0kai.stone.test_feature.planning.project -public interface BuildFactoryProject extends Project { -} +interface BuildFactoryProject : Project diff --git a/test_feature/planning/api/src/main/java/com/github/klee0kai/stone/test_feature/planning/project/LogisticProject.kt b/test_feature/planning/api/src/main/java/com/github/klee0kai/stone/test_feature/planning/project/LogisticProject.kt index 35a08b1a..fb704ac3 100644 --- a/test_feature/planning/api/src/main/java/com/github/klee0kai/stone/test_feature/planning/project/LogisticProject.kt +++ b/test_feature/planning/api/src/main/java/com/github/klee0kai/stone/test_feature/planning/project/LogisticProject.kt @@ -1,4 +1,3 @@ -package com.github.klee0kai.stone.test_feature.planning.project; +package com.github.klee0kai.stone.test_feature.planning.project -public interface LogisticProject extends Project { -} +interface LogisticProject : Project diff --git a/test_feature/planning/api/src/main/java/com/github/klee0kai/stone/test_feature/planning/project/Project.kt b/test_feature/planning/api/src/main/java/com/github/klee0kai/stone/test_feature/planning/project/Project.kt index db1b25bb..3c36cff5 100644 --- a/test_feature/planning/api/src/main/java/com/github/klee0kai/stone/test_feature/planning/project/Project.kt +++ b/test_feature/planning/api/src/main/java/com/github/klee0kai/stone/test_feature/planning/project/Project.kt @@ -1,16 +1,15 @@ -package com.github.klee0kai.stone.test_feature.planning.project; +package com.github.klee0kai.stone.test_feature.planning.project -import com.github.klee0kai.stone.test_feature.planning.model.ProjectInfo; -import com.github.klee0kai.stone.test_feature.planning.model.TaskInfo; +import com.github.klee0kai.stone.test_feature.planning.model.ProjectInfo +import com.github.klee0kai.stone.test_feature.planning.model.TaskInfo -public interface Project { +interface Project { - String getId(); + val id: String? - ProjectInfo projectInfo(); + fun projectInfo(): ProjectInfo? - void addTask(TaskInfo taskInfo); - - TaskInfo findTask(String taskId); + fun addTask(taskInfo: TaskInfo?) + fun findTask(taskId: String?): TaskInfo? } diff --git a/test_feature/planning/impl/build.gradle.kts b/test_feature/planning/impl/build.gradle.kts index 4e49ba81..9f31db36 100644 --- a/test_feature/planning/impl/build.gradle.kts +++ b/test_feature/planning/impl/build.gradle.kts @@ -1,5 +1,6 @@ plugins { - java + alias(libs.plugins.kotlin.jvm) + alias(libs.plugins.kotlin.ksp) } group = "com.github.klee0kai.stone.test_feature.planning" @@ -13,7 +14,7 @@ dependencies { implementation(project(":test_feature:finance:api")) implementation(project(":test_feature:hr:api")) - implementation(project(":stone_lib")) - annotationProcessor(project(":stone_processor")) + implementation(project(":stone_multiplatform")) + ksp(project(":stone_ksp")) } diff --git a/test_feature/planning/impl/src/main/java/com/github/klee0kai/stone/test_feature/planning/PlanningRun.kt b/test_feature/planning/impl/src/main/java/com/github/klee0kai/stone/test_feature/planning/PlanningRun.kt index 57a56e87..a5f002d7 100644 --- a/test_feature/planning/impl/src/main/java/com/github/klee0kai/stone/test_feature/planning/PlanningRun.kt +++ b/test_feature/planning/impl/src/main/java/com/github/klee0kai/stone/test_feature/planning/PlanningRun.kt @@ -1,31 +1,23 @@ -package com.github.klee0kai.stone.test_feature.planning; +package com.github.klee0kai.stone.test_feature.planning -import com.github.klee0kai.stone.test_feature.finance.model.WorkCalendar; -import com.github.klee0kai.stone.test_feature.hr.department.SecurityDepartment; -import com.github.klee0kai.stone.test_feature.planning.di.PlanningComponent; -import com.github.klee0kai.stone.test_feature.planning.project.LogisticProject; +import com.github.klee0kai.stone.test_feature.finance.model.WorkCalendar +import com.github.klee0kai.stone.test_feature.hr.department.SecurityDepartment +import com.github.klee0kai.stone.test_feature.planning.di.PlanningComponent +import com.github.klee0kai.stone.test_feature.planning.project.LogisticProject +import javax.inject.Inject -import javax.inject.Inject; - -public class PlanningRun { +class PlanningRun(private val component: PlanningComponent) { @Inject - public WorkCalendar workCalendar; + var workCalendar: WorkCalendar? = null @Inject - public LogisticProject logisticProject; + var logisticProject: LogisticProject? = null @Inject - public SecurityDepartment securityDepartment; - - private final PlanningComponent component; + var securityDepartment: SecurityDepartment? = null - public PlanningRun(PlanningComponent component) { - this.component = component; + fun start() { + component.inject(this) } - - public void start() { - component.inject(this); - } - } diff --git a/test_feature/planning/impl/src/main/java/com/github/klee0kai/stone/test_feature/planning/di/PlanningComponent.kt b/test_feature/planning/impl/src/main/java/com/github/klee0kai/stone/test_feature/planning/di/PlanningComponent.kt index 3123a356..ab04d5cb 100644 --- a/test_feature/planning/impl/src/main/java/com/github/klee0kai/stone/test_feature/planning/di/PlanningComponent.kt +++ b/test_feature/planning/impl/src/main/java/com/github/klee0kai/stone/test_feature/planning/di/PlanningComponent.kt @@ -1,19 +1,17 @@ -package com.github.klee0kai.stone.test_feature.planning.di; +package com.github.klee0kai.stone.test_feature.planning.di -import com.github.klee0kai.stone.annotations.component.Component; -import com.github.klee0kai.stone.annotations.component.Init; -import com.github.klee0kai.stone.test_feature.planning.PlanningRun; +import com.github.klee0kai.stone.annotations.component.Component +import com.github.klee0kai.stone.annotations.component.Init +import com.github.klee0kai.stone.test_feature.planning.PlanningRun @Component -public interface PlanningComponent { +interface PlanningComponent { + fun dependencies(): PlanningDependencies? - PlanningDependencies dependencies(); + fun projectsModule(): ProjectsModule? - ProjectsModule projectsModule(); - - void inject(PlanningRun planningRun); + fun inject(planningRun: PlanningRun?) @Init - void initDep(PlanningDependencies planningRun); - + fun initDep(planningRun: PlanningDependencies?) } diff --git a/test_feature/planning/impl/src/main/java/com/github/klee0kai/stone/test_feature/planning/di/PlanningDependencies.kt b/test_feature/planning/impl/src/main/java/com/github/klee0kai/stone/test_feature/planning/di/PlanningDependencies.kt index 1c5c4133..9f94e358 100644 --- a/test_feature/planning/impl/src/main/java/com/github/klee0kai/stone/test_feature/planning/di/PlanningDependencies.kt +++ b/test_feature/planning/impl/src/main/java/com/github/klee0kai/stone/test_feature/planning/di/PlanningDependencies.kt @@ -1,14 +1,12 @@ -package com.github.klee0kai.stone.test_feature.planning.di; +package com.github.klee0kai.stone.test_feature.planning.di -import com.github.klee0kai.stone.annotations.dependencies.Dependencies; -import com.github.klee0kai.stone.test_feature.finance.model.WorkCalendar; -import com.github.klee0kai.stone.test_feature.hr.department.SecurityDepartment; +import com.github.klee0kai.stone.annotations.dependencies.Dependencies +import com.github.klee0kai.stone.test_feature.finance.model.WorkCalendar +import com.github.klee0kai.stone.test_feature.hr.department.SecurityDepartment @Dependencies -public interface PlanningDependencies { - - WorkCalendar workCalendar(); - - SecurityDepartment securityDepartment(); +interface PlanningDependencies { + fun workCalendar(): WorkCalendar? + fun securityDepartment(): SecurityDepartment? } diff --git a/test_feature/planning/impl/src/main/java/com/github/klee0kai/stone/test_feature/planning/di/ProjectsModule.kt b/test_feature/planning/impl/src/main/java/com/github/klee0kai/stone/test_feature/planning/di/ProjectsModule.kt index a335a900..d072206e 100644 --- a/test_feature/planning/impl/src/main/java/com/github/klee0kai/stone/test_feature/planning/di/ProjectsModule.kt +++ b/test_feature/planning/impl/src/main/java/com/github/klee0kai/stone/test_feature/planning/di/ProjectsModule.kt @@ -1,28 +1,25 @@ -package com.github.klee0kai.stone.test_feature.planning.di; +package com.github.klee0kai.stone.test_feature.planning.di -import com.github.klee0kai.stone.annotations.module.Module; -import com.github.klee0kai.stone.annotations.module.Provide; -import com.github.klee0kai.stone.test_feature.planning.project.BuildFactoryProject; -import com.github.klee0kai.stone.test_feature.planning.project.BuildFactoryProjectImpl; -import com.github.klee0kai.stone.test_feature.planning.project.LogisticProject; -import com.github.klee0kai.stone.test_feature.planning.project.LogisticProjectImpl; -import com.github.klee0kai.stone.test_feature.planning.store.ProjectsStore; +import com.github.klee0kai.stone.annotations.module.Module +import com.github.klee0kai.stone.annotations.module.Provide +import com.github.klee0kai.stone.test_feature.planning.project.BuildFactoryProject +import com.github.klee0kai.stone.test_feature.planning.project.BuildFactoryProjectImpl +import com.github.klee0kai.stone.test_feature.planning.project.LogisticProject +import com.github.klee0kai.stone.test_feature.planning.project.LogisticProjectImpl +import com.github.klee0kai.stone.test_feature.planning.store.ProjectsStore @Module -public abstract class ProjectsModule { - +abstract class ProjectsModule { @Provide(cache = Provide.CacheType.Strong) - public abstract ProjectsStore projectsStore(); + abstract fun projectsStore(): ProjectsStore? @Provide(cache = Provide.CacheType.Soft) - public LogisticProject logisticProject() { - return new LogisticProjectImpl(); + open fun logisticProject(): LogisticProject { + return LogisticProjectImpl() } @Provide(cache = Provide.CacheType.Soft) - public BuildFactoryProject buildFactoryProject() { - return new BuildFactoryProjectImpl(); + open fun buildFactoryProject(): BuildFactoryProject { + return BuildFactoryProjectImpl() } - - } diff --git a/test_feature/planning/impl/src/main/java/com/github/klee0kai/stone/test_feature/planning/project/BuildFactoryProjectImpl.kt b/test_feature/planning/impl/src/main/java/com/github/klee0kai/stone/test_feature/planning/project/BuildFactoryProjectImpl.kt index b7bce2f0..01874427 100644 --- a/test_feature/planning/impl/src/main/java/com/github/klee0kai/stone/test_feature/planning/project/BuildFactoryProjectImpl.kt +++ b/test_feature/planning/impl/src/main/java/com/github/klee0kai/stone/test_feature/planning/project/BuildFactoryProjectImpl.kt @@ -1,4 +1,3 @@ -package com.github.klee0kai.stone.test_feature.planning.project; +package com.github.klee0kai.stone.test_feature.planning.project -public class BuildFactoryProjectImpl extends ProjectImpl implements BuildFactoryProject { -} +class BuildFactoryProjectImpl : ProjectImpl(), BuildFactoryProject diff --git a/test_feature/planning/impl/src/main/java/com/github/klee0kai/stone/test_feature/planning/project/LogisticProjectImpl.kt b/test_feature/planning/impl/src/main/java/com/github/klee0kai/stone/test_feature/planning/project/LogisticProjectImpl.kt index 49dcdfea..b3b40384 100644 --- a/test_feature/planning/impl/src/main/java/com/github/klee0kai/stone/test_feature/planning/project/LogisticProjectImpl.kt +++ b/test_feature/planning/impl/src/main/java/com/github/klee0kai/stone/test_feature/planning/project/LogisticProjectImpl.kt @@ -1,4 +1,3 @@ -package com.github.klee0kai.stone.test_feature.planning.project; +package com.github.klee0kai.stone.test_feature.planning.project -public class LogisticProjectImpl extends ProjectImpl implements LogisticProject { -} +class LogisticProjectImpl : ProjectImpl(), LogisticProject diff --git a/test_feature/planning/impl/src/main/java/com/github/klee0kai/stone/test_feature/planning/project/ProjectImpl.kt b/test_feature/planning/impl/src/main/java/com/github/klee0kai/stone/test_feature/planning/project/ProjectImpl.kt index 93ef9879..96ed1e09 100644 --- a/test_feature/planning/impl/src/main/java/com/github/klee0kai/stone/test_feature/planning/project/ProjectImpl.kt +++ b/test_feature/planning/impl/src/main/java/com/github/klee0kai/stone/test_feature/planning/project/ProjectImpl.kt @@ -1,31 +1,23 @@ -package com.github.klee0kai.stone.test_feature.planning.project; +package com.github.klee0kai.stone.test_feature.planning.project -import com.github.klee0kai.stone.test_feature.planning.model.ProjectInfo; -import com.github.klee0kai.stone.test_feature.planning.model.TaskInfo; +import com.github.klee0kai.stone.test_feature.planning.model.ProjectInfo +import com.github.klee0kai.stone.test_feature.planning.model.TaskInfo +import java.util.* -import java.util.UUID; +open class ProjectImpl : Project { + var uuid: UUID = UUID.randomUUID() -public class ProjectImpl implements Project { + override val id: String? + get() = uuid.toString() - public UUID uuid = UUID.randomUUID(); - - @Override - public String getId() { - return uuid.toString(); - } - - @Override - public ProjectInfo projectInfo() { - return null; + override fun projectInfo(): ProjectInfo? { + return null } - @Override - public void addTask(TaskInfo taskInfo) { - + override fun addTask(taskInfo: TaskInfo?) { } - @Override - public TaskInfo findTask(String taskId) { - return null; + override fun findTask(taskId: String?): TaskInfo? { + return null } } diff --git a/test_feature/planning/impl/src/main/java/com/github/klee0kai/stone/test_feature/planning/store/ProjectsStore.kt b/test_feature/planning/impl/src/main/java/com/github/klee0kai/stone/test_feature/planning/store/ProjectsStore.kt index 1d16639c..4093d966 100644 --- a/test_feature/planning/impl/src/main/java/com/github/klee0kai/stone/test_feature/planning/store/ProjectsStore.kt +++ b/test_feature/planning/impl/src/main/java/com/github/klee0kai/stone/test_feature/planning/store/ProjectsStore.kt @@ -1,4 +1,3 @@ -package com.github.klee0kai.stone.test_feature.planning.store; +package com.github.klee0kai.stone.test_feature.planning.store -public class ProjectsStore { -} +class ProjectsStore From ac7583621ddccc5a6a5437234ecdc4a7fc902ab9 Mon Sep 17 00:00:00 2001 From: klee0kai Date: Sat, 17 Jan 2026 10:10:02 +0100 Subject: [PATCH 098/122] migrate wiki to ksp arch --- settings.gradle.kts | 1 - wiki_java/build.gradle.kts | 16 -------- .../wiki/cachecontrol/GcMercuryScope.java | 15 ------- .../wiki/cachecontrol/PlanetsComponent.java | 39 ------------------- .../wiki/cachecontrol/PlanetsModule.java | 14 ------- .../wiki/cachecontrol/SolarSystem.java | 23 ----------- .../klee0kai/wiki/cachecontrol/SunScope.java | 15 ------- .../com/github/klee0kai/wiki/init/App.java | 18 --------- .../com/github/klee0kai/wiki/init/App2.java | 13 ------- .../klee0kai/wiki/init/AppComponent.java | 18 --------- .../klee0kai/wiki/init/AppProComponent.java | 15 ------- .../wiki/init/DynamicFeatureModule.java | 16 -------- .../klee0kai/wiki/init/FeatureModule.java | 15 ------- .../klee0kai/wiki/init/ProFeatureModule.java | 15 ------- .../klee0kai/wiki/init/StarsDependencies.java | 11 ------ .../wiki/init/StarsDependencies2.java | 13 ------- .../klee0kai/wiki/provide/binding/App.java | 17 -------- .../klee0kai/wiki/provide/binding/App2.java | 18 --------- .../binding/GodWorkspaceComponent.java | 13 ------- .../provide/binding/SunSystemComponent.java | 13 ------- .../wiki/provide/binding/SunSystemModule.java | 13 ------- .../wiki/provide/identifiers/App.java | 8 ---- .../provide/identifiers/AppComponent.java | 18 --------- .../provide/identifiers/FeaturePresenter.java | 13 ------- .../provide/identifiers/FeatureScreen.java | 12 ------ .../wiki/provide/identifiers/LoginId.java | 26 ------------- .../wiki/provide/identifiers/MyQualifier.java | 12 ------ .../provide/identifiers/PresentersModule.java | 20 ---------- .../wiki/provide/identifiers/ScreenId.java | 28 ------------- .../identifiers/SevenPlanetModule.java | 24 ------------ .../provide/identifiers/ThreadQualifier.java | 20 ---------- .../provide/identifiers/ThreadsModule.java | 19 --------- .../klee0kai/wiki/provide/inject/App.java | 9 ----- .../wiki/provide/inject/AppComponent.java | 21 ---------- .../wiki/provide/inject/FeatureScreen.java | 23 ----------- .../com/github/klee0kai/wiki/start/App.java | 15 ------- .../com/github/klee0kai/wiki/start/App2.java | 14 ------- .../wiki/start/SevenPlanetComponent.java | 10 ----- .../wiki/start/SevenPlanetModule.java | 15 ------- .../klee0kai/wiki/wrapping/CustomLazy.java | 22 ----------- .../klee0kai/wiki/wrapping/CustomWrapper.java | 19 --------- .../klee0kai/wiki/wrapping/GoodPhone.java | 25 ------------ .../wiki/wrapping/TechFactoryComponent.java | 19 --------- .../wiki/wrapping/TechFactoryModule.java | 18 --------- wiki_kotlin/build.gradle.kts | 9 +++-- .../klee0kai/wiki/cachecontrol/SolarSystem.kt | 3 +- .../com/github/klee0kai/wiki/init/App.kt | 3 +- .../com/github/klee0kai/wiki/init/App2.kt | 6 +-- .../klee0kai/wiki/provide/binding/App.kt | 4 +- .../klee0kai/wiki/provide/binding/App2.kt | 3 +- .../provide/identifiers/FeaturePresenter.kt | 2 +- .../provide/identifiers/PresentersModule.kt | 4 +- .../wiki/provide/inject/AppComponent.kt | 4 +- .../wiki/provide/inject/FeatureScreen.kt | 3 +- .../com/github/klee0kai/wiki/start/App.kt | 3 +- .../klee0kai/wiki/wrapping/CarBoxedWrapper.kt | 13 +++++++ .../klee0kai/wiki/wrapping/CustomLazy.kt | 2 +- .../klee0kai/wiki/wrapping/CustomWrapper.kt | 17 -------- .../klee0kai/wiki/wrapping/GoodPhone.kt | 3 +- .../wiki/wrapping/TechFactoryComponent.kt | 4 +- .../klee0kai/wiki/start/AppStartTest.kt | 18 +++++++++ 61 files changed, 56 insertions(+), 786 deletions(-) delete mode 100644 wiki_java/build.gradle.kts delete mode 100644 wiki_java/src/main/java/com/github/klee0kai/wiki/cachecontrol/GcMercuryScope.java delete mode 100644 wiki_java/src/main/java/com/github/klee0kai/wiki/cachecontrol/PlanetsComponent.java delete mode 100644 wiki_java/src/main/java/com/github/klee0kai/wiki/cachecontrol/PlanetsModule.java delete mode 100644 wiki_java/src/main/java/com/github/klee0kai/wiki/cachecontrol/SolarSystem.java delete mode 100644 wiki_java/src/main/java/com/github/klee0kai/wiki/cachecontrol/SunScope.java delete mode 100644 wiki_java/src/main/java/com/github/klee0kai/wiki/init/App.java delete mode 100644 wiki_java/src/main/java/com/github/klee0kai/wiki/init/App2.java delete mode 100644 wiki_java/src/main/java/com/github/klee0kai/wiki/init/AppComponent.java delete mode 100644 wiki_java/src/main/java/com/github/klee0kai/wiki/init/AppProComponent.java delete mode 100644 wiki_java/src/main/java/com/github/klee0kai/wiki/init/DynamicFeatureModule.java delete mode 100644 wiki_java/src/main/java/com/github/klee0kai/wiki/init/FeatureModule.java delete mode 100644 wiki_java/src/main/java/com/github/klee0kai/wiki/init/ProFeatureModule.java delete mode 100644 wiki_java/src/main/java/com/github/klee0kai/wiki/init/StarsDependencies.java delete mode 100644 wiki_java/src/main/java/com/github/klee0kai/wiki/init/StarsDependencies2.java delete mode 100644 wiki_java/src/main/java/com/github/klee0kai/wiki/provide/binding/App.java delete mode 100644 wiki_java/src/main/java/com/github/klee0kai/wiki/provide/binding/App2.java delete mode 100644 wiki_java/src/main/java/com/github/klee0kai/wiki/provide/binding/GodWorkspaceComponent.java delete mode 100644 wiki_java/src/main/java/com/github/klee0kai/wiki/provide/binding/SunSystemComponent.java delete mode 100644 wiki_java/src/main/java/com/github/klee0kai/wiki/provide/binding/SunSystemModule.java delete mode 100644 wiki_java/src/main/java/com/github/klee0kai/wiki/provide/identifiers/App.java delete mode 100644 wiki_java/src/main/java/com/github/klee0kai/wiki/provide/identifiers/AppComponent.java delete mode 100644 wiki_java/src/main/java/com/github/klee0kai/wiki/provide/identifiers/FeaturePresenter.java delete mode 100644 wiki_java/src/main/java/com/github/klee0kai/wiki/provide/identifiers/FeatureScreen.java delete mode 100644 wiki_java/src/main/java/com/github/klee0kai/wiki/provide/identifiers/LoginId.java delete mode 100644 wiki_java/src/main/java/com/github/klee0kai/wiki/provide/identifiers/MyQualifier.java delete mode 100644 wiki_java/src/main/java/com/github/klee0kai/wiki/provide/identifiers/PresentersModule.java delete mode 100644 wiki_java/src/main/java/com/github/klee0kai/wiki/provide/identifiers/ScreenId.java delete mode 100644 wiki_java/src/main/java/com/github/klee0kai/wiki/provide/identifiers/SevenPlanetModule.java delete mode 100644 wiki_java/src/main/java/com/github/klee0kai/wiki/provide/identifiers/ThreadQualifier.java delete mode 100644 wiki_java/src/main/java/com/github/klee0kai/wiki/provide/identifiers/ThreadsModule.java delete mode 100644 wiki_java/src/main/java/com/github/klee0kai/wiki/provide/inject/App.java delete mode 100644 wiki_java/src/main/java/com/github/klee0kai/wiki/provide/inject/AppComponent.java delete mode 100644 wiki_java/src/main/java/com/github/klee0kai/wiki/provide/inject/FeatureScreen.java delete mode 100644 wiki_java/src/main/java/com/github/klee0kai/wiki/start/App.java delete mode 100644 wiki_java/src/main/java/com/github/klee0kai/wiki/start/App2.java delete mode 100644 wiki_java/src/main/java/com/github/klee0kai/wiki/start/SevenPlanetComponent.java delete mode 100644 wiki_java/src/main/java/com/github/klee0kai/wiki/start/SevenPlanetModule.java delete mode 100644 wiki_java/src/main/java/com/github/klee0kai/wiki/wrapping/CustomLazy.java delete mode 100644 wiki_java/src/main/java/com/github/klee0kai/wiki/wrapping/CustomWrapper.java delete mode 100644 wiki_java/src/main/java/com/github/klee0kai/wiki/wrapping/GoodPhone.java delete mode 100644 wiki_java/src/main/java/com/github/klee0kai/wiki/wrapping/TechFactoryComponent.java delete mode 100644 wiki_java/src/main/java/com/github/klee0kai/wiki/wrapping/TechFactoryModule.java create mode 100644 wiki_kotlin/src/main/kotlin/com/github/klee0kai/wiki/wrapping/CarBoxedWrapper.kt delete mode 100644 wiki_kotlin/src/main/kotlin/com/github/klee0kai/wiki/wrapping/CustomWrapper.kt create mode 100644 wiki_kotlin/src/test/kotlin/com/github/klee0kai/wiki/start/AppStartTest.kt diff --git a/settings.gradle.kts b/settings.gradle.kts index 7d19b6b0..97513cc2 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -28,7 +28,6 @@ include(":stone_processor") include(":android_lib") include(":kotlin_lib") -include(":wiki_java") include(":wiki_kotlin") include(":tests") include(":tests_ext") diff --git a/wiki_java/build.gradle.kts b/wiki_java/build.gradle.kts deleted file mode 100644 index 218be786..00000000 --- a/wiki_java/build.gradle.kts +++ /dev/null @@ -1,16 +0,0 @@ -plugins { - application -} - -tasks.test { - useJUnitPlatform() -} - -dependencies { - implementation(project(":tests")) - implementation(project(":test_feature:finance:api")) - - implementation(project(":kotlin_lib")) - annotationProcessor(project(":stone_processor")) -} - diff --git a/wiki_java/src/main/java/com/github/klee0kai/wiki/cachecontrol/GcMercuryScope.java b/wiki_java/src/main/java/com/github/klee0kai/wiki/cachecontrol/GcMercuryScope.java deleted file mode 100644 index 55c2b04d..00000000 --- a/wiki_java/src/main/java/com/github/klee0kai/wiki/cachecontrol/GcMercuryScope.java +++ /dev/null @@ -1,15 +0,0 @@ -package com.github.klee0kai.wiki.cachecontrol; - -import com.github.klee0kai.stone.annotations.component.GcScopeAnnotation; - -import java.lang.annotation.Retention; -import java.lang.annotation.Target; - -import static java.lang.annotation.ElementType.METHOD; -import static java.lang.annotation.RetentionPolicy.RUNTIME; - -@GcScopeAnnotation -@Retention(RUNTIME) -@Target(METHOD) -public @interface GcMercuryScope { -} diff --git a/wiki_java/src/main/java/com/github/klee0kai/wiki/cachecontrol/PlanetsComponent.java b/wiki_java/src/main/java/com/github/klee0kai/wiki/cachecontrol/PlanetsComponent.java deleted file mode 100644 index e9e5d0b5..00000000 --- a/wiki_java/src/main/java/com/github/klee0kai/wiki/cachecontrol/PlanetsComponent.java +++ /dev/null @@ -1,39 +0,0 @@ -package com.github.klee0kai.wiki.cachecontrol; - -import com.github.klee0kai.stone.annotations.component.*; -import com.github.klee0kai.stone.annotations.module.BindInstance; -import com.github.klee0kai.stone.lifecycle.StoneLifeCycleOwner; -import com.github.klee0kai.test.mowgli.galaxy.Sun; - -@Component -public interface PlanetsComponent { - - PlanetsModule sunModule(); - - @RunGc - @GcMercuryScope - void gcMercury(); - - @RunGc - @GcSoftScope - @GcMercuryScope - void gcSoftMercury(); - - - @SunScope - @BindInstance - Sun sun(Sun sun); - - @SunScope - @SwitchCache(cache = SwitchCache.CacheType.Strong, timeMillis = 100) - void protectSun(); - - - void inject(SolarSystem solarSystem); - - @ProtectInjected(timeMillis = 30) - void protectInjected(SolarSystem solarSystem); - - void inject(SolarSystem solarSystem, StoneLifeCycleOwner lifeCycleOwner); - -} \ No newline at end of file diff --git a/wiki_java/src/main/java/com/github/klee0kai/wiki/cachecontrol/PlanetsModule.java b/wiki_java/src/main/java/com/github/klee0kai/wiki/cachecontrol/PlanetsModule.java deleted file mode 100644 index 5d23f706..00000000 --- a/wiki_java/src/main/java/com/github/klee0kai/wiki/cachecontrol/PlanetsModule.java +++ /dev/null @@ -1,14 +0,0 @@ -package com.github.klee0kai.wiki.cachecontrol; - -import com.github.klee0kai.stone.annotations.module.BindInstance; -import com.github.klee0kai.stone.annotations.module.Module; -import com.github.klee0kai.test.mowgli.galaxy.Mercury; - -@Module -public interface PlanetsModule { - - @GcMercuryScope - @BindInstance - Mercury mercury(Mercury sirius); - -} diff --git a/wiki_java/src/main/java/com/github/klee0kai/wiki/cachecontrol/SolarSystem.java b/wiki_java/src/main/java/com/github/klee0kai/wiki/cachecontrol/SolarSystem.java deleted file mode 100644 index 0174b844..00000000 --- a/wiki_java/src/main/java/com/github/klee0kai/wiki/cachecontrol/SolarSystem.java +++ /dev/null @@ -1,23 +0,0 @@ -package com.github.klee0kai.wiki.cachecontrol; - -import com.github.klee0kai.stone.Stone; -import com.github.klee0kai.test.mowgli.galaxy.Mercury; - -import javax.inject.Inject; - -public class SolarSystem { - - static PlanetsComponent DI = Stone.createComponent(PlanetsComponent.class); - - @Inject - Mercury mercury; - - void create() { - DI.inject(this); - } - - void beforeRecreate() { - DI.protectInjected(this); - } - -} diff --git a/wiki_java/src/main/java/com/github/klee0kai/wiki/cachecontrol/SunScope.java b/wiki_java/src/main/java/com/github/klee0kai/wiki/cachecontrol/SunScope.java deleted file mode 100644 index 99acbe65..00000000 --- a/wiki_java/src/main/java/com/github/klee0kai/wiki/cachecontrol/SunScope.java +++ /dev/null @@ -1,15 +0,0 @@ -package com.github.klee0kai.wiki.cachecontrol; - -import com.github.klee0kai.stone.annotations.component.GcScopeAnnotation; - -import java.lang.annotation.Retention; -import java.lang.annotation.Target; - -import static java.lang.annotation.ElementType.METHOD; -import static java.lang.annotation.RetentionPolicy.RUNTIME; - -@GcScopeAnnotation -@Retention(RUNTIME) -@Target(METHOD) -public @interface SunScope { -} \ No newline at end of file diff --git a/wiki_java/src/main/java/com/github/klee0kai/wiki/init/App.java b/wiki_java/src/main/java/com/github/klee0kai/wiki/init/App.java deleted file mode 100644 index 9fdc3e51..00000000 --- a/wiki_java/src/main/java/com/github/klee0kai/wiki/init/App.java +++ /dev/null @@ -1,18 +0,0 @@ -package com.github.klee0kai.wiki.init; - -import com.github.klee0kai.stone.Stone; - -public class App { - - public static void main(String[] args) { - // init stage - FeatureModule module = new FeatureModule(); - AppComponent DI = Stone.createComponent(AppComponent.class); - DI.initFeatureModule(module); - // some work - // dynamic feature loaded - DynamicFeatureModule moduleNewFeatures = new DynamicFeatureModule(); - DI.initFeatureModule(moduleNewFeatures); - } - -} diff --git a/wiki_java/src/main/java/com/github/klee0kai/wiki/init/App2.java b/wiki_java/src/main/java/com/github/klee0kai/wiki/init/App2.java deleted file mode 100644 index f805f3cc..00000000 --- a/wiki_java/src/main/java/com/github/klee0kai/wiki/init/App2.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.github.klee0kai.wiki.init; - -import com.github.klee0kai.stone.Stone; - -public class App2 { - - public static void main(String[] args) { - AppComponent DI = Stone.createComponent(AppComponent.class); - AppProComponent DIPro = Stone.createComponent(AppProComponent.class); - DIPro.extendComponent(DI); - } - -} \ No newline at end of file diff --git a/wiki_java/src/main/java/com/github/klee0kai/wiki/init/AppComponent.java b/wiki_java/src/main/java/com/github/klee0kai/wiki/init/AppComponent.java deleted file mode 100644 index 8f4d02d8..00000000 --- a/wiki_java/src/main/java/com/github/klee0kai/wiki/init/AppComponent.java +++ /dev/null @@ -1,18 +0,0 @@ -package com.github.klee0kai.wiki.init; - -import com.github.klee0kai.stone.annotations.component.Component; -import com.github.klee0kai.stone.annotations.component.Init; - -@Component -public interface AppComponent { - - FeatureModule feature(); - - StarsDependencies starsDependencies(); - - StarsDependencies2 starsDependencies2(); - - @Init - void initFeatureModule(FeatureModule featureModule); - -} diff --git a/wiki_java/src/main/java/com/github/klee0kai/wiki/init/AppProComponent.java b/wiki_java/src/main/java/com/github/klee0kai/wiki/init/AppProComponent.java deleted file mode 100644 index 294b3583..00000000 --- a/wiki_java/src/main/java/com/github/klee0kai/wiki/init/AppProComponent.java +++ /dev/null @@ -1,15 +0,0 @@ -package com.github.klee0kai.wiki.init; - -import com.github.klee0kai.stone.annotations.component.Component; -import com.github.klee0kai.stone.annotations.component.ExtendOf; - -@Component -public interface AppProComponent extends AppComponent { - - @Override - ProFeatureModule feature(); - - @ExtendOf - void extendComponent(AppComponent parent); - -} diff --git a/wiki_java/src/main/java/com/github/klee0kai/wiki/init/DynamicFeatureModule.java b/wiki_java/src/main/java/com/github/klee0kai/wiki/init/DynamicFeatureModule.java deleted file mode 100644 index ead6f2b1..00000000 --- a/wiki_java/src/main/java/com/github/klee0kai/wiki/init/DynamicFeatureModule.java +++ /dev/null @@ -1,16 +0,0 @@ -package com.github.klee0kai.wiki.init; - -import com.github.klee0kai.stone.annotations.module.Module; -import com.github.klee0kai.stone.annotations.module.Provide; -import com.github.klee0kai.test.mowgli.galaxy.Earth; - -@Module -public class DynamicFeatureModule extends FeatureModule { - - @Override - @Provide(cache = Provide.CacheType.Soft) - public Earth earth() { - return new Earth(); - } - -} diff --git a/wiki_java/src/main/java/com/github/klee0kai/wiki/init/FeatureModule.java b/wiki_java/src/main/java/com/github/klee0kai/wiki/init/FeatureModule.java deleted file mode 100644 index 26146286..00000000 --- a/wiki_java/src/main/java/com/github/klee0kai/wiki/init/FeatureModule.java +++ /dev/null @@ -1,15 +0,0 @@ -package com.github.klee0kai.wiki.init; - -import com.github.klee0kai.stone.annotations.module.Module; -import com.github.klee0kai.stone.annotations.module.Provide; -import com.github.klee0kai.test.mowgli.galaxy.Earth; - -@Module -public class FeatureModule { - - @Provide(cache = Provide.CacheType.Soft) - public Earth earth() { - return new Earth(); - } - -} diff --git a/wiki_java/src/main/java/com/github/klee0kai/wiki/init/ProFeatureModule.java b/wiki_java/src/main/java/com/github/klee0kai/wiki/init/ProFeatureModule.java deleted file mode 100644 index b709cef2..00000000 --- a/wiki_java/src/main/java/com/github/klee0kai/wiki/init/ProFeatureModule.java +++ /dev/null @@ -1,15 +0,0 @@ -package com.github.klee0kai.wiki.init; - -import com.github.klee0kai.stone.annotations.module.Module; -import com.github.klee0kai.stone.annotations.module.Provide; -import com.github.klee0kai.test.mowgli.galaxy.Earth; - -@Module -public class ProFeatureModule extends FeatureModule { - - @Provide(cache = Provide.CacheType.Soft) - public Earth earth() { - return new Earth(); - } - -} diff --git a/wiki_java/src/main/java/com/github/klee0kai/wiki/init/StarsDependencies.java b/wiki_java/src/main/java/com/github/klee0kai/wiki/init/StarsDependencies.java deleted file mode 100644 index 759f6de7..00000000 --- a/wiki_java/src/main/java/com/github/klee0kai/wiki/init/StarsDependencies.java +++ /dev/null @@ -1,11 +0,0 @@ -package com.github.klee0kai.wiki.init; - -import com.github.klee0kai.stone.annotations.dependencies.Dependencies; -import com.github.klee0kai.test.mowgli.galaxy.Sun; - -@Dependencies -public interface StarsDependencies { - - Sun sun(); - -} diff --git a/wiki_java/src/main/java/com/github/klee0kai/wiki/init/StarsDependencies2.java b/wiki_java/src/main/java/com/github/klee0kai/wiki/init/StarsDependencies2.java deleted file mode 100644 index fe3648e6..00000000 --- a/wiki_java/src/main/java/com/github/klee0kai/wiki/init/StarsDependencies2.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.github.klee0kai.wiki.init; - -import com.github.klee0kai.stone.annotations.module.Module; -import com.github.klee0kai.stone.annotations.module.Provide; -import com.github.klee0kai.test.mowgli.galaxy.Sun; - -@Module -public interface StarsDependencies2 { - - @Provide(cache = Provide.CacheType.Factory) - Sun sun(); - -} diff --git a/wiki_java/src/main/java/com/github/klee0kai/wiki/provide/binding/App.java b/wiki_java/src/main/java/com/github/klee0kai/wiki/provide/binding/App.java deleted file mode 100644 index 8bbd8d98..00000000 --- a/wiki_java/src/main/java/com/github/klee0kai/wiki/provide/binding/App.java +++ /dev/null @@ -1,17 +0,0 @@ -package com.github.klee0kai.wiki.provide.binding; - -import com.github.klee0kai.stone.Stone; -import com.github.klee0kai.test.mowgli.galaxy.Sun; - -public class App { - - public static void main(String[] args) { - GodWorkspaceComponent DI = Stone.createComponent(GodWorkspaceComponent.class); - Sun sun = new Sun(); - DI.sunSystem().sun(sun); - - Sun sunFromDI = DI.sunSystem().sun(null); - System.out.println("sunFromDI " + sunFromDI); - } - -} diff --git a/wiki_java/src/main/java/com/github/klee0kai/wiki/provide/binding/App2.java b/wiki_java/src/main/java/com/github/klee0kai/wiki/provide/binding/App2.java deleted file mode 100644 index 30c9c249..00000000 --- a/wiki_java/src/main/java/com/github/klee0kai/wiki/provide/binding/App2.java +++ /dev/null @@ -1,18 +0,0 @@ -package com.github.klee0kai.wiki.provide.binding; - -import com.github.klee0kai.stone.Stone; -import com.github.klee0kai.test.mowgli.galaxy.Sun; - -public class App2 { - - public static void main(String[] args) { - SunSystemComponent DI = Stone.createComponent(SunSystemComponent.class); - Sun sun = new Sun(); - DI.sun(sun); - - - Sun sunFromDI = DI.sun(null); - System.out.println("sunFromDI " + sunFromDI); - } - -} diff --git a/wiki_java/src/main/java/com/github/klee0kai/wiki/provide/binding/GodWorkspaceComponent.java b/wiki_java/src/main/java/com/github/klee0kai/wiki/provide/binding/GodWorkspaceComponent.java deleted file mode 100644 index cf1e44b7..00000000 --- a/wiki_java/src/main/java/com/github/klee0kai/wiki/provide/binding/GodWorkspaceComponent.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.github.klee0kai.wiki.provide.binding; - -import com.github.klee0kai.stone.annotations.component.Component; -import com.github.klee0kai.test.mowgli.galaxy.Sun; - -@Component -public interface GodWorkspaceComponent { - - SunSystemModule sunSystem(); - - Sun sun(); - -} \ No newline at end of file diff --git a/wiki_java/src/main/java/com/github/klee0kai/wiki/provide/binding/SunSystemComponent.java b/wiki_java/src/main/java/com/github/klee0kai/wiki/provide/binding/SunSystemComponent.java deleted file mode 100644 index 3d3ce177..00000000 --- a/wiki_java/src/main/java/com/github/klee0kai/wiki/provide/binding/SunSystemComponent.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.github.klee0kai.wiki.provide.binding; - -import com.github.klee0kai.stone.annotations.component.Component; -import com.github.klee0kai.stone.annotations.module.BindInstance; -import com.github.klee0kai.test.mowgli.galaxy.Sun; - -@Component -public interface SunSystemComponent { - - @BindInstance - Sun sun(Sun sun); - -} diff --git a/wiki_java/src/main/java/com/github/klee0kai/wiki/provide/binding/SunSystemModule.java b/wiki_java/src/main/java/com/github/klee0kai/wiki/provide/binding/SunSystemModule.java deleted file mode 100644 index c7496d61..00000000 --- a/wiki_java/src/main/java/com/github/klee0kai/wiki/provide/binding/SunSystemModule.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.github.klee0kai.wiki.provide.binding; - -import com.github.klee0kai.stone.annotations.module.BindInstance; -import com.github.klee0kai.stone.annotations.module.Module; -import com.github.klee0kai.test.mowgli.galaxy.Sun; - -@Module -public interface SunSystemModule { - - @BindInstance(cache = BindInstance.CacheType.Weak) - Sun sun(Sun sun); - -} \ No newline at end of file diff --git a/wiki_java/src/main/java/com/github/klee0kai/wiki/provide/identifiers/App.java b/wiki_java/src/main/java/com/github/klee0kai/wiki/provide/identifiers/App.java deleted file mode 100644 index a3793008..00000000 --- a/wiki_java/src/main/java/com/github/klee0kai/wiki/provide/identifiers/App.java +++ /dev/null @@ -1,8 +0,0 @@ -package com.github.klee0kai.wiki.provide.identifiers; - -public class App { - - public static void main(String[] args) { - - } -} diff --git a/wiki_java/src/main/java/com/github/klee0kai/wiki/provide/identifiers/AppComponent.java b/wiki_java/src/main/java/com/github/klee0kai/wiki/provide/identifiers/AppComponent.java deleted file mode 100644 index 74633795..00000000 --- a/wiki_java/src/main/java/com/github/klee0kai/wiki/provide/identifiers/AppComponent.java +++ /dev/null @@ -1,18 +0,0 @@ -package com.github.klee0kai.wiki.provide.identifiers; - -import com.github.klee0kai.stone.annotations.component.Component; - -@Component(identifiers = {ScreenId.class, LoginId.class}) -public interface AppComponent { - - SevenPlanetModule planetsModule(); - - ThreadsModule threadsModule(); - - PresentersModule presentersModule(); - - FeaturePresenter featurePresenter(LoginId loginId, ScreenId screenId); - - void inject(FeatureScreen screen, LoginId loginId, ScreenId screenId); - -} diff --git a/wiki_java/src/main/java/com/github/klee0kai/wiki/provide/identifiers/FeaturePresenter.java b/wiki_java/src/main/java/com/github/klee0kai/wiki/provide/identifiers/FeaturePresenter.java deleted file mode 100644 index 5f86890b..00000000 --- a/wiki_java/src/main/java/com/github/klee0kai/wiki/provide/identifiers/FeaturePresenter.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.github.klee0kai.wiki.provide.identifiers; - -import java.util.concurrent.ThreadPoolExecutor; - -public class FeaturePresenter { - - public FeaturePresenter(ThreadPoolExecutor executor) { - } - - public FeaturePresenter(ScreenId screenId, LoginId loginId) { - } - -} diff --git a/wiki_java/src/main/java/com/github/klee0kai/wiki/provide/identifiers/FeatureScreen.java b/wiki_java/src/main/java/com/github/klee0kai/wiki/provide/identifiers/FeatureScreen.java deleted file mode 100644 index 47571bd1..00000000 --- a/wiki_java/src/main/java/com/github/klee0kai/wiki/provide/identifiers/FeatureScreen.java +++ /dev/null @@ -1,12 +0,0 @@ -package com.github.klee0kai.wiki.provide.identifiers; - -import javax.inject.Inject; - -public class FeatureScreen { - - @Inject - public FeaturePresenter presenter; - - - -} diff --git a/wiki_java/src/main/java/com/github/klee0kai/wiki/provide/identifiers/LoginId.java b/wiki_java/src/main/java/com/github/klee0kai/wiki/provide/identifiers/LoginId.java deleted file mode 100644 index 2cdfb3a9..00000000 --- a/wiki_java/src/main/java/com/github/klee0kai/wiki/provide/identifiers/LoginId.java +++ /dev/null @@ -1,26 +0,0 @@ -package com.github.klee0kai.wiki.provide.identifiers; - -import java.util.Objects; - -public class LoginId { - - public String accountName = ""; - - public LoginId(String tag) { - this.accountName = tag; - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - LoginId screenId = (LoginId) o; - return Objects.equals(accountName, screenId.accountName); - } - - @Override - public int hashCode() { - return Objects.hash(accountName); - } - -} diff --git a/wiki_java/src/main/java/com/github/klee0kai/wiki/provide/identifiers/MyQualifier.java b/wiki_java/src/main/java/com/github/klee0kai/wiki/provide/identifiers/MyQualifier.java deleted file mode 100644 index faa6d502..00000000 --- a/wiki_java/src/main/java/com/github/klee0kai/wiki/provide/identifiers/MyQualifier.java +++ /dev/null @@ -1,12 +0,0 @@ -package com.github.klee0kai.wiki.provide.identifiers; - -import javax.inject.Qualifier; -import java.lang.annotation.Documented; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; - -@Qualifier -@Retention(RetentionPolicy.RUNTIME) -@Documented -public @interface MyQualifier { -} diff --git a/wiki_java/src/main/java/com/github/klee0kai/wiki/provide/identifiers/PresentersModule.java b/wiki_java/src/main/java/com/github/klee0kai/wiki/provide/identifiers/PresentersModule.java deleted file mode 100644 index be717723..00000000 --- a/wiki_java/src/main/java/com/github/klee0kai/wiki/provide/identifiers/PresentersModule.java +++ /dev/null @@ -1,20 +0,0 @@ -package com.github.klee0kai.wiki.provide.identifiers; - -import com.github.klee0kai.stone.annotations.module.Module; - -import java.util.concurrent.ThreadPoolExecutor; - -@Module -public abstract class PresentersModule { - - @MyQualifier - public abstract FeaturePresenter provideFeaturePresenter( - @ThreadQualifier(type = ThreadQualifier.ThreadType.Main) ThreadPoolExecutor executor - ); - - public abstract FeaturePresenter provideFeaturePresenter( - ScreenId screenId, - LoginId loginId - ); - -} diff --git a/wiki_java/src/main/java/com/github/klee0kai/wiki/provide/identifiers/ScreenId.java b/wiki_java/src/main/java/com/github/klee0kai/wiki/provide/identifiers/ScreenId.java deleted file mode 100644 index 3d9c2935..00000000 --- a/wiki_java/src/main/java/com/github/klee0kai/wiki/provide/identifiers/ScreenId.java +++ /dev/null @@ -1,28 +0,0 @@ -package com.github.klee0kai.wiki.provide.identifiers; - -import java.util.Objects; - -public class ScreenId { - - public String tag = ""; - - public ScreenId(String tag) { - this.tag = tag; - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - ScreenId screenId = (ScreenId) o; - return Objects.equals(tag, screenId.tag); - } - - @Override - public int hashCode() { - return Objects.hash(tag); - } - - - -} diff --git a/wiki_java/src/main/java/com/github/klee0kai/wiki/provide/identifiers/SevenPlanetModule.java b/wiki_java/src/main/java/com/github/klee0kai/wiki/provide/identifiers/SevenPlanetModule.java deleted file mode 100644 index 4e084cc2..00000000 --- a/wiki_java/src/main/java/com/github/klee0kai/wiki/provide/identifiers/SevenPlanetModule.java +++ /dev/null @@ -1,24 +0,0 @@ -package com.github.klee0kai.wiki.provide.identifiers; - -import com.github.klee0kai.stone.annotations.module.Module; -import com.github.klee0kai.test.mowgli.galaxy.Earth; -import com.github.klee0kai.test.mowgli.galaxy.SolarSystem; -import com.github.klee0kai.test.mowgli.galaxy.Sun; -import com.github.klee0kai.test.wire.Wire; -import com.github.klee0kai.test.wire.types.MiniUsb; -import com.github.klee0kai.test.wire.types.Usb; - -@Module -public abstract class SevenPlanetModule { - - public Earth earth() { - return new Earth(); - } - - public abstract Sun sun(); - - public abstract SolarSystem solarSystem(Sun sun, Earth earth); - - public abstract Wire usb_miniusb(); - -} diff --git a/wiki_java/src/main/java/com/github/klee0kai/wiki/provide/identifiers/ThreadQualifier.java b/wiki_java/src/main/java/com/github/klee0kai/wiki/provide/identifiers/ThreadQualifier.java deleted file mode 100644 index c9b183d3..00000000 --- a/wiki_java/src/main/java/com/github/klee0kai/wiki/provide/identifiers/ThreadQualifier.java +++ /dev/null @@ -1,20 +0,0 @@ -package com.github.klee0kai.wiki.provide.identifiers; - -import javax.inject.Qualifier; -import java.lang.annotation.Documented; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; - -@Qualifier -@Retention(RetentionPolicy.RUNTIME) -@Documented -public @interface ThreadQualifier { - ThreadType type() default ThreadType.Main; - - enum ThreadType { - Main, - Default, - IO - } - -} \ No newline at end of file diff --git a/wiki_java/src/main/java/com/github/klee0kai/wiki/provide/identifiers/ThreadsModule.java b/wiki_java/src/main/java/com/github/klee0kai/wiki/provide/identifiers/ThreadsModule.java deleted file mode 100644 index 109def44..00000000 --- a/wiki_java/src/main/java/com/github/klee0kai/wiki/provide/identifiers/ThreadsModule.java +++ /dev/null @@ -1,19 +0,0 @@ -package com.github.klee0kai.wiki.provide.identifiers; - -import com.github.klee0kai.stone.annotations.module.Module; -import com.github.klee0kai.stone.annotations.module.Provide; - -import java.util.concurrent.LinkedBlockingDeque; -import java.util.concurrent.ThreadPoolExecutor; -import java.util.concurrent.TimeUnit; - -@Module -public class ThreadsModule { - - @ThreadQualifier(type = ThreadQualifier.ThreadType.Main) - @Provide(cache = Provide.CacheType.Strong) - public ThreadPoolExecutor mainThreadPoolExecutor() { - return new ThreadPoolExecutor(0, 1, 0, TimeUnit.MILLISECONDS, new LinkedBlockingDeque<>(), runnable -> new Thread(runnable)); - } - -} \ No newline at end of file diff --git a/wiki_java/src/main/java/com/github/klee0kai/wiki/provide/inject/App.java b/wiki_java/src/main/java/com/github/klee0kai/wiki/provide/inject/App.java deleted file mode 100644 index 93eb11fc..00000000 --- a/wiki_java/src/main/java/com/github/klee0kai/wiki/provide/inject/App.java +++ /dev/null @@ -1,9 +0,0 @@ -package com.github.klee0kai.wiki.provide.inject; - -public class App { - - public static void main(String[] args) { - - } - -} diff --git a/wiki_java/src/main/java/com/github/klee0kai/wiki/provide/inject/AppComponent.java b/wiki_java/src/main/java/com/github/klee0kai/wiki/provide/inject/AppComponent.java deleted file mode 100644 index c22c7513..00000000 --- a/wiki_java/src/main/java/com/github/klee0kai/wiki/provide/inject/AppComponent.java +++ /dev/null @@ -1,21 +0,0 @@ -package com.github.klee0kai.wiki.provide.inject; - -import com.github.klee0kai.stone.annotations.component.Component; -import com.github.klee0kai.stone.lifecycle.StoneLifeCycleOwner; -import com.github.klee0kai.wiki.provide.identifiers.LoginId; -import com.github.klee0kai.wiki.provide.identifiers.PresentersModule; -import com.github.klee0kai.wiki.provide.identifiers.ScreenId; -import com.github.klee0kai.wiki.provide.identifiers.ThreadsModule; - -@Component(identifiers = {ScreenId.class, LoginId.class}) -public interface AppComponent { - - ThreadsModule threadsModule(); - - PresentersModule presentersModule(); - - void inject(FeatureScreen screen); - - void inject(FeatureScreen screen, StoneLifeCycleOwner owner, LoginId loginId, ScreenId screenId); - -} diff --git a/wiki_java/src/main/java/com/github/klee0kai/wiki/provide/inject/FeatureScreen.java b/wiki_java/src/main/java/com/github/klee0kai/wiki/provide/inject/FeatureScreen.java deleted file mode 100644 index fa810567..00000000 --- a/wiki_java/src/main/java/com/github/klee0kai/wiki/provide/inject/FeatureScreen.java +++ /dev/null @@ -1,23 +0,0 @@ -package com.github.klee0kai.wiki.provide.inject; - -import com.github.klee0kai.stone.Stone; -import com.github.klee0kai.wiki.provide.identifiers.FeaturePresenter; - -import javax.inject.Inject; - -public class FeatureScreen { - - @Inject - public FeaturePresenter presenter; - - @Inject - void init(FeaturePresenter presenter) { - - } - - void start() { - AppComponent DI = Stone.createComponent(AppComponent.class); - DI.inject(this); - } - -} diff --git a/wiki_java/src/main/java/com/github/klee0kai/wiki/start/App.java b/wiki_java/src/main/java/com/github/klee0kai/wiki/start/App.java deleted file mode 100644 index 5c613ce7..00000000 --- a/wiki_java/src/main/java/com/github/klee0kai/wiki/start/App.java +++ /dev/null @@ -1,15 +0,0 @@ -package com.github.klee0kai.wiki.start; - - -import com.github.klee0kai.stone.Stone; -import com.github.klee0kai.test.mowgli.galaxy.Earth; - -class App { - - static SevenPlanetComponent DI = Stone.createComponent(SevenPlanetComponent.class); - - public static void main(String[] args) { - Earth earth = DI.planets().earth(); - } - -} diff --git a/wiki_java/src/main/java/com/github/klee0kai/wiki/start/App2.java b/wiki_java/src/main/java/com/github/klee0kai/wiki/start/App2.java deleted file mode 100644 index 4164e7a0..00000000 --- a/wiki_java/src/main/java/com/github/klee0kai/wiki/start/App2.java +++ /dev/null @@ -1,14 +0,0 @@ -package com.github.klee0kai.wiki.start; - - -import com.github.klee0kai.test.mowgli.galaxy.Earth; - -class App2 { - - static SevenPlanetComponent DI = new SevenPlanetComponentStoneComponent(); - - public static void main(String[] args) { - Earth earth = DI.planets().earth(); - } - -} diff --git a/wiki_java/src/main/java/com/github/klee0kai/wiki/start/SevenPlanetComponent.java b/wiki_java/src/main/java/com/github/klee0kai/wiki/start/SevenPlanetComponent.java deleted file mode 100644 index 526d22e2..00000000 --- a/wiki_java/src/main/java/com/github/klee0kai/wiki/start/SevenPlanetComponent.java +++ /dev/null @@ -1,10 +0,0 @@ -package com.github.klee0kai.wiki.start; - -import com.github.klee0kai.stone.annotations.component.Component; - -@Component -public interface SevenPlanetComponent { - - SevenPlanetModule planets(); - -} \ No newline at end of file diff --git a/wiki_java/src/main/java/com/github/klee0kai/wiki/start/SevenPlanetModule.java b/wiki_java/src/main/java/com/github/klee0kai/wiki/start/SevenPlanetModule.java deleted file mode 100644 index 12b9d80e..00000000 --- a/wiki_java/src/main/java/com/github/klee0kai/wiki/start/SevenPlanetModule.java +++ /dev/null @@ -1,15 +0,0 @@ -package com.github.klee0kai.wiki.start; - -import com.github.klee0kai.stone.annotations.module.Module; -import com.github.klee0kai.stone.annotations.module.Provide; -import com.github.klee0kai.test.mowgli.galaxy.Earth; - -@Module -public class SevenPlanetModule { - - @Provide(cache = Provide.CacheType.Soft) - public Earth earth() { - return new Earth(); - } - -} diff --git a/wiki_java/src/main/java/com/github/klee0kai/wiki/wrapping/CustomLazy.java b/wiki_java/src/main/java/com/github/klee0kai/wiki/wrapping/CustomLazy.java deleted file mode 100644 index a419bebd..00000000 --- a/wiki_java/src/main/java/com/github/klee0kai/wiki/wrapping/CustomLazy.java +++ /dev/null @@ -1,22 +0,0 @@ -package com.github.klee0kai.wiki.wrapping; - -import com.github.klee0kai.stone.wrappers.Ref; - -import java.lang.ref.WeakReference; - -public class CustomLazy { - - private T value = null; - private final WeakReference call; - - public CustomLazy(Ref call) { - this.call = new WeakReference(call.get()); - } - - public T getValue() { - if (value != null) - return value; - return value = call.get(); - } - -} \ No newline at end of file diff --git a/wiki_java/src/main/java/com/github/klee0kai/wiki/wrapping/CustomWrapper.java b/wiki_java/src/main/java/com/github/klee0kai/wiki/wrapping/CustomWrapper.java deleted file mode 100644 index 15be9884..00000000 --- a/wiki_java/src/main/java/com/github/klee0kai/wiki/wrapping/CustomWrapper.java +++ /dev/null @@ -1,19 +0,0 @@ -package com.github.klee0kai.wiki.wrapping; - -import com.github.klee0kai.stone.annotations.wrappers.WrappersCreator; -import com.github.klee0kai.stone.wrappers.creators.ProviderWrapper; - -import javax.inject.Provider; - -@WrappersCreator(wrappers = {CustomLazy.class}) -public class CustomWrapper implements ProviderWrapper { - - @Override - public Wr wrap(Class wrapperCl, Provider originalProvider) { - if (wrapperCl.equals(CustomLazy.class)) { - return (Wr) new CustomLazy(originalProvider::get); - } - return null; - } - -} diff --git a/wiki_java/src/main/java/com/github/klee0kai/wiki/wrapping/GoodPhone.java b/wiki_java/src/main/java/com/github/klee0kai/wiki/wrapping/GoodPhone.java deleted file mode 100644 index d55249e7..00000000 --- a/wiki_java/src/main/java/com/github/klee0kai/wiki/wrapping/GoodPhone.java +++ /dev/null @@ -1,25 +0,0 @@ -package com.github.klee0kai.wiki.wrapping; - -import com.github.klee0kai.stone.Stone; -import com.github.klee0kai.stone.wrappers.LazyProvide; -import com.github.klee0kai.stone.wrappers.PhantomProvide; -import com.github.klee0kai.test.tech.components.Battery; -import com.github.klee0kai.test.tech.components.Ram; - -import javax.inject.Inject; - -public class GoodPhone { - - static TechFactoryComponent DI = Stone.createComponent(TechFactoryComponent.class); - - @Inject - public PhantomProvide battery; - - @Inject - public LazyProvide ram; - - public void create() { - DI.inject(this); - } - -} diff --git a/wiki_java/src/main/java/com/github/klee0kai/wiki/wrapping/TechFactoryComponent.java b/wiki_java/src/main/java/com/github/klee0kai/wiki/wrapping/TechFactoryComponent.java deleted file mode 100644 index e702dfb1..00000000 --- a/wiki_java/src/main/java/com/github/klee0kai/wiki/wrapping/TechFactoryComponent.java +++ /dev/null @@ -1,19 +0,0 @@ -package com.github.klee0kai.wiki.wrapping; - -import com.github.klee0kai.stone.annotations.component.Component; -import com.github.klee0kai.stone.wrappers.LazyProvide; -import com.github.klee0kai.stone.wrappers.PhantomProvide; -import com.github.klee0kai.test.tech.components.Battery; -import com.github.klee0kai.test.tech.components.Ram; - -@Component(wrapperProviders = {CustomWrapper.class}) -public interface TechFactoryComponent { - - TechFactoryModule factory(); - - PhantomProvide battery(); - - LazyProvide ramMemory(); - - void inject(GoodPhone goodPhone); -} diff --git a/wiki_java/src/main/java/com/github/klee0kai/wiki/wrapping/TechFactoryModule.java b/wiki_java/src/main/java/com/github/klee0kai/wiki/wrapping/TechFactoryModule.java deleted file mode 100644 index efdbe916..00000000 --- a/wiki_java/src/main/java/com/github/klee0kai/wiki/wrapping/TechFactoryModule.java +++ /dev/null @@ -1,18 +0,0 @@ -package com.github.klee0kai.wiki.wrapping; - -import com.github.klee0kai.stone.annotations.module.Module; -import com.github.klee0kai.stone.annotations.module.Provide; -import com.github.klee0kai.test.tech.components.Battery; -import com.github.klee0kai.test.tech.components.Ram; - - -@Module -public interface TechFactoryModule { - - @Provide(cache = Provide.CacheType.Factory) - Battery battery(); - - @Provide(cache = Provide.CacheType.Factory) - Ram ram(); - -} diff --git a/wiki_kotlin/build.gradle.kts b/wiki_kotlin/build.gradle.kts index c68b5fd8..ab8e94d2 100644 --- a/wiki_kotlin/build.gradle.kts +++ b/wiki_kotlin/build.gradle.kts @@ -1,6 +1,6 @@ plugins { alias(libs.plugins.kotlin.jvm) - alias(libs.plugins.kotlin.kapt) + alias(libs.plugins.kotlin.ksp) } tasks.test { @@ -11,7 +11,8 @@ dependencies { implementation(project(":tests")) implementation(project(":test_feature:finance:api")) - implementation(project(":kotlin_lib")) - kapt(project(":stone_processor")) -} + implementation(project(":stone_multiplatform")) + ksp(project(":stone_ksp")) + testImplementation(libs.bundles.junit) +} diff --git a/wiki_kotlin/src/main/kotlin/com/github/klee0kai/wiki/cachecontrol/SolarSystem.kt b/wiki_kotlin/src/main/kotlin/com/github/klee0kai/wiki/cachecontrol/SolarSystem.kt index ccde0b21..0e7132d5 100644 --- a/wiki_kotlin/src/main/kotlin/com/github/klee0kai/wiki/cachecontrol/SolarSystem.kt +++ b/wiki_kotlin/src/main/kotlin/com/github/klee0kai/wiki/cachecontrol/SolarSystem.kt @@ -1,10 +1,9 @@ package com.github.klee0kai.wiki.cachecontrol -import com.github.klee0kai.stone.Stone import com.github.klee0kai.test.mowgli.galaxy.Mercury import javax.inject.Inject -val DI: PlanetsComponent = Stone.createComponent(PlanetsComponent::class.java) +val DI: PlanetsComponent = PlanetsComponentStoneComponent() class SolarSystem { diff --git a/wiki_kotlin/src/main/kotlin/com/github/klee0kai/wiki/init/App.kt b/wiki_kotlin/src/main/kotlin/com/github/klee0kai/wiki/init/App.kt index 8b3c9ba3..cf48bd9d 100644 --- a/wiki_kotlin/src/main/kotlin/com/github/klee0kai/wiki/init/App.kt +++ b/wiki_kotlin/src/main/kotlin/com/github/klee0kai/wiki/init/App.kt @@ -1,11 +1,10 @@ package com.github.klee0kai.wiki.init -import com.github.klee0kai.stone.Stone fun main(args: Array) { // init stage val module = FeatureModule() - val DI = Stone.createComponent(AppComponent::class.java) + val DI: AppComponent = AppComponentStoneComponent() DI.initFeatureModule(module) // some work // dynamic feature loaded diff --git a/wiki_kotlin/src/main/kotlin/com/github/klee0kai/wiki/init/App2.kt b/wiki_kotlin/src/main/kotlin/com/github/klee0kai/wiki/init/App2.kt index 7c153f1b..06b3ac2e 100644 --- a/wiki_kotlin/src/main/kotlin/com/github/klee0kai/wiki/init/App2.kt +++ b/wiki_kotlin/src/main/kotlin/com/github/klee0kai/wiki/init/App2.kt @@ -1,9 +1,7 @@ package com.github.klee0kai.wiki.init -import com.github.klee0kai.stone.Stone - fun main(args: Array) { - val DI = Stone.createComponent(AppComponent::class.java) - val DIPro = Stone.createComponent(AppProComponent::class.java) + val DI = AppComponentStoneComponent() + val DIPro = AppProComponentStoneComponent() DIPro.extendComponent(DI) } diff --git a/wiki_kotlin/src/main/kotlin/com/github/klee0kai/wiki/provide/binding/App.kt b/wiki_kotlin/src/main/kotlin/com/github/klee0kai/wiki/provide/binding/App.kt index 35c3200f..38291c31 100644 --- a/wiki_kotlin/src/main/kotlin/com/github/klee0kai/wiki/provide/binding/App.kt +++ b/wiki_kotlin/src/main/kotlin/com/github/klee0kai/wiki/provide/binding/App.kt @@ -1,13 +1,13 @@ package com.github.klee0kai.wiki.provide.binding -import com.github.klee0kai.stone.Stone import com.github.klee0kai.test.mowgli.galaxy.Sun fun main(args: Array) { - val DI = Stone.createComponent(GodWorkspaceComponent::class.java) + val DI = GodWorkspaceComponentStoneComponent() val sun = Sun() DI.sunSystem().sun(sun) val sunFromDI = DI.sunSystem().sun(null) println("sunFromDI $sunFromDI") } + diff --git a/wiki_kotlin/src/main/kotlin/com/github/klee0kai/wiki/provide/binding/App2.kt b/wiki_kotlin/src/main/kotlin/com/github/klee0kai/wiki/provide/binding/App2.kt index 291f8850..f3002f4f 100644 --- a/wiki_kotlin/src/main/kotlin/com/github/klee0kai/wiki/provide/binding/App2.kt +++ b/wiki_kotlin/src/main/kotlin/com/github/klee0kai/wiki/provide/binding/App2.kt @@ -1,10 +1,9 @@ package com.github.klee0kai.wiki.provide.binding -import com.github.klee0kai.stone.Stone import com.github.klee0kai.test.mowgli.galaxy.Sun fun main(args: Array) { - val DI = Stone.createComponent(SunSystemComponent::class.java) + val DI = SunSystemComponentStoneComponent() val sun = Sun() DI.sun(sun) diff --git a/wiki_kotlin/src/main/kotlin/com/github/klee0kai/wiki/provide/identifiers/FeaturePresenter.kt b/wiki_kotlin/src/main/kotlin/com/github/klee0kai/wiki/provide/identifiers/FeaturePresenter.kt index baca39c5..e4604cf0 100644 --- a/wiki_kotlin/src/main/kotlin/com/github/klee0kai/wiki/provide/identifiers/FeaturePresenter.kt +++ b/wiki_kotlin/src/main/kotlin/com/github/klee0kai/wiki/provide/identifiers/FeaturePresenter.kt @@ -5,5 +5,5 @@ import java.util.concurrent.ThreadPoolExecutor class FeaturePresenter { constructor(executor: ThreadPoolExecutor) - constructor(screenId: ScreenId, loginId: LoginId) + constructor(screenId: ScreenId?, loginId: LoginId?) } diff --git a/wiki_kotlin/src/main/kotlin/com/github/klee0kai/wiki/provide/identifiers/PresentersModule.kt b/wiki_kotlin/src/main/kotlin/com/github/klee0kai/wiki/provide/identifiers/PresentersModule.kt index baab2722..d65d7d41 100644 --- a/wiki_kotlin/src/main/kotlin/com/github/klee0kai/wiki/provide/identifiers/PresentersModule.kt +++ b/wiki_kotlin/src/main/kotlin/com/github/klee0kai/wiki/provide/identifiers/PresentersModule.kt @@ -12,8 +12,8 @@ abstract class PresentersModule { ): FeaturePresenter abstract fun provideFeaturePresenter( - screenId: ScreenId, - loginId: LoginId + screenId: ScreenId?, + loginId: LoginId?, ): FeaturePresenter } diff --git a/wiki_kotlin/src/main/kotlin/com/github/klee0kai/wiki/provide/inject/AppComponent.kt b/wiki_kotlin/src/main/kotlin/com/github/klee0kai/wiki/provide/inject/AppComponent.kt index 5b62b56a..3d6474bd 100644 --- a/wiki_kotlin/src/main/kotlin/com/github/klee0kai/wiki/provide/inject/AppComponent.kt +++ b/wiki_kotlin/src/main/kotlin/com/github/klee0kai/wiki/provide/inject/AppComponent.kt @@ -7,7 +7,9 @@ import com.github.klee0kai.wiki.provide.identifiers.PresentersModule import com.github.klee0kai.wiki.provide.identifiers.ScreenId import com.github.klee0kai.wiki.provide.identifiers.ThreadsModule -@Component(identifiers = [ScreenId::class, LoginId::class]) +@Component( + identifiers = [ScreenId::class, LoginId::class] +) interface AppComponent { fun threadsModule(): ThreadsModule diff --git a/wiki_kotlin/src/main/kotlin/com/github/klee0kai/wiki/provide/inject/FeatureScreen.kt b/wiki_kotlin/src/main/kotlin/com/github/klee0kai/wiki/provide/inject/FeatureScreen.kt index fe835912..2ec5fb56 100644 --- a/wiki_kotlin/src/main/kotlin/com/github/klee0kai/wiki/provide/inject/FeatureScreen.kt +++ b/wiki_kotlin/src/main/kotlin/com/github/klee0kai/wiki/provide/inject/FeatureScreen.kt @@ -1,6 +1,5 @@ package com.github.klee0kai.wiki.provide.inject -import com.github.klee0kai.stone.Stone import com.github.klee0kai.wiki.provide.identifiers.FeaturePresenter import javax.inject.Inject @@ -14,7 +13,7 @@ class FeatureScreen { } fun start() { - val DI = Stone.createComponent(AppComponent::class.java) + val DI = AppComponentStoneComponent() DI.inject(this) } } diff --git a/wiki_kotlin/src/main/kotlin/com/github/klee0kai/wiki/start/App.kt b/wiki_kotlin/src/main/kotlin/com/github/klee0kai/wiki/start/App.kt index 0488ae59..bcd8ec66 100644 --- a/wiki_kotlin/src/main/kotlin/com/github/klee0kai/wiki/start/App.kt +++ b/wiki_kotlin/src/main/kotlin/com/github/klee0kai/wiki/start/App.kt @@ -1,11 +1,10 @@ package com.github.klee0kai.wiki.start -import com.github.klee0kai.stone.Stone object App { - val DI: SevenPlanetComponent = Stone.createComponent(SevenPlanetComponent::class.java) + val DI: SevenPlanetComponent = SevenPlanetComponentStoneComponent() fun main(args: Array) { val earth = DI.planets().earth() diff --git a/wiki_kotlin/src/main/kotlin/com/github/klee0kai/wiki/wrapping/CarBoxedWrapper.kt b/wiki_kotlin/src/main/kotlin/com/github/klee0kai/wiki/wrapping/CarBoxedWrapper.kt new file mode 100644 index 00000000..feb0eb30 --- /dev/null +++ b/wiki_kotlin/src/main/kotlin/com/github/klee0kai/wiki/wrapping/CarBoxedWrapper.kt @@ -0,0 +1,13 @@ +package com.github.klee0kai.wiki.wrapping + +import com.github.klee0kai.stone.annotations.wrappers.WrappersHelper +import com.github.klee0kai.stone.weakref.Provider + +@WrappersHelper +object CustomLazyWrapper { + + fun transformToCarLay( + origin: Provider, + ): CustomLazy = CustomLazy { origin.get() } + +} \ No newline at end of file diff --git a/wiki_kotlin/src/main/kotlin/com/github/klee0kai/wiki/wrapping/CustomLazy.kt b/wiki_kotlin/src/main/kotlin/com/github/klee0kai/wiki/wrapping/CustomLazy.kt index a37ddb6e..3a84ed52 100644 --- a/wiki_kotlin/src/main/kotlin/com/github/klee0kai/wiki/wrapping/CustomLazy.kt +++ b/wiki_kotlin/src/main/kotlin/com/github/klee0kai/wiki/wrapping/CustomLazy.kt @@ -1,6 +1,6 @@ package com.github.klee0kai.wiki.wrapping -import com.github.klee0kai.stone.wrappers.Ref +import com.github.klee0kai.stone.weakref.Ref import java.lang.ref.WeakReference class CustomLazy(call: Ref) { diff --git a/wiki_kotlin/src/main/kotlin/com/github/klee0kai/wiki/wrapping/CustomWrapper.kt b/wiki_kotlin/src/main/kotlin/com/github/klee0kai/wiki/wrapping/CustomWrapper.kt deleted file mode 100644 index 33945271..00000000 --- a/wiki_kotlin/src/main/kotlin/com/github/klee0kai/wiki/wrapping/CustomWrapper.kt +++ /dev/null @@ -1,17 +0,0 @@ -package com.github.klee0kai.wiki.wrapping - -import com.github.klee0kai.stone.annotations.wrappers.WrappersCreator -import com.github.klee0kai.stone.wrappers.creators.ProviderWrapper -import javax.inject.Provider - -@WrappersCreator(wrappers = [CustomLazy::class]) -class CustomWrapper : ProviderWrapper { - - override fun wrap(wrapperCl: Class, originalProvider: Provider): Wr? { - if (wrapperCl == CustomLazy::class.java) { - return CustomLazy { originalProvider.get() } as Wr - } - return null - } - -} diff --git a/wiki_kotlin/src/main/kotlin/com/github/klee0kai/wiki/wrapping/GoodPhone.kt b/wiki_kotlin/src/main/kotlin/com/github/klee0kai/wiki/wrapping/GoodPhone.kt index 9ff00297..e8734f58 100644 --- a/wiki_kotlin/src/main/kotlin/com/github/klee0kai/wiki/wrapping/GoodPhone.kt +++ b/wiki_kotlin/src/main/kotlin/com/github/klee0kai/wiki/wrapping/GoodPhone.kt @@ -1,13 +1,12 @@ package com.github.klee0kai.wiki.wrapping -import com.github.klee0kai.stone.Stone import com.github.klee0kai.stone.wrappers.LazyProvide import com.github.klee0kai.stone.wrappers.PhantomProvide import com.github.klee0kai.test.tech.components.Battery import com.github.klee0kai.test.tech.components.Ram import javax.inject.Inject -val DI: TechFactoryComponent = Stone.createComponent(TechFactoryComponent::class.java) +val DI: TechFactoryComponent = TechFactoryComponentStoneComponent() class GoodPhone { diff --git a/wiki_kotlin/src/main/kotlin/com/github/klee0kai/wiki/wrapping/TechFactoryComponent.kt b/wiki_kotlin/src/main/kotlin/com/github/klee0kai/wiki/wrapping/TechFactoryComponent.kt index 339e3155..fcb6ffa6 100644 --- a/wiki_kotlin/src/main/kotlin/com/github/klee0kai/wiki/wrapping/TechFactoryComponent.kt +++ b/wiki_kotlin/src/main/kotlin/com/github/klee0kai/wiki/wrapping/TechFactoryComponent.kt @@ -6,7 +6,9 @@ import com.github.klee0kai.stone.wrappers.PhantomProvide import com.github.klee0kai.test.tech.components.Battery import com.github.klee0kai.test.tech.components.Ram -@Component(wrapperProviders = [CustomWrapper::class]) +@Component( + wrapperHelpers = [CustomLazyWrapper::class], +) interface TechFactoryComponent { fun factory(): TechFactoryModule diff --git a/wiki_kotlin/src/test/kotlin/com/github/klee0kai/wiki/start/AppStartTest.kt b/wiki_kotlin/src/test/kotlin/com/github/klee0kai/wiki/start/AppStartTest.kt new file mode 100644 index 00000000..d7aff1ae --- /dev/null +++ b/wiki_kotlin/src/test/kotlin/com/github/klee0kai/wiki/start/AppStartTest.kt @@ -0,0 +1,18 @@ +package com.github.klee0kai.wiki.start + +import org.junit.jupiter.api.Test + +class AppStartTest { + + @Test + fun testAppStart1() { + App.main(arrayOf()) + } + + @Test + fun testAppStart2() { + App2.main(arrayOf()) + } + + +} \ No newline at end of file From 44071cebde159ce95af5828fbe5796eacd7dd86a Mon Sep 17 00:00:00 2001 From: klee0kai Date: Sun, 18 Jan 2026 00:40:25 +0100 Subject: [PATCH 099/122] delete kapt processors. disable compile tests. Remove android targets --- android_lib/.gitignore | 1 - android_lib/build.gradle.kts | 42 - android_lib/consumer-rules.pro | 0 android_lib/proguard-rules.pro | 21 - android_lib/src/main/AndroidManifest.xml | 5 - .../github/klee0kai/stone/AndroidStone.java | 38 - build.gradle.kts | 6 + inject_multiplatform/build.gradle.kts | 18 +- .../github/klee0kai/stone/weakref/Inject.kt | 3 - .../github/klee0kai/stone/weakref/Named.kt | 3 - .../github/klee0kai/stone/weakref/Provider.kt | 5 - .../klee0kai/stone/weakref/Qualifier.kt | 3 - .../github/klee0kai/stone/weakref/Scope.kt | 3 - .../klee0kai/stone/weakref/Singleton.kt | 3 - kotlin_lib/build.gradle.kts | 24 - .../klee0kai/stone/KotlinWrappersStone.kt | 21 - .../stone/type/wrappers/WrappersExt.kt | 13 - libs.versions.toml | 16 +- settings.gradle.kts | 7 +- stone_ksp/build.gradle.kts | 15 +- ...rProvider.kt => StoneProcessorProvider.kt} | 2 +- ...ols.ksp.processing.SymbolProcessorProvider | 2 +- stone_lib/build.gradle.kts | 27 - .../java/com/github/klee0kai/stone/Stone.java | 22 - .../klee0kai/stone/_hidden_/IModule.java | 60 -- .../stone/_hidden_/IModuleFactory.java | 8 - .../stone/_hidden_/IPrivateComponent.java | 53 -- .../_hidden_/provide/ProvideBuilder.java | 28 - .../_hidden_/provide/ProvideConsumer.java | 33 - .../stone/_hidden_/types/CacheAction.java | 70 -- .../stone/_hidden_/types/ListUtils.java | 154 ---- .../stone/_hidden_/types/MultiKey.java | 60 -- .../stone/_hidden_/types/NullGet.java | 23 - .../stone/_hidden_/types/RefCollection.java | 38 - .../stone/_hidden_/types/StoneCallback.java | 10 - .../_hidden_/types/SwitchCacheParam.java | 29 - .../stone/_hidden_/types/Threads.java | 23 - .../stone/_hidden_/types/WeakList.java | 78 -- .../_hidden_/types/holders/DataAwait.java | 57 -- .../_hidden_/types/holders/MapItemHolder.java | 193 ----- .../_hidden_/types/holders/ScheduleTask.java | 31 - .../types/holders/SingleItemHolder.java | 163 ---- .../_hidden_/types/holders/StoneRefType.java | 72 -- .../_hidden_/types/holders/TimeHolder.java | 47 - .../_hidden_/types/holders/TimeScheduler.java | 53 -- .../annotations/component/Component.java | 246 ------ .../stone/annotations/component/ExtendOf.java | 36 - .../annotations/component/GcAllScope.java | 20 - .../component/GcScopeAnnotation.java | 37 - .../annotations/component/GcSoftScope.java | 20 - .../annotations/component/GcStrongScope.java | 20 - .../annotations/component/GcWeakScope.java | 20 - .../stone/annotations/component/Init.java | 37 - .../component/ModuleOriginFactory.java | 32 - .../component/ProtectInjected.java | 39 - .../stone/annotations/component/RunGc.java | 45 - .../annotations/component/SwitchCache.java | 77 -- .../dependencies/Dependencies.java | 54 -- .../annotations/module/BindInstance.java | 85 -- .../stone/annotations/module/Module.java | 86 -- .../stone/annotations/module/Provide.java | 49 -- .../annotations/wrappers/WrappersCreator.java | 26 - .../lifecycle/StoneLifeCycleListener.java | 7 - .../stone/lifecycle/StoneLifeCycleOwner.java | 55 -- .../klee0kai/stone/wrappers/AsyncProvide.java | 40 - .../klee0kai/stone/wrappers/LazyProvide.java | 30 - .../stone/wrappers/PhantomProvide.java | 31 - .../github/klee0kai/stone/wrappers/Ref.java | 9 - .../wrappers/creators/CircleWrapper.java | 17 - .../wrappers/creators/ProviderWrapper.java | 18 - .../stone/wrappers/creators/Wrapper.java | 16 - .../types/holders/RefCollectionTests.java | 79 -- .../closed/types/holders/TimeHolderTests.java | 37 - stone_multiplatform/build.gradle.kts | 18 +- stone_processor/build.gradle.kts | 31 - .../klee0kai/stone/AnnotationProcessor.java | 183 ---- .../stone/checks/ComponentChecks.java | 145 ---- .../stone/checks/ComponentMethods.java | 255 ------ .../stone/checks/DependencyChecks.java | 45 - .../klee0kai/stone/checks/ModuleChecks.java | 98 --- .../klee0kai/stone/checks/ModuleMethods.java | 81 -- .../stone/checks/WrappersCreatorChecks.java | 109 --- .../stone/codegen/ComponentBuilder.java | 810 ------------------ .../klee0kai/stone/codegen/ModuleBuilder.java | 688 --------------- .../ModuleCacheControlInterfaceBuilder.java | 144 ---- .../stone/codegen/ModuleFactoryBuilder.java | 179 ---- .../stone/codegen/WrappersSupportBuilder.java | 120 --- .../codegen/model/WrapperCreatorField.java | 26 - .../ClassNotFoundStoneException.java | 15 - .../exceptions/ExceptionStringBuilder.java | 365 -------- .../ImplementMethodStoneException.java | 15 - .../IncorrectSignatureException.java | 23 - .../ObjectNotProvidedException.java | 22 - ...imitiveTypeNonSupportedStoneException.java | 15 - .../stone/exceptions/RecursiveProviding.java | 19 - .../stone/exceptions/StoneException.java | 28 - .../stone/helpers/AllClassesHelper.java | 212 ----- .../stone/helpers/SetFieldHelper.java | 80 -- .../helpers/codebuilder/DelayedCode.java | 7 - .../stone/helpers/codebuilder/ISmartCode.java | 5 - .../stone/helpers/codebuilder/SmartCode.java | 184 ---- .../invokecall/GenArgumentFunctions.java | 48 -- .../stone/helpers/invokecall/InvokeCall.java | 280 ------ .../helpers/invokecall/ModulesGraph.java | 300 ------- .../stone/helpers/invokecall/ProvideDep.java | 41 - .../helpers/itemholder/ItemCacheType.java | 78 -- .../itemholder/ItemHolderCodeHelper.java | 69 -- .../MultiKeyMapItemHolderHelper.java | 67 -- .../itemholder/SimpleMapItemHolderHelper.java | 65 -- .../itemholder/SingleItemHolderHelper.java | 61 -- .../stone/helpers/wrap/FormatInList.java | 14 - .../stone/helpers/wrap/FormatSimple.java | 13 - .../stone/helpers/wrap/WrapHelper.java | 302 ------- .../klee0kai/stone/helpers/wrap/WrapType.java | 22 - .../klee0kai/stone/model/ClassDetail.java | 340 -------- .../stone/model/ComponentClassDetails.java | 103 --- .../klee0kai/stone/model/FieldDetail.java | 121 --- .../klee0kai/stone/model/MethodDetail.java | 277 ------ .../com/github/klee0kai/stone/model/Pair.java | 33 - .../klee0kai/stone/model/TypeKindDetails.java | 72 -- .../model/annotations/BindInstanceAnn.java | 42 - .../stone/model/annotations/ComponentAnn.java | 97 --- .../model/annotations/DependenciesAnn.java | 38 - .../stone/model/annotations/ExtOfAnn.java | 44 - .../stone/model/annotations/IAnnotation.java | 9 - .../stone/model/annotations/InitAnn.java | 44 - .../stone/model/annotations/InjectAnn.java | 44 - .../stone/model/annotations/ModuleAnn.java | 38 - .../annotations/ModuleOriginFactoryAnn.java | 39 - .../model/annotations/ProtectInjectedAnn.java | 41 - .../stone/model/annotations/ProvideAnn.java | 45 - .../stone/model/annotations/QualifierAnn.java | 86 -- .../stone/model/annotations/RunGcAnn.java | 40 - .../stone/model/annotations/SingletonAnn.java | 44 - .../model/annotations/SwitchCacheAnn.java | 44 - .../model/annotations/WrapperCreatorsAnn.java | 65 -- .../stone/utils/AnnotationMirrorUtil.java | 47 - .../klee0kai/stone/utils/ClassNameUtils.java | 76 -- .../klee0kai/stone/utils/CodeFileUtil.java | 39 - .../utils/ImplementMethodCollection.java | 58 -- .../klee0kai/stone/utils/LocalFieldName.java | 13 - .../stone/utils/RecursiveDetector.java | 37 - .../stone/utils/StoneNamingUtils.java | 87 -- test_feature_core_deps/build.gradle.kts | 1 - tests_compile/build.gradle.kts | 13 +- .../github/klee0kai/stone/test/SimpleTests.kt | 33 + .../com/github/klee0kai/stone/test/Utils.kt | 14 + .../src/test/resources/SimpleCarComponent.kt | 16 + weakref_multiplatform/build.gradle.kts | 18 +- .../github/klee0kai/stone/weakref/SoftRef.kt | 15 - .../github/klee0kai/stone/weakref/WeakRef.kt | 15 - .../github/klee0kai/stone/weakref/Memory.kt | 2 +- .../klee0kai/stone/weakref/Memory.jvm.kt | 0 153 files changed, 117 insertions(+), 10206 deletions(-) delete mode 100644 android_lib/.gitignore delete mode 100644 android_lib/build.gradle.kts delete mode 100644 android_lib/consumer-rules.pro delete mode 100644 android_lib/proguard-rules.pro delete mode 100644 android_lib/src/main/AndroidManifest.xml delete mode 100644 android_lib/src/main/java/com/github/klee0kai/stone/AndroidStone.java delete mode 100644 inject_multiplatform/src/androidMain/kotlin/com/github/klee0kai/stone/weakref/Inject.kt delete mode 100644 inject_multiplatform/src/androidMain/kotlin/com/github/klee0kai/stone/weakref/Named.kt delete mode 100644 inject_multiplatform/src/androidMain/kotlin/com/github/klee0kai/stone/weakref/Provider.kt delete mode 100644 inject_multiplatform/src/androidMain/kotlin/com/github/klee0kai/stone/weakref/Qualifier.kt delete mode 100644 inject_multiplatform/src/androidMain/kotlin/com/github/klee0kai/stone/weakref/Scope.kt delete mode 100644 inject_multiplatform/src/androidMain/kotlin/com/github/klee0kai/stone/weakref/Singleton.kt delete mode 100644 kotlin_lib/build.gradle.kts delete mode 100644 kotlin_lib/src/main/kotlin/com/github/klee0kai/stone/KotlinWrappersStone.kt delete mode 100644 kotlin_lib/src/main/kotlin/com/github/klee0kai/stone/type/wrappers/WrappersExt.kt rename stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/{ProcessorProvider.kt => StoneProcessorProvider.kt} (89%) delete mode 100644 stone_lib/build.gradle.kts delete mode 100644 stone_lib/src/main/java/com/github/klee0kai/stone/Stone.java delete mode 100644 stone_lib/src/main/java/com/github/klee0kai/stone/_hidden_/IModule.java delete mode 100644 stone_lib/src/main/java/com/github/klee0kai/stone/_hidden_/IModuleFactory.java delete mode 100644 stone_lib/src/main/java/com/github/klee0kai/stone/_hidden_/IPrivateComponent.java delete mode 100644 stone_lib/src/main/java/com/github/klee0kai/stone/_hidden_/provide/ProvideBuilder.java delete mode 100644 stone_lib/src/main/java/com/github/klee0kai/stone/_hidden_/provide/ProvideConsumer.java delete mode 100644 stone_lib/src/main/java/com/github/klee0kai/stone/_hidden_/types/CacheAction.java delete mode 100644 stone_lib/src/main/java/com/github/klee0kai/stone/_hidden_/types/ListUtils.java delete mode 100644 stone_lib/src/main/java/com/github/klee0kai/stone/_hidden_/types/MultiKey.java delete mode 100644 stone_lib/src/main/java/com/github/klee0kai/stone/_hidden_/types/NullGet.java delete mode 100644 stone_lib/src/main/java/com/github/klee0kai/stone/_hidden_/types/RefCollection.java delete mode 100644 stone_lib/src/main/java/com/github/klee0kai/stone/_hidden_/types/StoneCallback.java delete mode 100644 stone_lib/src/main/java/com/github/klee0kai/stone/_hidden_/types/SwitchCacheParam.java delete mode 100644 stone_lib/src/main/java/com/github/klee0kai/stone/_hidden_/types/Threads.java delete mode 100644 stone_lib/src/main/java/com/github/klee0kai/stone/_hidden_/types/WeakList.java delete mode 100644 stone_lib/src/main/java/com/github/klee0kai/stone/_hidden_/types/holders/DataAwait.java delete mode 100644 stone_lib/src/main/java/com/github/klee0kai/stone/_hidden_/types/holders/MapItemHolder.java delete mode 100644 stone_lib/src/main/java/com/github/klee0kai/stone/_hidden_/types/holders/ScheduleTask.java delete mode 100644 stone_lib/src/main/java/com/github/klee0kai/stone/_hidden_/types/holders/SingleItemHolder.java delete mode 100644 stone_lib/src/main/java/com/github/klee0kai/stone/_hidden_/types/holders/StoneRefType.java delete mode 100644 stone_lib/src/main/java/com/github/klee0kai/stone/_hidden_/types/holders/TimeHolder.java delete mode 100644 stone_lib/src/main/java/com/github/klee0kai/stone/_hidden_/types/holders/TimeScheduler.java delete mode 100644 stone_lib/src/main/java/com/github/klee0kai/stone/annotations/component/Component.java delete mode 100644 stone_lib/src/main/java/com/github/klee0kai/stone/annotations/component/ExtendOf.java delete mode 100644 stone_lib/src/main/java/com/github/klee0kai/stone/annotations/component/GcAllScope.java delete mode 100644 stone_lib/src/main/java/com/github/klee0kai/stone/annotations/component/GcScopeAnnotation.java delete mode 100644 stone_lib/src/main/java/com/github/klee0kai/stone/annotations/component/GcSoftScope.java delete mode 100644 stone_lib/src/main/java/com/github/klee0kai/stone/annotations/component/GcStrongScope.java delete mode 100644 stone_lib/src/main/java/com/github/klee0kai/stone/annotations/component/GcWeakScope.java delete mode 100644 stone_lib/src/main/java/com/github/klee0kai/stone/annotations/component/Init.java delete mode 100644 stone_lib/src/main/java/com/github/klee0kai/stone/annotations/component/ModuleOriginFactory.java delete mode 100644 stone_lib/src/main/java/com/github/klee0kai/stone/annotations/component/ProtectInjected.java delete mode 100644 stone_lib/src/main/java/com/github/klee0kai/stone/annotations/component/RunGc.java delete mode 100644 stone_lib/src/main/java/com/github/klee0kai/stone/annotations/component/SwitchCache.java delete mode 100644 stone_lib/src/main/java/com/github/klee0kai/stone/annotations/dependencies/Dependencies.java delete mode 100644 stone_lib/src/main/java/com/github/klee0kai/stone/annotations/module/BindInstance.java delete mode 100644 stone_lib/src/main/java/com/github/klee0kai/stone/annotations/module/Module.java delete mode 100644 stone_lib/src/main/java/com/github/klee0kai/stone/annotations/module/Provide.java delete mode 100644 stone_lib/src/main/java/com/github/klee0kai/stone/annotations/wrappers/WrappersCreator.java delete mode 100644 stone_lib/src/main/java/com/github/klee0kai/stone/lifecycle/StoneLifeCycleListener.java delete mode 100644 stone_lib/src/main/java/com/github/klee0kai/stone/lifecycle/StoneLifeCycleOwner.java delete mode 100644 stone_lib/src/main/java/com/github/klee0kai/stone/wrappers/AsyncProvide.java delete mode 100644 stone_lib/src/main/java/com/github/klee0kai/stone/wrappers/LazyProvide.java delete mode 100644 stone_lib/src/main/java/com/github/klee0kai/stone/wrappers/PhantomProvide.java delete mode 100644 stone_lib/src/main/java/com/github/klee0kai/stone/wrappers/Ref.java delete mode 100644 stone_lib/src/main/java/com/github/klee0kai/stone/wrappers/creators/CircleWrapper.java delete mode 100644 stone_lib/src/main/java/com/github/klee0kai/stone/wrappers/creators/ProviderWrapper.java delete mode 100644 stone_lib/src/main/java/com/github/klee0kai/stone/wrappers/creators/Wrapper.java delete mode 100644 stone_lib/src/test/java/com/github/klee0kai/stone/closed/types/holders/RefCollectionTests.java delete mode 100644 stone_lib/src/test/java/com/github/klee0kai/stone/closed/types/holders/TimeHolderTests.java delete mode 100644 stone_processor/build.gradle.kts delete mode 100644 stone_processor/src/main/java/com/github/klee0kai/stone/AnnotationProcessor.java delete mode 100644 stone_processor/src/main/java/com/github/klee0kai/stone/checks/ComponentChecks.java delete mode 100644 stone_processor/src/main/java/com/github/klee0kai/stone/checks/ComponentMethods.java delete mode 100644 stone_processor/src/main/java/com/github/klee0kai/stone/checks/DependencyChecks.java delete mode 100644 stone_processor/src/main/java/com/github/klee0kai/stone/checks/ModuleChecks.java delete mode 100644 stone_processor/src/main/java/com/github/klee0kai/stone/checks/ModuleMethods.java delete mode 100644 stone_processor/src/main/java/com/github/klee0kai/stone/checks/WrappersCreatorChecks.java delete mode 100644 stone_processor/src/main/java/com/github/klee0kai/stone/codegen/ComponentBuilder.java delete mode 100644 stone_processor/src/main/java/com/github/klee0kai/stone/codegen/ModuleBuilder.java delete mode 100644 stone_processor/src/main/java/com/github/klee0kai/stone/codegen/ModuleCacheControlInterfaceBuilder.java delete mode 100644 stone_processor/src/main/java/com/github/klee0kai/stone/codegen/ModuleFactoryBuilder.java delete mode 100644 stone_processor/src/main/java/com/github/klee0kai/stone/codegen/WrappersSupportBuilder.java delete mode 100644 stone_processor/src/main/java/com/github/klee0kai/stone/codegen/model/WrapperCreatorField.java delete mode 100644 stone_processor/src/main/java/com/github/klee0kai/stone/exceptions/ClassNotFoundStoneException.java delete mode 100644 stone_processor/src/main/java/com/github/klee0kai/stone/exceptions/ExceptionStringBuilder.java delete mode 100644 stone_processor/src/main/java/com/github/klee0kai/stone/exceptions/ImplementMethodStoneException.java delete mode 100644 stone_processor/src/main/java/com/github/klee0kai/stone/exceptions/IncorrectSignatureException.java delete mode 100644 stone_processor/src/main/java/com/github/klee0kai/stone/exceptions/ObjectNotProvidedException.java delete mode 100644 stone_processor/src/main/java/com/github/klee0kai/stone/exceptions/PrimitiveTypeNonSupportedStoneException.java delete mode 100644 stone_processor/src/main/java/com/github/klee0kai/stone/exceptions/RecursiveProviding.java delete mode 100644 stone_processor/src/main/java/com/github/klee0kai/stone/exceptions/StoneException.java delete mode 100644 stone_processor/src/main/java/com/github/klee0kai/stone/helpers/AllClassesHelper.java delete mode 100644 stone_processor/src/main/java/com/github/klee0kai/stone/helpers/SetFieldHelper.java delete mode 100644 stone_processor/src/main/java/com/github/klee0kai/stone/helpers/codebuilder/DelayedCode.java delete mode 100644 stone_processor/src/main/java/com/github/klee0kai/stone/helpers/codebuilder/ISmartCode.java delete mode 100644 stone_processor/src/main/java/com/github/klee0kai/stone/helpers/codebuilder/SmartCode.java delete mode 100644 stone_processor/src/main/java/com/github/klee0kai/stone/helpers/invokecall/GenArgumentFunctions.java delete mode 100644 stone_processor/src/main/java/com/github/klee0kai/stone/helpers/invokecall/InvokeCall.java delete mode 100644 stone_processor/src/main/java/com/github/klee0kai/stone/helpers/invokecall/ModulesGraph.java delete mode 100644 stone_processor/src/main/java/com/github/klee0kai/stone/helpers/invokecall/ProvideDep.java delete mode 100644 stone_processor/src/main/java/com/github/klee0kai/stone/helpers/itemholder/ItemCacheType.java delete mode 100644 stone_processor/src/main/java/com/github/klee0kai/stone/helpers/itemholder/ItemHolderCodeHelper.java delete mode 100644 stone_processor/src/main/java/com/github/klee0kai/stone/helpers/itemholder/MultiKeyMapItemHolderHelper.java delete mode 100644 stone_processor/src/main/java/com/github/klee0kai/stone/helpers/itemholder/SimpleMapItemHolderHelper.java delete mode 100644 stone_processor/src/main/java/com/github/klee0kai/stone/helpers/itemholder/SingleItemHolderHelper.java delete mode 100644 stone_processor/src/main/java/com/github/klee0kai/stone/helpers/wrap/FormatInList.java delete mode 100644 stone_processor/src/main/java/com/github/klee0kai/stone/helpers/wrap/FormatSimple.java delete mode 100644 stone_processor/src/main/java/com/github/klee0kai/stone/helpers/wrap/WrapHelper.java delete mode 100644 stone_processor/src/main/java/com/github/klee0kai/stone/helpers/wrap/WrapType.java delete mode 100644 stone_processor/src/main/java/com/github/klee0kai/stone/model/ClassDetail.java delete mode 100644 stone_processor/src/main/java/com/github/klee0kai/stone/model/ComponentClassDetails.java delete mode 100644 stone_processor/src/main/java/com/github/klee0kai/stone/model/FieldDetail.java delete mode 100644 stone_processor/src/main/java/com/github/klee0kai/stone/model/MethodDetail.java delete mode 100644 stone_processor/src/main/java/com/github/klee0kai/stone/model/Pair.java delete mode 100644 stone_processor/src/main/java/com/github/klee0kai/stone/model/TypeKindDetails.java delete mode 100644 stone_processor/src/main/java/com/github/klee0kai/stone/model/annotations/BindInstanceAnn.java delete mode 100644 stone_processor/src/main/java/com/github/klee0kai/stone/model/annotations/ComponentAnn.java delete mode 100644 stone_processor/src/main/java/com/github/klee0kai/stone/model/annotations/DependenciesAnn.java delete mode 100644 stone_processor/src/main/java/com/github/klee0kai/stone/model/annotations/ExtOfAnn.java delete mode 100644 stone_processor/src/main/java/com/github/klee0kai/stone/model/annotations/IAnnotation.java delete mode 100644 stone_processor/src/main/java/com/github/klee0kai/stone/model/annotations/InitAnn.java delete mode 100644 stone_processor/src/main/java/com/github/klee0kai/stone/model/annotations/InjectAnn.java delete mode 100644 stone_processor/src/main/java/com/github/klee0kai/stone/model/annotations/ModuleAnn.java delete mode 100644 stone_processor/src/main/java/com/github/klee0kai/stone/model/annotations/ModuleOriginFactoryAnn.java delete mode 100644 stone_processor/src/main/java/com/github/klee0kai/stone/model/annotations/ProtectInjectedAnn.java delete mode 100644 stone_processor/src/main/java/com/github/klee0kai/stone/model/annotations/ProvideAnn.java delete mode 100644 stone_processor/src/main/java/com/github/klee0kai/stone/model/annotations/QualifierAnn.java delete mode 100644 stone_processor/src/main/java/com/github/klee0kai/stone/model/annotations/RunGcAnn.java delete mode 100644 stone_processor/src/main/java/com/github/klee0kai/stone/model/annotations/SingletonAnn.java delete mode 100644 stone_processor/src/main/java/com/github/klee0kai/stone/model/annotations/SwitchCacheAnn.java delete mode 100644 stone_processor/src/main/java/com/github/klee0kai/stone/model/annotations/WrapperCreatorsAnn.java delete mode 100644 stone_processor/src/main/java/com/github/klee0kai/stone/utils/AnnotationMirrorUtil.java delete mode 100644 stone_processor/src/main/java/com/github/klee0kai/stone/utils/ClassNameUtils.java delete mode 100644 stone_processor/src/main/java/com/github/klee0kai/stone/utils/CodeFileUtil.java delete mode 100644 stone_processor/src/main/java/com/github/klee0kai/stone/utils/ImplementMethodCollection.java delete mode 100644 stone_processor/src/main/java/com/github/klee0kai/stone/utils/LocalFieldName.java delete mode 100644 stone_processor/src/main/java/com/github/klee0kai/stone/utils/RecursiveDetector.java delete mode 100644 stone_processor/src/main/java/com/github/klee0kai/stone/utils/StoneNamingUtils.java create mode 100644 tests_compile/src/test/kotlin/com/github/klee0kai/stone/test/SimpleTests.kt create mode 100644 tests_compile/src/test/kotlin/com/github/klee0kai/stone/test/Utils.kt create mode 100644 tests_compile/src/test/resources/SimpleCarComponent.kt delete mode 100644 weakref_multiplatform/src/androidMain/kotlin/com/github/klee0kai/stone/weakref/SoftRef.kt delete mode 100644 weakref_multiplatform/src/androidMain/kotlin/com/github/klee0kai/stone/weakref/WeakRef.kt rename weakref_multiplatform/src/jvmMain/{java => kotlin}/com/github/klee0kai/stone/weakref/Memory.jvm.kt (100%) diff --git a/android_lib/.gitignore b/android_lib/.gitignore deleted file mode 100644 index 42afabfd..00000000 --- a/android_lib/.gitignore +++ /dev/null @@ -1 +0,0 @@ -/build \ No newline at end of file diff --git a/android_lib/build.gradle.kts b/android_lib/build.gradle.kts deleted file mode 100644 index 07cfd5a0..00000000 --- a/android_lib/build.gradle.kts +++ /dev/null @@ -1,42 +0,0 @@ -plugins { - alias(libs.plugins.android.library) - alias(libs.plugins.publish.maven) - alias(libs.plugins.publish.stone) -} - -group = "com.github.klee0kai.stone" -version = libs.versions.stone.get() - -android { - namespace = project.group.toString() - compileSdk = 33 - - defaultConfig { - minSdk = 21 - targetSdk = 33 - - consumerProguardFiles("consumer-rules.pro") - } - - - buildTypes { - release { - isMinifyEnabled = false - proguardFile(getDefaultProguardFile("proguard-android-optimize.txt")) - consumerProguardFiles("proguard-rules.pro") - } - } - publishing { - singleVariant("release") { - withSourcesJar() - withJavadocJar() - } - } -} - - -dependencies { - api(project(":stone_lib")) - - implementation(libs.android.appcompat) -} \ No newline at end of file diff --git a/android_lib/consumer-rules.pro b/android_lib/consumer-rules.pro deleted file mode 100644 index e69de29b..00000000 diff --git a/android_lib/proguard-rules.pro b/android_lib/proguard-rules.pro deleted file mode 100644 index ff59496d..00000000 --- a/android_lib/proguard-rules.pro +++ /dev/null @@ -1,21 +0,0 @@ -# Add project specific ProGuard rules here. -# You can control the set of applied configuration files using the -# proguardFiles setting in build.gradle.kts. -# -# For more details, see -# http://developer.android.com/guide/developing/tools/proguard.html - -# If your project uses WebView with JS, uncomment the following -# and specify the fully qualified class name to the JavaScript interface -# class: -#-keepclassmembers class fqcn.of.javascript.interface.for.webview { -# public *; -#} - -# Uncomment this to preserve the line number information for -# debugging stack traces. -#-keepattributes SourceFile,LineNumberTable - -# If you keep the line number information, uncomment this to -# hide the original source file name. -#-renamesourcefileattribute SourceFile \ No newline at end of file diff --git a/android_lib/src/main/AndroidManifest.xml b/android_lib/src/main/AndroidManifest.xml deleted file mode 100644 index 325bfcc5..00000000 --- a/android_lib/src/main/AndroidManifest.xml +++ /dev/null @@ -1,5 +0,0 @@ - - - - \ No newline at end of file diff --git a/android_lib/src/main/java/com/github/klee0kai/stone/AndroidStone.java b/android_lib/src/main/java/com/github/klee0kai/stone/AndroidStone.java deleted file mode 100644 index a7793a55..00000000 --- a/android_lib/src/main/java/com/github/klee0kai/stone/AndroidStone.java +++ /dev/null @@ -1,38 +0,0 @@ -package com.github.klee0kai.stone; - - -import androidx.annotation.NonNull; -import androidx.lifecycle.DefaultLifecycleObserver; -import androidx.lifecycle.Lifecycle; -import androidx.lifecycle.LifecycleOwner; -import com.github.klee0kai.stone.lifecycle.StoneLifeCycleOwner; -import org.jetbrains.annotations.NotNull; - -public class AndroidStone { - - private static final long PROTECT_TIME_MILLIS = 500; - - public static StoneLifeCycleOwner lifeCycleOwner(LifecycleOwner owner, long protectTimeMillis) { - return lifeCycleOwner(owner.getLifecycle(), protectTimeMillis); - } - - public static StoneLifeCycleOwner lifeCycleOwner(Lifecycle lifecycle, long protectTimeMillis) { - return listener -> lifecycle.addObserver(new DefaultLifecycleObserver() { - @Override - public void onPause(@NonNull @NotNull LifecycleOwner owner1) { - DefaultLifecycleObserver.super.onPause(owner1); - listener.protectForInjected(protectTimeMillis); - } - }); - } - - public static StoneLifeCycleOwner lifeCycleOwner(LifecycleOwner owner) { - return lifeCycleOwner(owner.getLifecycle(), PROTECT_TIME_MILLIS); - } - - public static StoneLifeCycleOwner lifeCycleOwner(Lifecycle lifecycle) { - return lifeCycleOwner(lifecycle, PROTECT_TIME_MILLIS); - } - - -} diff --git a/build.gradle.kts b/build.gradle.kts index e69de29b..bd73b8bf 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -0,0 +1,6 @@ +plugins { + // We declare plugins without application. We avoid possible version conflicts. + alias(libs.plugins.kotlin.multiplatform) apply false + alias(libs.plugins.kotlin.jvm) apply false + alias(libs.plugins.android.library) apply false +} \ No newline at end of file diff --git a/inject_multiplatform/build.gradle.kts b/inject_multiplatform/build.gradle.kts index afd5e7d3..2c430e84 100644 --- a/inject_multiplatform/build.gradle.kts +++ b/inject_multiplatform/build.gradle.kts @@ -1,21 +1,21 @@ plugins { alias(libs.plugins.kotlin.multiplatform) - alias(libs.plugins.android.library) +// alias(libs.plugins.android.library) } group = "com.github.klee0kai.stone.inject" version = libs.versions.stone.get() -android { - namespace = project.group.toString() - compileSdk = 36 - defaultConfig { - minSdk = 21 - } -} +//android { +// namespace = project.group.toString() +// compileSdk = 36 +// defaultConfig { +// minSdk = 21 +// } +//} kotlin { - androidTarget() +// androidTarget() jvm() js(IR) { browser() diff --git a/inject_multiplatform/src/androidMain/kotlin/com/github/klee0kai/stone/weakref/Inject.kt b/inject_multiplatform/src/androidMain/kotlin/com/github/klee0kai/stone/weakref/Inject.kt deleted file mode 100644 index 9d8e703d..00000000 --- a/inject_multiplatform/src/androidMain/kotlin/com/github/klee0kai/stone/weakref/Inject.kt +++ /dev/null @@ -1,3 +0,0 @@ -package com.github.klee0kai.stone.weakref - -actual annotation class Inject actual constructor() \ No newline at end of file diff --git a/inject_multiplatform/src/androidMain/kotlin/com/github/klee0kai/stone/weakref/Named.kt b/inject_multiplatform/src/androidMain/kotlin/com/github/klee0kai/stone/weakref/Named.kt deleted file mode 100644 index 6a8ffaf9..00000000 --- a/inject_multiplatform/src/androidMain/kotlin/com/github/klee0kai/stone/weakref/Named.kt +++ /dev/null @@ -1,3 +0,0 @@ -package com.github.klee0kai.stone.weakref - -actual annotation class Named actual constructor(actual val value: String) \ No newline at end of file diff --git a/inject_multiplatform/src/androidMain/kotlin/com/github/klee0kai/stone/weakref/Provider.kt b/inject_multiplatform/src/androidMain/kotlin/com/github/klee0kai/stone/weakref/Provider.kt deleted file mode 100644 index cc771814..00000000 --- a/inject_multiplatform/src/androidMain/kotlin/com/github/klee0kai/stone/weakref/Provider.kt +++ /dev/null @@ -1,5 +0,0 @@ -package com.github.klee0kai.stone.weakref - -actual interface Provider { - actual fun get(): T -} \ No newline at end of file diff --git a/inject_multiplatform/src/androidMain/kotlin/com/github/klee0kai/stone/weakref/Qualifier.kt b/inject_multiplatform/src/androidMain/kotlin/com/github/klee0kai/stone/weakref/Qualifier.kt deleted file mode 100644 index 7382be14..00000000 --- a/inject_multiplatform/src/androidMain/kotlin/com/github/klee0kai/stone/weakref/Qualifier.kt +++ /dev/null @@ -1,3 +0,0 @@ -package com.github.klee0kai.stone.weakref - -actual annotation class Qualifier actual constructor() \ No newline at end of file diff --git a/inject_multiplatform/src/androidMain/kotlin/com/github/klee0kai/stone/weakref/Scope.kt b/inject_multiplatform/src/androidMain/kotlin/com/github/klee0kai/stone/weakref/Scope.kt deleted file mode 100644 index 14247bbd..00000000 --- a/inject_multiplatform/src/androidMain/kotlin/com/github/klee0kai/stone/weakref/Scope.kt +++ /dev/null @@ -1,3 +0,0 @@ -package com.github.klee0kai.stone.weakref - -actual annotation class Scope actual constructor() \ No newline at end of file diff --git a/inject_multiplatform/src/androidMain/kotlin/com/github/klee0kai/stone/weakref/Singleton.kt b/inject_multiplatform/src/androidMain/kotlin/com/github/klee0kai/stone/weakref/Singleton.kt deleted file mode 100644 index 18f8cb56..00000000 --- a/inject_multiplatform/src/androidMain/kotlin/com/github/klee0kai/stone/weakref/Singleton.kt +++ /dev/null @@ -1,3 +0,0 @@ -package com.github.klee0kai.stone.weakref - -actual annotation class Singleton actual constructor() \ No newline at end of file diff --git a/kotlin_lib/build.gradle.kts b/kotlin_lib/build.gradle.kts deleted file mode 100644 index f3f5d804..00000000 --- a/kotlin_lib/build.gradle.kts +++ /dev/null @@ -1,24 +0,0 @@ -plugins { - alias(libs.plugins.kotlin.jvm) - alias(libs.plugins.kotlin.kapt) - alias(libs.plugins.publish.maven) - alias(libs.plugins.publish.stone) -} - -group = "com.github.klee0kai.stone" -version = libs.versions.stone.get() - -java { - withSourcesJar() - withJavadocJar() -} - -tasks.test { - useJUnitPlatform() -} - -dependencies { - api(project(":stone_lib")) -} - - diff --git a/kotlin_lib/src/main/kotlin/com/github/klee0kai/stone/KotlinWrappersStone.kt b/kotlin_lib/src/main/kotlin/com/github/klee0kai/stone/KotlinWrappersStone.kt deleted file mode 100644 index 768f7de7..00000000 --- a/kotlin_lib/src/main/kotlin/com/github/klee0kai/stone/KotlinWrappersStone.kt +++ /dev/null @@ -1,21 +0,0 @@ -package com.github.klee0kai.stone - -import com.github.klee0kai.stone.annotations.wrappers.WrappersCreator -import com.github.klee0kai.stone.wrappers.creators.ProviderWrapper -import javax.inject.Provider - -@WrappersCreator( - wrappers = [ - Lazy::class - ] -) -open class KotlinWrappersStone : ProviderWrapper { - - override fun wrap(wrapperCl: Class, originalProvider: Provider): Wr? { - return when { - wrapperCl == Lazy::class.java -> lazy { originalProvider.get() } as Wr - else -> null - } - } - -} \ No newline at end of file diff --git a/kotlin_lib/src/main/kotlin/com/github/klee0kai/stone/type/wrappers/WrappersExt.kt b/kotlin_lib/src/main/kotlin/com/github/klee0kai/stone/type/wrappers/WrappersExt.kt deleted file mode 100644 index cb7ab055..00000000 --- a/kotlin_lib/src/main/kotlin/com/github/klee0kai/stone/type/wrappers/WrappersExt.kt +++ /dev/null @@ -1,13 +0,0 @@ -package com.github.klee0kai.stone.type.wrappers - -import com.github.klee0kai.stone.wrappers.Ref -import java.lang.ref.SoftReference -import java.lang.ref.WeakReference -import kotlin.reflect.KProperty - -operator fun Ref.getValue(t: Any?, property: KProperty<*>): T = get() - -operator fun SoftReference.getValue(t: Any?, property: KProperty<*>): T? = get() - -operator fun WeakReference.getValue(t: Any?, property: KProperty<*>): T? = get() - diff --git a/libs.versions.toml b/libs.versions.toml index ce467f70..fdcf4dcd 100644 --- a/libs.versions.toml +++ b/libs.versions.toml @@ -6,16 +6,12 @@ kotlin = "2.2.21" ksp = "2.3.2" agp = "8.12.3" -appcompat = "1.7.1" javax-inject = "1" kotlinx-coroutines = "1.10.1" jetbrain-immutable = "0.3.7" jetbrain-coroutines = "1.10.1" kotlinx-atomicfu = "0.29.0" -auto-service = "1.1.1" -incap = "1.0.0" -javapoet = "1.13.0" kotlinpoet = "2.0.0" junit = "6.0.0" @@ -29,21 +25,12 @@ testing-compile = "0.23.0" jetbrain-immutable = { group = "org.jetbrains.kotlinx", name = "kotlinx-collections-immutable", version.ref = "jetbrain-immutable" } jetbrain-coroutines = { group = "org.jetbrains.kotlinx", name = "kotlinx-coroutines-core", version.ref = "jetbrain-coroutines" } -android-appcompat = { group = "androidx.appcompat", name = "appcompat", version.ref = "appcompat" } - # https://mvnrepository.com/artifact/javax.inject/javax.inject java-inject = { group = "javax.inject", name = "javax.inject", version.ref = "javax-inject" } kotlinx-coroutines = { group = "org.jetbrains.kotlinx", name = "kotlinx-coroutines-core", version.ref = "kotlinx-coroutines" } kotlinx-atomicfu = { group = "org.jetbrains.kotlinx", name = "atomicfu", version.ref = "kotlinx-atomicfu" } -auto-service = { group = "com.google.auto.service", name = "auto-service", version.ref = "auto-service" } - -incap = { group = "net.ltgt.gradle.incap", name = "incap", version.ref = "incap" } -incap-processor = { group = "net.ltgt.gradle.incap", name = "incap-processor", version.ref = "incap" } - -javapoet = { group = "com.squareup", name = "javapoet", version.ref = "javapoet" } - ksp = { group = "com.google.devtools.ksp", name = "symbol-processing-api", version.ref = "ksp" } kotlinpoet = { group = "com.squareup", name = "kotlinpoet", version.ref = "kotlinpoet" } @@ -53,7 +40,7 @@ jupiter-api = { group = "org.junit.jupiter", name = "junit-jupiter-api", version jupiter-engine = { group = "org.junit.jupiter", name = "junit-jupiter-engine", version.ref = "junit" } jupiter-launcher = { group = "org.junit.platform", name = "junit-platform-launcher", version.ref = "junit-launcher" } -testing-compile = { group = "com.google.testing.compile", name = "compile-testing", version.ref = "testing-compile" } +testing-kapt-compile = { group = "com.google.testing.compile", name = "compile-testing", version.ref = "testing-compile" } [bundles] @@ -65,7 +52,6 @@ kotlin = ["jetbrain-coroutines", "jetbrain-immutable"] kotlin-ksp = { id = "com.google.devtools.ksp", version.ref = "ksp" } kotlin-jvm = { id = "org.jetbrains.kotlin.jvm", version.ref = "kotlin" } -kotlin-kapt = { id = "org.jetbrains.kotlin.kapt", version.ref = "kotlin" } kotlin-multiplatform = { id = "org.jetbrains.kotlin.multiplatform", version.ref = "kotlin" } android-library = { id = "com.android.library", version.ref = "agp" } diff --git a/settings.gradle.kts b/settings.gradle.kts index 97513cc2..97fc81db 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -22,18 +22,15 @@ rootProject.name = "Stone" includeBuild("plugin_publish") include("weakref_multiplatform") include("inject_multiplatform") -include(":stone_lib") include(":stone_multiplatform") -include(":stone_processor") -include(":android_lib") -include(":kotlin_lib") include(":wiki_kotlin") include(":tests") include(":tests_ext") include(":tests_kotlin") include(":tests_wraps_kotlin") -include(":tests_compile") +// waiting to k2 support https://github.com/tschuchortdev/kotlin-compile-testing/issues/411 +//include(":tests_compile") include(":test_feature:companies:consulting") include(":test_feature:hr:api") include(":test_feature:hr:impl") diff --git a/stone_ksp/build.gradle.kts b/stone_ksp/build.gradle.kts index 072bc616..101a8b7e 100644 --- a/stone_ksp/build.gradle.kts +++ b/stone_ksp/build.gradle.kts @@ -1,5 +1,6 @@ plugins { alias(libs.plugins.kotlin.multiplatform) + `maven-publish` } group = "com.github.klee0kai.thekey.stone.ksp" @@ -10,14 +11,14 @@ kotlin { jvm() sourceSets { - commonMain.dependencies { - implementation(project(":stone_multiplatform")) - implementation(libs.bundles.kotlin) - implementation(libs.bundles.kotlinpoet) - implementation(libs.ksp) + val commonMain by getting { + dependencies { + implementation(project(":stone_multiplatform")) + implementation(libs.bundles.kotlin) + implementation(libs.bundles.kotlinpoet) + implementation(libs.ksp) + } } } } - - diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/ProcessorProvider.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/StoneProcessorProvider.kt similarity index 89% rename from stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/ProcessorProvider.kt rename to stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/StoneProcessorProvider.kt index 10363a5c..8271c8bf 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/ProcessorProvider.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/StoneProcessorProvider.kt @@ -4,7 +4,7 @@ import com.google.devtools.ksp.processing.SymbolProcessor import com.google.devtools.ksp.processing.SymbolProcessorEnvironment import com.google.devtools.ksp.processing.SymbolProcessorProvider -class ProcessorProvider : SymbolProcessorProvider { +class StoneProcessorProvider : SymbolProcessorProvider { override fun create(environment: SymbolProcessorEnvironment): SymbolProcessor { return Processor( diff --git a/stone_ksp/src/commonMain/resources/META-INF/services/com.google.devtools.ksp.processing.SymbolProcessorProvider b/stone_ksp/src/commonMain/resources/META-INF/services/com.google.devtools.ksp.processing.SymbolProcessorProvider index 517c103f..0745d06f 100644 --- a/stone_ksp/src/commonMain/resources/META-INF/services/com.google.devtools.ksp.processing.SymbolProcessorProvider +++ b/stone_ksp/src/commonMain/resources/META-INF/services/com.google.devtools.ksp.processing.SymbolProcessorProvider @@ -1 +1 @@ -com.github.klee0kai.thekey.stone.ksp.ProcessorProvider \ No newline at end of file +com.github.klee0kai.thekey.stone.ksp.StoneProcessorProvider \ No newline at end of file diff --git a/stone_lib/build.gradle.kts b/stone_lib/build.gradle.kts deleted file mode 100644 index d6f22d23..00000000 --- a/stone_lib/build.gradle.kts +++ /dev/null @@ -1,27 +0,0 @@ -plugins { - `java-library` -// alias(libs.plugins.publish.maven) -// alias(libs.plugins.publish.stone) -} - -group = "com.github.klee0kai.stone" -version = libs.versions.stone.get() - -java { - withSourcesJar() - withJavadocJar() -} - -tasks.javadoc { - exclude("com/github/klee0kai/stone/closed/") -} - -tasks.test { - useJUnitPlatform() -} - -dependencies { - api(libs.java.inject) - - testImplementation(libs.bundles.junit) -} diff --git a/stone_lib/src/main/java/com/github/klee0kai/stone/Stone.java b/stone_lib/src/main/java/com/github/klee0kai/stone/Stone.java deleted file mode 100644 index 29eb1d44..00000000 --- a/stone_lib/src/main/java/com/github/klee0kai/stone/Stone.java +++ /dev/null @@ -1,22 +0,0 @@ -package com.github.klee0kai.stone; - -import java.lang.reflect.InvocationTargetException; - -public class Stone { - - /** - * Create a new Stone component - */ - public static T createComponent(Class component) { - try { - Class gennedClass = Class.forName(component.getCanonicalName() + "StoneComponent"); - return (T) gennedClass.getConstructors()[0].newInstance(); - } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | - InvocationTargetException e) { - throw new RuntimeException(e); - } - } - - - -} diff --git a/stone_lib/src/main/java/com/github/klee0kai/stone/_hidden_/IModule.java b/stone_lib/src/main/java/com/github/klee0kai/stone/_hidden_/IModule.java deleted file mode 100644 index 95201ebd..00000000 --- a/stone_lib/src/main/java/com/github/klee0kai/stone/_hidden_/IModule.java +++ /dev/null @@ -1,60 +0,0 @@ -package com.github.klee0kai.stone._hidden_; - -import com.github.klee0kai.stone._hidden_.types.SwitchCacheParam; - -import java.util.Set; - -/** - * Stone Private class - */ -public interface IModule { - - /** - * Init module - * - * @param ob can be: - * - a factory instance - * - a factory class - */ - boolean __init(Object ob); - - /** - * Init caches from module prototype. - * using in extOf method - */ - void __initCachesFrom(IModule module); - - /** - * Update values of bindInstance variables - * - * @param module related module, source to update - */ - void __updateBindInstancesFrom(IModule module); - - /** - * bind instance objects - * - * @param object - An instance of bindable objects - */ - boolean __bind(Object object); - - /** - * get component's factory - * - * @return - */ - Object __getFactory(); - - /** - * Switch cache type for scope - */ - void __switchRef(Set scopes, SwitchCacheParam param); - - /** - * Clear null refs. - * Useful after gc - */ - void __clearNulls(); - - -} diff --git a/stone_lib/src/main/java/com/github/klee0kai/stone/_hidden_/IModuleFactory.java b/stone_lib/src/main/java/com/github/klee0kai/stone/_hidden_/IModuleFactory.java deleted file mode 100644 index 6fcb4bf4..00000000 --- a/stone_lib/src/main/java/com/github/klee0kai/stone/_hidden_/IModuleFactory.java +++ /dev/null @@ -1,8 +0,0 @@ -package com.github.klee0kai.stone._hidden_; - -/** - * Stone Private class - */ -public interface IModuleFactory { - -} diff --git a/stone_lib/src/main/java/com/github/klee0kai/stone/_hidden_/IPrivateComponent.java b/stone_lib/src/main/java/com/github/klee0kai/stone/_hidden_/IPrivateComponent.java deleted file mode 100644 index 6c1abc51..00000000 --- a/stone_lib/src/main/java/com/github/klee0kai/stone/_hidden_/IPrivateComponent.java +++ /dev/null @@ -1,53 +0,0 @@ -package com.github.klee0kai.stone._hidden_; - - -import com.github.klee0kai.stone._hidden_.types.StoneCallback; - -/** - * Private Stone class - * Each Stone component implement this interface. - */ -public interface IPrivateComponent { - - /** - * init modules. - * - * @param modules can be: - * - a factory instance - * - a factory class - * @deprecated Create init method with module type as argument - */ - void __init(Object... modules); - - /** - * init dependencies - * - * @param dependencies - An instance of dependencies - * @deprecated Create init method with dependency type as argument - */ - void __initDependencies(Object... dependencies); - - /** - * bind instance objects - * - * @param objects - An instance of bindable objects - */ - void __bind(Object... objects); - - /** - * this component extends of other - */ - void __extOf(IPrivateComponent components); - - /** - * hidden module - */ - IModule __hidden(); - - /** - * - * @param callback - */ - void __eachModule(StoneCallback callback); - -} diff --git a/stone_lib/src/main/java/com/github/klee0kai/stone/_hidden_/provide/ProvideBuilder.java b/stone_lib/src/main/java/com/github/klee0kai/stone/_hidden_/provide/ProvideBuilder.java deleted file mode 100644 index a8a834e8..00000000 --- a/stone_lib/src/main/java/com/github/klee0kai/stone/_hidden_/provide/ProvideBuilder.java +++ /dev/null @@ -1,28 +0,0 @@ -package com.github.klee0kai.stone._hidden_.provide; - -import java.util.List; - -public class ProvideBuilder { - - public interface ProvideBody { - void provide(ProvideConsumer consumer); - } - - private ProvideBody provideBody; - - public ProvideBuilder(ProvideBody provideBody) { - this.provideBody = provideBody; - } - - public T first() { - ProvideConsumer consumer = new ProvideConsumer<>(); - provideBody.provide(consumer); - return consumer.getFirst(); - } - - public List all() { - ProvideConsumer consumer = new ProvideConsumer<>(); - provideBody.provide(consumer); - return consumer.getList(); - } -} diff --git a/stone_lib/src/main/java/com/github/klee0kai/stone/_hidden_/provide/ProvideConsumer.java b/stone_lib/src/main/java/com/github/klee0kai/stone/_hidden_/provide/ProvideConsumer.java deleted file mode 100644 index 2288bf2f..00000000 --- a/stone_lib/src/main/java/com/github/klee0kai/stone/_hidden_/provide/ProvideConsumer.java +++ /dev/null @@ -1,33 +0,0 @@ -package com.github.klee0kai.stone._hidden_.provide; - -import com.github.klee0kai.stone._hidden_.types.ListUtils; - -import java.util.Collection; -import java.util.LinkedList; - -public class ProvideConsumer { - - private LinkedList list = new LinkedList<>(); - - public void addAll(Collection collection) { - if (collection != null) { - list.addAll(ListUtils.filter(collection, (i, it) -> it != null)); - } - } - - public void add(T element) { - if (element != null) { - list.add(element); - } - } - - public LinkedList getList() { - return list; - } - - public T getFirst() { - return list.isEmpty() ? null : list.getFirst(); - } - - -} diff --git a/stone_lib/src/main/java/com/github/klee0kai/stone/_hidden_/types/CacheAction.java b/stone_lib/src/main/java/com/github/klee0kai/stone/_hidden_/types/CacheAction.java deleted file mode 100644 index 4f85c0b3..00000000 --- a/stone_lib/src/main/java/com/github/klee0kai/stone/_hidden_/types/CacheAction.java +++ /dev/null @@ -1,70 +0,0 @@ -package com.github.klee0kai.stone._hidden_.types; - -import com.github.klee0kai.stone.annotations.component.SwitchCache; - -/** - * Stone Private class - */ -public class CacheAction { - - public final ActionType type; - public final SwitchCacheParam swCacheParams; - public final Object value; - - public CacheAction(ActionType type, SwitchCacheParam swCacheParams, Object value) { - this.type = type; - this.swCacheParams = swCacheParams; - this.value = value; - } - - - public static CacheAction getValueAction() { - return new CacheAction(ActionType.GET_VALUE, null, null); - } - - public static CacheAction setValueAction(Object value) { - return new CacheAction(ActionType.SET_VALUE, null, value); - } - - public static CacheAction setIfNullValueAction(Object value) { - return new CacheAction(ActionType.SET_IF_NULL, null, value); - } - - public static CacheAction switchCacheValueAction(SwitchCacheParam param) { - return new CacheAction(ActionType.SWITCH_CACHE, param, null); - } - - public static CacheAction switchCacheToDefAction() { - return new CacheAction(ActionType.SWITCH_CACHE, - new SwitchCacheParam(SwitchCache.CacheType.Default, 0, null), - null - ); - } - - public boolean isGetAction() { - return type == ActionType.GET_VALUE; - } - - public boolean isSetAction() { - return type == ActionType.SET_VALUE; - } - - public boolean isSetIfNullAction() { - return type == ActionType.SET_IF_NULL; - } - - public boolean isSwitchCacheAction() { - return type == ActionType.SWITCH_CACHE; - } - - - public enum ActionType { - GET_VALUE, - SET_VALUE, - SET_IF_NULL, - SWITCH_CACHE, - } - -} - - diff --git a/stone_lib/src/main/java/com/github/klee0kai/stone/_hidden_/types/ListUtils.java b/stone_lib/src/main/java/com/github/klee0kai/stone/_hidden_/types/ListUtils.java deleted file mode 100644 index 6a43c8a6..00000000 --- a/stone_lib/src/main/java/com/github/klee0kai/stone/_hidden_/types/ListUtils.java +++ /dev/null @@ -1,154 +0,0 @@ -package com.github.klee0kai.stone._hidden_.types; - -import java.util.*; - -/** - * Stone Private class - */ -public class ListUtils { - - public interface IFormat { - Tout format(Tin it); - } - - public interface ICompare { - int compare(T it1, T it2); - } - - - public interface IFilter { - boolean filter(int inx, T it); - } - - public interface IEq { - boolean eq(T it1, T it2); - } - - public static List format(Iterable list, IFormat format) { - if (list == null) return null; - LinkedList touts = new LinkedList<>(); - if (list != null) for (Tin it : list) { - touts.add(format.format(it)); - } - return touts; - } - - public static boolean contains(List list, IFilter filter) { - int idx = 0; - if (list != null) for (T it : list) { - if (filter.filter(idx++, it)) - return true; - } - return false; - } - - public static T first(Iterable list, IFilter filter) { - int idx = 0; - if (list != null) for (T it : list) { - if (filter == null || filter.filter(idx++, it)) - return it; - } - return null; - } - - public static T first(Iterable list) { - return first(list, null); - } - - public static int indexOf(List list, IFilter filter) { - int idx = 0; - if (list != null) for (T it : list) { - if (filter.filter(idx, it)) - return idx; - else idx++; - } - return -1; - } - - public static Tout firstNotNull(List list, IFormat format) { - if (list != null) for (Tin it : list) { - Tout out = format.format(it); - if (out != null) return out; - } - return null; - } - - public static LinkedList filter(Collection list, IFilter filter) { - if (list == null) return null; - LinkedList touts = new LinkedList<>(); - int idx = 0; - if (list != null) for (T it : list) { - if (filter.filter(idx++, it)) - touts.add(it); - } - return touts; - } - - public static void orderedAdd(List list, T item, ICompare compare) { - ListIterator itr = list.listIterator(); - while (true) { - if (!itr.hasNext()) { - itr.add(item); - return; - } - - T elementInList = itr.next(); - if (compare.compare(elementInList, item) > 0) { - itr.previous(); - itr.add(item); - return; - } - } - } - - public static Set setOf(List list, T... items) { - Set set = new HashSet<>(); - set.addAll(list); - set.addAll(Arrays.asList(items)); - return set; - } - - public static boolean endWith(List parentList, List childList) { - if (parentList == null || childList == null) return false; - if (childList.size() > parentList.size()) return false; - int pSt = parentList.size() - childList.size(); - - Iterator ch = childList.listIterator(); - Iterator p = parentList.listIterator(pSt); - while (ch.hasNext() && p.hasNext()) { - if (!Objects.equals(p.next(), ch.next())) - return false; - } - return !ch.hasNext() && !p.hasNext(); - } - - public static LinkedList removeDoubles(List list, IEq eqHelper) { - if (list == null) return null; - LinkedList out = new LinkedList<>(); - for (T item : list) { - boolean contains = ListUtils.contains(out, (i, it) -> eqHelper.eq(item, it)); - if (!contains) out.add(item); - } - return out; - } - - public static LinkedList removeDoublesRight(List list, IEq eqHelper) { - if (list == null) return null; - LinkedList out = new LinkedList<>(); - for (T item : list) { - out = ListUtils.filter(out, (i, it) -> !eqHelper.eq(item, it)); - out.add(item); - } - return out; - } - - public static boolean listAreSame(List list1, List list2, IEq eqHelper) { - if (list1 == list2) return true; - if ((list2 == null) != (list1 == null)) return false; - if (list1.size() != list2.size()) return false; - for (T it1 : list1) if (!list2.contains(it1)) return false; - return true; - } - - -} diff --git a/stone_lib/src/main/java/com/github/klee0kai/stone/_hidden_/types/MultiKey.java b/stone_lib/src/main/java/com/github/klee0kai/stone/_hidden_/types/MultiKey.java deleted file mode 100644 index 027c1560..00000000 --- a/stone_lib/src/main/java/com/github/klee0kai/stone/_hidden_/types/MultiKey.java +++ /dev/null @@ -1,60 +0,0 @@ -package com.github.klee0kai.stone._hidden_.types; - -import java.util.*; - -/** - * Stone Private class - */ - -public class MultiKey { - - private final List subKeys = new LinkedList<>(); - - public MultiKey(Object... subKeys){ - this.subKeys.addAll(Arrays.asList(subKeys)); - } - - @Override - public int hashCode() { - //AbstractList hash code - int hashCode = 1; - - Object e; - for(Iterator var2 = subKeys.iterator(); var2.hasNext(); - hashCode = 31 * hashCode + (e == null ? 0 : e.hashCode())) { - e = var2.next(); - } - - return hashCode; - } - - @Override - public boolean equals(Object obj) { - //AbstractList equals check - if (obj == this) { - return true; - } else if (!(obj instanceof MultiKey)) { - return false; - } else { - ListIterator e1 = this.subKeys.listIterator(); - ListIterator e2 = ((MultiKey)obj).subKeys.listIterator(); - - while(true) { - if (e1.hasNext() && e2.hasNext()) { - Object o1 = e1.next(); - Object o2 = e2.next(); - if (o1 == null) { - if (o2 == null) { - continue; - } - } else if (o1.equals(o2)) { - continue; - } - - return false; - } - return !e1.hasNext() && !e2.hasNext(); - } - } - } -} diff --git a/stone_lib/src/main/java/com/github/klee0kai/stone/_hidden_/types/NullGet.java b/stone_lib/src/main/java/com/github/klee0kai/stone/_hidden_/types/NullGet.java deleted file mode 100644 index e2d8d12e..00000000 --- a/stone_lib/src/main/java/com/github/klee0kai/stone/_hidden_/types/NullGet.java +++ /dev/null @@ -1,23 +0,0 @@ -package com.github.klee0kai.stone._hidden_.types; - -import java.util.Collections; -import java.util.List; -import java.util.function.Function; - -public class NullGet { - - public static R let(T v, Function uncover) { - return v != null ? uncover.apply(v) : null; - } - - public static List list(T v) { - return v != null ? Collections.singletonList(v) : null; - } - - @SafeVarargs - public static T first(T... values) { - for (T v : values) if (v != null) return v; - return null; - } - -} diff --git a/stone_lib/src/main/java/com/github/klee0kai/stone/_hidden_/types/RefCollection.java b/stone_lib/src/main/java/com/github/klee0kai/stone/_hidden_/types/RefCollection.java deleted file mode 100644 index 61b153c0..00000000 --- a/stone_lib/src/main/java/com/github/klee0kai/stone/_hidden_/types/RefCollection.java +++ /dev/null @@ -1,38 +0,0 @@ -package com.github.klee0kai.stone._hidden_.types; - -import com.github.klee0kai.stone.wrappers.Ref; - -import java.util.Iterator; -import java.util.LinkedList; -import java.util.List; - -public class RefCollection { - - private final List> refs = new LinkedList<>(); - - public void add(Ref ref) { - clearNulls(); - refs.add(ref); - } - - public List> getAllRefs() { - clearNulls(); - return refs; - } - - public List getAll() { - clearNulls(); - return ListUtils.format(refs, Ref::get); - } - - public void clearNulls() { - Iterator> it = refs.iterator(); - while (it.hasNext()) { - Ref ref = it.next(); - if (ref == null || ref.get() == null) - it.remove(); - } - } - - -} diff --git a/stone_lib/src/main/java/com/github/klee0kai/stone/_hidden_/types/StoneCallback.java b/stone_lib/src/main/java/com/github/klee0kai/stone/_hidden_/types/StoneCallback.java deleted file mode 100644 index eb786159..00000000 --- a/stone_lib/src/main/java/com/github/klee0kai/stone/_hidden_/types/StoneCallback.java +++ /dev/null @@ -1,10 +0,0 @@ -package com.github.klee0kai.stone._hidden_.types; - -/** - * Stone Private class - */ -public interface StoneCallback { - - void invoke(T arg); - -} diff --git a/stone_lib/src/main/java/com/github/klee0kai/stone/_hidden_/types/SwitchCacheParam.java b/stone_lib/src/main/java/com/github/klee0kai/stone/_hidden_/types/SwitchCacheParam.java deleted file mode 100644 index c2a7b818..00000000 --- a/stone_lib/src/main/java/com/github/klee0kai/stone/_hidden_/types/SwitchCacheParam.java +++ /dev/null @@ -1,29 +0,0 @@ -package com.github.klee0kai.stone._hidden_.types; - -import com.github.klee0kai.stone._hidden_.types.holders.TimeScheduler; -import com.github.klee0kai.stone.annotations.component.SwitchCache; - -/** - * Stone Private class - */ -public class SwitchCacheParam { - - public final SwitchCache.CacheType cache; - public final long time; - public final TimeScheduler scheduler; - - public SwitchCacheParam(SwitchCache.CacheType cache, long time, TimeScheduler scheduler) { - this.cache = cache; - this.time = time; - this.scheduler = scheduler; - } - - public static SwitchCacheParam toWeak() { - return new SwitchCacheParam(SwitchCache.CacheType.Weak, -1, null); - } - - public static SwitchCacheParam toDef() { - return new SwitchCacheParam(SwitchCache.CacheType.Default, -1, null); - } - -} diff --git a/stone_lib/src/main/java/com/github/klee0kai/stone/_hidden_/types/Threads.java b/stone_lib/src/main/java/com/github/klee0kai/stone/_hidden_/types/Threads.java deleted file mode 100644 index 5e025b18..00000000 --- a/stone_lib/src/main/java/com/github/klee0kai/stone/_hidden_/types/Threads.java +++ /dev/null @@ -1,23 +0,0 @@ -package com.github.klee0kai.stone._hidden_.types; - -import java.util.concurrent.LinkedBlockingDeque; -import java.util.concurrent.ThreadPoolExecutor; -import java.util.concurrent.TimeUnit; - -/** - * Stone Private class - */ -public class Threads { - - public static ThreadPoolExecutor singleThreadExecutor(String name) { - return new ThreadPoolExecutor(0, 1, 0, - TimeUnit.MILLISECONDS, - new LinkedBlockingDeque<>(), runnable -> { - Thread thread = new Thread(runnable); - thread.setDaemon(true); - thread.setName(name); - return thread; - }); - } - -} diff --git a/stone_lib/src/main/java/com/github/klee0kai/stone/_hidden_/types/WeakList.java b/stone_lib/src/main/java/com/github/klee0kai/stone/_hidden_/types/WeakList.java deleted file mode 100644 index 0270c958..00000000 --- a/stone_lib/src/main/java/com/github/klee0kai/stone/_hidden_/types/WeakList.java +++ /dev/null @@ -1,78 +0,0 @@ -package com.github.klee0kai.stone._hidden_.types; - - -import java.lang.ref.Reference; -import java.lang.ref.WeakReference; -import java.util.LinkedList; -import java.util.List; -import java.util.ListIterator; -import java.util.Objects; - -/** - * Stone Private class - */ -public class WeakList { - - private final LinkedList> list = new LinkedList<>(); - - public int size() { - return list.size(); - } - - public boolean isEmpty() { - return list.isEmpty(); - } - - public boolean add(T it) { - clearNulls(); - return list.add(new WeakReference<>(it)); - } - - public void add(int idx, T it) { - clearNulls(); - list.add(idx, new WeakReference<>(it)); - } - - public boolean remove(Object it) { - return clearNulls(it); - } - - public void clear() { - list.clear(); - } - - public boolean clearNulls() { - return clearNulls(null); - } - - public boolean clearNulls(Object ob) { - ListIterator> iter = list.listIterator(); - boolean removed = false; - while (iter.hasNext()) { - Reference it = iter.next(); - if (it.get() == null || Objects.equals(it.get(), ob)) { - iter.remove(); - removed = true; - } - } - return removed; - } - - - public List toList() { - clearNulls(); - LinkedList outList = new LinkedList<>(); - for (Reference it : list) { - outList.add(it.get()); - } - return outList; - } - - public T get(int idx) { - return list.get(idx).get(); - } - - - - -} diff --git a/stone_lib/src/main/java/com/github/klee0kai/stone/_hidden_/types/holders/DataAwait.java b/stone_lib/src/main/java/com/github/klee0kai/stone/_hidden_/types/holders/DataAwait.java deleted file mode 100644 index 32100841..00000000 --- a/stone_lib/src/main/java/com/github/klee0kai/stone/_hidden_/types/holders/DataAwait.java +++ /dev/null @@ -1,57 +0,0 @@ -package com.github.klee0kai.stone._hidden_.types.holders; - -import java.util.LinkedList; - -/** - * Stone Private class - */ -class DataAwait { - - private final LinkedList values = new LinkedList<>(); - private int awaitCount = 0; - - public synchronized T await() { - if (!values.isEmpty()) - return values.poll(); - - try { - awaitCount++; - wait(); - } catch (InterruptedException ignore) { - } finally { - awaitCount--; - } - - return values.poll(); - } - - - public synchronized T await(long millis) { - if (!values.isEmpty()) - return values.poll(); - - try { - awaitCount++; - wait(millis); - } catch (InterruptedException ignore) { - } finally { - awaitCount--; - } - - return values.poll(); - } - - public synchronized boolean trySend(T value) { - this.values.add(value); - if (awaitCount > 0) { - notifyAll(); - return true; - } - return false; - } - - public synchronized void clearAll() { - values.clear(); - } - -} diff --git a/stone_lib/src/main/java/com/github/klee0kai/stone/_hidden_/types/holders/MapItemHolder.java b/stone_lib/src/main/java/com/github/klee0kai/stone/_hidden_/types/holders/MapItemHolder.java deleted file mode 100644 index c465d995..00000000 --- a/stone_lib/src/main/java/com/github/klee0kai/stone/_hidden_/types/holders/MapItemHolder.java +++ /dev/null @@ -1,193 +0,0 @@ -package com.github.klee0kai.stone._hidden_.types.holders; - -import com.github.klee0kai.stone._hidden_.types.ListUtils; -import com.github.klee0kai.stone._hidden_.types.SwitchCacheParam; -import com.github.klee0kai.stone.wrappers.Ref; - -import java.lang.ref.Reference; -import java.util.*; -import java.util.concurrent.atomic.AtomicInteger; - -/** - * Stone Private class - */ -public class MapItemHolder { - - private final StoneRefType defType; - - private StoneRefType curRefType; - - - private final HashMap refMap = new HashMap<>(); - private final AtomicInteger shedTaskCount = new AtomicInteger(0); - - - public MapItemHolder(StoneRefType defType) { - this.defType = defType; - this.curRefType = defType; - } - - public T get(Key key) { - Object holder = refMap.get(key); - if (holder == null) return null; - switch (curRefType) { - case StrongObject: - return (T) holder; - case WeakObject: - case SoftObject: - Reference ref = ((Reference) holder); - return ref != null ? ref.get() : null; - } - return null; - } - - public List getList(Key key) { - Object holder = refMap.get(key); - if (holder == null) return null; - switch (curRefType) { - case ListObject: - return (List) holder; - case ListWeakObject: - case ListSoftObject: - return ListUtils.format((List>) holder, Reference::get); - } - return null; - } - - public void set(Key key, Ref creator, boolean onlyIfNull) { - Object refHolder = refMap.get(key); - if (Objects.equals(curRefType, StoneRefType.StrongObject)) { - if (onlyIfNull && refHolder != null) return; - refMap.put(key, creator.get()); - return; - } - ListUtils.IFormat> formatter = curRefType.formatter(); - if (formatter == null) return; - if (!onlyIfNull) { - //switch ref type case - refMap.put(key, formatter.format(creator.get())); - return; - } - - Reference ref = (Reference) refHolder; - if (ref == null || ref.get() == null) { - refMap.put(key, formatter.format(creator.get())); - } - } - - public void setList(Key key, Ref> creator, boolean onlyIfNull) { - Object refHolder = refMap.get(key); - if (Objects.equals(curRefType, StoneRefType.ListObject)) { - if (!onlyIfNull || refHolder == null) { - refMap.put(key, creator.get()); - return; - } - - // init nulls if needed - List created = null; - List refList = (List) refHolder; - for (int i = 0; i < refList.size(); i++) { - if (refList.get(i) == null) { - if (created == null) created = creator.get(); - refList.set(i, created.get(i)); - } - } - return; - } - ListUtils.IFormat> formatter = curRefType.formatter(); - if (formatter == null) return; - if (!onlyIfNull || refHolder == null) { - //switch ref type case - refMap.put(key, ListUtils.format(creator.get(), formatter)); - return; - } - - List> refList = (List>) refHolder; - List created = null; - for (int i = 0; i < refList.size(); i++) { - if (refList.get(i) == null || refList.get(i).get() == null) { - if (created == null) created = creator.get(); - refList.set(i, formatter.format(created.get(i))); - } - } - } - - - public void setRefType(StoneRefType refType) { - if (curRefType == refType) return; - if (defType.isList()) { - HashMap> listMap = new HashMap<>(); - for (Key key : refMap.keySet()) listMap.put(key, getList(key)); - curRefType = refType.forList(); - for (Key key : listMap.keySet()) setList(key, () -> listMap.get(key), false); - } else { - HashMap itemMap = new HashMap<>(); - for (Key key : refMap.keySet()) itemMap.put(key, get(key)); - curRefType = refType.forSingle(); - for (Key key : itemMap.keySet()) set(key, () -> itemMap.get(key), false); - } - } - - - public void remove(Key key) { - refMap.remove(key); - } - - - public void reset() { - curRefType = defType; - refMap.clear(); - } - - - public void clearNulls() { - Set keys = new HashSet<>(refMap.keySet()); - if (!curRefType.isList()) { - for (Key key : keys) { - if (get(key) == null) { - refMap.remove(key); - } - } - } else { - for (Key key : keys) { - List list = getList(key); - if (!ListUtils.contains(list, (i, it) -> it != null)) { - refMap.remove(key); - } - } - } - - } - - - public void switchCache(SwitchCacheParam args) { - switch (args.cache) { - case Default: - setRefType(defType); - return; - case Reset: - reset(); - return; - case Weak: - setRefType(StoneRefType.WeakObject); - break; - case Soft: - setRefType(StoneRefType.SoftObject); - break; - case Strong: - setRefType(StoneRefType.StrongObject); - break; - } - - if (args.time > 0) { - shedTaskCount.incrementAndGet(); - args.scheduler.schedule(new ScheduleTask(args.time) { - @Override - public void run() { - if (shedTaskCount.decrementAndGet() <= 0) setRefType(defType); - } - }); - } - } - -} diff --git a/stone_lib/src/main/java/com/github/klee0kai/stone/_hidden_/types/holders/ScheduleTask.java b/stone_lib/src/main/java/com/github/klee0kai/stone/_hidden_/types/holders/ScheduleTask.java deleted file mode 100644 index dcd84213..00000000 --- a/stone_lib/src/main/java/com/github/klee0kai/stone/_hidden_/types/holders/ScheduleTask.java +++ /dev/null @@ -1,31 +0,0 @@ -package com.github.klee0kai.stone._hidden_.types.holders; - -/** - * Stone Private class - */ - -abstract class ScheduleTask { - - private final long execTime; - - private boolean cancel = false; - - public ScheduleTask(long delay) { - execTime = System.currentTimeMillis() + delay; - } - - - public abstract void run(); - - public long scheduledExecutionTime() { - return execTime; - } - - public boolean isCancel() { - return cancel; - } - - public void cancel() { - cancel = true; - } -} diff --git a/stone_lib/src/main/java/com/github/klee0kai/stone/_hidden_/types/holders/SingleItemHolder.java b/stone_lib/src/main/java/com/github/klee0kai/stone/_hidden_/types/holders/SingleItemHolder.java deleted file mode 100644 index 16ddeb85..00000000 --- a/stone_lib/src/main/java/com/github/klee0kai/stone/_hidden_/types/holders/SingleItemHolder.java +++ /dev/null @@ -1,163 +0,0 @@ -package com.github.klee0kai.stone._hidden_.types.holders; - -import com.github.klee0kai.stone._hidden_.types.ListUtils; -import com.github.klee0kai.stone._hidden_.types.SwitchCacheParam; -import com.github.klee0kai.stone.wrappers.Ref; - -import java.lang.ref.Reference; -import java.util.List; -import java.util.Objects; -import java.util.concurrent.atomic.AtomicInteger; - -import static com.github.klee0kai.stone._hidden_.types.holders.StoneRefType.ListObject; -import static com.github.klee0kai.stone._hidden_.types.holders.StoneRefType.StrongObject; - -/** - * Stone Private class - */ -public class SingleItemHolder { - - private final StoneRefType defType; - private StoneRefType curRefType; - - private Object refHolder = null; - private final AtomicInteger shedTaskCount = new AtomicInteger(0); - - public SingleItemHolder(StoneRefType defType) { - this.defType = defType; - this.curRefType = defType; - } - - public synchronized T get() { - switch (curRefType) { - case StrongObject: - return (T) refHolder; - case WeakObject: - case SoftObject: - Reference ref = ((Reference) refHolder); - return ref != null ? ref.get() : null; - default: - return null; - } - } - - public synchronized List getList() { - switch (curRefType) { - case ListObject: - return (List) refHolder; - case ListWeakObject: - case ListSoftObject: - return ListUtils.format((List>) refHolder, Reference::get); - default: - return null; - } - } - - - public synchronized void set(Ref creator, boolean onlyIfNull) { - if (Objects.equals(curRefType, StrongObject)) { - if (refHolder != null && onlyIfNull) return; - refHolder = creator.get(); - return; - } - ListUtils.IFormat> formatter = curRefType.formatter(); - if (formatter == null) return; - if (!onlyIfNull) { - //switch ref type case - refHolder = formatter.format(creator.get()); - return; - } - - Reference ref = (Reference) refHolder; - if (ref == null || ref.get() == null) { - refHolder = formatter.format(creator.get()); - } - } - - public synchronized void setList(Ref> creator, boolean onlyIfNull) { - if (Objects.equals(curRefType, ListObject)) { - if (!onlyIfNull || refHolder == null) { - refHolder = creator.get(); - return; - } - - // init nulls if needed - List created = null; - List list = (List) refHolder; - for (int i = 0; i < list.size(); i++) { - if (list.get(i) == null) { - if (created == null) created = creator.get(); - list.set(i, created.get(i)); - } - } - return; - } - ListUtils.IFormat> formatter = curRefType.formatter(); - if (formatter == null) return; - List> refList = (List>) refHolder; - if (refList == null || !onlyIfNull) { - refHolder = ListUtils.format(creator.get(), formatter); - return; - } - - // init nulls if needed - List created = null; - for (int i = 0; i < refList.size(); i++) { - if (refList.get(i) == null || refList.get(i).get() == null) { - if (created == null) created = creator.get(); - refList.set(i, formatter.format(created.get(i))); - } - } - } - - public synchronized void setRefType(StoneRefType refType) { - if (curRefType == refType) return; - if (defType.isList()) { - List ob = getList(); - curRefType = refType.forList(); - setList(() -> ob, false); - } else { - T ob = get(); - curRefType = refType.forSingle(); - set(() -> ob, false); - } - } - - - public synchronized void reset() { - curRefType = defType; - refHolder = null; - } - - - public synchronized void switchCache(SwitchCacheParam args) { - switch (args.cache) { - case Default: - setRefType(defType); - return; - case Reset: - reset(); - return; - case Weak: - setRefType(StoneRefType.WeakObject); - break; - case Soft: - setRefType(StoneRefType.SoftObject); - break; - case Strong: - setRefType(StoneRefType.StrongObject); - break; - } - - if (args.time > 0) { - shedTaskCount.incrementAndGet(); - args.scheduler.schedule(new ScheduleTask(args.time) { - @Override - public void run() { - if (shedTaskCount.decrementAndGet() <= 0) setRefType(defType); - } - }); - } - } - -} diff --git a/stone_lib/src/main/java/com/github/klee0kai/stone/_hidden_/types/holders/StoneRefType.java b/stone_lib/src/main/java/com/github/klee0kai/stone/_hidden_/types/holders/StoneRefType.java deleted file mode 100644 index 3797bae2..00000000 --- a/stone_lib/src/main/java/com/github/klee0kai/stone/_hidden_/types/holders/StoneRefType.java +++ /dev/null @@ -1,72 +0,0 @@ -package com.github.klee0kai.stone._hidden_.types.holders; - -import com.github.klee0kai.stone._hidden_.types.ListUtils; - -import java.lang.ref.Reference; -import java.lang.ref.SoftReference; -import java.lang.ref.WeakReference; - -public enum StoneRefType { - StrongObject, - WeakObject, - SoftObject, - ListObject, - ListWeakObject, - ListSoftObject; - - public boolean isList() { - switch (this) { - case StrongObject: - case WeakObject: - case SoftObject: - return false; - case ListObject: - case ListWeakObject: - case ListSoftObject: - return true; - } - return false; - } - - public StoneRefType forList() { - switch (this) { - case StrongObject: - return ListObject; - case WeakObject: - return ListWeakObject; - case SoftObject: - return ListSoftObject; - default: - return this; - } - } - - - public StoneRefType forSingle() { - switch (this) { - case ListObject: - return StrongObject; - case ListWeakObject: - return WeakObject; - case ListSoftObject: - return SoftObject; - default: - return this; - } - } - - public ListUtils.IFormat> formatter() { - switch (this) { - case WeakObject: - case ListWeakObject: - return WeakReference::new; - case SoftObject: - case ListSoftObject: - return SoftReference::new; - default: - return null; - } - } - - -} diff --git a/stone_lib/src/main/java/com/github/klee0kai/stone/_hidden_/types/holders/TimeHolder.java b/stone_lib/src/main/java/com/github/klee0kai/stone/_hidden_/types/holders/TimeHolder.java deleted file mode 100644 index e5950f01..00000000 --- a/stone_lib/src/main/java/com/github/klee0kai/stone/_hidden_/types/holders/TimeHolder.java +++ /dev/null @@ -1,47 +0,0 @@ -package com.github.klee0kai.stone._hidden_.types.holders; - -import com.github.klee0kai.stone.wrappers.Ref; - -import java.lang.ref.Reference; -import java.lang.ref.SoftReference; - -/** - * Stone Private class - */ -public class TimeHolder implements Ref { - - private final TimeScheduler timer; - private Reference ref = null; - private ScheduleTask scheduleTask = null; - - public TimeHolder(TimeScheduler timer) { - this.timer = timer; - } - - public TimeHolder(TimeScheduler timer, T ref, long holdTime) { - this.timer = timer; - hold(ref, holdTime); - } - - public synchronized T hold(T ob, long holdTime) { - clearRef(); - this.ref = new SoftReference<>(ob); - timer.schedule(scheduleTask = new ScheduleTask(holdTime) { - @Override - public void run() { - clearRef(); - } - }); - return ob; - } - - public synchronized T get() { - return ref != null ? ref.get() : null; - } - - private synchronized void clearRef() { - ref = null; - if (scheduleTask != null) scheduleTask.cancel(); - } - -} diff --git a/stone_lib/src/main/java/com/github/klee0kai/stone/_hidden_/types/holders/TimeScheduler.java b/stone_lib/src/main/java/com/github/klee0kai/stone/_hidden_/types/holders/TimeScheduler.java deleted file mode 100644 index 0261910e..00000000 --- a/stone_lib/src/main/java/com/github/klee0kai/stone/_hidden_/types/holders/TimeScheduler.java +++ /dev/null @@ -1,53 +0,0 @@ -package com.github.klee0kai.stone._hidden_.types.holders; - -import com.github.klee0kai.stone._hidden_.types.ListUtils; -import com.github.klee0kai.stone._hidden_.types.Threads; - -import java.util.LinkedList; -import java.util.concurrent.ThreadPoolExecutor; - -/** - * Stone Private class - */ -public class TimeScheduler { - - private static final int MAX_VALUE_AWAIT_TIME = 30; - private static final int MIN_AWAIT_TIME = 3; - - private final ThreadPoolExecutor secThread = Threads.singleThreadExecutor("stone time scheduler"); - - private final DataAwait timeTaskAwait = new DataAwait<>(); - - public synchronized void schedule(ScheduleTask timerTask) { - timeTaskAwait.trySend(timerTask); - if (secThread.getQueue().isEmpty()) - secThread.submit(() -> { - LinkedList timers = new LinkedList<>(); - - //get first task - ScheduleTask task = timeTaskAwait.await(MAX_VALUE_AWAIT_TIME); - if (task != null) timers.add(task); - - while (timers.size() > 0) { - long now = System.currentTimeMillis(); - while (!timers.isEmpty() && now >= timers.get(0).scheduledExecutionTime()) { - timers.get(0).run(); - timers.removeFirst(); - } - - long awaitTime = !timers.isEmpty() ? - Math.max(timers.get(0).scheduledExecutionTime() - now, MIN_AWAIT_TIME) - : MAX_VALUE_AWAIT_TIME; - - task = timeTaskAwait.await(awaitTime); - if (task != null) - ListUtils.orderedAdd(timers, task, (ob1, ob2) -> - (int) (ob1.scheduledExecutionTime() - ob2.scheduledExecutionTime()) - ); - } - - }); - } - - -} diff --git a/stone_lib/src/main/java/com/github/klee0kai/stone/annotations/component/Component.java b/stone_lib/src/main/java/com/github/klee0kai/stone/annotations/component/Component.java deleted file mode 100644 index da60dc85..00000000 --- a/stone_lib/src/main/java/com/github/klee0kai/stone/annotations/component/Component.java +++ /dev/null @@ -1,246 +0,0 @@ -package com.github.klee0kai.stone.annotations.component; - - -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - - -/** - * The main component of providing dependencies. - * Here we list the modules for creating objects. - * Can be a public class, an abstract class, or an interface. - *

- * Based on this class, the library generates a child class `ClassName`StoneComponent. - * Which can be used directly, or simplified notation. - *

- * `ClassName` DI = Stone.createComponent(`ClassName`.class); - *

- * Modules - *

- * In the DI component, you can declare the modules used. - * To do this, you need to create a class with the @Module annotation, and provide it in the component. - *

- *

{@code
- *    ㅤ@Component
- *     public abstract class AppComponent {
- *         public abstract RepositoriesModule repositories();
- *     }
- *
- *    ㅤ@Module
- *     public interface RepositoriesModule{
- *         // some code
- *     }
- * }
- * Modules can be used directly. - * Also, declared modules in the component are used to resolve dependencies into injection methods, - * as well as into provider methods in the component. - *

- * Providing a module can be replaced by calling an initialization method. - *

{@code
- *
- *    ㅤ@Component
- *     public abstract class AppComponent {
- *         public abstract RepositoriesModule repositories();
- *        ㅤ@Init
- *         void initRepositories(RepositoriesModule repositories);
- *     }
- *
- * }
- *

- * Moreover, this initialization can be performed as when creating a component, - * and when using this component directly. - * In this case, the objects provided in the module will be replaced gradually as they are destroyed in memory. - * - *

- * Dependencies - *

- * All component dependencies are declared in the same way as modules. - * Dependency classes must use the `@Dependencies` annotation - *

{@code
- *    ㅤ@Component
- *     public abstract class FeatureComponent {
- *         public abstract CommonDependencies dependencies();
- *        ㅤ@Init
- *         void initDependencies(CommonDependencies dependencies);
- *     }
- *
- *    ㅤ@Dependencies
- *     public interface CommonDependencies{
- *         // some code
- *     }
- * }
- * Note that dependencies must be initialized before use. - *

- * Dependencies are not cached because - * they are already cached in their component or in their factory, the provider. - * - *

- * Provide objects - *

- * If a component contains at least one module, it can directly provide the dependencies - * of that and its other modules directly. - *

- * In a component, you can declare a provider method of any object that is provided in one of its modules. - * By providing this object, dependencies will be resolved automatically. - *

{@code
- *    ㅤ@Component
- *     public interface CarComponent {
- *
- *         CarModule module();
- *
- *         Car car();
- *     }
- *
- *    ㅤ@Module
- *     public interface CarModule{
- *         Wheel wheel();
- *         Window window();
- *         Bumper bumper();
- *
- *         Car car(Wheel wheel,Window window, Bumper bumper);
- *     }
- * }
- * You can also use additional identifiers to provide a unique object instance. - * The result can be wrapped in declared wrappers, for example, lazy providing, and asynchronous providing. - * - *

- * Bind Instances - *

- * The library allows you to use already known objects in the application as dependencies, as well as provisioning. - *

- * To do this, it is enough to declare the provision of an object with the `@BindInstance` annotation, if the declaration is performed directly in the component. - * Or without this annotation, if it has already been used in the module. - * - *

- * Inject - *

- * DI allows you to provide objects to classes. - * To do this, it is enough to declare an injection method without a return type, - * with only one argument - the injection class. - *

{@code
- *    ㅤ@Component
- *     public interface AppComponent {
- *         void inject(Activity activity);
- *     }
- * }
- * When this method is called, - * all fields and methods with the `@Inject` annotation will be initialized or called. - * - *

- * Initialization - *

- * The component allows you to initialize its dependencies and modules with the @Init annotation. - * - *

- * Extension - *

- * A component can extend another component with the `ExtendOf` annotation. - * When one component is extended by another, both begin to provide child component objects. - *

- * At the same time, object caching is temporarily preserved for the parent component. - * New objects are provided after being cleared from memory, - * or after explicitly using a child component. - * - *

{@code
- *    ㅤ@Component
- *     public interface AppProComponent extends AppComponent {
- *
- *        ㅤ@ExtendOf
- *         void extOf(AppComponent parent);
- *
- *     }
- * }
- *

- * GC collect - *

- * The library allows you to explicitly call garbage collection for cached objects. - * To do this, you need to declare a method without arguments and a return value - * with the @RunGc annotation and one or more scopes. - *

{@code
- *    ㅤ@Component
- *     public interface AppProComponent extends AppComponent {
- *
- *        ㅤ@RunGc
- *        ㅤ@GcAllScope
- *         void gcAll();
- *
- *     }
- * }
- * Caching will be cleared only for those objects - * that are not actually used in the application and are not held by anyone. - * If you hold on to the provided and cached object when calling this method, it will not be destroyed. - *

- * Switch cache - *

- * DI also allows you to change the caching for provided objects. - * To do this, you need to declare a method without arguments and a return value, - * use one of the GC scopes, and additionally use the `@SwitchCache` annotation - */ -@Retention(value = RetentionPolicy.CLASS) -@Target(value = ElementType.TYPE) -public @interface Component { - - /** - * You can use object identifiers. - * Identifiers allow you to provide and cache unique instances of an object. - *

- * To use identifiers, you need to declare object types, - * implementing the `hashCode` and `equals` methods (Kotlin data classes) - * and list them when declaring the component. - *

{@code
-     *    ㅤ@Component(identifiers = [PresenterTag::class])
-     *     interface AppComponent {
-     *         PresentersModule module();
-     *         WelcomePresenter welcomePresenter(PresenterTag tag);
-     *     }
-     *
-     *    ㅤ@Module
-     *     interface PresentersModule {
-     *         WelcomePresenter createWelcomePresenter(PresenterTag tag);
-     *     }
-     * }
- *

- * Identifiers are also used when resolving dependencies. - * For example, if a dependency uses an identifier, - * then when providing an object with dependencies, - * the dependency will be created by a unique identifier. - *

- * If you want to use different identifiers for a provided object and its dependencies, - * use identifiers of different types. - *

- * If no identifier is specified when providing the object, it will be null instead. - */ - Class[] identifiers() default {}; - - - /** - * The library allows you to provide objects in wrappers. - * Various wrappers allow, for example, to perform lazy or asynchronous providingF of objects, - * or not to keep cached objects in DI. - * Wrapping also allows you to render several different objects into one list. - *

- * The library contains a sufficient set of provider wrappers. - * However, if that's not enough, you can implement your own wrapping implementation - * class-based: `ProviderWrapper` and `Wrapper`. - * It is enough to override these classes, and use the `@WrappersCreator` annotation - * to list the wrappers implemented in this class. - *

{@code
-     *    ㅤ@WrappersCreator(wrappers = {CarRef.class})
-     *     public class CarWrapper implements Wrapper {
-     *
-     *        ㅤ@Override
-     *         public  Wr wrap(Class wrapperCl, T original) {
-     *             if (wrapperCl.equals(CarRef.class)) {
-     *                 return (Wr) new CarRef<>(original);
-     *
-     *             }
-     *             return null;
-     *         }
-     *     }
-     * }
- */ - Class[] wrapperProviders() default {}; - -} diff --git a/stone_lib/src/main/java/com/github/klee0kai/stone/annotations/component/ExtendOf.java b/stone_lib/src/main/java/com/github/klee0kai/stone/annotations/component/ExtendOf.java deleted file mode 100644 index 66cfe728..00000000 --- a/stone_lib/src/main/java/com/github/klee0kai/stone/annotations/component/ExtendOf.java +++ /dev/null @@ -1,36 +0,0 @@ -package com.github.klee0kai.stone.annotations.component; - - -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -/** - * A component extends a parent component. - * With the help of such an annotation, an extension method is declared on the parent component. - *
{@code
- *    ㅤ@Component
- *     public interface AppExtendComponent extends AppComponent {
- *
- *         ㅤ@ExtendOf
- *         void extOf(AppComponent parent);
- *
- *     }
- * }
- *

- * For the parent component, all object creation factories are replaced with new ones, - * from the child extending component. - * Components become interconnected, all cleanups, - * caching type changes are performed simultaneously for both components. - *

- * The replacement of generated and provided objects is not done immediately, but gradually. - * As they are cleared from memory. - * Be careful, the new objects provided should extend the functionality of the previous ones, not break the old logic. - * In some cases, interaction between objects of different versions is possible. - */ - -@Retention(value = RetentionPolicy.CLASS) -@Target(value = ElementType.METHOD) -public @interface ExtendOf { -} diff --git a/stone_lib/src/main/java/com/github/klee0kai/stone/annotations/component/GcAllScope.java b/stone_lib/src/main/java/com/github/klee0kai/stone/annotations/component/GcAllScope.java deleted file mode 100644 index 68dd2c00..00000000 --- a/stone_lib/src/main/java/com/github/klee0kai/stone/annotations/component/GcAllScope.java +++ /dev/null @@ -1,20 +0,0 @@ -package com.github.klee0kai.stone.annotations.component; - - -import javax.inject.Scope; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -/** - * A scope that defines all exposed objects in DI. - * Used for garbage collection and caching change methods. - */ - -@GcScopeAnnotation -@Scope -@Retention(value = RetentionPolicy.CLASS) -@Target(value = ElementType.METHOD) -public @interface GcAllScope { -} diff --git a/stone_lib/src/main/java/com/github/klee0kai/stone/annotations/component/GcScopeAnnotation.java b/stone_lib/src/main/java/com/github/klee0kai/stone/annotations/component/GcScopeAnnotation.java deleted file mode 100644 index facd32b2..00000000 --- a/stone_lib/src/main/java/com/github/klee0kai/stone/annotations/component/GcScopeAnnotation.java +++ /dev/null @@ -1,37 +0,0 @@ -package com.github.klee0kai.stone.annotations.component; - - -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -/** - * Annotation announcing new scopes for garbage collection and changing the caching method. - * Announce new scopes in the following way. - * - *

{@code
- *    ㅤ@GcScopeAnnotation
- *    ㅤ@Retention(RUNTIME)
- *    ㅤ@Target(METHOD)
- *     public @interface GcPlanetScope {
- *     }
- * }
- * Instead of this annotation, you can use the more general {@link javax.inject.Scope} - * annotation. - * - *
{@code
- *    ㅤ@Scope
- *    ㅤ@Retention(RUNTIME)
- *   ㅤ@Target(METHOD)
- *     public @interface GcPlanetScope {
- *     }
- * }
- *

- * Not Follow {@link javax.inject.Scope} documentation. - */ - -@Retention(value = RetentionPolicy.CLASS) -@Target(value = ElementType.ANNOTATION_TYPE) -public @interface GcScopeAnnotation { -} diff --git a/stone_lib/src/main/java/com/github/klee0kai/stone/annotations/component/GcSoftScope.java b/stone_lib/src/main/java/com/github/klee0kai/stone/annotations/component/GcSoftScope.java deleted file mode 100644 index de865a22..00000000 --- a/stone_lib/src/main/java/com/github/klee0kai/stone/annotations/component/GcSoftScope.java +++ /dev/null @@ -1,20 +0,0 @@ -package com.github.klee0kai.stone.annotations.component; - - -import javax.inject.Scope; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -/** - * A standard library scope that lists all cached objects using soft references. - * Used for garbage collection and caching change methods. - */ - -@GcScopeAnnotation -@Scope -@Retention(value = RetentionPolicy.CLASS) -@Target(value = ElementType.METHOD) -public @interface GcSoftScope { -} diff --git a/stone_lib/src/main/java/com/github/klee0kai/stone/annotations/component/GcStrongScope.java b/stone_lib/src/main/java/com/github/klee0kai/stone/annotations/component/GcStrongScope.java deleted file mode 100644 index 7801fd6a..00000000 --- a/stone_lib/src/main/java/com/github/klee0kai/stone/annotations/component/GcStrongScope.java +++ /dev/null @@ -1,20 +0,0 @@ -package com.github.klee0kai.stone.annotations.component; - - -import javax.inject.Scope; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -/** - * A standard library scope that enumerates all cacheable objects using strong references. - * Used for garbage collection and caching change methods. - */ - -@GcScopeAnnotation -@Scope -@Retention(value = RetentionPolicy.CLASS) -@Target(value = ElementType.METHOD) -public @interface GcStrongScope { -} diff --git a/stone_lib/src/main/java/com/github/klee0kai/stone/annotations/component/GcWeakScope.java b/stone_lib/src/main/java/com/github/klee0kai/stone/annotations/component/GcWeakScope.java deleted file mode 100644 index 9cc23e47..00000000 --- a/stone_lib/src/main/java/com/github/klee0kai/stone/annotations/component/GcWeakScope.java +++ /dev/null @@ -1,20 +0,0 @@ -package com.github.klee0kai.stone.annotations.component; - - -import javax.inject.Scope; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -/** - * A standard library scope that enumerates all cacheable objects using weak references. - * Used for garbage collection and caching change methods. - */ - -@GcScopeAnnotation -@Scope -@Retention(value = RetentionPolicy.CLASS) -@Target(value = ElementType.METHOD) -public @interface GcWeakScope { -} diff --git a/stone_lib/src/main/java/com/github/klee0kai/stone/annotations/component/Init.java b/stone_lib/src/main/java/com/github/klee0kai/stone/annotations/component/Init.java deleted file mode 100644 index 4ac22963..00000000 --- a/stone_lib/src/main/java/com/github/klee0kai/stone/annotations/component/Init.java +++ /dev/null @@ -1,37 +0,0 @@ -package com.github.klee0kai.stone.annotations.component; - - -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -/** - * Initializing a module or dependency in a component. - *

- * An initialization method is declared in a component that accepts an instance of the module or its class. - * - *

{@code
- *    ㅤ@Component
- *     interface AppComponent() {
- *
- *        ㅤ@Init
- *         void initRepositoriesModule(RepositoriesModule module);
- *
- *        ㅤ@Init
- *         void initRepositoriesModule(Class module);
- *
- *     }
- *
- *  ㅤㅤ@Module
- *     interface RepositoriesModule{
- *         // some code
- *     }
- * }
- *

- * Dependencies can only be initialized on an instance. - */ -@Retention(value = RetentionPolicy.CLASS) -@Target(value = ElementType.METHOD) -public @interface Init { -} diff --git a/stone_lib/src/main/java/com/github/klee0kai/stone/annotations/component/ModuleOriginFactory.java b/stone_lib/src/main/java/com/github/klee0kai/stone/annotations/component/ModuleOriginFactory.java deleted file mode 100644 index 22e3d27b..00000000 --- a/stone_lib/src/main/java/com/github/klee0kai/stone/annotations/component/ModuleOriginFactory.java +++ /dev/null @@ -1,32 +0,0 @@ -package com.github.klee0kai.stone.annotations.component; - - -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -/** - * Provide origin module's factory - * - *

{@code
- *    ㅤ@Component
- *     interface AppComponent() {
- *
- *        ㅤ@ModuleOriginFactory
- *         RepositoriesModule repModuleFactory();
- *
- *     }
- *
- *  ㅤㅤ@Module
- *     interface RepositoriesModule{
- *         // some code
- *     }
- * }
- *

- * Dependencies can only be initialized on an instance. - */ -@Retention(value = RetentionPolicy.CLASS) -@Target(value = ElementType.METHOD) -public @interface ModuleOriginFactory { -} diff --git a/stone_lib/src/main/java/com/github/klee0kai/stone/annotations/component/ProtectInjected.java b/stone_lib/src/main/java/com/github/klee0kai/stone/annotations/component/ProtectInjected.java deleted file mode 100644 index ec342dbd..00000000 --- a/stone_lib/src/main/java/com/github/klee0kai/stone/annotations/component/ProtectInjected.java +++ /dev/null @@ -1,39 +0,0 @@ -package com.github.klee0kai.stone.annotations.component; - - -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -/** - * Protect provided objects from being destroyed by injection. - * When a dependency consumer class is re-created, cached objects may be garbage collected. - * This can be prevented by calling the deletion protection method. - *

{@code
- *   ㅤ@Component
- *     public interface AppComponent {
- *
- *
- *         void inject(Activity activity);
- *
- *        ㅤ@ProtectInjected
- *         void protectInjected();
- *
- *     }
- * }
- *

- * Deletion protection changes object caching to strict. Objects cannot be deleted for some time. - */ - -@Retention(value = RetentionPolicy.CLASS) -@Target(value = ElementType.METHOD) -public @interface ProtectInjected { - - /** - * protect time millis. - * Default protect 5 sec. - */ - long timeMillis() default 5000L; - -} diff --git a/stone_lib/src/main/java/com/github/klee0kai/stone/annotations/component/RunGc.java b/stone_lib/src/main/java/com/github/klee0kai/stone/annotations/component/RunGc.java deleted file mode 100644 index 5ffffdc8..00000000 --- a/stone_lib/src/main/java/com/github/klee0kai/stone/annotations/component/RunGc.java +++ /dev/null @@ -1,45 +0,0 @@ -package com.github.klee0kai.stone.annotations.component; - - -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -/** - * Garbage collection in the selected scope. - * We explicitly clean up unused objects in DI. - *

- * In fact, only those objects that are used and not held by anyone will be deleted. - *

{@code
- *    ㅤ@Component
- *     interface AppComponent {
- *
- *        ㅤ@GcAllScope
- *        ㅤ@AuthScope
- *        ㅤ@RunGc
- *         public void authWeak();
- *
- *     }
- *
- *    ㅤ@GcScopeAnnotation
- *    ㅤ@Retention(value = RetentionPolicy.CLASS)
- *    ㅤ@Target(value = ElementType.METHOD)
- *     public @interface AuthScope {
- *     }
- * }
- *

- * Can be used with multiple garbage collector scopes. - * The final scope will be the intersection of several. - *

- * Caching will be cleared only for those objects that are not actually used in the application and are not held by anyone. - * If you hold on to the provided and cached object when calling this method, it will not be destroyed. - * Objects cached by a Weak link will almost always be collected when not in use. - */ - -@Retention(value = RetentionPolicy.CLASS) -@Target(value = ElementType.METHOD) -public @interface RunGc { - - -} diff --git a/stone_lib/src/main/java/com/github/klee0kai/stone/annotations/component/SwitchCache.java b/stone_lib/src/main/java/com/github/klee0kai/stone/annotations/component/SwitchCache.java deleted file mode 100644 index 242c359d..00000000 --- a/stone_lib/src/main/java/com/github/klee0kai/stone/annotations/component/SwitchCache.java +++ /dev/null @@ -1,77 +0,0 @@ -package com.github.klee0kai.stone.annotations.component; - - -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -/** - * Changing the caching method. - * Changes the caching method for cached objects, temporarily or permanently. - *

- * Allows in this way either to speed up the cleaning of unused objects from memory, or to protect them from deletion. - * - *

{@code
- *    ㅤ@Component
- *     interface AppComponent {
- *
- *        ㅤ@GcAllScope
- *        ㅤ@AuthScope
- *        ㅤ@SwitchCache(cache = SwitchCache.CacheType.Weak)
- *         public void authWeak();
- *
- *     }
- *
- *    ㅤ@GcScopeAnnotation
- *    ㅤ@Retention(value = RetentionPolicy.CLASS)
- *    ㅤ@Target(value = ElementType.METHOD)
- *     public @interface AuthScope {
- *     }
- * }
- *

- * Can be used with multiple garbage collector scopes. - * The final scope will be the intersection of several. - */ - -@Retention(value = RetentionPolicy.CLASS) -@Target(value = ElementType.METHOD) -public @interface SwitchCache { - - enum CacheType { - /** - * restore Default config cache - */ - Default, - /** - * reset cache - */ - Reset, - /** - * switch cache to weak. - */ - Weak, - /** - * switch cache to soft. - */ - Soft, - /** - * switch cache to strong. - */ - Strong - } - - /** - * new cache type for providing items - * - */ - CacheType cache() default CacheType.Default; - - /** - * Switch cache time duration. - * After time cache restored to default. - * - */ - long timeMillis() default -1; - -} diff --git a/stone_lib/src/main/java/com/github/klee0kai/stone/annotations/dependencies/Dependencies.java b/stone_lib/src/main/java/com/github/klee0kai/stone/annotations/dependencies/Dependencies.java deleted file mode 100644 index a7adf067..00000000 --- a/stone_lib/src/main/java/com/github/klee0kai/stone/annotations/dependencies/Dependencies.java +++ /dev/null @@ -1,54 +0,0 @@ -package com.github.klee0kai.stone.annotations.dependencies; - - -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -/** - * Component dependencies are provided through a class annotated with `@Dependencies`. - * When resolving dependencies, the objects declared in this class will also be used. - *

- * The signature of a dependency class is the same as that of a module. - * In this class, you just need to enumerate the provided objects and dependencies as interface methods. - * - *

{@code
- *    ㅤ@Dependencies
- *     public interface CarDependencies {
- *
- *         Wheel wheel();
- *
- *         Bumper bumper();
- *
- *         Window window();
- *
- *     }
- * }
- * Any factory, provider, or DI component can provide these dependencies by simply implementing this interface. - *
{@code
- *    ㅤ@Component
- *     public abstract class AppComponent implements CommonDependencies {
- *         // some code
- *     }
- *
- *    ㅤ@Dependencies
- *     public interface CommonDependencies{
- *         // some code
- *     }
- * }
- *

- * In your component, you simply initialize these dependencies. - *

{@code
- *    ㅤ@Comonent
- *     public abstract class FeatureComponent {
- *         public abstract CommonDependencies dependencies();
- *       ㅤ@Init
- *         void initDependencies(CommonDependencies dependencies);
- *     }
- * }
- */ -@Retention(value = RetentionPolicy.CLASS) -@Target(value = ElementType.TYPE) -public @interface Dependencies { -} diff --git a/stone_lib/src/main/java/com/github/klee0kai/stone/annotations/module/BindInstance.java b/stone_lib/src/main/java/com/github/klee0kai/stone/annotations/module/BindInstance.java deleted file mode 100644 index db2c3b71..00000000 --- a/stone_lib/src/main/java/com/github/klee0kai/stone/annotations/module/BindInstance.java +++ /dev/null @@ -1,85 +0,0 @@ -package com.github.klee0kai.stone.annotations.module; - - -import java.lang.annotation.*; - -/** - * Those objects that are created outside of DI. - * Can be included in DI by using the `@BindInstance` annotation - *

- * Binding can be declared in a module. - * To do this, we define the provider method in the module and the binding method in the module. - *

{@code
- *    ㅤ@Component
- *     public interface SpaceComponent {
- *
- *         SunSystemModule sunSystem();
- *
- *        ㅤ@BindInstance
- *         void bindSun(Sun sun);
- *
- *     }
- *
- *    ㅤ@Module
- *     public interface SunSystemModule {
- *
- *        ㅤ@BindInstance
- *         Sun sun();
- *
- *     }
- * }
- *

- * The method in the module should not contain arguments, but only return an object. - * A method in a component should only receive that object as an argument. - * Further, this object can already be passed in the component directly or through injection. - *

{@code
- *    ㅤ@Component
- *     public interface SpaceComponent {
- *         // some code
- *
- *         // providing method
- *         Sun sun();
- *
- *     }
- * }
- *

- * The second way to declare the use of binding is to declare everything in one method in the DI component. - *

{@code
- *    ㅤ@Component
- *     public interface SpaceComponent {
- *
- *        ㅤ@BindInstance
- *         Sun sun(Sun sun);
- *
- *     }
- * }
- *

- * The method receives and returns the same type. If null is passed as an argument, - * then the value of the binding does not change, but the object is simply provided. - *

- * Binding does not support nulling. Use different caching methods. - */ -@Retention(value = RetentionPolicy.CLASS) -@Target(value = ElementType.METHOD) -@Inherited -public @interface BindInstance { - - enum CacheType { - Weak, - Soft, - Strong - } - - /** - * Object caching type - *

    - *
  • Factory - creation of new objects without caching.
  • - *
  • Weak - caching weak reference objects. - *
  • Soft - caching objects with a soft link. - *
  • Strong - caching objects with a strong link.
  • - *
- *

- */ - BindInstance.CacheType cache() default BindInstance.CacheType.Soft; - -} diff --git a/stone_lib/src/main/java/com/github/klee0kai/stone/annotations/module/Module.java b/stone_lib/src/main/java/com/github/klee0kai/stone/annotations/module/Module.java deleted file mode 100644 index 1d298951..00000000 --- a/stone_lib/src/main/java/com/github/klee0kai/stone/annotations/module/Module.java +++ /dev/null @@ -1,86 +0,0 @@ -package com.github.klee0kai.stone.annotations.module; - - -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -/** - * You can provide new dependencies and objects via modules. - * Stone supports the announcement of new dependencies and providers. - * A module can be a public class, an abstract class, or an interface. - *

- * Each object provision must use one of the 2 annotations. - * `@Provide` - providing a new object - * `@BindInstance` - providing an already known object in the application. - * If you do not specify any of the specified annotations, - * then the `@Provide` annotation is assumed by default. - *

- * So for example in the machine creation module - *

{@code
- *    ㅤ@Module
- *     public abstract class CarModule {
- *
- *        ㅤ@BindInstance
- *         abstract Wheel wheel();
- *
- *        ㅤ@Provide
- *         Bumper bumper(){
- *             return new Bumper();
- *         }
- *
- *         Window window(){
- *             return new Window();
- *         }
- *
- *     }
- * }
- *

- * In our case, the wheel must be defined when initializing the DI component, - * the bumper and the window have the same behavior - each time a new one is created. - *

- * Each element can be cached by specifying how the object is cached. - *

{@code
- *    ㅤ@Module
- *     public abstract class CarModule {
- *
- *        ㅤ@BindInstance(cache = BindInstance.CacheType.Weak)
- *         abstract Wheel wheel();
- *
- *        ㅤ@Provide(cache = Provide.CacheType.Weak)
- *         Bumper bumper(){
- *             return new Bumper();
- *         }
- *
- *        ㅤ@Provide(cache = Provide.CacheType.Soft)
- *         Window window(){
- *             return new Window();
- *         }
- *
- *     }
- *  }
- *

- * And also, you can not explicitly specify the use of the constructor. - * The constructor will be found by the library automatically when using parameters. - * - *

{@code
- *    ㅤ@Module
- *     public interface CarModule {
- *
- *        ㅤ@BindInstance(cache = BindInstance.CacheType.Weak)
- *         Wheel wheel();
- *
- *        ㅤ@Provide(cache = Provide.CacheType.Weak)
- *         Bumper bumper();
- *
- *        ㅤ@Provide(cache = Provide.CacheType.Soft)
- *         Window window();
- *
- *     }
- * }
- */ -@Retention(value = RetentionPolicy.CLASS) -@Target(value = ElementType.TYPE) -public @interface Module { -} diff --git a/stone_lib/src/main/java/com/github/klee0kai/stone/annotations/module/Provide.java b/stone_lib/src/main/java/com/github/klee0kai/stone/annotations/module/Provide.java deleted file mode 100644 index 50b6ecbe..00000000 --- a/stone_lib/src/main/java/com/github/klee0kai/stone/annotations/module/Provide.java +++ /dev/null @@ -1,49 +0,0 @@ -package com.github.klee0kai.stone.annotations.module; - - -import java.lang.annotation.*; - -/** - * Providing objects. - * This annotation marks the methods in the module for providing objects. - *

- * The object can be created each time a new one, or cached. - * To use a specific caching method, you must explicitly select a caching method. - *

    - *
  • Factory - creation of new objects without caching.
  • - *
  • Weak - caching weak reference objects. - * The old object will be provided until the previous object is destroyed. None of the holders will let him go.
  • - *
  • Soft - caching objects with a soft link. - * The old object will be provided until the previous object is destroyed. None of the holders will let him go.
  • - *
  • Strong - caching objects with a strong link.
  • - *
- *

- * Dependencies for an object can be listed using function arguments. - *

{@code
- *   ㅤ@Module
- *     interface CarModule {
- *
- *        ㅤ@Provide(cache = Provide.CacheType.Weak)
- *         Car car(Bumper bumper, Wheel wheel, Window window);
- *
- *     }
- * }
- */ -@Retention(value = RetentionPolicy.CLASS) -@Target(value = ElementType.METHOD) -@Inherited -public @interface Provide { - - enum CacheType { - Factory, - Weak, - Soft, - Strong - } - - /** - * Object caching type - */ - CacheType cache() default CacheType.Factory; - -} diff --git a/stone_lib/src/main/java/com/github/klee0kai/stone/annotations/wrappers/WrappersCreator.java b/stone_lib/src/main/java/com/github/klee0kai/stone/annotations/wrappers/WrappersCreator.java deleted file mode 100644 index 4868bd9a..00000000 --- a/stone_lib/src/main/java/com/github/klee0kai/stone/annotations/wrappers/WrappersCreator.java +++ /dev/null @@ -1,26 +0,0 @@ -package com.github.klee0kai.stone.annotations.wrappers; - - -import com.github.klee0kai.stone.wrappers.creators.CircleWrapper; -import com.github.klee0kai.stone.wrappers.creators.ProviderWrapper; -import com.github.klee0kai.stone.wrappers.creators.Wrapper; - -import java.lang.annotation.*; - -/** - * Provide custom wrappers creator, class - *

- * Should implement {@link Wrapper} or {@link ProviderWrapper} or {@link CircleWrapper} - * and declare custom wrappers in annotation - */ -@Retention(value = RetentionPolicy.CLASS) -@Target(value = ElementType.TYPE) -@Inherited -public @interface WrappersCreator { - - /** - * Custom Wrappers, can be provided - */ - Class[] wrappers() default {}; - -} diff --git a/stone_lib/src/main/java/com/github/klee0kai/stone/lifecycle/StoneLifeCycleListener.java b/stone_lib/src/main/java/com/github/klee0kai/stone/lifecycle/StoneLifeCycleListener.java deleted file mode 100644 index 3905d32b..00000000 --- a/stone_lib/src/main/java/com/github/klee0kai/stone/lifecycle/StoneLifeCycleListener.java +++ /dev/null @@ -1,7 +0,0 @@ -package com.github.klee0kai.stone.lifecycle; - -public interface StoneLifeCycleListener { - - void protectForInjected(long timeMillis); - -} diff --git a/stone_lib/src/main/java/com/github/klee0kai/stone/lifecycle/StoneLifeCycleOwner.java b/stone_lib/src/main/java/com/github/klee0kai/stone/lifecycle/StoneLifeCycleOwner.java deleted file mode 100644 index fca50dee..00000000 --- a/stone_lib/src/main/java/com/github/klee0kai/stone/lifecycle/StoneLifeCycleOwner.java +++ /dev/null @@ -1,55 +0,0 @@ -package com.github.klee0kai.stone.lifecycle; - -/** - * Objects in an application can have a life cycle. - * Various components of your application can be created, destroyed, and re-created. - *

- * At the time of re-creation of the object, it may be necessary to save the objects provided to it from DI. - * In a normal case, this can be done by declaring an additional `@ProtectInjected` method in the component. - * For example: - *

{@code
- *    ㅤ@Component
- *     interface AppComponent {
- *
- *         void inject(Activity activity);
- *
- *        ㅤ@ProtectInjected
- *         void protectInjected(Activity activity);
- *
- *     }
- * }
- *

- * If your class can track life cycle events. - * Then for such classes, you can implement the Stone life cycle, - * which independently calls the deletion protection methods. - *

- * For example, for Android Activity it will look like this. - *

{@code
- *    public static StoneLifeCycleOwner lifeCycleOwner(Lifecycle lifecycle, long protectTimeMillis) {
- *         return listener -> lifecycle.addObserver(new DefaultLifecycleObserver() {
- *            ㅤ@Override
- *             public void onPause(@NonNull @NotNull LifecycleOwner owner1) {
- *                 DefaultLifecycleObserver.super.onPause(owner1);
- *                 listener.protectForInjected(protectTimeMillis);
- *             }
- *         });
- *     }
- * }
- *

- * Further, you simply use your class when injecting itself (if it implements StoneLifeCycleOwner), - * or with an additional StoneLifeCycleOwner argument - * - *

{@code
- *   ㅤ@Component
- *    interface AppComponent {
- *
- *          void inject(Activity activity, StoneLifeCycleOwner owner);
- *
- *    }
- * }
- */ -public interface StoneLifeCycleOwner { - - void subscribe(StoneLifeCycleListener listener); - -} diff --git a/stone_lib/src/main/java/com/github/klee0kai/stone/wrappers/AsyncProvide.java b/stone_lib/src/main/java/com/github/klee0kai/stone/wrappers/AsyncProvide.java deleted file mode 100644 index 7e62aba1..00000000 --- a/stone_lib/src/main/java/com/github/klee0kai/stone/wrappers/AsyncProvide.java +++ /dev/null @@ -1,40 +0,0 @@ -package com.github.klee0kai.stone.wrappers; - -import com.github.klee0kai.stone._hidden_.types.Threads; - -import java.util.concurrent.ExecutorService; - -/** - * Provision of an object with a provider on the 2nd stream. - * By the time of use, the object will already be created on the second thread, - * or lazy initialization will be performed. - *
{@code
- *    ㅤ@Component
- *     interface Component {
- *
- *         AsyncProvide presenter();
- *
- *     }
- * }
- */ -public class AsyncProvide implements Ref { - - private static final ExecutorService secThread = Threads.singleThreadExecutor("stone_async"); - - private T value = null; - private final Ref call; - - public AsyncProvide(Ref call) { - this.call = call; - secThread.submit(() -> { - get(); - }); - } - - @Override - public synchronized T get() { - if (value != null) - return value; - return value = call.get(); - } -} diff --git a/stone_lib/src/main/java/com/github/klee0kai/stone/wrappers/LazyProvide.java b/stone_lib/src/main/java/com/github/klee0kai/stone/wrappers/LazyProvide.java deleted file mode 100644 index 7458d504..00000000 --- a/stone_lib/src/main/java/com/github/klee0kai/stone/wrappers/LazyProvide.java +++ /dev/null @@ -1,30 +0,0 @@ -package com.github.klee0kai.stone.wrappers; - -/** - * Providing an object with lazy providing. - * The object will be provided the first time it is used. - *
{@code
- *    ㅤ@Component
- *     interface Component {
- *
- *         LazyProvide presenter();
- *
- *     }
- * }
- */ -public class LazyProvide implements Ref { - - private T value = null; - private final Ref call; - - public LazyProvide(Ref call) { - this.call = call; - } - - @Override - public T get() { - if (value != null) - return value; - return value = call.get(); - } -} diff --git a/stone_lib/src/main/java/com/github/klee0kai/stone/wrappers/PhantomProvide.java b/stone_lib/src/main/java/com/github/klee0kai/stone/wrappers/PhantomProvide.java deleted file mode 100644 index e8c20979..00000000 --- a/stone_lib/src/main/java/com/github/klee0kai/stone/wrappers/PhantomProvide.java +++ /dev/null @@ -1,31 +0,0 @@ -package com.github.klee0kai.stone.wrappers; - -/** - * Providing an object without any deduction. - * Each time you use this object through a provider, - * the object is not cached in your class, but is taken from the component each time. - *

- * Together with the use of Kotlin delegates, you can fully use the objects from the - * DI component directly without keeping them from being deleted in your class. - *

{@code
- *    ㅤ@Component
- *     interface Component {
- *
- *         PhantomProvide presenter();
- *
- *     }
- * }
- */ -public class PhantomProvide implements Ref { - - private final Ref call; - - public PhantomProvide(Ref call) { - this.call = call; - } - - @Override - public T get() { - return call.get(); - } -} diff --git a/stone_lib/src/main/java/com/github/klee0kai/stone/wrappers/Ref.java b/stone_lib/src/main/java/com/github/klee0kai/stone/wrappers/Ref.java deleted file mode 100644 index 6b033cdc..00000000 --- a/stone_lib/src/main/java/com/github/klee0kai/stone/wrappers/Ref.java +++ /dev/null @@ -1,9 +0,0 @@ -package com.github.klee0kai.stone.wrappers; - -import javax.inject.Provider; - -public interface Ref extends Provider { - - T get(); - -} diff --git a/stone_lib/src/main/java/com/github/klee0kai/stone/wrappers/creators/CircleWrapper.java b/stone_lib/src/main/java/com/github/klee0kai/stone/wrappers/creators/CircleWrapper.java deleted file mode 100644 index 48a20654..00000000 --- a/stone_lib/src/main/java/com/github/klee0kai/stone/wrappers/creators/CircleWrapper.java +++ /dev/null @@ -1,17 +0,0 @@ -package com.github.klee0kai.stone.wrappers.creators; - -public interface CircleWrapper extends ProviderWrapper { - - /** - * UnProvide wrapped object. - * - * @param wrapperCl type of wrapper - * @param objectType original provide object type - * @param wrapper wrapper to unwrap - * @param type of wrapper - * @param type of providing original object - * @return wrapped object provider - */ - T unwrap(Class wrapperCl, Class objectType, Wr wrapper); - -} diff --git a/stone_lib/src/main/java/com/github/klee0kai/stone/wrappers/creators/ProviderWrapper.java b/stone_lib/src/main/java/com/github/klee0kai/stone/wrappers/creators/ProviderWrapper.java deleted file mode 100644 index fb4275f9..00000000 --- a/stone_lib/src/main/java/com/github/klee0kai/stone/wrappers/creators/ProviderWrapper.java +++ /dev/null @@ -1,18 +0,0 @@ -package com.github.klee0kai.stone.wrappers.creators; - -import javax.inject.Provider; - -public interface ProviderWrapper { - - /** - * Provide wrapped object. - * - * @param wrapperCl type of wrapper - * @param originalProvider original object provider - * @param type of wrapper - * @param type of providing original object - * @return wrapped object provider - */ - Wr wrap(Class wrapperCl, Provider originalProvider); - -} diff --git a/stone_lib/src/main/java/com/github/klee0kai/stone/wrappers/creators/Wrapper.java b/stone_lib/src/main/java/com/github/klee0kai/stone/wrappers/creators/Wrapper.java deleted file mode 100644 index 922a6bdd..00000000 --- a/stone_lib/src/main/java/com/github/klee0kai/stone/wrappers/creators/Wrapper.java +++ /dev/null @@ -1,16 +0,0 @@ -package com.github.klee0kai.stone.wrappers.creators; - -public interface Wrapper { - - /** - * Provide wrapped object. - * - * @param wrapperCl type of wrapper - * @param original original object - * @param type of wrapper - * @param type of providing original object - * @return wrapped object provider - */ - Wr wrap(Class wrapperCl, T original); - -} diff --git a/stone_lib/src/test/java/com/github/klee0kai/stone/closed/types/holders/RefCollectionTests.java b/stone_lib/src/test/java/com/github/klee0kai/stone/closed/types/holders/RefCollectionTests.java deleted file mode 100644 index 06c57f83..00000000 --- a/stone_lib/src/test/java/com/github/klee0kai/stone/closed/types/holders/RefCollectionTests.java +++ /dev/null @@ -1,79 +0,0 @@ -package com.github.klee0kai.stone.closed.types.holders; - -import com.github.klee0kai.stone._hidden_.types.RefCollection; -import com.github.klee0kai.stone._hidden_.types.holders.TimeHolder; -import com.github.klee0kai.stone._hidden_.types.holders.TimeScheduler; -import org.junit.jupiter.api.Test; - -import java.util.Arrays; - -import static org.junit.jupiter.api.Assertions.assertEquals; - - -public class RefCollectionTests { - - @Test - public void clearNullTest() throws InterruptedException { - TimeScheduler timeScheduler = new TimeScheduler(); - RefCollection refCollection = new RefCollection(); - - refCollection.add(new TimeHolder(timeScheduler, 10, 40)); - refCollection.add(new TimeHolder(timeScheduler, 12, 100)); - refCollection.add(new TimeHolder(timeScheduler, null, 100)); - refCollection.add(new TimeHolder(timeScheduler, null, 100)); - refCollection.add(new TimeHolder(timeScheduler, 1, 100)); - refCollection.add(new TimeHolder(timeScheduler, 3, 100)); - - - refCollection.clearNulls(); - assertEquals(4, refCollection.getAll().size()); - assertEquals(Arrays.asList(10, 12, 1, 3), refCollection.getAll()); - - Thread.sleep(50); - - assertEquals(3, refCollection.getAll().size()); - assertEquals(Arrays.asList(12, 1, 3), refCollection.getAll()); - - Thread.sleep(60); - - assertEquals(0, refCollection.getAll().size()); - - } - - - @Test - public void clearNullTest2() throws InterruptedException { - TimeScheduler timeScheduler = new TimeScheduler(); - RefCollection refCollection = new RefCollection(); - - refCollection.add(new TimeHolder(timeScheduler, 10, 100)); - refCollection.add(new TimeHolder(timeScheduler, 12, 50)); - refCollection.add(new TimeHolder(timeScheduler, 1, 100)); - refCollection.add(new TimeHolder(timeScheduler, 3, 150)); - refCollection.add(new TimeHolder(timeScheduler, null, 150)); - refCollection.add(new TimeHolder(timeScheduler, null, 150)); - - - refCollection.clearNulls(); - assertEquals(4, refCollection.getAll().size()); - assertEquals(Arrays.asList(10, 12, 1, 3), refCollection.getAll()); - - - Thread.sleep(60); - - assertEquals(3, refCollection.getAll().size()); - assertEquals(Arrays.asList(10, 1, 3), refCollection.getAll()); - - - Thread.sleep(50); - - assertEquals(Arrays.asList(3), refCollection.getAll()); - - - Thread.sleep(50); - - assertEquals(0, refCollection.getAll().size()); - - } - -} diff --git a/stone_lib/src/test/java/com/github/klee0kai/stone/closed/types/holders/TimeHolderTests.java b/stone_lib/src/test/java/com/github/klee0kai/stone/closed/types/holders/TimeHolderTests.java deleted file mode 100644 index 87ffce21..00000000 --- a/stone_lib/src/test/java/com/github/klee0kai/stone/closed/types/holders/TimeHolderTests.java +++ /dev/null @@ -1,37 +0,0 @@ -package com.github.klee0kai.stone.closed.types.holders; - -import com.github.klee0kai.stone._hidden_.types.holders.TimeHolder; -import com.github.klee0kai.stone._hidden_.types.holders.TimeScheduler; -import org.junit.jupiter.api.Test; - -import static org.junit.jupiter.api.Assertions.assertNull; - -public class TimeHolderTests { - - - @Test - public void simpleTest() throws InterruptedException { - TimeScheduler timer = new TimeScheduler(); - - TimeHolder holder1 = new TimeHolder<>(timer, "1", 100); - TimeHolder holder2 = new TimeHolder<>(timer, "2", 100); - TimeHolder holder3 = new TimeHolder<>(timer, "3", 120); - TimeHolder holder4 = new TimeHolder<>(timer, "4", 120); - TimeHolder holder5 = new TimeHolder<>(timer, "5", 150); - TimeHolder holder6 = new TimeHolder<>(timer, "5", 50); - - - Thread.sleep(100); - - assertNull(holder6.get()); - - Thread.sleep(500); - - assertNull(holder1.get()); - assertNull(holder2.get()); - assertNull(holder3.get()); - assertNull(holder4.get()); - assertNull(holder5.get()); - - } -} diff --git a/stone_multiplatform/build.gradle.kts b/stone_multiplatform/build.gradle.kts index 4c3c6777..1f51ba3d 100644 --- a/stone_multiplatform/build.gradle.kts +++ b/stone_multiplatform/build.gradle.kts @@ -1,21 +1,21 @@ plugins { alias(libs.plugins.kotlin.multiplatform) - alias(libs.plugins.android.library) +// alias(libs.plugins.android.library) } group = "com.github.klee0kai.stone" version = libs.versions.stone.get() -android { - namespace = project.group.toString() - compileSdk = 36 - defaultConfig { - minSdk = 21 - } -} +//android { +// namespace = project.group.toString() +// compileSdk = 36 +// defaultConfig { +// minSdk = 21 +// } +//} kotlin { - androidTarget() +// androidTarget() jvm() js(IR) { browser() diff --git a/stone_processor/build.gradle.kts b/stone_processor/build.gradle.kts deleted file mode 100644 index 8401a6ee..00000000 --- a/stone_processor/build.gradle.kts +++ /dev/null @@ -1,31 +0,0 @@ -plugins { - `java-library` -// alias(libs.plugins.publish.maven) -// alias(libs.plugins.publish.stone) -} - -group = "com.github.klee0kai.stone" -version = libs.versions.stone.get() - -java { - withSourcesJar() - withJavadocJar() -} - -tasks.javadoc { - isEnabled = false -} - -dependencies { - implementation(project(":stone_lib")) - - implementation(libs.auto.service) - annotationProcessor(libs.auto.service) - - implementation(libs.incap) - implementation(libs.incap.processor) - - implementation(libs.javapoet) -} - - diff --git a/stone_processor/src/main/java/com/github/klee0kai/stone/AnnotationProcessor.java b/stone_processor/src/main/java/com/github/klee0kai/stone/AnnotationProcessor.java deleted file mode 100644 index 66bd775e..00000000 --- a/stone_processor/src/main/java/com/github/klee0kai/stone/AnnotationProcessor.java +++ /dev/null @@ -1,183 +0,0 @@ -package com.github.klee0kai.stone; - -import com.github.klee0kai.stone._hidden_.types.NullGet; -import com.github.klee0kai.stone.annotations.component.Component; -import com.github.klee0kai.stone.annotations.module.Module; -import com.github.klee0kai.stone.checks.ComponentChecks; -import com.github.klee0kai.stone.checks.ModuleChecks; -import com.github.klee0kai.stone.codegen.*; -import com.github.klee0kai.stone.exceptions.StoneException; -import com.github.klee0kai.stone.helpers.AllClassesHelper; -import com.github.klee0kai.stone.helpers.wrap.WrapHelper; -import com.github.klee0kai.stone.model.ClassDetail; -import com.github.klee0kai.stone.model.ComponentClassDetails; -import com.github.klee0kai.stone.model.annotations.ComponentAnn; -import com.github.klee0kai.stone.utils.StoneNamingUtils; -import com.google.auto.service.AutoService; -import com.squareup.javapoet.ClassName; - -import javax.annotation.processing.*; -import javax.lang.model.element.Element; -import javax.lang.model.element.TypeElement; -import java.util.Set; - -import static com.github.klee0kai.stone.exceptions.ExceptionStringBuilder.createErrorMes; -import static com.github.klee0kai.stone.utils.StoneNamingUtils.genCacheControlInterfaceModuleNameMirror; -import static com.github.klee0kai.stone.utils.StoneNamingUtils.genModuleNameMirror; -import static javax.tools.Diagnostic.Kind.ERROR; - -/** - * Stone's Annotation processor - * Entry Point of the lib. - */ -@AutoService(Processor.class) -@SupportedAnnotationTypes({"*"}) -public class AnnotationProcessor extends AbstractProcessor { - - public static final String PROJECT_URL = "https://github.com/klee0kai/stone"; - public static final AllClassesHelper allClassesHelper = new AllClassesHelper(); - - private static final boolean DEBUG = false; - private static final String DEBUG_PKG = null; - - public static ProcessingEnvironment env; - public static Messager messager; - - @Override - public synchronized void init(ProcessingEnvironment env) { - super.init(env); - AnnotationProcessor.env = env; - messager = env.getMessager(); - allClassesHelper.reInit(env.getElementUtils()); - WrapHelper.reInit(); - } - - @Override - public boolean process(Set set, RoundEnvironment roundEnv) { - for (Element componentEl : roundEnv.getElementsAnnotatedWith(Component.class)) { - try { - ClassDetail component = new ClassDetail((TypeElement) componentEl); - allClassesHelper.deepExtractAdditionalClasses(component); - } catch (StoneException cause) { - if (DEBUG) throw cause; - processingEnv.getMessager().printMessage(ERROR, - createErrorMes() - .cannotCreateComponent(componentEl.getSimpleName().toString()) - .collectCauseMessages(cause) - .build(), - NullGet.first(cause.findErrorElement(), componentEl) - ); - } - } - for (Element moduleEl : roundEnv.getElementsAnnotatedWith(Module.class)) { - try { - ClassDetail module = new ClassDetail((TypeElement) moduleEl); - allClassesHelper.deepExtractAdditionalClasses(module); - } catch (StoneException cause) { - if (DEBUG) throw cause; - processingEnv.getMessager().printMessage(ERROR, - createErrorMes() - .cannotCreateModule(moduleEl.toString()) - .collectCauseMessages(cause) - .build(), - NullGet.first(cause.findErrorElement(), moduleEl) - ); - } - } - - - try { - WrappersSupportBuilder wrappersBuilder = null; - for (Element componentEl : roundEnv.getElementsAnnotatedWith(Component.class)) { - ClassDetail component = new ClassDetail((TypeElement) componentEl); - if (wrappersBuilder == null) { - ClassName wrapperHelper = StoneNamingUtils.typeWrappersClass(component.className); - wrappersBuilder = new WrappersSupportBuilder(wrapperHelper); - } - - for (ClassName wrappedProvider : component.ann(ComponentAnn.class).wrapperProviders) { - ClassDetail wrappedProviderCl = allClassesHelper.findForType(wrappedProvider); - if (wrappedProviderCl != null) wrappersBuilder.addProvideWrapperField(wrappedProviderCl); - } - } - - if (wrappersBuilder != null && !wrappersBuilder.isEmpty()) { - wrappersBuilder.buildAndWrite(); - } - } catch (StoneException cause) { - if (DEBUG) throw cause; - processingEnv.getMessager().printMessage(ERROR, - createErrorMes() - .cannotCreateWrappersHelper() - .collectCauseMessages(cause) - .build(), - cause.findErrorElement() - ); - } - - - for (Element moduleEl : roundEnv.getElementsAnnotatedWith(Module.class)) { - try { - ClassDetail module = new ClassDetail((TypeElement) moduleEl); - if (DEBUG_PKG != null && !((ClassName) module.className).packageName().contains(DEBUG_PKG)) { - System.out.println("module skipped for debug " + module.className); - continue; - } - ModuleChecks.checkModuleClass(module); - - ModuleFactoryBuilder factoryBuilder = ModuleFactoryBuilder.fromModule(module); - factoryBuilder.buildAndWrite(); - - ModuleCacheControlInterfaceBuilder.from(module, genCacheControlInterfaceModuleNameMirror(module.className)) - .buildAndWrite(); - - ModuleBuilder.from(module, genModuleNameMirror(module.className), factoryBuilder.className) - .buildAndWrite(); - } catch (StoneException cause) { - if (DEBUG) throw cause; - processingEnv.getMessager().printMessage(ERROR, - createErrorMes() - .cannotCreateModule(moduleEl.toString()) - .collectCauseMessages(cause) - .build(), - NullGet.first(cause.findErrorElement(), moduleEl) - ); - } - } - - //create components - for (Element componentEl : roundEnv.getElementsAnnotatedWith(Component.class)) { - try { - ComponentClassDetails component = new ComponentClassDetails((TypeElement) componentEl); - if (DEBUG_PKG != null && !((ClassName) component.className).packageName().contains(DEBUG_PKG)) { - System.out.println("Component skipped for debug " + component.className); - continue; - } - - ComponentChecks.checkComponentClass(component); - - ComponentBuilder.from(component) - .buildAndWrite(); - - ModuleCacheControlInterfaceBuilder.from(component.hiddenModule, component.hiddenModuleCacheControlInterface) - .buildAndWrite(); - - ModuleBuilder.from(component.hiddenModule, (ClassName) component.hiddenModule.className, null) - .buildAndWrite(); - - } catch (StoneException cause) { - if (DEBUG) throw cause; - processingEnv.getMessager().printMessage(ERROR, - createErrorMes() - .cannotCreateComponent(componentEl.getSimpleName().toString()) - .collectCauseMessages(cause) - .build(), - NullGet.first(cause.findErrorElement(), componentEl) - ); - } - - } - return false; - } -} - diff --git a/stone_processor/src/main/java/com/github/klee0kai/stone/checks/ComponentChecks.java b/stone_processor/src/main/java/com/github/klee0kai/stone/checks/ComponentChecks.java deleted file mode 100644 index 549e3fec..00000000 --- a/stone_processor/src/main/java/com/github/klee0kai/stone/checks/ComponentChecks.java +++ /dev/null @@ -1,145 +0,0 @@ -package com.github.klee0kai.stone.checks; - -import com.github.klee0kai.stone.annotations.wrappers.WrappersCreator; -import com.github.klee0kai.stone.exceptions.IncorrectSignatureException; -import com.github.klee0kai.stone.model.ClassDetail; -import com.github.klee0kai.stone.model.MethodDetail; -import com.github.klee0kai.stone.model.annotations.*; -import com.squareup.javapoet.ClassName; -import com.squareup.javapoet.TypeName; - -import java.util.HashSet; -import java.util.Objects; -import java.util.Set; - -import static com.github.klee0kai.stone.AnnotationProcessor.allClassesHelper; -import static com.github.klee0kai.stone.checks.WrappersCreatorChecks.checkWrapperClass; -import static com.github.klee0kai.stone.exceptions.ExceptionStringBuilder.createErrorMes; -import static com.github.klee0kai.stone.helpers.wrap.WrapHelper.nonWrappedType; - -public class ComponentChecks { - - public static void checkComponentClass(ClassDetail cl) { - try { - checkClassAnnotations(cl); - checkClassNoHaveFields(cl); - for (MethodDetail m : cl.getAllMethods(false, true)) - checkMethodSignature(m); - checkNoModuleDoubles(cl); - - } catch (Exception e) { - throw new IncorrectSignatureException( - createErrorMes() - .componentsClass(cl.className.toString()) - .hasIncorrectSignature() - .build(), - e, - cl.sourceEl - ); - } - } - - private static void checkClassAnnotations(ClassDetail cl) { - if (cl.hasAnyAnnotation(WrapperCreatorsAnn.class)) { - throw new IncorrectSignatureException( - createErrorMes() - .componentsClass(cl.className.toString()) - .shouldNoHaveAnnotation(WrappersCreator.class.toString()) - .build() - ); - } - - for (ClassName q : cl.ann(ComponentAnn.class).identifiers) { - if (q.isPrimitive()) { - throw new IncorrectSignatureException( - createErrorMes() - .componentsClass(cl.className.toString()) - .shouldNoHaveIdentifiers("primitive") - .build() - ); - } - - if (Objects.equals(q, ClassName.OBJECT)) { - throw new IncorrectSignatureException( - createErrorMes() - .componentsClass(cl.className.toString()) - .shouldNoHaveIdentifiers("Object") - .build() - ); - } - } - - for (ClassName wr : cl.ann(ComponentAnn.class).wrapperProviders) { - ClassDetail wrCl = allClassesHelper.findForType(wr); - checkWrapperClass(wrCl); - } - } - - private static void checkNoModuleDoubles(ClassDetail cl) { - Set moduleProvideMethods = new HashSet<>(); - for (MethodDetail m : cl.getAllMethods(false, true)) { - if (m.hasAnyAnnotation(ModuleOriginFactoryAnn.class)) continue; - ClassDetail module = allClassesHelper.findForType(m.returnType); - if (module != null && module.hasAnyAnnotation(ModuleAnn.class, DependenciesAnn.class)) { - for (MethodDetail moduleMethod : moduleProvideMethods) { - if (moduleMethod.isSameMethod(m)) { - // overrided method - break; - } - if (moduleMethod.returnType.equals(m.returnType)) { - throw new IncorrectSignatureException( - createErrorMes() - .componentsClass(cl.className.toString()) - .shouldHaveOnlySingleModuleMethod(((ClassName) m.returnType).simpleName()) - .build(), - m.sourceEl - ); - } - } - - for (ClassDetail ignored : module.getAllParents(false)) { - if (module.hasAnyAnnotation(ModuleAnn.class, DependenciesAnn.class)) - moduleProvideMethods.add(m); - } - } - } - } - - private static void checkMethodSignature(MethodDetail m) { - IAnnotation prohibitedAnn = m.anyAnnotation(ProvideAnn.class, QualifierAnn.class, SingletonAnn.class); - if (prohibitedAnn != null) { - throw new IncorrectSignatureException( - createErrorMes() - .method(m.methodName) - .shouldNoHaveAnnotation(prohibitedAnn.originalAnn().getSimpleName()) - .build(), - m.sourceEl - ); - } - - Set identifiers = new HashSet<>(allClassesHelper.allIdentifiers); - if (identifiers.contains(nonWrappedType(m.returnType))) { - throw new IncorrectSignatureException( - createErrorMes() - .method(m.methodName) - .shouldNoProvideIdentifierType(m.returnType.toString()) - .build(), - m.sourceEl - ); - } - } - - private static void checkClassNoHaveFields(ClassDetail cl) { - if (!cl.fields.isEmpty()) { - throw new IncorrectSignatureException( - createErrorMes() - .componentsClass(cl.className.toString()) - .shouldNoHaveFields() - .build(), - cl.sourceEl - ); - } - } - - -} diff --git a/stone_processor/src/main/java/com/github/klee0kai/stone/checks/ComponentMethods.java b/stone_processor/src/main/java/com/github/klee0kai/stone/checks/ComponentMethods.java deleted file mode 100644 index a23d3cd2..00000000 --- a/stone_processor/src/main/java/com/github/klee0kai/stone/checks/ComponentMethods.java +++ /dev/null @@ -1,255 +0,0 @@ -package com.github.klee0kai.stone.checks; - -import com.github.klee0kai.stone.annotations.component.*; -import com.github.klee0kai.stone.annotations.module.BindInstance; -import com.github.klee0kai.stone.exceptions.IncorrectSignatureException; -import com.github.klee0kai.stone.exceptions.StoneException; -import com.github.klee0kai.stone.model.ClassDetail; -import com.github.klee0kai.stone.model.FieldDetail; -import com.github.klee0kai.stone.model.MethodDetail; -import com.github.klee0kai.stone.model.annotations.*; -import com.github.klee0kai.stone.utils.ClassNameUtils; -import com.squareup.javapoet.ClassName; -import com.squareup.javapoet.ParameterizedTypeName; -import com.squareup.javapoet.TypeName; - -import java.util.Objects; - -import static com.github.klee0kai.stone.AnnotationProcessor.allClassesHelper; -import static com.github.klee0kai.stone.exceptions.ExceptionStringBuilder.createErrorMes; - -public class ComponentMethods { - - public static boolean isModuleFactoryProvideMethod(MethodDetail m) { - boolean isProvideMethod = isProvideMethodSimple(m); - ClassDetail providingClDetails = isProvideMethod ? allClassesHelper.findForType(m.returnType) : null; - if (providingClDetails == null - || !providingClDetails.hasAnnotations(ModuleAnn.class) - || !m.hasAnyAnnotation(ModuleOriginFactoryAnn.class)) - return false; - if (!m.args.isEmpty() || !m.hasOnlyAnnotations(false, false, ModuleOriginFactoryAnn.class)) { - throw new IncorrectSignatureException( - createErrorMes() - .method(m.methodName) - .add("should no have arguments and annotations.") - .build(), - m.sourceEl - ); - } - ModuleChecks.checkModuleClass(providingClDetails); - checkMethodBusy(m); - - return m.args.isEmpty(); - } - - public static boolean isModuleProvideMethod(MethodDetail m) { - boolean isProvideMethod = isProvideMethod(m); - ClassDetail providingClDetails = isProvideMethod ? allClassesHelper.findForType(m.returnType) : null; - if (providingClDetails == null - || !providingClDetails.hasAnnotations(ModuleAnn.class) - || m.hasAnyAnnotation(ModuleOriginFactoryAnn.class)) - return false; - if (!m.args.isEmpty() || !m.annotations.isEmpty()) { - throw new IncorrectSignatureException( - createErrorMes() - .method(m.methodName) - .add("should no have arguments and annotations.") - .build(), - m.sourceEl - ); - } - ModuleChecks.checkModuleClass(providingClDetails); - checkMethodBusy(m); - - return m.args.isEmpty(); - } - - public static boolean isDepsProvide(MethodDetail m) { - boolean isProvideMethod = isProvideMethod(m); - ClassDetail providingClDetails = isProvideMethod ? allClassesHelper.findForType(m.returnType) : null; - if (providingClDetails == null || !providingClDetails.hasAnnotations(DependenciesAnn.class)) - return false; - if (!m.args.isEmpty() || !m.annotations.isEmpty()) { - throw new IncorrectSignatureException( - createErrorMes() - .method(m.methodName) - .add("should no have arguments and annotations.") - .build(), - m.sourceEl - ); - } - DependencyChecks.checkDependencyClass(providingClDetails); - checkMethodBusy(m); - - return true; - } - - - public static boolean isObjectProvideMethod(MethodDetail m) { - return isProvideMethod(m) && !isModuleProvideMethod(m) && !isDepsProvide(m); - } - - public static boolean isInitModuleMethod(MethodDetail m) { - if (!m.hasAnyAnnotation(InitAnn.class)) return false; - StoneException ex = new IncorrectSignatureException( - createErrorMes() - .componentInitMethodSignatureIncorrect(m.methodName, Init.class.getSimpleName()) - .build(), - m.sourceEl - ); - if (!m.hasOnlyAnnotations(false, false, InitAnn.class) - || m.args.isEmpty() || m.returnType != TypeName.VOID) - throw ex; - - for (FieldDetail f : m.args) { - ClassDetail initClass = allClassesHelper.findForType(f.type); - if (Objects.equals(ClassNameUtils.rawTypeOf(f.type), ClassName.get(Class.class))) { - TypeName variant = ((ParameterizedTypeName) f.type).typeArguments.get(0); - variant = ClassNameUtils.rawTypeOf(variant); - ClassDetail clVariant = allClassesHelper.findForType(variant); - if (clVariant != null) initClass = clVariant; - } - if (initClass == null) return false; - if (!initClass.hasAnyAnnotation(ModuleAnn.class, DependenciesAnn.class)) - throw ex; - } - checkMethodBusy(m); - - return true; - } - - public static boolean isExtOfMethod(ClassDetail cl, MethodDetail m) { - if (!m.hasAnyAnnotation(ExtOfAnn.class)) return false; - StoneException ex = new IncorrectSignatureException( - createErrorMes() - .componentExtOfMethodSignatureIncorrect(m.methodName, ExtendOf.class.getSimpleName()) - .build(), - m.sourceEl - ); - if (!m.hasOnlyAnnotations(false, false, ExtOfAnn.class) - || m.args.size() != 1 || m.returnType != TypeName.VOID) - throw ex; - ClassDetail parentComponent = allClassesHelper.findForType(m.args.get(0).type); - if (!parentComponent.hasOnlyAnnotations(ComponentAnn.class) || !cl.isExtOf(parentComponent.className)) - throw ex; - checkMethodBusy(m); - - return true; - } - - public static BindInstanceType isBindInstanceMethod(MethodDetail m) { - if (!m.hasAnyAnnotation(BindInstanceAnn.class)) return null; - StoneException ex = new IncorrectSignatureException( - createErrorMes() - .componentBindInstanceMethodSignatureIncorrect(m.methodName, BindInstance.class.getSimpleName()) - .build(), - m.sourceEl - ); - if (!m.hasOnlyAnnotations(true, true, BindInstanceAnn.class)) throw ex; - if (m.args.size() != 1) throw ex; - TypeName typeName = m.args.get(0).type; - if (typeName.isPrimitive() || typeName.isBoxedPrimitive()) throw ex; - checkMethodBusy(m); - - if (m.returnType == TypeName.VOID) - return BindInstanceType.BindInstance; - if (Objects.equals(m.returnType, m.args.get(0).type)) - return BindInstanceType.BindInstanceAndProvide; - - throw ex; - } - - public static boolean isGcMethod(MethodDetail m) { - if (!m.hasAnyAnnotation(RunGcAnn.class)) return false; - if (m.gcScopeAnnotations.isEmpty() || !m.hasOnlyAnnotations(true, false, RunGcAnn.class)) - throw new IncorrectSignatureException( - createErrorMes() - .componentGCMethodSignatureIncorrect(m.methodName, RunGc.class.getSimpleName()) - .build(), - m.sourceEl - ); - if (m.returnType != TypeName.VOID) { - throw new IncorrectSignatureException( - createErrorMes() - .componentGCMethodSignatureIncorrect(m.methodName, RunGc.class.getSimpleName()) - .build(), - m.sourceEl - ); - } - checkMethodBusy(m); - - return true; - } - - public static boolean isSwitchCacheMethod(MethodDetail m) { - if (!m.hasAnyAnnotation(SwitchCacheAnn.class)) return false; - StoneException ex = new IncorrectSignatureException( - createErrorMes() - .componentSwitchCacheMethodSignatureIncorrect(m.methodName, SwitchCache.class.getSimpleName()) - .build(), - m.sourceEl - ); - if (!m.hasOnlyAnnotations(true, false, SwitchCacheAnn.class)) throw ex; - if (m.returnType != TypeName.VOID || !m.args.isEmpty()) throw ex; - checkMethodBusy(m); - - return true; - } - - public static boolean isInjectMethod(MethodDetail m) { - if (!m.hasOnlyAnnotations(false, false) || m.returnType != TypeName.VOID || m.args.size() < 1) - return false; - checkMethodBusy(m); - - return true; - } - - public static boolean isProtectInjectedMethod(MethodDetail m) { - if (!m.hasAnyAnnotation(ProtectInjectedAnn.class)) return false; - StoneException ex = new IncorrectSignatureException( - createErrorMes() - .componentProtectInjectedMethodSignatureIncorrect(m.methodName, ProtectInjected.class.getSimpleName()) - .build(), - m.sourceEl - ); - if (!m.hasOnlyAnnotations(false, false, ProtectInjectedAnn.class) || m.returnType != TypeName.VOID || m.args.size() != 1) - throw ex; - TypeName typeName = m.args.get(0).type; - if (typeName.isPrimitive() || typeName.isBoxedPrimitive()) - throw ex; - checkMethodBusy(m); - - return true; - } - - private static boolean isProvideMethod(MethodDetail m) { - return !m.returnType.isPrimitive() - && !m.returnType.isBoxedPrimitive() - && m.returnType != TypeName.VOID - && m.hasOnlyAnnotations(false, true); - } - - private static boolean isProvideMethodSimple(MethodDetail m) { - return !m.returnType.isPrimitive() - && !m.returnType.isBoxedPrimitive() - && m.returnType != TypeName.VOID; - } - - - private static void checkMethodBusy(MethodDetail m) { - if (allClassesHelper.iComponentClassDetails.findMethod(m, true) != null) { - throw new IncorrectSignatureException( - createErrorMes() - .componentMethodNameBusy(m.methodName) - .build(), - m.sourceEl - ); - } - } - - public enum BindInstanceType { - BindInstance, - BindInstanceAndProvide - } - -} diff --git a/stone_processor/src/main/java/com/github/klee0kai/stone/checks/DependencyChecks.java b/stone_processor/src/main/java/com/github/klee0kai/stone/checks/DependencyChecks.java deleted file mode 100644 index 928daf34..00000000 --- a/stone_processor/src/main/java/com/github/klee0kai/stone/checks/DependencyChecks.java +++ /dev/null @@ -1,45 +0,0 @@ -package com.github.klee0kai.stone.checks; - -import com.github.klee0kai.stone.exceptions.IncorrectSignatureException; -import com.github.klee0kai.stone.model.ClassDetail; -import com.github.klee0kai.stone.model.MethodDetail; -import com.github.klee0kai.stone.model.annotations.ComponentAnn; -import com.github.klee0kai.stone.model.annotations.IAnnotation; -import com.github.klee0kai.stone.model.annotations.ModuleAnn; -import com.github.klee0kai.stone.model.annotations.WrapperCreatorsAnn; - -import static com.github.klee0kai.stone.exceptions.ExceptionStringBuilder.createErrorMes; - -public class DependencyChecks { - - public static void checkDependencyClass(ClassDetail cl) { - try { - checkClassAnnotations(cl); - ModuleChecks.checkModuleClassNoHaveFields(cl); - for (MethodDetail m : cl.getAllMethods(false, true)) - ModuleChecks.checkModuleMethodSignature(m); - } catch (Exception cause) { - throw new IncorrectSignatureException( - createErrorMes() - .dependencyClass(cl.className.toString()) - .hasIncorrectSignature() - .build(), - cause, - cl.sourceEl); - } - } - - private static void checkClassAnnotations(ClassDetail cl) { - IAnnotation prohibitedAnn = cl.anyAnnotation(ComponentAnn.class, ModuleAnn.class, WrapperCreatorsAnn.class); - if (prohibitedAnn != null) { - throw new IncorrectSignatureException( - createErrorMes() - .dependencyClass(cl.className.toString()) - .shouldNoHaveAnnotation(prohibitedAnn.originalAnn().getSimpleName()) - .build(), - cl.sourceEl - ); - } - } - -} diff --git a/stone_processor/src/main/java/com/github/klee0kai/stone/checks/ModuleChecks.java b/stone_processor/src/main/java/com/github/klee0kai/stone/checks/ModuleChecks.java deleted file mode 100644 index 94879c16..00000000 --- a/stone_processor/src/main/java/com/github/klee0kai/stone/checks/ModuleChecks.java +++ /dev/null @@ -1,98 +0,0 @@ -package com.github.klee0kai.stone.checks; - -import com.github.klee0kai.stone.exceptions.IncorrectSignatureException; -import com.github.klee0kai.stone.model.ClassDetail; -import com.github.klee0kai.stone.model.FieldDetail; -import com.github.klee0kai.stone.model.MethodDetail; -import com.github.klee0kai.stone.model.annotations.*; -import com.squareup.javapoet.TypeName; - -import java.util.Objects; - -import static com.github.klee0kai.stone.exceptions.ExceptionStringBuilder.createErrorMes; - -public class ModuleChecks { - - public static void checkModuleClass(ClassDetail cl) { - try { - checkClassAnnotations(cl); - checkModuleClassNoHaveFields(cl); - for (MethodDetail m : cl.getAllMethods(false, true)) - checkModuleMethodSignature(m); - } catch (Exception e) { - throw new IncorrectSignatureException( - createErrorMes() - .moduleClass(cl.className.toString()) - .hasIncorrectSignature() - .build(), - e, - cl.sourceEl - ); - } - } - - - public static void checkModuleMethodSignature(MethodDetail m) { - IAnnotation prohibitedAnn = m.anyAnnotation(InjectAnn.class, ProtectInjectedAnn.class, SwitchCacheAnn.class, QualifierAnn.class, SingletonAnn.class); - if (prohibitedAnn != null) { - throw new IncorrectSignatureException( - createErrorMes() - .method(m.methodName) - .shouldNoHaveAnnotation(prohibitedAnn.originalAnn().getSimpleName()) - .build(), - m.sourceEl - ); - } - - if (!Objects.equals(m.methodName, "")) { - if (Objects.equals(m.returnType, TypeName.VOID) || m.returnType.isPrimitive()) { - throw new IncorrectSignatureException( - createErrorMes() - .method(m.methodName) - .shouldProvideNonPrimitiveObjects() - .build(), - m.sourceEl - ); - } - - for (FieldDetail f : m.args) - if (f.type.isPrimitive()) { - throw new IncorrectSignatureException( - createErrorMes() - .method(m.methodName) - .shouldNoHavePrimitiveArguments() - .build(), - m.sourceEl - ); - } - } - } - - public static void checkModuleClassNoHaveFields(ClassDetail cl) { - if (!cl.fields.isEmpty()) { - throw new IncorrectSignatureException( - createErrorMes() - .dependencyClass(cl.className.toString()) - .shouldNoHaveFields() - .build(), - cl.sourceEl - ); - } - } - - - private static void checkClassAnnotations(ClassDetail cl) { - IAnnotation prohibitedAnn = cl.anyAnnotation(ComponentAnn.class, DependenciesAnn.class, WrapperCreatorsAnn.class); - if (prohibitedAnn != null) { - throw new IncorrectSignatureException( - createErrorMes() - .moduleClass(cl.className.toString()) - .shouldNoHaveAnnotation(prohibitedAnn.originalAnn().getSimpleName()) - .build(), - cl.sourceEl - ); - } - } - - -} diff --git a/stone_processor/src/main/java/com/github/klee0kai/stone/checks/ModuleMethods.java b/stone_processor/src/main/java/com/github/klee0kai/stone/checks/ModuleMethods.java deleted file mode 100644 index c660b4cb..00000000 --- a/stone_processor/src/main/java/com/github/klee0kai/stone/checks/ModuleMethods.java +++ /dev/null @@ -1,81 +0,0 @@ -package com.github.klee0kai.stone.checks; - -import com.github.klee0kai.stone.annotations.module.BindInstance; -import com.github.klee0kai.stone.annotations.module.Provide; -import com.github.klee0kai.stone.exceptions.IncorrectSignatureException; -import com.github.klee0kai.stone.model.MethodDetail; -import com.github.klee0kai.stone.model.annotations.BindInstanceAnn; -import com.github.klee0kai.stone.model.annotations.ProvideAnn; - -import static com.github.klee0kai.stone.exceptions.ExceptionStringBuilder.createErrorMes; -import static com.github.klee0kai.stone.helpers.wrap.WrapHelper.isAsyncProvider; -import static com.github.klee0kai.stone.helpers.wrap.WrapHelper.isNonCachingWrapper; - -public class ModuleMethods { - - public static boolean isProvideCachedObject(MethodDetail m) { - if (m.hasAnyAnnotation(BindInstanceAnn.class)) return false; - if (isProvideFactoryObject(m)) return false; - - if (!m.hasOnlyAnnotations(true, true, ProvideAnn.class)) { - throw new IncorrectSignatureException( - createErrorMes() - .method(m.methodName) - .hasIncorrectSignature() - .shouldHaveOnlyAnnotations(Provide.class.getSimpleName()) - .build(), - m.sourceEl - ); - } - - if (isNonCachingWrapper(m.returnType) || isAsyncProvider(m.returnType)) { - throw new IncorrectSignatureException( - createErrorMes() - .method(m.methodName) - .hasIncorrectSignature() - .add(" Not support caching, because return type wrapper is non support caching.\n") - .add(" You Should use annotation @Provide(cache = Provide.CacheType.Factory)") - .build(), - m.sourceEl - ); - } - - return true; - } - - public static boolean isProvideFactoryObject(MethodDetail m) { - if (m.hasAnyAnnotation(BindInstanceAnn.class)) return false; - ProvideAnn ann = m.ann(ProvideAnn.class); - if (ann != null && ann.cacheType != Provide.CacheType.Factory) return false; - - if (!m.hasOnlyAnnotations(true, true, ProvideAnn.class)) { - throw new IncorrectSignatureException( - createErrorMes() - .method(m.methodName) - .hasIncorrectSignature() - .shouldHaveOnlyAnnotations(Provide.class.getSimpleName()) - .build(), - m.sourceEl - ); - } - - return true; - } - - public static boolean isBindInstanceMethod(MethodDetail m) { - if (!m.hasAnyAnnotation(BindInstanceAnn.class)) return false; - - if (!m.hasOnlyAnnotations(true, true, BindInstanceAnn.class)) { - throw new IncorrectSignatureException( - createErrorMes() - .method(m.methodName) - .hasIncorrectSignature() - .shouldHaveOnlyAnnotations(BindInstance.class.getSimpleName()) - .build(), - m.sourceEl - ); - } - return true; - } - -} diff --git a/stone_processor/src/main/java/com/github/klee0kai/stone/checks/WrappersCreatorChecks.java b/stone_processor/src/main/java/com/github/klee0kai/stone/checks/WrappersCreatorChecks.java deleted file mode 100644 index eca56804..00000000 --- a/stone_processor/src/main/java/com/github/klee0kai/stone/checks/WrappersCreatorChecks.java +++ /dev/null @@ -1,109 +0,0 @@ -package com.github.klee0kai.stone.checks; - -import com.github.klee0kai.stone.annotations.wrappers.WrappersCreator; -import com.github.klee0kai.stone.exceptions.IncorrectSignatureException; -import com.github.klee0kai.stone.model.ClassDetail; -import com.github.klee0kai.stone.model.MethodDetail; -import com.github.klee0kai.stone.model.annotations.*; -import com.github.klee0kai.stone.wrappers.creators.CircleWrapper; -import com.github.klee0kai.stone.wrappers.creators.ProviderWrapper; -import com.github.klee0kai.stone.wrappers.creators.Wrapper; -import com.squareup.javapoet.ClassName; -import com.squareup.javapoet.TypeName; - -import javax.lang.model.element.Modifier; -import javax.lang.model.element.TypeElement; -import java.util.Arrays; -import java.util.Collections; -import java.util.List; - -import static com.github.klee0kai.stone.AnnotationProcessor.allClassesHelper; -import static com.github.klee0kai.stone.exceptions.ExceptionStringBuilder.createErrorMes; - -public class WrappersCreatorChecks { - - public static final ClassName wrapperClName = ClassName.get(Wrapper.class); - public static final ClassName asyncWrapperClName = ClassName.get(ProviderWrapper.class); - public static final ClassName circleWrapperClName = ClassName.get(CircleWrapper.class); - - public static void checkWrapperClass(ClassDetail cl) { - try { - checkClassAnnotations(cl); - checkWrapperCreatorInterface(cl); - checkWrappingClasses(cl); - } catch (Exception cause) { - throw new IncorrectSignatureException( - createErrorMes() - .wrappersCreatorClass(cl.className.toString()) - .hasIncorrectSignature() - .build(), - cause, - cl.sourceEl); - } - } - - private static void checkClassAnnotations(ClassDetail cl) { - IAnnotation prohibitedAnn = cl.anyAnnotation(ComponentAnn.class, DependenciesAnn.class, ModuleAnn.class); - if (prohibitedAnn != null) { - throw new IncorrectSignatureException( - createErrorMes() - .wrappersCreatorClass(cl.className.toString()) - .shouldNoHaveAnnotation(prohibitedAnn.originalAnn().getSimpleName()) - .build(), - cl.sourceEl - ); - } - } - - private static void checkWrapperCreatorInterface(ClassDetail cl) { - List wrapperClasses = Arrays.asList(wrapperClName, asyncWrapperClName, circleWrapperClName); - boolean isWrapperCreatorInterface = false; - for (ClassDetail p : cl.getAllParents(false)) - if (wrapperClasses.contains(p.className)) { - isWrapperCreatorInterface = true; - break; - } - if (!isWrapperCreatorInterface || !cl.hasAnyAnnotation(WrapperCreatorsAnn.class)) { - throw new IncorrectSignatureException( - createErrorMes() - .wrappersCreatorClass(cl.className.toString()) - .shouldImplementInterface(wrapperClName.canonicalName()) - .add(" or ") - .shouldImplementInterface(asyncWrapperClName.canonicalName()) - .add(" or ") - .shouldImplementInterface(circleWrapperClName.canonicalName()) - .add(" and ") - .shouldHaveAnnotations(WrappersCreator.class.getSimpleName()) - .build(), - cl.sourceEl - ); - } - - - MethodDetail m = cl.findMethod(MethodDetail.constructorMethod(Collections.emptyList()), false); - if (m == null || !m.modifiers.contains(Modifier.PUBLIC)) { - throw new IncorrectSignatureException( - createErrorMes() - .wrappersCreatorClass(cl.className.toString()) - .shouldHaveConstructorWithoutArgs() - .build(), - m != null ? m.sourceEl : cl.sourceEl - ); - } - } - - private static void checkWrappingClasses(ClassDetail cl) { - for (ClassName wrClName : cl.ann(WrapperCreatorsAnn.class).wrappers) { - TypeElement wrCl = allClassesHelper.typeElementFor(wrClName); - if (wrCl.getTypeParameters().size() != 1) { - throw new IncorrectSignatureException( - createErrorMes() - .wrapperShouldBeGenericType1(cl.className) - .build(), - cl.sourceEl - ); - } - } - } - -} diff --git a/stone_processor/src/main/java/com/github/klee0kai/stone/codegen/ComponentBuilder.java b/stone_processor/src/main/java/com/github/klee0kai/stone/codegen/ComponentBuilder.java deleted file mode 100644 index 16f0995d..00000000 --- a/stone_processor/src/main/java/com/github/klee0kai/stone/codegen/ComponentBuilder.java +++ /dev/null @@ -1,810 +0,0 @@ -package com.github.klee0kai.stone.codegen; - -import com.github.klee0kai.stone._hidden_.IModule; -import com.github.klee0kai.stone._hidden_.IPrivateComponent; -import com.github.klee0kai.stone._hidden_.types.*; -import com.github.klee0kai.stone._hidden_.types.holders.TimeHolder; -import com.github.klee0kai.stone._hidden_.types.holders.TimeScheduler; -import com.github.klee0kai.stone.annotations.component.SwitchCache; -import com.github.klee0kai.stone.checks.ComponentMethods; -import com.github.klee0kai.stone.exceptions.IncorrectSignatureException; -import com.github.klee0kai.stone.exceptions.ObjectNotProvidedException; -import com.github.klee0kai.stone.helpers.SetFieldHelper; -import com.github.klee0kai.stone.helpers.codebuilder.SmartCode; -import com.github.klee0kai.stone.helpers.invokecall.InvokeCall; -import com.github.klee0kai.stone.helpers.wrap.WrapHelper; -import com.github.klee0kai.stone.model.ClassDetail; -import com.github.klee0kai.stone.model.ComponentClassDetails; -import com.github.klee0kai.stone.model.FieldDetail; -import com.github.klee0kai.stone.model.MethodDetail; -import com.github.klee0kai.stone.model.annotations.*; -import com.github.klee0kai.stone.utils.ClassNameUtils; -import com.github.klee0kai.stone.utils.CodeFileUtil; -import com.github.klee0kai.stone.utils.ImplementMethodCollection; -import com.squareup.javapoet.*; - -import javax.lang.model.element.Modifier; -import java.util.*; - -import static com.github.klee0kai.stone.AnnotationProcessor.allClassesHelper; -import static com.github.klee0kai.stone.checks.ComponentMethods.BindInstanceType.BindInstanceAndProvide; -import static com.github.klee0kai.stone.checks.ComponentMethods.*; -import static com.github.klee0kai.stone.exceptions.ExceptionStringBuilder.createErrorMes; -import static com.github.klee0kai.stone.helpers.wrap.WrapHelper.*; -import static com.github.klee0kai.stone.utils.StoneNamingUtils.*; -import static com.squareup.javapoet.MethodSpec.methodBuilder; - -public class ComponentBuilder { - - public final ComponentClassDetails orComponentCl; - - public ClassName className; - - public static final String refCollectionGlFieldName = "__refCollection"; - public static final String scheduleGlFieldName = "__scheduler"; - public static final String hiddenModuleFieldName = "__hiddenModule"; - public static final String relatedComponentsListFieldName = "__related"; - public static final String protectRecursiveField = "__protectRecursive"; - public static final String hiddenModuleMethodName = "__hidden"; - public static final String eachModuleMethodName = "__eachModule"; - public static final String initMethodName = "__init"; - public static final String initDepsMethodName = "__initDependencies"; - public static final String bindMethodName = "__bind"; - public static final String extOfMethodName = "__extOf"; - - public final Set interfaces = new HashSet<>(); - - // ---------------------- common fields and method ---------------------------------- - public final HashMap fields = new HashMap<>(); - public final List iComponentMethods = new LinkedList<>(); - - public final CodeBlock.Builder initDepsCode = CodeBlock.builder(); - public final CodeBlock.Builder bindModuleCode = CodeBlock.builder(); - - - // ---------------------- provide fields and method ---------------------------------- - public final HashMap modulesFields = new HashMap<>(); - public final HashMap modulesFieldsTypes = new HashMap<>(); - public final HashMap depsFields = new HashMap<>(); - public final HashMap modulesMethods = new HashMap<>(); - public final HashMap moduleFactoriesMethods = new HashMap<>(); - public final HashMap depsMethods = new HashMap<>(); - public final List provideObjMethods = new LinkedList<>(); - public final List bindInstanceMethods = new LinkedList<>(); - public final List injectMethods = new LinkedList<>(); - public final List protectInjectedMethods = new LinkedList<>(); - public final List gcMethods = new LinkedList<>(); - public final List switchRefMethods = new LinkedList<>(); - - - private final ImplementMethodCollection collectRuns = new ImplementMethodCollection(); - - public static ComponentBuilder from(ComponentClassDetails component) { - ComponentBuilder componentBuilder = new ComponentBuilder(component, genComponentNameMirror(component.className)) - .implementIComponentMethods(); - - for (MethodDetail m : component.getAllMethods(false, false, "")) { - if (allClassesHelper.iComponentClassDetails.findMethod(m, false) != null) - continue; - - if (isModuleProvideMethod(m)) { - ClassDetail moduleCl = allClassesHelper.findForType(m.returnType); - componentBuilder.provideModuleMethod(m.methodName, moduleCl); - } else if (isModuleFactoryProvideMethod(m)) { - ClassDetail moduleCl = allClassesHelper.findForType(m.returnType); - componentBuilder.provideModuleFactoryMethod(m, moduleCl); - } else if (isDepsProvide(m)) { - ClassDetail dependencyCl = allClassesHelper.findForType(m.returnType); - componentBuilder.provideDependenciesMethod(m.methodName, dependencyCl); - } else if (isInitModuleMethod(m)) { - componentBuilder.initMethod(m); - } else if (isExtOfMethod(component, m)) { - componentBuilder.extOfMethod(m); - } else if (isObjectProvideMethod(m)) { - componentBuilder.provideObjMethod(m); - } else if (isBindInstanceMethod(m) != null) { - componentBuilder.bindInstanceMethod(m); - } else if (isGcMethod(m)) { - componentBuilder.gcMethod(m); - } else if (isSwitchCacheMethod(m)) { - componentBuilder.switchRefMethod(m); - } else if (isInjectMethod(m)) { - componentBuilder.injectMethod(m); - } else if (isProtectInjectedMethod(m)) { - componentBuilder.protectInjectedMethod(m); - } else if (component.isInterfaceClass() || m.isAbstract()) { - //non implemented method - throw new IncorrectSignatureException( - createErrorMes() - .methodPurposeNonDetected(m.methodName, component.className.toString()) - .build(), - m.sourceEl - ); - } - } - return componentBuilder; - } - - public ComponentBuilder(ComponentClassDetails orComponentCl, ClassName className) { - this.orComponentCl = orComponentCl; - this.className = className; - } - - /** - * Call first - */ - public ComponentBuilder implementIComponentMethods() { - interfaces.add(ClassName.get(IPrivateComponent.class)); - ParameterizedTypeName weakComponentsList = ParameterizedTypeName.get(WeakList.class, IPrivateComponent.class); - fields.put( - relatedComponentsListFieldName, - FieldSpec.builder(weakComponentsList, relatedComponentsListFieldName, Modifier.FINAL, Modifier.PRIVATE) - .initializer("new $T()", weakComponentsList) - ); - fields.put( - protectRecursiveField, - FieldSpec.builder(boolean.class, protectRecursiveField, Modifier.PRIVATE) - .initializer("false") - ); - - // IComponent - initMethod(true); - initDependenciesMethod(true); - bindMethod(true); - extOfMethod(true); - // IPrivateComponent - hiddenModuleMethod(true); - eachModuleMethod(true); - return this; - } - - public ComponentBuilder timeHolderFields() { - if (!fields.containsKey(scheduleGlFieldName)) - fields.put( - scheduleGlFieldName, - FieldSpec.builder(TimeScheduler.class, scheduleGlFieldName, Modifier.PRIVATE, Modifier.FINAL) - .initializer("new $T()", TimeScheduler.class) - ); - if (!fields.containsKey(refCollectionGlFieldName)) - fields.put( - refCollectionGlFieldName, - FieldSpec.builder(RefCollection.class, refCollectionGlFieldName, Modifier.PRIVATE, Modifier.FINAL) - .initializer("new $T()", RefCollection.class) - ); - return this; - } - - public ComponentBuilder initMethod(boolean override) { - MethodSpec.Builder builder = methodBuilder(initMethodName) - .addModifiers(Modifier.SYNCHRONIZED, Modifier.PUBLIC) - .addParameter(Object[].class, "modules") - .varargs(true); - if (override) builder.addAnnotation(Override.class); - - iComponentMethods.add(builder); - - collectRuns.execute(() -> - builder.beginControlFlow("for (Object m : modules)") - .beginControlFlow("if (m instanceof $T)", IPrivateComponent.class) - .addComment("related component") - .addStatement("$L.add( ( $T ) m)", relatedComponentsListFieldName, IPrivateComponent.class) - .endControlFlow() - .beginControlFlow("else") - .addComment("init modules") - .addStatement( - "$L( (module) -> { module.$L(m); } )", - eachModuleMethodName, ModuleBuilder.initMethodName - ) - .endControlFlow() - .endControlFlow()); - return this; - } - - public ComponentBuilder initDependenciesMethod(boolean override) { - MethodSpec.Builder builder = methodBuilder(initDepsMethodName) - .addModifiers(Modifier.SYNCHRONIZED, Modifier.PUBLIC) - .addParameter(Object[].class, "deps") - .varargs(true); - if (override) builder.addAnnotation(Override.class); - - iComponentMethods.add(builder); - - collectRuns.execute(() -> - builder.beginControlFlow("for (Object m : deps)") - .addComment("init dependencies") - .addCode(initDepsCode.build()) - .endControlFlow()); - return this; - } - - public ComponentBuilder initMethod(MethodDetail m) { - MethodSpec.Builder builder = methodBuilder(m.methodName) - .addAnnotation(Override.class) - .addModifiers(Modifier.PUBLIC); - for (FieldDetail arg : m.args) { - builder.addParameter(ParameterSpec.builder(arg.type, arg.name).build()); - ClassDetail iniCl = allClassesHelper.findForType(arg.type); - if (Objects.equals(ClassNameUtils.rawTypeOf(arg.type), ClassName.get(Class.class))) { - TypeName initType = ((ParameterizedTypeName) arg.type).typeArguments.get(0); - iniCl = allClassesHelper.findForType(initType); - } - - if (iniCl.hasAnyAnnotation(ModuleAnn.class, ComponentAnn.class)) { - builder.addStatement("$L( $L )", initMethodName, arg.name); - } else if (iniCl.hasAnyAnnotation(DependenciesAnn.class)) { - builder.addStatement("$L( $L )", initDepsMethodName, arg.name); - } else { - throw new IncorrectSignatureException( - createErrorMes() - .method(m.methodName) - .hasIncorrectSignature() - .build(), - m.sourceEl - ); - } - } - - iComponentMethods.add(builder); - return this; - } - - public ComponentBuilder bindMethod(boolean override) { - MethodSpec.Builder builder = methodBuilder(bindMethodName) - .addModifiers(Modifier.SYNCHRONIZED, Modifier.PUBLIC) - .addParameter(Object[].class, "objects") - .varargs(true); - if (override) builder.addAnnotation(Override.class); - - iComponentMethods.add(builder); - collectRuns.execute(() -> - builder.beginControlFlow("for (Object ob : objects)") - .addStatement( - "$L( (m) -> { m.$L(ob); } )", - eachModuleMethodName, ModuleBuilder.bindMethodName - ) - .endControlFlow()); - return this; - } - - public ComponentBuilder extOfMethod(boolean override) { - MethodSpec.Builder builder = methodBuilder(extOfMethodName) - .addModifiers(Modifier.PUBLIC) - .addParameter(IPrivateComponent.class, "c"); - if (override) builder.addAnnotation(Override.class); - - for (ClassDetail proto : orComponentCl.getAllParents(false)) { - if (Objects.equals(proto.className, ClassName.get(IPrivateComponent.class))) continue; - List provideModuleMethods = ListUtils.filter(proto.getAllMethods(false, false), - (i, m) -> ComponentMethods.isModuleProvideMethod(m) - ); - List bindInstanceAndProvideMethods = ListUtils.filter(proto.getAllMethods(false, false), - (i, m) -> ComponentMethods.isBindInstanceMethod(m) == BindInstanceAndProvide - ); - - if (provideModuleMethods.isEmpty() && bindInstanceAndProvideMethods.isEmpty()) continue; - - List provideFactories = ListUtils.format(provideModuleMethods, (it) -> it.methodName + "()"); - - builder.beginControlFlow("if (c instanceof $T)", proto.className) - .addStatement("$T protoComponent = ($T) c", proto.className, proto.className); - for (MethodDetail provideModule : provideModuleMethods) { - builder.addStatement( - "$L().$L( ($T) protoComponent.$L())", - provideModule.methodName, - ModuleBuilder.initCachesFromMethodName, - IModule.class, provideModule.methodName - ); - } - for (MethodDetail bindInstMethod : bindInstanceAndProvideMethods) { - builder.addStatement( - "$L(protoComponent.$L(null))", - bindInstMethod.methodName, bindInstMethod.methodName - ); - } - - builder.addStatement("c.$L( $L ) ", ModuleBuilder.initMethodName, String.join(",", provideFactories)) - .addStatement("c.$L(this)", ModuleBuilder.initMethodName) - .endControlFlow(); - - builder.beginControlFlow("if (c instanceof $T)", IPrivateComponent.class) - .addStatement( - "$L.add( ($T) c)", - relatedComponentsListFieldName, IPrivateComponent.class) - .endControlFlow(); - - } - - iComponentMethods.add(builder); - return this; - } - - public ComponentBuilder extOfMethod(MethodDetail m) { - MethodSpec.Builder builder = methodBuilder(m.methodName) - .addAnnotation(Override.class) - .addModifiers(Modifier.PUBLIC); - for (FieldDetail arg : m.args) { - builder.addParameter(ParameterSpec.builder(arg.type, arg.name).build()); - builder.addStatement("$L( ($T) $L )", extOfMethodName, IPrivateComponent.class, arg.name); - } - - iComponentMethods.add(builder); - return this; - } - - public ComponentBuilder hiddenModuleMethod(boolean override) { - ClassName tpName = genHiddenModuleNameMirror(orComponentCl.className); - MethodSpec.Builder builder = methodBuilder(hiddenModuleMethodName) - .addModifiers(Modifier.PUBLIC) - .returns(tpName) - .addStatement("return this.$L", hiddenModuleFieldName); - if (override) builder.addAnnotation(Override.class); - - String name = hiddenModuleFieldName; - modulesFields.put(name, FieldSpec.builder(tpName, name, Modifier.PRIVATE, Modifier.FINAL) - .initializer(CodeBlock.of("new $T()", tpName))); - - bindModuleCode.addStatement("this.$L.bind(ob)", name); - iComponentMethods.add(builder); - return this; - } - - public ComponentBuilder eachModuleMethod(boolean override) { - ParameterizedTypeName callbackType = ParameterizedTypeName.get(StoneCallback.class, IModule.class); - MethodSpec.Builder builder = methodBuilder(eachModuleMethodName) - .addModifiers(Modifier.PUBLIC) - .addParameter(ParameterSpec.builder(callbackType, "callback").build()) - .addStatement("if ($L) return ", protectRecursiveField) - .addStatement("$L = true", protectRecursiveField); - if (override) builder.addAnnotation(Override.class); - - collectRuns.execute(() -> { - for (String module : modulesMethods.keySet()) { - builder.addStatement("callback.invoke($L())", module); - } - if (modulesFields.containsKey(hiddenModuleFieldName)) { - builder.addStatement("callback.invoke($L())", hiddenModuleMethodName); - } - - builder.beginControlFlow("for ($T c: $L.toList())", IPrivateComponent.class, relatedComponentsListFieldName) - .addStatement("c.$L(callback)", eachModuleMethodName) - .endControlFlow(); - - - builder.addStatement("$L = false", protectRecursiveField); - }); - iComponentMethods.add(builder); - return this; - } - - public ComponentBuilder provideModuleMethod(String name, ClassDetail module) { - ClassName moduleStoneMirror = genModuleNameMirror(module.className); - modulesFields.put(name, FieldSpec.builder(moduleStoneMirror, name, Modifier.PRIVATE).initializer("new $T()", moduleStoneMirror)); - modulesFieldsTypes.putIfAbsent(module.className, name); - MethodSpec.Builder builder = methodBuilder(name) - .addAnnotation(Override.class) - .addModifiers(Modifier.PUBLIC) - .returns(moduleStoneMirror) - .addStatement("return this.$L", name); - modulesMethods.put(name, builder); - - bindModuleCode.addStatement("this.$L.bind(ob)", name); - return this; - } - - public ComponentBuilder provideModuleFactoryMethod(MethodDetail m, ClassDetail module) { - collectRuns.execute(createErrorMes().errorImplementMethod(m.methodName).build(), m.sourceEl, () -> { - if (!modulesFieldsTypes.containsKey(module.className)) { - throw new ObjectNotProvidedException( - createErrorMes() - .errorProvideModuleFactoryRequiredIn( - m.returnType.toString(), - orComponentCl.className.toString(), - m.methodName - ) - .build(), - m.sourceEl - ); - } - - MethodSpec.Builder builder = methodBuilder(m.methodName) - .addAnnotation(Override.class) - .addModifiers(Modifier.PUBLIC) - .returns(module.className) - .addStatement("return ( ( $T ) this.$L.$L() )", m.returnType, - modulesFieldsTypes.get(module.className), - ModuleBuilder.getFactoryMethodName - ); - moduleFactoriesMethods.put(m.methodName, builder); - - }); - return this; - } - - public ComponentBuilder provideDependenciesMethod(String name, ClassDetail depsModule) { - depsFields.put(name, FieldSpec.builder(depsModule.className, name, Modifier.PRIVATE)); - MethodSpec.Builder builder = methodBuilder(name) - .addAnnotation(Override.class) - .addModifiers(Modifier.PUBLIC) - .returns(depsModule.className) - .addStatement("return this.$L", name); - depsMethods.put(name, builder); - - initDepsCode.addStatement("if (m instanceof $T) this.$L = ( $T ) m", depsModule.className, name, depsModule.className); - return this; - } - - public ComponentBuilder provideObjMethod(MethodDetail m) { - MethodSpec.Builder builder = methodBuilder(m.methodName) - .addAnnotation(Override.class) - .addModifiers(Modifier.PUBLIC) - .returns(m.returnType); - - for (FieldDetail arg : m.args) - builder.addParameter(ParameterSpec.builder(arg.type, arg.name).build()); - List qFields = ListUtils.filter(m.args, - (inx, it) -> (it.type instanceof ClassName) && orComponentCl.identifiers.contains(it.type) - ); - - provideObjMethods.add(builder); - collectRuns.execute(createErrorMes().errorImplementMethod(m.methodName).build(), m.sourceEl, () -> { - SmartCode smartCode = orComponentCl.modulesGraph.codeProvideType(null, m.returnType, m.qualifierAnns); - if (smartCode == null) { - throw new ObjectNotProvidedException( - createErrorMes() - .errorProvideTypeRequiredIn( - m.returnType.toString(), - orComponentCl.className.toString(), - m.methodName - ) - .build(), - m.sourceEl - ); - } - builder.addCode("return ") - .addCode(smartCode.build(qFields)) - .addCode(";\n"); - }); - return this; - } - - - public ComponentBuilder bindInstanceMethod(MethodDetail m) { - List qFields = ListUtils.filter(m.args, - (inx, it) -> (it.type instanceof ClassName) && orComponentCl.identifiers.contains(it.type) - ); - FieldDetail setValueArg = ListUtils.first(m.args, (inx, it) -> !(it.type instanceof ClassName) || !orComponentCl.identifiers.contains(it.type)); - TypeName nonWrappedBindType = nonWrappedType(setValueArg.type); - boolean isProvideMethod = Objects.equals(nonWrappedType(m.returnType), nonWrappedBindType); - String hidingProvideName = isProvideMethod ? m.methodName : null; - - MethodSpec.Builder builder = methodBuilder(m.methodName) - .addAnnotation(Override.class) - .addModifiers(Modifier.PUBLIC) - .returns(m.returnType); - if (m.args != null) for (FieldDetail p : m.args) { - builder.addParameter(p.type, p.name); - } - - collectRuns.execute(createErrorMes().errorImplementMethod(m.methodName).build(), m.sourceEl, () -> { - // bind object declared in module - InvokeCall cacheControlInvoke = orComponentCl.modulesGraph.invokeControlCacheForType(hidingProvideName, nonWrappedBindType, m.qualifierAnns); - - boolean isListCache = isList(cacheControlInvoke.rawReturnType()); - TypeName cacheControlType = isListCache ? ParameterizedTypeName.get(ClassName.get(List.class), nonWrappedBindType) : nonWrappedBindType; - builder.addStatement(cacheControlInvoke.invokeCode(qFields, - typeName -> SmartCode.builder() - .add(CodeBlock.of("$T.setValueAction(", CacheAction.class)) - .add(transform( - SmartCode.of(setValueArg.name).providingType(setValueArg.type), - cacheControlType - )) - .add(")") - .build(null) - )) - .addStatement( - "$L( (module) -> { module.$L( $L() ); } )", - eachModuleMethodName, - ModuleBuilder.updateBindInstancesFrom, - cacheControlInvoke.bestSequence().get(0).methodName - ); - - - if (isProvideMethod) { - builder.addCode("return ") - .addCode( - transform( - orComponentCl.modulesGraph.codeProvideType(hidingProvideName, nonWrappedBindType, m.qualifierAnns), - m.returnType - ).build(m.args)) - .addCode(";\n"); - } - - }); - bindInstanceMethods.add(builder); - return this; - } - - public ComponentBuilder injectMethod(MethodDetail m) { - MethodSpec.Builder builder = methodBuilder(m.methodName) - .addAnnotation(Override.class) - .addModifiers(Modifier.PUBLIC) - .returns(void.class); - for (FieldDetail arg : m.args) - builder.addParameter(ParameterSpec.builder(arg.type, arg.name).build()); - List qFields = ListUtils.filter(m.args, (inx, it) -> (it.type instanceof ClassName) && orComponentCl.identifiers.contains(it.type)); - FieldDetail lifeCycleOwner = ListUtils.first(m.args, (inx, it) -> allClassesHelper.isLifeCycleOwner(it.type)); - - - List injectableFields = ListUtils.filter(m.args, (inx, it) -> (it.type instanceof ClassName) && !orComponentCl.identifiers.contains(it.type)); - - if (injectableFields.isEmpty()) { - throw new IncorrectSignatureException( - createErrorMes() - .method(m.methodName) - .shouldHaveInjectableClassAsParameter() - .build(), - m.sourceEl); - } - - if (lifeCycleOwner != null) timeHolderFields(); - - injectMethods.add(builder); - collectRuns.execute(createErrorMes().errorImplementMethod(m.methodName).build(), m.sourceEl, () -> { - for (FieldDetail injectableField : injectableFields) { - ClassDetail injectableCl = allClassesHelper.findForType(injectableField.type); - - for (FieldDetail injectField : injectableCl.getAllFields()) { - if (!injectField.injectAnnotation) continue; - SetFieldHelper setFieldHelper = new SetFieldHelper(injectField, injectableCl); - SmartCode provideCode = orComponentCl.modulesGraph.codeProvideType(null, injectField.type, injectField.qualifierAnns); - if (provideCode == null) { - throw new ObjectNotProvidedException( - createErrorMes() - .errorProvideTypeRequiredIn( - injectField.type.toString(), - injectableCl.className.toString(), - injectField.name - ) - .build(), - injectField.sourceEl - ); - } - builder.addCode(injectableField.name) - .addCode(".") - .addCode(setFieldHelper.codeSetField(provideCode.build(qFields))) - .addCode(";\n"); - } - - for (MethodDetail injectMethod : injectableCl.getAllMethods(false, false, "")) { - if (!injectMethod.hasAnnotations(InjectAnn.class)) continue; - - CodeBlock.Builder providingArgsCode = CodeBlock.builder(); - for (FieldDetail injectField : injectMethod.args) { - SmartCode provideCode = orComponentCl.modulesGraph.codeProvideType(null, injectField.type, injectField.qualifierAnns); - if (provideCode == null) { - throw new ObjectNotProvidedException( - createErrorMes() - .errorProvideTypeRequiredIn( - injectField.type.toString(), - injectableCl.className.toString(), - injectField.name - ) - .build(), - injectField.sourceEl - ); - } - - if (!providingArgsCode.isEmpty()) providingArgsCode.add(", "); - providingArgsCode.add(provideCode.build(m.args)); - } - - builder.addCode("$L.$L( ", injectableField.name, injectMethod.methodName) - .addCode(providingArgsCode.build()) - .addCode("); \n"); - } - - } - - //protect by lifecycle owner - for (FieldDetail injectableField : injectableFields) { - ClassDetail injectableCl = allClassesHelper.findForType(injectableField.type); - - CodeBlock.Builder subscrCode = CodeBlock.builder(); - boolean emptyCode = true; - if (lifeCycleOwner != null) { - - subscrCode.beginControlFlow("$L.subscribe( (timeMillis) -> ", lifeCycleOwner.name); - for (FieldDetail injectField : injectableCl.getAllFields()) { - if (!injectField.injectAnnotation) continue; - if (WrapHelper.isNonCachingWrapper(injectField.type)) - //nothing to protect - continue; - - SetFieldHelper getFieldHelper = new SetFieldHelper(injectField, injectableCl); - - emptyCode = false; - subscrCode.addStatement( - "$L.add(new $T($L, $L.$L , timeMillis))", - refCollectionGlFieldName, TimeHolder.class, scheduleGlFieldName, - injectableField.name, getFieldHelper.codeGetField() - ); - } - subscrCode.endControlFlow(")"); - - if (!emptyCode) builder.addCode(subscrCode.build()); - } - } - }); - return this; - } - - public ComponentBuilder protectInjectedMethod(MethodDetail m) { - ClassDetail injectableCl = allClassesHelper.findForType(m.args.get(0).type); - timeHolderFields(); - - MethodSpec.Builder builder = methodBuilder(m.methodName) - .addAnnotation(Override.class) - .addModifiers(Modifier.PUBLIC) - .addParameter(ParameterSpec.builder(injectableCl.className, "cl").build()) - .returns(void.class); - - protectInjectedMethods.add(builder); - collectRuns.execute(createErrorMes().errorImplementMethod(m.methodName).build(), m.sourceEl, () -> { - for (FieldDetail injectField : injectableCl.fields) { - if (!injectField.injectAnnotation) continue; - if (WrapHelper.isNonCachingWrapper(injectField.type)) - //nothing to protect - continue; - - SetFieldHelper getFieldHelper = new SetFieldHelper(injectField, injectableCl); - - builder.addStatement( - "$L.add(new $T($L, cl.$L , $L))", - refCollectionGlFieldName, TimeHolder.class, scheduleGlFieldName, - getFieldHelper.codeGetField(), - m.ann(ProtectInjectedAnn.class).timeMillis - ); - } - }); - return this; - } - - public ComponentBuilder gcMethod(MethodDetail m) { - CodeBlock.Builder scopesCode = CodeBlock.builder(); - int inx = 0; - for (TypeName sc : m.gcScopeAnnotations) { - if (inx++ > 0) scopesCode.add(", "); - scopesCode.add("$T.class", sc); - } - - MethodSpec.Builder builder = methodBuilder(m.methodName) - .addAnnotation(Override.class) - .addModifiers(Modifier.PUBLIC) - .returns(void.class); - - - builder.addStatement( - "$T scopes = new $T($T.asList( $L ))", - ParameterizedTypeName.get(Set.class, Class.class), - ParameterizedTypeName.get(HashSet.class, Class.class), - Arrays.class, - scopesCode.build() - ) - .addStatement("$T toWeak = $T.toWeak()", SwitchCacheParam.class, SwitchCacheParam.class) - .addStatement("$T toDef = $T.toDef()", SwitchCacheParam.class, SwitchCacheParam.class); - - - gcMethods.add(builder); - collectRuns.execute(createErrorMes().errorImplementMethod(m.methodName).build(), m.sourceEl, () -> { - builder.addStatement( - "$L( (m) -> { m.$L(scopes, toWeak); } )", - eachModuleMethodName, ModuleBuilder.switchRefMethodName - ) - .addStatement("$T.gc()", System.class) - .addStatement("$L.clearNulls()", relatedComponentsListFieldName) - .addStatement( - - "$L( (m) -> { m.__clearNulls(); m.$L(scopes, toDef); } )", - eachModuleMethodName, ModuleBuilder.switchRefMethodName - ); - - if (fields.containsKey(refCollectionGlFieldName)) - builder.addStatement("$L.clearNulls()", refCollectionGlFieldName); - }); - return this; - } - - public ComponentBuilder switchRefMethod(MethodDetail m) { - CodeBlock.Builder scopesCode = CodeBlock.builder(); - int inx = 0; - for (TypeName sc : m.gcScopeAnnotations) - if (inx++ <= 0) scopesCode.add("$T.class", sc); - else scopesCode.add(", $T.class", sc); - - MethodSpec.Builder builder = methodBuilder(m.methodName) - .addAnnotation(Override.class) - .addModifiers(Modifier.PUBLIC) - .returns(void.class); - - builder - .addStatement( - "$T scopes = new $T($T.asList( $L ))", - ParameterizedTypeName.get(Set.class, Class.class), - ParameterizedTypeName.get(HashSet.class, Class.class), - Arrays.class, - scopesCode.build() - ); - - - CodeBlock.Builder schedulerInitCode = CodeBlock.builder(); - if (m.ann(SwitchCacheAnn.class).timeMillis > 0) { - timeHolderFields(); - schedulerInitCode.add("this.$L", scheduleGlFieldName); - } else { - schedulerInitCode.add("null"); - } - builder.addStatement( - "$T switchCacheParams = new $T( $T.$L , $L, $L )", - SwitchCacheParam.class, SwitchCacheParam.class, - SwitchCache.CacheType.class, m.ann(SwitchCacheAnn.class).cache.name(), - m.ann(SwitchCacheAnn.class).timeMillis, - schedulerInitCode.build() - ).addStatement( - "$L( (m) -> { m.$L(scopes, switchCacheParams); } )", - eachModuleMethodName, ModuleBuilder.switchRefMethodName - ); - - switchRefMethods.add(builder); - return this; - } - - public TypeSpec build() { - collectRuns.executeAll(); - - TypeSpec.Builder typeSpecBuilder = TypeSpec.classBuilder(className); - typeSpecBuilder.addModifiers(Modifier.PUBLIC); - if (orComponentCl.isInterfaceClass()) typeSpecBuilder.addSuperinterface(orComponentCl.className); - else typeSpecBuilder.superclass(orComponentCl.className); - - for (TypeName supInterface : interfaces) - typeSpecBuilder.addSuperinterface(supInterface); - - for (FieldSpec.Builder field : fields.values()) - typeSpecBuilder.addField(field.build()); - - - for (FieldSpec.Builder field : depsFields.values()) - typeSpecBuilder.addField(field.build()); - - for (FieldSpec.Builder field : modulesFields.values()) - typeSpecBuilder.addField(field.build()); - - - List methodBuilders = new LinkedList<>(); - methodBuilders.addAll(iComponentMethods); - methodBuilders.addAll(depsMethods.values()); - methodBuilders.addAll(modulesMethods.values()); - methodBuilders.addAll(moduleFactoriesMethods.values()); - methodBuilders.addAll(provideObjMethods); - methodBuilders.addAll(bindInstanceMethods); - methodBuilders.addAll(injectMethods); - methodBuilders.addAll(protectInjectedMethods); - methodBuilders.addAll(switchRefMethods); - methodBuilders.addAll(gcMethods); - - for (MethodSpec.Builder method : methodBuilders) - typeSpecBuilder.addMethod(method.build()); - - return typeSpecBuilder.build(); - } - - public TypeSpec buildAndWrite() { - TypeSpec typeSpec = build(); - if (typeSpec != null) { - CodeFileUtil.writeToJavaFile(className.packageName(), typeSpec); - } - - return typeSpec; - } - -} diff --git a/stone_processor/src/main/java/com/github/klee0kai/stone/codegen/ModuleBuilder.java b/stone_processor/src/main/java/com/github/klee0kai/stone/codegen/ModuleBuilder.java deleted file mode 100644 index c87aedfd..00000000 --- a/stone_processor/src/main/java/com/github/klee0kai/stone/codegen/ModuleBuilder.java +++ /dev/null @@ -1,688 +0,0 @@ -package com.github.klee0kai.stone.codegen; - -import com.github.klee0kai.stone._hidden_.IModule; -import com.github.klee0kai.stone._hidden_.types.CacheAction; -import com.github.klee0kai.stone._hidden_.types.ListUtils; -import com.github.klee0kai.stone._hidden_.types.SwitchCacheParam; -import com.github.klee0kai.stone._hidden_.types.holders.SingleItemHolder; -import com.github.klee0kai.stone._hidden_.types.holders.StoneRefType; -import com.github.klee0kai.stone.annotations.component.GcAllScope; -import com.github.klee0kai.stone.annotations.module.BindInstance; -import com.github.klee0kai.stone.exceptions.IncorrectSignatureException; -import com.github.klee0kai.stone.helpers.codebuilder.SmartCode; -import com.github.klee0kai.stone.helpers.itemholder.ItemCacheType; -import com.github.klee0kai.stone.helpers.itemholder.ItemHolderCodeHelper; -import com.github.klee0kai.stone.model.ClassDetail; -import com.github.klee0kai.stone.model.FieldDetail; -import com.github.klee0kai.stone.model.MethodDetail; -import com.github.klee0kai.stone.model.annotations.BindInstanceAnn; -import com.github.klee0kai.stone.model.annotations.ModuleAnn; -import com.github.klee0kai.stone.model.annotations.ProvideAnn; -import com.github.klee0kai.stone.utils.CodeFileUtil; -import com.github.klee0kai.stone.utils.StoneNamingUtils; -import com.github.klee0kai.stone.wrappers.Ref; -import com.squareup.javapoet.*; - -import javax.lang.model.element.Modifier; -import java.lang.reflect.InvocationTargetException; -import java.util.*; - -import static com.github.klee0kai.stone.AnnotationProcessor.allClassesHelper; -import static com.github.klee0kai.stone.checks.ModuleMethods.*; -import static com.github.klee0kai.stone.codegen.ModuleCacheControlInterfaceBuilder.cacheControlMethodName; -import static com.github.klee0kai.stone.exceptions.ExceptionStringBuilder.createErrorMes; -import static com.github.klee0kai.stone.helpers.itemholder.ItemCacheType.cacheTypeFrom; -import static com.github.klee0kai.stone.helpers.itemholder.ItemHolderCodeHelper.of; -import static com.github.klee0kai.stone.helpers.wrap.WrapHelper.*; -import static com.github.klee0kai.stone.utils.ClassNameUtils.rawTypeOf; -import static com.github.klee0kai.stone.utils.StoneNamingUtils.genCacheControlInterfaceModuleNameMirror; -import static com.squareup.javapoet.MethodSpec.methodBuilder; - -public class ModuleBuilder { - - public static final String overridedModuleFieldName = "overridedModule"; - public static final String factoryFieldName = "factory"; - private static final String appliedLocalFieldName = "applied"; - public static final String initMethodName = "__init"; - public static final String initCachesFromMethodName = "__initCachesFrom"; - public static final String updateBindInstancesFrom = "__updateBindInstancesFrom"; - public static final String bindMethodName = "__bind"; - public static final String getFactoryMethodName = "__getFactory"; - public static final String switchRefMethodName = "__switchRef"; - public static final String clearNullsMethodName = "__clearNulls"; - - public final ClassDetail orModuleCl; - - public ClassName className; - - public final Set interfaces = new HashSet<>(); - - // ---------------------- common fields and method ---------------------------------- - public final HashMap fields = new HashMap<>(); - - public final HashMap iModuleMethodBuilders = new HashMap<>(); - - - // ---------------------- provide fields and method ---------------------------------- - public final List cacheFields = new LinkedList<>(); - public final List provideMethodBuilders = new LinkedList<>(); - public final List cacheControlMethodBuilders = new LinkedList<>(); - public final HashMap, CodeBlock.Builder> switchRefStatementBuilders = new HashMap<>(); - private final LinkedList collectRuns = new LinkedList<>(); - - public static ModuleBuilder from( - ClassDetail orModuleCl, - ClassName moduleClName, - ClassName factoryClName - ) { - ModuleBuilder builder = new ModuleBuilder( - orModuleCl, - moduleClName) - .factoryField(orModuleCl.className, factoryClName) - .overridedField() - .implementIModule(); - - for (MethodDetail m : orModuleCl.getAllMethods(false, false)) { - if (Objects.equals(m.methodName, "")) - continue; - - List idFields = ListUtils.filter(m.args, - (inx, it) -> (it.type instanceof ClassName) && allClassesHelper.allIdentifiers.contains(it.type) - ); - - int cacheFieldsCount = builder.cacheFields.size(); - - if (isProvideFactoryObject(m)) { - builder.provideFactory(m) - .mockControl(m); - } else if (isProvideCachedObject(m)) { - ItemCacheType cacheType = cacheTypeFrom(m.ann(ProvideAnn.class).cacheType); - ItemHolderCodeHelper itemHolderCodeHelper = of(m.methodName + cacheFieldsCount, m.returnType, idFields, cacheType); - builder.provideCached(m, itemHolderCodeHelper) - .cacheControl(m, itemHolderCodeHelper) - .switchRefFor(itemHolderCodeHelper, - ListUtils.setOf( - m.gcScopeAnnotations, - ClassName.get(GcAllScope.class), - cacheType.getGcScopeClassName() - )); - - builder.iModuleMethodBuilders.get(clearNullsMethodName).addCode(itemHolderCodeHelper.clearNullsStatement()); - } else if (isBindInstanceMethod(m)) { - ItemCacheType cacheType = cacheTypeFrom(m.ann(BindInstanceAnn.class).cacheType); - ItemHolderCodeHelper itemHolderCodeHelper = of(m.methodName + cacheFieldsCount, m.returnType, idFields, cacheType); - builder.bindInstance(m, itemHolderCodeHelper) - .cacheControl(m, itemHolderCodeHelper) - .switchRefFor(itemHolderCodeHelper, - ListUtils.setOf( - m.gcScopeAnnotations, - ClassName.get(GcAllScope.class), - cacheType.getGcScopeClassName() - )); - - builder.iModuleMethodBuilders.get(clearNullsMethodName).addCode(itemHolderCodeHelper.clearNullsStatement()); - } else { - throw new IncorrectSignatureException( - createErrorMes() - .moduleClass(orModuleCl.className.toString()) - .method(m.methodName) - .hasIncorrectSignature() - .build(), - m.sourceEl - ); - } - - } - return builder; - } - - - public ModuleBuilder(ClassDetail orModuleCl, ClassName moduleCl) { - this.orModuleCl = orModuleCl; - this.className = moduleCl; - } - - public ModuleBuilder factoryField(TypeName typeName, TypeName initTypeName) { - FieldSpec.Builder builder = FieldSpec.builder(typeName, factoryFieldName, Modifier.PRIVATE); - if (initTypeName != null) - builder.initializer("new $T()", initTypeName); - fields.put(factoryFieldName, builder); - return this; - } - - public ModuleBuilder overridedField() { - TypeName weakHolder = ParameterizedTypeName.get(ClassName.get(SingleItemHolder.class), genCacheControlInterfaceModuleNameMirror(orModuleCl.className)); - FieldSpec.Builder builder = FieldSpec.builder(weakHolder, overridedModuleFieldName, Modifier.PRIVATE, Modifier.FINAL) - .initializer("new $T($T.WeakObject)", weakHolder, StoneRefType.class); - fields.put(overridedModuleFieldName, builder); - return this; - } - - - /** - * Call first - * add IModule methods. - * - * @return - */ - public ModuleBuilder implementIModule() { - interfaces.add(ClassName.get(IModule.class)); - if (orModuleCl != null) for (ClassDetail parentModule : orModuleCl.getAllParents(false)) { - if (parentModule.hasAnnotations(ModuleAnn.class)) - interfaces.add(genCacheControlInterfaceModuleNameMirror(parentModule.className)); - } - - initMethod(); - initCachesFromModule(); - bindMethod(); - getFactoryMethod(); - switchRefMethod(); - updateBindInstanceFromModule(); - clearNullsMethod(); - return this; - } - - public ModuleBuilder initMethod() { - MethodSpec.Builder builder = methodBuilder(initMethodName) - .addModifiers(Modifier.PUBLIC, Modifier.SYNCHRONIZED) - .addAnnotation(Override.class) - .returns(boolean.class) - .addParameter(Object.class, "or") - .addStatement("if (or == this) return false; ") - .addStatement("boolean $L = false", appliedLocalFieldName); - - if (orModuleCl != null) { - builder - // check module class - .beginControlFlow("if ( (or instanceof $T) ) ", genCacheControlInterfaceModuleNameMirror(orModuleCl.className)) - .addStatement("$L.set(() -> ($T) or, false)", overridedModuleFieldName, genCacheControlInterfaceModuleNameMirror(orModuleCl.className)) - .addStatement("$L = ($T) (($T) or).$L() ", factoryFieldName, orModuleCl.className, IModule.class, getFactoryMethodName) - .addStatement("$L = true", appliedLocalFieldName) - .endControlFlow() - // check factory class - .beginControlFlow("else if (or instanceof $T) ", orModuleCl.className) - .addStatement("$L = ($T) or", factoryFieldName, orModuleCl.className) - .addStatement("$L = true", appliedLocalFieldName) - .endControlFlow() - // get module factory by module class - .beginControlFlow("else if (or instanceof Class && $T.class.isAssignableFrom((Class) or))", orModuleCl.className) - .beginControlFlow("try") - .addComment("looking for generated factory for module class") - .addStatement("Class gennedClass = Class.forName(((Class) or).getCanonicalName() + \"" + StoneNamingUtils.FACTORY_NAME_SUFFIX + "\")") - .addStatement("$L = ($T) gennedClass.getConstructors()[0].newInstance()", factoryFieldName, orModuleCl.className) - .addStatement("$L = true", appliedLocalFieldName) - .endControlFlow() - .beginControlFlow("catch ( $T | $T | $T | $T | $T e)", - ArrayIndexOutOfBoundsException.class, - ClassNotFoundException.class, - InstantiationException.class, - IllegalAccessException.class, - InvocationTargetException.class) - - .beginControlFlow("try") - .addComment("we don't got stone factory. We suppose class have constructor") - .addStatement("$L = ($T) ((Class) or).getConstructors()[0].newInstance()", factoryFieldName, orModuleCl.className) - .addStatement("$L = true", appliedLocalFieldName) - .endControlFlow() - .beginControlFlow("catch ($T | $T | $T | $T ex)", - ArrayIndexOutOfBoundsException.class, - InstantiationException.class, - IllegalAccessException.class, - InvocationTargetException.class - ) - .endControlFlow() - - .endControlFlow() - .endControlFlow(); - } - - builder.addStatement("return $L", appliedLocalFieldName); - - iModuleMethodBuilders.put(initMethodName, builder); - return this; - } - - - public ModuleBuilder initCachesFromModule() { - MethodSpec.Builder builder = methodBuilder(initCachesFromMethodName) - .addModifiers(Modifier.PUBLIC) - .addAnnotation(Override.class) - .addParameter(IModule.class, "m") - .addStatement("if (m == this) return"); - - collectRuns.add(() -> { - if (orModuleCl != null) for (ClassDetail cl : orModuleCl.getAllParents(false)) { - if (!cl.hasAnyAnnotation(ModuleAnn.class)) continue; - ClassName cacheControlInterfaceCl = genCacheControlInterfaceModuleNameMirror(cl.className); - builder.beginControlFlow("if ( m instanceof $T )", cacheControlInterfaceCl) - .addStatement("$T module = ($T) m", cacheControlInterfaceCl, cacheControlInterfaceCl); - - for (MethodDetail protoProvideMethod : cl.getAllMethods(false, false, "")) { - boolean isProvideMethod = !protoProvideMethod.returnType.isPrimitive() - && !Objects.equals(protoProvideMethod.returnType, TypeName.VOID) - && !protoProvideMethod.returnType.isBoxedPrimitive(); - if (!isProvideMethod) - continue; - String protoCacheControlMethodName = cacheControlMethodName(protoProvideMethod.methodName); - List qFields = ListUtils.filter(protoProvideMethod.args, - (inx, it) -> (it.type instanceof ClassName) && allClassesHelper.allIdentifiers.contains(it.type) - ); - if (!qFields.isEmpty()) { - // TODO https://github.com/klee0kai/stone/issues/42 - continue; - } - - builder.addStatement( - "$L( $T.setIfNullValueAction( module.$L( null ) ) )", - protoCacheControlMethodName, CacheAction.class, protoCacheControlMethodName - ); - - } - - builder.endControlFlow(); - } - }); - iModuleMethodBuilders.put(initCachesFromMethodName, builder); - return this; - } - - public ModuleBuilder updateBindInstanceFromModule() { - MethodSpec.Builder builder = methodBuilder(updateBindInstancesFrom) - .addModifiers(Modifier.PUBLIC) - .addAnnotation(Override.class) - .addParameter(IModule.class, "m") - .addStatement("if (m == this) return"); - - collectRuns.add(() -> { - if (orModuleCl != null) for (ClassDetail cl : orModuleCl.getAllParents(false)) { - if (!cl.hasAnyAnnotation(ModuleAnn.class)) continue; - ClassName cacheControlInterfaceCl = genCacheControlInterfaceModuleNameMirror(cl.className); - builder.beginControlFlow("if ( m instanceof $T )", cacheControlInterfaceCl) - .addStatement("$T module = ($T) m", cacheControlInterfaceCl, cacheControlInterfaceCl); - - for (MethodDetail protoProvideMethod : cl.getAllMethods(false, false, "")) { - if (!protoProvideMethod.hasAnyAnnotation(BindInstanceAnn.class)) - continue; - String protoCacheControlMethodName = cacheControlMethodName(protoProvideMethod.methodName); - List qFields = ListUtils.filter(protoProvideMethod.args, - (inx, it) -> (it.type instanceof ClassName) && allClassesHelper.allIdentifiers.contains(it.type) - ); - if (!qFields.isEmpty()) { - // TODO https://github.com/klee0kai/stone/issues/42 - continue; - } - - builder.addStatement( - "$L( $T.setValueAction( module.$L( null ) ) )", - protoCacheControlMethodName, CacheAction.class, protoCacheControlMethodName - ); - - } - - builder.endControlFlow(); - } - }); - iModuleMethodBuilders.put(updateBindInstancesFrom, builder); - return this; - } - - public ModuleBuilder bindMethod() { - MethodSpec.Builder builder = methodBuilder(bindMethodName) - .addModifiers(Modifier.PUBLIC, Modifier.SYNCHRONIZED) - .addAnnotation(BindInstance.class) - .addAnnotation(Override.class) - .addParameter(Object.class, "or") - .addStatement("boolean $L = false", appliedLocalFieldName) - .returns(boolean.class); - - if (fields.containsKey(overridedModuleFieldName)) - builder.beginControlFlow("if ( $L.get() != null )", overridedModuleFieldName) - .addStatement("$L.get().$L(or)", overridedModuleFieldName, bindMethodName) - .endControlFlow(); - - iModuleMethodBuilders.put(bindMethodName, builder); - - collectRuns.add(() -> { - builder.addStatement("return $L", appliedLocalFieldName); - }); - return this; - } - - - public ModuleBuilder getFactoryMethod() { - MethodSpec.Builder builder = methodBuilder(getFactoryMethodName) - .addModifiers(Modifier.PUBLIC) - .addAnnotation(Override.class) - .returns(Object.class) - .addStatement("return $L", fields.containsKey(factoryFieldName) ? factoryFieldName : "null"); - iModuleMethodBuilders.put(getFactoryMethodName, builder); - return this; - } - - public ModuleBuilder switchRefMethod() { - MethodSpec.Builder builder = methodBuilder(switchRefMethodName) - .addModifiers(Modifier.PUBLIC) - .addAnnotation(Override.class) - .addParameter(ParameterSpec.builder(ParameterizedTypeName.get(Set.class, Class.class), "scopes").build()) - .addParameter(ParameterSpec.builder(SwitchCacheParam.class, "__params").build()) - .returns(void.class); - - iModuleMethodBuilders.put(switchRefMethodName, builder); - - collectRuns.add(() -> { - for (Set gcScopes : switchRefStatementBuilders.keySet()) { - CodeBlock.Builder codeScopesList = CodeBlock.builder() - .add("$T.asList(", Arrays.class); - int i = 0; - for (TypeName sc : gcScopes) { - if (i++ > 0) codeScopesList.add(", "); - codeScopesList.add("$T.class", sc); - } - codeScopesList.add(")"); - - builder.beginControlFlow("if ($L.containsAll(scopes))", codeScopesList.build()) - .addCode(switchRefStatementBuilders.get(gcScopes).build()) - .endControlFlow(); - } - }); - return this; - } - - public ModuleBuilder clearNullsMethod() { - MethodSpec.Builder builder = methodBuilder(clearNullsMethodName) - .addModifiers(Modifier.PUBLIC) - .addAnnotation(Override.class) - .returns(void.class); - - iModuleMethodBuilders.put(clearNullsMethodName, builder); - return this; - } - - - public ModuleBuilder switchRefFor(ItemHolderCodeHelper fieldHelper, Set scopes) { - switchRefStatementBuilders.putIfAbsent(scopes, CodeBlock.builder()); - switchRefStatementBuilders.get(scopes).add(fieldHelper.statementSwitchRef(CodeBlock.of("__params"))); - return this; - } - - public ModuleBuilder bindInstance(MethodDetail m, ItemHolderCodeHelper itemHolderCodeHelper) { - String cacheControlMethodName = cacheControlMethodName(m.methodName); - cacheFields.add(itemHolderCodeHelper.cachedField()); - FieldDetail setValueArg = ListUtils.first(m.args, (inx, ob) -> Objects.equals(ob.type, m.returnType)); - List qFields = ListUtils.filter(m.args, - (inx, it) -> (it.type instanceof ClassName) && allClassesHelper.allIdentifiers.contains(it.type) - ); - - //provide method - MethodSpec.Builder provideMethodBuilder = methodBuilder(m.methodName) - .addModifiers(Modifier.PUBLIC, Modifier.SYNCHRONIZED) - .returns(m.returnType); - - if (fields.containsKey(overridedModuleFieldName)) { - // check cached from overrided module - provideMethodBuilder - .beginControlFlow("if ($L.get() != null )", overridedModuleFieldName) - .addStatement("$T cached = $L.get().$L( null $L ) ", - listWrapTypeIfNeed(m.returnType), - overridedModuleFieldName, cacheControlMethodName, - String.join("", ListUtils.format(qFields, (it) -> ", " + it.name)) - ) - .addCode("if (cached != null ) return ") - .addCode(transform( - SmartCode.of("cached").providingType(listWrapTypeIfNeed(m.returnType)), - m.returnType - ).build(null) - ).addCode(";\n") - .endControlFlow(); - } - - if (orModuleCl != null) provideMethodBuilder.addAnnotation(Override.class); - - - if (m.args != null) for (FieldDetail p : m.args) { - provideMethodBuilder.addParameter(p.type, p.name); - } - if (setValueArg != null) { - provideMethodBuilder.beginControlFlow("if ($L != null)", setValueArg.name) - .addStatement(itemHolderCodeHelper.codeSetCachedValue(CodeBlock.of("$L", setValueArg.name), false)) - .endControlFlow(); - } - provideMethodBuilder.addStatement( - "return $L", - transform(itemHolderCodeHelper.codeGetCachedValue(), m.returnType) - .build(null) - ); - provideMethodBuilders.add(provideMethodBuilder); - - - // bind item code. - // old design non-supports lists - MethodSpec.Builder bindMethodBuilder = iModuleMethodBuilders.get(bindMethodName); - if (bindMethodBuilder != null && !isList(m.returnType)) { - bindMethodBuilder.beginControlFlow("if ($T.equals(or.getClass(), $T.class)) ", Objects.class, rawTypeOf(nonWrappedType(m.returnType))) - .addStatement(itemHolderCodeHelper.codeSetCachedValue( - CodeBlock.of("($T) or", nonWrappedType(m.returnType)), false - )) - .addStatement("$L = true", appliedLocalFieldName) - .endControlFlow(); - } - return this; - } - - public ModuleBuilder provideFactory(MethodDetail m) { - MethodSpec.Builder provideMethodBuilder = methodBuilder(m.methodName) - .addModifiers(Modifier.PUBLIC) - .returns(m.returnType) - .addStatement("return $L.$L($L)", factoryFieldName, m.methodName, - String.join(",", ListUtils.format(m.args, (it) -> it.name))); - if (orModuleCl != null) provideMethodBuilder.addAnnotation(Override.class); - - for (FieldDetail p : m.args) { - provideMethodBuilder.addParameter(p.type, p.name); - } - - // not need to use override module. - // `factory` field already overridden - - provideMethodBuilders.add(provideMethodBuilder); - return this; - } - - public ModuleBuilder provideCached(MethodDetail m, ItemHolderCodeHelper itemHolderCodeHelper) { - String cacheControlMethodName = cacheControlMethodName(m.methodName); - List qFields = ListUtils.filter(m.args, - (inx, it) -> (it.type instanceof ClassName) && allClassesHelper.allIdentifiers.contains(it.type) - ); - cacheFields.add(itemHolderCodeHelper.cachedField()); - MethodSpec.Builder provideMethodBuilder = methodBuilder(m.methodName) - .addModifiers(Modifier.PUBLIC, Modifier.SYNCHRONIZED) - .returns(m.returnType); - if (orModuleCl != null) provideMethodBuilder.addAnnotation(Override.class); - - for (FieldDetail p : m.args) { - provideMethodBuilder.addParameter(p.type, p.name); - } - - if (fields.containsKey(overridedModuleFieldName)) { - // check cached from overrided module - provideMethodBuilder - .beginControlFlow("if ($L.get() != null )", overridedModuleFieldName) - .addStatement("$T cached = $L.get().$L( null $L ) ", - listWrapTypeIfNeed(m.returnType), - overridedModuleFieldName, cacheControlMethodName, - String.join("", ListUtils.format(qFields, (it) -> ", " + it.name)) - ) - .addCode("if (cached != null ) return ") - .addCode(transform( - SmartCode.of("cached").providingType(listWrapTypeIfNeed(m.returnType)), - m.returnType - ).build(null) - ).addCode(";\n") - .endControlFlow(); - } - - // set value if null - String argStrList = String.join(",", ListUtils.format(m.args, (it) -> it.name)); - provideMethodBuilder - .addCode("$T creator = () -> ", ParameterizedTypeName.get(ClassName.get(Ref.class), m.returnType)) - .addCode(" $L.get() != null ? ", overridedModuleFieldName) - .addCode(" $L.get().$L( $L ) ", overridedModuleFieldName, m.methodName, argStrList) - .addCode(":") - .addCode(" $L.$L($L)", factoryFieldName, m.methodName, argStrList) - .addCode(";\n") - .addStatement( - itemHolderCodeHelper.codeSetCachedValue( - transform(SmartCode.builder() - .add(CodeBlock.of("creator.get()")) - .providingType(m.returnType), - listWrapTypeIfNeed(m.returnType)) - .build(null), - true - ) - ) - //get cached value - .addStatement( - "return $L ", - transform(itemHolderCodeHelper.codeGetCachedValue(), m.returnType) - .build(null) - ); - - - provideMethodBuilders.add(provideMethodBuilder); - return this; - } - - - public ModuleBuilder cacheControl(MethodDetail m, ItemHolderCodeHelper itemHolderCodeHelper) { - String cacheControlMethodName = cacheControlMethodName(m.methodName); - TypeName cacheControlType = listWrapTypeIfNeed(m.returnType); - List qFields = ListUtils.filter(m.args, - (inx, it) -> (it.type instanceof ClassName) && allClassesHelper.allIdentifiers.contains(it.type) - ); - - MethodSpec.Builder cacheControldMethodBuilder = methodBuilder(cacheControlMethodName) - .addModifiers(Modifier.PUBLIC) - .returns(cacheControlType) - .addParameter(ParameterSpec.builder(CacheAction.class, "__action").build()); - if (orModuleCl != null) cacheControldMethodBuilder.addAnnotation(Override.class); - for (FieldDetail q : qFields) { - cacheControldMethodBuilder.addParameter(q.type, q.name); - } - - if (fields.containsKey(overridedModuleFieldName)) { - cacheControldMethodBuilder - // invoke for overrided module - .beginControlFlow("if ($L.get() != null)", overridedModuleFieldName) - .addStatement( - "$L.get().$L($L)", - overridedModuleFieldName, - cacheControlMethodName, - String.join(",", ListUtils.format( - cacheControldMethodBuilder.parameters, - (ListUtils.IFormat) it -> it.name) - ) - ) - .endControlFlow(); - } - - cacheControldMethodBuilder - .beginControlFlow("if (__action != null) switch (__action.type)") - //set value - .beginControlFlow("case SET_VALUE:") - .beginControlFlow("if ( __action.value instanceof $T)", rawTypeOf(cacheControlType)) - .addStatement(itemHolderCodeHelper.codeSetCachedValue( - CodeBlock.of(" ( $T ) __action.value", cacheControlType), false - )) - .endControlFlow() - .addStatement("break") - .endControlFlow() - //set if null value - .beginControlFlow("case SET_IF_NULL:") - .beginControlFlow("if (__action.value instanceof $T)", rawTypeOf(cacheControlType)) - .addStatement(itemHolderCodeHelper.codeSetCachedValue( - CodeBlock.of(" ( $T ) __action.value", cacheControlType), true - )) - .endControlFlow() - .addStatement("break") - .endControlFlow() - // switch cache type - .beginControlFlow("case SWITCH_CACHE:") - .addCode(itemHolderCodeHelper.statementSwitchRef(CodeBlock.of("__action.swCacheParams"))) - .addStatement("break") - .endControlFlow() - .endControlFlow() - .addStatement("return $L ", itemHolderCodeHelper.codeGetCachedValue().build(null)); - - cacheControlMethodBuilders.add(cacheControldMethodBuilder); - return this; - } - - - public ModuleBuilder mockControl(MethodDetail m) { - String cacheControlMethodName = cacheControlMethodName(m.methodName); - List qFields = ListUtils.filter(m.args, - (inx, it) -> (it.type instanceof ClassName) && allClassesHelper.allIdentifiers.contains(it.type) - ); - - MethodSpec.Builder cacheControldMethodBuilder = methodBuilder(cacheControlMethodName) - .addModifiers(Modifier.PUBLIC) - .returns(listWrapTypeIfNeed(m.returnType)) - .addParameter(ParameterSpec.builder(CacheAction.class, "__action").build()) - .addStatement("return null"); - if (orModuleCl != null) cacheControldMethodBuilder.addAnnotation(Override.class); - - for (FieldDetail q : qFields) { - cacheControldMethodBuilder.addParameter(q.type, q.name); - } - provideMethodBuilders.add(cacheControldMethodBuilder); - return this; - } - - public ModuleBuilder collect() { - for (Runnable r : collectRuns) - r.run(); - collectRuns.clear(); - return this; - } - - public TypeSpec build(boolean collectAll) { - if (collectAll) { - collect(); - } - - TypeSpec.Builder typeSpecBuilder = TypeSpec.classBuilder(className); - typeSpecBuilder.addModifiers(Modifier.PUBLIC); - if (orModuleCl != null && !Objects.equals(orModuleCl.className, className)) { - if (orModuleCl.isInterfaceClass()) - typeSpecBuilder.addSuperinterface(orModuleCl.className); - else typeSpecBuilder.superclass(orModuleCl.className); - } - for (TypeName supInterface : interfaces) - typeSpecBuilder.addSuperinterface(supInterface); - - for (FieldSpec.Builder fieldBuilder : fields.values()) - typeSpecBuilder.addField(fieldBuilder.build()); - for (FieldSpec.Builder cacheFieldBuilder : cacheFields) - typeSpecBuilder.addField(cacheFieldBuilder.build()); - - List methods = new LinkedList<>(); - methods.addAll(iModuleMethodBuilders.values()); - methods.addAll(provideMethodBuilders); - methods.addAll(cacheControlMethodBuilders); - - for (MethodSpec.Builder provideMethod : methods) - typeSpecBuilder.addMethod(provideMethod.build()); - - return typeSpecBuilder.build(); - } - - public TypeSpec buildAndWrite() { - TypeSpec typeSpec = build(true); - if (typeSpec != null) { - CodeFileUtil.writeToJavaFile(className.packageName(), typeSpec); - } - return typeSpec; - } - - -} diff --git a/stone_processor/src/main/java/com/github/klee0kai/stone/codegen/ModuleCacheControlInterfaceBuilder.java b/stone_processor/src/main/java/com/github/klee0kai/stone/codegen/ModuleCacheControlInterfaceBuilder.java deleted file mode 100644 index 86da2d03..00000000 --- a/stone_processor/src/main/java/com/github/klee0kai/stone/codegen/ModuleCacheControlInterfaceBuilder.java +++ /dev/null @@ -1,144 +0,0 @@ -package com.github.klee0kai.stone.codegen; - -import com.github.klee0kai.stone._hidden_.types.CacheAction; -import com.github.klee0kai.stone._hidden_.types.ListUtils; -import com.github.klee0kai.stone._hidden_.types.SwitchCacheParam; -import com.github.klee0kai.stone.model.ClassDetail; -import com.github.klee0kai.stone.model.FieldDetail; -import com.github.klee0kai.stone.model.MethodDetail; -import com.github.klee0kai.stone.utils.CodeFileUtil; -import com.squareup.javapoet.*; - -import javax.lang.model.element.Modifier; -import java.util.*; - -import static com.github.klee0kai.stone.AnnotationProcessor.allClassesHelper; -import static com.github.klee0kai.stone.codegen.ModuleBuilder.bindMethodName; -import static com.github.klee0kai.stone.codegen.ModuleBuilder.switchRefMethodName; -import static com.github.klee0kai.stone.helpers.wrap.WrapHelper.listWrapTypeIfNeed; -import static com.squareup.javapoet.MethodSpec.methodBuilder; - -public class ModuleCacheControlInterfaceBuilder { - - public final ClassDetail orModuleCl; - - public ClassName className; - - - public final Set interfaces = new HashSet<>(); - - public final HashMap iModuleMethodBuilders = new HashMap<>(); - - // ---------------------- provide fields and method ---------------------------------- - public final List methodBuilders = new LinkedList<>(); - - - public static ModuleCacheControlInterfaceBuilder from( - ClassDetail orModule, - ClassName cacheControlCl - ) { - ModuleCacheControlInterfaceBuilder builder = new ModuleCacheControlInterfaceBuilder( - orModule, - cacheControlCl - ).bindMethod() - .switchRefMethod(); - - for (MethodDetail m : orModule.getAllMethods(false, false)) { - if (Objects.equals(m.methodName, "")) - continue; - builder.provideMethod(m.methodName, m.returnType, m.args) - .cacheControlMethod(m.methodName, m.returnType, m.args); - } - return builder; - } - - public ModuleCacheControlInterfaceBuilder(ClassDetail orModuleCl, ClassName className) { - this.orModuleCl = orModuleCl; - this.className = className; - } - - public ModuleCacheControlInterfaceBuilder bindMethod() { - MethodSpec.Builder builder = methodBuilder(bindMethodName) - .addModifiers(Modifier.PUBLIC, Modifier.ABSTRACT) - .addParameter(Object.class, "or") - .returns(boolean.class); - - iModuleMethodBuilders.put(bindMethodName, builder); - - return this; - } - - public ModuleCacheControlInterfaceBuilder switchRefMethod() { - MethodSpec.Builder builder = methodBuilder(switchRefMethodName) - .addModifiers(Modifier.PUBLIC, Modifier.ABSTRACT) - .addParameter(ParameterSpec.builder(ParameterizedTypeName.get(Set.class, Class.class), "scopes").build()) - .addParameter(ParameterSpec.builder(SwitchCacheParam.class, "__params").build()) - .returns(void.class); - - iModuleMethodBuilders.put(switchRefMethodName, builder); - return this; - } - - - public ModuleCacheControlInterfaceBuilder provideMethod(String name, TypeName typeName, List args) { - MethodSpec.Builder provideMethodBuilder = methodBuilder(name) - .addModifiers(Modifier.PUBLIC, Modifier.ABSTRACT) - .returns(typeName); - - if (args != null) for (FieldDetail p : args) { - provideMethodBuilder.addParameter(p.type, p.name); - } - - methodBuilders.add(provideMethodBuilder); - return this; - } - - public ModuleCacheControlInterfaceBuilder cacheControlMethod(String name, TypeName typeName, List args) { - String cacheControlMethodName = cacheControlMethodName(name); - List qFields = ListUtils.filter(args, - (inx, it) -> (it.type instanceof ClassName) && allClassesHelper.allIdentifiers.contains(it.type) - ); - - MethodSpec.Builder cacheControldMethodBuilder = methodBuilder(cacheControlMethodName) - .addModifiers(Modifier.PUBLIC, Modifier.ABSTRACT) - .returns(listWrapTypeIfNeed(typeName)) - .addParameter(ParameterSpec.builder(CacheAction.class, "__action").build()); - for (FieldDetail q : qFields) { - cacheControldMethodBuilder.addParameter(q.type, q.name); - } - - methodBuilders.add(cacheControldMethodBuilder); - return this; - } - - public TypeSpec build() { - TypeSpec.Builder typeSpecBuilder = TypeSpec.interfaceBuilder(className); - - typeSpecBuilder.addModifiers(Modifier.PUBLIC); - - for (TypeName supInterface : interfaces) - typeSpecBuilder.addSuperinterface(supInterface); - - for (MethodSpec.Builder iModuleMethod : iModuleMethodBuilders.values()) - typeSpecBuilder.addMethod(iModuleMethod.build()); - - for (MethodSpec.Builder provideMethod : methodBuilders) - typeSpecBuilder.addMethod(provideMethod.build()); - - return typeSpecBuilder.build(); - } - - public TypeSpec buildAndWrite() { - TypeSpec typeSpec = build(); - if (typeSpec != null) { - CodeFileUtil.writeToJavaFile(className.packageName(), typeSpec); - } - return typeSpec; - } - - - public static String cacheControlMethodName(String factoryMethodName) { - return factoryMethodName != null ? "__" + factoryMethodName + "_cache" : null; - } - -} diff --git a/stone_processor/src/main/java/com/github/klee0kai/stone/codegen/ModuleFactoryBuilder.java b/stone_processor/src/main/java/com/github/klee0kai/stone/codegen/ModuleFactoryBuilder.java deleted file mode 100644 index eb084270..00000000 --- a/stone_processor/src/main/java/com/github/klee0kai/stone/codegen/ModuleFactoryBuilder.java +++ /dev/null @@ -1,179 +0,0 @@ -package com.github.klee0kai.stone.codegen; - -import com.github.klee0kai.stone._hidden_.IModuleFactory; -import com.github.klee0kai.stone._hidden_.types.ListUtils; -import com.github.klee0kai.stone.exceptions.ObjectNotProvidedException; -import com.github.klee0kai.stone.helpers.codebuilder.SmartCode; -import com.github.klee0kai.stone.helpers.wrap.WrapHelper; -import com.github.klee0kai.stone.model.ClassDetail; -import com.github.klee0kai.stone.model.FieldDetail; -import com.github.klee0kai.stone.model.MethodDetail; -import com.github.klee0kai.stone.model.annotations.BindInstanceAnn; -import com.github.klee0kai.stone.utils.CodeFileUtil; -import com.squareup.javapoet.ClassName; -import com.squareup.javapoet.CodeBlock; -import com.squareup.javapoet.MethodSpec; -import com.squareup.javapoet.TypeSpec; - -import javax.lang.model.element.Modifier; -import java.util.LinkedList; -import java.util.List; - -import static com.github.klee0kai.stone.AnnotationProcessor.allClassesHelper; -import static com.github.klee0kai.stone.exceptions.ExceptionStringBuilder.createErrorMes; -import static com.github.klee0kai.stone.helpers.wrap.WrapHelper.nonWrappedType; -import static com.github.klee0kai.stone.utils.StoneNamingUtils.genFactoryNameMirror; -import static com.squareup.javapoet.MethodSpec.methodBuilder; - -public class ModuleFactoryBuilder { - - public final ClassDetail orFactory; - - public ClassName className; - - public boolean needBuild = false; - - public final List provideMethodBuilders = new LinkedList<>(); - - public static ModuleFactoryBuilder fromModule(ClassDetail module) { - ModuleFactoryBuilder builder = new ModuleFactoryBuilder(module); - builder.needBuild = module.isAbstractClass() || module.isInterfaceClass(); - ClassDetail defaultImpl = allClassesHelper.tryFindForType(((ClassName) module.className).nestedClass("DefaultImpls")); - if (builder.needBuild) { - builder.className = genFactoryNameMirror(module.className); - for (MethodDetail m : module.getAllMethods(false, false, "")) { - if (!m.isAbstract() && !module.isInterfaceClass()) - continue; - boolean processed = false; - if (m.hasAnnotations(BindInstanceAnn.class)) { - builder.provideNullMethod(m); - processed = true; - } - if (!processed && defaultImpl != null) { - MethodDetail defProvideMethod = MethodDetail.simpleName(m.methodName); - defProvideMethod.args.add(FieldDetail.simple("thhhis", module.className)); - defProvideMethod.args.addAll(m.args); - if (defaultImpl.findMethod(defProvideMethod, false) != null) { - builder.provideMethodFrom(m, defaultImpl); - processed = true; - } - } - if (!processed) { - builder.provideMethod(m); - } - } - } - return builder; - } - - public ModuleFactoryBuilder(ClassDetail orFactory) { - this.orFactory = orFactory; - this.className = (ClassName) orFactory.className; - } - - public ModuleFactoryBuilder provideMethodFrom(MethodDetail m, ClassDetail defaultImpl) { - ClassDetail providingClass = allClassesHelper.findForType(nonWrappedType(m.returnType)); - MethodSpec.Builder builder = methodBuilder(m.methodName) - .addModifiers(Modifier.PUBLIC) - .addAnnotation(Override.class) - .returns(m.returnType); - for (FieldDetail p : m.args) - builder.addParameter(p.type, p.name); - - String argStr = m.args == null ? "" : String.join("", ListUtils.format(m.args, (it) -> ", " + it.name)); - SmartCode genCode = SmartCode.builder() - .add(CodeBlock.of("$T.$L( this $L )", defaultImpl.className, m.methodName, argStr)) - .providingType(providingClass.className); - - builder.addCode( - SmartCode.builder() - .add("return ") - .add(WrapHelper.transform(genCode, m.returnType)) - .add(";\n") - .build(m.args) - ); - - - provideMethodBuilders.add(builder); - return this; - } - - public ModuleFactoryBuilder provideMethod(MethodDetail m) { - ClassDetail providingClass = allClassesHelper.findForType(nonWrappedType(m.returnType)); - boolean hasConstructor = providingClass.findMethod(MethodDetail.constructorMethod(m.args), false) != null; - if (!hasConstructor) { - List argTypes = ListUtils.format(m.args, (it) -> it.type.toString()); - throw new ObjectNotProvidedException( - createErrorMes() - .constructorNonFound(providingClass.className.toString(), argTypes) - .build(), - m.sourceEl - ); - } - - MethodSpec.Builder builder = methodBuilder(m.methodName) - .addModifiers(Modifier.PUBLIC) - .addAnnotation(Override.class) - .returns(m.returnType); - for (FieldDetail p : m.args) - builder.addParameter(p.type, p.name); - - String argStr = m.args == null ? "" : String.join(",", ListUtils.format(m.args, (it) -> it.name)); - SmartCode genCode = SmartCode.builder() - .add(CodeBlock.of("new $T( $L )", providingClass.className, argStr)) - .providingType(providingClass.className); - - builder.addCode( - SmartCode.builder() - .add("return ") - .add(WrapHelper.transform(genCode, m.returnType)) - .add(";\n") - .build(m.args) - ); - - - provideMethodBuilders.add(builder); - return this; - } - - public ModuleFactoryBuilder provideNullMethod(MethodDetail m) { - MethodSpec.Builder builder = methodBuilder(m.methodName) - .addModifiers(Modifier.PUBLIC) - .addAnnotation(Override.class) - .returns(m.returnType) - .addStatement("return null"); - - if (m.args != null) for (FieldDetail p : m.args) - builder.addParameter(p.type, p.name); - - provideMethodBuilders.add(builder); - return this; - } - - - public TypeSpec build() { - if (!needBuild) - return null; - TypeSpec.Builder typeSpecBuilder = TypeSpec.classBuilder(className); - typeSpecBuilder.addModifiers(Modifier.PUBLIC); - if (orFactory.isInterfaceClass()) - typeSpecBuilder.addSuperinterface(orFactory.className); - else typeSpecBuilder.superclass(orFactory.className); - typeSpecBuilder.addSuperinterface(IModuleFactory.class); - - for (MethodSpec.Builder provideMethod : provideMethodBuilders) - typeSpecBuilder.addMethod(provideMethod.build()); - - return typeSpecBuilder.build(); - } - - public TypeSpec buildAndWrite() { - TypeSpec typeSpec = build(); - if (typeSpec != null) { - CodeFileUtil.writeToJavaFile(className.packageName(), typeSpec); - } - return typeSpec; - } - - -} diff --git a/stone_processor/src/main/java/com/github/klee0kai/stone/codegen/WrappersSupportBuilder.java b/stone_processor/src/main/java/com/github/klee0kai/stone/codegen/WrappersSupportBuilder.java deleted file mode 100644 index d94e8d3f..00000000 --- a/stone_processor/src/main/java/com/github/klee0kai/stone/codegen/WrappersSupportBuilder.java +++ /dev/null @@ -1,120 +0,0 @@ -package com.github.klee0kai.stone.codegen; - -import com.github.klee0kai.stone._hidden_.types.ListUtils; -import com.github.klee0kai.stone.codegen.model.WrapperCreatorField; -import com.github.klee0kai.stone.exceptions.IncorrectSignatureException; -import com.github.klee0kai.stone.helpers.codebuilder.SmartCode; -import com.github.klee0kai.stone.helpers.wrap.WrapHelper; -import com.github.klee0kai.stone.helpers.wrap.WrapType; -import com.github.klee0kai.stone.model.ClassDetail; -import com.github.klee0kai.stone.model.annotations.WrapperCreatorsAnn; -import com.github.klee0kai.stone.utils.CodeFileUtil; -import com.squareup.javapoet.*; - -import javax.lang.model.element.Modifier; -import java.util.LinkedList; -import java.util.Objects; - -import static com.github.klee0kai.stone.checks.WrappersCreatorChecks.*; -import static com.github.klee0kai.stone.exceptions.ExceptionStringBuilder.createErrorMes; - -public class WrappersSupportBuilder { - - public ClassName className; - - public static final String provideWrappersGlFieldPrefixName = "__wrapperCreator"; - public final LinkedList wrapperCreatorFields = new LinkedList<>(); - - public WrappersSupportBuilder(ClassName className) { - this.className = className; - } - - public WrappersSupportBuilder addProvideWrapperField(ClassDetail provideWrappersCl) { - String name = provideWrappersGlFieldPrefixName + wrapperCreatorFields.size(); - wrapperCreatorFields.add(new WrapperCreatorField( - name, - provideWrappersCl.ann(WrapperCreatorsAnn.class).wrappers, - FieldSpec.builder(provideWrappersCl.className, name, Modifier.PUBLIC, Modifier.FINAL, Modifier.STATIC) - .initializer("new $T()", provideWrappersCl.className) - )); - - boolean isSimpleWrapper = ListUtils.first(provideWrappersCl.getAllParents(false), - (i, it) -> Objects.equals(it.className, wrapperClName)) != null; - - boolean isAsyncWrapper = ListUtils.first(provideWrappersCl.getAllParents(false), - (i, it) -> Objects.equals(it.className, asyncWrapperClName)) != null; - - boolean isCycleWrapper = ListUtils.first(provideWrappersCl.getAllParents(false), - (i, it) -> Objects.equals(it.className, circleWrapperClName)) != null; - - for (ClassName wrapper : provideWrappersCl.ann(WrapperCreatorsAnn.class).wrappers) { - WrapType wrapType = new WrapType(); - wrapType.isNoCachingWrapper = !isAsyncWrapper; - wrapType.typeName = wrapper; - wrapType.wrap = or -> { - SmartCode builder = SmartCode.builder(); - - if (isSimpleWrapper) { - builder.add(CodeBlock.of("$T.$L.wrap( $T.class , ", className, name, wrapper)) - .add(or) - .add(")"); - } else if (isAsyncWrapper || isCycleWrapper) { - builder.add(CodeBlock.of("$T.$L.wrap( $T.class , () -> ", className, name, wrapper)) - .add(or) - .add(")"); - } else { - throw new IncorrectSignatureException(createErrorMes() - .typeTransformNonSupport(or.providingType, wrapper) - .build()); - } - if (or.providingType != null) - builder.providingType(ParameterizedTypeName.get(wrapper, or.providingType)); - return builder; - }; - wrapType.unwrap = or -> { - SmartCode builder = SmartCode.builder(); - TypeName paramType = WrapHelper.paramType(or.providingType); - if (isCycleWrapper) { - - builder.add(CodeBlock.of("$T.$L.unwrap( $T.class , $T.class, ", className, name, wrapper, paramType)) - .add(or) - .add(")") - .providingType(paramType); - } else { - throw new IncorrectSignatureException(createErrorMes() - .typeTransformNonSupport(or.providingType, wrapper) - .build()); - } - - return builder; - }; - - WrapHelper.support(wrapType); - } - return this; - } - - public boolean isEmpty() { - return wrapperCreatorFields.isEmpty(); - } - - public TypeSpec build() { - TypeSpec.Builder typeSpecBuilder = TypeSpec.classBuilder(className) - .addModifiers(Modifier.PUBLIC, Modifier.FINAL); - for (WrapperCreatorField field : wrapperCreatorFields) - typeSpecBuilder.addField(field.fieldBuilder.build()); - - return typeSpecBuilder.build(); - } - - - public TypeSpec buildAndWrite() { - TypeSpec typeSpec = build(); - if (typeSpec != null) { - CodeFileUtil.writeToJavaFile(className.packageName(), typeSpec); - } - - return typeSpec; - } - -} diff --git a/stone_processor/src/main/java/com/github/klee0kai/stone/codegen/model/WrapperCreatorField.java b/stone_processor/src/main/java/com/github/klee0kai/stone/codegen/model/WrapperCreatorField.java deleted file mode 100644 index 4672ec91..00000000 --- a/stone_processor/src/main/java/com/github/klee0kai/stone/codegen/model/WrapperCreatorField.java +++ /dev/null @@ -1,26 +0,0 @@ -package com.github.klee0kai.stone.codegen.model; - -import com.squareup.javapoet.ClassName; -import com.squareup.javapoet.FieldSpec; -import com.squareup.javapoet.TypeName; - -import java.util.List; - -public class WrapperCreatorField { - - public String fieldName; - - public List typeNames; - - public FieldSpec.Builder fieldBuilder; - - public WrapperCreatorField(String fieldName, List typeNames, FieldSpec.Builder fieldBuilder) { - this.fieldName = fieldName; - this.typeNames = typeNames; - this.fieldBuilder = fieldBuilder; - } - - public boolean isSupport(TypeName typeName) { - return typeNames.contains(typeName); - } -} diff --git a/stone_processor/src/main/java/com/github/klee0kai/stone/exceptions/ClassNotFoundStoneException.java b/stone_processor/src/main/java/com/github/klee0kai/stone/exceptions/ClassNotFoundStoneException.java deleted file mode 100644 index 355e8a25..00000000 --- a/stone_processor/src/main/java/com/github/klee0kai/stone/exceptions/ClassNotFoundStoneException.java +++ /dev/null @@ -1,15 +0,0 @@ -package com.github.klee0kai.stone.exceptions; - -import javax.lang.model.element.Element; - -public class ClassNotFoundStoneException extends StoneException { - - public ClassNotFoundStoneException(String message, Throwable cause) { - super(message, cause); - } - - public ClassNotFoundStoneException(String message, Throwable cause, Element element) { - super(message, cause, element); - } - -} diff --git a/stone_processor/src/main/java/com/github/klee0kai/stone/exceptions/ExceptionStringBuilder.java b/stone_processor/src/main/java/com/github/klee0kai/stone/exceptions/ExceptionStringBuilder.java deleted file mode 100644 index 2faff670..00000000 --- a/stone_processor/src/main/java/com/github/klee0kai/stone/exceptions/ExceptionStringBuilder.java +++ /dev/null @@ -1,365 +0,0 @@ -package com.github.klee0kai.stone.exceptions; - -import com.squareup.javapoet.TypeName; - -import java.util.List; -import java.util.Locale; - -/** - * Build error message by masks - * Pro-StringBuilder implementation for exceptions - */ -public class ExceptionStringBuilder { - - private final StringBuilder sb = new StringBuilder(); - - public static ExceptionStringBuilder createErrorMes() { - return new ExceptionStringBuilder(); - } - - public ExceptionStringBuilder cannotCreateComponent(String componentName) { - if (sb.length() > 0) sb.append(" "); - sb.append("Cannot create component: "); - sb.append(componentName); - return this; - } - - public ExceptionStringBuilder cannotCreateWrappersHelper() { - if (sb.length() > 0) sb.append(" "); - sb.append("Cannot create wrappers helper "); - return this; - } - - public ExceptionStringBuilder cannotCreateModule(String moduleName) { - if (sb.length() > 0) sb.append(" "); - sb.append("Cannot create component: "); - sb.append(moduleName); - return this; - } - - public ExceptionStringBuilder componentsClass(String className) { - if (sb.length() > 0) sb.append(" "); - sb.append(String.format(Locale.ROOT, - "Component's class %s", - className)); - return this; - } - - - public ExceptionStringBuilder moduleClass(String className) { - if (sb.length() > 0) sb.append(" "); - sb.append(String.format(Locale.ROOT, - "Module's class %s", - className)); - return this; - } - - public ExceptionStringBuilder dependencyClass(String className) { - if (sb.length() > 0) sb.append(" "); - sb.append(String.format(Locale.ROOT, - "Dependency's class %s", - className)); - return this; - } - - - public ExceptionStringBuilder wrappersCreatorClass(String className) { - if (sb.length() > 0) sb.append(" "); - sb.append(String.format(Locale.ROOT, - "WrappersCreator's class %s", - className)); - return this; - } - - public ExceptionStringBuilder wrapperShouldBeGenericType1(TypeName className) { - if (sb.length() > 0) sb.append(" "); - sb.append(String.format(Locale.ROOT, - "WrapperClass %s should be genericType with one type argument. Like SmthWrapper.class ", - className.toString())); - return this; - } - - public ExceptionStringBuilder method(String methodName) { - if (sb.length() > 0) sb.append(" "); - sb.append(String.format(Locale.ROOT, - "method '%s'", - methodName)); - return this; - } - - - public ExceptionStringBuilder classNonFound(String className) { - if (sb.length() > 0) sb.append(" "); - sb.append("Class not found: "); - sb.append(className); - sb.append(". Try import class directly."); - return this; - } - - public ExceptionStringBuilder primitiveTypesNonSupported(String typeName) { - if (sb.length() > 0) sb.append(" "); - sb.append("Primitive type non supported: "); - sb.append(typeName); - return this; - } - - public ExceptionStringBuilder methodPurposeNonDetected(String methodName, String className) { - if (sb.length() > 0) sb.append(" "); - sb.append(String.format(Locale.ROOT, - "What is purpose for Method '%s'. Declared in %s", - methodName, className)); - return this; - } - - public ExceptionStringBuilder errorProvideModuleFactoryRequiredIn(String providingTypeName, String className, String method) { - if (sb.length() > 0) sb.append(" "); - sb.append(String.format(Locale.ROOT, - "Error provide module %s. Required in %s.%s", - providingTypeName, className, method)); - return this; - } - - public ExceptionStringBuilder errorProvideTypeRequiredIn(String providingTypeName, String className, String method) { - if (sb.length() > 0) sb.append(" "); - sb.append(String.format(Locale.ROOT, - "Error provide type %s. Required in %s.%s", - providingTypeName, className, method)); - return this; - } - - public ExceptionStringBuilder errorProvideType(String providingTypeName) { - if (sb.length() > 0) sb.append(" "); - sb.append(String.format(Locale.ROOT, - "Error provide type %s", - providingTypeName)); - return this; - } - - public ExceptionStringBuilder shouldNoProvideIdentifierType(String providingTypeName) { - if (sb.length() > 0) sb.append(" "); - sb.append(String.format(Locale.ROOT, - "Should no provide identifier %s", - providingTypeName)); - return this; - } - - public ExceptionStringBuilder errorImplementMethod(String method) { - if (sb.length() > 0) sb.append(" "); - sb.append(String.format(Locale.ROOT, - "Error to implement method: '%s'", - method)); - return this; - } - - public ExceptionStringBuilder hasIncorrectSignature() { - if (sb.length() > 0) sb.append(" "); - sb.append("has incorrect signature"); - return this; - } - - public ExceptionStringBuilder shouldNoHaveAnnotation(String annotation) { - if (sb.length() > 0) sb.append(" "); - sb.append(String.format(Locale.ROOT, - "should not have @%s annotation", - annotation)); - return this; - } - - public ExceptionStringBuilder shouldHaveOnlyAnnotations(String... annotations) { - if (sb.length() > 0) sb.append(" "); - String annList = String.join(", @", annotations); - sb.append(String.format(Locale.ROOT, - "should have only @%s annotation", - annList)); - return this; - } - - public ExceptionStringBuilder shouldHaveAnnotations(String... annotations) { - if (sb.length() > 0) sb.append(" "); - String annList = String.join(", @", annotations); - sb.append(String.format(Locale.ROOT, - "should have @%s annotation", - annList)); - return this; - } - - - public ExceptionStringBuilder shouldNoHaveIdentifiers(String identifier) { - if (sb.length() > 0) sb.append(" "); - sb.append(String.format(Locale.ROOT, - "should not have %s identifiers", - identifier)); - return this; - } - - public ExceptionStringBuilder shouldHaveOnlySingleModuleMethod(String moduleType) { - if (sb.length() > 0) sb.append(" "); - sb.append(String.format(Locale.ROOT, - "should have only one module or dependency method. %s has duplicate", - moduleType)); - return this; - } - - public ExceptionStringBuilder shouldNoHaveFields() { - if (sb.length() > 0) sb.append(" "); - sb.append("should not have fields"); - return this; - } - - - public ExceptionStringBuilder shouldImplementInterface(String interfaceType) { - if (sb.length() > 0) sb.append(" "); - sb.append("should implement "); - sb.append(interfaceType); - return this; - } - - public ExceptionStringBuilder shouldHaveConstructorWithoutArgs() { - if (sb.length() > 0) sb.append(" "); - sb.append("should have public constructor without arguments"); - return this; - } - - public ExceptionStringBuilder shouldHaveInjectableClassAsParameter() { - if (sb.length() > 0) sb.append(" "); - sb.append("should have an injection class as a parameter"); - return this; - } - - public ExceptionStringBuilder shouldProvideNonPrimitiveObjects() { - if (sb.length() > 0) sb.append(" "); - sb.append("should provide non primitive objects"); - return this; - } - - - public ExceptionStringBuilder shouldNoHavePrimitiveArguments() { - if (sb.length() > 0) sb.append(" "); - sb.append("should no have primitive arguments"); - return this; - } - - - public ExceptionStringBuilder recursiveProviding() { - if (sb.length() > 0) sb.append(" "); - sb.append("Recursive providing detected"); - return this; - } - - public ExceptionStringBuilder constructorNonFound(String className, List argTypes) { - if (sb.length() > 0) sb.append(" "); - sb.append(String.format(Locale.ROOT, - "No found public constructor for class: %s with args: %s", - className, String.join(", ", argTypes))); - return this; - } - - - public ExceptionStringBuilder typeTransformNonSupport(TypeName or, TypeName dest) { - if (sb.length() > 0) sb.append(" "); - sb.append(String.format(Locale.ROOT, - "Type Transform non support %s -> %s", - or.toString(), dest.toString())); - return this; - } - - - public ExceptionStringBuilder componentInitMethodSignatureIncorrect(String className, String annotation) { - if (sb.length() > 0) sb.append(" "); - sb.append(String.format(Locale.ROOT, - "Component's init method have incorrect signature: '%s'. " - + "Method Should have only one %s annotation. " - + "Should have arguments of module or dependencies. " - + "Should be void.", - className, annotation)); - return this; - } - - - public ExceptionStringBuilder componentExtOfMethodSignatureIncorrect(String className, String annotation) { - if (sb.length() > 0) sb.append(" "); - sb.append(String.format(Locale.ROOT, - "Component's bindInstance method have incorrect signature: '%s'. " - + "Method Should have only %s annotation and GC scope annotations. " - + "Should have only one argument of providing object. " - + "Providing object should not be primitive or boxed primitive. " - + "Can return only providing object or should be void. ", - className, annotation)); - return this; - } - - public ExceptionStringBuilder componentBindInstanceMethodSignatureIncorrect(String className, String annotation) { - if (sb.length() > 0) sb.append(" "); - sb.append(String.format(Locale.ROOT, - "Component's bindInstance method have incorrect signature: '%s'. " - + "Method Should have only %s annotation and GC scope annotations. " - + "Should have only one argument of providing object. " - + "Providing object should not be primitive or boxed primitive. " - + "Can return only providing object or should be void. ", - className, annotation)); - return this; - } - - public ExceptionStringBuilder componentGCMethodSignatureIncorrect(String className, String annotation) { - if (sb.length() > 0) sb.append(" "); - sb.append(String.format(Locale.ROOT, - "Component's gc method have incorrect signature: '%s'. " - + "Method Should have only %s annotation and GC scope annotations. " - + "Should no have arguments. " - + "Should be void.", - className, annotation)); - return this; - } - - public ExceptionStringBuilder componentSwitchCacheMethodSignatureIncorrect(String className, String annotation) { - if (sb.length() > 0) sb.append(" "); - sb.append(String.format(Locale.ROOT, - "Component's SwitchCache method have incorrect signature: '%s'. " - + "Method Should have only %s annotation and GC scope annotations. " - + "Should no have arguments. " - + "Should be void.", - className, annotation)); - return this; - } - - public ExceptionStringBuilder componentProtectInjectedMethodSignatureIncorrect(String className, String annotation) { - if (sb.length() > 0) sb.append(" "); - sb.append(String.format(Locale.ROOT, - "Component's ProtectInjected method have incorrect signature: '%s'. " - + "Method Should have only %s annotation. " - + "Should have only one argument (non primitive and non boxed primitive). " - + "Should be void.", - className, annotation)); - return this; - } - - - public ExceptionStringBuilder componentMethodNameBusy(String methodName) { - if (sb.length() > 0) sb.append(" "); - sb.append(String.format(Locale.ROOT, - "Component's method name '%s' busy by lib's private interfaces", - methodName)); - return this; - } - - public ExceptionStringBuilder add(String mes) { - if (sb.length() > 0) sb.append(" "); - sb.append(mes); - return this; - } - - - public ExceptionStringBuilder collectCauseMessages(Throwable cause) { - while (cause != null) { - if (sb.length() > 0) sb.append("\nCaused by: "); - sb.append(cause.getMessage()); - cause = cause.getCause(); - } - return this; - } - - public String build() { - return sb.toString(); - } - -} diff --git a/stone_processor/src/main/java/com/github/klee0kai/stone/exceptions/ImplementMethodStoneException.java b/stone_processor/src/main/java/com/github/klee0kai/stone/exceptions/ImplementMethodStoneException.java deleted file mode 100644 index c3581c6e..00000000 --- a/stone_processor/src/main/java/com/github/klee0kai/stone/exceptions/ImplementMethodStoneException.java +++ /dev/null @@ -1,15 +0,0 @@ -package com.github.klee0kai.stone.exceptions; - -import javax.lang.model.element.Element; - -public class ImplementMethodStoneException extends StoneException { - - public ImplementMethodStoneException(String message, Throwable cause) { - super(message, cause); - } - - public ImplementMethodStoneException(String message, Throwable cause, Element element) { - super(message, cause, element); - } - -} diff --git a/stone_processor/src/main/java/com/github/klee0kai/stone/exceptions/IncorrectSignatureException.java b/stone_processor/src/main/java/com/github/klee0kai/stone/exceptions/IncorrectSignatureException.java deleted file mode 100644 index f44c0000..00000000 --- a/stone_processor/src/main/java/com/github/klee0kai/stone/exceptions/IncorrectSignatureException.java +++ /dev/null @@ -1,23 +0,0 @@ -package com.github.klee0kai.stone.exceptions; - -import javax.lang.model.element.Element; - -public class IncorrectSignatureException extends StoneException { - - public IncorrectSignatureException(String message) { - super(message, null); - } - - public IncorrectSignatureException(String message, Throwable e) { - super(message, e); - } - - public IncorrectSignatureException(String message, Throwable cause, Element element) { - super(message, cause, element); - } - - public IncorrectSignatureException(String message, Element element) { - super(message, null, element); - } - -} diff --git a/stone_processor/src/main/java/com/github/klee0kai/stone/exceptions/ObjectNotProvidedException.java b/stone_processor/src/main/java/com/github/klee0kai/stone/exceptions/ObjectNotProvidedException.java deleted file mode 100644 index 19333b31..00000000 --- a/stone_processor/src/main/java/com/github/klee0kai/stone/exceptions/ObjectNotProvidedException.java +++ /dev/null @@ -1,22 +0,0 @@ -package com.github.klee0kai.stone.exceptions; - -import javax.lang.model.element.Element; - -public class ObjectNotProvidedException extends StoneException { - - public ObjectNotProvidedException(String message, Throwable cause) { - super(message, cause); - } - - public ObjectNotProvidedException(String message) { - super(message, null, null); - } - - public ObjectNotProvidedException(String message, Throwable cause, Element element) { - super(message, cause, element); - } - - public ObjectNotProvidedException(String message, Element element) { - super(message, null, element); - } -} diff --git a/stone_processor/src/main/java/com/github/klee0kai/stone/exceptions/PrimitiveTypeNonSupportedStoneException.java b/stone_processor/src/main/java/com/github/klee0kai/stone/exceptions/PrimitiveTypeNonSupportedStoneException.java deleted file mode 100644 index 08db9263..00000000 --- a/stone_processor/src/main/java/com/github/klee0kai/stone/exceptions/PrimitiveTypeNonSupportedStoneException.java +++ /dev/null @@ -1,15 +0,0 @@ -package com.github.klee0kai.stone.exceptions; - -import javax.lang.model.element.Element; - -public class PrimitiveTypeNonSupportedStoneException extends StoneException { - - public PrimitiveTypeNonSupportedStoneException(String message, Throwable cause) { - super(message, cause); - } - - public PrimitiveTypeNonSupportedStoneException(String message, Throwable cause, Element element) { - super(message, cause,element); - } - -} diff --git a/stone_processor/src/main/java/com/github/klee0kai/stone/exceptions/RecursiveProviding.java b/stone_processor/src/main/java/com/github/klee0kai/stone/exceptions/RecursiveProviding.java deleted file mode 100644 index 5adced4f..00000000 --- a/stone_processor/src/main/java/com/github/klee0kai/stone/exceptions/RecursiveProviding.java +++ /dev/null @@ -1,19 +0,0 @@ -package com.github.klee0kai.stone.exceptions; - -import javax.lang.model.element.Element; - -public class RecursiveProviding extends StoneException { - - public RecursiveProviding(String message) { - super(message, null); - } - - public RecursiveProviding(String message, Throwable cause) { - super(message, cause); - } - - public RecursiveProviding(String message, Throwable cause, Element element) { - super(message, cause,element); - } - -} diff --git a/stone_processor/src/main/java/com/github/klee0kai/stone/exceptions/StoneException.java b/stone_processor/src/main/java/com/github/klee0kai/stone/exceptions/StoneException.java deleted file mode 100644 index 56de8df9..00000000 --- a/stone_processor/src/main/java/com/github/klee0kai/stone/exceptions/StoneException.java +++ /dev/null @@ -1,28 +0,0 @@ -package com.github.klee0kai.stone.exceptions; - -import javax.lang.model.element.Element; - -public class StoneException extends IllegalStateException { - - public Element errorElement = null; - - public StoneException(String message, Throwable cause) { - super(message, cause); - } - - public StoneException(String message, Throwable cause, Element element) { - this(message, cause); - this.errorElement = element; - } - - public Element findErrorElement() { - Element sourceElement = null; - if (getCause() instanceof StoneException) { - sourceElement = ((StoneException) getCause()).findErrorElement(); - } - if (sourceElement == null) sourceElement = errorElement; - return sourceElement; - } - - -} diff --git a/stone_processor/src/main/java/com/github/klee0kai/stone/helpers/AllClassesHelper.java b/stone_processor/src/main/java/com/github/klee0kai/stone/helpers/AllClassesHelper.java deleted file mode 100644 index e4b7ab84..00000000 --- a/stone_processor/src/main/java/com/github/klee0kai/stone/helpers/AllClassesHelper.java +++ /dev/null @@ -1,212 +0,0 @@ -package com.github.klee0kai.stone.helpers; - -import com.github.klee0kai.stone._hidden_.IModule; -import com.github.klee0kai.stone._hidden_.IPrivateComponent; -import com.github.klee0kai.stone._hidden_.types.ListUtils; -import com.github.klee0kai.stone.annotations.component.GcScopeAnnotation; -import com.github.klee0kai.stone.exceptions.ClassNotFoundStoneException; -import com.github.klee0kai.stone.lifecycle.StoneLifeCycleOwner; -import com.github.klee0kai.stone.model.ClassDetail; -import com.github.klee0kai.stone.model.annotations.ComponentAnn; -import com.github.klee0kai.stone.utils.ClassNameUtils; -import com.squareup.javapoet.ClassName; -import com.squareup.javapoet.TypeName; - -import javax.inject.Named; -import javax.inject.Qualifier; -import javax.inject.Scope; -import javax.lang.model.element.AnnotationMirror; -import javax.lang.model.element.Element; -import javax.lang.model.element.TypeElement; -import javax.lang.model.util.Elements; -import java.util.*; - -import static com.github.klee0kai.stone.exceptions.ExceptionStringBuilder.createErrorMes; - -/** - * Index all elements in projects. - */ -public class AllClassesHelper { - - private Elements elements; - private final Set lifeCycleOwners = new HashSet<>(); - private final Map gcScopeAnnotations = new HashMap<>(); - private final Map qualifierAnnotations = new HashMap<>(); - - public final Set allIdentifiers = new HashSet<>(); - - public ClassDetail iComponentClassDetails; - public ClassDetail iModule; - public ClassDetail iLifeCycleOwner; - - public TypeElement scopeAnnotationElement; - public TypeElement gcScopeAnnotationElement; - - public TypeElement qualifierAnnotationElement; - - - /** - * Index common classes using in lib - * - * @param elements annotation processor's elements - */ - public void reInit(Elements elements) { - lifeCycleOwners.clear(); - gcScopeAnnotations.clear(); - qualifierAnnotations.clear(); - allIdentifiers.clear(); - - this.elements = elements; - iComponentClassDetails = findForType(ClassName.get(IPrivateComponent.class)); - iModule = findForType(ClassName.get(IModule.class)); - iLifeCycleOwner = findForType(ClassName.get(StoneLifeCycleOwner.class)); - - scopeAnnotationElement = typeElementFor(ClassName.get(Scope.class)); - gcScopeAnnotationElement = typeElementFor(ClassName.get(GcScopeAnnotation.class)); - qualifierAnnotationElement = typeElementFor(ClassName.get(Qualifier.class)); - - TypeName namedType = ClassName.get(Named.class); - qualifierAnnotations.putIfAbsent(namedType.toString(), findForType(namedType)); - } - - /** - * Collect all using GcScope annotations in component and all in component's parents. - * After the method you can use findGcScopeAnnotation to get annotation details - * - * @param classDetail component's ClassDetail object - */ - public void deepExtractAdditionalClasses(ClassDetail classDetail) { - for (ClassDetail parent : classDetail.getAllParents(false)) { - TypeElement parentEl = typeElementFor(parent.className); - ComponentAnn parentCompAnn = parent.ann(ComponentAnn.class); - if (parentCompAnn != null) allIdentifiers.addAll(parentCompAnn.identifiers); - - for (Element methodEl : parentEl.getEnclosedElements()) { - for (AnnotationMirror ann : methodEl.getAnnotationMirrors()) { - List methodAnnotations = ann.getAnnotationType().asElement().getAnnotationMirrors(); - // add as GC Scope - boolean isScopeAnnotated = ListUtils.contains(methodAnnotations, (inx, it) -> { - Element annEl = it.getAnnotationType().asElement(); - return Objects.equals(annEl, scopeAnnotationElement) || Objects.equals(annEl, gcScopeAnnotationElement); - }); - if (isScopeAnnotated) { - String annClName = ann.getAnnotationType().toString(); - ClassDetail annClDetails = new ClassDetail(typeElementFor(annClName)); - gcScopeAnnotations.put(annClDetails.className.toString(), annClDetails); - } - - // add as Qualifier Annotation - boolean isQualifierAnnotated = ListUtils.contains(methodAnnotations, (inx, it) -> { - Element annEl = it.getAnnotationType().asElement(); - return Objects.equals(annEl, qualifierAnnotationElement); - }); - if (isQualifierAnnotated) { - String annClName = ann.getAnnotationType().toString(); - ClassDetail annClDetails = new ClassDetail(typeElementFor(annClName)); - qualifierAnnotations.put(annClDetails.className.toString(), annClDetails); - } - } - } - } - } - - - /** - * Get annotation details for annotation name - * - * @param annTypeName full class name - * @return ClassDetail object of the annotation if found - */ - public ClassDetail findGcScopeAnnotation(String annTypeName) { - return gcScopeAnnotations.getOrDefault(annTypeName, null); - } - - public ClassDetail findQualifierAnnotation(String annTypeName) { - return qualifierAnnotations.getOrDefault(annTypeName, null); - } - - /** - * Check that class is implement stone lifecycle owner. - * {@link StoneLifeCycleOwner} - * - * @param typeName class name - * @return true if this class implement {@link StoneLifeCycleOwner} - */ - public boolean isLifeCycleOwner(TypeName typeName) { - if (lifeCycleOwners.contains(typeName)) - return true; - ClassDetail cl = findForType(typeName); - if (cl.isExtOf(iLifeCycleOwner.className)) { - lifeCycleOwners.add(typeName); - return true; - } - return false; - } - - /** - * Find class details of type. - * May throw exception - * - * @param typeName type name - * @return {@link ClassDetail} if found - */ - public ClassDetail findForType(TypeName typeName) { - try { - TypeName rawType = ClassNameUtils.rawTypeOf(typeName); - if (rawType instanceof ClassName) { - ClassDetail cl = new ClassDetail(elements.getTypeElement(((ClassName) rawType).canonicalName())); - cl.className = typeName; - return cl; - } - return null; - } catch (Exception e) { - throw new ClassNotFoundStoneException( - createErrorMes() - .classNonFound(typeName.toString()) - .build(), - e - ); - } - } - - /** - * Find class details of type. - * - * @param typeName type name - * @return {@link ClassDetail} if found or null - */ - public ClassDetail tryFindForType(TypeName typeName) { - try { - return findForType(typeName); - } catch (Exception e) { - return null; - } - } - - /** - * Find compile element of typename - * - * @param typeName typename - * @return compile element if found - */ - public TypeElement typeElementFor(TypeName typeName) { - if (typeName instanceof ClassName) - return elements.getTypeElement(((ClassName) typeName).canonicalName()); - return null; - } - - /** - * Find compile element of typename - * - * @param canonicalName type canonical name - * @return compile element if found - */ - public TypeElement typeElementFor(String canonicalName) { - return elements.getTypeElement(canonicalName); - } - - public TypeElement typeElementFor(ClassName canonicalName) { - return elements.getTypeElement(canonicalName.canonicalName()); - } - -} diff --git a/stone_processor/src/main/java/com/github/klee0kai/stone/helpers/SetFieldHelper.java b/stone_processor/src/main/java/com/github/klee0kai/stone/helpers/SetFieldHelper.java deleted file mode 100644 index 037dd755..00000000 --- a/stone_processor/src/main/java/com/github/klee0kai/stone/helpers/SetFieldHelper.java +++ /dev/null @@ -1,80 +0,0 @@ -package com.github.klee0kai.stone.helpers; - -import com.github.klee0kai.stone.model.ClassDetail; -import com.github.klee0kai.stone.model.FieldDetail; -import com.github.klee0kai.stone.model.MethodDetail; -import com.squareup.javapoet.CodeBlock; - -import java.util.Locale; - -public class SetFieldHelper { - - private final FieldDetail fieldDetail; - private MethodDetail kotlinGetMethod = null, kotlinSetMethod = null; - - public static String capitalized(String str) { - return str.substring(0, 1).toUpperCase(Locale.ROOT) + str.substring(1); - } - - /** - * @param fieldDetail - * @param fieldOwner class where field is declare - */ - public SetFieldHelper(FieldDetail fieldDetail, ClassDetail fieldOwner) { - this.fieldDetail = fieldDetail; - - // check kotlin field - String capitalizedName = capitalized(fieldDetail.name); - MethodDetail getMethod = fieldOwner.findMethod( - MethodDetail.simpleGetMethod("get" + capitalizedName, fieldDetail.type), - true - ); - MethodDetail setMethod = fieldOwner.findMethod( - MethodDetail.simpleSetMethod("set" + capitalizedName, fieldDetail.type), - true - ); - - kotlinGetMethod = fieldOwner.findMethod(getMethod, true); - kotlinSetMethod = fieldOwner.findMethod(setMethod, true); - } - - /** - * set value code - * - * @param valueCode set value code - * @return - */ - public CodeBlock codeSetField(CodeBlock valueCode) { - if (isKotlinField()) { - return CodeBlock.of( - "$L( $L )", - kotlinSetMethod.methodName, valueCode - ); - } else { - return CodeBlock.of( - "$L = $L", - fieldDetail.name, valueCode - ); - } - } - - - /** - * get original value code - * - * @return - */ - public CodeBlock codeGetField() { - if (isKotlinField()) { - return CodeBlock.of("$L()", kotlinGetMethod.methodName); - } else { - return CodeBlock.of("$L", fieldDetail.name); - } - } - - private boolean isKotlinField() { - return kotlinGetMethod != null && kotlinSetMethod != null; - } - - -} diff --git a/stone_processor/src/main/java/com/github/klee0kai/stone/helpers/codebuilder/DelayedCode.java b/stone_processor/src/main/java/com/github/klee0kai/stone/helpers/codebuilder/DelayedCode.java deleted file mode 100644 index 942ac352..00000000 --- a/stone_processor/src/main/java/com/github/klee0kai/stone/helpers/codebuilder/DelayedCode.java +++ /dev/null @@ -1,7 +0,0 @@ -package com.github.klee0kai.stone.helpers.codebuilder; - -public interface DelayedCode extends ISmartCode { - - SmartCode apply(SmartCode builder); - -} diff --git a/stone_processor/src/main/java/com/github/klee0kai/stone/helpers/codebuilder/ISmartCode.java b/stone_processor/src/main/java/com/github/klee0kai/stone/helpers/codebuilder/ISmartCode.java deleted file mode 100644 index 1aaa4125..00000000 --- a/stone_processor/src/main/java/com/github/klee0kai/stone/helpers/codebuilder/ISmartCode.java +++ /dev/null @@ -1,5 +0,0 @@ -package com.github.klee0kai.stone.helpers.codebuilder; - -public interface ISmartCode { - -} diff --git a/stone_processor/src/main/java/com/github/klee0kai/stone/helpers/codebuilder/SmartCode.java b/stone_processor/src/main/java/com/github/klee0kai/stone/helpers/codebuilder/SmartCode.java deleted file mode 100644 index c6b9e12a..00000000 --- a/stone_processor/src/main/java/com/github/klee0kai/stone/helpers/codebuilder/SmartCode.java +++ /dev/null @@ -1,184 +0,0 @@ -package com.github.klee0kai.stone.helpers.codebuilder; - -import com.github.klee0kai.stone.model.FieldDetail; -import com.github.klee0kai.stone.model.annotations.QualifierAnn; -import com.squareup.javapoet.CodeBlock; -import com.squareup.javapoet.TypeName; - -import java.util.*; - -public class SmartCode implements ISmartCode { - - private static final boolean REMOVE_NON_USED = true; - - // atom meta info - private CodeBlock code = null; - public String fieldName; - public Set qualifierAnns = new HashSet<>(); - public TypeName providingType; - - public LinkedList usedFields = new LinkedList<>(); - - - // code group info - private Set declaredFields = Collections.emptySet(); - - private final LinkedList codes = new LinkedList<>(); - - private final LinkedList collectedCode = new LinkedList<>(); - - - public static SmartCode of(CodeBlock code, Collection usedFields) { - SmartCode builder = new SmartCode(); - builder.code = code; - if (usedFields != null) builder.usedFields.addAll(usedFields); - return builder; - } - - public static SmartCode of(String code, Collection usedFields) { - SmartCode builder = new SmartCode(); - builder.code = CodeBlock.of(code); - if (usedFields != null) builder.usedFields.addAll(usedFields); - return builder; - } - - public static SmartCode of(CodeBlock code) { - return of(code, null); - } - - public static SmartCode of(String code) { - return of(code, null); - } - - // delayed code block - private SmartCode() { - - } - - public static SmartCode builder() { - return new SmartCode(); - } - - //meta info - - public SmartCode providingType(TypeName typeName) { - providingType = typeName; - return this; - } - - // public methods - - public SmartCode withLocals(DelayedCode codeGen) { - codes.add(codeGen); - return this; - } - - public SmartCode add(SmartCode code) { - codes.add(code); - if (providingType == null) providingType = code.providingType; - return this; - } - - - public SmartCode add(String code, Collection usedFields) { - return add(SmartCode.of(code, usedFields)); - } - - public SmartCode add(String code) { - return add(code, null); - } - - public SmartCode add(CodeBlock codeBlock, Collection usedFields) { - return add(SmartCode.of(codeBlock, usedFields)); - } - - public SmartCode add(CodeBlock codeBlock) { - return add(codeBlock, null); - } - - - public SmartCode localVariable(String fieldName, Set qualifiers, SmartCode initVariable) { - this.providingType = initVariable.providingType; - this.fieldName = fieldName; - this.qualifierAnns.addAll(qualifiers); - - add(CodeBlock.of("$T $L = ", providingType, fieldName), null); - add(initVariable); - add(";\n"); - return this; - } - - public int getSize() { - int size = 1; - for (ISmartCode s : codes) { - if (s instanceof SmartCode) size += ((SmartCode) s).getSize(); - } - return size; - } - - public List getDeclaredFields() { - return new ArrayList<>(declaredFields); - } - - public CodeBlock build(Collection declaredFields) { - clearAllCollectedCodes(); - return internalBuild(declaredFields == null ? new HashSet<>() : new HashSet<>(declaredFields)); - } - - private void clearAllCollectedCodes() { - collectedCode.clear(); - for (ISmartCode s : codes) { - if (s instanceof SmartCode) ((SmartCode) s).clearAllCollectedCodes(); - } - } - - private CodeBlock internalBuild(HashSet declaredFields) { - collect(declaredFields); - - CodeBlock.Builder builder = CodeBlock.builder(); - if (code != null) builder.add(code); - for (SmartCode c : collectedCode) { - if (REMOVE_NON_USED && c.fieldName != null && !usedFields.contains(c.fieldName)) { - continue; - } - - builder.add(c.internalBuild(declaredFields)); - } - - return builder.build(); - } - - private SmartCode collect(HashSet declaredFields) { - if (!collectedCode.isEmpty()) return this; - - this.declaredFields = declaredFields; - - for (ISmartCode c : codes) { - SmartCode smartCode = null; - if (c instanceof DelayedCode) { - DelayedCode delayedCode = (DelayedCode) c; - smartCode = SmartCode.builder(); - - smartCode.declaredFields = declaredFields; - smartCode = delayedCode.apply(smartCode); - - smartCode.declaredFields = declaredFields; - } else if (c instanceof SmartCode) { - smartCode = (SmartCode) c; - } - if (smartCode == null) continue; - collectedCode.add(smartCode.collect(declaredFields)); - - if (smartCode.fieldName != null && smartCode.providingType != null) { - FieldDetail field = FieldDetail.simple(smartCode.fieldName, smartCode.providingType); - field.qualifierAnns = smartCode.qualifierAnns; - declaredFields.add(field); - } - usedFields.addAll(smartCode.usedFields); - } - - this.declaredFields = Collections.emptySet(); - return this; - } - -} diff --git a/stone_processor/src/main/java/com/github/klee0kai/stone/helpers/invokecall/GenArgumentFunctions.java b/stone_processor/src/main/java/com/github/klee0kai/stone/helpers/invokecall/GenArgumentFunctions.java deleted file mode 100644 index 53b90fb8..00000000 --- a/stone_processor/src/main/java/com/github/klee0kai/stone/helpers/invokecall/GenArgumentFunctions.java +++ /dev/null @@ -1,48 +0,0 @@ -package com.github.klee0kai.stone.helpers.invokecall; - -import com.github.klee0kai.stone._hidden_.types.ListUtils; -import com.github.klee0kai.stone.model.FieldDetail; -import com.github.klee0kai.stone.model.Pair; -import com.github.klee0kai.stone.wrappers.PhantomProvide; -import com.squareup.javapoet.ClassName; -import com.squareup.javapoet.CodeBlock; -import com.squareup.javapoet.ParameterizedTypeName; -import com.squareup.javapoet.TypeName; - -import java.util.List; -import java.util.Objects; -import java.util.function.Function; - -public class GenArgumentFunctions { - - /** - * Simple unwrap argument from wrapped type (WeakReference and other). - * If you have arguments like
- * {@code Provide someVariable;}
- * unwrapArgument support to unwrap SomeClass type on invoke method, like
- * {@code doSmth(someVariable.provide()) } - * - * @param envFields available fields - * @return unwrapped field get code, or null - */ - public static Function unwrapArgument(List envFields) { - List> provideFields = ListUtils.format(envFields, it -> { - if (it.type instanceof ParameterizedTypeName) { - ParameterizedTypeName type = (ParameterizedTypeName) it.type; - TypeName orType = type.typeArguments.get(type.typeArguments.size() - 1); - if (Objects.equals(type.rawType, ClassName.get(PhantomProvide.class))) - return new Pair<>(orType, it.name + ".get()"); - } - return new Pair<>(it.type, it.name); - }); - - return wannaType -> { - for (Pair provideField : provideFields) { - if (Objects.equals(wannaType, provideField.first)) - return CodeBlock.of(provideField.second); - } - return null; - }; - } - -} diff --git a/stone_processor/src/main/java/com/github/klee0kai/stone/helpers/invokecall/InvokeCall.java b/stone_processor/src/main/java/com/github/klee0kai/stone/helpers/invokecall/InvokeCall.java deleted file mode 100644 index fc960b14..00000000 --- a/stone_processor/src/main/java/com/github/klee0kai/stone/helpers/invokecall/InvokeCall.java +++ /dev/null @@ -1,280 +0,0 @@ -package com.github.klee0kai.stone.helpers.invokecall; - -import com.github.klee0kai.stone._hidden_.provide.ProvideBuilder; -import com.github.klee0kai.stone._hidden_.types.ListUtils; -import com.github.klee0kai.stone.helpers.codebuilder.SmartCode; -import com.github.klee0kai.stone.helpers.wrap.WrapHelper; -import com.github.klee0kai.stone.model.FieldDetail; -import com.github.klee0kai.stone.model.MethodDetail; -import com.github.klee0kai.stone.model.annotations.QualifierAnn; -import com.squareup.javapoet.ClassName; -import com.squareup.javapoet.CodeBlock; -import com.squareup.javapoet.ParameterizedTypeName; -import com.squareup.javapoet.TypeName; - -import java.util.*; -import java.util.function.Function; - -import static com.github.klee0kai.stone.helpers.invokecall.GenArgumentFunctions.unwrapArgument; -import static com.github.klee0kai.stone.helpers.wrap.WrapHelper.*; -import static com.github.klee0kai.stone.utils.LocalFieldName.genLocalFieldName; -import static java.util.Collections.singleton; - -/** - * Invoke sequence or call sequence. - * Like someMethod1(arg1,arg2).someMethod2(arg3).someMethod3() - *

- * Describe method names and using arguments for code generation. - * Arguments for chaining are reused by type. - */ -public class InvokeCall { - - /** - * Invoke sequence provides the object, which caching in DI. - */ - public static final int INVOKE_PROVIDE_OBJECT_CACHED = 0x1; - /** - * ignore recursive providing for bind instances - */ - public static final int INVOKE_PROVIDE_BIND_INSTANCE = 0x2; - - public final List> invokeSequenceVariants = new LinkedList<>(); - public final int flags; - - /** - * Create new invoke sequence - * - * @param callSequence ordered methods in invoke sequence - */ - public InvokeCall(MethodDetail... callSequence) { - this.flags = 0; - this.invokeSequenceVariants.add(Arrays.asList(callSequence)); - } - - /** - * Create new invoke sequence - * - * @param flags available flags: - * {@code INVOKE_PROVIDE_OBJECT_CACHED} providing cached object - * @param callSequence ordered methods in invoke sequence - */ - public InvokeCall(int flags, MethodDetail... callSequence) { - this.flags = flags; - this.invokeSequenceVariants.add(Arrays.asList(callSequence)); - } - - /** - * Merge variants. All should return same type - * - * @param variants all variants from best to worse - */ - public InvokeCall(Collection variants) { - int mergeflag = 0; - for (InvokeCall v : variants) { - mergeflag |= v.flags; - this.invokeSequenceVariants.addAll(v.invokeSequenceVariants); - } - this.flags = mergeflag; - } - - - public List bestSequence() { - return invokeSequenceVariants.get(0); - } - - public Set qualifierAnnotations(boolean crossing) { - List> allQualifiersLists = new LinkedList<>(new HashSet<>()); - for (List variant : invokeSequenceVariants) { - Set qualifiers = new HashSet<>(); - for (MethodDetail m : variant) qualifiers.addAll(m.qualifierAnns); - allQualifiersLists.add(qualifiers); - } - if (allQualifiersLists.isEmpty()) return Collections.emptySet(); - - Set allQualifiers = allQualifiersLists.get(0); - if (crossing) { - for (Set q : allQualifiersLists) allQualifiers.retainAll(q); - } else { - for (Set q : allQualifiersLists) allQualifiers.addAll(q); - } - return allQualifiers; - } - - /** - * Using arguments in invoke sequence - * - * @return collection of all argument's types - */ - public Set argDeps() { - Set argsTypes = new HashSet<>(); - for (List invokeSequence : invokeSequenceVariants) - for (MethodDetail m : invokeSequence) { - List types = ListUtils.format(m.args, (it) -> new ProvideDep(it.type, it.qualifierAnns)); - argsTypes.addAll(types); - } - return argsTypes; - } - - /** - * Providing type in this invoke sequence - * - * @return return type - */ - public TypeName resultType() { - return nonWrappedType(rawReturnType()); - } - - public TypeName rawReturnType() { - List invokeSequence = bestSequence(); - return invokeSequence.get(invokeSequence.size() - 1).returnType; - } - - /** - * Generate invoke code bloke - * - * @param envFields predefined arguments in generated code - * @param argGen argument generator, if non found in envFields - * @return new code block without semicolon - */ - @SafeVarargs - public final CodeBlock invokeCode( - List envFields, - Function... argGen - ) { - List> argGens = new LinkedList<>(); - argGens.add(unwrapArgument(envFields)); - argGens.addAll(Arrays.asList(argGen)); - - CodeBlock.Builder invokeBuilder = CodeBlock.builder(); - int invokeCount = 0; - for (MethodDetail m : bestSequence()) { - int argCount = 0; - CodeBlock.Builder argsCodeBuilder = CodeBlock.builder(); - for (FieldDetail arg : m.args) { - if (argCount++ > 0) argsCodeBuilder.add(","); - CodeBlock argCode = ListUtils.firstNotNull(argGens, it -> it.apply(arg.type)); - argsCodeBuilder.add(argCode != null ? argCode : CodeBlock.of("null")); - } - - if (invokeCount++ > 0) invokeBuilder.add("."); - invokeBuilder.add("$L($L)", m.methodName, argsCodeBuilder.build()); - } - return invokeBuilder.build(); - } - - public SmartCode invokeBest() { - return SmartCode - .builder() - .providingType(resultType()) - .withLocals(builder -> transform(invokeSequence(bestSequence()), resultType())); - } - - public SmartCode invokeAllToList() { - TypeName provType = ParameterizedTypeName.get(ClassName.get(List.class), resultType()); - return SmartCode - .builder() - .providingType(provType) - .withLocals(builder -> { - String listFieldName = genLocalFieldName(); - builder.add(CodeBlock.of("new $T( ( $L ) -> { \n", - ParameterizedTypeName.get(ClassName.get(ProvideBuilder.class), resultType()), listFieldName - )); - for (List sequence : invokeSequenceVariants) { - SmartCode seqCode = invokeSequence(sequence); - if (WrapHelper.isList(seqCode.providingType)) { - builder.add(listFieldName) - .add(".addAll(") - .add(transform(seqCode, provType)) - .add(");\n"); - } else { - builder.add(listFieldName) - .add(".add(") - .add(transform(seqCode, resultType())) - .add(");\n"); - } - } - builder.add(" }).all() "); - return builder; - }); - } - - - private SmartCode invokeSequence(List sequence) { - return SmartCode.builder().withLocals(builder -> { - int invokeCount = 0; - for (MethodDetail m : sequence) { - if (invokeCount++ > 0) builder.add("."); - builder.add(m.methodName) - .add("("); - - int argCount = 0; - for (FieldDetail arg : m.args) { - if (argCount++ > 0) builder.add(", "); - boolean isList = isList(arg.type); - List typeFields = ListUtils.filter(builder.getDeclaredFields(), (i, f) -> - Objects.equals(nonWrappedType(f.type), nonWrappedType(arg.type))); - - FieldDetail field = isList ? ListUtils.first(typeFields, (i, f) -> - isList(f.type) && Objects.equals(f.qualifierAnns, arg.qualifierAnns) - ) : null; - if (field == null) { - //non list - field = ListUtils.first(typeFields, (i, f) -> Objects.equals(f.qualifierAnns, arg.qualifierAnns)); - } - - if (field == null) { - builder.add("null", null); - } else { - // unwrap type - builder.add( - transform(SmartCode.of(field.name, singleton(field.name)) - .providingType(field.type), - arg.type - )); - } - } - - builder.add(")"); - } - return builder; - }) - .providingType(sequence.get(sequence.size() - 1).returnType); - } - - @Override - public String toString() { - StringBuilder builder = new StringBuilder(); - if (invokeSequenceVariants.size() <= 1) - for (QualifierAnn qualifierAnn : qualifierAnnotations(false)) { - builder.append(qualifierAnn.toString()) - .append(" "); - } - int variantIndx = 0; - for (List variant : invokeSequenceVariants) { - if (variantIndx++ > 0) builder.append(";\n"); - int secIndx = 0; - for (MethodDetail m : variant) { - if (secIndx++ > 0) builder.append("."); - builder.append(m.methodName) - .append("(") - .append(String.join(",", ListUtils.format(m.args, f -> f.type.toString()))) - .append(")"); - } - } - return builder.toString(); - } - - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - InvokeCall that = (InvokeCall) o; - return Objects.equals(invokeSequenceVariants, that.invokeSequenceVariants); - } - - @Override - public int hashCode() { - return Objects.hash(invokeSequenceVariants); - } -} diff --git a/stone_processor/src/main/java/com/github/klee0kai/stone/helpers/invokecall/ModulesGraph.java b/stone_processor/src/main/java/com/github/klee0kai/stone/helpers/invokecall/ModulesGraph.java deleted file mode 100644 index f11bb327..00000000 --- a/stone_processor/src/main/java/com/github/klee0kai/stone/helpers/invokecall/ModulesGraph.java +++ /dev/null @@ -1,300 +0,0 @@ -package com.github.klee0kai.stone.helpers.invokecall; - -import com.github.klee0kai.stone.AnnotationProcessor; -import com.github.klee0kai.stone._hidden_.provide.ProvideBuilder; -import com.github.klee0kai.stone._hidden_.types.CacheAction; -import com.github.klee0kai.stone._hidden_.types.ListUtils; -import com.github.klee0kai.stone.exceptions.IncorrectSignatureException; -import com.github.klee0kai.stone.exceptions.ObjectNotProvidedException; -import com.github.klee0kai.stone.exceptions.RecursiveProviding; -import com.github.klee0kai.stone.exceptions.StoneException; -import com.github.klee0kai.stone.helpers.codebuilder.SmartCode; -import com.github.klee0kai.stone.helpers.wrap.WrapHelper; -import com.github.klee0kai.stone.model.ClassDetail; -import com.github.klee0kai.stone.model.FieldDetail; -import com.github.klee0kai.stone.model.MethodDetail; -import com.github.klee0kai.stone.model.annotations.BindInstanceAnn; -import com.github.klee0kai.stone.model.annotations.ProvideAnn; -import com.github.klee0kai.stone.model.annotations.QualifierAnn; -import com.github.klee0kai.stone.utils.RecursiveDetector; -import com.github.klee0kai.stone.wrappers.Ref; -import com.squareup.javapoet.ClassName; -import com.squareup.javapoet.CodeBlock; -import com.squareup.javapoet.ParameterizedTypeName; -import com.squareup.javapoet.TypeName; - -import java.util.*; - -import static com.github.klee0kai.stone.AnnotationProcessor.allClassesHelper; -import static com.github.klee0kai.stone.codegen.ModuleCacheControlInterfaceBuilder.cacheControlMethodName; -import static com.github.klee0kai.stone.exceptions.ExceptionStringBuilder.createErrorMes; -import static com.github.klee0kai.stone.helpers.invokecall.InvokeCall.INVOKE_PROVIDE_BIND_INSTANCE; -import static com.github.klee0kai.stone.helpers.invokecall.InvokeCall.INVOKE_PROVIDE_OBJECT_CACHED; -import static com.github.klee0kai.stone.helpers.wrap.WrapHelper.*; -import static com.github.klee0kai.stone.utils.LocalFieldName.genLocalFieldName; -import static java.util.Collections.singleton; - -public class ModulesGraph { - - public static boolean SIMPLE_PROVIDE_OPTIMIZING = true; - public static int MAX_PROVIDE_RESOLVE_COUNT = 10_000; - - private final HashMap> provideTypeCodes = new HashMap<>(); - private final HashMap> cacheControlTypeCodes = new HashMap<>(); - - - /** - * Methods graph build. - * - * @param provideModuleMethod module's provide method - * @param module module's class - */ - public void collectFromModule(MethodDetail provideModuleMethod, ClassDetail module) { - ClassDetail iModuleInterface = AnnotationProcessor.allClassesHelper.iModule; - for (MethodDetail m : module.getAllMethods(false, true, "")) { - TypeName provTypeName = nonWrappedType(m.returnType); - if (provTypeName.isPrimitive() || provTypeName == TypeName.VOID) - continue; - if (iModuleInterface.findMethod(m, false) != null) - continue; - boolean isCached = !m.hasAnnotations(ProvideAnn.class) || m.ann(ProvideAnn.class).isCachingProvideType(); - boolean isBindInstance = m.hasAnnotations(BindInstanceAnn.class); - int invokeProvideFlags = isCached ? INVOKE_PROVIDE_OBJECT_CACHED : 0; - invokeProvideFlags |= isBindInstance ? INVOKE_PROVIDE_BIND_INSTANCE : 0; - - provideTypeCodes.putIfAbsent(provTypeName, new HashSet<>()); - provideTypeCodes.get(provTypeName).add(new InvokeCall(invokeProvideFlags, provideModuleMethod, m)); - - MethodDetail cacheControlMethod = new MethodDetail(); - cacheControlMethod.methodName = cacheControlMethodName(m.methodName); - cacheControlMethod.args.add(FieldDetail.simple("__action", ClassName.get(CacheAction.class))); - for (FieldDetail it : m.args) { - if (!((it.type instanceof ClassName) && allClassesHelper.allIdentifiers.contains(it.type))) - continue; - cacheControlMethod.args.add(it); - } - cacheControlMethod.returnType = listWrapTypeIfNeed(m.returnType); - cacheControlMethod.qualifierAnns = m.qualifierAnns; - - cacheControlTypeCodes.putIfAbsent(provTypeName, new HashSet<>()); - cacheControlTypeCodes.get(provTypeName).add(new InvokeCall(provideModuleMethod, cacheControlMethod)); - } - } - - public SmartCode codeProvideType(String methodName, TypeName returnType, Set qualifierAnns) { - boolean isWrappedReturn = isSupport(returnType); - boolean isListReturn = isList(returnType); - TypeName providingType = isWrappedReturn ? nonWrappedType(returnType) : returnType; - - List provideTypeInvokes = provideInvokesWithDeps(new ProvideDep(methodName, returnType, qualifierAnns)); - if (provideTypeInvokes == null || provideTypeInvokes.isEmpty()) { - return null; - } - - if (SIMPLE_PROVIDE_OPTIMIZING && provideTypeInvokes.size() == 1 && !isListReturn) { - InvokeCall invokeCall = provideTypeInvokes.get(0); - return WrapHelper.transform( - SmartCode.builder() - .add(invokeCall.invokeBest()) - .providingType(invokeCall.resultType()), - returnType); - } - - SmartCode builder = SmartCode.builder(); - TypeName provideBuilder = ParameterizedTypeName.get(ClassName.get(ProvideBuilder.class), providingType); - TypeName provideBuilderList = ParameterizedTypeName.get(ClassName.get(Collection.class), providingType); - String listFieldName = genLocalFieldName(); - builder.add(CodeBlock.of("new $T( ( $L ) -> { \n", provideBuilder, listFieldName), null); - - for (InvokeCall inv : provideTypeInvokes) { - boolean isCacheProvide = (inv.flags & INVOKE_PROVIDE_OBJECT_CACHED) != 0; - FieldDetail singleDepField = FieldDetail.simple(genLocalFieldName(), null); - FieldDetail listDepField = FieldDetail.simple(genLocalFieldName(), null); - boolean isListInv = inv.invokeSequenceVariants.size() > 1; - - builder.withLocals(localBuilder -> { - // provide single objects - if (isCacheProvide) { - localBuilder.localVariable(singleDepField.name, inv.qualifierAnnotations(true), inv.invokeBest()); - singleDepField.type = inv.resultType(); - } else { - singleDepField.type = ParameterizedTypeName.get(ClassName.get(Ref.class), inv.resultType()); - localBuilder.localVariable(singleDepField.name, inv.qualifierAnnotations(true), SmartCode.builder() - .add("() -> ") - .add(inv.invokeBest()) - .providingType(singleDepField.type) - ); - } - return localBuilder; - }); - - builder.withLocals(localBuilder -> { - // provide list objects - listDepField.type = ParameterizedTypeName.get(ClassName.get(Ref.class), - ParameterizedTypeName.get(ClassName.get(List.class), inv.resultType()) - ); - localBuilder.localVariable(listDepField.name, inv.qualifierAnnotations(true), SmartCode.builder() - .add("() -> ") - .add(inv.invokeAllToList()) - .providingType(listDepField.type) - ); - return localBuilder; - }); - - if (Objects.equals(inv.resultType(), providingType)) { - builder.withLocals(localBuilder -> { - if (isListReturn) { - localBuilder - .add(listFieldName) - .add(".addAll( ") - .add( - transform( - SmartCode.of(listDepField.name, singleton(listDepField.name)) - .providingType(listDepField.type), - provideBuilderList - ) - ).add(");\n"); - } else { - localBuilder - .add(listFieldName) - .add(".add( ") - .add( - transform( - SmartCode.of(singleDepField.name, singleton(singleDepField.name)) - .providingType(singleDepField.type), - providingType - ) - ).add(");\n"); - - } - return localBuilder; - }); - if (!isListReturn) - break; - } - } - - - builder.add("\n })"); - if (WrapHelper.isList(returnType)) { - builder.add(".all() ") - .providingType(ParameterizedTypeName.get(ClassName.get(List.class), providingType)); - } else { - builder.add(".first() ") - .providingType(providingType); - } - return WrapHelper.transform(builder, returnType); - } - - - public List provideInvokesWithDeps(ProvideDep provideDep) { - LinkedList provideTypeInvokes = new LinkedList<>(); - LinkedList needProvideDeps = new LinkedList<>(); - RecursiveDetector needProvideDepsRecursiveDetector = new RecursiveDetector<>(); - needProvideDeps.add(provideDep); - int loopCount = 0; - - // provide dependencies while not provide all - while (!needProvideDeps.isEmpty()) { - ProvideDep rawDep = needProvideDeps.pollFirst(); - TypeName dep = nonWrappedType(rawDep.typeName); - InvokeCall invokeCall = provideTypeInvokeCall(provideTypeCodes, dep, rawDep.qualifierAnns, rawDep.methodName, isList(rawDep.typeName)); - if (invokeCall == null) { - if (Objects.equals(provideDep, rawDep)) { - return null; - } - - throw new ObjectNotProvidedException( - createErrorMes() - .errorProvideType(dep.toString()) - .build() - ); - } - - boolean isBindInstanceInvoke = (invokeCall.flags & INVOKE_PROVIDE_BIND_INSTANCE) != 0; - List newDeps = ListUtils.filter(invokeCall.argDeps(), (i, it) -> { - if (isBindInstanceInvoke && Objects.equals(rawDep.typeName, it.typeName)) { - // bind instance case. Argument and return type are equals - return false; - } - // qualifies not need to provide - TypeName argNonWrapped = nonWrappedType(it.typeName); - return argNonWrapped instanceof ClassName && !allClassesHelper.allIdentifiers.contains(argNonWrapped); - }); - - needProvideDeps.addAll(newDeps); - needProvideDeps = ListUtils.removeDoublesRight(needProvideDeps, Objects::equals); - boolean recursiveDetected = !newDeps.isEmpty() && needProvideDepsRecursiveDetector.next(needProvideDeps.hashCode()); - if (recursiveDetected) { - throw new RecursiveProviding( - createErrorMes() - .errorProvideType(provideDep.typeName.toString()) - .recursiveProviding() - .build() - ); - } - if (loopCount++ > MAX_PROVIDE_RESOLVE_COUNT) { - throw new StoneException( - createErrorMes() - .errorProvideType(provideDep.typeName.toString()) - .add("long providing loop for type. Stone library Error.") - .build(), - null - ); - } - - provideTypeInvokes.add(invokeCall); - provideTypeInvokes = ListUtils.removeDoublesRight(provideTypeInvokes, (it1, it2) -> { - return Objects.equals(it1.resultType(), it2.resultType()) - && Objects.equals(it1.qualifierAnnotations(true), it2.qualifierAnnotations(true)); - }); - - } - Collections.reverse(provideTypeInvokes); - return provideTypeInvokes; - } - - /** - * Generate cache control method invoke. Clean refs, change ref type and other - * - * @param provideMethodName predefined method name - * @param typeName the name of the type whose cache needs to be changed - * @return cache control invoke call - */ - public InvokeCall invokeControlCacheForType(String provideMethodName, TypeName typeName, Set qualifierAnns) { - String cacheControlMethodName = cacheControlMethodName(provideMethodName); - return provideTypeInvokeCall(cacheControlTypeCodes, typeName, qualifierAnns, cacheControlMethodName, false); - } - - private InvokeCall provideTypeInvokeCall( - HashMap> provideTypeCodes, - TypeName typeName, - Set qualifierAnns, - String provideMethodName, - boolean listVariants - ) { - Set invokeCalls = provideTypeCodes.getOrDefault(typeName, null); - if (invokeCalls == null || invokeCalls.isEmpty()) - return null; - List filtered = !listVariants || qualifierAnns != null && !qualifierAnns.isEmpty() - ? ListUtils.filter(invokeCalls, (i, it) -> Objects.equals(it.qualifierAnnotations(false), qualifierAnns)) - : new LinkedList<>(invokeCalls); - - filtered = provideMethodName != null ? ListUtils.filter(filtered, (i, it) -> { - int len = it.bestSequence().size(); - String mName = it.bestSequence().get(len - 1).methodName; - return Objects.equals(provideMethodName, mName); - }) : filtered; - - if (!listVariants && filtered.size() > 1) { - throw new IncorrectSignatureException( - createErrorMes() - .errorProvideType(typeName.toString()) - .add(": is bound multi times.\n") - .add(String.join(" and \n", ListUtils.format(filtered, InvokeCall::toString))) - .build()); - } - return !filtered.isEmpty() ? new InvokeCall(filtered) : null; - } - -} diff --git a/stone_processor/src/main/java/com/github/klee0kai/stone/helpers/invokecall/ProvideDep.java b/stone_processor/src/main/java/com/github/klee0kai/stone/helpers/invokecall/ProvideDep.java deleted file mode 100644 index ecf4abe7..00000000 --- a/stone_processor/src/main/java/com/github/klee0kai/stone/helpers/invokecall/ProvideDep.java +++ /dev/null @@ -1,41 +0,0 @@ -package com.github.klee0kai.stone.helpers.invokecall; - -import com.github.klee0kai.stone.model.annotations.QualifierAnn; -import com.squareup.javapoet.TypeName; - -import java.util.Objects; -import java.util.Set; - -import static com.github.klee0kai.stone.helpers.wrap.WrapHelper.listWrapTypeIfNeed; - -public class ProvideDep { - - public String methodName = null; - - public TypeName typeName; - public Set qualifierAnns; - - public ProvideDep(TypeName typeName, Set qualifierAnns) { - this.typeName = listWrapTypeIfNeed(typeName); - this.qualifierAnns = qualifierAnns; - } - - public ProvideDep(String methodName, TypeName typeName, Set qualifierAnns) { - this.methodName = methodName; - this.typeName = listWrapTypeIfNeed(typeName); - this.qualifierAnns = qualifierAnns; - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - ProvideDep that = (ProvideDep) o; - return Objects.equals(typeName, that.typeName) && Objects.equals(qualifierAnns, that.qualifierAnns); - } - - @Override - public int hashCode() { - return Objects.hash(typeName, qualifierAnns); - } -} diff --git a/stone_processor/src/main/java/com/github/klee0kai/stone/helpers/itemholder/ItemCacheType.java b/stone_processor/src/main/java/com/github/klee0kai/stone/helpers/itemholder/ItemCacheType.java deleted file mode 100644 index d4a4989a..00000000 --- a/stone_processor/src/main/java/com/github/klee0kai/stone/helpers/itemholder/ItemCacheType.java +++ /dev/null @@ -1,78 +0,0 @@ -package com.github.klee0kai.stone.helpers.itemholder; - -import com.github.klee0kai.stone._hidden_.types.holders.StoneRefType; -import com.github.klee0kai.stone.annotations.component.GcSoftScope; -import com.github.klee0kai.stone.annotations.component.GcStrongScope; -import com.github.klee0kai.stone.annotations.component.GcWeakScope; -import com.github.klee0kai.stone.annotations.module.BindInstance; -import com.github.klee0kai.stone.annotations.module.Provide; -import com.squareup.javapoet.ClassName; - -public enum ItemCacheType { - Strong, Soft, Weak; - - public ClassName getGcScopeClassName() { - switch (this) { - case Weak: - return ClassName.get(GcWeakScope.class); - case Strong: - return ClassName.get(GcStrongScope.class); - case Soft: - default: - return ClassName.get(GcSoftScope.class); - } - } - - public static ItemCacheType cacheTypeFrom(BindInstance.CacheType cacheType) { - if (cacheType != null) switch (cacheType) { - case Weak: - return ItemCacheType.Weak; - case Strong: - return ItemCacheType.Strong; - case Soft: - default: - return ItemCacheType.Soft; - } - return ItemCacheType.Soft; - } - - public static ItemCacheType cacheTypeFrom(Provide.CacheType cacheType) { - if (cacheType != null) switch (cacheType) { - case Weak: - return ItemCacheType.Weak; - case Strong: - return ItemCacheType.Strong; - case Soft: - default: - return ItemCacheType.Soft; - } - return ItemCacheType.Soft; - } - - public StoneRefType toRefTypeSingle() { - switch (this) { - case Strong: - return StoneRefType.StrongObject; - case Soft: - return StoneRefType.SoftObject; - case Weak: - return StoneRefType.WeakObject; - default: - return null; - } - } - - public StoneRefType toRefTypeList() { - switch (this) { - case Strong: - return StoneRefType.ListObject; - case Soft: - return StoneRefType.ListSoftObject; - case Weak: - return StoneRefType.ListWeakObject; - default: - return null; - } - } - -} diff --git a/stone_processor/src/main/java/com/github/klee0kai/stone/helpers/itemholder/ItemHolderCodeHelper.java b/stone_processor/src/main/java/com/github/klee0kai/stone/helpers/itemholder/ItemHolderCodeHelper.java deleted file mode 100644 index 201d9b90..00000000 --- a/stone_processor/src/main/java/com/github/klee0kai/stone/helpers/itemholder/ItemHolderCodeHelper.java +++ /dev/null @@ -1,69 +0,0 @@ -package com.github.klee0kai.stone.helpers.itemholder; - -import com.github.klee0kai.stone._hidden_.types.MultiKey; -import com.github.klee0kai.stone.helpers.codebuilder.SmartCode; -import com.github.klee0kai.stone.model.FieldDetail; -import com.squareup.javapoet.ClassName; -import com.squareup.javapoet.CodeBlock; -import com.squareup.javapoet.FieldSpec; -import com.squareup.javapoet.TypeName; - -import java.util.List; - -import static com.github.klee0kai.stone.helpers.wrap.WrapHelper.isList; -import static com.github.klee0kai.stone.helpers.wrap.WrapHelper.nonWrappedType; - -public interface ItemHolderCodeHelper { - - ClassName multiKeyClassName = ClassName.get(MultiKey.class); - - static ItemHolderCodeHelper of( - String fieldName, - TypeName returnType, - List idFields, - ItemCacheType cacheType - ) { - if (idFields == null || idFields.isEmpty()) { - SingleItemHolderHelper singleItemHolderHelper = new SingleItemHolderHelper(); - singleItemHolderHelper.fieldName = fieldName; - singleItemHolderHelper.nonWrappedType = nonWrappedType(returnType); - singleItemHolderHelper.returnType = returnType; - singleItemHolderHelper.isListCaching = isList(returnType); - singleItemHolderHelper.defRefType = isList(returnType) ? cacheType.toRefTypeList() : cacheType.toRefTypeSingle(); - return singleItemHolderHelper; - } - - if (idFields.size() == 1) { - SimpleMapItemHolderHelper simpleMapItemHolderHelper = new SimpleMapItemHolderHelper(); - simpleMapItemHolderHelper.fieldName = fieldName; - simpleMapItemHolderHelper.nonWrappedType = nonWrappedType(returnType); - simpleMapItemHolderHelper.returnType = returnType; - simpleMapItemHolderHelper.keyParam = idFields.get(0); - simpleMapItemHolderHelper.isListCaching = isList(returnType); - simpleMapItemHolderHelper.defRefType = isList(returnType) ? cacheType.toRefTypeList() : cacheType.toRefTypeSingle(); - return simpleMapItemHolderHelper; - } - - MultiKeyMapItemHolderHelper multiKeyMapItemHolderHelper = new MultiKeyMapItemHolderHelper(); - multiKeyMapItemHolderHelper.fieldName = fieldName; - multiKeyMapItemHolderHelper.nonWrappedType = nonWrappedType(returnType); - multiKeyMapItemHolderHelper.returnType = returnType; - multiKeyMapItemHolderHelper.keyArgs = idFields; - multiKeyMapItemHolderHelper.isListCaching = isList(returnType); - multiKeyMapItemHolderHelper.defRefType = isList(returnType) ? cacheType.toRefTypeList() : cacheType.toRefTypeSingle(); - - return multiKeyMapItemHolderHelper; - } - - FieldSpec.Builder cachedField(); - - CodeBlock clearNullsStatement(); - - SmartCode codeGetCachedValue(); - - CodeBlock codeSetCachedValue(CodeBlock value, boolean onlyIfNull); - - CodeBlock statementSwitchRef(CodeBlock paramsCode); - - -} diff --git a/stone_processor/src/main/java/com/github/klee0kai/stone/helpers/itemholder/MultiKeyMapItemHolderHelper.java b/stone_processor/src/main/java/com/github/klee0kai/stone/helpers/itemholder/MultiKeyMapItemHolderHelper.java deleted file mode 100644 index 32416a26..00000000 --- a/stone_processor/src/main/java/com/github/klee0kai/stone/helpers/itemholder/MultiKeyMapItemHolderHelper.java +++ /dev/null @@ -1,67 +0,0 @@ -package com.github.klee0kai.stone.helpers.itemholder; - -import com.github.klee0kai.stone._hidden_.types.ListUtils; -import com.github.klee0kai.stone._hidden_.types.holders.MapItemHolder; -import com.github.klee0kai.stone._hidden_.types.holders.StoneRefType; -import com.github.klee0kai.stone.helpers.codebuilder.SmartCode; -import com.github.klee0kai.stone.model.FieldDetail; -import com.squareup.javapoet.*; - -import javax.lang.model.element.Modifier; -import java.util.List; - -import static com.github.klee0kai.stone.helpers.wrap.WrapHelper.listWrapTypeIfNeed; - -public class MultiKeyMapItemHolderHelper implements ItemHolderCodeHelper { - - public String fieldName; - public TypeName nonWrappedType; - public TypeName returnType; - public StoneRefType defRefType; - public List keyArgs; - public boolean isListCaching; - - - @Override - public FieldSpec.Builder cachedField() { - ParameterizedTypeName cacheType = ParameterizedTypeName.get(ClassName.get(MapItemHolder.class), multiKeyClassName, nonWrappedType); - return FieldSpec.builder(cacheType, fieldName, Modifier.PRIVATE, Modifier.FINAL) - .initializer("new $T($T.$L)", cacheType, StoneRefType.class, defRefType.toString()); - } - - @Override - public CodeBlock clearNullsStatement() { - return CodeBlock.builder() - .addStatement("$L.clearNulls()", fieldName) - .build(); - } - - - @Override - public SmartCode codeGetCachedValue() { - String getMethod = isListCaching ? "getList" : "get"; - return SmartCode.of(CodeBlock.of("$L.$L(new $T($L) )", fieldName, getMethod, multiKeyClassName, - String.join(",", ListUtils.format(keyArgs, (k) -> k.name)))) - .providingType(listWrapTypeIfNeed(returnType)); - } - - @Override - public CodeBlock codeSetCachedValue(CodeBlock value, boolean isOnlyIfNeed) { - String setMethod = isListCaching ? "setList" : "set"; - return SmartCode.builder() - .add(CodeBlock.of("$L.$L( new $T( $L ), () -> ", fieldName, setMethod, multiKeyClassName, - String.join(",", ListUtils.format(keyArgs, (k) -> k.name)))) - .add(value) - .add(CodeBlock.of(", $L )", isOnlyIfNeed)) - .build(null); - } - - @Override - public CodeBlock statementSwitchRef(CodeBlock paramsCode) { - return CodeBlock.builder() - .addStatement("$L.switchCache($L)", fieldName, paramsCode) - .build(); - } - - -} diff --git a/stone_processor/src/main/java/com/github/klee0kai/stone/helpers/itemholder/SimpleMapItemHolderHelper.java b/stone_processor/src/main/java/com/github/klee0kai/stone/helpers/itemholder/SimpleMapItemHolderHelper.java deleted file mode 100644 index 72f09a69..00000000 --- a/stone_processor/src/main/java/com/github/klee0kai/stone/helpers/itemholder/SimpleMapItemHolderHelper.java +++ /dev/null @@ -1,65 +0,0 @@ -package com.github.klee0kai.stone.helpers.itemholder; - -import com.github.klee0kai.stone._hidden_.types.holders.MapItemHolder; -import com.github.klee0kai.stone._hidden_.types.holders.StoneRefType; -import com.github.klee0kai.stone.helpers.codebuilder.SmartCode; -import com.github.klee0kai.stone.model.FieldDetail; -import com.squareup.javapoet.*; - -import javax.lang.model.element.Modifier; - -import static com.github.klee0kai.stone.helpers.wrap.WrapHelper.listWrapTypeIfNeed; - -public class SimpleMapItemHolderHelper implements ItemHolderCodeHelper { - - public String fieldName; - public TypeName nonWrappedType; - - public TypeName returnType; - public FieldDetail keyParam; - - public StoneRefType defRefType; - - public boolean isListCaching; - - - @Override - public FieldSpec.Builder cachedField() { - ParameterizedTypeName cacheType = ParameterizedTypeName.get(ClassName.get(MapItemHolder.class), keyParam.type, nonWrappedType); - return FieldSpec.builder(cacheType, fieldName, Modifier.PRIVATE, Modifier.FINAL) - .initializer("new $T($T.$L)", cacheType, StoneRefType.class, defRefType.toString()); - } - - @Override - public CodeBlock clearNullsStatement() { - return CodeBlock.builder() - .addStatement("$L.clearNulls()", fieldName) - .build(); - } - - @Override - public SmartCode codeGetCachedValue() { - String getMethod = isListCaching ? "getList" : "get"; - return SmartCode.of(CodeBlock.of("$L.$L($L)", fieldName, getMethod, keyParam.name)) - .providingType(listWrapTypeIfNeed(returnType)); - } - - @Override - public CodeBlock codeSetCachedValue(CodeBlock value, boolean isOnlyIfNeed) { - String setMethod = isListCaching ? "setList" : "set"; - return SmartCode.builder() - .add(CodeBlock.of("$L.$L( $L, () -> ", fieldName, setMethod, keyParam.name)) - .add(value) - .add(CodeBlock.of(", $L )", isOnlyIfNeed)) - .build(null); - } - - @Override - public CodeBlock statementSwitchRef(CodeBlock paramsCode) { - return CodeBlock.builder() - .addStatement("$L.switchCache($L)", fieldName, paramsCode) - .build(); - } - - -} diff --git a/stone_processor/src/main/java/com/github/klee0kai/stone/helpers/itemholder/SingleItemHolderHelper.java b/stone_processor/src/main/java/com/github/klee0kai/stone/helpers/itemholder/SingleItemHolderHelper.java deleted file mode 100644 index ab3d8ea3..00000000 --- a/stone_processor/src/main/java/com/github/klee0kai/stone/helpers/itemholder/SingleItemHolderHelper.java +++ /dev/null @@ -1,61 +0,0 @@ -package com.github.klee0kai.stone.helpers.itemholder; - -import com.github.klee0kai.stone._hidden_.types.holders.SingleItemHolder; -import com.github.klee0kai.stone._hidden_.types.holders.StoneRefType; -import com.github.klee0kai.stone.helpers.codebuilder.SmartCode; -import com.squareup.javapoet.*; - -import javax.lang.model.element.Modifier; - -import static com.github.klee0kai.stone.helpers.wrap.WrapHelper.listWrapTypeIfNeed; - -public class SingleItemHolderHelper implements ItemHolderCodeHelper { - - public String fieldName; - public TypeName nonWrappedType; - - public TypeName returnType; - - public StoneRefType defRefType; - public boolean isListCaching; - - - @Override - public FieldSpec.Builder cachedField() { - ParameterizedTypeName cacheType = ParameterizedTypeName.get(ClassName.get(SingleItemHolder.class), nonWrappedType); - return FieldSpec.builder(cacheType, fieldName, Modifier.PRIVATE, Modifier.FINAL) - .initializer("new $T($T.$L)", cacheType, StoneRefType.class, defRefType.toString()); - } - - @Override - public CodeBlock clearNullsStatement() { - return CodeBlock.of(""); - } - - @Override - public SmartCode codeGetCachedValue() { - String getMethod = isListCaching ? "getList" : "get"; - return SmartCode.of(CodeBlock.of("$L.$L()", fieldName, getMethod)) - .providingType(listWrapTypeIfNeed(returnType)); - } - - @Override - public CodeBlock codeSetCachedValue(CodeBlock value, boolean onlyIfNull) { - String setMethod = isListCaching ? "setList" : "set"; - return SmartCode.builder() - .add(CodeBlock.of("$L.$L( ()-> ", fieldName, setMethod)) - .add(value) - .add(CodeBlock.of(", $L)", onlyIfNull)) - .providingType(listWrapTypeIfNeed(returnType)) - .build(null); - } - - @Override - public CodeBlock statementSwitchRef(CodeBlock paramsCode) { - return CodeBlock.builder() - .addStatement("$L.switchCache($L)", fieldName, paramsCode) - .build(); - } - - -} diff --git a/stone_processor/src/main/java/com/github/klee0kai/stone/helpers/wrap/FormatInList.java b/stone_processor/src/main/java/com/github/klee0kai/stone/helpers/wrap/FormatInList.java deleted file mode 100644 index d2763f72..00000000 --- a/stone_processor/src/main/java/com/github/klee0kai/stone/helpers/wrap/FormatInList.java +++ /dev/null @@ -1,14 +0,0 @@ -package com.github.klee0kai.stone.helpers.wrap; - -import com.github.klee0kai.stone.helpers.codebuilder.SmartCode; - -public interface FormatInList { - - /** - * @param originalListCode original list code - * @param itemTransformFun format each type - * @return - */ - SmartCode formatCode(SmartCode originalListCode, FormatSimple itemTransformFun); - -} diff --git a/stone_processor/src/main/java/com/github/klee0kai/stone/helpers/wrap/FormatSimple.java b/stone_processor/src/main/java/com/github/klee0kai/stone/helpers/wrap/FormatSimple.java deleted file mode 100644 index 7d15fe47..00000000 --- a/stone_processor/src/main/java/com/github/klee0kai/stone/helpers/wrap/FormatSimple.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.github.klee0kai.stone.helpers.wrap; - -import com.github.klee0kai.stone.helpers.codebuilder.SmartCode; - -public interface FormatSimple { - - /** - * @param code code witch return original type - * @return code witch return wanna type - */ - SmartCode formatCode(SmartCode code); - -} diff --git a/stone_processor/src/main/java/com/github/klee0kai/stone/helpers/wrap/WrapHelper.java b/stone_processor/src/main/java/com/github/klee0kai/stone/helpers/wrap/WrapHelper.java deleted file mode 100644 index 9880f50f..00000000 --- a/stone_processor/src/main/java/com/github/klee0kai/stone/helpers/wrap/WrapHelper.java +++ /dev/null @@ -1,302 +0,0 @@ -package com.github.klee0kai.stone.helpers.wrap; - -import com.github.klee0kai.stone._hidden_.types.ListUtils; -import com.github.klee0kai.stone._hidden_.types.NullGet; -import com.github.klee0kai.stone.exceptions.StoneException; -import com.github.klee0kai.stone.helpers.codebuilder.SmartCode; -import com.github.klee0kai.stone.wrappers.AsyncProvide; -import com.github.klee0kai.stone.wrappers.LazyProvide; -import com.github.klee0kai.stone.wrappers.PhantomProvide; -import com.github.klee0kai.stone.wrappers.Ref; -import com.squareup.javapoet.*; - -import javax.inject.Provider; -import java.lang.ref.Reference; -import java.lang.ref.SoftReference; -import java.lang.ref.WeakReference; -import java.util.*; - -import static com.github.klee0kai.stone.exceptions.ExceptionStringBuilder.createErrorMes; -import static com.github.klee0kai.stone.utils.ClassNameUtils.noWildCardType; -import static com.github.klee0kai.stone.utils.ClassNameUtils.rawTypeOf; - -public class WrapHelper { - - public static HashMap wrapTypes = new HashMap<>(); - - public static void reInit() { - wrapTypes.clear(); - std(); - } - - public static void support(WrapType wrapType) { - wrapTypes.putIfAbsent(wrapType.typeName, wrapType); - } - - - public static boolean isSupport(TypeName typeName) { - return wrapTypes.containsKey(rawTypeOf(typeName)); - } - - public static boolean isNonCachingWrapper(TypeName typeName) { - for (TypeName t : allParamTypes(typeName)) { - WrapType wrapType = wrapTypes.get(rawTypeOf(t)); - if (wrapType != null && wrapType.isNoCachingWrapper) - return true; - } - return false; - } - - public static boolean isAsyncProvider(TypeName typeName) { - for (TypeName t : allParamTypes(typeName)) { - WrapType wrapType = wrapTypes.get(rawTypeOf(t)); - if (wrapType != null && wrapType.isAsyncProvider) - return true; - } - return false; - } - - public static boolean isList(TypeName typeName) { - return ListUtils.indexOf(allParamTypes(typeName), (i, it) -> { - WrapType wrapType = wrapTypes.get(rawTypeOf(it)); - return wrapType != null && wrapType.isList(); - }) >= 0; - } - - - public static TypeName paramType(TypeName typeName) { - if (typeName instanceof ParameterizedTypeName) { - ParameterizedTypeName par = (ParameterizedTypeName) typeName; - if (isSupport(par.rawType) && par.typeArguments != null && !par.typeArguments.isEmpty()) - return par.typeArguments.get(0); - } - return typeName; - } - - public static TypeName nonWrappedType(TypeName typeName) { - if (typeName instanceof ParameterizedTypeName) { - ParameterizedTypeName par = (ParameterizedTypeName) typeName; - if (isSupport(par.rawType) && par.typeArguments != null && !par.typeArguments.isEmpty()) - return nonWrappedType(par.typeArguments.get(0)); - } - if (typeName instanceof WildcardTypeName) { - WildcardTypeName par = (WildcardTypeName) typeName; - if (!par.upperBounds.isEmpty()) - return nonWrappedType(par.upperBounds.get(0)); - } - return typeName; - } - - public static TypeName listWrapTypeIfNeed(TypeName typeName) { - if (isList(typeName)) - return ParameterizedTypeName.get(ClassName.get(List.class), nonWrappedType(typeName)); - return nonWrappedType(typeName); - } - - public static List allParamTypes(TypeName typeName) { - typeName = noWildCardType(typeName); - List allParams = new LinkedList<>(); - while (true) { - allParams.add(typeName); - ParameterizedTypeName paramType = typeName instanceof ParameterizedTypeName ? (ParameterizedTypeName) typeName : null; - if (paramType == null || paramType.typeArguments.isEmpty()) break; - typeName = noWildCardType(paramType.typeArguments.get(0)); - } - return allParams; - } - - public static SmartCode transform(SmartCode code, TypeName wannaType) { - if (code.providingType == null || Objects.equals(code.providingType, wannaType)) { - return code; - } - - SmartCode smartCode = SmartCode.builder().add(code); - LinkedList wrapPathNames = new LinkedList<>(allParamTypes(wannaType)); - LinkedList unwrapPathNames = new LinkedList<>(allParamTypes(code.providingType)); - Collections.reverse(wrapPathNames); - while (!wrapPathNames.isEmpty() && !unwrapPathNames.isEmpty() - && Objects.equals(rawTypeOf(unwrapPathNames.getLast()), rawTypeOf(wrapPathNames.getFirst()))) { - unwrapPathNames.pollLast(); - wrapPathNames.pollFirst(); - } - - ListUtils.IFormat wrapTypeFormat = it -> { - WrapType type = wrapTypes.get(rawTypeOf(it)); - if (type == null) { - throw new StoneException( - createErrorMes() - .typeTransformNonSupport(noWildCardType(code.providingType), wannaType) - .classNonFound(it.toString()) - .build(), - null - ); - } - return type; - }; - - LinkedList unwrapPath = new LinkedList<>(ListUtils.format(unwrapPathNames, wrapTypeFormat)); - LinkedList wrapPath = new LinkedList<>(ListUtils.format(wrapPathNames, wrapTypeFormat)); - - while (!unwrapPath.isEmpty()) { - WrapType unwrapType = unwrapPath.get(0); - if (unwrapType.isList()) { - int wrapListIndex = ListUtils.indexOf(wrapPath, (i, it) -> it.isList()); - if (wrapListIndex >= 0) { - TypeName unWrapItemType = paramType(unwrapPathNames.get(0)); - TypeName wrapItemType = paramType(wrapPathNames.get(wrapListIndex)); - WrapType wrapListType = wrapPath.get(wrapListIndex); - smartCode = wrapListType.inListFormat.formatCode(smartCode, - listItemCode -> transform(listItemCode.providingType(unWrapItemType), wrapItemType)); - - for (int i = 0; i <= wrapListIndex; i++) { - wrapPath.pollFirst(); - wrapPathNames.pollFirst(); - } - unwrapPath.clear(); - unwrapPathNames.clear(); - break; - } - } - smartCode = unwrapType.unwrap.formatCode(smartCode); - unwrapPath.pollFirst(); - unwrapPathNames.pollFirst(); - } - - while (!wrapPath.isEmpty()) { - smartCode = wrapPath.get(0).wrap.formatCode(smartCode); - wrapPath.pollFirst(); - wrapPathNames.pollFirst(); - } - - return smartCode - .providingType(wannaType); - } - - private static void std() { - for (Class cl : Arrays.asList(WeakReference.class, SoftReference.class, Reference.class)) { - ClassName wrapper = ClassName.get(cl); - ClassName creator = !Objects.equals(cl, Reference.class) ? wrapper : ClassName.get(WeakReference.class); - - WrapType wrapType = new WrapType(); - wrapType.isNoCachingWrapper = false; - wrapType.typeName = wrapper; - wrapType.wrap = (or) -> { - SmartCode builder = SmartCode.builder() - .add(CodeBlock.of("$T.let(", NullGet.class)) - .add(or) - .add(CodeBlock.of(", $T::new )", creator)); - if (or.providingType != null) - builder.providingType(ParameterizedTypeName.get(wrapper, or.providingType)); - return builder; - }; - - wrapType.unwrap = (or) -> { - SmartCode builder = SmartCode.builder() - .add(CodeBlock.of("$T.let( ", NullGet.class)) - .add(or) - .add(CodeBlock.of(", $T::get ) ", cl)); - if (or.providingType != null) - builder.providingType(paramType(or.providingType)); - return builder; - }; - - support(wrapType); - } - - for (Class cl : Arrays.asList(PhantomProvide.class, Ref.class, Provider.class, LazyProvide.class, AsyncProvide.class)) { - ClassName wrapper = ClassName.get(cl); - - WrapType wrapType = new WrapType(); - wrapType.isNoCachingWrapper = !Objects.equals(cl, LazyProvide.class) && !Objects.equals(cl, AsyncProvide.class); - wrapType.isAsyncProvider = true; - wrapType.typeName = wrapper; - - wrapType.wrap = (or) -> { - // TODO sometimes work not well. Need use types directly - SmartCode builder = SmartCode.builder() - .add(CodeBlock.of("new $T( () -> ", wrapType.isNoCachingWrapper ? ClassName.get(PhantomProvide.class) : wrapper)) - .add(or) - .add(" )"); - if (or.providingType != null) - builder.providingType(ParameterizedTypeName.get(wrapper, or.providingType)); - return builder; - }; - - wrapType.unwrap = (or) -> { - // TODO sometimes work not well. Need use types directly - SmartCode builder = SmartCode.builder() - .add(CodeBlock.of("$T.let( ", NullGet.class)) - .add(or) - .add(CodeBlock.of(", $T::get ) ", cl)); - if (or.providingType != null) - builder.providingType(paramType(or.providingType)); - return builder; - }; - support(wrapType); - } - - int index = 0; - for (Class cl : Arrays.asList(LinkedList.class, ArrayList.class, List.class, Collection.class)) { - ClassName wrapper = ClassName.get(cl); - boolean needConstructor = Arrays.asList(LinkedList.class, ArrayList.class).contains(cl); - ClassName createType = index++ <= 0 ? wrapper : ClassName.get(ArrayList.class); - - WrapType wrapType = new WrapType(); - wrapType.typeName = wrapper; - wrapType.wrap = (or) -> { - SmartCode builder = SmartCode.builder(); - if (needConstructor) - builder.add(CodeBlock.of("$T.let( ", NullGet.class)); - - builder.add(CodeBlock.of("$T.list( ", NullGet.class)) - .add(or) - .add(")"); - - if (needConstructor) builder.add(CodeBlock.of(", $T::new)", createType)); - if (or.providingType != null) - builder.providingType(ParameterizedTypeName.get(wrapper, or.providingType)); - return builder; - }; - - wrapType.unwrap = (or) -> { - SmartCode builder = SmartCode.builder() - .add(CodeBlock.of("$T.first( ", ListUtils.class)) - .add(or) - .add(CodeBlock.of(") ")); - if (or.providingType != null) - builder.providingType(paramType(or.providingType)); - return builder; - }; - - wrapType.inListFormat = (originalListCode, itemTransformFun) -> { - SmartCode builder = SmartCode.builder(); - boolean isListNeedConstructor = needConstructor - || originalListCode.providingType != null && !Objects.equals(rawTypeOf(wrapper), rawTypeOf(originalListCode.providingType)); - - if (isListNeedConstructor) builder.add(CodeBlock.of("$T.let( ", NullGet.class)); - - SmartCode itemTransform = itemTransformFun.formatCode(SmartCode.of("it", null)); - if (itemTransform.getSize() <= 1) { - //no transforms - builder.add(originalListCode); - } else { - builder.add(CodeBlock.of("$T.format( ", ListUtils.class)) - .add(originalListCode) - .add(", it -> ") - .add(itemTransformFun.formatCode(SmartCode.of("it", null))) - .add(") "); - - } - if (isListNeedConstructor) builder.add(CodeBlock.of(", $T::new)", createType)); - - if (originalListCode.providingType != null) - builder.providingType(rawTypeOf(originalListCode.providingType)); - return builder; - }; - support(wrapType); - - } - } - - -} diff --git a/stone_processor/src/main/java/com/github/klee0kai/stone/helpers/wrap/WrapType.java b/stone_processor/src/main/java/com/github/klee0kai/stone/helpers/wrap/WrapType.java deleted file mode 100644 index af0a8498..00000000 --- a/stone_processor/src/main/java/com/github/klee0kai/stone/helpers/wrap/WrapType.java +++ /dev/null @@ -1,22 +0,0 @@ -package com.github.klee0kai.stone.helpers.wrap; - -import com.squareup.javapoet.TypeName; - -public class WrapType { - - public TypeName typeName; - - public boolean isAsyncProvider = false; - - public boolean isNoCachingWrapper = false; - - public FormatSimple unwrap; - - public FormatSimple wrap; - - public FormatInList inListFormat; - - public boolean isList() { - return inListFormat != null; - } -} diff --git a/stone_processor/src/main/java/com/github/klee0kai/stone/model/ClassDetail.java b/stone_processor/src/main/java/com/github/klee0kai/stone/model/ClassDetail.java deleted file mode 100644 index 71e1af91..00000000 --- a/stone_processor/src/main/java/com/github/klee0kai/stone/model/ClassDetail.java +++ /dev/null @@ -1,340 +0,0 @@ -package com.github.klee0kai.stone.model; - -import com.github.klee0kai.stone._hidden_.types.ListUtils; -import com.github.klee0kai.stone.annotations.component.Component; -import com.github.klee0kai.stone.annotations.dependencies.Dependencies; -import com.github.klee0kai.stone.annotations.module.Module; -import com.github.klee0kai.stone.annotations.wrappers.WrappersCreator; -import com.github.klee0kai.stone.model.annotations.*; -import com.github.klee0kai.stone.utils.AnnotationMirrorUtil; -import com.github.klee0kai.stone.utils.ClassNameUtils; -import com.squareup.javapoet.ClassName; -import com.squareup.javapoet.TypeName; - -import javax.lang.model.element.*; -import javax.lang.model.type.DeclaredType; -import javax.lang.model.type.TypeMirror; -import java.util.*; - -import static com.github.klee0kai.stone.helpers.SetFieldHelper.capitalized; - -/** - * Collected class details of compile type or type specs. - * Collect the information you need in one place - */ -public class ClassDetail implements Cloneable { - - public TypeName className; - - public Set modifiers = Collections.emptySet(); - - public TypeKindDetails kind; - - public List methods = new LinkedList<>(); - public List fields = new LinkedList<>(); - - public ClassDetail superClass = null; - public List interfaces = new LinkedList<>(); - - public Element sourceEl = null; - - - // ------- annotations --------- - - private Map, IAnnotation> annotations = new HashMap<>(); - - public ClassDetail(TypeName className) { - this.className = className; - } - - - /** - * Take class details from compile type element - * - * @param owner original element - */ - public ClassDetail(TypeElement owner) { - className = ClassNameUtils.classNameOf(owner.getQualifiedName().toString()); - modifiers = owner.getModifiers(); - kind = TypeKindDetails.of(owner.getKind()); - sourceEl = owner; - - addAnnotation(ComponentAnn.of(AnnotationMirrorUtil.findAnnotationMirror(owner, Component.class))); - addAnnotation(ModuleAnn.of(AnnotationMirrorUtil.findAnnotationMirror(owner, Module.class))); - addAnnotation(DependenciesAnn.of(AnnotationMirrorUtil.findAnnotationMirror(owner, Dependencies.class))); - addAnnotation(WrapperCreatorsAnn.of(AnnotationMirrorUtil.findAnnotationMirror(owner, WrappersCreator.class))); - - for (Element el : owner.getEnclosedElements()) { - if (el instanceof ExecutableElement) - methods.add(MethodDetail.of((ExecutableElement) el)); - else if (el instanceof VariableElement) { - String getAnnotationsElName = "get" + capitalized(el.getSimpleName().toString()) + "$annotations"; - Element getAnnotationsEl = ListUtils.first(owner.getEnclosedElements(), (i, it) -> - Objects.equals(it.getSimpleName().toString(), getAnnotationsElName) - ); - fields.add(FieldDetail.of((VariableElement) el, getAnnotationsEl)); - } - } - if (owner.getSuperclass() instanceof DeclaredType) { - if (((DeclaredType) owner.getSuperclass()).asElement() instanceof TypeElement) - superClass = new ClassDetail((TypeElement) (((DeclaredType) owner.getSuperclass()).asElement())); - } - - for (TypeMirror tp : owner.getInterfaces()) { - if (tp instanceof DeclaredType && ((DeclaredType) tp).asElement() instanceof TypeElement) - interfaces.add(new ClassDetail((TypeElement) ((DeclaredType) tp).asElement())); - } - } - - public ClassDetail(ClassDetail cp) { - this.className = cp.className; - this.modifiers = cp.modifiers; - this.kind = cp.kind; - this.methods = cp.methods; - this.fields = cp.fields; - this.superClass = cp.superClass; - this.interfaces = cp.interfaces; - this.annotations = cp.annotations; - this.sourceEl = cp.sourceEl; - } - - /** - * List all methods of this class include parent classes and interfaces - * - * @param includeObjectMethods return object's methods (equals, hashCode and etc) - * @param allowDoubles true if we want to check return types of overridden methods - * @param exceptNames filter names by except list - * @return list of all methods - */ - public List getAllMethods(boolean includeObjectMethods, boolean allowDoubles, String... exceptNames) { - if (!includeObjectMethods && className.equals(ClassName.OBJECT)) - return Collections.emptyList(); - LinkedList allMethods = new LinkedList<>(this.methods); - if (superClass != null) - allMethods.addAll(superClass.getAllMethods(includeObjectMethods, allowDoubles)); - if (interfaces != null) for (ClassDetail interf : interfaces) - allMethods.addAll(interf.getAllMethods(includeObjectMethods, allowDoubles)); - - LinkedList outMethods = new LinkedList<>(); - for (MethodDetail m : allMethods) { - boolean exist = false; - for (MethodDetail exitMethod : outMethods) { - if (exist |= exitMethod.isSameMethod(m)) - break; - } - if (exist && !allowDoubles) continue; - boolean ignore = false; - if (exceptNames != null) - for (String ex : exceptNames) - if (Objects.equals(ex, m.methodName)) { - ignore = true; - break; - } - if (ignore) continue; - outMethods.add(m); - } - return outMethods; - } - - /** - * List all fields of this class include parent classes - * - * @return list of all fields - */ - public List getAllFields() { - if (className.equals(ClassName.OBJECT)) - return Collections.emptyList(); - LinkedList allFields = new LinkedList<>(this.fields); - if (superClass != null) - allFields.addAll(superClass.getAllFields()); - if (interfaces != null) for (ClassDetail interf : interfaces) - allFields.addAll(interf.getAllFields()); - - LinkedList outFields = new LinkedList<>(); - for (FieldDetail m : allFields) { - boolean exist = false; - for (FieldDetail exitMethod : outFields) { - if (exist |= (Objects.equals(exitMethod.name, m.name))) - break; - } - if (!exist) - outFields.add(m); - } - return outFields; - } - - /** - * List all parents of class: classes and interfaces. - * - * @param includeObject return also java object's class - * @return list for all parents - */ - public List getAllParents(boolean includeObject) { - if (!includeObject && className.equals(ClassName.OBJECT)) - return Collections.emptyList(); - List parents = new LinkedList<>(); - parents.add(this); - if (superClass != null) - parents.addAll(superClass.getAllParents(includeObject)); - if (interfaces != null) for (ClassDetail interf : interfaces) - parents.addAll(interf.getAllParents(includeObject)); - return parents; - } - - - /** - * Find method by method details. - * Compare by name and argument's list. - * - * @param methodDetail excepting method - * @param checkSuperclass search in superclasses - * @return found method details - */ - public MethodDetail findMethod(MethodDetail methodDetail, boolean checkSuperclass) { - for (MethodDetail m : methods) { - if (m.isSameMethod(methodDetail)) - return m; - } - if (checkSuperclass) { - if (superClass != null) { - MethodDetail m = superClass.findMethod(methodDetail, true); - if (m != null) return m; - } - for (ClassDetail cl : interfaces) { - MethodDetail m = cl.findMethod(methodDetail, true); - if (m != null) return m; - } - } - return null; - } - - /** - * Check for superclasses - * - * @param typeName excepting superclass - * @return true if class has superclass - */ - public boolean isExtOf(TypeName typeName) { - if (Objects.equals(typeName, this.className)) - return true; - if (superClass != null && superClass.isExtOf(typeName)) - return true; - if (interfaces != null) for (ClassDetail i : interfaces) - if (i.isExtOf(typeName)) - return true; - return false; - } - - /** - * @return true if is abstract class - */ - public boolean isAbstractClass() { - return modifiers.contains(Modifier.ABSTRACT); - } - - /** - * @return true if is interface class - */ - public boolean isInterfaceClass() { - return kind == TypeKindDetails.INTERFACE; - } - - /** - * Add annotation to class - * - * @param annotation new annotation - */ - public void addAnnotation(IAnnotation annotation) { - if (annotation != null) annotations.put(annotation.getClass(), annotation); - } - - /** - * Get annotation by type - * - * @param tClass class name of annotation - * @param type of annotation - * @return found annotation - */ - public T ann(Class tClass) { - return (T) annotations.getOrDefault(tClass, null); - } - - /** - * Check is any annotation exist - * - * @param aClasses list of annotation types - * @return found first annotation from list - */ - @SafeVarargs - public final IAnnotation anyAnnotation(Class... aClasses) { - for (Class cl : aClasses) { - IAnnotation ann = annotations.getOrDefault(cl, null); - if (ann != null) return ann; - } - return null; - } - - /** - * Check is list of annotations exist - * - * @param aClasses list of annotation types - * @return true if all annotations from list exist - */ - @SafeVarargs - public final boolean hasAnnotations(Class... aClasses) { - for (Class cl : aClasses) { - if (!annotations.containsKey(cl)) return false; - } - return true; - } - - /** - * Check is any of annotation exist - * - * @param aClasses list of annotation types - * @return true if any annotation from list exist - */ - @SafeVarargs - public final boolean hasAnyAnnotation(Class... aClasses) { - for (Class cl : aClasses) { - if (annotations.containsKey(cl)) return true; - } - return false; - } - - /** - * Check class have annotations exact as annotation list - * - * @param aClasses list of annotation types - * @return true if class has exact same annotations list - */ - @SafeVarargs - public final boolean hasOnlyAnnotations(Class... aClasses) { - if (annotations.size() != aClasses.length) return false; - for (Class cl : aClasses) { - if (!annotations.containsKey(cl)) return false; - } - return true; - } - - /** - * copy class details - */ - @Override - public ClassDetail clone() throws CloneNotSupportedException { - return (ClassDetail) super.clone(); - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - ClassDetail that = (ClassDetail) o; - return Objects.equals(className, that.className) && Objects.equals(modifiers, that.modifiers) && kind == that.kind && Objects.equals(methods, that.methods) && Objects.equals(fields, that.fields) && Objects.equals(superClass, that.superClass) && Objects.equals(interfaces, that.interfaces) && Objects.equals(annotations, that.annotations); - } - - @Override - public int hashCode() { - return Objects.hash(className, modifiers, kind, methods, fields, superClass, interfaces, annotations); - } -} diff --git a/stone_processor/src/main/java/com/github/klee0kai/stone/model/ComponentClassDetails.java b/stone_processor/src/main/java/com/github/klee0kai/stone/model/ComponentClassDetails.java deleted file mode 100644 index 14189920..00000000 --- a/stone_processor/src/main/java/com/github/klee0kai/stone/model/ComponentClassDetails.java +++ /dev/null @@ -1,103 +0,0 @@ -package com.github.klee0kai.stone.model; - - -import com.github.klee0kai.stone._hidden_.types.ListUtils; -import com.github.klee0kai.stone.checks.ComponentMethods; -import com.github.klee0kai.stone.helpers.invokecall.ModulesGraph; -import com.github.klee0kai.stone.model.annotations.ComponentAnn; -import com.github.klee0kai.stone.model.annotations.ModuleAnn; -import com.squareup.javapoet.ClassName; - -import javax.lang.model.element.TypeElement; -import java.util.HashSet; -import java.util.List; -import java.util.Set; - -import static com.github.klee0kai.stone.AnnotationProcessor.allClassesHelper; -import static com.github.klee0kai.stone.checks.ComponentMethods.isDepsProvide; -import static com.github.klee0kai.stone.checks.ComponentMethods.isModuleProvideMethod; -import static com.github.klee0kai.stone.codegen.ComponentBuilder.hiddenModuleMethodName; -import static com.github.klee0kai.stone.utils.StoneNamingUtils.genCacheControlInterfaceModuleNameMirror; -import static com.github.klee0kai.stone.utils.StoneNamingUtils.genHiddenModuleNameMirror; - -/** - * Collected component's class details of compile type or type specs. - * Collect the information you need in one place - */ -public class ComponentClassDetails extends ClassDetail { - - public final ModulesGraph modulesGraph = new ModulesGraph(); - public final Set identifiers = new HashSet<>(); - public ClassDetail hiddenModule = null; - public ClassName hiddenModuleCacheControlInterface = null; - - public ComponentClassDetails(TypeElement owner) { - super(owner); - collectComponentInfo(); - } - - public ComponentClassDetails(ClassDetail cp) { - super(cp); - collectComponentInfo(); - } - - - private void collectComponentInfo() { - for (ClassDetail componentParentCl : getAllParents(false)) { - ComponentAnn parentCompAnn = componentParentCl.ann(ComponentAnn.class); - if (parentCompAnn != null) identifiers.addAll(parentCompAnn.identifiers); - } - - for (MethodDetail m : getAllMethods(false, false, "")) { - if (allClassesHelper.iComponentClassDetails.findMethod(m, false) != null) - continue; - - if (isModuleProvideMethod(m)) { - ClassDetail moduleCl = allClassesHelper.findForType(m.returnType); - modulesGraph.collectFromModule(m, moduleCl); - } else if (isDepsProvide(m)) { - ClassDetail moduleCl = allClassesHelper.findForType(m.returnType); - modulesGraph.collectFromModule(m, moduleCl); - } - } - if (superClass != null && superClass.hasAnnotations(ComponentAnn.class)) { - superClass = new ComponentClassDetails(superClass); - } - for (int i = 0; i < interfaces.size(); i++) { - if (interfaces.get(i).hasAnnotations(ComponentAnn.class)) { - interfaces.set(i, new ComponentClassDetails(interfaces.get(i))); - } - } - genHiddenModule(); - } - - private void genHiddenModule() { - if (hiddenModule != null) return; - List hiddenBindInstanceMethods = ListUtils.filter( - getAllMethods(false, false, ""), - (i, m) -> { - boolean isBindAndProvide = ComponentMethods.isBindInstanceMethod(m) == ComponentMethods.BindInstanceType.BindInstanceAndProvide; - boolean noInModules = isBindAndProvide && modulesGraph.codeProvideType(m.methodName, m.returnType, m.qualifierAnns) == null; - return isBindAndProvide && noInModules; - }); - - hiddenModule = new ClassDetail(genHiddenModuleNameMirror(className)); - hiddenModule.addAnnotation(new ModuleAnn()); - hiddenModule.methods.addAll(hiddenBindInstanceMethods); - hiddenModuleCacheControlInterface = genCacheControlInterfaceModuleNameMirror(hiddenModule.className); - - - for (ClassDetail p : getAllParents(false)) { - if (p == this || !(p instanceof ComponentClassDetails)) continue; - ComponentClassDetails parent = (ComponentClassDetails) p; - hiddenModule.interfaces.add(new ClassDetail(parent.hiddenModule)); - } - - modulesGraph.collectFromModule( - MethodDetail.simpleName(hiddenModuleMethodName), - hiddenModule - ); - } - - -} diff --git a/stone_processor/src/main/java/com/github/klee0kai/stone/model/FieldDetail.java b/stone_processor/src/main/java/com/github/klee0kai/stone/model/FieldDetail.java deleted file mode 100644 index f3bd7cf9..00000000 --- a/stone_processor/src/main/java/com/github/klee0kai/stone/model/FieldDetail.java +++ /dev/null @@ -1,121 +0,0 @@ -package com.github.klee0kai.stone.model; - -import com.github.klee0kai.stone._hidden_.types.ListUtils; -import com.github.klee0kai.stone.model.annotations.QualifierAnn; -import com.squareup.javapoet.ClassName; -import com.squareup.javapoet.FieldSpec; -import com.squareup.javapoet.ParameterSpec; -import com.squareup.javapoet.TypeName; - -import javax.inject.Inject; -import javax.lang.model.element.AnnotationMirror; -import javax.lang.model.element.Element; -import javax.lang.model.element.VariableElement; -import java.util.HashSet; -import java.util.Objects; -import java.util.Set; - -import static com.github.klee0kai.stone.AnnotationProcessor.allClassesHelper; - -/** - * Collected field details of compile element or field specs. - * Collect the information you need in one place - */ -public class FieldDetail { - - public String name; - - public TypeName type; - - public Set qualifierAnns = new HashSet<>(); - - public boolean injectAnnotation = false; - - public Element sourceEl = null; - - /** - * Take field details for compile variable-element - * - * @param p original element - * @return new FieldDetails object of this element - */ - public static FieldDetail of(VariableElement p, Element annotationsEl) { - FieldDetail fieldDetail = new FieldDetail(); - fieldDetail.type = TypeName.get(p.asType()); - fieldDetail.name = p.getSimpleName().toString(); - fieldDetail.injectAnnotation = p.getAnnotation(Inject.class) != null; - fieldDetail.sourceEl = p; - - for (AnnotationMirror ann : p.getAnnotationMirrors()) { - String clName = ann.getAnnotationType().toString(); - ClassDetail qualifierAnn = allClassesHelper.findQualifierAnnotation(clName); - if (qualifierAnn != null) fieldDetail.qualifierAnns.add(QualifierAnn.of(ann)); - } - if (annotationsEl != null) - for (AnnotationMirror ann : annotationsEl.getAnnotationMirrors()) { - String clName = ann.getAnnotationType().toString(); - ClassDetail qualifierAnn = allClassesHelper.findQualifierAnnotation(clName); - if (qualifierAnn != null) fieldDetail.qualifierAnns.add(QualifierAnn.of(ann)); - } - return fieldDetail; - } - - /** - * Take field details for field spec - * - * @param field original element - * @return new FieldDetails object of this element - */ - public static FieldDetail of(FieldSpec field) { - FieldDetail fieldDetail = new FieldDetail(); - fieldDetail.name = field.name; - fieldDetail.type = field.type; - fieldDetail.injectAnnotation = ListUtils.contains(field.annotations, - (inx, ob) -> Objects.equals(ob.type, ClassName.get(Inject.class))); - return fieldDetail; - } - - /** - * Take field details for parameter spec. - * Annotations not Supported. - * - * @param field original element - * @return new FieldDetail object of this element - */ - public static FieldDetail of(ParameterSpec field) { - FieldDetail fieldDetail = new FieldDetail(); - fieldDetail.name = field.name; - fieldDetail.type = field.type; - fieldDetail.injectAnnotation = ListUtils.contains(field.annotations, - (inx, ob) -> Objects.equals(ob.type, ClassName.get(Inject.class))); - return fieldDetail; - } - - /** - * Create new field details - * - * @param name name of field - * @param typeName type of field - * @return new FieldDetail - */ - public static FieldDetail simple(String name, TypeName typeName) { - FieldDetail fieldDetail = new FieldDetail(); - fieldDetail.type = typeName; - fieldDetail.name = name; - return fieldDetail; - } - - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - FieldDetail that = (FieldDetail) o; - return Objects.equals(name, that.name) && Objects.equals(type, that.type); - } - - @Override - public int hashCode() { - return Objects.hash(name, type); - } -} diff --git a/stone_processor/src/main/java/com/github/klee0kai/stone/model/MethodDetail.java b/stone_processor/src/main/java/com/github/klee0kai/stone/model/MethodDetail.java deleted file mode 100644 index a5bfb0f1..00000000 --- a/stone_processor/src/main/java/com/github/klee0kai/stone/model/MethodDetail.java +++ /dev/null @@ -1,277 +0,0 @@ -package com.github.klee0kai.stone.model; - -import com.github.klee0kai.stone._hidden_.types.ListUtils; -import com.github.klee0kai.stone.annotations.component.*; -import com.github.klee0kai.stone.annotations.module.BindInstance; -import com.github.klee0kai.stone.annotations.module.Provide; -import com.github.klee0kai.stone.model.annotations.*; -import com.squareup.javapoet.ClassName; -import com.squareup.javapoet.TypeName; - -import javax.inject.Inject; -import javax.inject.Singleton; -import javax.lang.model.element.*; -import java.lang.annotation.Annotation; -import java.util.*; - -import static com.github.klee0kai.stone.AnnotationProcessor.allClassesHelper; -import static com.github.klee0kai.stone.helpers.SetFieldHelper.capitalized; - -/** - * Collected method details of compile element or method specs. - * Collect the information you need in one place - */ -public class MethodDetail implements Cloneable { - - public String methodName; - - public TypeName returnType; - - public Set modifiers = Collections.emptySet(); - - public ElementKind elementKind; - - public List args = new LinkedList<>(); - - public Map, IAnnotation> annotations = new HashMap<>(); - public LinkedList gcScopeAnnotations = new LinkedList<>(); - public Set qualifierAnns = new HashSet<>(); - - public Object defValue = null; - - public Element sourceEl; - - /** - * Take method details from compile element - * - * @param element original element - * @return new MethodDetail of element - */ - public static MethodDetail of(ExecutableElement element) { - MethodDetail methodDetail = new MethodDetail(); - methodDetail.methodName = element.getSimpleName().toString(); - methodDetail.returnType = TypeName.get(element.getReturnType()); - methodDetail.modifiers = element.getModifiers(); - methodDetail.elementKind = element.getKind(); - methodDetail.defValue = element.getDefaultValue() != null ? element.getDefaultValue().getValue() : null; - methodDetail.sourceEl = element; - - - methodDetail.addAnnotation(InitAnn.of(element.getAnnotation(Init.class))); - methodDetail.addAnnotation(ExtOfAnn.of(element.getAnnotation(ExtendOf.class))); - methodDetail.addAnnotation(ProvideAnn.of(element.getAnnotation(Provide.class))); - methodDetail.addAnnotation(BindInstanceAnn.of(element.getAnnotation(BindInstance.class))); - methodDetail.addAnnotation(ProtectInjectedAnn.of(element.getAnnotation(ProtectInjected.class))); - methodDetail.addAnnotation(RunGcAnn.of(element.getAnnotation(RunGc.class))); - methodDetail.addAnnotation(SwitchCacheAnn.of(element.getAnnotation(SwitchCache.class))); - methodDetail.addAnnotation(InjectAnn.of(element.getAnnotation(Inject.class))); - methodDetail.addAnnotation(SingletonAnn.of(element.getAnnotation(Singleton.class))); - methodDetail.addAnnotation(ModuleOriginFactoryAnn.of(element.getAnnotation(ModuleOriginFactory.class))); - - List> scClasses = Arrays.asList(GcAllScope.class, GcWeakScope.class, GcSoftScope.class, GcStrongScope.class); - for (Class sc : scClasses) - if (element.getAnnotation(sc) != null) - methodDetail.gcScopeAnnotations.add(ClassName.get(sc)); - - for (AnnotationMirror ann : element.getAnnotationMirrors()) { - String clName = ann.getAnnotationType().toString(); - ClassDetail gcAnn = allClassesHelper.findGcScopeAnnotation(clName); - if (gcAnn != null) methodDetail.gcScopeAnnotations.add(gcAnn.className); - - ClassDetail qualifierAnn = allClassesHelper.findQualifierAnnotation(clName); - if (qualifierAnn != null) methodDetail.qualifierAnns.add(QualifierAnn.of(ann)); - } - for (VariableElement v : element.getParameters()) { - // get$annotations not checked for method's arguments - String getAnnotationsElName = "get" + capitalized(v.getSimpleName().toString()) + "$annotations"; - Element getAnnotationsEl = ListUtils.first(element.getParameters(), (i, it) -> - Objects.equals(it.getSimpleName().toString(), getAnnotationsElName) - ); - methodDetail.args.add(FieldDetail.of(v, getAnnotationsEl)); - } - - return methodDetail; - } - - /** - * Create new method without args and returns - * - * @param methodName method name - * @return new FieldDetail object - */ - public static MethodDetail simpleName(String methodName) { - MethodDetail methodDetail = new MethodDetail(); - methodDetail.methodName = methodName; - return methodDetail; - } - - /** - * Create new get type method. - * - * @param name method name. Supposed to be like "getSmth" - * @param typeName return type of method - * @return new FieldDetail object - */ - public static MethodDetail simpleGetMethod(String name, TypeName typeName) { - MethodDetail m = new MethodDetail(); - m.methodName = name; - m.returnType = typeName; - return m; - } - - /** - * Create new set type method. - * - * @param name method name. Supposed to be like "setSmth" - * @param typeName arg type of method - * @return new FieldDetail object - */ - public static MethodDetail simpleSetMethod(String name, TypeName typeName) { - MethodDetail m = new MethodDetail(); - m.methodName = name; - m.args.add(FieldDetail.simple(name, typeName)); - m.returnType = TypeName.VOID; - return m; - } - - /** - * Create new class constructor method. - * - * @param args list of args - * @return new methodDetail object - */ - public static MethodDetail constructorMethod(List args) { - MethodDetail m = new MethodDetail(); - m.methodName = ""; - m.args = args; - return m; - } - - /** - * @return true if method has abstract modifier - */ - public boolean isAbstract() { - return modifiers.contains(Modifier.ABSTRACT); - } - - /** - * Methods are same if they have same name and argument types - * - * @param methodDetail method to compare - * @return true if methods are same - */ - public boolean isSameMethod(MethodDetail methodDetail) { - if (methodDetail == null - || !Objects.equals(this.methodName, methodDetail.methodName) - || ((args == null) != (methodDetail.args == null)) - || args != null && args.size() != methodDetail.args.size()) { - return false; - } - if (args == null) - return true; - for (int i = 0; i < args.size(); i++) - if (!Objects.equals(args.get(i).type, methodDetail.args.get(i).type)) - return false; - return true; - } - - /** - * Add annotation to method - * - * @param annotation annotation details - */ - public void addAnnotation(IAnnotation annotation) { - if (annotation != null) annotations.put(annotation.getClass(), annotation); - } - - /** - * Get annotation by type - * - * @param tClass class name of annotation - * @param type of annotation - * @return found annotation - */ - public T ann(Class tClass) { - return (T) annotations.getOrDefault(tClass, null); - } - - /** - * Check is any annotation exist - * - * @param aClasses list of annotation types - * @return found first annotation from list - */ - @SafeVarargs - public final IAnnotation anyAnnotation(Class... aClasses) { - for (Class cl : aClasses) { - IAnnotation ann = annotations.getOrDefault(cl, null); - if (ann != null) return ann; - } - return null; - } - - /** - * Check is list of annotations exist - * - * @param aClasses list of annotation types - * @return true if all annotations from list exist - */ - @SafeVarargs - public final boolean hasAnnotations(Class... aClasses) { - for (Class cl : aClasses) { - if (!annotations.containsKey(cl)) return false; - } - return true; - } - - /** - * Check is any of annotation exist - * - * @param aClasses list of annotation types - * @return true if any annotation from list exist - */ - @SafeVarargs - public final boolean hasAnyAnnotation(Class... aClasses) { - for (Class cl : aClasses) { - if (annotations.containsKey(cl)) return true; - } - return false; - } - - /** - * Check class have annotations exact as annotation list - * - * @param aClasses list of annotation types - * @return true if class has exact same annotations list - */ - @SafeVarargs - public final boolean hasOnlyAnnotations(boolean allowGsScopeAnnotations, boolean allowQualifierAnnotations, Class... aClasses) { - if (annotations.size() > aClasses.length) return false; - List> availableClasses = Arrays.asList(aClasses); - for (Class annotation : annotations.keySet()) { - if (!availableClasses.contains(annotation)) return false; - } - return (allowGsScopeAnnotations || gcScopeAnnotations.isEmpty()) - && (allowQualifierAnnotations || qualifierAnns.isEmpty()); - } - - - @Override - public MethodDetail clone() throws CloneNotSupportedException { - return (MethodDetail) super.clone(); - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - MethodDetail that = (MethodDetail) o; - return Objects.equals(methodName, that.methodName) && Objects.equals(returnType, that.returnType) - && Objects.equals(args, that.args); - } - - @Override - public int hashCode() { - return Objects.hash(methodName, returnType, args); - } -} diff --git a/stone_processor/src/main/java/com/github/klee0kai/stone/model/Pair.java b/stone_processor/src/main/java/com/github/klee0kai/stone/model/Pair.java deleted file mode 100644 index 392abdc4..00000000 --- a/stone_processor/src/main/java/com/github/klee0kai/stone/model/Pair.java +++ /dev/null @@ -1,33 +0,0 @@ -package com.github.klee0kai.stone.model; - -import java.util.Objects; - -/** - * Simple pair type. - * - * @param first's type - * @param second's type - */ -public class Pair { - - public final K first; - public final T second; - - public Pair(K first, T second) { - this.first = first; - this.second = second; - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - Pair pair = (Pair) o; - return Objects.equals(first, pair.first) && Objects.equals(second, pair.second); - } - - @Override - public int hashCode() { - return Objects.hash(first, second); - } -} diff --git a/stone_processor/src/main/java/com/github/klee0kai/stone/model/TypeKindDetails.java b/stone_processor/src/main/java/com/github/klee0kai/stone/model/TypeKindDetails.java deleted file mode 100644 index 76ff9ad7..00000000 --- a/stone_processor/src/main/java/com/github/klee0kai/stone/model/TypeKindDetails.java +++ /dev/null @@ -1,72 +0,0 @@ -package com.github.klee0kai.stone.model; - -import com.squareup.javapoet.TypeSpec; - -import javax.lang.model.element.ElementKind; - -/** - * Out class king's enum. - * Collected class king of compile type or type specs. - * Collect the information you need in one place - */ -public enum TypeKindDetails { - - /** - * King of simple java class. - */ - CLASS, - /** - * King of simple java interface. - */ - INTERFACE, - /** - * Java enum type - */ - ENUM, - /** - * Java annotation type - */ - ANNOTATION; - - /** - * Take class king details from compile type element - * - * @param elementKind original element - * @return new TypeKindDetails object of this element - */ - public static TypeKindDetails of(ElementKind elementKind) { - if (elementKind == ElementKind.ANNOTATION_TYPE) { - return ANNOTATION; - } else if (elementKind == ElementKind.INTERFACE) { - return INTERFACE; - } else if (elementKind == ElementKind.ENUM) { - return ENUM; - } else if (elementKind == ElementKind.CLASS) { - return CLASS; - } else { - return null; - } - } - - /** - * Take class king details from type specs. - * - * @param king original element - * @return new TypeKindDetails object of this element - */ - public static TypeKindDetails of(TypeSpec.Kind king) { - if (king == TypeSpec.Kind.ANNOTATION) { - return ANNOTATION; - } else if (king == TypeSpec.Kind.INTERFACE) { - return INTERFACE; - } else if (king == TypeSpec.Kind.ENUM) { - return ENUM; - } else if (king == TypeSpec.Kind.CLASS) { - return CLASS; - } else { - return null; - } - } -} - - diff --git a/stone_processor/src/main/java/com/github/klee0kai/stone/model/annotations/BindInstanceAnn.java b/stone_processor/src/main/java/com/github/klee0kai/stone/model/annotations/BindInstanceAnn.java deleted file mode 100644 index 23ba3688..00000000 --- a/stone_processor/src/main/java/com/github/klee0kai/stone/model/annotations/BindInstanceAnn.java +++ /dev/null @@ -1,42 +0,0 @@ -package com.github.klee0kai.stone.model.annotations; - -import com.github.klee0kai.stone._hidden_.types.ListUtils; -import com.github.klee0kai.stone.annotations.module.BindInstance; -import com.squareup.javapoet.AnnotationSpec; -import com.squareup.javapoet.ClassName; - -import java.lang.annotation.Annotation; -import java.util.List; -import java.util.Objects; - -public class BindInstanceAnn implements Cloneable, IAnnotation { - - public BindInstance.CacheType cacheType = BindInstance.CacheType.Soft; - - public static BindInstanceAnn of(BindInstance ann) { - if (ann == null) - return null; - BindInstanceAnn sAnn = new BindInstanceAnn(); - sAnn.cacheType = ann.cache(); - return sAnn; - } - - public static BindInstanceAnn findFrom(List annotationSpecs) { - AnnotationSpec spec = ListUtils.first(annotationSpecs, - (inx, ob) -> Objects.equals(ob.type, ClassName.get(BindInstance.class))); - if (spec == null) - return null; - return new BindInstanceAnn(); - } - - - @Override - public BindInstanceAnn clone() throws CloneNotSupportedException { - return (BindInstanceAnn) super.clone(); - } - - @Override - public Class originalAnn() { - return BindInstance.class; - } -} diff --git a/stone_processor/src/main/java/com/github/klee0kai/stone/model/annotations/ComponentAnn.java b/stone_processor/src/main/java/com/github/klee0kai/stone/model/annotations/ComponentAnn.java deleted file mode 100644 index 16723257..00000000 --- a/stone_processor/src/main/java/com/github/klee0kai/stone/model/annotations/ComponentAnn.java +++ /dev/null @@ -1,97 +0,0 @@ -package com.github.klee0kai.stone.model.annotations; - -import com.github.klee0kai.stone._hidden_.types.ListUtils; -import com.github.klee0kai.stone.annotations.component.Component; -import com.github.klee0kai.stone.exceptions.IncorrectSignatureException; -import com.github.klee0kai.stone.exceptions.PrimitiveTypeNonSupportedStoneException; -import com.github.klee0kai.stone.utils.ClassNameUtils; -import com.squareup.javapoet.AnnotationSpec; -import com.squareup.javapoet.ClassName; - -import javax.lang.model.element.AnnotationMirror; -import javax.lang.model.element.AnnotationValue; -import javax.lang.model.element.ExecutableElement; -import java.lang.annotation.Annotation; -import java.util.LinkedList; -import java.util.List; -import java.util.Map; -import java.util.Objects; - -public class ComponentAnn implements Cloneable, IAnnotation { - - public List identifiers = new LinkedList<>(); - - public List wrapperProviders = new LinkedList<>(); - - public static ComponentAnn of(AnnotationMirror annMirror) { - if (annMirror == null) - return null; - ComponentAnn componentAnn = new ComponentAnn(); - - ExecutableElement identifierKey = null; - ExecutableElement wrappersProvidersKey = null; - Map elementMap = annMirror.getElementValues(); - if (elementMap != null) for (ExecutableElement k : elementMap.keySet()) { - if (Objects.equals(k.getSimpleName().toString(), "identifiers")) - identifierKey = k; - if (Objects.equals(k.getSimpleName().toString(), "wrapperProviders")) - wrappersProvidersKey = k; - } - - try { - AnnotationValue __qValue = elementMap != null && identifierKey != null ? elementMap.get(identifierKey) : null; - if (__qValue != null) { - List identifiers = __qValue.getValue() instanceof List ? (List) __qValue.getValue() : null; - for (int i = 0; identifiers != null && i < identifiers.size(); i++) { - if (identifiers.get(i) == null) - continue; - componentAnn.identifiers.add(ClassNameUtils.classNameOf(identifiers.get(i).toString())); - } - } - } catch (Exception e) { - if (e instanceof PrimitiveTypeNonSupportedStoneException) { - throw new IncorrectSignatureException("Primitive types non supported for Component's identifiers", e); - } - throw e; - } - - try { - AnnotationValue __wrValue = elementMap != null && wrappersProvidersKey != null ? elementMap.get(wrappersProvidersKey) : null; - if (__wrValue != null) { - List wrapperProviders = __wrValue.getValue() instanceof List ? (List) __wrValue.getValue() : null; - for (int i = 0; wrapperProviders != null && i < wrapperProviders.size(); i++) { - if (wrapperProviders.get(i) == null) - continue; - componentAnn.wrapperProviders.add(ClassNameUtils.classNameOf(wrapperProviders.get(i).toString())); - } - } - } catch (Exception e) { - if (e instanceof PrimitiveTypeNonSupportedStoneException) { - throw new IncorrectSignatureException("Primitive types non supported for Component's WrapperProviders", e); - } - throw e; - } - - - return componentAnn; - } - - - public static ComponentAnn findFrom(List annotationSpecs) { - AnnotationSpec spec = ListUtils.first(annotationSpecs, - (inx, ob) -> Objects.equals(ob.type, ClassName.get(Component.class))); - if (spec == null) - return null; - return new ComponentAnn(); - } - - @Override - public ComponentAnn clone() throws CloneNotSupportedException { - return (ComponentAnn) super.clone(); - } - - @Override - public Class originalAnn() { - return Component.class; - } -} diff --git a/stone_processor/src/main/java/com/github/klee0kai/stone/model/annotations/DependenciesAnn.java b/stone_processor/src/main/java/com/github/klee0kai/stone/model/annotations/DependenciesAnn.java deleted file mode 100644 index 7e9f3d99..00000000 --- a/stone_processor/src/main/java/com/github/klee0kai/stone/model/annotations/DependenciesAnn.java +++ /dev/null @@ -1,38 +0,0 @@ -package com.github.klee0kai.stone.model.annotations; - -import com.github.klee0kai.stone._hidden_.types.ListUtils; -import com.github.klee0kai.stone.annotations.dependencies.Dependencies; -import com.squareup.javapoet.AnnotationSpec; -import com.squareup.javapoet.ClassName; - -import javax.lang.model.element.AnnotationMirror; -import java.lang.annotation.Annotation; -import java.util.List; -import java.util.Objects; - -public class DependenciesAnn implements Cloneable, IAnnotation { - - public static DependenciesAnn of(AnnotationMirror annMirror) { - if (annMirror == null) - return null; - return new DependenciesAnn(); - } - - public static DependenciesAnn findFrom(List annotationSpecs) { - AnnotationSpec spec = ListUtils.first(annotationSpecs, - (inx, ob) -> Objects.equals(ob.type, ClassName.get(Dependencies.class))); - if (spec == null) - return null; - return new DependenciesAnn(); - } - - @Override - public DependenciesAnn clone() throws CloneNotSupportedException { - return (DependenciesAnn) super.clone(); - } - - @Override - public Class originalAnn() { - return Dependencies.class; - } -} diff --git a/stone_processor/src/main/java/com/github/klee0kai/stone/model/annotations/ExtOfAnn.java b/stone_processor/src/main/java/com/github/klee0kai/stone/model/annotations/ExtOfAnn.java deleted file mode 100644 index cb9eda0e..00000000 --- a/stone_processor/src/main/java/com/github/klee0kai/stone/model/annotations/ExtOfAnn.java +++ /dev/null @@ -1,44 +0,0 @@ -package com.github.klee0kai.stone.model.annotations; - -import com.github.klee0kai.stone._hidden_.types.ListUtils; -import com.github.klee0kai.stone.annotations.component.ExtendOf; -import com.squareup.javapoet.AnnotationSpec; -import com.squareup.javapoet.ClassName; - -import javax.lang.model.element.AnnotationMirror; -import java.lang.annotation.Annotation; -import java.util.List; -import java.util.Objects; - -public class ExtOfAnn implements Cloneable, IAnnotation { - - public static ExtOfAnn of(ExtendOf ann) { - if (ann == null) - return null; - return new ExtOfAnn(); - } - - public static ExtOfAnn of(AnnotationMirror annMirror) { - if (annMirror == null) - return null; - return new ExtOfAnn(); - } - - public static ExtOfAnn findFrom(List annotationSpecs) { - AnnotationSpec spec = ListUtils.first(annotationSpecs, - (inx, ob) -> Objects.equals(ob.type, ClassName.get(ExtendOf.class))); - if (spec == null) - return null; - return new ExtOfAnn(); - } - - @Override - public ExtOfAnn clone() throws CloneNotSupportedException { - return (ExtOfAnn) super.clone(); - } - - @Override - public Class originalAnn() { - return ExtendOf.class; - } -} diff --git a/stone_processor/src/main/java/com/github/klee0kai/stone/model/annotations/IAnnotation.java b/stone_processor/src/main/java/com/github/klee0kai/stone/model/annotations/IAnnotation.java deleted file mode 100644 index 2c8a71f1..00000000 --- a/stone_processor/src/main/java/com/github/klee0kai/stone/model/annotations/IAnnotation.java +++ /dev/null @@ -1,9 +0,0 @@ -package com.github.klee0kai.stone.model.annotations; - -import java.lang.annotation.Annotation; - -public interface IAnnotation { - - Class originalAnn(); - -} diff --git a/stone_processor/src/main/java/com/github/klee0kai/stone/model/annotations/InitAnn.java b/stone_processor/src/main/java/com/github/klee0kai/stone/model/annotations/InitAnn.java deleted file mode 100644 index 5690967f..00000000 --- a/stone_processor/src/main/java/com/github/klee0kai/stone/model/annotations/InitAnn.java +++ /dev/null @@ -1,44 +0,0 @@ -package com.github.klee0kai.stone.model.annotations; - -import com.github.klee0kai.stone._hidden_.types.ListUtils; -import com.github.klee0kai.stone.annotations.component.Init; -import com.squareup.javapoet.AnnotationSpec; -import com.squareup.javapoet.ClassName; - -import javax.lang.model.element.AnnotationMirror; -import java.lang.annotation.Annotation; -import java.util.List; -import java.util.Objects; - -public class InitAnn implements Cloneable, IAnnotation { - - public static InitAnn of(Init ann) { - if (ann == null) - return null; - return new InitAnn(); - } - - public static InitAnn of(AnnotationMirror annMirror) { - if (annMirror == null) - return null; - return new InitAnn(); - } - - public static InitAnn findFrom(List annotationSpecs) { - AnnotationSpec spec = ListUtils.first(annotationSpecs, - (inx, ob) -> Objects.equals(ob.type, ClassName.get(Init.class))); - if (spec == null) - return null; - return new InitAnn(); - } - - @Override - public InitAnn clone() throws CloneNotSupportedException { - return (InitAnn) super.clone(); - } - - @Override - public Class originalAnn() { - return Init.class; - } -} diff --git a/stone_processor/src/main/java/com/github/klee0kai/stone/model/annotations/InjectAnn.java b/stone_processor/src/main/java/com/github/klee0kai/stone/model/annotations/InjectAnn.java deleted file mode 100644 index 46f71482..00000000 --- a/stone_processor/src/main/java/com/github/klee0kai/stone/model/annotations/InjectAnn.java +++ /dev/null @@ -1,44 +0,0 @@ -package com.github.klee0kai.stone.model.annotations; - -import com.github.klee0kai.stone._hidden_.types.ListUtils; -import com.squareup.javapoet.AnnotationSpec; -import com.squareup.javapoet.ClassName; - -import javax.inject.Inject; -import javax.lang.model.element.AnnotationMirror; -import java.lang.annotation.Annotation; -import java.util.List; -import java.util.Objects; - -public class InjectAnn implements Cloneable,IAnnotation { - - public static InjectAnn of(Inject ann) { - if (ann == null) - return null; - return new InjectAnn(); - } - - public static InjectAnn of(AnnotationMirror annMirror) { - if (annMirror == null) - return null; - return new InjectAnn(); - } - - public static InjectAnn findFrom(List annotationSpecs) { - AnnotationSpec spec = ListUtils.first(annotationSpecs, - (inx, ob) -> Objects.equals(ob.type, ClassName.get(Inject.class))); - if (spec == null) - return null; - return new InjectAnn(); - } - - @Override - public InjectAnn clone() throws CloneNotSupportedException { - return (InjectAnn) super.clone(); - } - - @Override - public Class originalAnn() { - return Inject.class; - } -} diff --git a/stone_processor/src/main/java/com/github/klee0kai/stone/model/annotations/ModuleAnn.java b/stone_processor/src/main/java/com/github/klee0kai/stone/model/annotations/ModuleAnn.java deleted file mode 100644 index 44028126..00000000 --- a/stone_processor/src/main/java/com/github/klee0kai/stone/model/annotations/ModuleAnn.java +++ /dev/null @@ -1,38 +0,0 @@ -package com.github.klee0kai.stone.model.annotations; - -import com.github.klee0kai.stone._hidden_.types.ListUtils; -import com.github.klee0kai.stone.annotations.module.Module; -import com.squareup.javapoet.AnnotationSpec; -import com.squareup.javapoet.ClassName; - -import javax.lang.model.element.AnnotationMirror; -import java.lang.annotation.Annotation; -import java.util.List; -import java.util.Objects; - -public class ModuleAnn implements Cloneable, IAnnotation { - - public static ModuleAnn of(AnnotationMirror annMirror) { - if (annMirror == null) - return null; - return new ModuleAnn(); - } - - public static ModuleAnn findFrom(List annotationSpecs) { - AnnotationSpec spec = ListUtils.first(annotationSpecs, - (inx, ob) -> Objects.equals(ob.type, ClassName.get(Module.class))); - if (spec == null) - return null; - return new ModuleAnn(); - } - - @Override - public ModuleAnn clone() throws CloneNotSupportedException { - return (ModuleAnn) super.clone(); - } - - @Override - public Class originalAnn() { - return Module.class; - } -} diff --git a/stone_processor/src/main/java/com/github/klee0kai/stone/model/annotations/ModuleOriginFactoryAnn.java b/stone_processor/src/main/java/com/github/klee0kai/stone/model/annotations/ModuleOriginFactoryAnn.java deleted file mode 100644 index 10d13af7..00000000 --- a/stone_processor/src/main/java/com/github/klee0kai/stone/model/annotations/ModuleOriginFactoryAnn.java +++ /dev/null @@ -1,39 +0,0 @@ -package com.github.klee0kai.stone.model.annotations; - -import com.github.klee0kai.stone._hidden_.types.ListUtils; -import com.github.klee0kai.stone.annotations.component.ModuleOriginFactory; -import com.squareup.javapoet.AnnotationSpec; -import com.squareup.javapoet.ClassName; - -import java.lang.annotation.Annotation; -import java.util.List; -import java.util.Objects; - -public class ModuleOriginFactoryAnn implements Cloneable, IAnnotation { - - public static ModuleOriginFactoryAnn of(ModuleOriginFactory ann) { - if (ann == null) - return null; - ModuleOriginFactoryAnn sAnn = new ModuleOriginFactoryAnn(); - return sAnn; - } - - public static ModuleOriginFactoryAnn findFrom(List annotationSpecs) { - AnnotationSpec spec = ListUtils.first(annotationSpecs, - (inx, ob) -> Objects.equals(ob.type, ClassName.get(ModuleOriginFactory.class))); - if (spec == null) - return null; - return new ModuleOriginFactoryAnn(); - } - - @Override - public ModuleOriginFactoryAnn clone() throws CloneNotSupportedException { - return (ModuleOriginFactoryAnn) super.clone(); - } - - @Override - public Class originalAnn() { - return ModuleOriginFactory.class; - } - -} diff --git a/stone_processor/src/main/java/com/github/klee0kai/stone/model/annotations/ProtectInjectedAnn.java b/stone_processor/src/main/java/com/github/klee0kai/stone/model/annotations/ProtectInjectedAnn.java deleted file mode 100644 index 761785ca..00000000 --- a/stone_processor/src/main/java/com/github/klee0kai/stone/model/annotations/ProtectInjectedAnn.java +++ /dev/null @@ -1,41 +0,0 @@ -package com.github.klee0kai.stone.model.annotations; - -import com.github.klee0kai.stone._hidden_.types.ListUtils; -import com.github.klee0kai.stone.annotations.component.ProtectInjected; -import com.squareup.javapoet.AnnotationSpec; -import com.squareup.javapoet.ClassName; - -import java.lang.annotation.Annotation; -import java.util.List; -import java.util.Objects; - -public class ProtectInjectedAnn implements Cloneable, IAnnotation { - - public long timeMillis; - - public static ProtectInjectedAnn of(ProtectInjected ann) { - if (ann == null) - return null; - ProtectInjectedAnn sAnn = new ProtectInjectedAnn(); - sAnn.timeMillis = ann.timeMillis(); - return sAnn; - } - - public static ProtectInjectedAnn findFrom(List annotationSpecs) { - AnnotationSpec spec = ListUtils.first(annotationSpecs, - (inx, ob) -> Objects.equals(ob.type, ClassName.get(ProtectInjected.class))); - if (spec == null) - return null; - return new ProtectInjectedAnn(); - } - - @Override - public ProtectInjectedAnn clone() throws CloneNotSupportedException { - return (ProtectInjectedAnn) super.clone(); - } - - @Override - public Class originalAnn() { - return ProtectInjected.class; - } -} diff --git a/stone_processor/src/main/java/com/github/klee0kai/stone/model/annotations/ProvideAnn.java b/stone_processor/src/main/java/com/github/klee0kai/stone/model/annotations/ProvideAnn.java deleted file mode 100644 index 2232c442..00000000 --- a/stone_processor/src/main/java/com/github/klee0kai/stone/model/annotations/ProvideAnn.java +++ /dev/null @@ -1,45 +0,0 @@ -package com.github.klee0kai.stone.model.annotations; - -import com.github.klee0kai.stone._hidden_.types.ListUtils; -import com.github.klee0kai.stone.annotations.module.Provide; -import com.squareup.javapoet.AnnotationSpec; -import com.squareup.javapoet.ClassName; - -import java.lang.annotation.Annotation; -import java.util.List; -import java.util.Objects; - -public class ProvideAnn implements Cloneable, IAnnotation { - - public Provide.CacheType cacheType = Provide.CacheType.Factory; - - public static ProvideAnn of(Provide ann) { - if (ann == null) - return null; - ProvideAnn sAnn = new ProvideAnn(); - sAnn.cacheType = ann.cache(); - return sAnn; - } - - public static ProvideAnn findFrom(List annotationSpecs) { - AnnotationSpec spec = ListUtils.first(annotationSpecs, - (inx, ob) -> Objects.equals(ob.type, ClassName.get(Provide.class))); - if (spec == null) - return null; - return new ProvideAnn(); - } - - @Override - public ProvideAnn clone() throws CloneNotSupportedException { - return (ProvideAnn) super.clone(); - } - - public boolean isCachingProvideType() { - return cacheType != Provide.CacheType.Factory; - } - - @Override - public Class originalAnn() { - return Provide.class; - } -} diff --git a/stone_processor/src/main/java/com/github/klee0kai/stone/model/annotations/QualifierAnn.java b/stone_processor/src/main/java/com/github/klee0kai/stone/model/annotations/QualifierAnn.java deleted file mode 100644 index f2180d13..00000000 --- a/stone_processor/src/main/java/com/github/klee0kai/stone/model/annotations/QualifierAnn.java +++ /dev/null @@ -1,86 +0,0 @@ -package com.github.klee0kai.stone.model.annotations; - -import com.github.klee0kai.stone._hidden_.types.ListUtils; -import com.github.klee0kai.stone.model.ClassDetail; -import com.github.klee0kai.stone.model.MethodDetail; -import com.squareup.javapoet.ClassName; - -import javax.lang.model.element.AnnotationMirror; -import javax.lang.model.element.AnnotationValue; -import javax.lang.model.element.ExecutableElement; -import java.lang.annotation.Annotation; -import java.util.HashMap; -import java.util.Map; -import java.util.Objects; - -import static com.github.klee0kai.stone.AnnotationProcessor.allClassesHelper; - -public class QualifierAnn implements Cloneable, IAnnotation { - - - public String qualifierClStr = null; - - public Map values = new HashMap<>(); - - public static QualifierAnn custom(String custom) { - QualifierAnn qualifier = new QualifierAnn(); - qualifier.qualifierClStr = custom; - return qualifier; - } - - public static QualifierAnn of(AnnotationMirror annMirror) { - if (annMirror == null) - return null; - QualifierAnn qualifier = new QualifierAnn(); - qualifier.qualifierClStr = annMirror.getAnnotationType().toString(); - Map elementMap = annMirror.getElementValues(); - if (elementMap != null) for (ExecutableElement k : elementMap.keySet()) - qualifier.values.putIfAbsent(k.getSimpleName().toString(), elementMap.get(k).getValue()); - - ClassDetail annCl = allClassesHelper.tryFindForType(ClassName.get(annMirror.getAnnotationType())); - if (annCl != null) { - for (MethodDetail m : annCl.getAllMethods(false, false)) { - if (m.defValue != null) qualifier.values.putIfAbsent(m.methodName, m.defValue); - } - } - - return qualifier; - } - - @Override - public Class originalAnn() { - return null; - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - QualifierAnn that = (QualifierAnn) o; - return Objects.equals(qualifierClStr, that.qualifierClStr) && Objects.equals(values, that.values); - } - - @Override - public int hashCode() { - return Objects.hash(qualifierClStr, values); - } - - @Override - public QualifierAnn clone() throws CloneNotSupportedException { - return (QualifierAnn) super.clone(); - } - - @Override - public String toString() { - StringBuilder builder = new StringBuilder(); - builder.append("@"); - builder.append(qualifierClStr); - if (!values.isEmpty()) { - builder.append("(") - .append(String.join(",", ListUtils.format(values.values(), Object::toString))) - .append(")"); - - } - return builder.toString(); - } -} diff --git a/stone_processor/src/main/java/com/github/klee0kai/stone/model/annotations/RunGcAnn.java b/stone_processor/src/main/java/com/github/klee0kai/stone/model/annotations/RunGcAnn.java deleted file mode 100644 index 173c115f..00000000 --- a/stone_processor/src/main/java/com/github/klee0kai/stone/model/annotations/RunGcAnn.java +++ /dev/null @@ -1,40 +0,0 @@ -package com.github.klee0kai.stone.model.annotations; - -import com.github.klee0kai.stone._hidden_.types.ListUtils; -import com.github.klee0kai.stone.annotations.component.RunGc; -import com.squareup.javapoet.AnnotationSpec; -import com.squareup.javapoet.ClassName; - -import java.lang.annotation.Annotation; -import java.util.List; -import java.util.Objects; - -public class RunGcAnn implements Cloneable, IAnnotation { - - - public static RunGcAnn of(RunGc ann) { - if (ann == null) - return null; - RunGcAnn sAnn = new RunGcAnn(); - return sAnn; - } - - public static RunGcAnn findFrom(List annotationSpecs) { - AnnotationSpec spec = ListUtils.first(annotationSpecs, - (inx, ob) -> Objects.equals(ob.type, ClassName.get(RunGc.class))); - if (spec == null) - return null; - return new RunGcAnn(); - } - - - @Override - public RunGcAnn clone() throws CloneNotSupportedException { - return (RunGcAnn) super.clone(); - } - - @Override - public Class originalAnn() { - return RunGc.class; - } -} diff --git a/stone_processor/src/main/java/com/github/klee0kai/stone/model/annotations/SingletonAnn.java b/stone_processor/src/main/java/com/github/klee0kai/stone/model/annotations/SingletonAnn.java deleted file mode 100644 index 0b95b059..00000000 --- a/stone_processor/src/main/java/com/github/klee0kai/stone/model/annotations/SingletonAnn.java +++ /dev/null @@ -1,44 +0,0 @@ -package com.github.klee0kai.stone.model.annotations; - -import com.github.klee0kai.stone._hidden_.types.ListUtils; -import com.squareup.javapoet.AnnotationSpec; -import com.squareup.javapoet.ClassName; - -import javax.inject.Singleton; -import javax.lang.model.element.AnnotationMirror; -import java.lang.annotation.Annotation; -import java.util.List; -import java.util.Objects; - -public class SingletonAnn implements Cloneable, IAnnotation { - - public static SingletonAnn of(Singleton ann) { - if (ann == null) - return null; - return new SingletonAnn(); - } - - public static SingletonAnn of(AnnotationMirror annMirror) { - if (annMirror == null) - return null; - return new SingletonAnn(); - } - - public static SingletonAnn findFrom(List annotationSpecs) { - AnnotationSpec spec = ListUtils.first(annotationSpecs, - (inx, ob) -> Objects.equals(ob.type, ClassName.get(Singleton.class))); - if (spec == null) - return null; - return new SingletonAnn(); - } - - @Override - public SingletonAnn clone() throws CloneNotSupportedException { - return (SingletonAnn) super.clone(); - } - - @Override - public Class originalAnn() { - return Singleton.class; - } -} diff --git a/stone_processor/src/main/java/com/github/klee0kai/stone/model/annotations/SwitchCacheAnn.java b/stone_processor/src/main/java/com/github/klee0kai/stone/model/annotations/SwitchCacheAnn.java deleted file mode 100644 index 7b5c3aad..00000000 --- a/stone_processor/src/main/java/com/github/klee0kai/stone/model/annotations/SwitchCacheAnn.java +++ /dev/null @@ -1,44 +0,0 @@ -package com.github.klee0kai.stone.model.annotations; - -import com.github.klee0kai.stone._hidden_.types.ListUtils; -import com.github.klee0kai.stone.annotations.component.SwitchCache; -import com.squareup.javapoet.AnnotationSpec; -import com.squareup.javapoet.ClassName; - -import java.lang.annotation.Annotation; -import java.util.List; -import java.util.Objects; - -public class SwitchCacheAnn implements Cloneable, IAnnotation { - - public SwitchCache.CacheType cache; - public long timeMillis; - - public static SwitchCacheAnn of(SwitchCache ann) { - if (ann == null) - return null; - SwitchCacheAnn sAnn = new SwitchCacheAnn(); - sAnn.timeMillis = ann.timeMillis(); - sAnn.cache = ann.cache(); - return sAnn; - } - - public static SwitchCacheAnn findFrom(List annotationSpecs) { - AnnotationSpec spec = ListUtils.first(annotationSpecs, - (inx, ob) -> Objects.equals(ob.type, ClassName.get(SwitchCache.class))); - if (spec == null) - return null; - return new SwitchCacheAnn(); - } - - - @Override - public SwitchCacheAnn clone() throws CloneNotSupportedException { - return (SwitchCacheAnn) super.clone(); - } - - @Override - public Class originalAnn() { - return SwitchCache.class; - } -} diff --git a/stone_processor/src/main/java/com/github/klee0kai/stone/model/annotations/WrapperCreatorsAnn.java b/stone_processor/src/main/java/com/github/klee0kai/stone/model/annotations/WrapperCreatorsAnn.java deleted file mode 100644 index ce824521..00000000 --- a/stone_processor/src/main/java/com/github/klee0kai/stone/model/annotations/WrapperCreatorsAnn.java +++ /dev/null @@ -1,65 +0,0 @@ -package com.github.klee0kai.stone.model.annotations; - -import com.github.klee0kai.stone._hidden_.types.ListUtils; -import com.github.klee0kai.stone.annotations.wrappers.WrappersCreator; -import com.github.klee0kai.stone.utils.ClassNameUtils; -import com.squareup.javapoet.AnnotationSpec; -import com.squareup.javapoet.ClassName; - -import javax.lang.model.element.AnnotationMirror; -import javax.lang.model.element.AnnotationValue; -import javax.lang.model.element.ExecutableElement; -import java.lang.annotation.Annotation; -import java.util.LinkedList; -import java.util.List; -import java.util.Map; -import java.util.Objects; - -public class WrapperCreatorsAnn implements Cloneable, IAnnotation { - - public List wrappers = new LinkedList<>(); - - public static WrapperCreatorsAnn of(AnnotationMirror annMirror) { - if (annMirror == null) - return null; - - WrapperCreatorsAnn wrapperCreatorsAnn = new WrapperCreatorsAnn(); - - ExecutableElement wrappersKey = null; - Map elementMap = annMirror.getElementValues(); - if (elementMap != null) for (ExecutableElement k : elementMap.keySet()) - if (Objects.equals(k.getSimpleName().toString(), "wrappers")) - wrappersKey = k; - - AnnotationValue __wrValue = elementMap != null && wrappersKey != null ? elementMap.get(wrappersKey) : null; - if (__wrValue != null) { - List wrappers = __wrValue.getValue() instanceof List ? (List) __wrValue.getValue() : null; - for (int i = 0; wrappers != null && i < wrappers.size(); i++) { - if (wrappers.get(i) == null) - continue; - wrapperCreatorsAnn.wrappers.add(ClassNameUtils.classNameOf(wrappers.get(i).toString())); - } - } - - return wrapperCreatorsAnn; - } - - - public static WrapperCreatorsAnn findFrom(List annotationSpecs) { - AnnotationSpec spec = ListUtils.first(annotationSpecs, - (inx, ob) -> Objects.equals(ob.type, ClassName.get(WrappersCreator.class))); - if (spec == null) - return null; - return new WrapperCreatorsAnn(); - } - - @Override - public WrapperCreatorsAnn clone() throws CloneNotSupportedException { - return (WrapperCreatorsAnn) super.clone(); - } - - @Override - public Class originalAnn() { - return WrappersCreator.class; - } -} diff --git a/stone_processor/src/main/java/com/github/klee0kai/stone/utils/AnnotationMirrorUtil.java b/stone_processor/src/main/java/com/github/klee0kai/stone/utils/AnnotationMirrorUtil.java deleted file mode 100644 index cd94b06f..00000000 --- a/stone_processor/src/main/java/com/github/klee0kai/stone/utils/AnnotationMirrorUtil.java +++ /dev/null @@ -1,47 +0,0 @@ -package com.github.klee0kai.stone.utils; - -import javax.lang.model.element.AnnotationMirror; -import javax.lang.model.element.AnnotationValue; -import javax.lang.model.element.Element; - -/** - * Annotation mirror's util - */ -public class AnnotationMirrorUtil { - - - /** - * Find annotation mirror on element by the type - * - * @param typeElement compile code element - * @param clazz annotation class - * @return annotation mirror if exist - */ - public static AnnotationMirror findAnnotationMirror(Element typeElement, Class clazz) { - String clazzName = clazz.getName(); - for (AnnotationMirror m : typeElement.getAnnotationMirrors()) { - if (m.getAnnotationType().toString().equals(clazzName)) { - return m; - } - } - return null; - } - - - /** - * Find value for annotation mirror by the name of field - * - * @param annotationMirror annotation mirror - * @param strKey field's name - * @return value if exist - */ - public static AnnotationValue findValue(AnnotationMirror annotationMirror, String strKey) { - for (Object k : annotationMirror.getElementValues().keySet()) { - if (k.toString().equals(strKey)) { - return annotationMirror.getElementValues().get(k); - } - } - return null; - } - -} diff --git a/stone_processor/src/main/java/com/github/klee0kai/stone/utils/ClassNameUtils.java b/stone_processor/src/main/java/com/github/klee0kai/stone/utils/ClassNameUtils.java deleted file mode 100644 index 591684f8..00000000 --- a/stone_processor/src/main/java/com/github/klee0kai/stone/utils/ClassNameUtils.java +++ /dev/null @@ -1,76 +0,0 @@ -package com.github.klee0kai.stone.utils; - -import com.github.klee0kai.stone.exceptions.ClassNotFoundStoneException; -import com.github.klee0kai.stone.exceptions.PrimitiveTypeNonSupportedStoneException; -import com.squareup.javapoet.ClassName; -import com.squareup.javapoet.ParameterizedTypeName; -import com.squareup.javapoet.TypeName; -import com.squareup.javapoet.WildcardTypeName; - -import java.util.List; - -import static com.github.klee0kai.stone.exceptions.ExceptionStringBuilder.createErrorMes; - -/** - * Class and type resolving utils. - */ -public class ClassNameUtils { - - /** - * Get class name from full name. - * Primitives and boxed types are not support - * - * @param clFullName class full name like "com.github.klee0kai.stone.annotations.component.class" - * @return class name - * @throws PrimitiveTypeNonSupportedStoneException primitive types are not support - */ - public static ClassName classNameOf(String clFullName) { - try { - if (clFullName.endsWith(".class")) - clFullName = clFullName.substring(0, clFullName.lastIndexOf(".class")); - return ClassName.get(clFullName.substring(0, clFullName.lastIndexOf(".")), - clFullName.substring(clFullName.lastIndexOf(".") + 1)); - } catch (Exception e) { - if (!clFullName.contains(".")) { - throw new PrimitiveTypeNonSupportedStoneException( - createErrorMes() - .primitiveTypesNonSupported(clFullName) - .build(), - e); - } - throw new ClassNotFoundStoneException( - createErrorMes() - .classNonFound(clFullName) - .build(), - e); - } - - } - - public static TypeName rawTypeOf(TypeName typeName) { - if (typeName instanceof ParameterizedTypeName) - return rawTypeOf(((ParameterizedTypeName) typeName).rawType); - if (typeName instanceof WildcardTypeName) { - List upperBounds = ((WildcardTypeName) typeName).upperBounds; - return rawTypeOf(!upperBounds.isEmpty() ? upperBounds.get(0) : null); - } - return typeName; - } - - - public static TypeName noWildCardType(TypeName type) { - if (type instanceof WildcardTypeName) { - List upperBounds = ((WildcardTypeName) type).upperBounds; - return !upperBounds.isEmpty() ? noWildCardType(upperBounds.get(0)) : type; - } - return type; - } - - public static String simpleName(TypeName typeName) { - TypeName raw = rawTypeOf(typeName); - if (raw instanceof ClassName) - return ((ClassName) raw).simpleName(); - return null; - } - -} diff --git a/stone_processor/src/main/java/com/github/klee0kai/stone/utils/CodeFileUtil.java b/stone_processor/src/main/java/com/github/klee0kai/stone/utils/CodeFileUtil.java deleted file mode 100644 index d01e484c..00000000 --- a/stone_processor/src/main/java/com/github/klee0kai/stone/utils/CodeFileUtil.java +++ /dev/null @@ -1,39 +0,0 @@ -package com.github.klee0kai.stone.utils; - -import com.github.klee0kai.stone.AnnotationProcessor; -import com.github.klee0kai.stone.annotations.module.Provide; -import com.squareup.javapoet.ClassName; -import com.squareup.javapoet.JavaFile; -import com.squareup.javapoet.TypeSpec; - -import java.io.IOException; - - -/** - * Generate java files util - */ -public class CodeFileUtil { - - /** - * Generate class java file. - * - * @param packageName package of type - * @param spec type specifications - */ - public static void writeToJavaFile(String packageName, TypeSpec spec) { - try { - JavaFile javaFile = - JavaFile.builder(packageName, spec) - .addFileComment("Generated by Stone Library\n") - .addFileComment("Project " + AnnotationProcessor.PROJECT_URL + "\n") - .addFileComment("Copyright (c) 2022 Andrey Kuzubov") - .addStaticImport(ClassName.get(Provide.CacheType.class), "*") - .build(); - javaFile.writeTo(AnnotationProcessor.env.getFiler()); - } catch (IOException e) { - //ignore - } - } - -} - diff --git a/stone_processor/src/main/java/com/github/klee0kai/stone/utils/ImplementMethodCollection.java b/stone_processor/src/main/java/com/github/klee0kai/stone/utils/ImplementMethodCollection.java deleted file mode 100644 index 237f2a32..00000000 --- a/stone_processor/src/main/java/com/github/klee0kai/stone/utils/ImplementMethodCollection.java +++ /dev/null @@ -1,58 +0,0 @@ -package com.github.klee0kai.stone.utils; - -import com.github.klee0kai.stone.exceptions.ImplementMethodStoneException; - -import javax.lang.model.element.Element; -import java.util.LinkedList; - -/** - * We collect all delayed launches and launch at the next stage - */ -public class ImplementMethodCollection { - - private final LinkedList collectRuns = new LinkedList<>(); - - - public void execute(String errMessage, Element souseEl, Runnable runnable) { - collectRuns.add(new DelayStart(errMessage, souseEl, runnable)); - } - - public void execute(Runnable runnable) { - execute(null, null, runnable); - } - - - public void execute(String errMessage, Runnable runnable) { - execute(errMessage, null, runnable); - } - - - /** - * Run all pending tasks - */ - public void executeAll() { - for (DelayStart r : collectRuns) { - try { - r.run.run(); - } catch (Throwable e) { - if (r.errorMessage == null) throw e; - throw new ImplementMethodStoneException(r.errorMessage, e, r.sourceEl); - } - } - - collectRuns.clear(); - } - - private static class DelayStart { - public String errorMessage; - public Element sourceEl; - public Runnable run; - - public DelayStart(String errorMessage, Element sourceEl, Runnable run) { - this.errorMessage = errorMessage; - this.sourceEl = sourceEl; - this.run = run; - } - } - -} diff --git a/stone_processor/src/main/java/com/github/klee0kai/stone/utils/LocalFieldName.java b/stone_processor/src/main/java/com/github/klee0kai/stone/utils/LocalFieldName.java deleted file mode 100644 index 640e55f8..00000000 --- a/stone_processor/src/main/java/com/github/klee0kai/stone/utils/LocalFieldName.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.github.klee0kai.stone.utils; - -public class LocalFieldName { - - private static long localVariableIndx = 0; - - - public static String genLocalFieldName() { - return "_lc" + localVariableIndx++; - } - - -} diff --git a/stone_processor/src/main/java/com/github/klee0kai/stone/utils/RecursiveDetector.java b/stone_processor/src/main/java/com/github/klee0kai/stone/utils/RecursiveDetector.java deleted file mode 100644 index b09f0867..00000000 --- a/stone_processor/src/main/java/com/github/klee0kai/stone/utils/RecursiveDetector.java +++ /dev/null @@ -1,37 +0,0 @@ -package com.github.klee0kai.stone.utils; - -import java.util.LinkedList; -import java.util.Objects; - -/** - * A tortoise is chasing the hare. - * If the sequence is looped, then the hare will meet the tortoise on the next circle - * - * @param sequence type - */ -public class RecursiveDetector { - - private final LinkedList race = new LinkedList<>(); - private long hareStep = 0; - - - /** - * Do next step. - * - * @param next next item in sequence - * @return true if sequence is cycled - */ - public boolean next(T next) { - race.add(next); - if (hareStep++ % 2 == 0) { - race.pollFirst(); - } - if (race.size() <= 2) return false; - - T hare = next; - T turtle = race.getFirst(); - return Objects.equals(hare, turtle); - } - - -} diff --git a/stone_processor/src/main/java/com/github/klee0kai/stone/utils/StoneNamingUtils.java b/stone_processor/src/main/java/com/github/klee0kai/stone/utils/StoneNamingUtils.java deleted file mode 100644 index 3dd32bb8..00000000 --- a/stone_processor/src/main/java/com/github/klee0kai/stone/utils/StoneNamingUtils.java +++ /dev/null @@ -1,87 +0,0 @@ -package com.github.klee0kai.stone.utils; - -import com.squareup.javapoet.ClassName; -import com.squareup.javapoet.TypeName; - -/** - * Stone's class naming utils - */ -public class StoneNamingUtils { - - public static String COMPONENT_NAME_SUFFIX = "StoneComponent"; - public static String FACTORY_NAME_SUFFIX = "_FStone"; - public static String MODULE_NAME_SUFFIX = "_MStone"; - public static String CACHE_CONTROL_NAME_SUFFIX = "_CCMStone"; - public static String HIDDEN_MODULE_NAME_SUFFIX = "_HMStone"; - public static String TYPE_WRAPPER_NAME_SUFFIX = "_TWStone"; - - /** - * Component's class name creator - * - * @param or original user's component's class type - * @return stone component class name - */ - public static ClassName genComponentNameMirror(TypeName or) { - if (!(or instanceof ClassName)) return null; - ClassName origin = (ClassName) or; - return ClassName.get(origin.packageName(), origin.simpleName() + COMPONENT_NAME_SUFFIX); - } - - /** - * Factory's class name creator - * - * @param or original user's module's class type - * @return stone factory class name - */ - public static ClassName genFactoryNameMirror(TypeName or) { - if (!(or instanceof ClassName)) return null; - ClassName origin = (ClassName) or; - return ClassName.get(origin.packageName(), origin.simpleName() + FACTORY_NAME_SUFFIX); - } - - - /** - * Module's class name creator - * - * @param or original user's module's class type - * @return stone module class name - */ - public static ClassName genModuleNameMirror(TypeName or) { - if (!(or instanceof ClassName)) return null; - ClassName origin = (ClassName) or; - return ClassName.get(origin.packageName(), origin.simpleName() + MODULE_NAME_SUFFIX); - } - - - /** - * CacheControl's class name creator - * - * @param or original user's module's class type - * @return stone cache-control class name - */ - public static ClassName genCacheControlInterfaceModuleNameMirror(TypeName or) { - if (!(or instanceof ClassName)) return null; - ClassName origin = (ClassName) or; - return ClassName.get(origin.packageName(), origin.simpleName() + CACHE_CONTROL_NAME_SUFFIX); - } - - /** - * HiddenModule's class name creator - * - * @param or original user's module's class type - * @return stone hidden-module class name - */ - public static ClassName genHiddenModuleNameMirror(TypeName or) { - if (!(or instanceof ClassName)) return null; - ClassName origin = (ClassName) or; - return ClassName.get(origin.packageName(), origin.simpleName() + HIDDEN_MODULE_NAME_SUFFIX); - } - - - public static ClassName typeWrappersClass(TypeName or) { - if (!(or instanceof ClassName)) return null; - ClassName origin = (ClassName) or; - return ClassName.get(origin.packageName(), origin.simpleName() + TYPE_WRAPPER_NAME_SUFFIX); - } - -} diff --git a/test_feature_core_deps/build.gradle.kts b/test_feature_core_deps/build.gradle.kts index 90417071..8bc4d7fe 100644 --- a/test_feature_core_deps/build.gradle.kts +++ b/test_feature_core_deps/build.gradle.kts @@ -1,6 +1,5 @@ plugins { alias(libs.plugins.kotlin.jvm) - alias(libs.plugins.kotlin.kapt) alias(libs.plugins.kotlin.ksp) } diff --git a/tests_compile/build.gradle.kts b/tests_compile/build.gradle.kts index 8c823144..90afe6de 100644 --- a/tests_compile/build.gradle.kts +++ b/tests_compile/build.gradle.kts @@ -1,19 +1,22 @@ plugins { - java + alias(libs.plugins.kotlin.jvm) + } tasks.test { useJUnitPlatform() } -dependencies { - implementation(project(":stone_lib")) - implementation(project(":stone_processor")) +dependencies { + implementation(project(":stone_multiplatform")) + implementation(project(":stone_ksp")) testImplementation(libs.bundles.junit) - testImplementation(libs.testing.compile) + testImplementation(libs.testing.kapt.compile) + // not support k2 + testImplementation("com.github.tschuchortdev:kotlin-compile-testing-ksp:1.5.0") } diff --git a/tests_compile/src/test/kotlin/com/github/klee0kai/stone/test/SimpleTests.kt b/tests_compile/src/test/kotlin/com/github/klee0kai/stone/test/SimpleTests.kt new file mode 100644 index 00000000..2cda01ed --- /dev/null +++ b/tests_compile/src/test/kotlin/com/github/klee0kai/stone/test/SimpleTests.kt @@ -0,0 +1,33 @@ +package com.github.klee0kai.stone.test + +import com.github.klee0kai.thekey.stone.ksp.StoneProcessorProvider +import com.tschuchort.compiletesting.KotlinCompilation +import com.tschuchort.compiletesting.SourceFile +import com.tschuchort.compiletesting.symbolProcessorProviders +import org.junit.jupiter.api.Assertions.assertEquals +import org.junit.jupiter.api.Assertions.assertTrue +import org.junit.jupiter.api.Test + +class SimpleKspTests { + + @Test + fun simpleTest() { + + val compilation = KotlinCompilation().apply { + sources = listOf(SourceFile.fromResources("SimpleCarComponent.kt")) + symbolProcessorProviders = listOf(StoneProcessorProvider()) + inheritClassPath = true + messageOutputStream = System.out + } + + val result = compilation.compile() + + assertEquals(KotlinCompilation.ExitCode.OK, result.exitCode) + + assertTrue( + result.messages.contains("CarInjectModule has duplicate"), + result.messages + ) + } + +} \ No newline at end of file diff --git a/tests_compile/src/test/kotlin/com/github/klee0kai/stone/test/Utils.kt b/tests_compile/src/test/kotlin/com/github/klee0kai/stone/test/Utils.kt new file mode 100644 index 00000000..f049ab56 --- /dev/null +++ b/tests_compile/src/test/kotlin/com/github/klee0kai/stone/test/Utils.kt @@ -0,0 +1,14 @@ +package com.github.klee0kai.stone.test + +import com.tschuchort.compiletesting.SourceFile + + +fun SourceFile.Companion.fromResources(path: String): SourceFile { + val content = object {}::class.java.classLoader + .getResourceAsStream(path) + ?.bufferedReader() + ?.readText() + ?: error("Resource not found: $path") + + return SourceFile.kotlin(path.substringAfterLast('/'), content) +} \ No newline at end of file diff --git a/tests_compile/src/test/resources/SimpleCarComponent.kt b/tests_compile/src/test/resources/SimpleCarComponent.kt new file mode 100644 index 00000000..7060da8f --- /dev/null +++ b/tests_compile/src/test/resources/SimpleCarComponent.kt @@ -0,0 +1,16 @@ +package com.github.klee0kai.stone.test; + +import com.github.klee0kai.stone.annotations.component.Component; +import com.github.klee0kai.stone.annotations.module.Module; + +@Component() +abstract class CarInjectComponent { + + abstract fun module(): CarInjectModule + +} + +@Module +abstract class CarInjectModule { + +} diff --git a/weakref_multiplatform/build.gradle.kts b/weakref_multiplatform/build.gradle.kts index a11b741f..a295b723 100644 --- a/weakref_multiplatform/build.gradle.kts +++ b/weakref_multiplatform/build.gradle.kts @@ -1,21 +1,11 @@ plugins { alias(libs.plugins.kotlin.multiplatform) - alias(libs.plugins.android.library) } group = "com.github.klee0kai.stone.weakref" version = libs.versions.stone.get() -android { - namespace = project.group.toString() - compileSdk = 36 - defaultConfig { - minSdk = 21 - } -} - kotlin { - androidTarget() jvm() js(IR) { browser() @@ -33,9 +23,17 @@ kotlin { commonTest.dependencies { implementation(kotlin("test")) } + all { + languageSettings { + // Enables expect/actual classes support without warnings + optIn("kotlin.ExperimentalStdlibApi") + compilerOptions.freeCompilerArgs.add("-Xexpect-actual-classes") + } + } } } + val isMac = System.getProperty("os.name").contains("Mac") if (isMac) kotlin { macosX64() diff --git a/weakref_multiplatform/src/androidMain/kotlin/com/github/klee0kai/stone/weakref/SoftRef.kt b/weakref_multiplatform/src/androidMain/kotlin/com/github/klee0kai/stone/weakref/SoftRef.kt deleted file mode 100644 index 94f654de..00000000 --- a/weakref_multiplatform/src/androidMain/kotlin/com/github/klee0kai/stone/weakref/SoftRef.kt +++ /dev/null @@ -1,15 +0,0 @@ -package com.github.klee0kai.stone.weakref - -import java.lang.ref.SoftReference - -actual class SoftRef actual constructor(value: T) : Ref { - - val weakRef: SoftReference = SoftReference(value) - - actual override fun get(): T? = weakRef.get() - - actual fun clear() { - weakRef.clear() - } - -} \ No newline at end of file diff --git a/weakref_multiplatform/src/androidMain/kotlin/com/github/klee0kai/stone/weakref/WeakRef.kt b/weakref_multiplatform/src/androidMain/kotlin/com/github/klee0kai/stone/weakref/WeakRef.kt deleted file mode 100644 index d4cc44ec..00000000 --- a/weakref_multiplatform/src/androidMain/kotlin/com/github/klee0kai/stone/weakref/WeakRef.kt +++ /dev/null @@ -1,15 +0,0 @@ -package com.github.klee0kai.stone.weakref - -import java.lang.ref.WeakReference - -actual class WeakRef actual constructor(value: T) : Ref { - - val weakRef: WeakReference = WeakReference(value) - - actual override fun get(): T? = weakRef.get() - - actual fun clear() { - weakRef.clear() - } - -} \ No newline at end of file diff --git a/weakref_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/weakref/Memory.kt b/weakref_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/weakref/Memory.kt index e63fb404..dafd477b 100644 --- a/weakref_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/weakref/Memory.kt +++ b/weakref_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/weakref/Memory.kt @@ -2,6 +2,6 @@ package com.github.klee0kai.stone.weakref expect object Memory { - fun gc() + fun gc() } \ No newline at end of file diff --git a/weakref_multiplatform/src/jvmMain/java/com/github/klee0kai/stone/weakref/Memory.jvm.kt b/weakref_multiplatform/src/jvmMain/kotlin/com/github/klee0kai/stone/weakref/Memory.jvm.kt similarity index 100% rename from weakref_multiplatform/src/jvmMain/java/com/github/klee0kai/stone/weakref/Memory.jvm.kt rename to weakref_multiplatform/src/jvmMain/kotlin/com/github/klee0kai/stone/weakref/Memory.jvm.kt From 0a6d3d3f861d3a621866bf03202040c8f8d4faae Mon Sep 17 00:00:00 2001 From: klee0kai Date: Sun, 18 Jan 2026 00:50:23 +0100 Subject: [PATCH 100/122] maven publish --- inject_multiplatform/build.gradle.kts | 11 ++--------- libs.versions.toml | 2 +- .../github/klee0kai/stone/publish/MavenPublishExt.kt | 11 ----------- stone_ksp/build.gradle.kts | 5 +++-- stone_multiplatform/build.gradle.kts | 9 --------- weakref_multiplatform/build.gradle.kts | 2 ++ 6 files changed, 8 insertions(+), 32 deletions(-) diff --git a/inject_multiplatform/build.gradle.kts b/inject_multiplatform/build.gradle.kts index 2c430e84..d4224d03 100644 --- a/inject_multiplatform/build.gradle.kts +++ b/inject_multiplatform/build.gradle.kts @@ -1,21 +1,14 @@ plugins { alias(libs.plugins.kotlin.multiplatform) -// alias(libs.plugins.android.library) + alias(libs.plugins.publish.stone) + alias(libs.plugins.publish.maven) } group = "com.github.klee0kai.stone.inject" version = libs.versions.stone.get() -//android { -// namespace = project.group.toString() -// compileSdk = 36 -// defaultConfig { -// minSdk = 21 -// } -//} kotlin { -// androidTarget() jvm() js(IR) { browser() diff --git a/libs.versions.toml b/libs.versions.toml index fdcf4dcd..340d8169 100644 --- a/libs.versions.toml +++ b/libs.versions.toml @@ -1,6 +1,6 @@ [versions] -stone = "1.0.7" +stone = "2.0.0" kotlin = "2.2.21" ksp = "2.3.2" diff --git a/plugin_publish/src/main/kotlin/com/github/klee0kai/stone/publish/MavenPublishExt.kt b/plugin_publish/src/main/kotlin/com/github/klee0kai/stone/publish/MavenPublishExt.kt index 79a5954c..6d8af935 100644 --- a/plugin_publish/src/main/kotlin/com/github/klee0kai/stone/publish/MavenPublishExt.kt +++ b/plugin_publish/src/main/kotlin/com/github/klee0kai/stone/publish/MavenPublishExt.kt @@ -14,17 +14,6 @@ fun PublishingExtension.stoneToMaven(project: Project) { artifactId = project.name version = project.version.toString() - when { - "java" in project.components.names -> { - //publish simple java lib - from(project.components["java"]) - } - "release" in project.components.names -> { - //publish android lib - from(project.components["release"]) - } - } - pom { name.set("Stone") description.set("Library DI designed on weak references.") diff --git a/stone_ksp/build.gradle.kts b/stone_ksp/build.gradle.kts index 101a8b7e..ed8227eb 100644 --- a/stone_ksp/build.gradle.kts +++ b/stone_ksp/build.gradle.kts @@ -1,9 +1,10 @@ plugins { alias(libs.plugins.kotlin.multiplatform) - `maven-publish` + alias(libs.plugins.publish.stone) + alias(libs.plugins.publish.maven) } -group = "com.github.klee0kai.thekey.stone.ksp" +group = "com.github.klee0kai.stone.ksp" version = libs.versions.stone.get() diff --git a/stone_multiplatform/build.gradle.kts b/stone_multiplatform/build.gradle.kts index 1f51ba3d..63089057 100644 --- a/stone_multiplatform/build.gradle.kts +++ b/stone_multiplatform/build.gradle.kts @@ -1,21 +1,12 @@ plugins { alias(libs.plugins.kotlin.multiplatform) -// alias(libs.plugins.android.library) } group = "com.github.klee0kai.stone" version = libs.versions.stone.get() -//android { -// namespace = project.group.toString() -// compileSdk = 36 -// defaultConfig { -// minSdk = 21 -// } -//} kotlin { -// androidTarget() jvm() js(IR) { browser() diff --git a/weakref_multiplatform/build.gradle.kts b/weakref_multiplatform/build.gradle.kts index a295b723..a933fa7d 100644 --- a/weakref_multiplatform/build.gradle.kts +++ b/weakref_multiplatform/build.gradle.kts @@ -1,5 +1,7 @@ plugins { alias(libs.plugins.kotlin.multiplatform) + alias(libs.plugins.publish.stone) + alias(libs.plugins.publish.maven) } group = "com.github.klee0kai.stone.weakref" From 063b4515556b6290b891c344d2925fd3aa4a29e6 Mon Sep 17 00:00:00 2001 From: klee0kai Date: Sun, 18 Jan 2026 00:53:28 +0100 Subject: [PATCH 101/122] correct github deps --- .github/workflows/deploy_dev.yml | 6 +++--- .github/workflows/deploy_pull_request.yml | 6 +++--- .github/workflows/deploy_release.yml | 4 ++-- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/.github/workflows/deploy_dev.yml b/.github/workflows/deploy_dev.yml index ded9b430..a8ac8243 100644 --- a/.github/workflows/deploy_dev.yml +++ b/.github/workflows/deploy_dev.yml @@ -35,7 +35,7 @@ jobs: run: ./gradlew test - name: Upload test artifacts if: always() - uses: actions/upload-artifact@v3 + uses: actions/upload-artifact@v4 with: name: test-report path: | @@ -50,7 +50,7 @@ jobs: steps: - uses: actions/checkout@v3 - name: Download Test Artifact - uses: actions/download-artifact@v3 + uses: actions/download-artifact@v4 with: name: test-report @@ -70,7 +70,7 @@ jobs: steps: - uses: actions/checkout@v3 - name: Download Test Artifact - uses: actions/download-artifact@v3 + uses: actions/download-artifact@v4 with: name: test-report diff --git a/.github/workflows/deploy_pull_request.yml b/.github/workflows/deploy_pull_request.yml index c5c2c6e7..2907b605 100644 --- a/.github/workflows/deploy_pull_request.yml +++ b/.github/workflows/deploy_pull_request.yml @@ -31,7 +31,7 @@ jobs: run: ./gradlew test - name: Upload test artifacts if: always() - uses: actions/upload-artifact@v3 + uses: actions/upload-artifact@v4 with: name: test-report path: | @@ -46,7 +46,7 @@ jobs: steps: - uses: actions/checkout@v3 - name: Download Test Artifact - uses: actions/download-artifact@v3 + uses: actions/download-artifact@v4 with: name: test-report @@ -66,7 +66,7 @@ jobs: steps: - uses: actions/checkout@v3 - name: Download Test Artifact - uses: actions/download-artifact@v3 + uses: actions/download-artifact@v4 with: name: test-report diff --git a/.github/workflows/deploy_release.yml b/.github/workflows/deploy_release.yml index 1f26fd56..91702d81 100644 --- a/.github/workflows/deploy_release.yml +++ b/.github/workflows/deploy_release.yml @@ -23,7 +23,7 @@ jobs: cmd: "gh_release_diff -l -d --summary -w changes.md" - name: Upload changes artifacts - uses: actions/upload-artifact@v3 + uses: actions/upload-artifact@v4 with: name: changes path: | @@ -49,7 +49,7 @@ jobs: run: ./gradlew publishToMavenLocal - name: Upload changes artifacts - uses: actions/upload-artifact@v3 + uses: actions/upload-artifact@v4 with: name: artifacts path: | From 6f452af38cad97ea87cf639f6da807ccc519931e Mon Sep 17 00:00:00 2001 From: klee0kai Date: Sun, 18 Jan 2026 10:13:37 +0100 Subject: [PATCH 102/122] ci: matrix report --- .github/workflows/deploy_dev.yml | 35 ++++++++--------------- .github/workflows/deploy_pull_request.yml | 33 +++++++-------------- 2 files changed, 23 insertions(+), 45 deletions(-) diff --git a/.github/workflows/deploy_dev.yml b/.github/workflows/deploy_dev.yml index a8ac8243..e48d159e 100644 --- a/.github/workflows/deploy_dev.yml +++ b/.github/workflows/deploy_dev.yml @@ -23,7 +23,7 @@ jobs: name: Run Unit Tests on Java ${{ matrix.java_distribution }} ${{ matrix.java_version }} steps: - uses: actions/checkout@v3 - - name: set up JDK 11 + - name: set up JDK uses: actions/setup-java@v3 with: java-version: ${{ matrix.java_version }} @@ -37,42 +37,31 @@ jobs: if: always() uses: actions/upload-artifact@v4 with: - name: test-report + name: test-report-${{ matrix.java_distribution }}-${{ matrix.java_version }} path: | ./**/build/reports ./**/build/test-results - dorny_report: - name: Prepare Dorny Test Report - needs: tests - runs-on: ubuntu-latest - if: ${{ always() }} - steps: - - uses: actions/checkout@v3 - - name: Download Test Artifact - uses: actions/download-artifact@v4 - with: - name: test-report - - - name: Publish Dorny Test Report - uses: dorny/test-reporter@v1 - with: - name: Dorny JUnit Test Report - path: '**/build/test-results/**/*.xml' - reporter: java-junit - list-tests: 'all' - mikepenz_report: name: Prepare Mikepenz Test Report needs: tests runs-on: ubuntu-latest if: ${{ always() }} + strategy: + matrix: + include: + - java_version: 17 + java_distribution: "temurin" + - java_version: 17 + java_distribution: "oracle" + - java_version: 17 + java_distribution: "corretto" steps: - uses: actions/checkout@v3 - name: Download Test Artifact uses: actions/download-artifact@v4 with: - name: test-report + name: test-report-${{ matrix.java_distribution }}-${{ matrix.java_version }} - name: Publish Test Report uses: mikepenz/action-junit-report@v3 diff --git a/.github/workflows/deploy_pull_request.yml b/.github/workflows/deploy_pull_request.yml index 2907b605..c7dd90ab 100644 --- a/.github/workflows/deploy_pull_request.yml +++ b/.github/workflows/deploy_pull_request.yml @@ -33,42 +33,31 @@ jobs: if: always() uses: actions/upload-artifact@v4 with: - name: test-report + name: test-report-${{ matrix.java_distribution }}-${{ matrix.java_version }} path: | ./**/build/reports ./**/build/test-results - dorny_report: - name: Prepare Dorny Test Report - needs: tests - runs-on: ubuntu-latest - if: ${{ always() }} - steps: - - uses: actions/checkout@v3 - - name: Download Test Artifact - uses: actions/download-artifact@v4 - with: - name: test-report - - - name: Publish Dorny Test Report - uses: dorny/test-reporter@v1 - with: - name: Dorny JUnit Test Report - path: '**/build/test-results/**/*.xml' - reporter: java-junit - list-tests: 'all' - mikepenz_report: name: Prepare Mikepenz Test Report needs: tests runs-on: ubuntu-latest if: ${{ always() }} + strategy: + matrix: + include: + - java_version: 17 + java_distribution: "temurin" + - java_version: 17 + java_distribution: "oracle" + - java_version: 17 + java_distribution: "corretto" steps: - uses: actions/checkout@v3 - name: Download Test Artifact uses: actions/download-artifact@v4 with: - name: test-report + name: test-report-${{ matrix.java_distribution }}-${{ matrix.java_version }} - name: Publish Test Report uses: mikepenz/action-junit-report@v3 From 763b32b8b93a1ad909f6076aac5a674a8445ebd9 Mon Sep 17 00:00:00 2001 From: klee0kai Date: Sun, 18 Jan 2026 10:17:37 +0100 Subject: [PATCH 103/122] update readme --- readme.md | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/readme.md b/readme.md index f1c83d5e..402fea6a 100644 --- a/readme.md +++ b/readme.md @@ -37,8 +37,8 @@ In the project module, import dependencies ```kotlin dependencies { // stone - implementation("com.github.klee0kai.stone:stone_lib:1.0.7") - kapt("com.github.klee0kai.stone:stone_processor:1.0.7") + implementation("com.github.klee0kai.stone:stone_multiplatform:2.0.0") + ksp("com.github.klee0kai.stone:stone_ksp:2.0.0") } ``` @@ -64,7 +64,7 @@ interface PlanetsComponent { And further use. ```kotlin -val DI: PlanetsComponent = Stone.createComponent(PlanetsComponent::class.java) +val DI: PlanetsComponent = PlanetsComponentStoneComponent() fun main(args: Array) { val earth = DI.planets().earth() } @@ -115,14 +115,9 @@ or to implement initialization in coroutine scopes. Documentation with examples - [Kotlin](https://github.com/klee0kai/stone/wiki/kotlin_start) - - [Java](https://github.com/klee0kai/stone/wiki/java_start) - -## Find this library useful? -Support it by joining __[stargazers](https://github.com/klee0kai/stone/stargazers)__ for this repository. :star:
-Also, __[follow me](https://github.com/klee0kai)__ on GitHub for more libraries! ## License ``` -Copyright (c) 2024 Andrey Kuzubov +Copyright (c) 2022 Andrey Kuzubov ``` From 85d3a16d9258a4e5f7bff3688f17b0831ef95f69 Mon Sep 17 00:00:00 2001 From: klee0kai Date: Sun, 18 Jan 2026 12:22:33 +0100 Subject: [PATCH 104/122] publish wasm libs --- inject_multiplatform/build.gradle.kts | 12 +++++- .../klee0kai/stone/publish/MavenPublishExt.kt | 37 ++++++++----------- stone_ksp/build.gradle.kts | 11 +++++- stone_multiplatform/build.gradle.kts | 12 ++++++ .../coroutines/CoroutinesExt.jvm.kt | 0 .../coroutines/CoroutinesExt.linux.kt | 5 --- .../coroutines/CoroutinesExt.native.kt | 3 -- weakref_multiplatform/build.gradle.kts | 12 +++++- .../com/github/klee0kai/stone/weakref/Ref.kt | 2 +- .../github/klee0kai/stone/weakref/SoftRef.kt | 5 ++- .../github/klee0kai/stone/weakref/WeakRef.kt | 4 +- .../klee0kai/stone/weakref/Memory.web.kt | 2 + .../klee0kai/stone/weakref/SoftRef.js.kt} | 7 +++- .../github/klee0kai/stone/weakref/WeakRef.kt | 7 +++- .../github/klee0kai/stone/weakref/SoftRef.kt | 6 ++- .../github/klee0kai/stone/weakref/WeakRef.kt | 6 ++- .../github/klee0kai/stone/weakref/SoftRef.kt | 6 ++- .../github/klee0kai/stone/weakref/WeakRef.kt | 6 ++- .../klee0kai/stone/weakref/Memory.web.kt | 7 ++++ .../klee0kai/stone/weakref/SoftRef.wasmJs.kt | 18 +++++++++ .../klee0kai/stone/weakref/WeakRef.wasmJs.kt | 18 +++++++++ 21 files changed, 143 insertions(+), 43 deletions(-) rename stone_multiplatform/src/jvmMain/{java => kotlin}/com/github/klee0kai/stone/__hidden__/coroutines/CoroutinesExt.jvm.kt (100%) delete mode 100644 stone_multiplatform/src/linuxMain/kotlin/com/github/klee0kai/stone/__hidden__/coroutines/CoroutinesExt.linux.kt rename weakref_multiplatform/src/{webMain => jsMain}/kotlin/com/github/klee0kai/stone/weakref/Memory.web.kt (87%) rename weakref_multiplatform/src/{webMain/kotlin/com/github/klee0kai/stone/weakref/SoftRef.kt => jsMain/kotlin/com/github/klee0kai/stone/weakref/SoftRef.js.kt} (86%) rename weakref_multiplatform/src/{webMain => jsMain}/kotlin/com/github/klee0kai/stone/weakref/WeakRef.kt (86%) create mode 100644 weakref_multiplatform/src/wasmJsMain/kotlin/com/github/klee0kai/stone/weakref/Memory.web.kt create mode 100644 weakref_multiplatform/src/wasmJsMain/kotlin/com/github/klee0kai/stone/weakref/SoftRef.wasmJs.kt create mode 100644 weakref_multiplatform/src/wasmJsMain/kotlin/com/github/klee0kai/stone/weakref/WeakRef.wasmJs.kt diff --git a/inject_multiplatform/build.gradle.kts b/inject_multiplatform/build.gradle.kts index d4224d03..007827c7 100644 --- a/inject_multiplatform/build.gradle.kts +++ b/inject_multiplatform/build.gradle.kts @@ -4,10 +4,9 @@ plugins { alias(libs.plugins.publish.maven) } -group = "com.github.klee0kai.stone.inject" +group = "com.github.klee0kai.stone" version = libs.versions.stone.get() - kotlin { jvm() js(IR) { @@ -17,6 +16,7 @@ kotlin { linuxX64() mingwX64() + wasmJs() sourceSets { commonMain.dependencies { @@ -64,4 +64,12 @@ if (isMac) kotlin { } } +publishing { + publications.withType().configureEach { + pom { + name.set("Stone") + description.set("Library DI designed on weak references.") + } + } +} diff --git a/plugin_publish/src/main/kotlin/com/github/klee0kai/stone/publish/MavenPublishExt.kt b/plugin_publish/src/main/kotlin/com/github/klee0kai/stone/publish/MavenPublishExt.kt index 6d8af935..6834955b 100644 --- a/plugin_publish/src/main/kotlin/com/github/klee0kai/stone/publish/MavenPublishExt.kt +++ b/plugin_publish/src/main/kotlin/com/github/klee0kai/stone/publish/MavenPublishExt.kt @@ -3,33 +3,26 @@ package com.github.klee0kai.stone.publish import org.gradle.api.Project import org.gradle.api.publish.PublishingExtension import org.gradle.api.publish.maven.MavenPublication -import org.gradle.kotlin.dsl.create -import org.gradle.kotlin.dsl.get +import org.gradle.kotlin.dsl.withType fun PublishingExtension.stoneToMaven(project: Project) { - publications { - create("maven") { - groupId = project.group.toString() - artifactId = project.name - version = project.version.toString() + publications.withType().configureEach { + version = project.version.toString() - pom { - name.set("Stone") - description.set("Library DI designed on weak references.") - url.set("https://github.com/klee0kai/stone") - licenses { - license { - name.set("GNU General Public License, Version 3") - url.set("https://github.com/klee0kai/stone/blob/dev/LICENCE.md") - } + pom { + url.set("https://github.com/klee0kai/stone") + licenses { + license { + name.set("GNU General Public License, Version 3") + url.set("https://github.com/klee0kai/stone/blob/dev/LICENCE.md") } - developers { - developer { - id.set("klee0kai") - name.set("Andrei Kuzubov") - email.set("klee0kai@gmail.com") - } + } + developers { + developer { + id.set("klee0kai") + name.set("Andrei Kuzubov") + email.set("klee0kai@gmail.com") } } } diff --git a/stone_ksp/build.gradle.kts b/stone_ksp/build.gradle.kts index ed8227eb..6bffb8d7 100644 --- a/stone_ksp/build.gradle.kts +++ b/stone_ksp/build.gradle.kts @@ -4,7 +4,7 @@ plugins { alias(libs.plugins.publish.maven) } -group = "com.github.klee0kai.stone.ksp" +group = "com.github.klee0kai.stone" version = libs.versions.stone.get() @@ -23,3 +23,12 @@ kotlin { } } +publishing { + publications.withType().configureEach { + pom { + name.set("Stone") + description.set("Library DI designed on weak references.") + } + } +} + diff --git a/stone_multiplatform/build.gradle.kts b/stone_multiplatform/build.gradle.kts index 63089057..9957fdb3 100644 --- a/stone_multiplatform/build.gradle.kts +++ b/stone_multiplatform/build.gradle.kts @@ -1,5 +1,7 @@ plugins { alias(libs.plugins.kotlin.multiplatform) + alias(libs.plugins.publish.stone) + alias(libs.plugins.publish.maven) } group = "com.github.klee0kai.stone" @@ -15,6 +17,7 @@ kotlin { linuxX64() mingwX64() + wasmJs() sourceSets { commonMain.dependencies { @@ -64,3 +67,12 @@ if (isMac) kotlin { } } + +publishing { + publications.withType().configureEach { + pom { + name.set("Stone") + description.set("Library DI designed on weak references.") + } + } +} diff --git a/stone_multiplatform/src/jvmMain/java/com/github/klee0kai/stone/__hidden__/coroutines/CoroutinesExt.jvm.kt b/stone_multiplatform/src/jvmMain/kotlin/com/github/klee0kai/stone/__hidden__/coroutines/CoroutinesExt.jvm.kt similarity index 100% rename from stone_multiplatform/src/jvmMain/java/com/github/klee0kai/stone/__hidden__/coroutines/CoroutinesExt.jvm.kt rename to stone_multiplatform/src/jvmMain/kotlin/com/github/klee0kai/stone/__hidden__/coroutines/CoroutinesExt.jvm.kt diff --git a/stone_multiplatform/src/linuxMain/kotlin/com/github/klee0kai/stone/__hidden__/coroutines/CoroutinesExt.linux.kt b/stone_multiplatform/src/linuxMain/kotlin/com/github/klee0kai/stone/__hidden__/coroutines/CoroutinesExt.linux.kt deleted file mode 100644 index d68e16a4..00000000 --- a/stone_multiplatform/src/linuxMain/kotlin/com/github/klee0kai/stone/__hidden__/coroutines/CoroutinesExt.linux.kt +++ /dev/null @@ -1,5 +0,0 @@ -package com.github.klee0kai.stone.__hidden__.coroutines - -actual fun T.syncIfAvailable(mutex: kotlinx.coroutines.sync.Mutex, block: T.() -> R): R { - TODO("Not yet implemented") -} \ No newline at end of file diff --git a/stone_multiplatform/src/nativeMain/kotlin/com/github/klee0kai/stone/__hidden__/coroutines/CoroutinesExt.native.kt b/stone_multiplatform/src/nativeMain/kotlin/com/github/klee0kai/stone/__hidden__/coroutines/CoroutinesExt.native.kt index 4683ce56..653283db 100644 --- a/stone_multiplatform/src/nativeMain/kotlin/com/github/klee0kai/stone/__hidden__/coroutines/CoroutinesExt.native.kt +++ b/stone_multiplatform/src/nativeMain/kotlin/com/github/klee0kai/stone/__hidden__/coroutines/CoroutinesExt.native.kt @@ -7,6 +7,3 @@ actual fun T.syncIfAvailable( block: T.() -> R ): R = block() -actual fun T.syncIfAvailable(mutex: kotlinx.coroutines.sync.Mutex, block: T.() -> R): R { - TODO("Not yet implemented") -} \ No newline at end of file diff --git a/weakref_multiplatform/build.gradle.kts b/weakref_multiplatform/build.gradle.kts index a933fa7d..48d5574a 100644 --- a/weakref_multiplatform/build.gradle.kts +++ b/weakref_multiplatform/build.gradle.kts @@ -4,7 +4,7 @@ plugins { alias(libs.plugins.publish.maven) } -group = "com.github.klee0kai.stone.weakref" +group = "com.github.klee0kai.stone" version = libs.versions.stone.get() kotlin { @@ -16,6 +16,7 @@ kotlin { linuxX64() mingwX64() + wasmJs() sourceSets { commonMain.dependencies { @@ -72,3 +73,12 @@ if (isMac) kotlin { } +publishing { + publications.withType().configureEach { + pom { + name.set("WeakRef") + description.set("Multi platform weak ref implementation.") + } + } +} + diff --git a/weakref_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/weakref/Ref.kt b/weakref_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/weakref/Ref.kt index b11f1e9d..7de041ca 100644 --- a/weakref_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/weakref/Ref.kt +++ b/weakref_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/weakref/Ref.kt @@ -1,6 +1,6 @@ package com.github.klee0kai.stone.weakref -fun interface Ref { +fun interface Ref { fun get(): T diff --git a/weakref_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/weakref/SoftRef.kt b/weakref_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/weakref/SoftRef.kt index 0dd7d877..0851cea6 100644 --- a/weakref_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/weakref/SoftRef.kt +++ b/weakref_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/weakref/SoftRef.kt @@ -1,9 +1,12 @@ package com.github.klee0kai.stone.weakref -expect class SoftRef constructor(value: T) : Ref { +expect class SoftRef constructor(value: T) : Ref, AutoCloseable { override fun get(): T? fun clear() + override fun close() + + } \ No newline at end of file diff --git a/weakref_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/weakref/WeakRef.kt b/weakref_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/weakref/WeakRef.kt index 76ebc039..1ad20843 100644 --- a/weakref_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/weakref/WeakRef.kt +++ b/weakref_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/weakref/WeakRef.kt @@ -1,9 +1,11 @@ package com.github.klee0kai.stone.weakref -expect class WeakRef constructor(value: T) : Ref { +expect class WeakRef constructor(value: T) : Ref, AutoCloseable { override fun get(): T? fun clear() + override fun close() + } \ No newline at end of file diff --git a/weakref_multiplatform/src/webMain/kotlin/com/github/klee0kai/stone/weakref/Memory.web.kt b/weakref_multiplatform/src/jsMain/kotlin/com/github/klee0kai/stone/weakref/Memory.web.kt similarity index 87% rename from weakref_multiplatform/src/webMain/kotlin/com/github/klee0kai/stone/weakref/Memory.web.kt rename to weakref_multiplatform/src/jsMain/kotlin/com/github/klee0kai/stone/weakref/Memory.web.kt index 81d3f0d9..966e1622 100644 --- a/weakref_multiplatform/src/webMain/kotlin/com/github/klee0kai/stone/weakref/Memory.web.kt +++ b/weakref_multiplatform/src/jsMain/kotlin/com/github/klee0kai/stone/weakref/Memory.web.kt @@ -1,5 +1,7 @@ package com.github.klee0kai.stone.weakref +import kotlin.js.js + actual object Memory { actual fun gc() { diff --git a/weakref_multiplatform/src/webMain/kotlin/com/github/klee0kai/stone/weakref/SoftRef.kt b/weakref_multiplatform/src/jsMain/kotlin/com/github/klee0kai/stone/weakref/SoftRef.js.kt similarity index 86% rename from weakref_multiplatform/src/webMain/kotlin/com/github/klee0kai/stone/weakref/SoftRef.kt rename to weakref_multiplatform/src/jsMain/kotlin/com/github/klee0kai/stone/weakref/SoftRef.js.kt index 489fa9b9..02e7aac1 100644 --- a/weakref_multiplatform/src/webMain/kotlin/com/github/klee0kai/stone/weakref/SoftRef.kt +++ b/weakref_multiplatform/src/jsMain/kotlin/com/github/klee0kai/stone/weakref/SoftRef.js.kt @@ -1,6 +1,6 @@ package com.github.klee0kai.stone.weakref -actual class SoftRef actual constructor(value: T) : Ref { +actual class SoftRef actual constructor(value: T) : Ref, AutoCloseable { private var weakRefDynamic: dynamic = null private var strongFallback: T? = null @@ -31,4 +31,9 @@ actual class SoftRef actual constructor(value: T) : Ref { strongFallback = null } + actual override fun close() { + weakRefDynamic = null + strongFallback = null + } + } \ No newline at end of file diff --git a/weakref_multiplatform/src/webMain/kotlin/com/github/klee0kai/stone/weakref/WeakRef.kt b/weakref_multiplatform/src/jsMain/kotlin/com/github/klee0kai/stone/weakref/WeakRef.kt similarity index 86% rename from weakref_multiplatform/src/webMain/kotlin/com/github/klee0kai/stone/weakref/WeakRef.kt rename to weakref_multiplatform/src/jsMain/kotlin/com/github/klee0kai/stone/weakref/WeakRef.kt index 8a541b58..7be98009 100644 --- a/weakref_multiplatform/src/webMain/kotlin/com/github/klee0kai/stone/weakref/WeakRef.kt +++ b/weakref_multiplatform/src/jsMain/kotlin/com/github/klee0kai/stone/weakref/WeakRef.kt @@ -1,6 +1,6 @@ package com.github.klee0kai.stone.weakref -actual class WeakRef actual constructor(value: T) : Ref { +actual class WeakRef actual constructor(value: T) : Ref, AutoCloseable { private var weakRefDynamic: dynamic = null private var strongFallback: T? = null @@ -31,4 +31,9 @@ actual class WeakRef actual constructor(value: T) : Ref { strongFallback = null } + actual override fun close() { + weakRefDynamic = null + strongFallback = null + } + } \ No newline at end of file diff --git a/weakref_multiplatform/src/jvmMain/kotlin/com/github/klee0kai/stone/weakref/SoftRef.kt b/weakref_multiplatform/src/jvmMain/kotlin/com/github/klee0kai/stone/weakref/SoftRef.kt index 94f654de..87cf984c 100644 --- a/weakref_multiplatform/src/jvmMain/kotlin/com/github/klee0kai/stone/weakref/SoftRef.kt +++ b/weakref_multiplatform/src/jvmMain/kotlin/com/github/klee0kai/stone/weakref/SoftRef.kt @@ -2,7 +2,7 @@ package com.github.klee0kai.stone.weakref import java.lang.ref.SoftReference -actual class SoftRef actual constructor(value: T) : Ref { +actual class SoftRef actual constructor(value: T) : Ref, AutoCloseable { val weakRef: SoftReference = SoftReference(value) @@ -12,4 +12,8 @@ actual class SoftRef actual constructor(value: T) : Ref { weakRef.clear() } + actual override fun close() { + weakRef.clear() + } + } \ No newline at end of file diff --git a/weakref_multiplatform/src/jvmMain/kotlin/com/github/klee0kai/stone/weakref/WeakRef.kt b/weakref_multiplatform/src/jvmMain/kotlin/com/github/klee0kai/stone/weakref/WeakRef.kt index d4cc44ec..a75e89d5 100644 --- a/weakref_multiplatform/src/jvmMain/kotlin/com/github/klee0kai/stone/weakref/WeakRef.kt +++ b/weakref_multiplatform/src/jvmMain/kotlin/com/github/klee0kai/stone/weakref/WeakRef.kt @@ -2,7 +2,7 @@ package com.github.klee0kai.stone.weakref import java.lang.ref.WeakReference -actual class WeakRef actual constructor(value: T) : Ref { +actual class WeakRef actual constructor(value: T) : Ref, AutoCloseable { val weakRef: WeakReference = WeakReference(value) @@ -12,4 +12,8 @@ actual class WeakRef actual constructor(value: T) : Ref { weakRef.clear() } + actual override fun close() { + weakRef.clear() + } + } \ No newline at end of file diff --git a/weakref_multiplatform/src/nativeMain/kotlin/com/github/klee0kai/stone/weakref/SoftRef.kt b/weakref_multiplatform/src/nativeMain/kotlin/com/github/klee0kai/stone/weakref/SoftRef.kt index 0289aa8a..7fdd623c 100644 --- a/weakref_multiplatform/src/nativeMain/kotlin/com/github/klee0kai/stone/weakref/SoftRef.kt +++ b/weakref_multiplatform/src/nativeMain/kotlin/com/github/klee0kai/stone/weakref/SoftRef.kt @@ -5,7 +5,7 @@ package com.github.klee0kai.stone.weakref import kotlin.experimental.ExperimentalNativeApi import kotlin.native.ref.WeakReference -actual class SoftRef actual constructor(value: T) : Ref { +actual class SoftRef actual constructor(value: T) : Ref, AutoCloseable { val weakRef: WeakReference? = value?.let { WeakReference(value) } @@ -15,4 +15,8 @@ actual class SoftRef actual constructor(value: T) : Ref { weakRef?.clear() } + actual override fun close() { + weakRef?.clear() + } + } \ No newline at end of file diff --git a/weakref_multiplatform/src/nativeMain/kotlin/com/github/klee0kai/stone/weakref/WeakRef.kt b/weakref_multiplatform/src/nativeMain/kotlin/com/github/klee0kai/stone/weakref/WeakRef.kt index 2ea53dde..3ec60902 100644 --- a/weakref_multiplatform/src/nativeMain/kotlin/com/github/klee0kai/stone/weakref/WeakRef.kt +++ b/weakref_multiplatform/src/nativeMain/kotlin/com/github/klee0kai/stone/weakref/WeakRef.kt @@ -5,7 +5,7 @@ package com.github.klee0kai.stone.weakref import kotlin.experimental.ExperimentalNativeApi import kotlin.native.ref.WeakReference -actual class WeakRef actual constructor(value: T) : Ref { +actual class WeakRef actual constructor(value: T) : Ref, AutoCloseable { val weakRef: WeakReference? = value?.let { WeakReference(value) } @@ -15,4 +15,8 @@ actual class WeakRef actual constructor(value: T) : Ref { weakRef?.clear() } + actual override fun close() { + weakRef?.clear() + } + } \ No newline at end of file diff --git a/weakref_multiplatform/src/wasmJsMain/kotlin/com/github/klee0kai/stone/weakref/Memory.web.kt b/weakref_multiplatform/src/wasmJsMain/kotlin/com/github/klee0kai/stone/weakref/Memory.web.kt new file mode 100644 index 00000000..08c38f12 --- /dev/null +++ b/weakref_multiplatform/src/wasmJsMain/kotlin/com/github/klee0kai/stone/weakref/Memory.web.kt @@ -0,0 +1,7 @@ +package com.github.klee0kai.stone.weakref + +actual object Memory { + + actual fun gc() = Unit + +} \ No newline at end of file diff --git a/weakref_multiplatform/src/wasmJsMain/kotlin/com/github/klee0kai/stone/weakref/SoftRef.wasmJs.kt b/weakref_multiplatform/src/wasmJsMain/kotlin/com/github/klee0kai/stone/weakref/SoftRef.wasmJs.kt new file mode 100644 index 00000000..192ac47a --- /dev/null +++ b/weakref_multiplatform/src/wasmJsMain/kotlin/com/github/klee0kai/stone/weakref/SoftRef.wasmJs.kt @@ -0,0 +1,18 @@ +package com.github.klee0kai.stone.weakref + + +actual class SoftRef actual constructor(value: T) : Ref, AutoCloseable { + + private var ref: T? = value + + actual override fun get(): T? = ref + + actual fun clear() { + ref = null + } + + actual override fun close() { + ref = null + } + +} \ No newline at end of file diff --git a/weakref_multiplatform/src/wasmJsMain/kotlin/com/github/klee0kai/stone/weakref/WeakRef.wasmJs.kt b/weakref_multiplatform/src/wasmJsMain/kotlin/com/github/klee0kai/stone/weakref/WeakRef.wasmJs.kt new file mode 100644 index 00000000..41c8b2f3 --- /dev/null +++ b/weakref_multiplatform/src/wasmJsMain/kotlin/com/github/klee0kai/stone/weakref/WeakRef.wasmJs.kt @@ -0,0 +1,18 @@ +package com.github.klee0kai.stone.weakref + + +actual class WeakRef actual constructor(value: T) : Ref, AutoCloseable { + + private var ref: T? = value + + actual override fun get(): T? = ref + + actual fun clear() { + ref = null + } + + actual override fun close() { + ref = null + } + +} \ No newline at end of file From c789986d8d885f625e432208ed18c6ff50204b92 Mon Sep 17 00:00:00 2001 From: klee0kai Date: Sun, 18 Jan 2026 15:13:27 +0100 Subject: [PATCH 105/122] rm useless code --- .../ksp/exceptions/ExceptionStringBuilder.kt | 499 ------------------ .../stone/ksp/helpers/TypeHelpersExt.kt | 14 - .../invokecall/GenArgumentFunctions.kt | 46 -- .../stone/ksp/helpers/wrap/ClassNameUtils.kt | 35 -- 4 files changed, 594 deletions(-) delete mode 100644 stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/exceptions/ExceptionStringBuilder.kt delete mode 100644 stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/invokecall/GenArgumentFunctions.kt diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/exceptions/ExceptionStringBuilder.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/exceptions/ExceptionStringBuilder.kt deleted file mode 100644 index 6fdf7db7..00000000 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/exceptions/ExceptionStringBuilder.kt +++ /dev/null @@ -1,499 +0,0 @@ -package com.github.klee0kai.thekey.stone.ksp.exceptions - -import com.squareup.kotlinpoet.TypeName -import java.lang.String -import java.util.* -import kotlin.Deprecated -import kotlin.Throwable -import kotlin.text.format - -/** - * Build error message by masks - * Pro-StringBuilder implementation for exceptions - */ -@Deprecated(message = "use kotlin string builder instead") -class ExceptionStringBuilder { - private val sb = StringBuilder() - - fun cannotCreateComponent(componentName: String?): ExceptionStringBuilder { - if (sb.length > 0) sb.append(" ") - sb.append("Cannot create component: ") - sb.append(componentName) - return this - } - - fun cannotCreateWrappersHelper(): ExceptionStringBuilder { - if (sb.length > 0) sb.append(" ") - sb.append("Cannot create wrappers helper ") - return this - } - - fun cannotCreateModule(moduleName: String?): ExceptionStringBuilder { - if (sb.length > 0) sb.append(" ") - sb.append("Cannot create component: ") - sb.append(moduleName) - return this - } - - fun componentsClass(className: String?): ExceptionStringBuilder { - if (sb.length > 0) sb.append(" ") - sb.append( - String.format( - Locale.ROOT, - "Component's class %s", - className - ) - ) - return this - } - - - fun moduleClass(className: String?): ExceptionStringBuilder { - if (sb.length > 0) sb.append(" ") - sb.append( - String.format( - Locale.ROOT, - "Module's class %s", - className - ) - ) - return this - } - - fun dependencyClass(className: String?): ExceptionStringBuilder { - if (sb.length > 0) sb.append(" ") - sb.append( - String.format( - Locale.ROOT, - "Dependency's class %s", - className - ) - ) - return this - } - - - fun wrappersCreatorClass(className: String?): ExceptionStringBuilder { - if (sb.length > 0) sb.append(" ") - sb.append( - String.format( - Locale.ROOT, - "WrappersCreator's class %s", - className - ) - ) - return this - } - - fun wrapperShouldBeGenericType1(className: TypeName): ExceptionStringBuilder { - if (sb.length > 0) sb.append(" ") - sb.append( - String.format( - Locale.ROOT, - "WrapperClass %s should be genericType with one type argument. Like SmthWrapper.class ", - className.toString() - ) - ) - return this - } - - fun method(methodName: kotlin.String?): ExceptionStringBuilder { - if (sb.length > 0) sb.append(" ") - sb.append( - kotlin.String.format( - Locale.ROOT, - "method '%s'", - methodName - ) - ) - return this - } - - - fun classNonFound(className: kotlin.String?): ExceptionStringBuilder { - if (sb.length > 0) sb.append(" ") - sb.append("Class not found: ") - sb.append(className) - sb.append(". Try import class directly.") - return this - } - - fun primitiveTypesNonSupported(typeName: kotlin.String?): ExceptionStringBuilder { - if (sb.length > 0) sb.append(" ") - sb.append("Primitive type non supported: ") - sb.append(typeName) - return this - } - - fun methodPurposeNonDetected(methodName: kotlin.String?, className: kotlin.String?): ExceptionStringBuilder { - if (sb.length > 0) sb.append(" ") - sb.append( - kotlin.String.format( - Locale.ROOT, - "What is purpose for Method '%s'. Declared in %s", - methodName, className - ) - ) - return this - } - - fun errorProvideModuleFactoryRequiredIn( - providingTypeName: kotlin.String?, - className: kotlin.String?, - method: kotlin.String? - ): ExceptionStringBuilder { - if (sb.length > 0) sb.append(" ") - sb.append( - kotlin.String.format( - Locale.ROOT, - "Error provide module %s. Required in %s.%s", - providingTypeName, className, method - ) - ) - return this - } - - fun errorProvideTypeRequiredIn( - providingTypeName: kotlin.String?, - className: kotlin.String?, - method: kotlin.String? - ): ExceptionStringBuilder { - if (sb.length > 0) sb.append(" ") - sb.append( - kotlin.String.format( - Locale.ROOT, - "Error provide type %s. Required in %s.%s", - providingTypeName, className, method - ) - ) - return this - } - - fun errorProvideType(providingTypeName: kotlin.String?): ExceptionStringBuilder { - if (sb.length > 0) sb.append(" ") - sb.append( - kotlin.String.format( - Locale.ROOT, - "Error provide type %s", - providingTypeName - ) - ) - return this - } - - fun shouldNoProvideIdentifierType(providingTypeName: kotlin.String?): ExceptionStringBuilder { - if (sb.length > 0) sb.append(" ") - sb.append( - kotlin.String.format( - Locale.ROOT, - "Should no provide identifier %s", - providingTypeName - ) - ) - return this - } - - fun errorImplementMethod(method: kotlin.String?): ExceptionStringBuilder { - if (sb.length > 0) sb.append(" ") - sb.append( - kotlin.String.format( - Locale.ROOT, - "Error to implement method: '%s'", - method - ) - ) - return this - } - - fun hasIncorrectSignature(): ExceptionStringBuilder { - if (sb.length > 0) sb.append(" ") - sb.append("has incorrect signature") - return this - } - - fun shouldNoHaveAnnotation(annotation: kotlin.String?): ExceptionStringBuilder { - if (sb.length > 0) sb.append(" ") - sb.append( - kotlin.String.format( - Locale.ROOT, - "should not have @%s annotation", - annotation - ) - ) - return this - } - - fun shouldHaveOnlyAnnotations(vararg annotations: kotlin.String?): ExceptionStringBuilder { - if (sb.length > 0) sb.append(" ") - val annList = String.join(", @", *annotations) - sb.append( - kotlin.String.format( - Locale.ROOT, - "should have only @%s annotation", - annList - ) - ) - return this - } - - fun shouldHaveAnnotations(vararg annotations: kotlin.String?): ExceptionStringBuilder { - if (sb.length > 0) sb.append(" ") - val annList = String.join(", @", *annotations) - sb.append( - kotlin.String.format( - Locale.ROOT, - "should have @%s annotation", - annList - ) - ) - return this - } - - - fun shouldNoHaveIdentifiers(identifier: kotlin.String?): ExceptionStringBuilder { - if (sb.length > 0) sb.append(" ") - sb.append( - kotlin.String.format( - Locale.ROOT, - "should not have %s identifiers", - identifier - ) - ) - return this - } - - fun shouldHaveOnlySingleModuleMethod(moduleType: kotlin.String?): ExceptionStringBuilder { - if (sb.length > 0) sb.append(" ") - sb.append( - kotlin.String.format( - Locale.ROOT, - "should have only one module or dependency method. %s has duplicate", - moduleType - ) - ) - return this - } - - fun shouldNoHaveFields(): ExceptionStringBuilder { - if (sb.length > 0) sb.append(" ") - sb.append("should not have fields") - return this - } - - - fun shouldImplementInterface(interfaceType: kotlin.String?): ExceptionStringBuilder { - if (sb.length > 0) sb.append(" ") - sb.append("should implement ") - sb.append(interfaceType) - return this - } - - fun shouldHaveConstructorWithoutArgs(): ExceptionStringBuilder { - if (sb.length > 0) sb.append(" ") - sb.append("should have public constructor without arguments") - return this - } - - fun shouldHaveInjectableClassAsParameter(): ExceptionStringBuilder { - if (sb.length > 0) sb.append(" ") - sb.append("should have an injection class as a parameter") - return this - } - - fun shouldProvideNonPrimitiveObjects(): ExceptionStringBuilder { - if (sb.length > 0) sb.append(" ") - sb.append("should provide non primitive objects") - return this - } - - - fun shouldNoHavePrimitiveArguments(): ExceptionStringBuilder { - if (sb.length > 0) sb.append(" ") - sb.append("should no have primitive arguments") - return this - } - - - fun recursiveProviding(): ExceptionStringBuilder { - if (sb.length > 0) sb.append(" ") - sb.append("Recursive providing detected") - return this - } - - fun constructorNonFound(className: kotlin.String?, argTypes: MutableList): ExceptionStringBuilder { - if (sb.length > 0) sb.append(" ") - sb.append( - kotlin.String.format( - Locale.ROOT, - "No found public constructor for class: %s with args: %s", - className, String.join(", ", argTypes) - ) - ) - return this - } - - - fun typeTransformNonSupport(or: TypeName, dest: TypeName): ExceptionStringBuilder { - if (sb.length > 0) sb.append(" ") - sb.append( - String.format( - Locale.ROOT, - "Type Transform non support %s -> %s", - or.toString(), dest.toString() - ) - ) - return this - } - - - fun componentInitMethodSignatureIncorrect( - className: kotlin.String?, - annotation: kotlin.String? - ): ExceptionStringBuilder { - if (sb.length > 0) sb.append(" ") - sb.append( - kotlin.String.format( - Locale.ROOT, - ("Component's init method have incorrect signature: '%s'. " - + "Method Should have only one %s annotation. " - + "Should have arguments of module or dependencies. " - + "Should be void."), - className, annotation - ) - ) - return this - } - - - fun componentExtOfMethodSignatureIncorrect( - className: kotlin.String?, - annotation: kotlin.String? - ): ExceptionStringBuilder { - if (sb.length > 0) sb.append(" ") - sb.append( - kotlin.String.format( - Locale.ROOT, - ("Component's bindInstance method have incorrect signature: '%s'. " - + "Method Should have only %s annotation and GC scope annotations. " - + "Should have only one argument of providing object. " - + "Providing object should not be primitive or boxed primitive. " - + "Can return only providing object or should be void. "), - className, annotation - ) - ) - return this - } - - fun componentBindInstanceMethodSignatureIncorrect( - className: kotlin.String?, - annotation: kotlin.String? - ): ExceptionStringBuilder { - if (sb.length > 0) sb.append(" ") - sb.append( - kotlin.String.format( - Locale.ROOT, - ("Component's bindInstance method have incorrect signature: '%s'. " - + "Method Should have only %s annotation and GC scope annotations. " - + "Should have only one argument of providing object. " - + "Providing object should not be primitive or boxed primitive. " - + "Can return only providing object or should be void. "), - className, annotation - ) - ) - return this - } - - fun componentGCMethodSignatureIncorrect( - className: kotlin.String?, - annotation: kotlin.String? - ): ExceptionStringBuilder { - if (sb.length > 0) sb.append(" ") - sb.append( - kotlin.String.format( - Locale.ROOT, - ("Component's gc method have incorrect signature: '%s'. " - + "Method Should have only %s annotation and GC scope annotations. " - + "Should no have arguments. " - + "Should be void."), - className, annotation - ) - ) - return this - } - - fun componentSwitchCacheMethodSignatureIncorrect( - className: kotlin.String?, - annotation: kotlin.String? - ): ExceptionStringBuilder { - if (sb.length > 0) sb.append(" ") - sb.append( - kotlin.String.format( - Locale.ROOT, - ("Component's SwitchCache method have incorrect signature: '%s'. " - + "Method Should have only %s annotation and GC scope annotations. " - + "Should no have arguments. " - + "Should be void."), - className, annotation - ) - ) - return this - } - - fun componentProtectInjectedMethodSignatureIncorrect( - className: kotlin.String?, - annotation: kotlin.String? - ): ExceptionStringBuilder { - if (sb.length > 0) sb.append(" ") - sb.append( - kotlin.String.format( - Locale.ROOT, - ("Component's ProtectInjected method have incorrect signature: '%s'. " - + "Method Should have only %s annotation. " - + "Should have only one argument (non primitive and non boxed primitive). " - + "Should be void."), - className, annotation - ) - ) - return this - } - - - fun componentMethodNameBusy(methodName: kotlin.String?): ExceptionStringBuilder { - if (sb.length > 0) sb.append(" ") - sb.append( - kotlin.String.format( - Locale.ROOT, - "Component's method name '%s' busy by lib's private interfaces", - methodName - ) - ) - return this - } - - fun add(mes: kotlin.String?): ExceptionStringBuilder { - if (sb.length > 0) sb.append(" ") - sb.append(mes) - return this - } - - - fun collectCauseMessages(cause: Throwable?): ExceptionStringBuilder { - var cause = cause - while (cause != null) { - if (sb.length > 0) sb.append("\nCaused by: ") - sb.append(cause.message) - cause = cause.cause - } - return this - } - - fun build(): kotlin.String { - return sb.toString() - } - - companion object { - fun createErrorMes(): ExceptionStringBuilder { - return ExceptionStringBuilder() - } - } -} diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/TypeHelpersExt.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/TypeHelpersExt.kt index 1b9ca4f2..eeaf8493 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/TypeHelpersExt.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/TypeHelpersExt.kt @@ -22,17 +22,3 @@ fun KSType.isListType( ?.superTypes ?.any { it.resolve().isListType() } == true } - -@Deprecated("ue wrap helper ") -fun KSType.noWrappedType( - wrappedTypes: List, -): KSType { - if (arguments.isEmpty()) return this - if (this in wrappedTypes) { - return arguments - .first().type?.resolve() - ?.noWrappedType(wrappedTypes) - ?: this - } - return this -} diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/invokecall/GenArgumentFunctions.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/invokecall/GenArgumentFunctions.kt deleted file mode 100644 index 216a59e4..00000000 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/invokecall/GenArgumentFunctions.kt +++ /dev/null @@ -1,46 +0,0 @@ -package com.github.klee0kai.thekey.stone.ksp.helpers.invokecall - -import com.google.devtools.ksp.symbol.KSValueParameter -import com.squareup.kotlinpoet.CodeBlock -import com.squareup.kotlinpoet.TypeName - -object GenArgumentFunctions { - /** - * Simple unwrap argument from wrapped type (WeakReference and other). - * If you have arguments like

- * `Provide someVariable;`

- * unwrapArgument support to unwrap SomeClass type on invoke method, like

- * `doSmth(someVariable.provide()) ` - * - * @param envFields available fields - * @return unwrapped field get code, or null - */ - fun unwrapArgument( - envFields: List, - ): (TypeName) -> CodeBlock { - envFields.map { - it.type.resolve().arguments - - - } - TODO() -// val provideFields: MutableList> = ListUtils.format(envFields, { it -> -// if (it.type is ParameterizedTypeName) { -// val type: ParameterizedTypeName = it.type as ParameterizedTypeName -// val orType: TypeName? = type.typeArguments.get(type.typeArguments.size() - 1) -// if (type.rawType == ClassName.get(PhantomProvide::class.java)) return@format Pair( -// orType, -// it.name + ".get()" -// ) -// } -// Pair(it.type, it.name) -// }) -// -// return Function { wannaType: TypeName? -> -// for (provideField in provideFields) { -// if (wannaType == provideField.first) return@Function CodeBlock.of(provideField.second) -// } -// null -// } - } -} diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/wrap/ClassNameUtils.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/wrap/ClassNameUtils.kt index c94e9ecc..52b8413a 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/wrap/ClassNameUtils.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/wrap/ClassNameUtils.kt @@ -1,46 +1,11 @@ package com.github.klee0kai.thekey.stone.ksp.helpers.wrap -import com.github.klee0kai.thekey.stone.ksp.exceptions.ClassNotFoundStoneException -import com.github.klee0kai.thekey.stone.ksp.exceptions.ExceptionStringBuilder -import com.github.klee0kai.thekey.stone.ksp.exceptions.PrimitiveTypeNonSupportedStoneException -import com.squareup.kotlinpoet.ClassName import com.squareup.kotlinpoet.ParameterizedTypeName import com.squareup.kotlinpoet.TypeName import com.squareup.kotlinpoet.WildcardTypeName object ClassNameUtils { - /** - * Get class name from full name. - * Primitives and boxed types are not support - * - * @param clFullName class full name like "com.github.klee0kai.stone.annotations.component.class" - * @return class name - * @throws PrimitiveTypeNonSupportedStoneException primitive types are not support - */ - fun classNameOf(clFullName: String): ClassName { - var clFullName = clFullName - try { - if (clFullName.endsWith(".class")) clFullName = clFullName.take(clFullName.lastIndexOf(".class")) - return ClassName.bestGuess(clFullName) - } catch (e: Exception) { - if (!clFullName.contains(".")) { - throw PrimitiveTypeNonSupportedStoneException( - ExceptionStringBuilder.createErrorMes() - .primitiveTypesNonSupported(clFullName) - .build(), - e - ) - } - throw ClassNotFoundStoneException( - ExceptionStringBuilder.createErrorMes() - .classNonFound(clFullName) - .build(), - e - ) - } - } - fun rawTypeOf(typeName: TypeName): TypeName { if (typeName is ParameterizedTypeName) { return rawTypeOf((typeName).rawType) From 2311cf7239ebb7338c6ff9d4df70ab30c7b31322 Mon Sep 17 00:00:00 2001 From: klee0kai Date: Sun, 18 Jan 2026 15:42:46 +0100 Subject: [PATCH 106/122] kdoc --- .../github/klee0kai/stone/weakref/Inject.kt | 8 +++++ .../github/klee0kai/stone/weakref/Named.kt | 18 ++++++++++++ .../github/klee0kai/stone/weakref/Provider.kt | 5 ++++ .../klee0kai/stone/weakref/Qualifier.kt | 29 +++++++++++++++++++ .../github/klee0kai/stone/weakref/Scope.kt | 11 +++++++ .../klee0kai/stone/weakref/Singleton.kt | 5 ++++ .../github/klee0kai/stone/weakref/Inject.kt | 1 + .../helpers/invokecall/model/FieldDetail.kt | 8 ----- .../MultiKeyMapItemHolderCodeHelper.kt | 1 - .../stone/ksp/helpers/wrap/ClassNameUtils.kt | 1 - .../klee0kai/thekey/stone/ksp/poet/PoetExt.kt | 2 +- .../poet/member/CoroutinesMemberFunctions.kt | 9 ------ .../thekey/stone/ksp/target/CommonPoetExt.kt | 7 +---- .../target/component/ComponentsMethodsExt.kt | 3 -- .../hiddenmodule/GenHiddenModuleProcessor.kt | 2 -- .../ksp/target/module/GenModuleProcessor.kt | 5 ---- .../stone/annotations/component/GcAllScope.kt | 2 +- .../annotations/component/GcSoftScope.kt | 2 +- .../annotations/component/GcStrongScope.kt | 2 +- .../annotations/component/GcWeakScope.kt | 2 +- .../annotations/qualifier/IgnoreQualifier.kt | 6 +++- 21 files changed, 88 insertions(+), 41 deletions(-) delete mode 100644 stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/poet/member/CoroutinesMemberFunctions.kt diff --git a/inject_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/weakref/Inject.kt b/inject_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/weakref/Inject.kt index 7b882f7b..316907d7 100644 --- a/inject_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/weakref/Inject.kt +++ b/inject_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/weakref/Inject.kt @@ -1,3 +1,11 @@ package com.github.klee0kai.stone.weakref +/** + * Identifies injectable constructors, methods, and fields. May apply to static + * as well as instance members. An injectable member may have any access + * modifier (private, package-private, protected, public). Constructors are + * injected first, followed by fields, and then methods. Fields and methods + * in superclasses are injected before those in subclasses. Ordering of + * injection among fields and among methods in the same class is not specified. + */ expect annotation class Inject() \ No newline at end of file diff --git a/inject_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/weakref/Named.kt b/inject_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/weakref/Named.kt index 2f6ad9be..fa7ff1d9 100644 --- a/inject_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/weakref/Named.kt +++ b/inject_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/weakref/Named.kt @@ -1,5 +1,23 @@ package com.github.klee0kai.stone.weakref + +/** + * String-based [Qualifier]. + * + * Example usage: + * + * ``` + * class Car { + * @Inject + * @Named("driver") + * var driverSeat : DriverSeat + * + * @Inject + * @Named("passenger") + * var passengerSeat: Seat + * } + * ``` + */ expect annotation class Named( val value: String = "" ) diff --git a/inject_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/weakref/Provider.kt b/inject_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/weakref/Provider.kt index 35bc0ff8..16d82c6a 100644 --- a/inject_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/weakref/Provider.kt +++ b/inject_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/weakref/Provider.kt @@ -1,5 +1,10 @@ package com.github.klee0kai.stone.weakref +/** + * Provides instances of [T]. Typically implemented by an injector. For + * any type [T] that can be injected, you can also inject + * `Provider`. + */ expect interface Provider { fun get(): T diff --git a/inject_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/weakref/Qualifier.kt b/inject_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/weakref/Qualifier.kt index 633b3608..d8cd3b75 100644 --- a/inject_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/weakref/Qualifier.kt +++ b/inject_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/weakref/Qualifier.kt @@ -1,3 +1,32 @@ package com.github.klee0kai.stone.weakref +/** + * Identifies qualifier annotations. Anyone can define a new qualifier. A + * qualifier annotation: + * + * - is annotated with `@Qualifier`, `@Retention(RUNTIME)`, + * and typically `@Documented`. + * - can have attributes. + * - may be part of the public API, much like the dependency type, but + * unlike implementation types which needn't be part of the public + * API. + * - may have restricted usage if annotated with {@code @Target}. While + * this specification covers applying qualifiers to fields and + * parameters only, some injector configurations might use qualifier + * annotations in other places (on methods or classes for example). + * + * + * For example: + * + * ``` + * @Documented + * @Retention(RUNTIME) + * @Qualifier + * annotation class Leather( + * val color: Color + * ) + * ``` + * + * @see [Named] + */ expect annotation class Qualifier() \ No newline at end of file diff --git a/inject_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/weakref/Scope.kt b/inject_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/weakref/Scope.kt index 78fe2b5a..4a95653f 100644 --- a/inject_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/weakref/Scope.kt +++ b/inject_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/weakref/Scope.kt @@ -1,3 +1,14 @@ package com.github.klee0kai.stone.weakref +/** + * Identifies scope annotations. A scope annotation applies to a class + * containing an injectable constructor and governs how the injector reuses + * instances of the type. By default, if no scope annotation is present, the + * injector creates an instance (by injecting the type's constructor), uses + * the instance for one injection, and then forgets it. If a scope annotation + * is present, the injector may retain the instance for possible reuse in a + * later injection. If multiple threads can access a scoped instance, its + * implementation should be thread safe. The implementation of the scope + * itself is left up to the injector. + */ expect annotation class Scope() \ No newline at end of file diff --git a/inject_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/weakref/Singleton.kt b/inject_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/weakref/Singleton.kt index 95fe5867..bfc6f18c 100644 --- a/inject_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/weakref/Singleton.kt +++ b/inject_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/weakref/Singleton.kt @@ -1,3 +1,8 @@ package com.github.klee0kai.stone.weakref +/** + * Identifies a type that the injector only instantiates once. Not inherited. + * + * @see [Scope] + */ expect annotation class Singleton() \ No newline at end of file diff --git a/inject_multiplatform/src/nativeMain/kotlin/com/github/klee0kai/stone/weakref/Inject.kt b/inject_multiplatform/src/nativeMain/kotlin/com/github/klee0kai/stone/weakref/Inject.kt index 9d8e703d..1b06381a 100644 --- a/inject_multiplatform/src/nativeMain/kotlin/com/github/klee0kai/stone/weakref/Inject.kt +++ b/inject_multiplatform/src/nativeMain/kotlin/com/github/klee0kai/stone/weakref/Inject.kt @@ -1,3 +1,4 @@ package com.github.klee0kai.stone.weakref + actual annotation class Inject actual constructor() \ No newline at end of file diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/invokecall/model/FieldDetail.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/invokecall/model/FieldDetail.kt index e4a89620..f424f7f0 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/invokecall/model/FieldDetail.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/invokecall/model/FieldDetail.kt @@ -1,11 +1,9 @@ package com.github.klee0kai.thekey.stone.ksp.helpers.invokecall.model -import com.github.klee0kai.stone.annotations.qualifier.IgnoreQualifier import com.github.klee0kai.thekey.stone.ksp.helpers.qualifierAnnotations import com.github.klee0kai.thekey.stone.ksp.ksp.resolveNotNullable import com.google.devtools.ksp.symbol.KSValueParameter import com.squareup.kotlinpoet.TypeName -import com.squareup.kotlinpoet.asClassName import com.squareup.kotlinpoet.ksp.toTypeName data class FieldDetail( @@ -14,8 +12,6 @@ data class FieldDetail( val qualifierAnns: Set = emptySet(), ) { companion object; - - } fun FieldDetail.Companion.simple(name: String, type: TypeName) = FieldDetail(name, type) @@ -26,7 +22,3 @@ fun KSValueParameter.toFieldDetail() = FieldDetail( qualifierAnns = qualifierAnnotations.map { it.toQualifierAnn() }.toSet(), ) -fun Set.anyIgnoreQualifier( -): Boolean = any { it.typeName == IgnoreQualifier::class.asClassName() } - - diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/itemholder/MultiKeyMapItemHolderCodeHelper.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/itemholder/MultiKeyMapItemHolderCodeHelper.kt index 683f8b36..d7beb9aa 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/itemholder/MultiKeyMapItemHolderCodeHelper.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/itemholder/MultiKeyMapItemHolderCodeHelper.kt @@ -69,5 +69,4 @@ class MultiKeyMapItemHolderCodeHelper( .addStatement("%L.clearNulls()", fieldName) .build() - } \ No newline at end of file diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/wrap/ClassNameUtils.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/wrap/ClassNameUtils.kt index 52b8413a..3b4c874f 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/wrap/ClassNameUtils.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/wrap/ClassNameUtils.kt @@ -32,7 +32,6 @@ object ClassNameUtils { return type } - } diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/poet/PoetExt.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/poet/PoetExt.kt index 02168db2..bbce7438 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/poet/PoetExt.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/poet/PoetExt.kt @@ -12,7 +12,7 @@ annotation class PoetDsl fun FileSpec.Builder.genLibComment() { addFileComment("Generated by Stone Library\n") addFileComment("Project " + Processor.PROJECT_URL + "\n") - addFileComment("Copyright (c) 2025 Andrey Kuzubov") + addFileComment("Copyright (c) 2022 Andrey Kuzubov") } diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/poet/member/CoroutinesMemberFunctions.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/poet/member/CoroutinesMemberFunctions.kt deleted file mode 100644 index f2944d56..00000000 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/poet/member/CoroutinesMemberFunctions.kt +++ /dev/null @@ -1,9 +0,0 @@ -package com.github.klee0kai.thekey.stone.ksp.poet.member - -import com.squareup.kotlinpoet.MemberName - -object CoroutinesMemberFunctions { - - val SupervisorJob = MemberName("kotlinx.coroutines", "SupervisorJob") - -} \ No newline at end of file diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/CommonPoetExt.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/CommonPoetExt.kt index d31d9bcc..cb5ea061 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/CommonPoetExt.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/CommonPoetExt.kt @@ -2,13 +2,8 @@ package com.github.klee0kai.thekey.stone.ksp.target import com.google.devtools.ksp.symbol.KSFunctionDeclaration import com.google.devtools.ksp.symbol.Modifier -import com.squareup.kotlinpoet.FunSpec -import com.squareup.kotlinpoet.KModifier -import com.squareup.kotlinpoet.ParameterSpec +import com.squareup.kotlinpoet.* import com.squareup.kotlinpoet.ParameterizedTypeName.Companion.parameterizedBy -import com.squareup.kotlinpoet.TypeName -import com.squareup.kotlinpoet.asClassName -import com.squareup.kotlinpoet.ksp.toClassName import com.squareup.kotlinpoet.ksp.toTypeName import kotlinx.coroutines.Deferred import kotlinx.coroutines.Job diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/component/ComponentsMethodsExt.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/component/ComponentsMethodsExt.kt index d5357457..c1ffa260 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/component/ComponentsMethodsExt.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/component/ComponentsMethodsExt.kt @@ -13,7 +13,6 @@ import com.github.klee0kai.thekey.stone.ksp.helpers.scopeAnnotations import com.github.klee0kai.thekey.stone.ksp.ksp.isClassReturn import com.github.klee0kai.thekey.stone.ksp.ksp.isNotPrimitive import com.github.klee0kai.thekey.stone.ksp.ksp.isUnit -import com.github.klee0kai.thekey.stone.ksp.ksp.resolveAlias import com.github.klee0kai.thekey.stone.ksp.ksp.resolveNotNullable import com.github.klee0kai.thekey.stone.ksp.target.module.GenModuleProcessor import com.google.devtools.ksp.getAllSuperTypes @@ -307,5 +306,3 @@ fun KSFunctionDeclaration.checkMethodNameBusy() { private val KSFunctionDeclaration.isProvideMethodSimple get() = isClassReturn() - - diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/hiddenmodule/GenHiddenModuleProcessor.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/hiddenmodule/GenHiddenModuleProcessor.kt index b7535992..bbab773c 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/hiddenmodule/GenHiddenModuleProcessor.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/hiddenmodule/GenHiddenModuleProcessor.kt @@ -427,8 +427,6 @@ class GenHiddenModuleProcessor : TargetFileProcessor { addModifiers(KModifier.OVERRIDE) addCode(codeBlocks.clearNullsMethodBody.build()) } - } - } diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/module/GenModuleProcessor.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/module/GenModuleProcessor.kt index 72deec18..b588aba1 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/module/GenModuleProcessor.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/module/GenModuleProcessor.kt @@ -101,13 +101,8 @@ class GenModuleProcessor : TargetFileProcessor { ?.allIdentifierTypes?.toList() ?: emptyList() - val wrapperTypes = componentCl - ?.wrapperProviders?.toList() - ?: emptyList() - val genModuleClassName = moduleCl.moduleStoneClName - val fileSpec = genFileSpec(genModuleClassName.packageName, genModuleClassName.simpleName) { genLibComment() diff --git a/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/annotations/component/GcAllScope.kt b/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/annotations/component/GcAllScope.kt index 8fa10fd7..28333808 100644 --- a/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/annotations/component/GcAllScope.kt +++ b/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/annotations/component/GcAllScope.kt @@ -4,7 +4,7 @@ package com.github.klee0kai.stone.annotations.component * A scope that defines all exposed objects in DI. * Used for garbage collection and caching change methods. */ -@com.github.klee0kai.stone.annotations.component.GcScopeAnnotation +@GcScopeAnnotation @Retention(AnnotationRetention.BINARY) @Target(AnnotationTarget.FUNCTION, AnnotationTarget.PROPERTY_GETTER, AnnotationTarget.PROPERTY_SETTER) annotation class GcAllScope diff --git a/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/annotations/component/GcSoftScope.kt b/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/annotations/component/GcSoftScope.kt index d9932b57..08107bd2 100644 --- a/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/annotations/component/GcSoftScope.kt +++ b/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/annotations/component/GcSoftScope.kt @@ -7,7 +7,7 @@ import com.github.klee0kai.stone.weakref.Scope * A standard library scope that lists all cached objects using soft references. * Used for garbage collection and caching change methods. */ -@com.github.klee0kai.stone.annotations.component.GcScopeAnnotation +@GcScopeAnnotation @Scope @Retention(AnnotationRetention.BINARY) @Target(AnnotationTarget.FUNCTION, AnnotationTarget.PROPERTY_GETTER, AnnotationTarget.PROPERTY_SETTER) diff --git a/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/annotations/component/GcStrongScope.kt b/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/annotations/component/GcStrongScope.kt index feb349a3..4350ca91 100644 --- a/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/annotations/component/GcStrongScope.kt +++ b/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/annotations/component/GcStrongScope.kt @@ -7,7 +7,7 @@ import com.github.klee0kai.stone.weakref.Scope * A standard library scope that enumerates all cacheable objects using strong references. * Used for garbage collection and caching change methods. */ -@com.github.klee0kai.stone.annotations.component.GcScopeAnnotation +@GcScopeAnnotation @Scope @Retention(AnnotationRetention.BINARY) @Target(AnnotationTarget.FUNCTION, AnnotationTarget.PROPERTY_GETTER, AnnotationTarget.PROPERTY_SETTER) diff --git a/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/annotations/component/GcWeakScope.kt b/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/annotations/component/GcWeakScope.kt index 82cd3cb5..11b01e77 100644 --- a/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/annotations/component/GcWeakScope.kt +++ b/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/annotations/component/GcWeakScope.kt @@ -7,7 +7,7 @@ import com.github.klee0kai.stone.weakref.Scope * A standard library scope that enumerates all cacheable objects using weak references. * Used for garbage collection and caching change methods. */ -@com.github.klee0kai.stone.annotations.component.GcScopeAnnotation +@GcScopeAnnotation @Scope @Retention(AnnotationRetention.BINARY) @Target(AnnotationTarget.FUNCTION, AnnotationTarget.PROPERTY_GETTER, AnnotationTarget.PROPERTY_SETTER) diff --git a/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/annotations/qualifier/IgnoreQualifier.kt b/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/annotations/qualifier/IgnoreQualifier.kt index 9d9989b5..a07d1d49 100644 --- a/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/annotations/qualifier/IgnoreQualifier.kt +++ b/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/annotations/qualifier/IgnoreQualifier.kt @@ -1,8 +1,12 @@ package com.github.klee0kai.stone.annotations.qualifier +import com.github.klee0kai.stone.weakref.Qualifier /** - * TODO kdoc + * For dependencies, we ignore all qualifier rules. + * If we collect dependencies into a collection, all available implementations with all qualifiers will be collected. + * + * @see [Qualifier] */ @Retention(AnnotationRetention.BINARY) @Target( From cde723275126a093ed3e34924a862f6b25029717 Mon Sep 17 00:00:00 2001 From: klee0kai Date: Sun, 18 Jan 2026 15:43:37 +0100 Subject: [PATCH 107/122] alpha version --- libs.versions.toml | 2 +- readme.md | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/libs.versions.toml b/libs.versions.toml index 340d8169..f307bd83 100644 --- a/libs.versions.toml +++ b/libs.versions.toml @@ -1,6 +1,6 @@ [versions] -stone = "2.0.0" +stone = "2.0.0_alpha" kotlin = "2.2.21" ksp = "2.3.2" diff --git a/readme.md b/readme.md index 402fea6a..00df9c54 100644 --- a/readme.md +++ b/readme.md @@ -37,8 +37,8 @@ In the project module, import dependencies ```kotlin dependencies { // stone - implementation("com.github.klee0kai.stone:stone_multiplatform:2.0.0") - ksp("com.github.klee0kai.stone:stone_ksp:2.0.0") + implementation("com.github.klee0kai.stone:stone_multiplatform:2.0.0_alpha") + ksp("com.github.klee0kai.stone:stone_ksp:2.0.0_alpha") } ``` From 600d865722073a8ac41f4111727334a867089185 Mon Sep 17 00:00:00 2001 From: klee0kai Date: Sun, 18 Jan 2026 16:15:36 +0100 Subject: [PATCH 108/122] jitpack build --- jitpack.yml | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 jitpack.yml diff --git a/jitpack.yml b/jitpack.yml new file mode 100644 index 00000000..d14c8f94 --- /dev/null +++ b/jitpack.yml @@ -0,0 +1,5 @@ +jdk: + - openjdk17 +install: + - echo "publish" + - ./gradlew publishToMavenLocal From 587389cfa5ecfe77ee9c2530c0fca2a1ec849392 Mon Sep 17 00:00:00 2001 From: klee0kai Date: Wed, 18 Feb 2026 22:39:21 +0100 Subject: [PATCH 109/122] correct nullable providing --- .../thekey/stone/ksp/helpers/invokecall/ModulesGraph.kt | 2 +- .../klee0kai/stone/__hidden__/provide/ProvideBuilder.kt | 9 ++++++++- .../klee0kai/test/di/earthmirror/EarthComponent.kt | 5 +++-- .../klee0kai/test/di/house/simple/HouseComponent.kt | 4 ++-- 4 files changed, 14 insertions(+), 6 deletions(-) diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/invokecall/ModulesGraph.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/invokecall/ModulesGraph.kt index 325999a3..7f8273fa 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/invokecall/ModulesGraph.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/invokecall/ModulesGraph.kt @@ -301,7 +301,7 @@ class ModulesGraph( ) } else { - codeBlock.add(".first() ") + codeBlock.add(if (providingType.isNullable) ".firstOrNull()" else ".first() ") return wrapHelper.transform( providingType, diff --git a/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/__hidden__/provide/ProvideBuilder.kt b/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/__hidden__/provide/ProvideBuilder.kt index 1aca2adc..26552f79 100644 --- a/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/__hidden__/provide/ProvideBuilder.kt +++ b/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/__hidden__/provide/ProvideBuilder.kt @@ -8,12 +8,19 @@ class ProvideBuilder( fun provide(consumer: ProvideConsumer) } - fun first(): T? { + fun firstOrNull(): T? { val consumer = ProvideConsumer() provideBody.provide(consumer) return consumer.first } + + fun first(): T { + val consumer = ProvideConsumer() + provideBody.provide(consumer) + return consumer.first!! + } + fun all(): List { val consumer = ProvideConsumer() provideBody.provide(consumer) diff --git a/tests/src/main/java/com/github/klee0kai/test/di/earthmirror/EarthComponent.kt b/tests/src/main/java/com/github/klee0kai/test/di/earthmirror/EarthComponent.kt index afacaa9f..5cb67888 100644 --- a/tests/src/main/java/com/github/klee0kai/test/di/earthmirror/EarthComponent.kt +++ b/tests/src/main/java/com/github/klee0kai/test/di/earthmirror/EarthComponent.kt @@ -5,7 +5,8 @@ import com.github.klee0kai.test.mowgli.earth.Cave.CaveType @Component(identifiers = [CaveType::class, Int::class]) interface EarthComponent { - fun east(): EastModule? - fun west(): WestModule? + fun east(): EastModule + + fun west(): WestModule } diff --git a/tests/src/main/java/com/github/klee0kai/test/di/house/simple/HouseComponent.kt b/tests/src/main/java/com/github/klee0kai/test/di/house/simple/HouseComponent.kt index 50743dfb..23e4f698 100644 --- a/tests/src/main/java/com/github/klee0kai/test/di/house/simple/HouseComponent.kt +++ b/tests/src/main/java/com/github/klee0kai/test/di/house/simple/HouseComponent.kt @@ -22,9 +22,9 @@ interface HouseComponent { fun house(): House? - fun sanitizers(): Sanitizers? + fun sanitizers(): Sanitizers - fun house(type: StoreAreaType?): House? + fun house(type: StoreAreaType?): House fun inject(storeAreaType: StoreAreaType?, inHouse: InHouse?) From 51ef2fb4c07e76cee35477564234a305c05c0e48 Mon Sep 17 00:00:00 2001 From: klee0kai Date: Thu, 19 Feb 2026 23:12:25 +0100 Subject: [PATCH 110/122] move files to multiplatform --- .../stone/ksp/helpers/wrap/WrapHelper.kt | 35 ++- .../stone/ksp/ksp/KSClassDeclarationExt.kt | 4 +- tests/build.gradle.kts | 27 +- .../test/di/base_forest/ForestComponent.kt | 0 .../test/di/base_forest/IdentityModule.kt | 0 .../test/di/base_forest/UnitedBlueModule.kt | 5 +- .../test/di/base_forest/UnitedModule.kt | 3 +- .../test/di/base_phone/PhoneComponent.kt | 0 .../klee0kai/test/di/base_phone/TechModule.kt | 2 +- .../base_phone/identifiers/DataStorageSize.kt | 5 + .../di/base_phone/identifiers/PhoneOsType.kt | 0 .../base_phone/identifiers/PhoneOsVersion.kt | 5 + .../test/di/base_phone/identifiers/RamSize.kt | 5 + .../simple/GodWorkspaceComponent.kt | 0 .../di/bindinstance/simple/SunSystemModule.kt | 0 .../simple_inject/SevenPlanetComponent.kt | 0 .../simple_inject/SevenPlanetModule.kt | 0 .../bindinstance/simple_inject/StarsModule.kt | 0 .../singlemethod/PlanetComponent.kt | 0 .../di/bindinstance/singlemethod/SunModule.kt | 3 +- .../singlemethod_gc/PlanetRollingComponent.kt | 0 .../singlemethod_inject/StarSkyComponent.kt | 1 + .../singlemethod_inject/StarSkyModule.kt | 0 .../bindinstance/solarsystem/PlanetModule.kt | 0 .../solarsystem/SolarSystemComponent.kt | 2 +- .../solarsystem/SolarSystemDependencies.kt | 0 .../test/di/earthmirror/EarthComponent.kt | 0 .../test/di/earthmirror/EastModule.kt | 0 .../test/di/earthmirror/WestModule.kt | 0 .../test/di/gcforest/GcEarthComponent.kt | 0 .../test/di/gcforest/GcEarthModule.kt | 0 .../test/di/gcforest/GcGodComponent.kt | 0 .../test/di/gcforest/GcSunSystemModule.kt | 0 .../di/gcforest/scopes/GcMountainScope.kt | 0 .../test/di/gcforest/scopes/GcPlanetScope.kt | 0 .../test/di/gcforest/scopes/GcRiverScope.kt | 2 +- .../test/di/gcforest/scopes/GcSunScope.kt | 2 +- .../di/house/nulls/HouseNullsComponent.kt | 0 .../test/di/house/nulls/HouseNullsModule.kt | 0 .../test/di/house/simple/AreasModule.kt | 0 .../test/di/house/simple/HouseComponent.kt | 0 .../test/di/house/simple/HouseModule.kt | 0 .../test/di/house/simple/RoomsModule.kt | 0 .../test/di/house/simple/ToolsModule.kt | 0 .../test/di/swcache/SwitchCacheComponent.kt | 0 .../di/techfactory/ITechProviderComponent.kt | 11 +- .../di/techfactory/TechFactoryComponent.kt | 0 .../test/di/techfactory/TechFactoryModule.kt | 2 +- .../klee0kai/test/di/wire/WireComponent.kt | 6 +- .../klee0kai/test/di/wire/WireModule.kt | 2 + .../com/github/klee0kai/test/house/House.kt | 21 ++ .../com/github/klee0kai/test/house/InHouse.kt | 8 +- .../test/house/identifiers/StoreAreaType.kt | 0 .../klee0kai/test/house/kitchen/Kichen.kt | 14 +- .../house/kitchen/cookingarea/CookingArea.kt | 10 + .../test/house/kitchen/sinkarea/SinkArea.kt | 10 + .../test/house/kitchen/storagearea/Clothes.kt | 10 + .../house/kitchen/storagearea/Cookware.kt | 10 + .../house/kitchen/storagearea/GarageStore.kt | 7 + .../house/kitchen/storagearea/Sanitizers.kt | 9 +- .../house/kitchen/storagearea/StoreArea.kt | 10 + .../klee0kai/test/house/rooms/BathRoom.kt | 11 + .../klee0kai/test/house/rooms/BedRoom.kt | 11 + .../klee0kai/test/house/rooms/Garage.kt | 7 +- .../github/klee0kai/test/mowgli/MoonSky.kt | 3 +- .../com/github/klee0kai/test/mowgli/School.kt | 7 +- .../klee0kai/test/mowgli/animal/Horse.kt | 11 +- .../klee0kai/test/mowgli/animal/IAnimal.kt | 0 .../klee0kai/test/mowgli/animal/Mowgli.kt | 17 +- .../klee0kai/test/mowgli/animal/Snake.kt | 3 +- .../github/klee0kai/test/mowgli/body/Blood.kt | 17 ++ .../klee0kai/test/mowgli/community/History.kt | 10 + .../github/klee0kai/test/mowgli/earth/Cave.kt | 4 +- .../klee0kai/test/mowgli/earth/IMountain.kt | 0 .../klee0kai/test/mowgli/earth/IRiver.kt | 0 .../klee0kai/test/mowgli/earth/Mountain.kt | 14 + .../klee0kai/test/mowgli/earth/River.kt | 10 + .../klee0kai/test/mowgli/galaxy/Earth.kt | 12 + .../klee0kai/test/mowgli/galaxy/IPlanet.kt | 0 .../klee0kai/test/mowgli/galaxy/IStar.kt | 0 .../klee0kai/test/mowgli/galaxy/Mercury.kt | 10 + .../klee0kai/test/mowgli/galaxy/Saturn.kt | 12 + .../test/mowgli/galaxy/SolarSystem.kt | 0 .../github/klee0kai/test/mowgli/galaxy/Sun.kt | 14 + .../test/mowgli/identity/Conscience.kt | 15 + .../klee0kai/test/mowgli/identity/Ideology.kt | 14 + .../test/mowgli/identity/Knowledge.kt | 17 ++ .../klee0kai/test/tech/components/Battery.kt | 12 + .../test/tech/components/DataStorage.kt | 8 +- .../test/tech/components/OperationSystem.kt | 12 +- .../klee0kai/test/tech/components/Ram.kt | 8 +- .../klee0kai/test/tech/phone/GoodPhone.kt | 10 +- .../klee0kai/test/tech/phone/OnePhone.kt | 6 +- .../klee0kai/test/tech/phone/base/ATech.kt | 5 +- .../test/tech/phone/base/ATechLifecycle.kt | 0 .../test/tech/phone/base/LifecycleUtils.kt | 0 .../com/github/klee0kai/test/wire/Wire.kt | 0 .../github/klee0kai/test/wire/types/Hdmi.kt | 0 .../klee0kai/test/wire/types/MiniUsb.kt | 0 .../github/klee0kai/test/wire/types/Usb.kt | 0 .../simple/GodFirstWorkDayTest.kt | 6 +- .../test/bindinstance/simple/GodTouchTest.kt | 8 +- .../simple_inject/SevenPlanetTests.kt | 3 +- .../singlemethod/PlanetProvideTests.kt | 6 +- .../singlemethod/StarProvideTests.kt | 6 +- .../singlemethod_gc/PlanetRollingTests.kt | 80 ++--- .../MoonSkyProtectInjectedTests.kt | 21 +- .../singlemethod_inject/MoonSkyTests.kt | 6 +- .../solarsystem/SolarSystemTests.kt | 4 + .../stone/test/cache/EarthCacheTests.kt | 3 + .../stone/test/cache/EarthSwitchCacheTests.kt | 34 +-- .../stone/test/deps/HouseFactoryTests.kt | 3 + .../stone/test/deps/HouseNullsTests.kt | 4 +- .../klee0kai/stone/test/deps/HouseTests.kt | 5 + .../klee0kai/stone/test/deps/InHouseTests.kt | 17 +- .../stone/test/gc/EarthLastDayTests.kt | 285 ++++++++++++++++++ .../stone/test/gc/GodLastWorkDayTests.kt | 46 +-- .../test/identifiers/GoodPhoneInjectTests.kt | 2 + .../test/identifiers/MultiIdentifiersTests.kt | 4 +- .../test/identifiers/TechComponentsTests.kt | 3 + .../identifiers/TechFactoryComponentTests.kt | 4 + .../test/identifiers/TechFactoryTests.kt | 2 + .../identifiers/TechFactoryWrappersTests.kt | 4 + .../stone/test/inject/HorseInjectTests.kt | 5 +- .../test/inject/HorseProtectInjectTests.kt | 13 +- .../inject/MowgliInjectMethodWrappersTests.kt | 7 +- .../test/inject/MowgliInjectWrappersTests.kt | 4 + .../SchoolProtectInjectWrappersTests.kt | 12 +- .../test/interfaceprovide/DeepCaveTest.kt | 4 +- .../test/interfaceprovide/EarthWayTest.kt | 4 +- .../test/lifecycle/GoodPhoneRepairTests.kt | 46 +-- .../test/lifecycle/OnePhoneRepairTests.kt | 45 ++- .../test/moduleinit/BeginOfBegins2Tests.kt | 2 + .../test/moduleinit/BeginOfBeginsTests.kt | 5 +- .../stone/test/parameterized/WireTest.kt | 6 +- .../stone/test/types/ListUtilTests.java | 0 .../base_phone/identifiers/DataStorageSize.kt | 16 - .../base_phone/identifiers/PhoneOsVersion.kt | 16 - .../test/di/base_phone/identifiers/RamSize.kt | 16 - .../com/github/klee0kai/test/house/House.kt | 12 - .../house/kitchen/cookingarea/CookingArea.kt | 7 - .../test/house/kitchen/sinkarea/SinkArea.kt | 7 - .../test/house/kitchen/storagearea/Clothes.kt | 7 - .../house/kitchen/storagearea/Cookware.kt | 7 - .../house/kitchen/storagearea/GarageStore.kt | 3 - .../house/kitchen/storagearea/StoreArea.kt | 5 - .../klee0kai/test/house/rooms/BathRoom.kt | 8 - .../klee0kai/test/house/rooms/BedRoom.kt | 8 - .../github/klee0kai/test/mowgli/body/Blood.kt | 15 - .../klee0kai/test/mowgli/community/History.kt | 7 - .../klee0kai/test/mowgli/earth/Mountain.kt | 8 - .../klee0kai/test/mowgli/earth/River.kt | 7 - .../klee0kai/test/mowgli/galaxy/Earth.kt | 8 - .../klee0kai/test/mowgli/galaxy/Mercury.kt | 7 - .../klee0kai/test/mowgli/galaxy/Saturn.kt | 8 - .../github/klee0kai/test/mowgli/galaxy/Sun.kt | 8 - .../test/mowgli/identity/Conscience.kt | 11 - .../klee0kai/test/mowgli/identity/Ideology.kt | 10 - .../test/mowgli/identity/Knowledge.kt | 12 - .../klee0kai/test/tech/components/Battery.kt | 8 - .../stone/test/gc/EarthLastDayTests.kt | 281 ----------------- .../test_ext/inject/mowgli/earth/WaterFlow.kt | 7 +- .../inject/tech/components/DDR3Ram.kt | 7 +- 163 files changed, 962 insertions(+), 774 deletions(-) rename tests/src/{main/java => commonMain/kotlin}/com/github/klee0kai/test/di/base_forest/ForestComponent.kt (100%) rename tests/src/{main/java => commonMain/kotlin}/com/github/klee0kai/test/di/base_forest/IdentityModule.kt (100%) rename tests/src/{main/java => commonMain/kotlin}/com/github/klee0kai/test/di/base_forest/UnitedBlueModule.kt (86%) rename tests/src/{main/java => commonMain/kotlin}/com/github/klee0kai/test/di/base_forest/UnitedModule.kt (91%) rename tests/src/{main/java => commonMain/kotlin}/com/github/klee0kai/test/di/base_phone/PhoneComponent.kt (100%) rename tests/src/{main/java => commonMain/kotlin}/com/github/klee0kai/test/di/base_phone/TechModule.kt (96%) create mode 100644 tests/src/commonMain/kotlin/com/github/klee0kai/test/di/base_phone/identifiers/DataStorageSize.kt rename tests/src/{main/java => commonMain/kotlin}/com/github/klee0kai/test/di/base_phone/identifiers/PhoneOsType.kt (100%) create mode 100644 tests/src/commonMain/kotlin/com/github/klee0kai/test/di/base_phone/identifiers/PhoneOsVersion.kt create mode 100644 tests/src/commonMain/kotlin/com/github/klee0kai/test/di/base_phone/identifiers/RamSize.kt rename tests/src/{main/java => commonMain/kotlin}/com/github/klee0kai/test/di/bindinstance/simple/GodWorkspaceComponent.kt (100%) rename tests/src/{main/java => commonMain/kotlin}/com/github/klee0kai/test/di/bindinstance/simple/SunSystemModule.kt (100%) rename tests/src/{main/java => commonMain/kotlin}/com/github/klee0kai/test/di/bindinstance/simple_inject/SevenPlanetComponent.kt (100%) rename tests/src/{main/java => commonMain/kotlin}/com/github/klee0kai/test/di/bindinstance/simple_inject/SevenPlanetModule.kt (100%) rename tests/src/{main/java => commonMain/kotlin}/com/github/klee0kai/test/di/bindinstance/simple_inject/StarsModule.kt (100%) rename tests/src/{main/java => commonMain/kotlin}/com/github/klee0kai/test/di/bindinstance/singlemethod/PlanetComponent.kt (100%) rename tests/src/{main/java => commonMain/kotlin}/com/github/klee0kai/test/di/bindinstance/singlemethod/SunModule.kt (94%) rename tests/src/{main/java => commonMain/kotlin}/com/github/klee0kai/test/di/bindinstance/singlemethod_gc/PlanetRollingComponent.kt (100%) rename tests/src/{main/java => commonMain/kotlin}/com/github/klee0kai/test/di/bindinstance/singlemethod_inject/StarSkyComponent.kt (99%) rename tests/src/{main/java => commonMain/kotlin}/com/github/klee0kai/test/di/bindinstance/singlemethod_inject/StarSkyModule.kt (100%) rename tests/src/{main/java => commonMain/kotlin}/com/github/klee0kai/test/di/bindinstance/solarsystem/PlanetModule.kt (100%) rename tests/src/{main/java => commonMain/kotlin}/com/github/klee0kai/test/di/bindinstance/solarsystem/SolarSystemComponent.kt (100%) rename tests/src/{main/java => commonMain/kotlin}/com/github/klee0kai/test/di/bindinstance/solarsystem/SolarSystemDependencies.kt (100%) rename tests/src/{main/java => commonMain/kotlin}/com/github/klee0kai/test/di/earthmirror/EarthComponent.kt (100%) rename tests/src/{main/java => commonMain/kotlin}/com/github/klee0kai/test/di/earthmirror/EastModule.kt (100%) rename tests/src/{main/java => commonMain/kotlin}/com/github/klee0kai/test/di/earthmirror/WestModule.kt (100%) rename tests/src/{main/java => commonMain/kotlin}/com/github/klee0kai/test/di/gcforest/GcEarthComponent.kt (100%) rename tests/src/{main/java => commonMain/kotlin}/com/github/klee0kai/test/di/gcforest/GcEarthModule.kt (100%) rename tests/src/{main/java => commonMain/kotlin}/com/github/klee0kai/test/di/gcforest/GcGodComponent.kt (100%) rename tests/src/{main/java => commonMain/kotlin}/com/github/klee0kai/test/di/gcforest/GcSunSystemModule.kt (100%) rename tests/src/{main/java => commonMain/kotlin}/com/github/klee0kai/test/di/gcforest/scopes/GcMountainScope.kt (100%) rename tests/src/{main/java => commonMain/kotlin}/com/github/klee0kai/test/di/gcforest/scopes/GcPlanetScope.kt (100%) rename tests/src/{main/java => commonMain/kotlin}/com/github/klee0kai/test/di/gcforest/scopes/GcRiverScope.kt (83%) rename tests/src/{main/java => commonMain/kotlin}/com/github/klee0kai/test/di/gcforest/scopes/GcSunScope.kt (83%) rename tests/src/{main/java => commonMain/kotlin}/com/github/klee0kai/test/di/house/nulls/HouseNullsComponent.kt (100%) rename tests/src/{main/java => commonMain/kotlin}/com/github/klee0kai/test/di/house/nulls/HouseNullsModule.kt (100%) rename tests/src/{main/java => commonMain/kotlin}/com/github/klee0kai/test/di/house/simple/AreasModule.kt (100%) rename tests/src/{main/java => commonMain/kotlin}/com/github/klee0kai/test/di/house/simple/HouseComponent.kt (100%) rename tests/src/{main/java => commonMain/kotlin}/com/github/klee0kai/test/di/house/simple/HouseModule.kt (100%) rename tests/src/{main/java => commonMain/kotlin}/com/github/klee0kai/test/di/house/simple/RoomsModule.kt (100%) rename tests/src/{main/java => commonMain/kotlin}/com/github/klee0kai/test/di/house/simple/ToolsModule.kt (100%) rename tests/src/{main/java => commonMain/kotlin}/com/github/klee0kai/test/di/swcache/SwitchCacheComponent.kt (100%) rename tests/src/{main/java => commonMain/kotlin}/com/github/klee0kai/test/di/techfactory/ITechProviderComponent.kt (80%) rename tests/src/{main/java => commonMain/kotlin}/com/github/klee0kai/test/di/techfactory/TechFactoryComponent.kt (100%) rename tests/src/{main/java => commonMain/kotlin}/com/github/klee0kai/test/di/techfactory/TechFactoryModule.kt (96%) rename tests/src/{main/java => commonMain/kotlin}/com/github/klee0kai/test/di/wire/WireComponent.kt (85%) rename tests/src/{main/java => commonMain/kotlin}/com/github/klee0kai/test/di/wire/WireModule.kt (99%) create mode 100644 tests/src/commonMain/kotlin/com/github/klee0kai/test/house/House.kt rename tests/src/{main/java => commonMain/kotlin}/com/github/klee0kai/test/house/InHouse.kt (84%) rename tests/src/{main/java => commonMain/kotlin}/com/github/klee0kai/test/house/identifiers/StoreAreaType.kt (100%) rename tests/src/{main/java => commonMain/kotlin}/com/github/klee0kai/test/house/kitchen/Kichen.kt (52%) create mode 100644 tests/src/commonMain/kotlin/com/github/klee0kai/test/house/kitchen/cookingarea/CookingArea.kt create mode 100644 tests/src/commonMain/kotlin/com/github/klee0kai/test/house/kitchen/sinkarea/SinkArea.kt create mode 100644 tests/src/commonMain/kotlin/com/github/klee0kai/test/house/kitchen/storagearea/Clothes.kt create mode 100644 tests/src/commonMain/kotlin/com/github/klee0kai/test/house/kitchen/storagearea/Cookware.kt create mode 100644 tests/src/commonMain/kotlin/com/github/klee0kai/test/house/kitchen/storagearea/GarageStore.kt rename tests/src/{main/java => commonMain/kotlin}/com/github/klee0kai/test/house/kitchen/storagearea/Sanitizers.kt (54%) create mode 100644 tests/src/commonMain/kotlin/com/github/klee0kai/test/house/kitchen/storagearea/StoreArea.kt create mode 100644 tests/src/commonMain/kotlin/com/github/klee0kai/test/house/rooms/BathRoom.kt create mode 100644 tests/src/commonMain/kotlin/com/github/klee0kai/test/house/rooms/BedRoom.kt rename tests/src/{main/java => commonMain/kotlin}/com/github/klee0kai/test/house/rooms/Garage.kt (52%) rename tests/src/{main/java => commonMain/kotlin}/com/github/klee0kai/test/mowgli/MoonSky.kt (83%) rename tests/src/{main/java => commonMain/kotlin}/com/github/klee0kai/test/mowgli/School.kt (84%) rename tests/src/{main/java => commonMain/kotlin}/com/github/klee0kai/test/mowgli/animal/Horse.kt (88%) rename tests/src/{main/java => commonMain/kotlin}/com/github/klee0kai/test/mowgli/animal/IAnimal.kt (100%) rename tests/src/{main/java => commonMain/kotlin}/com/github/klee0kai/test/mowgli/animal/Mowgli.kt (79%) rename tests/src/{main/java => commonMain/kotlin}/com/github/klee0kai/test/mowgli/animal/Snake.kt (89%) create mode 100644 tests/src/commonMain/kotlin/com/github/klee0kai/test/mowgli/body/Blood.kt create mode 100644 tests/src/commonMain/kotlin/com/github/klee0kai/test/mowgli/community/History.kt rename tests/src/{main/java => commonMain/kotlin}/com/github/klee0kai/test/mowgli/earth/Cave.kt (74%) rename tests/src/{main/java => commonMain/kotlin}/com/github/klee0kai/test/mowgli/earth/IMountain.kt (100%) rename tests/src/{main/java => commonMain/kotlin}/com/github/klee0kai/test/mowgli/earth/IRiver.kt (100%) create mode 100644 tests/src/commonMain/kotlin/com/github/klee0kai/test/mowgli/earth/Mountain.kt create mode 100644 tests/src/commonMain/kotlin/com/github/klee0kai/test/mowgli/earth/River.kt create mode 100644 tests/src/commonMain/kotlin/com/github/klee0kai/test/mowgli/galaxy/Earth.kt rename tests/src/{main/java => commonMain/kotlin}/com/github/klee0kai/test/mowgli/galaxy/IPlanet.kt (100%) rename tests/src/{main/java => commonMain/kotlin}/com/github/klee0kai/test/mowgli/galaxy/IStar.kt (100%) create mode 100644 tests/src/commonMain/kotlin/com/github/klee0kai/test/mowgli/galaxy/Mercury.kt create mode 100644 tests/src/commonMain/kotlin/com/github/klee0kai/test/mowgli/galaxy/Saturn.kt rename tests/src/{main/java => commonMain/kotlin}/com/github/klee0kai/test/mowgli/galaxy/SolarSystem.kt (100%) create mode 100644 tests/src/commonMain/kotlin/com/github/klee0kai/test/mowgli/galaxy/Sun.kt create mode 100644 tests/src/commonMain/kotlin/com/github/klee0kai/test/mowgli/identity/Conscience.kt create mode 100644 tests/src/commonMain/kotlin/com/github/klee0kai/test/mowgli/identity/Ideology.kt create mode 100644 tests/src/commonMain/kotlin/com/github/klee0kai/test/mowgli/identity/Knowledge.kt create mode 100644 tests/src/commonMain/kotlin/com/github/klee0kai/test/tech/components/Battery.kt rename tests/src/{main/java => commonMain/kotlin}/com/github/klee0kai/test/tech/components/DataStorage.kt (64%) rename tests/src/{main/java => commonMain/kotlin}/com/github/klee0kai/test/tech/components/OperationSystem.kt (77%) rename tests/src/{main/java => commonMain/kotlin}/com/github/klee0kai/test/tech/components/Ram.kt (64%) rename tests/src/{main/java => commonMain/kotlin}/com/github/klee0kai/test/tech/phone/GoodPhone.kt (91%) rename tests/src/{main/java => commonMain/kotlin}/com/github/klee0kai/test/tech/phone/OnePhone.kt (91%) rename tests/src/{main/java => commonMain/kotlin}/com/github/klee0kai/test/tech/phone/base/ATech.kt (83%) rename tests/src/{main/java => commonMain/kotlin}/com/github/klee0kai/test/tech/phone/base/ATechLifecycle.kt (100%) rename tests/src/{main/java => commonMain/kotlin}/com/github/klee0kai/test/tech/phone/base/LifecycleUtils.kt (100%) rename tests/src/{main/java => commonMain/kotlin}/com/github/klee0kai/test/wire/Wire.kt (100%) rename tests/src/{main/java => commonMain/kotlin}/com/github/klee0kai/test/wire/types/Hdmi.kt (100%) rename tests/src/{main/java => commonMain/kotlin}/com/github/klee0kai/test/wire/types/MiniUsb.kt (100%) rename tests/src/{main/java => commonMain/kotlin}/com/github/klee0kai/test/wire/types/Usb.kt (100%) rename tests/src/{test/java => commonTest/kotlin}/com/github/klee0kai/stone/test/bindinstance/simple/GodFirstWorkDayTest.kt (94%) rename tests/src/{test/java => commonTest/kotlin}/com/github/klee0kai/stone/test/bindinstance/simple/GodTouchTest.kt (92%) rename tests/src/{test/java => commonTest/kotlin}/com/github/klee0kai/stone/test/bindinstance/simple_inject/SevenPlanetTests.kt (94%) rename tests/src/{test/java => commonTest/kotlin}/com/github/klee0kai/stone/test/bindinstance/singlemethod/PlanetProvideTests.kt (93%) rename tests/src/{test/java => commonTest/kotlin}/com/github/klee0kai/stone/test/bindinstance/singlemethod/StarProvideTests.kt (91%) rename tests/src/{test/java => commonTest/kotlin}/com/github/klee0kai/stone/test/bindinstance/singlemethod_gc/PlanetRollingTests.kt (71%) rename tests/src/{test/java => commonTest/kotlin}/com/github/klee0kai/stone/test/bindinstance/singlemethod_inject/MoonSkyProtectInjectedTests.kt (79%) rename tests/src/{test/java => commonTest/kotlin}/com/github/klee0kai/stone/test/bindinstance/singlemethod_inject/MoonSkyTests.kt (92%) rename tests/src/{test/java => commonTest/kotlin}/com/github/klee0kai/stone/test/bindinstance/solarsystem/SolarSystemTests.kt (91%) rename tests/src/{test/java => commonTest/kotlin}/com/github/klee0kai/stone/test/cache/EarthCacheTests.kt (97%) rename tests/src/{test/java => commonTest/kotlin}/com/github/klee0kai/stone/test/cache/EarthSwitchCacheTests.kt (62%) rename tests/src/{test/java => commonTest/kotlin}/com/github/klee0kai/stone/test/deps/HouseFactoryTests.kt (91%) rename tests/src/{test/java => commonTest/kotlin}/com/github/klee0kai/stone/test/deps/HouseNullsTests.kt (87%) rename tests/src/{test/java => commonTest/kotlin}/com/github/klee0kai/stone/test/deps/HouseTests.kt (93%) rename tests/src/{test/java => commonTest/kotlin}/com/github/klee0kai/stone/test/deps/InHouseTests.kt (91%) create mode 100644 tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/gc/EarthLastDayTests.kt rename tests/src/{test/java => commonTest/kotlin}/com/github/klee0kai/stone/test/gc/GodLastWorkDayTests.kt (75%) rename tests/src/{test/java => commonTest/kotlin}/com/github/klee0kai/stone/test/identifiers/GoodPhoneInjectTests.kt (95%) rename tests/src/{test/java => commonTest/kotlin}/com/github/klee0kai/stone/test/identifiers/MultiIdentifiersTests.kt (95%) rename tests/src/{test/java => commonTest/kotlin}/com/github/klee0kai/stone/test/identifiers/TechComponentsTests.kt (95%) rename tests/src/{test/java => commonTest/kotlin}/com/github/klee0kai/stone/test/identifiers/TechFactoryComponentTests.kt (95%) rename tests/src/{test/java => commonTest/kotlin}/com/github/klee0kai/stone/test/identifiers/TechFactoryTests.kt (95%) rename tests/src/{test/java => commonTest/kotlin}/com/github/klee0kai/stone/test/identifiers/TechFactoryWrappersTests.kt (94%) rename tests/src/{test/java => commonTest/kotlin}/com/github/klee0kai/stone/test/inject/HorseInjectTests.kt (94%) rename tests/src/{test/java => commonTest/kotlin}/com/github/klee0kai/stone/test/inject/HorseProtectInjectTests.kt (83%) rename tests/src/{test/java => commonTest/kotlin}/com/github/klee0kai/stone/test/inject/MowgliInjectMethodWrappersTests.kt (94%) rename tests/src/{test/java => commonTest/kotlin}/com/github/klee0kai/stone/test/inject/MowgliInjectWrappersTests.kt (94%) rename tests/src/{test/java => commonTest/kotlin}/com/github/klee0kai/stone/test/inject/SchoolProtectInjectWrappersTests.kt (71%) rename tests/src/{test/java => commonTest/kotlin}/com/github/klee0kai/stone/test/interfaceprovide/DeepCaveTest.kt (90%) rename tests/src/{test/java => commonTest/kotlin}/com/github/klee0kai/stone/test/interfaceprovide/EarthWayTest.kt (83%) rename tests/src/{test/java => commonTest/kotlin}/com/github/klee0kai/stone/test/lifecycle/GoodPhoneRepairTests.kt (79%) rename tests/src/{test/java => commonTest/kotlin}/com/github/klee0kai/stone/test/lifecycle/OnePhoneRepairTests.kt (73%) rename tests/src/{test/java => commonTest/kotlin}/com/github/klee0kai/stone/test/moduleinit/BeginOfBegins2Tests.kt (97%) rename tests/src/{test/java => commonTest/kotlin}/com/github/klee0kai/stone/test/moduleinit/BeginOfBeginsTests.kt (83%) rename tests/src/{test/java => commonTest/kotlin}/com/github/klee0kai/stone/test/parameterized/WireTest.kt (90%) rename tests/src/{test/java => commonTest/kotlin}/com/github/klee0kai/stone/test/types/ListUtilTests.java (100%) delete mode 100644 tests/src/main/java/com/github/klee0kai/test/di/base_phone/identifiers/DataStorageSize.kt delete mode 100644 tests/src/main/java/com/github/klee0kai/test/di/base_phone/identifiers/PhoneOsVersion.kt delete mode 100644 tests/src/main/java/com/github/klee0kai/test/di/base_phone/identifiers/RamSize.kt delete mode 100644 tests/src/main/java/com/github/klee0kai/test/house/House.kt delete mode 100644 tests/src/main/java/com/github/klee0kai/test/house/kitchen/cookingarea/CookingArea.kt delete mode 100644 tests/src/main/java/com/github/klee0kai/test/house/kitchen/sinkarea/SinkArea.kt delete mode 100644 tests/src/main/java/com/github/klee0kai/test/house/kitchen/storagearea/Clothes.kt delete mode 100644 tests/src/main/java/com/github/klee0kai/test/house/kitchen/storagearea/Cookware.kt delete mode 100644 tests/src/main/java/com/github/klee0kai/test/house/kitchen/storagearea/GarageStore.kt delete mode 100644 tests/src/main/java/com/github/klee0kai/test/house/kitchen/storagearea/StoreArea.kt delete mode 100644 tests/src/main/java/com/github/klee0kai/test/house/rooms/BathRoom.kt delete mode 100644 tests/src/main/java/com/github/klee0kai/test/house/rooms/BedRoom.kt delete mode 100644 tests/src/main/java/com/github/klee0kai/test/mowgli/body/Blood.kt delete mode 100644 tests/src/main/java/com/github/klee0kai/test/mowgli/community/History.kt delete mode 100644 tests/src/main/java/com/github/klee0kai/test/mowgli/earth/Mountain.kt delete mode 100644 tests/src/main/java/com/github/klee0kai/test/mowgli/earth/River.kt delete mode 100644 tests/src/main/java/com/github/klee0kai/test/mowgli/galaxy/Earth.kt delete mode 100644 tests/src/main/java/com/github/klee0kai/test/mowgli/galaxy/Mercury.kt delete mode 100644 tests/src/main/java/com/github/klee0kai/test/mowgli/galaxy/Saturn.kt delete mode 100644 tests/src/main/java/com/github/klee0kai/test/mowgli/galaxy/Sun.kt delete mode 100644 tests/src/main/java/com/github/klee0kai/test/mowgli/identity/Conscience.kt delete mode 100644 tests/src/main/java/com/github/klee0kai/test/mowgli/identity/Ideology.kt delete mode 100644 tests/src/main/java/com/github/klee0kai/test/mowgli/identity/Knowledge.kt delete mode 100644 tests/src/main/java/com/github/klee0kai/test/tech/components/Battery.kt delete mode 100644 tests/src/test/java/com/github/klee0kai/stone/test/gc/EarthLastDayTests.kt diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/wrap/WrapHelper.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/wrap/WrapHelper.kt index c8da8585..1388feb8 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/wrap/WrapHelper.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/wrap/WrapHelper.kt @@ -1,6 +1,8 @@ package com.github.klee0kai.thekey.stone.ksp.helpers.wrap import com.github.klee0kai.stone.weakref.Ref +import com.github.klee0kai.stone.weakref.SoftRef +import com.github.klee0kai.stone.weakref.WeakRef import com.github.klee0kai.stone.wrappers.AsyncCoroutineProvide import com.github.klee0kai.stone.wrappers.LazyProvide import com.github.klee0kai.stone.wrappers.PhantomProvide @@ -217,6 +219,38 @@ class WrapHelper { support(wrapType) } + + for (cl in listOf( + WeakRef::class, + SoftRef::class, + Ref::class, + )) { + val creator = cl.asClassName() + + val wrapType = WrapType( + typeName = creator, + isNoCachingWrapper = false, + wrap = { or, srcNullable, targetNullable, argTypeNullable -> + codeBlock { + when { + !srcNullable -> add("%T( %L )", creator, or) + targetNullable -> add("%L?.let{ %T( it ) }", or, creator) + else -> add("%T( %L!! )", creator, or) + } + } + }, + unwrap = { or, srcNullable, targetNullable -> + codeBlock { + when { + targetNullable -> add("%L?.get()", or) + else -> add("%L!!.get()!!", or) + } + } + } + ) + support(wrapType) + } + for (cl in listOf( Lazy::class, )) { @@ -247,7 +281,6 @@ class WrapHelper { for (cl in listOf( PhantomProvide::class, - Ref::class, Provider::class, LazyProvide::class, AsyncCoroutineProvide::class diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/ksp/KSClassDeclarationExt.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/ksp/KSClassDeclarationExt.kt index 8d6f80b5..ce07eb96 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/ksp/KSClassDeclarationExt.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/ksp/KSClassDeclarationExt.kt @@ -17,9 +17,9 @@ fun KSTypeReference.resolveNotNullable(): KSType = resolve().makeNotNullable().u fun KSType.unwrapAlias(): KSType { var current: KSType = this - while (current.declaration is KSTypeAlias) { + if (current.declaration is KSTypeAlias) { val alias = current.declaration as KSTypeAlias - current = alias.type.resolve() + current = alias.type.resolve().replace(current.arguments) } return current } diff --git a/tests/build.gradle.kts b/tests/build.gradle.kts index 06a16db4..69730d2b 100644 --- a/tests/build.gradle.kts +++ b/tests/build.gradle.kts @@ -1,16 +1,33 @@ plugins { - alias(libs.plugins.kotlin.jvm) + alias(libs.plugins.kotlin.multiplatform) alias(libs.plugins.kotlin.ksp) } -tasks.test { - useJUnitPlatform() + +kotlin { + jvm() + js(IR) { + browser() + nodejs() + } + + linuxX64() + mingwX64() + wasmJs() + + sourceSets { + commonMain.dependencies { + implementation(project(":stone_multiplatform")) + + } + commonTest.dependencies { + implementation(kotlin("test")) + } + } } dependencies { - implementation(project(":stone_multiplatform")) ksp(project(":stone_ksp")) - testImplementation(libs.bundles.junit) } diff --git a/tests/src/main/java/com/github/klee0kai/test/di/base_forest/ForestComponent.kt b/tests/src/commonMain/kotlin/com/github/klee0kai/test/di/base_forest/ForestComponent.kt similarity index 100% rename from tests/src/main/java/com/github/klee0kai/test/di/base_forest/ForestComponent.kt rename to tests/src/commonMain/kotlin/com/github/klee0kai/test/di/base_forest/ForestComponent.kt diff --git a/tests/src/main/java/com/github/klee0kai/test/di/base_forest/IdentityModule.kt b/tests/src/commonMain/kotlin/com/github/klee0kai/test/di/base_forest/IdentityModule.kt similarity index 100% rename from tests/src/main/java/com/github/klee0kai/test/di/base_forest/IdentityModule.kt rename to tests/src/commonMain/kotlin/com/github/klee0kai/test/di/base_forest/IdentityModule.kt diff --git a/tests/src/main/java/com/github/klee0kai/test/di/base_forest/UnitedBlueModule.kt b/tests/src/commonMain/kotlin/com/github/klee0kai/test/di/base_forest/UnitedBlueModule.kt similarity index 86% rename from tests/src/main/java/com/github/klee0kai/test/di/base_forest/UnitedBlueModule.kt rename to tests/src/commonMain/kotlin/com/github/klee0kai/test/di/base_forest/UnitedBlueModule.kt index 0335e267..dcc29a2e 100644 --- a/tests/src/main/java/com/github/klee0kai/test/di/base_forest/UnitedBlueModule.kt +++ b/tests/src/commonMain/kotlin/com/github/klee0kai/test/di/base_forest/UnitedBlueModule.kt @@ -3,12 +3,13 @@ package com.github.klee0kai.test.di.base_forest import com.github.klee0kai.stone.annotations.module.Module import com.github.klee0kai.stone.annotations.module.Provide import com.github.klee0kai.test.mowgli.body.Blood -import java.awt.Color @Module abstract class UnitedBlueModule : UnitedModule() { + @Provide(cache = Provide.CacheType.Strong) override fun blood(): Blood? { - return Blood(Color.BLUE) + return Blood(1) } + } diff --git a/tests/src/main/java/com/github/klee0kai/test/di/base_forest/UnitedModule.kt b/tests/src/commonMain/kotlin/com/github/klee0kai/test/di/base_forest/UnitedModule.kt similarity index 91% rename from tests/src/main/java/com/github/klee0kai/test/di/base_forest/UnitedModule.kt rename to tests/src/commonMain/kotlin/com/github/klee0kai/test/di/base_forest/UnitedModule.kt index 92c59090..21206cc7 100644 --- a/tests/src/main/java/com/github/klee0kai/test/di/base_forest/UnitedModule.kt +++ b/tests/src/commonMain/kotlin/com/github/klee0kai/test/di/base_forest/UnitedModule.kt @@ -5,14 +5,13 @@ import com.github.klee0kai.stone.annotations.module.Provide import com.github.klee0kai.test.mowgli.body.Blood import com.github.klee0kai.test.mowgli.community.History import com.github.klee0kai.test.mowgli.galaxy.Earth -import java.awt.Color @Module abstract class UnitedModule { @Provide(cache = Provide.CacheType.Strong) open fun blood(): Blood? { - return Blood(Color.RED) + return Blood(color = 2) } @Provide(cache = Provide.CacheType.Soft) diff --git a/tests/src/main/java/com/github/klee0kai/test/di/base_phone/PhoneComponent.kt b/tests/src/commonMain/kotlin/com/github/klee0kai/test/di/base_phone/PhoneComponent.kt similarity index 100% rename from tests/src/main/java/com/github/klee0kai/test/di/base_phone/PhoneComponent.kt rename to tests/src/commonMain/kotlin/com/github/klee0kai/test/di/base_phone/PhoneComponent.kt diff --git a/tests/src/main/java/com/github/klee0kai/test/di/base_phone/TechModule.kt b/tests/src/commonMain/kotlin/com/github/klee0kai/test/di/base_phone/TechModule.kt similarity index 96% rename from tests/src/main/java/com/github/klee0kai/test/di/base_phone/TechModule.kt rename to tests/src/commonMain/kotlin/com/github/klee0kai/test/di/base_phone/TechModule.kt index f5f2c7b3..91ba9178 100644 --- a/tests/src/main/java/com/github/klee0kai/test/di/base_phone/TechModule.kt +++ b/tests/src/commonMain/kotlin/com/github/klee0kai/test/di/base_phone/TechModule.kt @@ -2,6 +2,7 @@ package com.github.klee0kai.test.di.base_phone import com.github.klee0kai.stone.annotations.module.Module import com.github.klee0kai.stone.annotations.module.Provide +import com.github.klee0kai.stone.weakref.Named import com.github.klee0kai.test.di.base_phone.identifiers.DataStorageSize import com.github.klee0kai.test.di.base_phone.identifiers.PhoneOsType import com.github.klee0kai.test.di.base_phone.identifiers.PhoneOsVersion @@ -10,7 +11,6 @@ import com.github.klee0kai.test.tech.components.Battery import com.github.klee0kai.test.tech.components.DataStorage import com.github.klee0kai.test.tech.components.OperationSystem import com.github.klee0kai.test.tech.components.Ram -import javax.inject.Named @Module interface TechModule { diff --git a/tests/src/commonMain/kotlin/com/github/klee0kai/test/di/base_phone/identifiers/DataStorageSize.kt b/tests/src/commonMain/kotlin/com/github/klee0kai/test/di/base_phone/identifiers/DataStorageSize.kt new file mode 100644 index 00000000..91bdfee6 --- /dev/null +++ b/tests/src/commonMain/kotlin/com/github/klee0kai/test/di/base_phone/identifiers/DataStorageSize.kt @@ -0,0 +1,5 @@ +package com.github.klee0kai.test.di.base_phone.identifiers + +data class DataStorageSize( + var size: String? +) diff --git a/tests/src/main/java/com/github/klee0kai/test/di/base_phone/identifiers/PhoneOsType.kt b/tests/src/commonMain/kotlin/com/github/klee0kai/test/di/base_phone/identifiers/PhoneOsType.kt similarity index 100% rename from tests/src/main/java/com/github/klee0kai/test/di/base_phone/identifiers/PhoneOsType.kt rename to tests/src/commonMain/kotlin/com/github/klee0kai/test/di/base_phone/identifiers/PhoneOsType.kt diff --git a/tests/src/commonMain/kotlin/com/github/klee0kai/test/di/base_phone/identifiers/PhoneOsVersion.kt b/tests/src/commonMain/kotlin/com/github/klee0kai/test/di/base_phone/identifiers/PhoneOsVersion.kt new file mode 100644 index 00000000..4551260c --- /dev/null +++ b/tests/src/commonMain/kotlin/com/github/klee0kai/test/di/base_phone/identifiers/PhoneOsVersion.kt @@ -0,0 +1,5 @@ +package com.github.klee0kai.test.di.base_phone.identifiers + +data class PhoneOsVersion( + var version: String?, +) diff --git a/tests/src/commonMain/kotlin/com/github/klee0kai/test/di/base_phone/identifiers/RamSize.kt b/tests/src/commonMain/kotlin/com/github/klee0kai/test/di/base_phone/identifiers/RamSize.kt new file mode 100644 index 00000000..40499bf5 --- /dev/null +++ b/tests/src/commonMain/kotlin/com/github/klee0kai/test/di/base_phone/identifiers/RamSize.kt @@ -0,0 +1,5 @@ +package com.github.klee0kai.test.di.base_phone.identifiers + +data class RamSize( + var size: String?, +) diff --git a/tests/src/main/java/com/github/klee0kai/test/di/bindinstance/simple/GodWorkspaceComponent.kt b/tests/src/commonMain/kotlin/com/github/klee0kai/test/di/bindinstance/simple/GodWorkspaceComponent.kt similarity index 100% rename from tests/src/main/java/com/github/klee0kai/test/di/bindinstance/simple/GodWorkspaceComponent.kt rename to tests/src/commonMain/kotlin/com/github/klee0kai/test/di/bindinstance/simple/GodWorkspaceComponent.kt diff --git a/tests/src/main/java/com/github/klee0kai/test/di/bindinstance/simple/SunSystemModule.kt b/tests/src/commonMain/kotlin/com/github/klee0kai/test/di/bindinstance/simple/SunSystemModule.kt similarity index 100% rename from tests/src/main/java/com/github/klee0kai/test/di/bindinstance/simple/SunSystemModule.kt rename to tests/src/commonMain/kotlin/com/github/klee0kai/test/di/bindinstance/simple/SunSystemModule.kt diff --git a/tests/src/main/java/com/github/klee0kai/test/di/bindinstance/simple_inject/SevenPlanetComponent.kt b/tests/src/commonMain/kotlin/com/github/klee0kai/test/di/bindinstance/simple_inject/SevenPlanetComponent.kt similarity index 100% rename from tests/src/main/java/com/github/klee0kai/test/di/bindinstance/simple_inject/SevenPlanetComponent.kt rename to tests/src/commonMain/kotlin/com/github/klee0kai/test/di/bindinstance/simple_inject/SevenPlanetComponent.kt diff --git a/tests/src/main/java/com/github/klee0kai/test/di/bindinstance/simple_inject/SevenPlanetModule.kt b/tests/src/commonMain/kotlin/com/github/klee0kai/test/di/bindinstance/simple_inject/SevenPlanetModule.kt similarity index 100% rename from tests/src/main/java/com/github/klee0kai/test/di/bindinstance/simple_inject/SevenPlanetModule.kt rename to tests/src/commonMain/kotlin/com/github/klee0kai/test/di/bindinstance/simple_inject/SevenPlanetModule.kt diff --git a/tests/src/main/java/com/github/klee0kai/test/di/bindinstance/simple_inject/StarsModule.kt b/tests/src/commonMain/kotlin/com/github/klee0kai/test/di/bindinstance/simple_inject/StarsModule.kt similarity index 100% rename from tests/src/main/java/com/github/klee0kai/test/di/bindinstance/simple_inject/StarsModule.kt rename to tests/src/commonMain/kotlin/com/github/klee0kai/test/di/bindinstance/simple_inject/StarsModule.kt diff --git a/tests/src/main/java/com/github/klee0kai/test/di/bindinstance/singlemethod/PlanetComponent.kt b/tests/src/commonMain/kotlin/com/github/klee0kai/test/di/bindinstance/singlemethod/PlanetComponent.kt similarity index 100% rename from tests/src/main/java/com/github/klee0kai/test/di/bindinstance/singlemethod/PlanetComponent.kt rename to tests/src/commonMain/kotlin/com/github/klee0kai/test/di/bindinstance/singlemethod/PlanetComponent.kt diff --git a/tests/src/main/java/com/github/klee0kai/test/di/bindinstance/singlemethod/SunModule.kt b/tests/src/commonMain/kotlin/com/github/klee0kai/test/di/bindinstance/singlemethod/SunModule.kt similarity index 94% rename from tests/src/main/java/com/github/klee0kai/test/di/bindinstance/singlemethod/SunModule.kt rename to tests/src/commonMain/kotlin/com/github/klee0kai/test/di/bindinstance/singlemethod/SunModule.kt index 2698d7cd..c4dd0dd2 100644 --- a/tests/src/main/java/com/github/klee0kai/test/di/bindinstance/singlemethod/SunModule.kt +++ b/tests/src/commonMain/kotlin/com/github/klee0kai/test/di/bindinstance/singlemethod/SunModule.kt @@ -2,14 +2,15 @@ package com.github.klee0kai.test.di.bindinstance.singlemethod import com.github.klee0kai.stone.annotations.module.BindInstance import com.github.klee0kai.stone.annotations.module.Module +import com.github.klee0kai.stone.weakref.Named import com.github.klee0kai.test.di.gcforest.scopes.GcSunScope import com.github.klee0kai.test.mowgli.galaxy.IStar import com.github.klee0kai.test.mowgli.galaxy.Sun -import javax.inject.Named @Module interface SunModule { + @GcSunScope @Named("strong") @BindInstance(cache = BindInstance.CacheType.Strong) diff --git a/tests/src/main/java/com/github/klee0kai/test/di/bindinstance/singlemethod_gc/PlanetRollingComponent.kt b/tests/src/commonMain/kotlin/com/github/klee0kai/test/di/bindinstance/singlemethod_gc/PlanetRollingComponent.kt similarity index 100% rename from tests/src/main/java/com/github/klee0kai/test/di/bindinstance/singlemethod_gc/PlanetRollingComponent.kt rename to tests/src/commonMain/kotlin/com/github/klee0kai/test/di/bindinstance/singlemethod_gc/PlanetRollingComponent.kt diff --git a/tests/src/main/java/com/github/klee0kai/test/di/bindinstance/singlemethod_inject/StarSkyComponent.kt b/tests/src/commonMain/kotlin/com/github/klee0kai/test/di/bindinstance/singlemethod_inject/StarSkyComponent.kt similarity index 99% rename from tests/src/main/java/com/github/klee0kai/test/di/bindinstance/singlemethod_inject/StarSkyComponent.kt rename to tests/src/commonMain/kotlin/com/github/klee0kai/test/di/bindinstance/singlemethod_inject/StarSkyComponent.kt index 25d52345..ee91380d 100644 --- a/tests/src/main/java/com/github/klee0kai/test/di/bindinstance/singlemethod_inject/StarSkyComponent.kt +++ b/tests/src/commonMain/kotlin/com/github/klee0kai/test/di/bindinstance/singlemethod_inject/StarSkyComponent.kt @@ -31,4 +31,5 @@ interface StarSkyComponent { @ProtectInjected(timeMillis = 50) fun protectInjected(moonSky: MoonSky?) + } diff --git a/tests/src/main/java/com/github/klee0kai/test/di/bindinstance/singlemethod_inject/StarSkyModule.kt b/tests/src/commonMain/kotlin/com/github/klee0kai/test/di/bindinstance/singlemethod_inject/StarSkyModule.kt similarity index 100% rename from tests/src/main/java/com/github/klee0kai/test/di/bindinstance/singlemethod_inject/StarSkyModule.kt rename to tests/src/commonMain/kotlin/com/github/klee0kai/test/di/bindinstance/singlemethod_inject/StarSkyModule.kt diff --git a/tests/src/main/java/com/github/klee0kai/test/di/bindinstance/solarsystem/PlanetModule.kt b/tests/src/commonMain/kotlin/com/github/klee0kai/test/di/bindinstance/solarsystem/PlanetModule.kt similarity index 100% rename from tests/src/main/java/com/github/klee0kai/test/di/bindinstance/solarsystem/PlanetModule.kt rename to tests/src/commonMain/kotlin/com/github/klee0kai/test/di/bindinstance/solarsystem/PlanetModule.kt diff --git a/tests/src/main/java/com/github/klee0kai/test/di/bindinstance/solarsystem/SolarSystemComponent.kt b/tests/src/commonMain/kotlin/com/github/klee0kai/test/di/bindinstance/solarsystem/SolarSystemComponent.kt similarity index 100% rename from tests/src/main/java/com/github/klee0kai/test/di/bindinstance/solarsystem/SolarSystemComponent.kt rename to tests/src/commonMain/kotlin/com/github/klee0kai/test/di/bindinstance/solarsystem/SolarSystemComponent.kt index a65abba1..113d3f45 100644 --- a/tests/src/main/java/com/github/klee0kai/test/di/bindinstance/solarsystem/SolarSystemComponent.kt +++ b/tests/src/commonMain/kotlin/com/github/klee0kai/test/di/bindinstance/solarsystem/SolarSystemComponent.kt @@ -6,8 +6,8 @@ import com.github.klee0kai.test.mowgli.galaxy.SolarSystem @Component interface SolarSystemComponent : SolarSystemDependencies { - fun planets(): PlanetModule? + fun planets(): PlanetModule? @BindInstance fun bind(system: SolarSystem?): SolarSystem? diff --git a/tests/src/main/java/com/github/klee0kai/test/di/bindinstance/solarsystem/SolarSystemDependencies.kt b/tests/src/commonMain/kotlin/com/github/klee0kai/test/di/bindinstance/solarsystem/SolarSystemDependencies.kt similarity index 100% rename from tests/src/main/java/com/github/klee0kai/test/di/bindinstance/solarsystem/SolarSystemDependencies.kt rename to tests/src/commonMain/kotlin/com/github/klee0kai/test/di/bindinstance/solarsystem/SolarSystemDependencies.kt diff --git a/tests/src/main/java/com/github/klee0kai/test/di/earthmirror/EarthComponent.kt b/tests/src/commonMain/kotlin/com/github/klee0kai/test/di/earthmirror/EarthComponent.kt similarity index 100% rename from tests/src/main/java/com/github/klee0kai/test/di/earthmirror/EarthComponent.kt rename to tests/src/commonMain/kotlin/com/github/klee0kai/test/di/earthmirror/EarthComponent.kt diff --git a/tests/src/main/java/com/github/klee0kai/test/di/earthmirror/EastModule.kt b/tests/src/commonMain/kotlin/com/github/klee0kai/test/di/earthmirror/EastModule.kt similarity index 100% rename from tests/src/main/java/com/github/klee0kai/test/di/earthmirror/EastModule.kt rename to tests/src/commonMain/kotlin/com/github/klee0kai/test/di/earthmirror/EastModule.kt diff --git a/tests/src/main/java/com/github/klee0kai/test/di/earthmirror/WestModule.kt b/tests/src/commonMain/kotlin/com/github/klee0kai/test/di/earthmirror/WestModule.kt similarity index 100% rename from tests/src/main/java/com/github/klee0kai/test/di/earthmirror/WestModule.kt rename to tests/src/commonMain/kotlin/com/github/klee0kai/test/di/earthmirror/WestModule.kt diff --git a/tests/src/main/java/com/github/klee0kai/test/di/gcforest/GcEarthComponent.kt b/tests/src/commonMain/kotlin/com/github/klee0kai/test/di/gcforest/GcEarthComponent.kt similarity index 100% rename from tests/src/main/java/com/github/klee0kai/test/di/gcforest/GcEarthComponent.kt rename to tests/src/commonMain/kotlin/com/github/klee0kai/test/di/gcforest/GcEarthComponent.kt diff --git a/tests/src/main/java/com/github/klee0kai/test/di/gcforest/GcEarthModule.kt b/tests/src/commonMain/kotlin/com/github/klee0kai/test/di/gcforest/GcEarthModule.kt similarity index 100% rename from tests/src/main/java/com/github/klee0kai/test/di/gcforest/GcEarthModule.kt rename to tests/src/commonMain/kotlin/com/github/klee0kai/test/di/gcforest/GcEarthModule.kt diff --git a/tests/src/main/java/com/github/klee0kai/test/di/gcforest/GcGodComponent.kt b/tests/src/commonMain/kotlin/com/github/klee0kai/test/di/gcforest/GcGodComponent.kt similarity index 100% rename from tests/src/main/java/com/github/klee0kai/test/di/gcforest/GcGodComponent.kt rename to tests/src/commonMain/kotlin/com/github/klee0kai/test/di/gcforest/GcGodComponent.kt diff --git a/tests/src/main/java/com/github/klee0kai/test/di/gcforest/GcSunSystemModule.kt b/tests/src/commonMain/kotlin/com/github/klee0kai/test/di/gcforest/GcSunSystemModule.kt similarity index 100% rename from tests/src/main/java/com/github/klee0kai/test/di/gcforest/GcSunSystemModule.kt rename to tests/src/commonMain/kotlin/com/github/klee0kai/test/di/gcforest/GcSunSystemModule.kt diff --git a/tests/src/main/java/com/github/klee0kai/test/di/gcforest/scopes/GcMountainScope.kt b/tests/src/commonMain/kotlin/com/github/klee0kai/test/di/gcforest/scopes/GcMountainScope.kt similarity index 100% rename from tests/src/main/java/com/github/klee0kai/test/di/gcforest/scopes/GcMountainScope.kt rename to tests/src/commonMain/kotlin/com/github/klee0kai/test/di/gcforest/scopes/GcMountainScope.kt diff --git a/tests/src/main/java/com/github/klee0kai/test/di/gcforest/scopes/GcPlanetScope.kt b/tests/src/commonMain/kotlin/com/github/klee0kai/test/di/gcforest/scopes/GcPlanetScope.kt similarity index 100% rename from tests/src/main/java/com/github/klee0kai/test/di/gcforest/scopes/GcPlanetScope.kt rename to tests/src/commonMain/kotlin/com/github/klee0kai/test/di/gcforest/scopes/GcPlanetScope.kt diff --git a/tests/src/main/java/com/github/klee0kai/test/di/gcforest/scopes/GcRiverScope.kt b/tests/src/commonMain/kotlin/com/github/klee0kai/test/di/gcforest/scopes/GcRiverScope.kt similarity index 83% rename from tests/src/main/java/com/github/klee0kai/test/di/gcforest/scopes/GcRiverScope.kt rename to tests/src/commonMain/kotlin/com/github/klee0kai/test/di/gcforest/scopes/GcRiverScope.kt index ff6c5c85..cb30651a 100644 --- a/tests/src/main/java/com/github/klee0kai/test/di/gcforest/scopes/GcRiverScope.kt +++ b/tests/src/commonMain/kotlin/com/github/klee0kai/test/di/gcforest/scopes/GcRiverScope.kt @@ -1,6 +1,6 @@ package com.github.klee0kai.test.di.gcforest.scopes -import javax.inject.Scope +import com.github.klee0kai.stone.weakref.Scope @Scope @Retention(AnnotationRetention.RUNTIME) diff --git a/tests/src/main/java/com/github/klee0kai/test/di/gcforest/scopes/GcSunScope.kt b/tests/src/commonMain/kotlin/com/github/klee0kai/test/di/gcforest/scopes/GcSunScope.kt similarity index 83% rename from tests/src/main/java/com/github/klee0kai/test/di/gcforest/scopes/GcSunScope.kt rename to tests/src/commonMain/kotlin/com/github/klee0kai/test/di/gcforest/scopes/GcSunScope.kt index 80b7c97f..1e66a762 100644 --- a/tests/src/main/java/com/github/klee0kai/test/di/gcforest/scopes/GcSunScope.kt +++ b/tests/src/commonMain/kotlin/com/github/klee0kai/test/di/gcforest/scopes/GcSunScope.kt @@ -1,6 +1,6 @@ package com.github.klee0kai.test.di.gcforest.scopes -import javax.inject.Scope +import com.github.klee0kai.stone.weakref.Scope @Scope @Retention(AnnotationRetention.RUNTIME) diff --git a/tests/src/main/java/com/github/klee0kai/test/di/house/nulls/HouseNullsComponent.kt b/tests/src/commonMain/kotlin/com/github/klee0kai/test/di/house/nulls/HouseNullsComponent.kt similarity index 100% rename from tests/src/main/java/com/github/klee0kai/test/di/house/nulls/HouseNullsComponent.kt rename to tests/src/commonMain/kotlin/com/github/klee0kai/test/di/house/nulls/HouseNullsComponent.kt diff --git a/tests/src/main/java/com/github/klee0kai/test/di/house/nulls/HouseNullsModule.kt b/tests/src/commonMain/kotlin/com/github/klee0kai/test/di/house/nulls/HouseNullsModule.kt similarity index 100% rename from tests/src/main/java/com/github/klee0kai/test/di/house/nulls/HouseNullsModule.kt rename to tests/src/commonMain/kotlin/com/github/klee0kai/test/di/house/nulls/HouseNullsModule.kt diff --git a/tests/src/main/java/com/github/klee0kai/test/di/house/simple/AreasModule.kt b/tests/src/commonMain/kotlin/com/github/klee0kai/test/di/house/simple/AreasModule.kt similarity index 100% rename from tests/src/main/java/com/github/klee0kai/test/di/house/simple/AreasModule.kt rename to tests/src/commonMain/kotlin/com/github/klee0kai/test/di/house/simple/AreasModule.kt diff --git a/tests/src/main/java/com/github/klee0kai/test/di/house/simple/HouseComponent.kt b/tests/src/commonMain/kotlin/com/github/klee0kai/test/di/house/simple/HouseComponent.kt similarity index 100% rename from tests/src/main/java/com/github/klee0kai/test/di/house/simple/HouseComponent.kt rename to tests/src/commonMain/kotlin/com/github/klee0kai/test/di/house/simple/HouseComponent.kt diff --git a/tests/src/main/java/com/github/klee0kai/test/di/house/simple/HouseModule.kt b/tests/src/commonMain/kotlin/com/github/klee0kai/test/di/house/simple/HouseModule.kt similarity index 100% rename from tests/src/main/java/com/github/klee0kai/test/di/house/simple/HouseModule.kt rename to tests/src/commonMain/kotlin/com/github/klee0kai/test/di/house/simple/HouseModule.kt diff --git a/tests/src/main/java/com/github/klee0kai/test/di/house/simple/RoomsModule.kt b/tests/src/commonMain/kotlin/com/github/klee0kai/test/di/house/simple/RoomsModule.kt similarity index 100% rename from tests/src/main/java/com/github/klee0kai/test/di/house/simple/RoomsModule.kt rename to tests/src/commonMain/kotlin/com/github/klee0kai/test/di/house/simple/RoomsModule.kt diff --git a/tests/src/main/java/com/github/klee0kai/test/di/house/simple/ToolsModule.kt b/tests/src/commonMain/kotlin/com/github/klee0kai/test/di/house/simple/ToolsModule.kt similarity index 100% rename from tests/src/main/java/com/github/klee0kai/test/di/house/simple/ToolsModule.kt rename to tests/src/commonMain/kotlin/com/github/klee0kai/test/di/house/simple/ToolsModule.kt diff --git a/tests/src/main/java/com/github/klee0kai/test/di/swcache/SwitchCacheComponent.kt b/tests/src/commonMain/kotlin/com/github/klee0kai/test/di/swcache/SwitchCacheComponent.kt similarity index 100% rename from tests/src/main/java/com/github/klee0kai/test/di/swcache/SwitchCacheComponent.kt rename to tests/src/commonMain/kotlin/com/github/klee0kai/test/di/swcache/SwitchCacheComponent.kt diff --git a/tests/src/main/java/com/github/klee0kai/test/di/techfactory/ITechProviderComponent.kt b/tests/src/commonMain/kotlin/com/github/klee0kai/test/di/techfactory/ITechProviderComponent.kt similarity index 80% rename from tests/src/main/java/com/github/klee0kai/test/di/techfactory/ITechProviderComponent.kt rename to tests/src/commonMain/kotlin/com/github/klee0kai/test/di/techfactory/ITechProviderComponent.kt index 5140859c..1c07f96a 100644 --- a/tests/src/main/java/com/github/klee0kai/test/di/techfactory/ITechProviderComponent.kt +++ b/tests/src/commonMain/kotlin/com/github/klee0kai/test/di/techfactory/ITechProviderComponent.kt @@ -1,6 +1,6 @@ package com.github.klee0kai.test.di.techfactory -import com.github.klee0kai.stone.weakref.Ref +import com.github.klee0kai.stone.weakref.* import com.github.klee0kai.stone.wrappers.LazyProvide import com.github.klee0kai.stone.wrappers.PhantomProvide import com.github.klee0kai.test.di.base_phone.identifiers.PhoneOsType @@ -9,12 +9,9 @@ import com.github.klee0kai.test.di.base_phone.identifiers.RamSize import com.github.klee0kai.test.tech.components.Battery import com.github.klee0kai.test.tech.components.OperationSystem import com.github.klee0kai.test.tech.components.Ram -import java.lang.ref.SoftReference -import java.lang.ref.WeakReference -import javax.inject.Named -import javax.inject.Provider interface ITechProviderComponent { + fun batteryLazy(): LazyProvide? fun batteryProviderIRef(): Ref? @@ -23,9 +20,9 @@ interface ITechProviderComponent { fun batteryProvider(): Provider? - fun batterySoft(): SoftReference? + fun batterySoft(): SoftRef? - fun batteryWeak(): WeakReference? + fun batteryWeak(): WeakRef? @Named("null_args") fun ram(): Ram? diff --git a/tests/src/main/java/com/github/klee0kai/test/di/techfactory/TechFactoryComponent.kt b/tests/src/commonMain/kotlin/com/github/klee0kai/test/di/techfactory/TechFactoryComponent.kt similarity index 100% rename from tests/src/main/java/com/github/klee0kai/test/di/techfactory/TechFactoryComponent.kt rename to tests/src/commonMain/kotlin/com/github/klee0kai/test/di/techfactory/TechFactoryComponent.kt diff --git a/tests/src/main/java/com/github/klee0kai/test/di/techfactory/TechFactoryModule.kt b/tests/src/commonMain/kotlin/com/github/klee0kai/test/di/techfactory/TechFactoryModule.kt similarity index 96% rename from tests/src/main/java/com/github/klee0kai/test/di/techfactory/TechFactoryModule.kt rename to tests/src/commonMain/kotlin/com/github/klee0kai/test/di/techfactory/TechFactoryModule.kt index 14e0c428..544d00c0 100644 --- a/tests/src/main/java/com/github/klee0kai/test/di/techfactory/TechFactoryModule.kt +++ b/tests/src/commonMain/kotlin/com/github/klee0kai/test/di/techfactory/TechFactoryModule.kt @@ -2,6 +2,7 @@ package com.github.klee0kai.test.di.techfactory import com.github.klee0kai.stone.annotations.module.Module import com.github.klee0kai.stone.annotations.module.Provide +import com.github.klee0kai.stone.weakref.Named import com.github.klee0kai.test.di.base_phone.identifiers.DataStorageSize import com.github.klee0kai.test.di.base_phone.identifiers.PhoneOsType import com.github.klee0kai.test.di.base_phone.identifiers.PhoneOsVersion @@ -10,7 +11,6 @@ import com.github.klee0kai.test.tech.components.Battery import com.github.klee0kai.test.tech.components.DataStorage import com.github.klee0kai.test.tech.components.OperationSystem import com.github.klee0kai.test.tech.components.Ram -import javax.inject.Named @Module interface TechFactoryModule { diff --git a/tests/src/main/java/com/github/klee0kai/test/di/wire/WireComponent.kt b/tests/src/commonMain/kotlin/com/github/klee0kai/test/di/wire/WireComponent.kt similarity index 85% rename from tests/src/main/java/com/github/klee0kai/test/di/wire/WireComponent.kt rename to tests/src/commonMain/kotlin/com/github/klee0kai/test/di/wire/WireComponent.kt index 868a81d9..73fd8afc 100644 --- a/tests/src/main/java/com/github/klee0kai/test/di/wire/WireComponent.kt +++ b/tests/src/commonMain/kotlin/com/github/klee0kai/test/di/wire/WireComponent.kt @@ -2,22 +2,24 @@ package com.github.klee0kai.test.di.wire import com.github.klee0kai.stone.annotations.component.Component import com.github.klee0kai.stone.annotations.module.BindInstance +import com.github.klee0kai.stone.weakref.WeakRef import com.github.klee0kai.test.wire.Wire import com.github.klee0kai.test.wire.types.Hdmi import com.github.klee0kai.test.wire.types.MiniUsb import com.github.klee0kai.test.wire.types.Usb -import java.lang.ref.WeakReference @Component abstract class WireComponent { + abstract fun module(): WireModule? abstract fun usb_hdmi(): Wire? - abstract fun usb_usb(): WeakReference?>? + abstract fun usb_usb(): WeakRef?>? abstract fun simple(): Wire<*, *>? @BindInstance abstract fun miniusb_miniusb(wire: Wire?): Wire? + } diff --git a/tests/src/main/java/com/github/klee0kai/test/di/wire/WireModule.kt b/tests/src/commonMain/kotlin/com/github/klee0kai/test/di/wire/WireModule.kt similarity index 99% rename from tests/src/main/java/com/github/klee0kai/test/di/wire/WireModule.kt rename to tests/src/commonMain/kotlin/com/github/klee0kai/test/di/wire/WireModule.kt index e605dced..60ea3b48 100644 --- a/tests/src/main/java/com/github/klee0kai/test/di/wire/WireModule.kt +++ b/tests/src/commonMain/kotlin/com/github/klee0kai/test/di/wire/WireModule.kt @@ -9,6 +9,7 @@ import com.github.klee0kai.test.wire.types.Usb @Module abstract class WireModule { + @Provide(cache = Provide.CacheType.Soft) abstract fun usb_miniusb(): Wire? @@ -24,4 +25,5 @@ abstract class WireModule { open fun simple(): Wire<*, *>? { return Wire() } + } diff --git a/tests/src/commonMain/kotlin/com/github/klee0kai/test/house/House.kt b/tests/src/commonMain/kotlin/com/github/klee0kai/test/house/House.kt new file mode 100644 index 00000000..7b99ec78 --- /dev/null +++ b/tests/src/commonMain/kotlin/com/github/klee0kai/test/house/House.kt @@ -0,0 +1,21 @@ +@file:OptIn(ExperimentalUuidApi::class) + +package com.github.klee0kai.test.house + +import com.github.klee0kai.test.house.kitchen.Kichen +import com.github.klee0kai.test.house.rooms.BathRoom +import com.github.klee0kai.test.house.rooms.BedRoom +import com.github.klee0kai.test.house.rooms.Garage +import kotlin.uuid.ExperimentalUuidApi +import kotlin.uuid.Uuid + +class House( + val kichen: Kichen?, + val bathRoom: BathRoom?, + val bedRoom: BedRoom?, + val garage: Garage?, +) { + + var uuid: String = Uuid.random().toString() + +} diff --git a/tests/src/main/java/com/github/klee0kai/test/house/InHouse.kt b/tests/src/commonMain/kotlin/com/github/klee0kai/test/house/InHouse.kt similarity index 84% rename from tests/src/main/java/com/github/klee0kai/test/house/InHouse.kt rename to tests/src/commonMain/kotlin/com/github/klee0kai/test/house/InHouse.kt index a204117f..13c9ea1f 100644 --- a/tests/src/main/java/com/github/klee0kai/test/house/InHouse.kt +++ b/tests/src/commonMain/kotlin/com/github/klee0kai/test/house/InHouse.kt @@ -1,29 +1,25 @@ package com.github.klee0kai.test.house +import com.github.klee0kai.stone.weakref.Inject import com.github.klee0kai.test.house.kitchen.Kichen import com.github.klee0kai.test.house.kitchen.storagearea.StoreArea import com.github.klee0kai.test.house.rooms.BathRoom import com.github.klee0kai.test.house.rooms.Garage -import javax.inject.Inject class InHouse { - @JvmField + @Inject var kichen: Kichen? = null - @JvmField @Inject var bathRoom: BathRoom? = null - @JvmField @Inject var bedRoom: BathRoom? = null - @JvmField @Inject var garage: Garage? = null - @JvmField @Inject var bedStoreArea: StoreArea? = null } diff --git a/tests/src/main/java/com/github/klee0kai/test/house/identifiers/StoreAreaType.kt b/tests/src/commonMain/kotlin/com/github/klee0kai/test/house/identifiers/StoreAreaType.kt similarity index 100% rename from tests/src/main/java/com/github/klee0kai/test/house/identifiers/StoreAreaType.kt rename to tests/src/commonMain/kotlin/com/github/klee0kai/test/house/identifiers/StoreAreaType.kt diff --git a/tests/src/main/java/com/github/klee0kai/test/house/kitchen/Kichen.kt b/tests/src/commonMain/kotlin/com/github/klee0kai/test/house/kitchen/Kichen.kt similarity index 52% rename from tests/src/main/java/com/github/klee0kai/test/house/kitchen/Kichen.kt rename to tests/src/commonMain/kotlin/com/github/klee0kai/test/house/kitchen/Kichen.kt index 3543604a..7231f126 100644 --- a/tests/src/main/java/com/github/klee0kai/test/house/kitchen/Kichen.kt +++ b/tests/src/commonMain/kotlin/com/github/klee0kai/test/house/kitchen/Kichen.kt @@ -1,15 +1,17 @@ +@file:OptIn(ExperimentalUuidApi::class) + package com.github.klee0kai.test.house.kitchen import com.github.klee0kai.test.house.kitchen.cookingarea.CookingArea import com.github.klee0kai.test.house.kitchen.sinkarea.SinkArea import com.github.klee0kai.test.house.kitchen.storagearea.StoreArea -import java.util.* +import kotlin.uuid.ExperimentalUuidApi +import kotlin.uuid.Uuid class Kichen( - @JvmField val cookingArea: CookingArea?, - @JvmField val sinkArea: SinkArea?, - @JvmField val storeArea: StoreArea? + val cookingArea: CookingArea?, + val sinkArea: SinkArea?, + val storeArea: StoreArea? ) { - @JvmField - var uuid: UUID = UUID.randomUUID() + var uuid: String = Uuid.random().toString() } diff --git a/tests/src/commonMain/kotlin/com/github/klee0kai/test/house/kitchen/cookingarea/CookingArea.kt b/tests/src/commonMain/kotlin/com/github/klee0kai/test/house/kitchen/cookingarea/CookingArea.kt new file mode 100644 index 00000000..46427868 --- /dev/null +++ b/tests/src/commonMain/kotlin/com/github/klee0kai/test/house/kitchen/cookingarea/CookingArea.kt @@ -0,0 +1,10 @@ +@file:OptIn(ExperimentalUuidApi::class) + +package com.github.klee0kai.test.house.kitchen.cookingarea + +import kotlin.uuid.ExperimentalUuidApi +import kotlin.uuid.Uuid + +class CookingArea { + var uuid: String = Uuid.random().toString() +} diff --git a/tests/src/commonMain/kotlin/com/github/klee0kai/test/house/kitchen/sinkarea/SinkArea.kt b/tests/src/commonMain/kotlin/com/github/klee0kai/test/house/kitchen/sinkarea/SinkArea.kt new file mode 100644 index 00000000..f61ae98f --- /dev/null +++ b/tests/src/commonMain/kotlin/com/github/klee0kai/test/house/kitchen/sinkarea/SinkArea.kt @@ -0,0 +1,10 @@ +@file:OptIn(ExperimentalUuidApi::class) + +package com.github.klee0kai.test.house.kitchen.sinkarea + +import kotlin.uuid.ExperimentalUuidApi +import kotlin.uuid.Uuid + +class SinkArea { + var uuid: String = Uuid.random().toString() +} diff --git a/tests/src/commonMain/kotlin/com/github/klee0kai/test/house/kitchen/storagearea/Clothes.kt b/tests/src/commonMain/kotlin/com/github/klee0kai/test/house/kitchen/storagearea/Clothes.kt new file mode 100644 index 00000000..8b5e307c --- /dev/null +++ b/tests/src/commonMain/kotlin/com/github/klee0kai/test/house/kitchen/storagearea/Clothes.kt @@ -0,0 +1,10 @@ +@file:OptIn(ExperimentalUuidApi::class) + +package com.github.klee0kai.test.house.kitchen.storagearea + +import kotlin.uuid.ExperimentalUuidApi +import kotlin.uuid.Uuid + +class Clothes { + var uuid: String = Uuid.random().toString() +} diff --git a/tests/src/commonMain/kotlin/com/github/klee0kai/test/house/kitchen/storagearea/Cookware.kt b/tests/src/commonMain/kotlin/com/github/klee0kai/test/house/kitchen/storagearea/Cookware.kt new file mode 100644 index 00000000..80fc2820 --- /dev/null +++ b/tests/src/commonMain/kotlin/com/github/klee0kai/test/house/kitchen/storagearea/Cookware.kt @@ -0,0 +1,10 @@ +@file:OptIn(ExperimentalUuidApi::class) + +package com.github.klee0kai.test.house.kitchen.storagearea + +import kotlin.uuid.ExperimentalUuidApi +import kotlin.uuid.Uuid + +class Cookware { + var uuid: String = Uuid.random().toString() +} diff --git a/tests/src/commonMain/kotlin/com/github/klee0kai/test/house/kitchen/storagearea/GarageStore.kt b/tests/src/commonMain/kotlin/com/github/klee0kai/test/house/kitchen/storagearea/GarageStore.kt new file mode 100644 index 00000000..d53900eb --- /dev/null +++ b/tests/src/commonMain/kotlin/com/github/klee0kai/test/house/kitchen/storagearea/GarageStore.kt @@ -0,0 +1,7 @@ +package com.github.klee0kai.test.house.kitchen.storagearea + +data class GarageStore( + val cookware: Cookware?, + val clothes: Clothes?, + val sanitizers: Sanitizers?, +) diff --git a/tests/src/main/java/com/github/klee0kai/test/house/kitchen/storagearea/Sanitizers.kt b/tests/src/commonMain/kotlin/com/github/klee0kai/test/house/kitchen/storagearea/Sanitizers.kt similarity index 54% rename from tests/src/main/java/com/github/klee0kai/test/house/kitchen/storagearea/Sanitizers.kt rename to tests/src/commonMain/kotlin/com/github/klee0kai/test/house/kitchen/storagearea/Sanitizers.kt index 781e353e..8c2d2800 100644 --- a/tests/src/main/java/com/github/klee0kai/test/house/kitchen/storagearea/Sanitizers.kt +++ b/tests/src/commonMain/kotlin/com/github/klee0kai/test/house/kitchen/storagearea/Sanitizers.kt @@ -1,10 +1,13 @@ +@file:OptIn(ExperimentalUuidApi::class) + package com.github.klee0kai.test.house.kitchen.storagearea -import java.util.* +import kotlin.uuid.ExperimentalUuidApi +import kotlin.uuid.Uuid class Sanitizers { - @JvmField - var uuid: UUID = UUID.randomUUID() + + var uuid: String = Uuid.random().toString() init { createCount++ diff --git a/tests/src/commonMain/kotlin/com/github/klee0kai/test/house/kitchen/storagearea/StoreArea.kt b/tests/src/commonMain/kotlin/com/github/klee0kai/test/house/kitchen/storagearea/StoreArea.kt new file mode 100644 index 00000000..f7f64f61 --- /dev/null +++ b/tests/src/commonMain/kotlin/com/github/klee0kai/test/house/kitchen/storagearea/StoreArea.kt @@ -0,0 +1,10 @@ +package com.github.klee0kai.test.house.kitchen.storagearea + +import com.github.klee0kai.test.house.identifiers.StoreAreaType + +class StoreArea( + val type: StoreAreaType?, + val cookware: Cookware?, + val clothes: Clothes?, + val sanitizers: Sanitizers?, +) diff --git a/tests/src/commonMain/kotlin/com/github/klee0kai/test/house/rooms/BathRoom.kt b/tests/src/commonMain/kotlin/com/github/klee0kai/test/house/rooms/BathRoom.kt new file mode 100644 index 00000000..27df93a9 --- /dev/null +++ b/tests/src/commonMain/kotlin/com/github/klee0kai/test/house/rooms/BathRoom.kt @@ -0,0 +1,11 @@ +@file:OptIn(ExperimentalUuidApi::class) + +package com.github.klee0kai.test.house.rooms + +import com.github.klee0kai.test.house.kitchen.storagearea.StoreArea +import kotlin.uuid.ExperimentalUuidApi +import kotlin.uuid.Uuid + +class BathRoom(val storeArea: StoreArea?) { + var uuid: String = Uuid.random().toString() +} diff --git a/tests/src/commonMain/kotlin/com/github/klee0kai/test/house/rooms/BedRoom.kt b/tests/src/commonMain/kotlin/com/github/klee0kai/test/house/rooms/BedRoom.kt new file mode 100644 index 00000000..8e104893 --- /dev/null +++ b/tests/src/commonMain/kotlin/com/github/klee0kai/test/house/rooms/BedRoom.kt @@ -0,0 +1,11 @@ +@file:OptIn(ExperimentalUuidApi::class) + +package com.github.klee0kai.test.house.rooms + +import com.github.klee0kai.test.house.kitchen.storagearea.StoreArea +import kotlin.uuid.ExperimentalUuidApi +import kotlin.uuid.Uuid + +class BedRoom(val storeArea: StoreArea?) { + var uuid: String = Uuid.random().toString() +} diff --git a/tests/src/main/java/com/github/klee0kai/test/house/rooms/Garage.kt b/tests/src/commonMain/kotlin/com/github/klee0kai/test/house/rooms/Garage.kt similarity index 52% rename from tests/src/main/java/com/github/klee0kai/test/house/rooms/Garage.kt rename to tests/src/commonMain/kotlin/com/github/klee0kai/test/house/rooms/Garage.kt index c85ee05c..1c301199 100644 --- a/tests/src/main/java/com/github/klee0kai/test/house/rooms/Garage.kt +++ b/tests/src/commonMain/kotlin/com/github/klee0kai/test/house/rooms/Garage.kt @@ -1,8 +1,11 @@ +@file:OptIn(ExperimentalUuidApi::class) + package com.github.klee0kai.test.house.rooms import com.github.klee0kai.test.house.kitchen.storagearea.GarageStore -import java.util.* +import kotlin.uuid.ExperimentalUuidApi +import kotlin.uuid.Uuid class Garage(val garageStore: GarageStore?) { - var uuid: UUID = UUID.randomUUID() + var uuid: String = Uuid.random().toString() } diff --git a/tests/src/main/java/com/github/klee0kai/test/mowgli/MoonSky.kt b/tests/src/commonMain/kotlin/com/github/klee0kai/test/mowgli/MoonSky.kt similarity index 83% rename from tests/src/main/java/com/github/klee0kai/test/mowgli/MoonSky.kt rename to tests/src/commonMain/kotlin/com/github/klee0kai/test/mowgli/MoonSky.kt index 06ba8815..19efda6c 100644 --- a/tests/src/main/java/com/github/klee0kai/test/mowgli/MoonSky.kt +++ b/tests/src/commonMain/kotlin/com/github/klee0kai/test/mowgli/MoonSky.kt @@ -1,7 +1,8 @@ package com.github.klee0kai.test.mowgli +import com.github.klee0kai.stone.weakref.Inject import com.github.klee0kai.test.mowgli.galaxy.* -import javax.inject.Inject +import kotlin.jvm.JvmField class MoonSky { diff --git a/tests/src/main/java/com/github/klee0kai/test/mowgli/School.kt b/tests/src/commonMain/kotlin/com/github/klee0kai/test/mowgli/School.kt similarity index 84% rename from tests/src/main/java/com/github/klee0kai/test/mowgli/School.kt rename to tests/src/commonMain/kotlin/com/github/klee0kai/test/mowgli/School.kt index 2bfbfa97..419e2374 100644 --- a/tests/src/main/java/com/github/klee0kai/test/mowgli/School.kt +++ b/tests/src/commonMain/kotlin/com/github/klee0kai/test/mowgli/School.kt @@ -1,14 +1,16 @@ package com.github.klee0kai.test.mowgli +import com.github.klee0kai.stone.weakref.Inject +import com.github.klee0kai.stone.weakref.Provider import com.github.klee0kai.stone.weakref.Ref import com.github.klee0kai.stone.wrappers.LazyProvide import com.github.klee0kai.stone.wrappers.PhantomProvide import com.github.klee0kai.test.mowgli.community.History import com.github.klee0kai.test.mowgli.identity.Knowledge -import javax.inject.Inject -import javax.inject.Provider +import kotlin.jvm.JvmField class School { + @JvmField @Inject var historyLazyProvide: LazyProvide? = null @@ -24,4 +26,5 @@ class School { @JvmField @Inject var knowledgePhantomProvide: PhantomProvide? = null + } diff --git a/tests/src/main/java/com/github/klee0kai/test/mowgli/animal/Horse.kt b/tests/src/commonMain/kotlin/com/github/klee0kai/test/mowgli/animal/Horse.kt similarity index 88% rename from tests/src/main/java/com/github/klee0kai/test/mowgli/animal/Horse.kt rename to tests/src/commonMain/kotlin/com/github/klee0kai/test/mowgli/animal/Horse.kt index 8caf41f6..4ffbe5f4 100644 --- a/tests/src/main/java/com/github/klee0kai/test/mowgli/animal/Horse.kt +++ b/tests/src/commonMain/kotlin/com/github/klee0kai/test/mowgli/animal/Horse.kt @@ -1,42 +1,35 @@ package com.github.klee0kai.test.mowgli.animal +import com.github.klee0kai.stone.weakref.Inject import com.github.klee0kai.test.mowgli.body.Blood import com.github.klee0kai.test.mowgli.community.History import com.github.klee0kai.test.mowgli.galaxy.Earth import com.github.klee0kai.test.mowgli.identity.Conscience import com.github.klee0kai.test.mowgli.identity.Ideology import com.github.klee0kai.test.mowgli.identity.Knowledge -import javax.inject.Inject open class Horse : IAnimal { - @JvmField + @Inject var blood: Blood? = null - @JvmField @Inject var earth: Earth? = null - @JvmField @Inject var history: History? = null - @JvmField @Inject var conscience: Conscience? = null - @JvmField @Inject var knowledge: Knowledge? = null @Inject open var ideology: Ideology? = null - - @JvmField var methodInjectedConscience: Conscience? = null - @JvmField var methodInjectedKnowledge: Knowledge? = null @Inject diff --git a/tests/src/main/java/com/github/klee0kai/test/mowgli/animal/IAnimal.kt b/tests/src/commonMain/kotlin/com/github/klee0kai/test/mowgli/animal/IAnimal.kt similarity index 100% rename from tests/src/main/java/com/github/klee0kai/test/mowgli/animal/IAnimal.kt rename to tests/src/commonMain/kotlin/com/github/klee0kai/test/mowgli/animal/IAnimal.kt diff --git a/tests/src/main/java/com/github/klee0kai/test/mowgli/animal/Mowgli.kt b/tests/src/commonMain/kotlin/com/github/klee0kai/test/mowgli/animal/Mowgli.kt similarity index 79% rename from tests/src/main/java/com/github/klee0kai/test/mowgli/animal/Mowgli.kt rename to tests/src/commonMain/kotlin/com/github/klee0kai/test/mowgli/animal/Mowgli.kt index f8577fb0..187088ab 100644 --- a/tests/src/main/java/com/github/klee0kai/test/mowgli/animal/Mowgli.kt +++ b/tests/src/commonMain/kotlin/com/github/klee0kai/test/mowgli/animal/Mowgli.kt @@ -1,6 +1,6 @@ package com.github.klee0kai.test.mowgli.animal -import com.github.klee0kai.stone.weakref.Ref +import com.github.klee0kai.stone.weakref.* import com.github.klee0kai.stone.wrappers.LazyProvide import com.github.klee0kai.stone.wrappers.PhantomProvide import com.github.klee0kai.test.mowgli.body.Blood @@ -8,10 +8,7 @@ import com.github.klee0kai.test.mowgli.community.History import com.github.klee0kai.test.mowgli.galaxy.Earth import com.github.klee0kai.test.mowgli.identity.Conscience import com.github.klee0kai.test.mowgli.identity.Knowledge -import java.lang.ref.SoftReference -import java.lang.ref.WeakReference -import javax.inject.Inject -import javax.inject.Provider +import kotlin.jvm.JvmField class Mowgli : IAnimal { @@ -33,11 +30,11 @@ class Mowgli : IAnimal { @JvmField @Inject - var knowledgeWeakRef: WeakReference? = null + var knowledgeWeakRef: WeakRef? = null @JvmField @Inject - var knowledgeSoftRef: SoftReference? = null + var knowledgeSoftRef: SoftRef? = null @JvmField @Inject @@ -55,10 +52,10 @@ class Mowgli : IAnimal { var knowledgePhantomProvide: PhantomProvide? = null @JvmField - var methodKnowledgeWeakRef: WeakReference? = null + var methodKnowledgeWeakRef: WeakRef? = null @JvmField - var methodKnowledgeSoftRef: SoftReference? = null + var methodKnowledgeSoftRef: SoftRef? = null @JvmField var methodKnowledgeLazyProvide: LazyProvide? = null @@ -73,7 +70,7 @@ class Mowgli : IAnimal { var methodKnowledgePhantomProvide: PhantomProvide? = null @Inject - fun refInject(knowledgeWeakRef: WeakReference?, knowledgeSoftRef: SoftReference?) { + fun refInject(knowledgeWeakRef: WeakRef?, knowledgeSoftRef: SoftRef?) { methodKnowledgeWeakRef = knowledgeWeakRef methodKnowledgeSoftRef = knowledgeSoftRef } diff --git a/tests/src/main/java/com/github/klee0kai/test/mowgli/animal/Snake.kt b/tests/src/commonMain/kotlin/com/github/klee0kai/test/mowgli/animal/Snake.kt similarity index 89% rename from tests/src/main/java/com/github/klee0kai/test/mowgli/animal/Snake.kt rename to tests/src/commonMain/kotlin/com/github/klee0kai/test/mowgli/animal/Snake.kt index f7464613..19490727 100644 --- a/tests/src/main/java/com/github/klee0kai/test/mowgli/animal/Snake.kt +++ b/tests/src/commonMain/kotlin/com/github/klee0kai/test/mowgli/animal/Snake.kt @@ -1,11 +1,12 @@ package com.github.klee0kai.test.mowgli.animal +import com.github.klee0kai.stone.weakref.Inject import com.github.klee0kai.test.mowgli.body.Blood import com.github.klee0kai.test.mowgli.community.History import com.github.klee0kai.test.mowgli.galaxy.Earth import com.github.klee0kai.test.mowgli.identity.Conscience import com.github.klee0kai.test.mowgli.identity.Knowledge -import javax.inject.Inject +import kotlin.jvm.JvmField class Snake : IAnimal { @JvmField diff --git a/tests/src/commonMain/kotlin/com/github/klee0kai/test/mowgli/body/Blood.kt b/tests/src/commonMain/kotlin/com/github/klee0kai/test/mowgli/body/Blood.kt new file mode 100644 index 00000000..f58b1451 --- /dev/null +++ b/tests/src/commonMain/kotlin/com/github/klee0kai/test/mowgli/body/Blood.kt @@ -0,0 +1,17 @@ +@file:OptIn(ExperimentalUuidApi::class) + +package com.github.klee0kai.test.mowgli.body + +import kotlin.uuid.ExperimentalUuidApi +import kotlin.uuid.Uuid + +class Blood(color: Int?) { + + var uuid: String = Uuid.random().toString() + + var color: Int? = null + + init { + this.color = color + } +} diff --git a/tests/src/commonMain/kotlin/com/github/klee0kai/test/mowgli/community/History.kt b/tests/src/commonMain/kotlin/com/github/klee0kai/test/mowgli/community/History.kt new file mode 100644 index 00000000..b5030d07 --- /dev/null +++ b/tests/src/commonMain/kotlin/com/github/klee0kai/test/mowgli/community/History.kt @@ -0,0 +1,10 @@ +@file:OptIn(ExperimentalUuidApi::class) + +package com.github.klee0kai.test.mowgli.community + +import kotlin.uuid.ExperimentalUuidApi +import kotlin.uuid.Uuid + +class History { + var uuid: String = Uuid.random().toString() +} diff --git a/tests/src/main/java/com/github/klee0kai/test/mowgli/earth/Cave.kt b/tests/src/commonMain/kotlin/com/github/klee0kai/test/mowgli/earth/Cave.kt similarity index 74% rename from tests/src/main/java/com/github/klee0kai/test/mowgli/earth/Cave.kt rename to tests/src/commonMain/kotlin/com/github/klee0kai/test/mowgli/earth/Cave.kt index 10b51378..f2459577 100644 --- a/tests/src/main/java/com/github/klee0kai/test/mowgli/earth/Cave.kt +++ b/tests/src/commonMain/kotlin/com/github/klee0kai/test/mowgli/earth/Cave.kt @@ -1,9 +1,9 @@ package com.github.klee0kai.test.mowgli.earth -import java.util.* +import kotlin.uuid.Uuid class Cave : IMountain { - var uuid: UUID = UUID.randomUUID() + var uuid: String = Uuid.random().toString() constructor() diff --git a/tests/src/main/java/com/github/klee0kai/test/mowgli/earth/IMountain.kt b/tests/src/commonMain/kotlin/com/github/klee0kai/test/mowgli/earth/IMountain.kt similarity index 100% rename from tests/src/main/java/com/github/klee0kai/test/mowgli/earth/IMountain.kt rename to tests/src/commonMain/kotlin/com/github/klee0kai/test/mowgli/earth/IMountain.kt diff --git a/tests/src/main/java/com/github/klee0kai/test/mowgli/earth/IRiver.kt b/tests/src/commonMain/kotlin/com/github/klee0kai/test/mowgli/earth/IRiver.kt similarity index 100% rename from tests/src/main/java/com/github/klee0kai/test/mowgli/earth/IRiver.kt rename to tests/src/commonMain/kotlin/com/github/klee0kai/test/mowgli/earth/IRiver.kt diff --git a/tests/src/commonMain/kotlin/com/github/klee0kai/test/mowgli/earth/Mountain.kt b/tests/src/commonMain/kotlin/com/github/klee0kai/test/mowgli/earth/Mountain.kt new file mode 100644 index 00000000..5a7542f0 --- /dev/null +++ b/tests/src/commonMain/kotlin/com/github/klee0kai/test/mowgli/earth/Mountain.kt @@ -0,0 +1,14 @@ +@file:OptIn(ExperimentalUuidApi::class) + +package com.github.klee0kai.test.mowgli.earth + +import kotlin.jvm.JvmField +import kotlin.uuid.ExperimentalUuidApi +import kotlin.uuid.Uuid + +class Mountain : IMountain { + + @JvmField + var uuid: String = Uuid.random().toString() + +} diff --git a/tests/src/commonMain/kotlin/com/github/klee0kai/test/mowgli/earth/River.kt b/tests/src/commonMain/kotlin/com/github/klee0kai/test/mowgli/earth/River.kt new file mode 100644 index 00000000..63f6a798 --- /dev/null +++ b/tests/src/commonMain/kotlin/com/github/klee0kai/test/mowgli/earth/River.kt @@ -0,0 +1,10 @@ +@file:OptIn(ExperimentalUuidApi::class) + +package com.github.klee0kai.test.mowgli.earth + +import kotlin.uuid.ExperimentalUuidApi +import kotlin.uuid.Uuid + +open class River : IRiver { + open var uuid: String = Uuid.random().toString() +} diff --git a/tests/src/commonMain/kotlin/com/github/klee0kai/test/mowgli/galaxy/Earth.kt b/tests/src/commonMain/kotlin/com/github/klee0kai/test/mowgli/galaxy/Earth.kt new file mode 100644 index 00000000..0096717c --- /dev/null +++ b/tests/src/commonMain/kotlin/com/github/klee0kai/test/mowgli/galaxy/Earth.kt @@ -0,0 +1,12 @@ +@file:OptIn(ExperimentalUuidApi::class) + +package com.github.klee0kai.test.mowgli.galaxy + +import kotlin.jvm.JvmField +import kotlin.uuid.ExperimentalUuidApi +import kotlin.uuid.Uuid + +class Earth : IPlanet { + @JvmField + var uuid: String = Uuid.random().toString() +} diff --git a/tests/src/main/java/com/github/klee0kai/test/mowgli/galaxy/IPlanet.kt b/tests/src/commonMain/kotlin/com/github/klee0kai/test/mowgli/galaxy/IPlanet.kt similarity index 100% rename from tests/src/main/java/com/github/klee0kai/test/mowgli/galaxy/IPlanet.kt rename to tests/src/commonMain/kotlin/com/github/klee0kai/test/mowgli/galaxy/IPlanet.kt diff --git a/tests/src/main/java/com/github/klee0kai/test/mowgli/galaxy/IStar.kt b/tests/src/commonMain/kotlin/com/github/klee0kai/test/mowgli/galaxy/IStar.kt similarity index 100% rename from tests/src/main/java/com/github/klee0kai/test/mowgli/galaxy/IStar.kt rename to tests/src/commonMain/kotlin/com/github/klee0kai/test/mowgli/galaxy/IStar.kt diff --git a/tests/src/commonMain/kotlin/com/github/klee0kai/test/mowgli/galaxy/Mercury.kt b/tests/src/commonMain/kotlin/com/github/klee0kai/test/mowgli/galaxy/Mercury.kt new file mode 100644 index 00000000..ecef986b --- /dev/null +++ b/tests/src/commonMain/kotlin/com/github/klee0kai/test/mowgli/galaxy/Mercury.kt @@ -0,0 +1,10 @@ +@file:OptIn(ExperimentalUuidApi::class) + +package com.github.klee0kai.test.mowgli.galaxy + +import kotlin.uuid.ExperimentalUuidApi +import kotlin.uuid.Uuid + +class Mercury : IPlanet { + var uuid: String = Uuid.random().toString() +} diff --git a/tests/src/commonMain/kotlin/com/github/klee0kai/test/mowgli/galaxy/Saturn.kt b/tests/src/commonMain/kotlin/com/github/klee0kai/test/mowgli/galaxy/Saturn.kt new file mode 100644 index 00000000..e511afce --- /dev/null +++ b/tests/src/commonMain/kotlin/com/github/klee0kai/test/mowgli/galaxy/Saturn.kt @@ -0,0 +1,12 @@ +@file:OptIn(ExperimentalUuidApi::class) + +package com.github.klee0kai.test.mowgli.galaxy + +import kotlin.jvm.JvmField +import kotlin.uuid.ExperimentalUuidApi +import kotlin.uuid.Uuid + +class Saturn : IPlanet { + @JvmField + var uuid: String = Uuid.random().toString() +} diff --git a/tests/src/main/java/com/github/klee0kai/test/mowgli/galaxy/SolarSystem.kt b/tests/src/commonMain/kotlin/com/github/klee0kai/test/mowgli/galaxy/SolarSystem.kt similarity index 100% rename from tests/src/main/java/com/github/klee0kai/test/mowgli/galaxy/SolarSystem.kt rename to tests/src/commonMain/kotlin/com/github/klee0kai/test/mowgli/galaxy/SolarSystem.kt diff --git a/tests/src/commonMain/kotlin/com/github/klee0kai/test/mowgli/galaxy/Sun.kt b/tests/src/commonMain/kotlin/com/github/klee0kai/test/mowgli/galaxy/Sun.kt new file mode 100644 index 00000000..fb5fa7cc --- /dev/null +++ b/tests/src/commonMain/kotlin/com/github/klee0kai/test/mowgli/galaxy/Sun.kt @@ -0,0 +1,14 @@ +@file:OptIn(ExperimentalUuidApi::class) + +package com.github.klee0kai.test.mowgli.galaxy + +import kotlin.jvm.JvmField +import kotlin.uuid.ExperimentalUuidApi +import kotlin.uuid.Uuid + +class Sun : IStar { + + @JvmField + var uuid: String = Uuid.random().toString() + +} diff --git a/tests/src/commonMain/kotlin/com/github/klee0kai/test/mowgli/identity/Conscience.kt b/tests/src/commonMain/kotlin/com/github/klee0kai/test/mowgli/identity/Conscience.kt new file mode 100644 index 00000000..f69a0812 --- /dev/null +++ b/tests/src/commonMain/kotlin/com/github/klee0kai/test/mowgli/identity/Conscience.kt @@ -0,0 +1,15 @@ +@file:OptIn(ExperimentalUuidApi::class) + +package com.github.klee0kai.test.mowgli.identity + +import kotlin.jvm.JvmField +import kotlin.uuid.ExperimentalUuidApi +import kotlin.uuid.Uuid + +class Conscience { + @JvmField + var uuid: String = Uuid.random().toString() + + val isOldConscience: Boolean + get() = false +} diff --git a/tests/src/commonMain/kotlin/com/github/klee0kai/test/mowgli/identity/Ideology.kt b/tests/src/commonMain/kotlin/com/github/klee0kai/test/mowgli/identity/Ideology.kt new file mode 100644 index 00000000..1ae05beb --- /dev/null +++ b/tests/src/commonMain/kotlin/com/github/klee0kai/test/mowgli/identity/Ideology.kt @@ -0,0 +1,14 @@ +@file:OptIn(ExperimentalUuidApi::class) + +package com.github.klee0kai.test.mowgli.identity + +import kotlin.uuid.ExperimentalUuidApi +import kotlin.uuid.Uuid + +open class Ideology { + + open var uuid: String = Uuid.random().toString() + + open val isFamilyIdeology: Boolean get() = false + +} diff --git a/tests/src/commonMain/kotlin/com/github/klee0kai/test/mowgli/identity/Knowledge.kt b/tests/src/commonMain/kotlin/com/github/klee0kai/test/mowgli/identity/Knowledge.kt new file mode 100644 index 00000000..37999ba3 --- /dev/null +++ b/tests/src/commonMain/kotlin/com/github/klee0kai/test/mowgli/identity/Knowledge.kt @@ -0,0 +1,17 @@ +@file:OptIn(ExperimentalUuidApi::class) + +package com.github.klee0kai.test.mowgli.identity + +import kotlin.jvm.JvmField +import kotlin.uuid.ExperimentalUuidApi +import kotlin.uuid.Uuid + +open class Knowledge { + + @JvmField + var uuid: String = Uuid.random().toString() + + + open val isOldKnowledge: Boolean + get() = false +} diff --git a/tests/src/commonMain/kotlin/com/github/klee0kai/test/tech/components/Battery.kt b/tests/src/commonMain/kotlin/com/github/klee0kai/test/tech/components/Battery.kt new file mode 100644 index 00000000..749c50ce --- /dev/null +++ b/tests/src/commonMain/kotlin/com/github/klee0kai/test/tech/components/Battery.kt @@ -0,0 +1,12 @@ +@file:OptIn(ExperimentalUuidApi::class) + +package com.github.klee0kai.test.tech.components + +import kotlin.jvm.JvmField +import kotlin.uuid.ExperimentalUuidApi +import kotlin.uuid.Uuid + +class Battery { + @JvmField + var uuid: String = Uuid.random().toString() +} diff --git a/tests/src/main/java/com/github/klee0kai/test/tech/components/DataStorage.kt b/tests/src/commonMain/kotlin/com/github/klee0kai/test/tech/components/DataStorage.kt similarity index 64% rename from tests/src/main/java/com/github/klee0kai/test/tech/components/DataStorage.kt rename to tests/src/commonMain/kotlin/com/github/klee0kai/test/tech/components/DataStorage.kt index 6515bfcb..30f04173 100644 --- a/tests/src/main/java/com/github/klee0kai/test/tech/components/DataStorage.kt +++ b/tests/src/commonMain/kotlin/com/github/klee0kai/test/tech/components/DataStorage.kt @@ -1,11 +1,15 @@ +@file:OptIn(ExperimentalUuidApi::class) + package com.github.klee0kai.test.tech.components import com.github.klee0kai.test.di.base_phone.identifiers.DataStorageSize -import java.util.* +import kotlin.jvm.JvmField +import kotlin.uuid.ExperimentalUuidApi +import kotlin.uuid.Uuid class DataStorage { @JvmField - val uuid: UUID = UUID.randomUUID() + var uuid: String = Uuid.random().toString() @JvmField val size: String? diff --git a/tests/src/main/java/com/github/klee0kai/test/tech/components/OperationSystem.kt b/tests/src/commonMain/kotlin/com/github/klee0kai/test/tech/components/OperationSystem.kt similarity index 77% rename from tests/src/main/java/com/github/klee0kai/test/tech/components/OperationSystem.kt rename to tests/src/commonMain/kotlin/com/github/klee0kai/test/tech/components/OperationSystem.kt index a09d3fc2..8eb609c1 100644 --- a/tests/src/main/java/com/github/klee0kai/test/tech/components/OperationSystem.kt +++ b/tests/src/commonMain/kotlin/com/github/klee0kai/test/tech/components/OperationSystem.kt @@ -1,18 +1,24 @@ +@file:OptIn(ExperimentalUuidApi::class) + package com.github.klee0kai.test.tech.components import com.github.klee0kai.test.di.base_phone.identifiers.PhoneOsType import com.github.klee0kai.test.di.base_phone.identifiers.PhoneOsVersion -import java.util.* +import kotlin.jvm.JvmField +import kotlin.uuid.ExperimentalUuidApi +import kotlin.uuid.Uuid class OperationSystem { + @JvmField - val uuid: UUID = UUID.randomUUID() + var uuid: String = Uuid.random().toString() + @JvmField val phoneOsType: PhoneOsType? + @JvmField val version: PhoneOsVersion? - constructor(phoneOsType: PhoneOsType?) { this.phoneOsType = phoneOsType this.version = PhoneOsVersion("default") diff --git a/tests/src/main/java/com/github/klee0kai/test/tech/components/Ram.kt b/tests/src/commonMain/kotlin/com/github/klee0kai/test/tech/components/Ram.kt similarity index 64% rename from tests/src/main/java/com/github/klee0kai/test/tech/components/Ram.kt rename to tests/src/commonMain/kotlin/com/github/klee0kai/test/tech/components/Ram.kt index 92d6b2cb..9f563f19 100644 --- a/tests/src/main/java/com/github/klee0kai/test/tech/components/Ram.kt +++ b/tests/src/commonMain/kotlin/com/github/klee0kai/test/tech/components/Ram.kt @@ -1,10 +1,14 @@ +@file:OptIn(ExperimentalUuidApi::class) + package com.github.klee0kai.test.tech.components import com.github.klee0kai.test.di.base_phone.identifiers.RamSize -import java.util.* +import kotlin.uuid.ExperimentalUuidApi +import kotlin.uuid.Uuid open class Ram { - open val uuid: UUID = UUID.randomUUID() + open val uuid: String = Uuid.random().toString() + val size: String? diff --git a/tests/src/main/java/com/github/klee0kai/test/tech/phone/GoodPhone.kt b/tests/src/commonMain/kotlin/com/github/klee0kai/test/tech/phone/GoodPhone.kt similarity index 91% rename from tests/src/main/java/com/github/klee0kai/test/tech/phone/GoodPhone.kt rename to tests/src/commonMain/kotlin/com/github/klee0kai/test/tech/phone/GoodPhone.kt index 727c6bb8..ecad2aa9 100644 --- a/tests/src/main/java/com/github/klee0kai/test/tech/phone/GoodPhone.kt +++ b/tests/src/commonMain/kotlin/com/github/klee0kai/test/tech/phone/GoodPhone.kt @@ -1,33 +1,28 @@ package com.github.klee0kai.test.tech.phone import com.github.klee0kai.stone.lifecycle.StoneLifeCycleOwner +import com.github.klee0kai.stone.weakref.Inject import com.github.klee0kai.test.tech.components.Battery import com.github.klee0kai.test.tech.components.DataStorage import com.github.klee0kai.test.tech.components.OperationSystem import com.github.klee0kai.test.tech.components.Ram import com.github.klee0kai.test.tech.phone.base.ATech import com.github.klee0kai.test.tech.phone.base.LifecycleUtils -import javax.inject.Inject class GoodPhone : ATech() { - @JvmField + var lifeCycleOwner: StoneLifeCycleOwner = LifecycleUtils.createFromATech(this) - @JvmField @Inject var battery: Battery? = null - @JvmField @Inject var dataStorage: DataStorage? = null - - @JvmField @Inject var ram: Ram? = null - @JvmField @Inject var os: OperationSystem? = null @@ -44,4 +39,5 @@ class GoodPhone : ATech() { dataStorage = null ram = null } + } diff --git a/tests/src/main/java/com/github/klee0kai/test/tech/phone/OnePhone.kt b/tests/src/commonMain/kotlin/com/github/klee0kai/test/tech/phone/OnePhone.kt similarity index 91% rename from tests/src/main/java/com/github/klee0kai/test/tech/phone/OnePhone.kt rename to tests/src/commonMain/kotlin/com/github/klee0kai/test/tech/phone/OnePhone.kt index 0dfb631b..9529c0e7 100644 --- a/tests/src/main/java/com/github/klee0kai/test/tech/phone/OnePhone.kt +++ b/tests/src/commonMain/kotlin/com/github/klee0kai/test/tech/phone/OnePhone.kt @@ -2,15 +2,17 @@ package com.github.klee0kai.test.tech.phone import com.github.klee0kai.stone.lifecycle.StoneLifeCycleListener import com.github.klee0kai.stone.lifecycle.StoneLifeCycleOwner +import com.github.klee0kai.stone.weakref.Inject +import com.github.klee0kai.stone.weakref.Named import com.github.klee0kai.test.tech.components.Battery import com.github.klee0kai.test.tech.components.DataStorage import com.github.klee0kai.test.tech.components.Ram import com.github.klee0kai.test.tech.phone.base.ATech import com.github.klee0kai.test.tech.phone.base.ATechLifecycle -import javax.inject.Inject -import javax.inject.Named +import kotlin.jvm.JvmField class OnePhone : ATech(), StoneLifeCycleOwner { + @JvmField @Inject var battery: Battery? = null diff --git a/tests/src/main/java/com/github/klee0kai/test/tech/phone/base/ATech.kt b/tests/src/commonMain/kotlin/com/github/klee0kai/test/tech/phone/base/ATech.kt similarity index 83% rename from tests/src/main/java/com/github/klee0kai/test/tech/phone/base/ATech.kt rename to tests/src/commonMain/kotlin/com/github/klee0kai/test/tech/phone/base/ATech.kt index c27486b7..b8075e43 100644 --- a/tests/src/main/java/com/github/klee0kai/test/tech/phone/base/ATech.kt +++ b/tests/src/commonMain/kotlin/com/github/klee0kai/test/tech/phone/base/ATech.kt @@ -1,9 +1,8 @@ package com.github.klee0kai.test.tech.phone.base -import java.util.* - abstract class ATech { - private val listeners = LinkedList() + + private val listeners = mutableListOf() fun subscribe(listener: ATechLifecycle?) { this.listeners.add(listener!!) diff --git a/tests/src/main/java/com/github/klee0kai/test/tech/phone/base/ATechLifecycle.kt b/tests/src/commonMain/kotlin/com/github/klee0kai/test/tech/phone/base/ATechLifecycle.kt similarity index 100% rename from tests/src/main/java/com/github/klee0kai/test/tech/phone/base/ATechLifecycle.kt rename to tests/src/commonMain/kotlin/com/github/klee0kai/test/tech/phone/base/ATechLifecycle.kt diff --git a/tests/src/main/java/com/github/klee0kai/test/tech/phone/base/LifecycleUtils.kt b/tests/src/commonMain/kotlin/com/github/klee0kai/test/tech/phone/base/LifecycleUtils.kt similarity index 100% rename from tests/src/main/java/com/github/klee0kai/test/tech/phone/base/LifecycleUtils.kt rename to tests/src/commonMain/kotlin/com/github/klee0kai/test/tech/phone/base/LifecycleUtils.kt diff --git a/tests/src/main/java/com/github/klee0kai/test/wire/Wire.kt b/tests/src/commonMain/kotlin/com/github/klee0kai/test/wire/Wire.kt similarity index 100% rename from tests/src/main/java/com/github/klee0kai/test/wire/Wire.kt rename to tests/src/commonMain/kotlin/com/github/klee0kai/test/wire/Wire.kt diff --git a/tests/src/main/java/com/github/klee0kai/test/wire/types/Hdmi.kt b/tests/src/commonMain/kotlin/com/github/klee0kai/test/wire/types/Hdmi.kt similarity index 100% rename from tests/src/main/java/com/github/klee0kai/test/wire/types/Hdmi.kt rename to tests/src/commonMain/kotlin/com/github/klee0kai/test/wire/types/Hdmi.kt diff --git a/tests/src/main/java/com/github/klee0kai/test/wire/types/MiniUsb.kt b/tests/src/commonMain/kotlin/com/github/klee0kai/test/wire/types/MiniUsb.kt similarity index 100% rename from tests/src/main/java/com/github/klee0kai/test/wire/types/MiniUsb.kt rename to tests/src/commonMain/kotlin/com/github/klee0kai/test/wire/types/MiniUsb.kt diff --git a/tests/src/main/java/com/github/klee0kai/test/wire/types/Usb.kt b/tests/src/commonMain/kotlin/com/github/klee0kai/test/wire/types/Usb.kt similarity index 100% rename from tests/src/main/java/com/github/klee0kai/test/wire/types/Usb.kt rename to tests/src/commonMain/kotlin/com/github/klee0kai/test/wire/types/Usb.kt diff --git a/tests/src/test/java/com/github/klee0kai/stone/test/bindinstance/simple/GodFirstWorkDayTest.kt b/tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/bindinstance/simple/GodFirstWorkDayTest.kt similarity index 94% rename from tests/src/test/java/com/github/klee0kai/stone/test/bindinstance/simple/GodFirstWorkDayTest.kt rename to tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/bindinstance/simple/GodFirstWorkDayTest.kt index 3a268cf3..b90a4736 100644 --- a/tests/src/test/java/com/github/klee0kai/stone/test/bindinstance/simple/GodFirstWorkDayTest.kt +++ b/tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/bindinstance/simple/GodFirstWorkDayTest.kt @@ -4,9 +4,9 @@ import com.github.klee0kai.test.di.bindinstance.simple.GodWorkspaceComponentSton import com.github.klee0kai.test.mowgli.galaxy.Earth import com.github.klee0kai.test.mowgli.galaxy.Saturn import com.github.klee0kai.test.mowgli.galaxy.Sun -import org.junit.jupiter.api.Assertions.assertEquals -import org.junit.jupiter.api.Assertions.assertNull -import org.junit.jupiter.api.Test +import kotlin.test.Test +import kotlin.test.assertEquals +import kotlin.test.assertNull class GodFirstWorkDayTest { diff --git a/tests/src/test/java/com/github/klee0kai/stone/test/bindinstance/simple/GodTouchTest.kt b/tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/bindinstance/simple/GodTouchTest.kt similarity index 92% rename from tests/src/test/java/com/github/klee0kai/stone/test/bindinstance/simple/GodTouchTest.kt rename to tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/bindinstance/simple/GodTouchTest.kt index 0c1edc13..de89b7bc 100644 --- a/tests/src/test/java/com/github/klee0kai/stone/test/bindinstance/simple/GodTouchTest.kt +++ b/tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/bindinstance/simple/GodTouchTest.kt @@ -4,9 +4,9 @@ import com.github.klee0kai.test.di.bindinstance.simple.GodWorkspaceComponentSton import com.github.klee0kai.test.mowgli.galaxy.Earth import com.github.klee0kai.test.mowgli.galaxy.Saturn import com.github.klee0kai.test.mowgli.galaxy.Sun -import org.junit.jupiter.api.Assertions.assertEquals -import org.junit.jupiter.api.Test -import org.junit.jupiter.api.assertNull +import kotlin.test.Test +import kotlin.test.assertEquals +import kotlin.test.assertNull class GodTouchTest { @@ -26,7 +26,7 @@ class GodTouchTest { } - @org.junit.jupiter.api.Test + @Test fun createSunAndEarthTest() { //Given val DI = GodWorkspaceComponentStoneComponent() diff --git a/tests/src/test/java/com/github/klee0kai/stone/test/bindinstance/simple_inject/SevenPlanetTests.kt b/tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/bindinstance/simple_inject/SevenPlanetTests.kt similarity index 94% rename from tests/src/test/java/com/github/klee0kai/stone/test/bindinstance/simple_inject/SevenPlanetTests.kt rename to tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/bindinstance/simple_inject/SevenPlanetTests.kt index 88d2e50a..a775c3c5 100644 --- a/tests/src/test/java/com/github/klee0kai/stone/test/bindinstance/simple_inject/SevenPlanetTests.kt +++ b/tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/bindinstance/simple_inject/SevenPlanetTests.kt @@ -5,7 +5,8 @@ import com.github.klee0kai.test.mowgli.MoonSky import com.github.klee0kai.test.mowgli.galaxy.Earth import com.github.klee0kai.test.mowgli.galaxy.Mercury import org.junit.jupiter.api.Assertions.assertEquals -import org.junit.jupiter.api.Test +import kotlin.test.Test +import kotlin.test.assertEquals class SevenPlanetTests { diff --git a/tests/src/test/java/com/github/klee0kai/stone/test/bindinstance/singlemethod/PlanetProvideTests.kt b/tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/bindinstance/singlemethod/PlanetProvideTests.kt similarity index 93% rename from tests/src/test/java/com/github/klee0kai/stone/test/bindinstance/singlemethod/PlanetProvideTests.kt rename to tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/bindinstance/singlemethod/PlanetProvideTests.kt index f52a59fa..bf21849c 100644 --- a/tests/src/test/java/com/github/klee0kai/stone/test/bindinstance/singlemethod/PlanetProvideTests.kt +++ b/tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/bindinstance/singlemethod/PlanetProvideTests.kt @@ -3,9 +3,9 @@ package com.github.klee0kai.stone.test.bindinstance.singlemethod import com.github.klee0kai.test.di.bindinstance.singlemethod.PlanetComponentStoneComponent import com.github.klee0kai.test.di.bindinstance.singlemethod_gc.PlanetRollingComponentStoneComponent import com.github.klee0kai.test.mowgli.galaxy.Earth -import org.junit.jupiter.api.Assertions.assertEquals -import org.junit.jupiter.api.Test -import org.junit.jupiter.api.assertNull +import kotlin.test.Test +import kotlin.test.assertEquals +import kotlin.test.assertNull class PlanetProvideTests { diff --git a/tests/src/test/java/com/github/klee0kai/stone/test/bindinstance/singlemethod/StarProvideTests.kt b/tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/bindinstance/singlemethod/StarProvideTests.kt similarity index 91% rename from tests/src/test/java/com/github/klee0kai/stone/test/bindinstance/singlemethod/StarProvideTests.kt rename to tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/bindinstance/singlemethod/StarProvideTests.kt index 3d7e188f..ccfbcf8d 100644 --- a/tests/src/test/java/com/github/klee0kai/stone/test/bindinstance/singlemethod/StarProvideTests.kt +++ b/tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/bindinstance/singlemethod/StarProvideTests.kt @@ -2,9 +2,9 @@ package com.github.klee0kai.stone.test.bindinstance.singlemethod import com.github.klee0kai.test.di.bindinstance.singlemethod.PlanetComponentStoneComponent import com.github.klee0kai.test.mowgli.galaxy.Sun -import org.junit.jupiter.api.Assertions.assertEquals -import org.junit.jupiter.api.Test -import org.junit.jupiter.api.assertNull +import kotlin.test.Test +import kotlin.test.assertEquals +import kotlin.test.assertNull class StarProvideTests { diff --git a/tests/src/test/java/com/github/klee0kai/stone/test/bindinstance/singlemethod_gc/PlanetRollingTests.kt b/tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/bindinstance/singlemethod_gc/PlanetRollingTests.kt similarity index 71% rename from tests/src/test/java/com/github/klee0kai/stone/test/bindinstance/singlemethod_gc/PlanetRollingTests.kt rename to tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/bindinstance/singlemethod_gc/PlanetRollingTests.kt index 92a17860..6a9c2f68 100644 --- a/tests/src/test/java/com/github/klee0kai/stone/test/bindinstance/singlemethod_gc/PlanetRollingTests.kt +++ b/tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/bindinstance/singlemethod_gc/PlanetRollingTests.kt @@ -1,12 +1,12 @@ package com.github.klee0kai.stone.test.bindinstance.singlemethod_gc +import com.github.klee0kai.stone.weakref.WeakRef import com.github.klee0kai.test.di.bindinstance.singlemethod_gc.PlanetRollingComponentStoneComponent import com.github.klee0kai.test.mowgli.galaxy.Earth import com.github.klee0kai.test.mowgli.galaxy.Sun -import org.junit.jupiter.api.Test -import org.junit.jupiter.api.assertNotNull -import org.junit.jupiter.api.assertNull -import java.lang.ref.WeakReference +import kotlin.test.Test +import kotlin.test.assertNotNull +import kotlin.test.assertNull class PlanetRollingTests { @@ -14,12 +14,12 @@ class PlanetRollingTests { fun gcAllTest() { //Given val DI = PlanetRollingComponentStoneComponent() - val earthStrong = WeakReference(Earth()) - val earthSoft = WeakReference(Earth()) - val planetWeak = WeakReference(Earth()) - val sunStrong = WeakReference(Sun()) - val sunSoft = WeakReference(Sun()) - val starWeak = WeakReference(Sun()) + val earthStrong = WeakRef(Earth()) + val earthSoft = WeakRef(Earth()) + val planetWeak = WeakRef(Earth()) + val sunStrong = WeakRef(Sun()) + val sunSoft = WeakRef(Sun()) + val starWeak = WeakRef(Sun()) DI.earthStrong(earthStrong.get()) DI.earthSoft(earthSoft.get()) DI.planet(planetWeak.get()) @@ -44,12 +44,12 @@ class PlanetRollingTests { fun gcStrongTest() { //Given val DI = PlanetRollingComponentStoneComponent() - val earthStrong = WeakReference(Earth()) - val earthSoft = WeakReference(Earth()) - val planetWeak = WeakReference(Earth()) - val sunStrong = WeakReference(Sun()) - val sunSoft = WeakReference(Sun()) - val starWeak = WeakReference(Sun()) + val earthStrong = WeakRef(Earth()) + val earthSoft = WeakRef(Earth()) + val planetWeak = WeakRef(Earth()) + val sunStrong = WeakRef(Sun()) + val sunSoft = WeakRef(Sun()) + val starWeak = WeakRef(Sun()) DI.earthStrong(earthStrong.get()) DI.earthSoft(earthSoft.get()) DI.planet(planetWeak.get()) @@ -80,12 +80,12 @@ class PlanetRollingTests { fun gcSoftTest() { //Given val DI = PlanetRollingComponentStoneComponent() - val earthStrong = WeakReference(Earth()) - val earthSoft = WeakReference(Earth()) - val planetWeak = WeakReference(Earth()) - val sunStrong = WeakReference(Sun()) - val sunSoft = WeakReference(Sun()) - val starWeak = WeakReference(Sun()) + val earthStrong = WeakRef(Earth()) + val earthSoft = WeakRef(Earth()) + val planetWeak = WeakRef(Earth()) + val sunStrong = WeakRef(Sun()) + val sunSoft = WeakRef(Sun()) + val starWeak = WeakRef(Sun()) DI.earthStrong(earthStrong.get()) DI.earthSoft(earthSoft.get()) DI.planet(planetWeak.get()) @@ -116,12 +116,12 @@ class PlanetRollingTests { fun gcWeakTest() { //Given val DI = PlanetRollingComponentStoneComponent() - val earthStrong = WeakReference(Earth()) - val earthSoft = WeakReference(Earth()) - val planetWeak = WeakReference(Earth()) - val sunStrong = WeakReference(Sun()) - val sunSoft = WeakReference(Sun()) - val starWeak = WeakReference(Sun()) + val earthStrong = WeakRef(Earth()) + val earthSoft = WeakRef(Earth()) + val planetWeak = WeakRef(Earth()) + val sunStrong = WeakRef(Sun()) + val sunSoft = WeakRef(Sun()) + val starWeak = WeakRef(Sun()) DI.earthStrong(earthStrong.get()) DI.earthSoft(earthSoft.get()) DI.planet(planetWeak.get()) @@ -152,12 +152,12 @@ class PlanetRollingTests { fun gcSoftSunTest() { //Given val DI = PlanetRollingComponentStoneComponent() - val earthStrong = WeakReference(Earth()) - val earthSoft = WeakReference(Earth()) - val planetWeak = WeakReference(Earth()) - val sunStrong = WeakReference(Sun()) - val sunSoft = WeakReference(Sun()) - val starWeak = WeakReference(Sun()) + val earthStrong = WeakRef(Earth()) + val earthSoft = WeakRef(Earth()) + val planetWeak = WeakRef(Earth()) + val sunStrong = WeakRef(Sun()) + val sunSoft = WeakRef(Sun()) + val starWeak = WeakRef(Sun()) DI.earthStrong(earthStrong.get()) DI.earthSoft(earthSoft.get()) DI.planet(planetWeak.get()) @@ -188,12 +188,12 @@ class PlanetRollingTests { fun gcSoftPlanetsTest() { //Given val DI = PlanetRollingComponentStoneComponent() - val earthStrong = WeakReference(Earth()) - val earthSoft = WeakReference(Earth()) - val planetWeak = WeakReference(Earth()) - val sunStrong = WeakReference(Sun()) - val sunSoft = WeakReference(Sun()) - val starWeak = WeakReference(Sun()) + val earthStrong = WeakRef(Earth()) + val earthSoft = WeakRef(Earth()) + val planetWeak = WeakRef(Earth()) + val sunStrong = WeakRef(Sun()) + val sunSoft = WeakRef(Sun()) + val starWeak = WeakRef(Sun()) DI.earthStrong(earthStrong.get()) DI.earthSoft(earthSoft.get()) DI.planet(planetWeak.get()) diff --git a/tests/src/test/java/com/github/klee0kai/stone/test/bindinstance/singlemethod_inject/MoonSkyProtectInjectedTests.kt b/tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/bindinstance/singlemethod_inject/MoonSkyProtectInjectedTests.kt similarity index 79% rename from tests/src/test/java/com/github/klee0kai/stone/test/bindinstance/singlemethod_inject/MoonSkyProtectInjectedTests.kt rename to tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/bindinstance/singlemethod_inject/MoonSkyProtectInjectedTests.kt index 9f2e391a..c184856b 100644 --- a/tests/src/test/java/com/github/klee0kai/stone/test/bindinstance/singlemethod_inject/MoonSkyProtectInjectedTests.kt +++ b/tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/bindinstance/singlemethod_inject/MoonSkyProtectInjectedTests.kt @@ -1,5 +1,7 @@ package com.github.klee0kai.stone.test.bindinstance.singlemethod_inject +import com.github.klee0kai.stone.weakref.Memory +import com.github.klee0kai.stone.weakref.WeakRef import com.github.klee0kai.test.di.bindinstance.singlemethod_inject.StarSkyComponentStoneComponent import com.github.klee0kai.test.mowgli.MoonSky import com.github.klee0kai.test.mowgli.galaxy.Mercury @@ -8,6 +10,9 @@ import org.junit.jupiter.api.Test import org.junit.jupiter.api.assertNotNull import org.junit.jupiter.api.assertNull import java.lang.ref.WeakReference +import kotlin.test.Test +import kotlin.test.assertNotNull +import kotlin.test.assertNull class MoonSkyProtectInjectedTests { @@ -15,8 +20,8 @@ class MoonSkyProtectInjectedTests { fun withoutProtectInjectedTest() { //Given val component = StarSkyComponentStoneComponent() - val mercury = WeakReference(Mercury()) - val star = WeakReference(Sun()) + val mercury = WeakRef(Mercury()) + val star = WeakRef(Sun()) component.starModule().star(star.get()) component.mercury(mercury.get()) @@ -34,13 +39,12 @@ class MoonSkyProtectInjectedTests { @Test - @Throws(InterruptedException::class) fun withProtectInjectedTest() { //Given - System.gc() + Memory.gc() val component = StarSkyComponentStoneComponent() - val mercury = WeakReference(Mercury()) - val star = WeakReference(Sun()) + val mercury = WeakRef(Mercury()) + val star = WeakRef(Sun()) component.starModule().star(star.get()) component.mercury(mercury.get()) @@ -55,9 +59,10 @@ class MoonSkyProtectInjectedTests { assertNotNull(star.get()) //Then after protect finished - Thread.sleep(100) - System.gc() +// Thread.sleep(100) + Memory.gc() assertNull(mercury.get()) assertNull(star.get()) } + } diff --git a/tests/src/test/java/com/github/klee0kai/stone/test/bindinstance/singlemethod_inject/MoonSkyTests.kt b/tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/bindinstance/singlemethod_inject/MoonSkyTests.kt similarity index 92% rename from tests/src/test/java/com/github/klee0kai/stone/test/bindinstance/singlemethod_inject/MoonSkyTests.kt rename to tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/bindinstance/singlemethod_inject/MoonSkyTests.kt index c603ae77..cebaa045 100644 --- a/tests/src/test/java/com/github/klee0kai/stone/test/bindinstance/singlemethod_inject/MoonSkyTests.kt +++ b/tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/bindinstance/singlemethod_inject/MoonSkyTests.kt @@ -5,11 +5,12 @@ import com.github.klee0kai.test.mowgli.MoonSky import com.github.klee0kai.test.mowgli.galaxy.Earth import com.github.klee0kai.test.mowgli.galaxy.Mercury import com.github.klee0kai.test.mowgli.galaxy.Sun -import org.junit.jupiter.api.Assertions.assertEquals +import kotlin.test.Test +import kotlin.test.assertEquals class MoonSkyTests { - @org.junit.jupiter.api.Test + @Test fun moonSkyTest() { //Given val component = StarSkyComponentStoneComponent() @@ -32,4 +33,5 @@ class MoonSkyTests { assertEquals(earth, moonSky.earth) assertEquals(planet, moonSky.planet) } + } diff --git a/tests/src/test/java/com/github/klee0kai/stone/test/bindinstance/solarsystem/SolarSystemTests.kt b/tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/bindinstance/solarsystem/SolarSystemTests.kt similarity index 91% rename from tests/src/test/java/com/github/klee0kai/stone/test/bindinstance/solarsystem/SolarSystemTests.kt rename to tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/bindinstance/solarsystem/SolarSystemTests.kt index b2c1215d..bedada92 100644 --- a/tests/src/test/java/com/github/klee0kai/stone/test/bindinstance/solarsystem/SolarSystemTests.kt +++ b/tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/bindinstance/solarsystem/SolarSystemTests.kt @@ -5,6 +5,9 @@ import com.github.klee0kai.test.mowgli.galaxy.SolarSystem import org.junit.jupiter.api.Assertions.assertEquals import org.junit.jupiter.api.Assertions.assertNotNull import org.junit.jupiter.api.Test +import kotlin.test.Test +import kotlin.test.assertEquals +import kotlin.test.assertNotNull class SolarSystemTests { @@ -34,4 +37,5 @@ class SolarSystemTests { // Then assertNotNull(DI.earth()) } + } diff --git a/tests/src/test/java/com/github/klee0kai/stone/test/cache/EarthCacheTests.kt b/tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/cache/EarthCacheTests.kt similarity index 97% rename from tests/src/test/java/com/github/klee0kai/stone/test/cache/EarthCacheTests.kt rename to tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/cache/EarthCacheTests.kt index de952bf4..ca9f202e 100644 --- a/tests/src/test/java/com/github/klee0kai/stone/test/cache/EarthCacheTests.kt +++ b/tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/cache/EarthCacheTests.kt @@ -4,6 +4,9 @@ import com.github.klee0kai.test.di.gcforest.GcGodComponentStoneComponent import org.junit.jupiter.api.Assertions.assertEquals import org.junit.jupiter.api.Assertions.assertNotEquals import org.junit.jupiter.api.Test +import kotlin.test.Test +import kotlin.test.assertEquals +import kotlin.test.assertNotEquals class EarthCacheTests { diff --git a/tests/src/test/java/com/github/klee0kai/stone/test/cache/EarthSwitchCacheTests.kt b/tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/cache/EarthSwitchCacheTests.kt similarity index 62% rename from tests/src/test/java/com/github/klee0kai/stone/test/cache/EarthSwitchCacheTests.kt rename to tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/cache/EarthSwitchCacheTests.kt index b1e29388..05aa5b00 100644 --- a/tests/src/test/java/com/github/klee0kai/stone/test/cache/EarthSwitchCacheTests.kt +++ b/tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/cache/EarthSwitchCacheTests.kt @@ -1,10 +1,11 @@ package com.github.klee0kai.stone.test.cache +import com.github.klee0kai.stone.weakref.Memory +import com.github.klee0kai.stone.weakref.WeakRef import com.github.klee0kai.test.di.swcache.SwitchCacheComponentStoneComponent -import org.junit.jupiter.api.Test -import org.junit.jupiter.api.assertNotNull -import org.junit.jupiter.api.assertNull -import java.lang.ref.WeakReference +import kotlin.test.Test +import kotlin.test.assertNotNull +import kotlin.test.assertNull class EarthSwitchCacheTests { @@ -12,11 +13,11 @@ class EarthSwitchCacheTests { fun allToWeakTest() { //Given val DI = SwitchCacheComponentStoneComponent() - val mountain = WeakReference(DI.earth().mountainStrong()) + val mountain = WeakRef(DI.earth().mountainStrong()) //When DI.allWeak() - System.gc() + Memory.gc() //Then assertNull(mountain.get()) @@ -26,12 +27,12 @@ class EarthSwitchCacheTests { fun strongToWeakTest() { //Given val DI = SwitchCacheComponentStoneComponent() - val mountainStrong = WeakReference(DI.earth().mountainStrong()) - val mountainSoft = WeakReference(DI.earth().mountainSoft()) + val mountainStrong = WeakRef(DI.earth().mountainStrong()) + val mountainSoft = WeakRef(DI.earth().mountainSoft()) //When DI.strongToWeak() - System.gc() + Memory.gc() //Then assertNull(mountainStrong.get()) @@ -39,22 +40,21 @@ class EarthSwitchCacheTests { } @Test - @Throws(InterruptedException::class) fun weakToStrongFewMillisTest() { //Given val DI = SwitchCacheComponentStoneComponent() - val mountainWeak = WeakReference(DI.earth().mountainWeak()) + val mountainWeak = WeakRef(DI.earth().mountainWeak()) //When DI.allStrongFewMillis() - System.gc() + Memory.gc() //Then: can't GC assertNotNull(mountainWeak.get()) //When: after few millis - Thread.sleep(110) - System.gc() +// Thread.sleep(110) + Memory.gc() //Then: can GC assertNull(mountainWeak.get()) @@ -65,12 +65,12 @@ class EarthSwitchCacheTests { fun mountainToWeakTest() { //Given val DI = SwitchCacheComponentStoneComponent() - val mountain = WeakReference(DI.earth().mountainStrong()) - val river = WeakReference(DI.earth().riverSoft()) + val mountain = WeakRef(DI.earth().mountainStrong()) + val river = WeakRef(DI.earth().riverSoft()) //When DI.mountainToWeak() - System.gc() + Memory.gc() //Then assertNull(mountain.get()) diff --git a/tests/src/test/java/com/github/klee0kai/stone/test/deps/HouseFactoryTests.kt b/tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/deps/HouseFactoryTests.kt similarity index 91% rename from tests/src/test/java/com/github/klee0kai/stone/test/deps/HouseFactoryTests.kt rename to tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/deps/HouseFactoryTests.kt index 86c2e84a..711df3b0 100644 --- a/tests/src/test/java/com/github/klee0kai/stone/test/deps/HouseFactoryTests.kt +++ b/tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/deps/HouseFactoryTests.kt @@ -4,6 +4,9 @@ import com.github.klee0kai.test.di.house.simple.HouseComponentStoneComponent import org.junit.jupiter.api.Assertions.assertEquals import org.junit.jupiter.api.Assertions.assertNotEquals import org.junit.jupiter.api.Test +import kotlin.test.Test +import kotlin.test.assertEquals +import kotlin.test.assertNotEquals class HouseFactoryTests { diff --git a/tests/src/test/java/com/github/klee0kai/stone/test/deps/HouseNullsTests.kt b/tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/deps/HouseNullsTests.kt similarity index 87% rename from tests/src/test/java/com/github/klee0kai/stone/test/deps/HouseNullsTests.kt rename to tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/deps/HouseNullsTests.kt index 05dd2a74..73908abb 100644 --- a/tests/src/test/java/com/github/klee0kai/stone/test/deps/HouseNullsTests.kt +++ b/tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/deps/HouseNullsTests.kt @@ -1,8 +1,8 @@ package com.github.klee0kai.stone.test.deps import com.github.klee0kai.test.di.house.nulls.HouseNullsComponentStoneComponent -import org.junit.jupiter.api.Test -import org.junit.jupiter.api.assertNull +import kotlin.test.Test +import kotlin.test.assertNull class HouseNullsTests { diff --git a/tests/src/test/java/com/github/klee0kai/stone/test/deps/HouseTests.kt b/tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/deps/HouseTests.kt similarity index 93% rename from tests/src/test/java/com/github/klee0kai/stone/test/deps/HouseTests.kt rename to tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/deps/HouseTests.kt index 4bbaf791..06b1a5b2 100644 --- a/tests/src/test/java/com/github/klee0kai/stone/test/deps/HouseTests.kt +++ b/tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/deps/HouseTests.kt @@ -8,6 +8,11 @@ import org.junit.jupiter.api.Assertions.assertNotEquals import org.junit.jupiter.api.Test import org.junit.jupiter.api.assertNotNull import org.junit.jupiter.api.assertNull +import kotlin.test.Test +import kotlin.test.assertEquals +import kotlin.test.assertNotEquals +import kotlin.test.assertNotNull +import kotlin.test.assertNull class HouseTests { diff --git a/tests/src/test/java/com/github/klee0kai/stone/test/deps/InHouseTests.kt b/tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/deps/InHouseTests.kt similarity index 91% rename from tests/src/test/java/com/github/klee0kai/stone/test/deps/InHouseTests.kt rename to tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/deps/InHouseTests.kt index 928421bd..f1be1edb 100644 --- a/tests/src/test/java/com/github/klee0kai/stone/test/deps/InHouseTests.kt +++ b/tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/deps/InHouseTests.kt @@ -7,9 +7,15 @@ import org.junit.jupiter.api.Assertions.assertEquals import org.junit.jupiter.api.Assertions.assertNotEquals import org.junit.jupiter.api.assertNotNull import org.junit.jupiter.api.assertNull +import kotlin.test.Test +import kotlin.test.assertEquals +import kotlin.test.assertNotEquals +import kotlin.test.assertNotNull +import kotlin.test.assertNull class InHouseTests { - @org.junit.jupiter.api.Test + + @Test fun buildHouseTest() { //Given val di = HouseComponentStoneComponent() @@ -26,7 +32,7 @@ class InHouseTests { assertNotNull(inHouse.bedStoreArea) } - @org.junit.jupiter.api.Test + @Test fun identifiersTest() { //Given val di = HouseComponentStoneComponent() @@ -40,7 +46,7 @@ class InHouseTests { assertEquals(StoreAreaType.CLOSED, inHouse.kichen?.storeArea?.type) } - @org.junit.jupiter.api.Test + @Test fun identifiersNullTest() { //Given val di = HouseComponentStoneComponent() @@ -55,7 +61,7 @@ class InHouseTests { } - @org.junit.jupiter.api.Test + @Test fun cacheTest() { //Given val di = HouseComponentStoneComponent() @@ -74,7 +80,7 @@ class InHouseTests { } - @org.junit.jupiter.api.Test + @Test fun factoryTest() { //Given val di = HouseComponentStoneComponent() @@ -95,4 +101,5 @@ class InHouseTests { inHouse2.bedRoom?.storeArea?.sanitizers, ) } + } diff --git a/tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/gc/EarthLastDayTests.kt b/tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/gc/EarthLastDayTests.kt new file mode 100644 index 00000000..8acbb568 --- /dev/null +++ b/tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/gc/EarthLastDayTests.kt @@ -0,0 +1,285 @@ +package com.github.klee0kai.stone.test.gc + +import com.github.klee0kai.stone.weakref.WeakRef +import com.github.klee0kai.test.di.gcforest.GcGodComponentStoneComponent +import org.junit.jupiter.api.Test +import org.junit.jupiter.api.assertNotNull +import org.junit.jupiter.api.assertNull +import java.lang.ref.WeakReference +import kotlin.test.Test +import kotlin.test.assertNotNull +import kotlin.test.assertNull + +class EarthLastDayTests { + + @Test + fun gcAllTest() { + //Given + val di = GcGodComponentStoneComponent() + val mountainStrong = WeakRef(di.earth().mountainStrong()) + val mountainSoft = WeakRef(di.earth().mountainSoft()) + val mountainWeak = WeakRef(di.earth().mountainWeak()) + val mountainDef = WeakRef(di.earth().mountainDefaultFactory()) + val mountainDef2 = WeakRef(di.earth().mountainDefault2Factory()) + val riverStrong = WeakRef(di.earth().riverStrong()) + val riverSoft = WeakRef(di.earth().riverSoft()) + val riverWeak = WeakRef(di.earth().riverWeak()) + val riverDef = WeakRef(di.earth().riverDefaultSoft()) + + //When + di.gcAll() + + //Then + for (ref in listOf( + mountainStrong, mountainSoft, mountainDef2, mountainWeak, mountainDef, + riverStrong, riverSoft, riverWeak, riverDef + )) { + assertNull(ref.get()) + } + } + + @Test + fun gcStrongTest() { + //Given + val di = GcGodComponentStoneComponent() + val mountainStrong = WeakRef(di.earth().mountainStrong()) + val mountainSoft = WeakRef(di.earth().mountainSoft()) + val mountainWeak = WeakRef(di.earth().mountainWeak()) + val mountainDef = WeakRef(di.earth().mountainDefaultFactory()) + val mountainDef2 = WeakRef(di.earth().mountainDefault2Factory()) + val riverStrong = WeakRef(di.earth().riverStrong()) + val riverSoft = WeakRef(di.earth().riverSoft()) + val riverWeak = WeakRef(di.earth().riverWeak()) + val riverDef = WeakRef(di.earth().riverDefaultSoft()) + + //When + di.gcStrong() + + //Then + for (ref in listOf( + mountainStrong, mountainWeak, mountainDef, mountainDef2, + riverStrong, riverWeak, riverDef + )) { + assertNull(ref.get()) + } + + for (ref in listOf( + mountainSoft, + riverSoft + )) { + assertNotNull(ref.get()) + } + } + + @Test + fun gcSoftTest() { + //Given + val di = GcGodComponentStoneComponent() + val mountainStrong = WeakRef(di.earth().mountainStrong()) + val mountainSoft = WeakRef(di.earth().mountainSoft()) + val mountainWeak = WeakRef(di.earth().mountainWeak()) + val mountainDef = WeakRef(di.earth().mountainDefaultFactory()) + val mountainDef2 = WeakRef(di.earth().mountainDefault2Factory()) + val riverStrong = WeakRef(di.earth().riverStrong()) + val riverSoft = WeakRef(di.earth().riverSoft()) + val riverWeak = WeakRef(di.earth().riverWeak()) + val riverDef = WeakRef(di.earth().riverDefaultSoft()) + + //When + di.gcSoft() + + //Then + for (ref in listOf( + mountainSoft, mountainWeak, mountainDef, mountainDef2, + riverSoft, riverWeak, riverDef + )) { + assertNull(ref.get()) + } + for (ref in listOf( + mountainStrong, + riverStrong + )) { + assertNotNull(ref.get()) + } + } + + @Test + fun gcWeakTest() { + //Given + val di = GcGodComponentStoneComponent() + val mountainStrong = WeakRef(di.earth().mountainStrong()) + val mountainSoft = WeakRef(di.earth().mountainSoft()) + val mountainWeak = WeakRef(di.earth().mountainWeak()) + val mountainDef = WeakRef(di.earth().mountainDefaultFactory()) + val riverStrong = WeakRef(di.earth().riverStrong()) + val riverSoft = WeakRef(di.earth().riverSoft()) + val riverWeak = WeakRef(di.earth().riverWeak()) + val riverDef = WeakRef(di.earth().riverDefaultSoft()) + + //When + di.gcWeak() + + //Then + for (ref in listOf( + mountainWeak, mountainDef, + riverWeak, riverDef + )) { + assertNull(ref.get()) + } + for (ref in listOf( + mountainStrong, mountainSoft, + riverStrong, riverSoft + )) { + assertNotNull(ref.get()) + } + } + + @Test + fun gcMountainTest() { + //Given + val di = GcGodComponentStoneComponent() + val mountainStrong = WeakRef(di.earth().mountainStrong()) + val mountainSoft = WeakRef(di.earth().mountainSoft()) + val mountainWeak = WeakRef(di.earth().mountainWeak()) + val mountainDef = WeakRef(di.earth().mountainDefaultFactory()) + val riverStrong = WeakRef(di.earth().riverStrong()) + val riverSoft = WeakRef(di.earth().riverSoft()) + val riverWeak = WeakRef(di.earth().riverWeak()) + val riverDef = WeakRef(di.earth().riverDefaultSoft()) + + //When + di.gcMountains() + + //Then + for (ref in listOf( + mountainStrong, mountainSoft, mountainWeak, mountainDef, + riverWeak, riverDef + )) { + assertNull(ref.get()) + } + for (ref in listOf( + riverStrong, riverSoft + )) { + assertNotNull(ref.get()) + } + } + + @Test + fun gcRiverTest() { + //Given + val di = GcGodComponentStoneComponent() + val mountainStrong = WeakRef(di.earth().mountainStrong()) + val mountainSoft = WeakRef(di.earth().mountainSoft()) + val mountainWeak = WeakRef(di.earth().mountainWeak()) + val mountainDef = WeakRef(di.earth().mountainDefaultFactory()) + val riverStrong = WeakRef(di.earth().riverStrong()) + val riverSoft = WeakRef(di.earth().riverSoft()) + val riverWeak = WeakRef(di.earth().riverWeak()) + val riverDef = WeakRef(di.earth().riverDefaultSoft()) + + //When + di.gcRivers() + + //Then + for (ref in listOf( + mountainWeak, mountainDef, + riverStrong, riverSoft, riverWeak, riverDef + )) { + assertNull(ref.get()) + } + for (ref in listOf( + mountainStrong, mountainSoft + )) { + assertNotNull(ref.get()) + } + } + + @Test + fun gcMountainAndRiverTest() { + //Given + val di = GcGodComponentStoneComponent() + val mountainStrong = WeakRef(di.earth().mountainStrong()) + val mountainSoft = WeakRef(di.earth().mountainSoft()) + val mountainWeak = WeakRef(di.earth().mountainWeak()) + val mountainDef = WeakRef(di.earth().mountainDefaultFactory()) + val riverStrong = WeakRef(di.earth().riverStrong()) + val riverSoft = WeakRef(di.earth().riverSoft()) + val riverWeak = WeakRef(di.earth().riverWeak()) + val riverDef = WeakRef(di.earth().riverDefaultSoft()) + + //When + di.gcMountainsAndRivers() + + //Then + for (ref in listOf( + mountainStrong, mountainSoft, mountainWeak, mountainDef, + riverStrong, riverSoft, riverWeak, riverDef + )) { + assertNull(ref.get()) + } + } + + + @Test + fun gcSoftMountainTest() { + //Given + val di = GcGodComponentStoneComponent() + val mountainStrong = WeakRef(di.earth().mountainStrong()) + val mountainSoft = WeakRef(di.earth().mountainSoft()) + val mountainWeak = WeakRef(di.earth().mountainWeak()) + val mountainDef = WeakRef(di.earth().mountainDefaultFactory()) + val riverStrong = WeakRef(di.earth().riverStrong()) + val riverSoft = WeakRef(di.earth().riverSoft()) + val riverWeak = WeakRef(di.earth().riverWeak()) + val riverDef = WeakRef(di.earth().riverDefaultSoft()) + + //When + di.gcSoftMountains() + + //Then + for (ref in listOf( + mountainSoft, mountainWeak, mountainDef, + riverWeak, riverDef + )) { + assertNull(ref.get()) + } + for (ref in listOf( + mountainStrong, + riverStrong, riverSoft + )) { + assertNotNull(ref.get()) + } + } + + @Test + fun gcStrongMountainTest() { + //Given + val di = GcGodComponentStoneComponent() + val mountainStrong = WeakRef(di.earth().mountainStrong()) + val mountainSoft = WeakRef(di.earth().mountainSoft()) + val mountainWeak = WeakRef(di.earth().mountainWeak()) + val mountainDef = WeakRef(di.earth().mountainDefaultFactory()) + val riverStrong = WeakRef(di.earth().riverStrong()) + val riverSoft = WeakRef(di.earth().riverSoft()) + val riverWeak = WeakRef(di.earth().riverWeak()) + val riverDef = WeakRef(di.earth().riverDefaultSoft()) + + //When + di.gcStrongMountains() + + //Then + for (ref in listOf( + mountainStrong, mountainWeak, mountainDef, + riverWeak, riverDef + )) { + assertNull(ref.get()) + } + for (ref in listOf( + mountainSoft, + riverStrong, riverSoft + )) { + assertNotNull(ref.get()) + } + } + +} diff --git a/tests/src/test/java/com/github/klee0kai/stone/test/gc/GodLastWorkDayTests.kt b/tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/gc/GodLastWorkDayTests.kt similarity index 75% rename from tests/src/test/java/com/github/klee0kai/stone/test/gc/GodLastWorkDayTests.kt rename to tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/gc/GodLastWorkDayTests.kt index 74c26a84..b33ddfb1 100644 --- a/tests/src/test/java/com/github/klee0kai/stone/test/gc/GodLastWorkDayTests.kt +++ b/tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/gc/GodLastWorkDayTests.kt @@ -1,5 +1,6 @@ package com.github.klee0kai.stone.test.gc +import com.github.klee0kai.stone.weakref.WeakRef import com.github.klee0kai.test.di.gcforest.GcGodComponentStoneComponent import com.github.klee0kai.test.mowgli.galaxy.Earth import com.github.klee0kai.test.mowgli.galaxy.Saturn @@ -8,6 +9,9 @@ import org.junit.jupiter.api.Test import org.junit.jupiter.api.assertNotNull import org.junit.jupiter.api.assertNull import java.lang.ref.WeakReference +import kotlin.test.Test +import kotlin.test.assertNotNull +import kotlin.test.assertNull class GodLastWorkDayTests { @@ -15,9 +19,9 @@ class GodLastWorkDayTests { fun gcAllTest() { //Given val di = GcGodComponentStoneComponent() - val sunRef = WeakReference(Sun()) - val earthRef = WeakReference(Earth()) - val saturnRef = WeakReference(Saturn()) + val sunRef = WeakRef(Sun()) + val earthRef = WeakRef(Earth()) + val saturnRef = WeakRef(Saturn()) di.bind(sunRef.get()) di.bind(earthRef.get()) di.bind(saturnRef.get()) @@ -36,9 +40,9 @@ class GodLastWorkDayTests { fun gcWeakTest() { //Given val di = GcGodComponentStoneComponent() - val sunRef = WeakReference(Sun()) - val earthRef = WeakReference(Earth()) - val saturnRef = WeakReference(Saturn()) + val sunRef = WeakRef(Sun()) + val earthRef = WeakRef(Earth()) + val saturnRef = WeakRef(Saturn()) di.bind(sunRef.get()) di.bind(earthRef.get()) di.bind(saturnRef.get()) @@ -57,9 +61,9 @@ class GodLastWorkDayTests { fun gcSoftTest() { //Given val di = GcGodComponentStoneComponent() - val sunRef = WeakReference(Sun()) - val earthRef = WeakReference(Earth()) - val saturnRef = WeakReference(Saturn()) + val sunRef = WeakRef(Sun()) + val earthRef = WeakRef(Earth()) + val saturnRef = WeakRef(Saturn()) di.bind(sunRef.get()) di.bind(earthRef.get()) di.bind(saturnRef.get()) @@ -77,9 +81,9 @@ class GodLastWorkDayTests { fun gcStrongTest() { //Given val di = GcGodComponentStoneComponent() - val sunRef = WeakReference(Sun()) - val earthRef = WeakReference(Earth()) - val saturnRef = WeakReference(Saturn()) + val sunRef = WeakRef(Sun()) + val earthRef = WeakRef(Earth()) + val saturnRef = WeakRef(Saturn()) di.bind(sunRef.get()) di.bind(earthRef.get()) di.bind(saturnRef.get()) @@ -98,9 +102,9 @@ class GodLastWorkDayTests { fun gcSunTest() { //Given val di = GcGodComponentStoneComponent() - val sunRef = WeakReference(Sun()) - val earthRef = WeakReference(Earth()) - val saturnRef = WeakReference(Saturn()) + val sunRef = WeakRef(Sun()) + val earthRef = WeakRef(Earth()) + val saturnRef = WeakRef(Saturn()) di.bind(sunRef.get()) di.bind(earthRef.get()) di.bind(saturnRef.get()) @@ -119,9 +123,9 @@ class GodLastWorkDayTests { fun gcPlanetsTest() { //Given val di = GcGodComponentStoneComponent() - val sunRef = WeakReference(Sun()) - val earthRef = WeakReference(Earth()) - val saturnRef = WeakReference(Saturn()) + val sunRef = WeakRef(Sun()) + val earthRef = WeakRef(Earth()) + val saturnRef = WeakRef(Saturn()) di.bind(sunRef.get()) di.bind(earthRef.get()) di.bind(saturnRef.get()) @@ -139,9 +143,9 @@ class GodLastWorkDayTests { fun gcSunAndPlanetsTest() { //Given val di = GcGodComponentStoneComponent() - val sunRef = WeakReference(Sun()) - val earthRef = WeakReference(Earth()) - val saturnRef = WeakReference(Saturn()) + val sunRef = WeakRef(Sun()) + val earthRef = WeakRef(Earth()) + val saturnRef = WeakRef(Saturn()) di.bind(sunRef.get()) di.bind(earthRef.get()) di.bind(saturnRef.get()) diff --git a/tests/src/test/java/com/github/klee0kai/stone/test/identifiers/GoodPhoneInjectTests.kt b/tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/identifiers/GoodPhoneInjectTests.kt similarity index 95% rename from tests/src/test/java/com/github/klee0kai/stone/test/identifiers/GoodPhoneInjectTests.kt rename to tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/identifiers/GoodPhoneInjectTests.kt index 8d836020..44bfd410 100644 --- a/tests/src/test/java/com/github/klee0kai/stone/test/identifiers/GoodPhoneInjectTests.kt +++ b/tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/identifiers/GoodPhoneInjectTests.kt @@ -6,6 +6,8 @@ import com.github.klee0kai.test.di.base_phone.identifiers.RamSize import com.github.klee0kai.test.tech.phone.GoodPhone import org.junit.jupiter.api.Assertions.assertEquals import org.junit.jupiter.api.Test +import kotlin.test.Test +import kotlin.test.assertEquals class GoodPhoneInjectTests { diff --git a/tests/src/test/java/com/github/klee0kai/stone/test/identifiers/MultiIdentifiersTests.kt b/tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/identifiers/MultiIdentifiersTests.kt similarity index 95% rename from tests/src/test/java/com/github/klee0kai/stone/test/identifiers/MultiIdentifiersTests.kt rename to tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/identifiers/MultiIdentifiersTests.kt index f6b5d5c2..c013ceec 100644 --- a/tests/src/test/java/com/github/klee0kai/stone/test/identifiers/MultiIdentifiersTests.kt +++ b/tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/identifiers/MultiIdentifiersTests.kt @@ -5,7 +5,9 @@ import com.github.klee0kai.test.di.base_phone.identifiers.PhoneOsType import com.github.klee0kai.test.di.base_phone.identifiers.PhoneOsVersion import org.junit.jupiter.api.Assertions.assertEquals import org.junit.jupiter.api.Assertions.assertNotEquals -import org.junit.jupiter.api.Test +import kotlin.test.Test +import kotlin.test.assertEquals +import kotlin.test.assertNotEquals class MultiIdentifiersTests { diff --git a/tests/src/test/java/com/github/klee0kai/stone/test/identifiers/TechComponentsTests.kt b/tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/identifiers/TechComponentsTests.kt similarity index 95% rename from tests/src/test/java/com/github/klee0kai/stone/test/identifiers/TechComponentsTests.kt rename to tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/identifiers/TechComponentsTests.kt index f8f7a487..601a736c 100644 --- a/tests/src/test/java/com/github/klee0kai/stone/test/identifiers/TechComponentsTests.kt +++ b/tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/identifiers/TechComponentsTests.kt @@ -6,6 +6,9 @@ import com.github.klee0kai.test.di.base_phone.identifiers.RamSize import org.junit.jupiter.api.Assertions.assertEquals import org.junit.jupiter.api.Assertions.assertNotEquals import org.junit.jupiter.api.Test +import kotlin.test.Test +import kotlin.test.assertEquals +import kotlin.test.assertNotEquals class TechComponentsTests { diff --git a/tests/src/test/java/com/github/klee0kai/stone/test/identifiers/TechFactoryComponentTests.kt b/tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/identifiers/TechFactoryComponentTests.kt similarity index 95% rename from tests/src/test/java/com/github/klee0kai/stone/test/identifiers/TechFactoryComponentTests.kt rename to tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/identifiers/TechFactoryComponentTests.kt index fe89b81f..e6e1ca9d 100644 --- a/tests/src/test/java/com/github/klee0kai/stone/test/identifiers/TechFactoryComponentTests.kt +++ b/tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/identifiers/TechFactoryComponentTests.kt @@ -8,6 +8,10 @@ import org.junit.jupiter.api.Assertions.assertEquals import org.junit.jupiter.api.Assertions.assertNotEquals import org.junit.jupiter.api.Test import org.junit.jupiter.api.assertNull +import kotlin.test.Test +import kotlin.test.assertEquals +import kotlin.test.assertNotEquals +import kotlin.test.assertNull class TechFactoryComponentTests { diff --git a/tests/src/test/java/com/github/klee0kai/stone/test/identifiers/TechFactoryTests.kt b/tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/identifiers/TechFactoryTests.kt similarity index 95% rename from tests/src/test/java/com/github/klee0kai/stone/test/identifiers/TechFactoryTests.kt rename to tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/identifiers/TechFactoryTests.kt index f0085b19..eeaa84f3 100644 --- a/tests/src/test/java/com/github/klee0kai/stone/test/identifiers/TechFactoryTests.kt +++ b/tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/identifiers/TechFactoryTests.kt @@ -5,6 +5,8 @@ import com.github.klee0kai.test.di.base_phone.identifiers.RamSize import com.github.klee0kai.test.di.techfactory.TechFactoryComponentStoneComponent import org.junit.jupiter.api.Assertions.assertNotEquals import org.junit.jupiter.api.Test +import kotlin.test.Test +import kotlin.test.assertNotEquals class TechFactoryTests { diff --git a/tests/src/test/java/com/github/klee0kai/stone/test/identifiers/TechFactoryWrappersTests.kt b/tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/identifiers/TechFactoryWrappersTests.kt similarity index 94% rename from tests/src/test/java/com/github/klee0kai/stone/test/identifiers/TechFactoryWrappersTests.kt rename to tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/identifiers/TechFactoryWrappersTests.kt index 538994e3..a97a9b22 100644 --- a/tests/src/test/java/com/github/klee0kai/stone/test/identifiers/TechFactoryWrappersTests.kt +++ b/tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/identifiers/TechFactoryWrappersTests.kt @@ -5,6 +5,10 @@ import org.junit.jupiter.api.Assertions.assertEquals import org.junit.jupiter.api.Assertions.assertNotEquals import org.junit.jupiter.api.Test import org.junit.jupiter.api.assertNotNull +import kotlin.test.Test +import kotlin.test.assertEquals +import kotlin.test.assertNotEquals +import kotlin.test.assertNotNull class TechFactoryWrappersTests { diff --git a/tests/src/test/java/com/github/klee0kai/stone/test/inject/HorseInjectTests.kt b/tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/inject/HorseInjectTests.kt similarity index 94% rename from tests/src/test/java/com/github/klee0kai/stone/test/inject/HorseInjectTests.kt rename to tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/inject/HorseInjectTests.kt index 76c67432..c5ced0ca 100644 --- a/tests/src/test/java/com/github/klee0kai/stone/test/inject/HorseInjectTests.kt +++ b/tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/inject/HorseInjectTests.kt @@ -7,8 +7,11 @@ import com.github.klee0kai.test.mowgli.animal.Mowgli import com.github.klee0kai.test.mowgli.animal.Snake import org.junit.jupiter.api.Assertions.assertEquals import org.junit.jupiter.api.Assertions.assertNotEquals -import org.junit.jupiter.api.Test import org.junit.jupiter.api.assertNotNull +import kotlin.test.Test +import kotlin.test.assertEquals +import kotlin.test.assertNotEquals +import kotlin.test.assertNotNull class HorseInjectTests { diff --git a/tests/src/test/java/com/github/klee0kai/stone/test/inject/HorseProtectInjectTests.kt b/tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/inject/HorseProtectInjectTests.kt similarity index 83% rename from tests/src/test/java/com/github/klee0kai/stone/test/inject/HorseProtectInjectTests.kt rename to tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/inject/HorseProtectInjectTests.kt index 5c2ff833..7b841381 100644 --- a/tests/src/test/java/com/github/klee0kai/stone/test/inject/HorseProtectInjectTests.kt +++ b/tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/inject/HorseProtectInjectTests.kt @@ -1,11 +1,11 @@ package com.github.klee0kai.stone.test.inject +import com.github.klee0kai.stone.weakref.Memory import com.github.klee0kai.test.di.base_forest.ForestComponentStoneComponent import com.github.klee0kai.test.mowgli.animal.Horse -import org.junit.jupiter.api.Test -import org.junit.jupiter.api.assertNotNull -import org.junit.jupiter.api.assertNull -import java.lang.ref.WeakReference +import kotlin.test.Test +import kotlin.test.assertNotNull +import kotlin.test.assertNull class HorseProtectInjectTests { @@ -24,14 +24,13 @@ class HorseProtectInjectTests { val historyWeakReference = WeakReference(horse?.history) horse = null - System.gc() + Memory.gc() //Then: without protect all not uses should be garbage collected assertNull(historyWeakReference.get()) } @Test - @Throws(InterruptedException::class) fun withProtectInjectTest() { // Given val DI = ForestComponentStoneComponent() @@ -52,7 +51,7 @@ class HorseProtectInjectTests { assertNotNull(historyWeakReference.get()) //after protect finished - Thread.sleep(50) +// Thread.sleep(50) DI.gcAll() assertNull(historyWeakReference.get()) } diff --git a/tests/src/test/java/com/github/klee0kai/stone/test/inject/MowgliInjectMethodWrappersTests.kt b/tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/inject/MowgliInjectMethodWrappersTests.kt similarity index 94% rename from tests/src/test/java/com/github/klee0kai/stone/test/inject/MowgliInjectMethodWrappersTests.kt rename to tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/inject/MowgliInjectMethodWrappersTests.kt index 2fb3982a..e852ff34 100644 --- a/tests/src/test/java/com/github/klee0kai/stone/test/inject/MowgliInjectMethodWrappersTests.kt +++ b/tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/inject/MowgliInjectMethodWrappersTests.kt @@ -2,10 +2,11 @@ package com.github.klee0kai.stone.test.inject import com.github.klee0kai.test.di.base_forest.ForestComponentStoneComponent import com.github.klee0kai.test.mowgli.animal.Mowgli -import org.junit.jupiter.api.Assertions.assertEquals import org.junit.jupiter.api.Assertions.assertNotEquals -import org.junit.jupiter.api.Test -import org.junit.jupiter.api.assertNotNull +import kotlin.test.Test +import kotlin.test.assertEquals +import kotlin.test.assertNotEquals +import kotlin.test.assertNotNull class MowgliInjectMethodWrappersTests { diff --git a/tests/src/test/java/com/github/klee0kai/stone/test/inject/MowgliInjectWrappersTests.kt b/tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/inject/MowgliInjectWrappersTests.kt similarity index 94% rename from tests/src/test/java/com/github/klee0kai/stone/test/inject/MowgliInjectWrappersTests.kt rename to tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/inject/MowgliInjectWrappersTests.kt index 229b7e93..d68373a4 100644 --- a/tests/src/test/java/com/github/klee0kai/stone/test/inject/MowgliInjectWrappersTests.kt +++ b/tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/inject/MowgliInjectWrappersTests.kt @@ -4,6 +4,10 @@ import com.github.klee0kai.test.di.base_forest.ForestComponentStoneComponent import com.github.klee0kai.test.mowgli.animal.Mowgli import org.junit.jupiter.api.Assertions.* import org.junit.jupiter.api.Test +import kotlin.test.Test +import kotlin.test.assertEquals +import kotlin.test.assertNotEquals +import kotlin.test.assertNotNull class MowgliInjectWrappersTests { diff --git a/tests/src/test/java/com/github/klee0kai/stone/test/inject/SchoolProtectInjectWrappersTests.kt b/tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/inject/SchoolProtectInjectWrappersTests.kt similarity index 71% rename from tests/src/test/java/com/github/klee0kai/stone/test/inject/SchoolProtectInjectWrappersTests.kt rename to tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/inject/SchoolProtectInjectWrappersTests.kt index 046fd77d..b1312ec3 100644 --- a/tests/src/test/java/com/github/klee0kai/stone/test/inject/SchoolProtectInjectWrappersTests.kt +++ b/tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/inject/SchoolProtectInjectWrappersTests.kt @@ -1,11 +1,15 @@ package com.github.klee0kai.stone.test.inject +import com.github.klee0kai.stone.weakref.WeakRef import com.github.klee0kai.test.di.base_forest.ForestComponentStoneComponent import com.github.klee0kai.test.mowgli.School import org.junit.jupiter.api.Test import org.junit.jupiter.api.assertNotNull import org.junit.jupiter.api.assertNull import java.lang.ref.WeakReference +import kotlin.test.Test +import kotlin.test.assertNotNull +import kotlin.test.assertNull class SchoolProtectInjectWrappersTests { @@ -18,7 +22,7 @@ class SchoolProtectInjectWrappersTests { //When DI.inject(school) - val history = WeakReference(school.historyLazyProvide!!.get()) + val history = WeakRef(school.historyLazyProvide!!.get()) DI.protectInjected(school) DI.gcAll() @@ -34,9 +38,9 @@ class SchoolProtectInjectWrappersTests { //When DI.inject(school) - val knowledge1 = WeakReference(school.knowledgePhantomProvide!!.get()) - val knowledge2 = WeakReference(school.knowledgePhantomProvide2!!.get()) - val knowledge3 = WeakReference(school.knowledgePhantomProvide3!!.get()) + val knowledge1 = WeakRef(school.knowledgePhantomProvide!!.get()) + val knowledge2 = WeakRef(school.knowledgePhantomProvide2!!.get()) + val knowledge3 = WeakRef(school.knowledgePhantomProvide3!!.get()) DI.protectInjected(school) DI.gcAll() diff --git a/tests/src/test/java/com/github/klee0kai/stone/test/interfaceprovide/DeepCaveTest.kt b/tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/interfaceprovide/DeepCaveTest.kt similarity index 90% rename from tests/src/test/java/com/github/klee0kai/stone/test/interfaceprovide/DeepCaveTest.kt rename to tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/interfaceprovide/DeepCaveTest.kt index 38bfce5b..c1c3ccf4 100644 --- a/tests/src/test/java/com/github/klee0kai/stone/test/interfaceprovide/DeepCaveTest.kt +++ b/tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/interfaceprovide/DeepCaveTest.kt @@ -2,8 +2,8 @@ package com.github.klee0kai.stone.test.interfaceprovide import com.github.klee0kai.test.di.earthmirror.EarthComponentStoneComponent import com.github.klee0kai.test.mowgli.earth.Cave -import org.junit.jupiter.api.Test -import org.junit.jupiter.api.assertNotNull +import kotlin.test.Test +import kotlin.test.assertNotNull class DeepCaveTest { diff --git a/tests/src/test/java/com/github/klee0kai/stone/test/interfaceprovide/EarthWayTest.kt b/tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/interfaceprovide/EarthWayTest.kt similarity index 83% rename from tests/src/test/java/com/github/klee0kai/stone/test/interfaceprovide/EarthWayTest.kt rename to tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/interfaceprovide/EarthWayTest.kt index c0893f55..0271ce80 100644 --- a/tests/src/test/java/com/github/klee0kai/stone/test/interfaceprovide/EarthWayTest.kt +++ b/tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/interfaceprovide/EarthWayTest.kt @@ -1,8 +1,8 @@ package com.github.klee0kai.stone.test.interfaceprovide import com.github.klee0kai.test.di.earthmirror.EarthComponentStoneComponent -import org.junit.jupiter.api.Test -import org.junit.jupiter.api.assertNotNull +import kotlin.test.Test +import kotlin.test.assertNotNull class EarthWayTest { diff --git a/tests/src/test/java/com/github/klee0kai/stone/test/lifecycle/GoodPhoneRepairTests.kt b/tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/lifecycle/GoodPhoneRepairTests.kt similarity index 79% rename from tests/src/test/java/com/github/klee0kai/stone/test/lifecycle/GoodPhoneRepairTests.kt rename to tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/lifecycle/GoodPhoneRepairTests.kt index e47756ba..99f3598c 100644 --- a/tests/src/test/java/com/github/klee0kai/stone/test/lifecycle/GoodPhoneRepairTests.kt +++ b/tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/lifecycle/GoodPhoneRepairTests.kt @@ -1,16 +1,16 @@ package com.github.klee0kai.stone.test.lifecycle +import com.github.klee0kai.stone.weakref.Memory +import com.github.klee0kai.stone.weakref.WeakRef import com.github.klee0kai.test.di.base_phone.PhoneComponentStoneComponent import com.github.klee0kai.test.di.base_phone.identifiers.DataStorageSize import com.github.klee0kai.test.di.base_phone.identifiers.RamSize import com.github.klee0kai.test.tech.phone.GoodPhone -import org.junit.jupiter.api.Assertions import org.junit.jupiter.api.Assertions.assertEquals -import org.junit.jupiter.api.Assertions.assertNotEquals -import org.junit.jupiter.api.Test -import org.junit.jupiter.api.assertNotNull -import org.junit.jupiter.api.assertNull -import java.lang.ref.WeakReference +import kotlin.test.Test +import kotlin.test.assertNotEquals +import kotlin.test.assertNotNull +import kotlin.test.assertNull /** * Test lifecycle owner over LifecycleUtils @@ -38,13 +38,13 @@ class GoodPhoneRepairTests { val DI = PhoneComponentStoneComponent() val goodPhone = GoodPhone() DI.inject(goodPhone, goodPhone.lifeCycleOwner, DataStorageSize("64G"), RamSize("4G")) - val batteryRef = WeakReference(goodPhone.battery) - val dataStorageRef = WeakReference(goodPhone.dataStorage) - val ramRef = WeakReference(goodPhone.ram) + val batteryRef = WeakRef(goodPhone.battery) + val dataStorageRef = WeakRef(goodPhone.dataStorage) + val ramRef = WeakRef(goodPhone.ram) //When broke and repair goodPhone.broke() - System.gc() + Memory.gc() DI.inject(goodPhone, DataStorageSize("64G"), RamSize("4G")) //Then: Need new details for repair phone. Old components collected by GC @@ -54,19 +54,19 @@ class GoodPhoneRepairTests { } @Test - @Throws(InterruptedException::class) +// @Throws(InterruptedException::class) fun goodPhoneDropWatterTest() { //Given val DI = PhoneComponentStoneComponent() val goodPhone = GoodPhone() DI.inject(goodPhone, goodPhone.lifeCycleOwner, DataStorageSize("64G"), RamSize("4G")) - val batteryRef = WeakReference(goodPhone.battery) - val dataStorageRef = WeakReference(goodPhone.dataStorage) - val ramRef = WeakReference(goodPhone.ram) + val batteryRef = WeakRef(goodPhone.battery) + val dataStorageRef = WeakRef(goodPhone.dataStorage) + val ramRef = WeakRef(goodPhone.ram) //When goodPhone.dropToWater() - System.gc() + Memory.gc() //Then: Phone not link with his components assertNull(goodPhone.battery) @@ -79,8 +79,8 @@ class GoodPhoneRepairTests { assertNotNull(ramRef.get()) //When: After little time - Thread.sleep(120) - System.gc() +// Thread.sleep(120) + Memory.gc() //Then: Phone can not be repaired, components lost assertNull(batteryRef.get()) @@ -90,7 +90,7 @@ class GoodPhoneRepairTests { @Test - @Throws(InterruptedException::class) +// @Throws(InterruptedException::class) fun goodPhoneDrownedRepairTest() { //Given val DI = PhoneComponentStoneComponent() @@ -100,8 +100,8 @@ class GoodPhoneRepairTests { //When goodPhone.dropToWater() - Thread.sleep(10) - System.gc() +// Thread.sleep(10) + Memory.gc() DI.inject(goodPhone, goodPhone.lifeCycleOwner, DataStorageSize("64G"), RamSize("4G")) //Then: Can be repair after little time @@ -110,7 +110,7 @@ class GoodPhoneRepairTests { @Test - @Throws(InterruptedException::class) +// @Throws(InterruptedException::class) fun goodPhoneDeepDrownedRepairTest() { //Given val DI = PhoneComponentStoneComponent() @@ -120,8 +120,8 @@ class GoodPhoneRepairTests { //When goodPhone.dropToWater() - Thread.sleep(120) - System.gc() +// Thread.sleep(120) + Memory.gc() DI.inject(goodPhone, goodPhone.lifeCycleOwner, DataStorageSize("64G"), RamSize("4G")) //Then: Can not be repair without new details diff --git a/tests/src/test/java/com/github/klee0kai/stone/test/lifecycle/OnePhoneRepairTests.kt b/tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/lifecycle/OnePhoneRepairTests.kt similarity index 73% rename from tests/src/test/java/com/github/klee0kai/stone/test/lifecycle/OnePhoneRepairTests.kt rename to tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/lifecycle/OnePhoneRepairTests.kt index b0621efe..cc799d0b 100644 --- a/tests/src/test/java/com/github/klee0kai/stone/test/lifecycle/OnePhoneRepairTests.kt +++ b/tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/lifecycle/OnePhoneRepairTests.kt @@ -1,14 +1,11 @@ package com.github.klee0kai.stone.test.lifecycle +import com.github.klee0kai.stone.weakref.Memory +import com.github.klee0kai.stone.weakref.WeakRef import com.github.klee0kai.test.di.base_phone.PhoneComponentStoneComponent import com.github.klee0kai.test.tech.phone.OnePhone -import org.junit.jupiter.api.Assertions.assertEquals -import org.junit.jupiter.api.Assertions.assertNotEquals -import org.junit.jupiter.api.Test -import org.junit.jupiter.api.assertNotNull -import org.junit.jupiter.api.assertNull -import java.lang.ref.WeakReference import java.util.* +import kotlin.test.* /** * Test lifecycle owner implemented in providing model @@ -36,13 +33,13 @@ class OnePhoneRepairTests { val DI = PhoneComponentStoneComponent() val onePhone: OnePhone = OnePhone() DI.inject(onePhone) - val batteryRef = WeakReference(onePhone.battery) - val dataStorageRef = WeakReference(onePhone.dataStorage) - val ramRef = WeakReference(onePhone.ram) + val batteryRef = WeakRef(onePhone.battery) + val dataStorageRef = WeakRef(onePhone.dataStorage) + val ramRef = WeakRef(onePhone.ram) //When onePhone.broke() - System.gc() + Memory.gc() DI.inject(onePhone) //Then: Need new details for repair phone. Old components collected by GC @@ -58,13 +55,13 @@ class OnePhoneRepairTests { val DI = PhoneComponentStoneComponent() val onePhone: OnePhone = OnePhone() DI.inject(onePhone) - val batteryRef = WeakReference(onePhone.battery) - val dataStorageRef = WeakReference(onePhone.dataStorage) - val ramRef = WeakReference(onePhone.ram) + val batteryRef = WeakRef(onePhone.battery) + val dataStorageRef = WeakRef(onePhone.dataStorage) + val ramRef = WeakRef(onePhone.ram) //When onePhone.dropToWatter() - System.gc() + Memory.gc() //Then: Phone not link with his components assertNull(onePhone.battery) @@ -77,8 +74,8 @@ class OnePhoneRepairTests { assertNotNull(ramRef.get()) //When: After little time - Thread.sleep(120) - System.gc() +// Thread.sleep(120) + Memory.gc() //Then: Phone can not be repaired, components lost assertNull(batteryRef.get()) @@ -88,18 +85,18 @@ class OnePhoneRepairTests { @Test - @Throws(InterruptedException::class) +// @Throws(InterruptedException::class) fun onePhoneDrownedRepairTest() { //Given val DI = PhoneComponentStoneComponent() val onePhone: OnePhone = OnePhone() DI.inject(onePhone) - val ramUuid: UUID = onePhone.dataStorage!!.uuid + val ramUuid: String = onePhone.dataStorage!!.uuid //When onePhone.dropToWatter() - Thread.sleep(10) - System.gc() +// Thread.sleep(10) + Memory.gc() DI.inject(onePhone) //Then: Can be repair after little time @@ -108,18 +105,18 @@ class OnePhoneRepairTests { @Test - @Throws(InterruptedException::class) +// @Throws(InterruptedException::class) fun onePhoneDeepDrownedRepairTest() { //Given val DI = PhoneComponentStoneComponent() val onePhone: OnePhone = OnePhone() DI.inject(onePhone) - val ramUuid: UUID = onePhone.dataStorage!!.uuid + val ramUuid: String = onePhone.dataStorage!!.uuid //When onePhone.dropToWatter() - Thread.sleep(120) - System.gc() +// Thread.sleep(120) + Memory.gc() DI.inject(onePhone) //Then: Can not be repair without new details diff --git a/tests/src/test/java/com/github/klee0kai/stone/test/moduleinit/BeginOfBegins2Tests.kt b/tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/moduleinit/BeginOfBegins2Tests.kt similarity index 97% rename from tests/src/test/java/com/github/klee0kai/stone/test/moduleinit/BeginOfBegins2Tests.kt rename to tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/moduleinit/BeginOfBegins2Tests.kt index 79a5afba..5904c9a0 100644 --- a/tests/src/test/java/com/github/klee0kai/stone/test/moduleinit/BeginOfBegins2Tests.kt +++ b/tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/moduleinit/BeginOfBegins2Tests.kt @@ -10,6 +10,8 @@ import com.github.klee0kai.test.mowgli.identity.Ideology import com.github.klee0kai.test.mowgli.identity.Knowledge import org.junit.jupiter.api.Assertions.assertEquals import org.junit.jupiter.api.Test +import kotlin.test.Test +import kotlin.test.assertEquals class BeginOfBegins2Tests { diff --git a/tests/src/test/java/com/github/klee0kai/stone/test/moduleinit/BeginOfBeginsTests.kt b/tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/moduleinit/BeginOfBeginsTests.kt similarity index 83% rename from tests/src/test/java/com/github/klee0kai/stone/test/moduleinit/BeginOfBeginsTests.kt rename to tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/moduleinit/BeginOfBeginsTests.kt index a2f6de64..83f9326f 100644 --- a/tests/src/test/java/com/github/klee0kai/stone/test/moduleinit/BeginOfBeginsTests.kt +++ b/tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/moduleinit/BeginOfBeginsTests.kt @@ -2,10 +2,9 @@ package com.github.klee0kai.stone.test.moduleinit import com.github.klee0kai.test.di.base_forest.ForestComponentStoneComponent import com.github.klee0kai.test.di.base_forest.UnitedModule -import com.github.klee0kai.test.mowgli.community.History import com.github.klee0kai.test.mowgli.galaxy.Earth -import org.junit.jupiter.api.Assertions.assertEquals -import org.junit.jupiter.api.Test +import kotlin.test.Test +import kotlin.test.assertEquals class BeginOfBeginsTests { diff --git a/tests/src/test/java/com/github/klee0kai/stone/test/parameterized/WireTest.kt b/tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/parameterized/WireTest.kt similarity index 90% rename from tests/src/test/java/com/github/klee0kai/stone/test/parameterized/WireTest.kt rename to tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/parameterized/WireTest.kt index e7e80cc4..b9a23f59 100644 --- a/tests/src/test/java/com/github/klee0kai/stone/test/parameterized/WireTest.kt +++ b/tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/parameterized/WireTest.kt @@ -7,6 +7,10 @@ import org.junit.jupiter.api.Assertions.assertEquals import org.junit.jupiter.api.Assertions.assertNotEquals import org.junit.jupiter.api.Test import org.junit.jupiter.api.assertNotNull +import kotlin.test.Test +import kotlin.test.assertEquals +import kotlin.test.assertNotEquals +import kotlin.test.assertNotNull class WireTest { @@ -31,7 +35,7 @@ class WireTest { ) } - @org.junit.jupiter.api.Test + @Test fun miniUsbBindTest() { //When val di = WireComponentStoneComponent() diff --git a/tests/src/test/java/com/github/klee0kai/stone/test/types/ListUtilTests.java b/tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/types/ListUtilTests.java similarity index 100% rename from tests/src/test/java/com/github/klee0kai/stone/test/types/ListUtilTests.java rename to tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/types/ListUtilTests.java diff --git a/tests/src/main/java/com/github/klee0kai/test/di/base_phone/identifiers/DataStorageSize.kt b/tests/src/main/java/com/github/klee0kai/test/di/base_phone/identifiers/DataStorageSize.kt deleted file mode 100644 index fbb3d298..00000000 --- a/tests/src/main/java/com/github/klee0kai/test/di/base_phone/identifiers/DataStorageSize.kt +++ /dev/null @@ -1,16 +0,0 @@ -package com.github.klee0kai.test.di.base_phone.identifiers - -import java.util.* - -class DataStorageSize(var size: String?) { - override fun equals(o: Any?): Boolean { - if (this === o) return true - if (o == null || javaClass != o.javaClass) return false - val that = o as DataStorageSize - return size == that.size - } - - override fun hashCode(): Int { - return Objects.hash(size) - } -} diff --git a/tests/src/main/java/com/github/klee0kai/test/di/base_phone/identifiers/PhoneOsVersion.kt b/tests/src/main/java/com/github/klee0kai/test/di/base_phone/identifiers/PhoneOsVersion.kt deleted file mode 100644 index 136a3a64..00000000 --- a/tests/src/main/java/com/github/klee0kai/test/di/base_phone/identifiers/PhoneOsVersion.kt +++ /dev/null @@ -1,16 +0,0 @@ -package com.github.klee0kai.test.di.base_phone.identifiers - -import java.util.* - -class PhoneOsVersion(@JvmField var version: String?) { - override fun equals(o: Any?): Boolean { - if (this === o) return true - if (o == null || javaClass != o.javaClass) return false - val that = o as PhoneOsVersion - return version == that.version - } - - override fun hashCode(): Int { - return Objects.hash(version) - } -} diff --git a/tests/src/main/java/com/github/klee0kai/test/di/base_phone/identifiers/RamSize.kt b/tests/src/main/java/com/github/klee0kai/test/di/base_phone/identifiers/RamSize.kt deleted file mode 100644 index 04db2791..00000000 --- a/tests/src/main/java/com/github/klee0kai/test/di/base_phone/identifiers/RamSize.kt +++ /dev/null @@ -1,16 +0,0 @@ -package com.github.klee0kai.test.di.base_phone.identifiers - -import java.util.* - -class RamSize(var size: String?) { - override fun equals(o: Any?): Boolean { - if (this === o) return true - if (o == null || javaClass != o.javaClass) return false - val that = o as RamSize - return size == that.size - } - - override fun hashCode(): Int { - return Objects.hash(size) - } -} diff --git a/tests/src/main/java/com/github/klee0kai/test/house/House.kt b/tests/src/main/java/com/github/klee0kai/test/house/House.kt deleted file mode 100644 index 89f96246..00000000 --- a/tests/src/main/java/com/github/klee0kai/test/house/House.kt +++ /dev/null @@ -1,12 +0,0 @@ -package com.github.klee0kai.test.house - -import com.github.klee0kai.test.house.kitchen.Kichen -import com.github.klee0kai.test.house.rooms.BathRoom -import com.github.klee0kai.test.house.rooms.BedRoom -import com.github.klee0kai.test.house.rooms.Garage -import java.util.* - -class House(@JvmField val kichen: Kichen?, @JvmField val bathRoom: BathRoom?, @JvmField val bedRoom: BedRoom?, val garage: Garage?) { - @JvmField - var uuid: UUID = UUID.randomUUID() -} diff --git a/tests/src/main/java/com/github/klee0kai/test/house/kitchen/cookingarea/CookingArea.kt b/tests/src/main/java/com/github/klee0kai/test/house/kitchen/cookingarea/CookingArea.kt deleted file mode 100644 index 10b450e0..00000000 --- a/tests/src/main/java/com/github/klee0kai/test/house/kitchen/cookingarea/CookingArea.kt +++ /dev/null @@ -1,7 +0,0 @@ -package com.github.klee0kai.test.house.kitchen.cookingarea - -import java.util.* - -class CookingArea { - var uuid: UUID = UUID.randomUUID() -} diff --git a/tests/src/main/java/com/github/klee0kai/test/house/kitchen/sinkarea/SinkArea.kt b/tests/src/main/java/com/github/klee0kai/test/house/kitchen/sinkarea/SinkArea.kt deleted file mode 100644 index 9164d82c..00000000 --- a/tests/src/main/java/com/github/klee0kai/test/house/kitchen/sinkarea/SinkArea.kt +++ /dev/null @@ -1,7 +0,0 @@ -package com.github.klee0kai.test.house.kitchen.sinkarea - -import java.util.* - -class SinkArea { - var uuid: UUID = UUID.randomUUID() -} diff --git a/tests/src/main/java/com/github/klee0kai/test/house/kitchen/storagearea/Clothes.kt b/tests/src/main/java/com/github/klee0kai/test/house/kitchen/storagearea/Clothes.kt deleted file mode 100644 index 42b4f571..00000000 --- a/tests/src/main/java/com/github/klee0kai/test/house/kitchen/storagearea/Clothes.kt +++ /dev/null @@ -1,7 +0,0 @@ -package com.github.klee0kai.test.house.kitchen.storagearea - -import java.util.* - -class Clothes { - var uuid: UUID = UUID.randomUUID() -} diff --git a/tests/src/main/java/com/github/klee0kai/test/house/kitchen/storagearea/Cookware.kt b/tests/src/main/java/com/github/klee0kai/test/house/kitchen/storagearea/Cookware.kt deleted file mode 100644 index 78c5fc8a..00000000 --- a/tests/src/main/java/com/github/klee0kai/test/house/kitchen/storagearea/Cookware.kt +++ /dev/null @@ -1,7 +0,0 @@ -package com.github.klee0kai.test.house.kitchen.storagearea - -import java.util.* - -class Cookware { - var uuid: UUID = UUID.randomUUID() -} diff --git a/tests/src/main/java/com/github/klee0kai/test/house/kitchen/storagearea/GarageStore.kt b/tests/src/main/java/com/github/klee0kai/test/house/kitchen/storagearea/GarageStore.kt deleted file mode 100644 index dc62174c..00000000 --- a/tests/src/main/java/com/github/klee0kai/test/house/kitchen/storagearea/GarageStore.kt +++ /dev/null @@ -1,3 +0,0 @@ -package com.github.klee0kai.test.house.kitchen.storagearea - -class GarageStore(val cookware: Cookware?, val clothes: Clothes?, val sanitizers: Sanitizers?) diff --git a/tests/src/main/java/com/github/klee0kai/test/house/kitchen/storagearea/StoreArea.kt b/tests/src/main/java/com/github/klee0kai/test/house/kitchen/storagearea/StoreArea.kt deleted file mode 100644 index daf8eb43..00000000 --- a/tests/src/main/java/com/github/klee0kai/test/house/kitchen/storagearea/StoreArea.kt +++ /dev/null @@ -1,5 +0,0 @@ -package com.github.klee0kai.test.house.kitchen.storagearea - -import com.github.klee0kai.test.house.identifiers.StoreAreaType - -class StoreArea(@JvmField val type: StoreAreaType?, val cookware: Cookware?, val clothes: Clothes?, @JvmField val sanitizers: Sanitizers?) diff --git a/tests/src/main/java/com/github/klee0kai/test/house/rooms/BathRoom.kt b/tests/src/main/java/com/github/klee0kai/test/house/rooms/BathRoom.kt deleted file mode 100644 index c2559434..00000000 --- a/tests/src/main/java/com/github/klee0kai/test/house/rooms/BathRoom.kt +++ /dev/null @@ -1,8 +0,0 @@ -package com.github.klee0kai.test.house.rooms - -import com.github.klee0kai.test.house.kitchen.storagearea.StoreArea -import java.util.* - -class BathRoom(@JvmField val storeArea: StoreArea?) { - var uuid: UUID = UUID.randomUUID() -} diff --git a/tests/src/main/java/com/github/klee0kai/test/house/rooms/BedRoom.kt b/tests/src/main/java/com/github/klee0kai/test/house/rooms/BedRoom.kt deleted file mode 100644 index f3f8ab38..00000000 --- a/tests/src/main/java/com/github/klee0kai/test/house/rooms/BedRoom.kt +++ /dev/null @@ -1,8 +0,0 @@ -package com.github.klee0kai.test.house.rooms - -import com.github.klee0kai.test.house.kitchen.storagearea.StoreArea -import java.util.* - -class BedRoom(@JvmField val storeArea: StoreArea?) { - var uuid: UUID = UUID.randomUUID() -} diff --git a/tests/src/main/java/com/github/klee0kai/test/mowgli/body/Blood.kt b/tests/src/main/java/com/github/klee0kai/test/mowgli/body/Blood.kt deleted file mode 100644 index 6a2c11e5..00000000 --- a/tests/src/main/java/com/github/klee0kai/test/mowgli/body/Blood.kt +++ /dev/null @@ -1,15 +0,0 @@ -package com.github.klee0kai.test.mowgli.body - -import java.awt.Color -import java.util.* - -class Blood(color: Color?) { - - var uuid: UUID = UUID.randomUUID() - - var color: Color? = null - - init { - this.color = color - } -} diff --git a/tests/src/main/java/com/github/klee0kai/test/mowgli/community/History.kt b/tests/src/main/java/com/github/klee0kai/test/mowgli/community/History.kt deleted file mode 100644 index 91cbd250..00000000 --- a/tests/src/main/java/com/github/klee0kai/test/mowgli/community/History.kt +++ /dev/null @@ -1,7 +0,0 @@ -package com.github.klee0kai.test.mowgli.community - -import java.util.* - -class History { - var uuid: UUID = UUID.randomUUID() -} diff --git a/tests/src/main/java/com/github/klee0kai/test/mowgli/earth/Mountain.kt b/tests/src/main/java/com/github/klee0kai/test/mowgli/earth/Mountain.kt deleted file mode 100644 index caac4544..00000000 --- a/tests/src/main/java/com/github/klee0kai/test/mowgli/earth/Mountain.kt +++ /dev/null @@ -1,8 +0,0 @@ -package com.github.klee0kai.test.mowgli.earth - -import java.util.* - -class Mountain : IMountain { - @JvmField - var uuid: UUID = UUID.randomUUID() -} diff --git a/tests/src/main/java/com/github/klee0kai/test/mowgli/earth/River.kt b/tests/src/main/java/com/github/klee0kai/test/mowgli/earth/River.kt deleted file mode 100644 index 9613f0ff..00000000 --- a/tests/src/main/java/com/github/klee0kai/test/mowgli/earth/River.kt +++ /dev/null @@ -1,7 +0,0 @@ -package com.github.klee0kai.test.mowgli.earth - -import java.util.* - -open class River : IRiver { - open var uuid: UUID = UUID.randomUUID() -} diff --git a/tests/src/main/java/com/github/klee0kai/test/mowgli/galaxy/Earth.kt b/tests/src/main/java/com/github/klee0kai/test/mowgli/galaxy/Earth.kt deleted file mode 100644 index 67e485a5..00000000 --- a/tests/src/main/java/com/github/klee0kai/test/mowgli/galaxy/Earth.kt +++ /dev/null @@ -1,8 +0,0 @@ -package com.github.klee0kai.test.mowgli.galaxy - -import java.util.* - -class Earth : IPlanet { - @JvmField - var uuid: UUID = UUID.randomUUID() -} diff --git a/tests/src/main/java/com/github/klee0kai/test/mowgli/galaxy/Mercury.kt b/tests/src/main/java/com/github/klee0kai/test/mowgli/galaxy/Mercury.kt deleted file mode 100644 index 6785f9ea..00000000 --- a/tests/src/main/java/com/github/klee0kai/test/mowgli/galaxy/Mercury.kt +++ /dev/null @@ -1,7 +0,0 @@ -package com.github.klee0kai.test.mowgli.galaxy - -import java.util.* - -class Mercury : IPlanet { - var uuid: UUID = UUID.randomUUID() -} diff --git a/tests/src/main/java/com/github/klee0kai/test/mowgli/galaxy/Saturn.kt b/tests/src/main/java/com/github/klee0kai/test/mowgli/galaxy/Saturn.kt deleted file mode 100644 index 50035452..00000000 --- a/tests/src/main/java/com/github/klee0kai/test/mowgli/galaxy/Saturn.kt +++ /dev/null @@ -1,8 +0,0 @@ -package com.github.klee0kai.test.mowgli.galaxy - -import java.util.* - -class Saturn : IPlanet { - @JvmField - var uuid: UUID = UUID.randomUUID() -} diff --git a/tests/src/main/java/com/github/klee0kai/test/mowgli/galaxy/Sun.kt b/tests/src/main/java/com/github/klee0kai/test/mowgli/galaxy/Sun.kt deleted file mode 100644 index f5812947..00000000 --- a/tests/src/main/java/com/github/klee0kai/test/mowgli/galaxy/Sun.kt +++ /dev/null @@ -1,8 +0,0 @@ -package com.github.klee0kai.test.mowgli.galaxy - -import java.util.* - -class Sun : IStar { - @JvmField - var uuid: UUID = UUID.randomUUID() -} diff --git a/tests/src/main/java/com/github/klee0kai/test/mowgli/identity/Conscience.kt b/tests/src/main/java/com/github/klee0kai/test/mowgli/identity/Conscience.kt deleted file mode 100644 index 9a4c9a02..00000000 --- a/tests/src/main/java/com/github/klee0kai/test/mowgli/identity/Conscience.kt +++ /dev/null @@ -1,11 +0,0 @@ -package com.github.klee0kai.test.mowgli.identity - -import java.util.* - -class Conscience { - @JvmField - var uuid: UUID = UUID.randomUUID() - - val isOldConscience: Boolean - get() = false -} diff --git a/tests/src/main/java/com/github/klee0kai/test/mowgli/identity/Ideology.kt b/tests/src/main/java/com/github/klee0kai/test/mowgli/identity/Ideology.kt deleted file mode 100644 index 00f875cf..00000000 --- a/tests/src/main/java/com/github/klee0kai/test/mowgli/identity/Ideology.kt +++ /dev/null @@ -1,10 +0,0 @@ -package com.github.klee0kai.test.mowgli.identity - -import java.util.* - -open class Ideology { - open var uuid: UUID = UUID.randomUUID() - - open val isFamilyIdeology: Boolean get() = false - -} diff --git a/tests/src/main/java/com/github/klee0kai/test/mowgli/identity/Knowledge.kt b/tests/src/main/java/com/github/klee0kai/test/mowgli/identity/Knowledge.kt deleted file mode 100644 index e8ff29df..00000000 --- a/tests/src/main/java/com/github/klee0kai/test/mowgli/identity/Knowledge.kt +++ /dev/null @@ -1,12 +0,0 @@ -package com.github.klee0kai.test.mowgli.identity - -import java.util.* - -open class Knowledge { - @JvmField - var uuid: UUID = UUID.randomUUID() - - - open val isOldKnowledge: Boolean - get() = false -} diff --git a/tests/src/main/java/com/github/klee0kai/test/tech/components/Battery.kt b/tests/src/main/java/com/github/klee0kai/test/tech/components/Battery.kt deleted file mode 100644 index 66a5a6ac..00000000 --- a/tests/src/main/java/com/github/klee0kai/test/tech/components/Battery.kt +++ /dev/null @@ -1,8 +0,0 @@ -package com.github.klee0kai.test.tech.components - -import java.util.* - -class Battery { - @JvmField - val uuid: UUID = UUID.randomUUID() -} diff --git a/tests/src/test/java/com/github/klee0kai/stone/test/gc/EarthLastDayTests.kt b/tests/src/test/java/com/github/klee0kai/stone/test/gc/EarthLastDayTests.kt deleted file mode 100644 index fb313122..00000000 --- a/tests/src/test/java/com/github/klee0kai/stone/test/gc/EarthLastDayTests.kt +++ /dev/null @@ -1,281 +0,0 @@ -package com.github.klee0kai.stone.test.gc - -import com.github.klee0kai.test.di.gcforest.GcGodComponentStoneComponent -import org.junit.jupiter.api.Test -import org.junit.jupiter.api.assertNotNull -import org.junit.jupiter.api.assertNull -import java.lang.ref.WeakReference - -class EarthLastDayTests { - - @Test - fun gcAllTest() { - //Given - val di = GcGodComponentStoneComponent() - val mountainStrong = WeakReference(di.earth().mountainStrong()) - val mountainSoft = WeakReference(di.earth().mountainSoft()) - val mountainWeak = WeakReference(di.earth().mountainWeak()) - val mountainDef = WeakReference(di.earth().mountainDefaultFactory()) - val mountainDef2 = WeakReference(di.earth().mountainDefault2Factory()) - val riverStrong = WeakReference(di.earth().riverStrong()) - val riverSoft = WeakReference(di.earth().riverSoft()) - val riverWeak = WeakReference(di.earth().riverWeak()) - val riverDef = WeakReference(di.earth().riverDefaultSoft()) - - //When - di.gcAll() - - //Then - for (ref in listOf( - mountainStrong, mountainSoft, mountainDef2, mountainWeak, mountainDef, - riverStrong, riverSoft, riverWeak, riverDef - )) { - assertNull(ref.get()) - } - } - - @Test - fun gcStrongTest() { - //Given - val di = GcGodComponentStoneComponent() - val mountainStrong = WeakReference(di.earth().mountainStrong()) - val mountainSoft = WeakReference(di.earth().mountainSoft()) - val mountainWeak = WeakReference(di.earth().mountainWeak()) - val mountainDef = WeakReference(di.earth().mountainDefaultFactory()) - val mountainDef2 = WeakReference(di.earth().mountainDefault2Factory()) - val riverStrong = WeakReference(di.earth().riverStrong()) - val riverSoft = WeakReference(di.earth().riverSoft()) - val riverWeak = WeakReference(di.earth().riverWeak()) - val riverDef = WeakReference(di.earth().riverDefaultSoft()) - - //When - di.gcStrong() - - //Then - for (ref in listOf( - mountainStrong, mountainWeak, mountainDef, mountainDef2, - riverStrong, riverWeak, riverDef - )) { - assertNull(ref.get()) - } - - for (ref in listOf( - mountainSoft, - riverSoft - )) { - assertNotNull(ref.get()) - } - } - - @Test - fun gcSoftTest() { - //Given - val di = GcGodComponentStoneComponent() - val mountainStrong = WeakReference(di.earth().mountainStrong()) - val mountainSoft = WeakReference(di.earth().mountainSoft()) - val mountainWeak = WeakReference(di.earth().mountainWeak()) - val mountainDef = WeakReference(di.earth().mountainDefaultFactory()) - val mountainDef2 = WeakReference(di.earth().mountainDefault2Factory()) - val riverStrong = WeakReference(di.earth().riverStrong()) - val riverSoft = WeakReference(di.earth().riverSoft()) - val riverWeak = WeakReference(di.earth().riverWeak()) - val riverDef = WeakReference(di.earth().riverDefaultSoft()) - - //When - di.gcSoft() - - //Then - for (ref in listOf( - mountainSoft, mountainWeak, mountainDef, mountainDef2, - riverSoft, riverWeak, riverDef - )) { - assertNull(ref.get()) - } - for (ref in listOf( - mountainStrong, - riverStrong - )) { - assertNotNull(ref.get()) - } - } - - @Test - fun gcWeakTest() { - //Given - val di = GcGodComponentStoneComponent() - val mountainStrong = WeakReference(di.earth().mountainStrong()) - val mountainSoft = WeakReference(di.earth().mountainSoft()) - val mountainWeak = WeakReference(di.earth().mountainWeak()) - val mountainDef = WeakReference(di.earth().mountainDefaultFactory()) - val riverStrong = WeakReference(di.earth().riverStrong()) - val riverSoft = WeakReference(di.earth().riverSoft()) - val riverWeak = WeakReference(di.earth().riverWeak()) - val riverDef = WeakReference(di.earth().riverDefaultSoft()) - - //When - di.gcWeak() - - //Then - for (ref in listOf( - mountainWeak, mountainDef, - riverWeak, riverDef - )) { - assertNull(ref.get()) - } - for (ref in listOf( - mountainStrong, mountainSoft, - riverStrong, riverSoft - )) { - assertNotNull(ref.get()) - } - } - - @Test - fun gcMountainTest() { - //Given - val di = GcGodComponentStoneComponent() - val mountainStrong = WeakReference(di.earth().mountainStrong()) - val mountainSoft = WeakReference(di.earth().mountainSoft()) - val mountainWeak = WeakReference(di.earth().mountainWeak()) - val mountainDef = WeakReference(di.earth().mountainDefaultFactory()) - val riverStrong = WeakReference(di.earth().riverStrong()) - val riverSoft = WeakReference(di.earth().riverSoft()) - val riverWeak = WeakReference(di.earth().riverWeak()) - val riverDef = WeakReference(di.earth().riverDefaultSoft()) - - //When - di.gcMountains() - - //Then - for (ref in listOf( - mountainStrong, mountainSoft, mountainWeak, mountainDef, - riverWeak, riverDef - )) { - assertNull(ref.get()) - } - for (ref in listOf( - riverStrong, riverSoft - )) { - assertNotNull(ref.get()) - } - } - - @Test - fun gcRiverTest() { - //Given - val di = GcGodComponentStoneComponent() - val mountainStrong = WeakReference(di.earth().mountainStrong()) - val mountainSoft = WeakReference(di.earth().mountainSoft()) - val mountainWeak = WeakReference(di.earth().mountainWeak()) - val mountainDef = WeakReference(di.earth().mountainDefaultFactory()) - val riverStrong = WeakReference(di.earth().riverStrong()) - val riverSoft = WeakReference(di.earth().riverSoft()) - val riverWeak = WeakReference(di.earth().riverWeak()) - val riverDef = WeakReference(di.earth().riverDefaultSoft()) - - //When - di.gcRivers() - - //Then - for (ref in listOf( - mountainWeak, mountainDef, - riverStrong, riverSoft, riverWeak, riverDef - )) { - assertNull(ref.get()) - } - for (ref in listOf( - mountainStrong, mountainSoft - )) { - assertNotNull(ref.get()) - } - } - - @Test - fun gcMountainAndRiverTest() { - //Given - val di = GcGodComponentStoneComponent() - val mountainStrong = WeakReference(di.earth().mountainStrong()) - val mountainSoft = WeakReference(di.earth().mountainSoft()) - val mountainWeak = WeakReference(di.earth().mountainWeak()) - val mountainDef = WeakReference(di.earth().mountainDefaultFactory()) - val riverStrong = WeakReference(di.earth().riverStrong()) - val riverSoft = WeakReference(di.earth().riverSoft()) - val riverWeak = WeakReference(di.earth().riverWeak()) - val riverDef = WeakReference(di.earth().riverDefaultSoft()) - - //When - di.gcMountainsAndRivers() - - //Then - for (ref in listOf( - mountainStrong, mountainSoft, mountainWeak, mountainDef, - riverStrong, riverSoft, riverWeak, riverDef - )) { - assertNull(ref.get()) - } - } - - - @Test - fun gcSoftMountainTest() { - //Given - val di = GcGodComponentStoneComponent() - val mountainStrong = WeakReference(di.earth().mountainStrong()) - val mountainSoft = WeakReference(di.earth().mountainSoft()) - val mountainWeak = WeakReference(di.earth().mountainWeak()) - val mountainDef = WeakReference(di.earth().mountainDefaultFactory()) - val riverStrong = WeakReference(di.earth().riverStrong()) - val riverSoft = WeakReference(di.earth().riverSoft()) - val riverWeak = WeakReference(di.earth().riverWeak()) - val riverDef = WeakReference(di.earth().riverDefaultSoft()) - - //When - di.gcSoftMountains() - - //Then - for (ref in listOf( - mountainSoft, mountainWeak, mountainDef, - riverWeak, riverDef - )) { - assertNull(ref.get()) - } - for (ref in listOf( - mountainStrong, - riverStrong, riverSoft - )) { - assertNotNull(ref.get()) - } - } - - @Test - fun gcStrongMountainTest() { - //Given - val di = GcGodComponentStoneComponent() - val mountainStrong = WeakReference(di.earth().mountainStrong()) - val mountainSoft = WeakReference(di.earth().mountainSoft()) - val mountainWeak = WeakReference(di.earth().mountainWeak()) - val mountainDef = WeakReference(di.earth().mountainDefaultFactory()) - val riverStrong = WeakReference(di.earth().riverStrong()) - val riverSoft = WeakReference(di.earth().riverSoft()) - val riverWeak = WeakReference(di.earth().riverWeak()) - val riverDef = WeakReference(di.earth().riverDefaultSoft()) - - //When - di.gcStrongMountains() - - //Then - for (ref in listOf( - mountainStrong, mountainWeak, mountainDef, - riverWeak, riverDef - )) { - assertNull(ref.get()) - } - for (ref in listOf( - mountainSoft, - riverStrong, riverSoft - )) { - assertNotNull(ref.get()) - } - } - -} diff --git a/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/mowgli/earth/WaterFlow.kt b/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/mowgli/earth/WaterFlow.kt index 9acb5a69..1edc5a30 100644 --- a/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/mowgli/earth/WaterFlow.kt +++ b/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/mowgli/earth/WaterFlow.kt @@ -1,8 +1,11 @@ +@file:OptIn(ExperimentalUuidApi::class) + package com.github.klee0kai.test_ext.inject.mowgli.earth import com.github.klee0kai.test.mowgli.earth.River -import java.util.* +import kotlin.uuid.ExperimentalUuidApi +import kotlin.uuid.Uuid class WaterFlow : River() { - override var uuid: UUID = UUID.randomUUID() + override var uuid: String = Uuid.random().toString() } diff --git a/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/tech/components/DDR3Ram.kt b/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/tech/components/DDR3Ram.kt index bf06208e..1f6462e0 100644 --- a/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/tech/components/DDR3Ram.kt +++ b/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/tech/components/DDR3Ram.kt @@ -1,12 +1,15 @@ +@file:OptIn(ExperimentalUuidApi::class) + package com.github.klee0kai.test_ext.inject.tech.components import com.github.klee0kai.test.di.base_phone.identifiers.RamSize import com.github.klee0kai.test.tech.components.Ram import com.github.klee0kai.test_ext.inject.di.techfactory.identifiers.Frequency -import java.util.* +import kotlin.uuid.ExperimentalUuidApi +import kotlin.uuid.Uuid class DDR3Ram : Ram { - override val uuid: UUID = UUID.randomUUID() + override val uuid: String = Uuid.random().toString() val frequency: String? From 4052b10f5002d024e229627842d1daaf175d6411 Mon Sep 17 00:00:00 2001 From: klee0kai Date: Fri, 20 Feb 2026 23:40:58 +0100 Subject: [PATCH 111/122] short multiplatform fixs --- .../ksp/helpers/invokecall/model/QualifierAnn.kt | 3 ++- .../thekey/stone/ksp/helpers/wrap/WrapHelper.kt | 2 +- .../thekey/stone/ksp/ksp/AnnotationProtectedExt.kt | 14 ++++++++++++++ .../hiddenmodule/GenHiddenModuleProcessor.kt | 5 +++-- .../stone/ksp/target/module/GenModuleProcessor.kt | 11 ++++++----- .../klee0kai/test/di/base_phone/PhoneComponent.kt | 1 + .../bindinstance/simple/GodWorkspaceComponent.kt | 4 +++- .../com/github/klee0kai/test/mowgli/earth/Cave.kt | 3 +++ .../bindinstance/simple/GodFirstWorkDayTest.kt | 10 +++++----- .../bindinstance/simple_inject/SevenPlanetTests.kt | 1 - .../MoonSkyProtectInjectedTests.kt | 4 ---- .../bindinstance/solarsystem/SolarSystemTests.kt | 3 --- .../klee0kai/stone/test/cache/EarthCacheTests.kt | 3 --- .../klee0kai/stone/test/deps/HouseFactoryTests.kt | 3 --- .../github/klee0kai/stone/test/deps/HouseTests.kt | 11 +---------- .../klee0kai/stone/test/deps/InHouseTests.kt | 10 +--------- .../klee0kai/stone/test/gc/EarthLastDayTests.kt | 4 ---- .../klee0kai/stone/test/gc/GodLastWorkDayTests.kt | 4 ---- .../stone/test/identifiers/GoodPhoneInjectTests.kt | 2 -- .../test/identifiers/MultiIdentifiersTests.kt | 2 -- .../stone/test/identifiers/TechComponentsTests.kt | 3 --- .../test/identifiers/TechFactoryComponentTests.kt | 4 ---- .../stone/test/identifiers/TechFactoryTests.kt | 2 -- .../test/identifiers/TechFactoryWrappersTests.kt | 4 ---- .../klee0kai/stone/test/inject/HorseInjectTests.kt | 3 --- .../stone/test/inject/HorseProtectInjectTests.kt | 5 +++-- .../test/inject/MowgliInjectMethodWrappersTests.kt | 1 - .../stone/test/inject/MowgliInjectWrappersTests.kt | 2 -- .../inject/SchoolProtectInjectWrappersTests.kt | 4 ---- .../stone/test/lifecycle/GoodPhoneRepairTests.kt | 6 +----- .../stone/test/moduleinit/BeginOfBegins2Tests.kt | 2 -- .../klee0kai/stone/test/parameterized/WireTest.kt | 4 ---- .../simple/GodWorkspaceComponent.js.kt | 3 +++ .../simple/GodWorkspaceComponent.jvm.kt | 5 +++++ 34 files changed, 52 insertions(+), 96 deletions(-) create mode 100644 stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/ksp/AnnotationProtectedExt.kt create mode 100644 tests/src/jsMain/kotlin/com/github/klee0kai/test/di/bindinstance/simple/GodWorkspaceComponent.js.kt create mode 100644 tests/src/jvmMain/kotlin/com/github/klee0kai/test/di/bindinstance/simple/GodWorkspaceComponent.jvm.kt diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/invokecall/model/QualifierAnn.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/invokecall/model/QualifierAnn.kt index 542245e6..1ecd8d77 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/invokecall/model/QualifierAnn.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/invokecall/model/QualifierAnn.kt @@ -1,6 +1,7 @@ package com.github.klee0kai.thekey.stone.ksp.helpers.invokecall.model import com.github.klee0kai.stone.annotations.qualifier.IgnoreQualifier +import com.github.klee0kai.thekey.stone.ksp.ksp.resolveAlias import com.google.devtools.ksp.symbol.KSAnnotation import com.squareup.kotlinpoet.ClassName import com.squareup.kotlinpoet.TypeName @@ -23,7 +24,7 @@ fun QualifierAnn.Companion.ignoreQualifier( fun KSAnnotation.toQualifierAnn( ) = QualifierAnn( - typeName = annotationType.resolve().toClassName(), + typeName = annotationType.resolveAlias().toClassName(), values = arguments.map { it.name?.asString()!! to it.value }.groupBy { it.first }, ) diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/wrap/WrapHelper.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/wrap/WrapHelper.kt index 1388feb8..3ad43f0a 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/wrap/WrapHelper.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/wrap/WrapHelper.kt @@ -223,7 +223,6 @@ class WrapHelper { for (cl in listOf( WeakRef::class, SoftRef::class, - Ref::class, )) { val creator = cl.asClassName() @@ -281,6 +280,7 @@ class WrapHelper { for (cl in listOf( PhantomProvide::class, + Ref::class, Provider::class, LazyProvide::class, AsyncCoroutineProvide::class diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/ksp/AnnotationProtectedExt.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/ksp/AnnotationProtectedExt.kt new file mode 100644 index 00000000..d99e2638 --- /dev/null +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/ksp/AnnotationProtectedExt.kt @@ -0,0 +1,14 @@ +package com.github.klee0kai.thekey.stone.ksp.ksp + +import com.github.klee0kai.stone.annotations.module.BindInstance +import com.github.klee0kai.stone.annotations.module.Provide + +/** + * fix crash at :tests:kspKotlinWasmJs + */ +val Provide.cacheProtected get() = runCatching { cache }.getOrNull() ?: Provide.CacheType.Factory + +/** + * fix crash at :tests:kspKotlinWasmJs + */ +val BindInstance.cacheProtected get() = runCatching { cache }.getOrNull() ?: BindInstance.CacheType.Soft \ No newline at end of file diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/hiddenmodule/GenHiddenModuleProcessor.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/hiddenmodule/GenHiddenModuleProcessor.kt index bbab773c..5b58934d 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/hiddenmodule/GenHiddenModuleProcessor.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/hiddenmodule/GenHiddenModuleProcessor.kt @@ -21,6 +21,7 @@ import com.github.klee0kai.thekey.stone.ksp.helpers.wrap.WrapHelper import com.github.klee0kai.thekey.stone.ksp.ksp.arch.GenSpec import com.github.klee0kai.thekey.stone.ksp.ksp.arch.SymbolsToProcess import com.github.klee0kai.thekey.stone.ksp.ksp.arch.TargetFileProcessor +import com.github.klee0kai.thekey.stone.ksp.ksp.cacheProtected import com.github.klee0kai.thekey.stone.ksp.ksp.getAllMethods import com.github.klee0kai.thekey.stone.ksp.ksp.resolveNotNullable import com.github.klee0kai.thekey.stone.ksp.poet.* @@ -115,10 +116,10 @@ class GenHiddenModuleProcessor : TargetFileProcessor { fieldName = "${function.simpleName.asString()}$itemHolderIdx", returnType = returnType, idArguments = idArguments, - cacheType = bindAnn.cache.toItemCacheType(), + cacheType = bindAnn.cacheProtected.toItemCacheType(), wrapHelper = wrapHelper, ) - gcScopes += bindAnn.cache.toItemCacheType().gcScopeClassName + gcScopes += bindAnn.cacheProtected.toItemCacheType().gcScopeClassName codeBlocks.switchRefStatementBuilders.getOrPut(gcScopes) { CodeBlock.builder() } .add(itemHolderCodeHelper.statementSwitchRef(CodeBlock.of("__params"))) diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/module/GenModuleProcessor.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/module/GenModuleProcessor.kt index b588aba1..36247089 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/module/GenModuleProcessor.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/module/GenModuleProcessor.kt @@ -24,6 +24,7 @@ import com.github.klee0kai.thekey.stone.ksp.helpers.wrap.WrapHelper import com.github.klee0kai.thekey.stone.ksp.ksp.arch.GenSpec import com.github.klee0kai.thekey.stone.ksp.ksp.arch.SymbolsToProcess import com.github.klee0kai.thekey.stone.ksp.ksp.arch.TargetFileProcessor +import com.github.klee0kai.thekey.stone.ksp.ksp.cacheProtected import com.github.klee0kai.thekey.stone.ksp.ksp.getAllMethods import com.github.klee0kai.thekey.stone.ksp.ksp.resolveNotNullable import com.github.klee0kai.thekey.stone.ksp.poet.* @@ -144,10 +145,10 @@ class GenModuleProcessor : TargetFileProcessor { fieldName = "${function.simpleName.asString()}$holderIdx", returnType = returnType, idArguments = idArguments, - cacheType = bindAnn.cache.toItemCacheType(), + cacheType = bindAnn.cacheProtected.toItemCacheType(), wrapHelper = wrapHelper, ) - gcScopes += bindAnn.cache.toItemCacheType().gcScopeClassName + gcScopes += bindAnn.cacheProtected.toItemCacheType().gcScopeClassName codeBlocks.switchRefStatementBuilders.getOrPut(gcScopes) { CodeBlock.builder() } .add(itemHolderCodeHelper.statementSwitchRef(CodeBlock.of("__params"))) @@ -184,7 +185,7 @@ class GenModuleProcessor : TargetFileProcessor { } - provideAnn == null || provideAnn.cache == Provide.CacheType.Factory -> { + provideAnn == null || provideAnn.cacheProtected == Provide.CacheType.Factory -> { genOverrideFun(function) { addStatement( "return %L.%L(%L)", factoryFieldName, @@ -210,10 +211,10 @@ class GenModuleProcessor : TargetFileProcessor { fieldName = "${function.simpleName.asString()}$holderIdx", returnType = returnType, idArguments = idArguments, - cacheType = provideAnn.cache.toItemCacheType() ?: return@forEachFun, + cacheType = provideAnn.cacheProtected.toItemCacheType() ?: return@forEachFun, wrapHelper = wrapHelper, ) - gcScopes += provideAnn.cache.toItemCacheType()!!.gcScopeClassName + gcScopes += provideAnn.cacheProtected.toItemCacheType()!!.gcScopeClassName codeBlocks.switchRefStatementBuilders.getOrPut(gcScopes) { CodeBlock.builder() } .add(itemHolderCodeHelper.statementSwitchRef(CodeBlock.of("__params"))) codeBlocks.clearNullsMethodBody.add(itemHolderCodeHelper.clearNullsStatement()) diff --git a/tests/src/commonMain/kotlin/com/github/klee0kai/test/di/base_phone/PhoneComponent.kt b/tests/src/commonMain/kotlin/com/github/klee0kai/test/di/base_phone/PhoneComponent.kt index ee62865e..a705eb8e 100644 --- a/tests/src/commonMain/kotlin/com/github/klee0kai/test/di/base_phone/PhoneComponent.kt +++ b/tests/src/commonMain/kotlin/com/github/klee0kai/test/di/base_phone/PhoneComponent.kt @@ -15,6 +15,7 @@ import com.github.klee0kai.test.tech.phone.OnePhone ] ) interface PhoneComponent { + fun components(): TechModule? fun inject(onePhone: OnePhone?) diff --git a/tests/src/commonMain/kotlin/com/github/klee0kai/test/di/bindinstance/simple/GodWorkspaceComponent.kt b/tests/src/commonMain/kotlin/com/github/klee0kai/test/di/bindinstance/simple/GodWorkspaceComponent.kt index 067ca6ce..09c41256 100644 --- a/tests/src/commonMain/kotlin/com/github/klee0kai/test/di/bindinstance/simple/GodWorkspaceComponent.kt +++ b/tests/src/commonMain/kotlin/com/github/klee0kai/test/di/bindinstance/simple/GodWorkspaceComponent.kt @@ -7,10 +7,12 @@ import com.github.klee0kai.test.mowgli.galaxy.IPlanet import com.github.klee0kai.test.mowgli.galaxy.Saturn import com.github.klee0kai.test.mowgli.galaxy.Sun +expect fun genGodWorkspaceComponent(): GodWorkspaceComponent + @Component interface GodWorkspaceComponent { - fun sunSystem(): SunSystemModule? + fun sunSystem(): SunSystemModule @BindInstance fun bindPlanet(planet: IPlanet?) diff --git a/tests/src/commonMain/kotlin/com/github/klee0kai/test/mowgli/earth/Cave.kt b/tests/src/commonMain/kotlin/com/github/klee0kai/test/mowgli/earth/Cave.kt index f2459577..5281a4c6 100644 --- a/tests/src/commonMain/kotlin/com/github/klee0kai/test/mowgli/earth/Cave.kt +++ b/tests/src/commonMain/kotlin/com/github/klee0kai/test/mowgli/earth/Cave.kt @@ -1,5 +1,8 @@ +@file:OptIn(ExperimentalUuidApi::class) + package com.github.klee0kai.test.mowgli.earth +import kotlin.uuid.ExperimentalUuidApi import kotlin.uuid.Uuid class Cave : IMountain { diff --git a/tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/bindinstance/simple/GodFirstWorkDayTest.kt b/tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/bindinstance/simple/GodFirstWorkDayTest.kt index b90a4736..04b7782e 100644 --- a/tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/bindinstance/simple/GodFirstWorkDayTest.kt +++ b/tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/bindinstance/simple/GodFirstWorkDayTest.kt @@ -1,6 +1,6 @@ package com.github.klee0kai.stone.test.bindinstance.simple -import com.github.klee0kai.test.di.bindinstance.simple.GodWorkspaceComponentStoneComponent +import com.github.klee0kai.test.di.bindinstance.simple.genGodWorkspaceComponent import com.github.klee0kai.test.mowgli.galaxy.Earth import com.github.klee0kai.test.mowgli.galaxy.Saturn import com.github.klee0kai.test.mowgli.galaxy.Sun @@ -13,7 +13,7 @@ class GodFirstWorkDayTest { @Test fun firstCreateSunTest() { //Given - val DI = GodWorkspaceComponentStoneComponent() + val DI = genGodWorkspaceComponent() val sun = Sun() //When @@ -28,7 +28,7 @@ class GodFirstWorkDayTest { @Test fun createSunAndEarthTest() { //Given - val DI = GodWorkspaceComponentStoneComponent() + val DI = genGodWorkspaceComponent() val sun = Sun() val earth = Earth() @@ -46,7 +46,7 @@ class GodFirstWorkDayTest { @Test fun createSunEarthSaturnTest() { //Given - val DI = GodWorkspaceComponentStoneComponent() + val DI = genGodWorkspaceComponent() val sun = Sun() val earth = Earth() val saturn = Saturn() @@ -67,7 +67,7 @@ class GodFirstWorkDayTest { @Test fun createSaturnEarthSunTest() { //Given - val DI = GodWorkspaceComponentStoneComponent() + val DI = genGodWorkspaceComponent() val sun = Sun() val earth = Earth() val saturn = Saturn() diff --git a/tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/bindinstance/simple_inject/SevenPlanetTests.kt b/tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/bindinstance/simple_inject/SevenPlanetTests.kt index a775c3c5..13528ccb 100644 --- a/tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/bindinstance/simple_inject/SevenPlanetTests.kt +++ b/tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/bindinstance/simple_inject/SevenPlanetTests.kt @@ -4,7 +4,6 @@ import com.github.klee0kai.test.di.bindinstance.simple_inject.SevenPlanetCompone import com.github.klee0kai.test.mowgli.MoonSky import com.github.klee0kai.test.mowgli.galaxy.Earth import com.github.klee0kai.test.mowgli.galaxy.Mercury -import org.junit.jupiter.api.Assertions.assertEquals import kotlin.test.Test import kotlin.test.assertEquals diff --git a/tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/bindinstance/singlemethod_inject/MoonSkyProtectInjectedTests.kt b/tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/bindinstance/singlemethod_inject/MoonSkyProtectInjectedTests.kt index c184856b..df63be60 100644 --- a/tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/bindinstance/singlemethod_inject/MoonSkyProtectInjectedTests.kt +++ b/tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/bindinstance/singlemethod_inject/MoonSkyProtectInjectedTests.kt @@ -6,10 +6,6 @@ import com.github.klee0kai.test.di.bindinstance.singlemethod_inject.StarSkyCompo import com.github.klee0kai.test.mowgli.MoonSky import com.github.klee0kai.test.mowgli.galaxy.Mercury import com.github.klee0kai.test.mowgli.galaxy.Sun -import org.junit.jupiter.api.Test -import org.junit.jupiter.api.assertNotNull -import org.junit.jupiter.api.assertNull -import java.lang.ref.WeakReference import kotlin.test.Test import kotlin.test.assertNotNull import kotlin.test.assertNull diff --git a/tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/bindinstance/solarsystem/SolarSystemTests.kt b/tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/bindinstance/solarsystem/SolarSystemTests.kt index bedada92..df082453 100644 --- a/tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/bindinstance/solarsystem/SolarSystemTests.kt +++ b/tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/bindinstance/solarsystem/SolarSystemTests.kt @@ -2,9 +2,6 @@ package com.github.klee0kai.stone.test.bindinstance.solarsystem import com.github.klee0kai.test.di.bindinstance.solarsystem.SolarSystemComponentStoneComponent import com.github.klee0kai.test.mowgli.galaxy.SolarSystem -import org.junit.jupiter.api.Assertions.assertEquals -import org.junit.jupiter.api.Assertions.assertNotNull -import org.junit.jupiter.api.Test import kotlin.test.Test import kotlin.test.assertEquals import kotlin.test.assertNotNull diff --git a/tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/cache/EarthCacheTests.kt b/tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/cache/EarthCacheTests.kt index ca9f202e..616f52dd 100644 --- a/tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/cache/EarthCacheTests.kt +++ b/tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/cache/EarthCacheTests.kt @@ -1,9 +1,6 @@ package com.github.klee0kai.stone.test.cache import com.github.klee0kai.test.di.gcforest.GcGodComponentStoneComponent -import org.junit.jupiter.api.Assertions.assertEquals -import org.junit.jupiter.api.Assertions.assertNotEquals -import org.junit.jupiter.api.Test import kotlin.test.Test import kotlin.test.assertEquals import kotlin.test.assertNotEquals diff --git a/tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/deps/HouseFactoryTests.kt b/tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/deps/HouseFactoryTests.kt index 711df3b0..594064b1 100644 --- a/tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/deps/HouseFactoryTests.kt +++ b/tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/deps/HouseFactoryTests.kt @@ -1,9 +1,6 @@ package com.github.klee0kai.stone.test.deps import com.github.klee0kai.test.di.house.simple.HouseComponentStoneComponent -import org.junit.jupiter.api.Assertions.assertEquals -import org.junit.jupiter.api.Assertions.assertNotEquals -import org.junit.jupiter.api.Test import kotlin.test.Test import kotlin.test.assertEquals import kotlin.test.assertNotEquals diff --git a/tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/deps/HouseTests.kt b/tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/deps/HouseTests.kt index 06b1a5b2..187ec1ae 100644 --- a/tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/deps/HouseTests.kt +++ b/tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/deps/HouseTests.kt @@ -3,16 +3,7 @@ package com.github.klee0kai.stone.test.deps import com.github.klee0kai.test.di.house.simple.HouseComponentStoneComponent import com.github.klee0kai.test.house.House import com.github.klee0kai.test.house.identifiers.StoreAreaType -import org.junit.jupiter.api.Assertions.assertEquals -import org.junit.jupiter.api.Assertions.assertNotEquals -import org.junit.jupiter.api.Test -import org.junit.jupiter.api.assertNotNull -import org.junit.jupiter.api.assertNull -import kotlin.test.Test -import kotlin.test.assertEquals -import kotlin.test.assertNotEquals -import kotlin.test.assertNotNull -import kotlin.test.assertNull +import kotlin.test.* class HouseTests { diff --git a/tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/deps/InHouseTests.kt b/tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/deps/InHouseTests.kt index f1be1edb..25ce8481 100644 --- a/tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/deps/InHouseTests.kt +++ b/tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/deps/InHouseTests.kt @@ -3,15 +3,7 @@ package com.github.klee0kai.stone.test.deps import com.github.klee0kai.test.di.house.simple.HouseComponentStoneComponent import com.github.klee0kai.test.house.InHouse import com.github.klee0kai.test.house.identifiers.StoreAreaType -import org.junit.jupiter.api.Assertions.assertEquals -import org.junit.jupiter.api.Assertions.assertNotEquals -import org.junit.jupiter.api.assertNotNull -import org.junit.jupiter.api.assertNull -import kotlin.test.Test -import kotlin.test.assertEquals -import kotlin.test.assertNotEquals -import kotlin.test.assertNotNull -import kotlin.test.assertNull +import kotlin.test.* class InHouseTests { diff --git a/tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/gc/EarthLastDayTests.kt b/tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/gc/EarthLastDayTests.kt index 8acbb568..82b6cbc6 100644 --- a/tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/gc/EarthLastDayTests.kt +++ b/tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/gc/EarthLastDayTests.kt @@ -2,10 +2,6 @@ package com.github.klee0kai.stone.test.gc import com.github.klee0kai.stone.weakref.WeakRef import com.github.klee0kai.test.di.gcforest.GcGodComponentStoneComponent -import org.junit.jupiter.api.Test -import org.junit.jupiter.api.assertNotNull -import org.junit.jupiter.api.assertNull -import java.lang.ref.WeakReference import kotlin.test.Test import kotlin.test.assertNotNull import kotlin.test.assertNull diff --git a/tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/gc/GodLastWorkDayTests.kt b/tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/gc/GodLastWorkDayTests.kt index b33ddfb1..5fb56367 100644 --- a/tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/gc/GodLastWorkDayTests.kt +++ b/tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/gc/GodLastWorkDayTests.kt @@ -5,10 +5,6 @@ import com.github.klee0kai.test.di.gcforest.GcGodComponentStoneComponent import com.github.klee0kai.test.mowgli.galaxy.Earth import com.github.klee0kai.test.mowgli.galaxy.Saturn import com.github.klee0kai.test.mowgli.galaxy.Sun -import org.junit.jupiter.api.Test -import org.junit.jupiter.api.assertNotNull -import org.junit.jupiter.api.assertNull -import java.lang.ref.WeakReference import kotlin.test.Test import kotlin.test.assertNotNull import kotlin.test.assertNull diff --git a/tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/identifiers/GoodPhoneInjectTests.kt b/tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/identifiers/GoodPhoneInjectTests.kt index 44bfd410..3bd99a44 100644 --- a/tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/identifiers/GoodPhoneInjectTests.kt +++ b/tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/identifiers/GoodPhoneInjectTests.kt @@ -4,8 +4,6 @@ import com.github.klee0kai.test.di.base_phone.PhoneComponentStoneComponent import com.github.klee0kai.test.di.base_phone.identifiers.DataStorageSize import com.github.klee0kai.test.di.base_phone.identifiers.RamSize import com.github.klee0kai.test.tech.phone.GoodPhone -import org.junit.jupiter.api.Assertions.assertEquals -import org.junit.jupiter.api.Test import kotlin.test.Test import kotlin.test.assertEquals diff --git a/tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/identifiers/MultiIdentifiersTests.kt b/tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/identifiers/MultiIdentifiersTests.kt index c013ceec..61b296c6 100644 --- a/tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/identifiers/MultiIdentifiersTests.kt +++ b/tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/identifiers/MultiIdentifiersTests.kt @@ -3,8 +3,6 @@ package com.github.klee0kai.stone.test.identifiers import com.github.klee0kai.test.di.base_phone.PhoneComponentStoneComponent import com.github.klee0kai.test.di.base_phone.identifiers.PhoneOsType import com.github.klee0kai.test.di.base_phone.identifiers.PhoneOsVersion -import org.junit.jupiter.api.Assertions.assertEquals -import org.junit.jupiter.api.Assertions.assertNotEquals import kotlin.test.Test import kotlin.test.assertEquals import kotlin.test.assertNotEquals diff --git a/tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/identifiers/TechComponentsTests.kt b/tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/identifiers/TechComponentsTests.kt index 601a736c..a81523d5 100644 --- a/tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/identifiers/TechComponentsTests.kt +++ b/tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/identifiers/TechComponentsTests.kt @@ -3,9 +3,6 @@ package com.github.klee0kai.stone.test.identifiers import com.github.klee0kai.test.di.base_phone.PhoneComponentStoneComponent import com.github.klee0kai.test.di.base_phone.identifiers.PhoneOsType import com.github.klee0kai.test.di.base_phone.identifiers.RamSize -import org.junit.jupiter.api.Assertions.assertEquals -import org.junit.jupiter.api.Assertions.assertNotEquals -import org.junit.jupiter.api.Test import kotlin.test.Test import kotlin.test.assertEquals import kotlin.test.assertNotEquals diff --git a/tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/identifiers/TechFactoryComponentTests.kt b/tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/identifiers/TechFactoryComponentTests.kt index e6e1ca9d..8fdc8adb 100644 --- a/tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/identifiers/TechFactoryComponentTests.kt +++ b/tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/identifiers/TechFactoryComponentTests.kt @@ -4,10 +4,6 @@ import com.github.klee0kai.test.di.base_phone.identifiers.PhoneOsType import com.github.klee0kai.test.di.base_phone.identifiers.PhoneOsVersion import com.github.klee0kai.test.di.base_phone.identifiers.RamSize import com.github.klee0kai.test.di.techfactory.TechFactoryComponentStoneComponent -import org.junit.jupiter.api.Assertions.assertEquals -import org.junit.jupiter.api.Assertions.assertNotEquals -import org.junit.jupiter.api.Test -import org.junit.jupiter.api.assertNull import kotlin.test.Test import kotlin.test.assertEquals import kotlin.test.assertNotEquals diff --git a/tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/identifiers/TechFactoryTests.kt b/tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/identifiers/TechFactoryTests.kt index eeaa84f3..40a4e563 100644 --- a/tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/identifiers/TechFactoryTests.kt +++ b/tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/identifiers/TechFactoryTests.kt @@ -3,8 +3,6 @@ package com.github.klee0kai.stone.test.identifiers import com.github.klee0kai.test.di.base_phone.identifiers.PhoneOsType import com.github.klee0kai.test.di.base_phone.identifiers.RamSize import com.github.klee0kai.test.di.techfactory.TechFactoryComponentStoneComponent -import org.junit.jupiter.api.Assertions.assertNotEquals -import org.junit.jupiter.api.Test import kotlin.test.Test import kotlin.test.assertNotEquals diff --git a/tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/identifiers/TechFactoryWrappersTests.kt b/tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/identifiers/TechFactoryWrappersTests.kt index a97a9b22..a74a49a7 100644 --- a/tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/identifiers/TechFactoryWrappersTests.kt +++ b/tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/identifiers/TechFactoryWrappersTests.kt @@ -1,10 +1,6 @@ package com.github.klee0kai.stone.test.identifiers import com.github.klee0kai.test.di.techfactory.TechFactoryComponentStoneComponent -import org.junit.jupiter.api.Assertions.assertEquals -import org.junit.jupiter.api.Assertions.assertNotEquals -import org.junit.jupiter.api.Test -import org.junit.jupiter.api.assertNotNull import kotlin.test.Test import kotlin.test.assertEquals import kotlin.test.assertNotEquals diff --git a/tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/inject/HorseInjectTests.kt b/tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/inject/HorseInjectTests.kt index c5ced0ca..3cbe2f9b 100644 --- a/tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/inject/HorseInjectTests.kt +++ b/tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/inject/HorseInjectTests.kt @@ -5,9 +5,6 @@ import com.github.klee0kai.test.di.base_forest.ForestComponentStoneComponent import com.github.klee0kai.test.mowgli.animal.Horse import com.github.klee0kai.test.mowgli.animal.Mowgli import com.github.klee0kai.test.mowgli.animal.Snake -import org.junit.jupiter.api.Assertions.assertEquals -import org.junit.jupiter.api.Assertions.assertNotEquals -import org.junit.jupiter.api.assertNotNull import kotlin.test.Test import kotlin.test.assertEquals import kotlin.test.assertNotEquals diff --git a/tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/inject/HorseProtectInjectTests.kt b/tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/inject/HorseProtectInjectTests.kt index 7b841381..d4b6bd34 100644 --- a/tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/inject/HorseProtectInjectTests.kt +++ b/tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/inject/HorseProtectInjectTests.kt @@ -1,6 +1,7 @@ package com.github.klee0kai.stone.test.inject import com.github.klee0kai.stone.weakref.Memory +import com.github.klee0kai.stone.weakref.WeakRef import com.github.klee0kai.test.di.base_forest.ForestComponentStoneComponent import com.github.klee0kai.test.mowgli.animal.Horse import kotlin.test.Test @@ -22,7 +23,7 @@ class HorseProtectInjectTests { stoneLifeCycleOwner = { } ) - val historyWeakReference = WeakReference(horse?.history) + val historyWeakReference = WeakRef(horse?.history) horse = null Memory.gc() @@ -42,7 +43,7 @@ class HorseProtectInjectTests { stoneLifeCycleOwner = {} ) - val historyWeakReference = WeakReference(horse!!.history) + val historyWeakReference = WeakRef(horse!!.history) DI.protectInjected(horse) horse = null DI.gcAll() diff --git a/tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/inject/MowgliInjectMethodWrappersTests.kt b/tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/inject/MowgliInjectMethodWrappersTests.kt index e852ff34..09864eb4 100644 --- a/tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/inject/MowgliInjectMethodWrappersTests.kt +++ b/tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/inject/MowgliInjectMethodWrappersTests.kt @@ -2,7 +2,6 @@ package com.github.klee0kai.stone.test.inject import com.github.klee0kai.test.di.base_forest.ForestComponentStoneComponent import com.github.klee0kai.test.mowgli.animal.Mowgli -import org.junit.jupiter.api.Assertions.assertNotEquals import kotlin.test.Test import kotlin.test.assertEquals import kotlin.test.assertNotEquals diff --git a/tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/inject/MowgliInjectWrappersTests.kt b/tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/inject/MowgliInjectWrappersTests.kt index d68373a4..1d668f18 100644 --- a/tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/inject/MowgliInjectWrappersTests.kt +++ b/tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/inject/MowgliInjectWrappersTests.kt @@ -2,8 +2,6 @@ package com.github.klee0kai.stone.test.inject import com.github.klee0kai.test.di.base_forest.ForestComponentStoneComponent import com.github.klee0kai.test.mowgli.animal.Mowgli -import org.junit.jupiter.api.Assertions.* -import org.junit.jupiter.api.Test import kotlin.test.Test import kotlin.test.assertEquals import kotlin.test.assertNotEquals diff --git a/tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/inject/SchoolProtectInjectWrappersTests.kt b/tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/inject/SchoolProtectInjectWrappersTests.kt index b1312ec3..b10a4628 100644 --- a/tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/inject/SchoolProtectInjectWrappersTests.kt +++ b/tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/inject/SchoolProtectInjectWrappersTests.kt @@ -3,10 +3,6 @@ package com.github.klee0kai.stone.test.inject import com.github.klee0kai.stone.weakref.WeakRef import com.github.klee0kai.test.di.base_forest.ForestComponentStoneComponent import com.github.klee0kai.test.mowgli.School -import org.junit.jupiter.api.Test -import org.junit.jupiter.api.assertNotNull -import org.junit.jupiter.api.assertNull -import java.lang.ref.WeakReference import kotlin.test.Test import kotlin.test.assertNotNull import kotlin.test.assertNull diff --git a/tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/lifecycle/GoodPhoneRepairTests.kt b/tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/lifecycle/GoodPhoneRepairTests.kt index 99f3598c..fb7702cf 100644 --- a/tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/lifecycle/GoodPhoneRepairTests.kt +++ b/tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/lifecycle/GoodPhoneRepairTests.kt @@ -6,11 +6,7 @@ import com.github.klee0kai.test.di.base_phone.PhoneComponentStoneComponent import com.github.klee0kai.test.di.base_phone.identifiers.DataStorageSize import com.github.klee0kai.test.di.base_phone.identifiers.RamSize import com.github.klee0kai.test.tech.phone.GoodPhone -import org.junit.jupiter.api.Assertions.assertEquals -import kotlin.test.Test -import kotlin.test.assertNotEquals -import kotlin.test.assertNotNull -import kotlin.test.assertNull +import kotlin.test.* /** * Test lifecycle owner over LifecycleUtils diff --git a/tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/moduleinit/BeginOfBegins2Tests.kt b/tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/moduleinit/BeginOfBegins2Tests.kt index 5904c9a0..be59ec29 100644 --- a/tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/moduleinit/BeginOfBegins2Tests.kt +++ b/tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/moduleinit/BeginOfBegins2Tests.kt @@ -8,8 +8,6 @@ import com.github.klee0kai.test.mowgli.galaxy.Earth import com.github.klee0kai.test.mowgli.identity.Conscience import com.github.klee0kai.test.mowgli.identity.Ideology import com.github.klee0kai.test.mowgli.identity.Knowledge -import org.junit.jupiter.api.Assertions.assertEquals -import org.junit.jupiter.api.Test import kotlin.test.Test import kotlin.test.assertEquals diff --git a/tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/parameterized/WireTest.kt b/tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/parameterized/WireTest.kt index b9a23f59..4d4f3c60 100644 --- a/tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/parameterized/WireTest.kt +++ b/tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/parameterized/WireTest.kt @@ -3,10 +3,6 @@ package com.github.klee0kai.stone.test.parameterized import com.github.klee0kai.test.di.wire.WireComponentStoneComponent import com.github.klee0kai.test.wire.Wire import com.github.klee0kai.test.wire.types.MiniUsb -import org.junit.jupiter.api.Assertions.assertEquals -import org.junit.jupiter.api.Assertions.assertNotEquals -import org.junit.jupiter.api.Test -import org.junit.jupiter.api.assertNotNull import kotlin.test.Test import kotlin.test.assertEquals import kotlin.test.assertNotEquals diff --git a/tests/src/jsMain/kotlin/com/github/klee0kai/test/di/bindinstance/simple/GodWorkspaceComponent.js.kt b/tests/src/jsMain/kotlin/com/github/klee0kai/test/di/bindinstance/simple/GodWorkspaceComponent.js.kt new file mode 100644 index 00000000..4f7a8258 --- /dev/null +++ b/tests/src/jsMain/kotlin/com/github/klee0kai/test/di/bindinstance/simple/GodWorkspaceComponent.js.kt @@ -0,0 +1,3 @@ +package com.github.klee0kai.test.di.bindinstance.simple + +actual fun genGodWorkspaceComponent() = GodWorkspaceComponentStoneComponent() \ No newline at end of file diff --git a/tests/src/jvmMain/kotlin/com/github/klee0kai/test/di/bindinstance/simple/GodWorkspaceComponent.jvm.kt b/tests/src/jvmMain/kotlin/com/github/klee0kai/test/di/bindinstance/simple/GodWorkspaceComponent.jvm.kt new file mode 100644 index 00000000..f5479555 --- /dev/null +++ b/tests/src/jvmMain/kotlin/com/github/klee0kai/test/di/bindinstance/simple/GodWorkspaceComponent.jvm.kt @@ -0,0 +1,5 @@ +package com.github.klee0kai.test.di.bindinstance.simple + +actual fun genGodWorkspaceComponent( + +): GodWorkspaceComponent = GodWorkspaceComponentStoneComponent() \ No newline at end of file From 7cc6d718e8f36b6f1b9c6f970d3949d911bf3110 Mon Sep 17 00:00:00 2001 From: klee0kai Date: Sat, 21 Feb 2026 20:58:41 +0100 Subject: [PATCH 112/122] We use two separate sets of annotations --- .gitignore | 3 +- .../github/klee0kai/stone/weakref/Inject.kt | 2 +- .../github/klee0kai/stone/weakref/Named.kt | 6 ++-- .../github/klee0kai/stone/weakref/Provider.kt | 4 +-- .../klee0kai/stone/weakref/Qualifier.kt | 2 +- .../github/klee0kai/stone/weakref/Scope.kt | 2 +- .../klee0kai/stone/weakref/Singleton.kt | 8 ----- .../github/klee0kai/stone/weakref/Inject.kt | 5 --- .../github/klee0kai/stone/weakref/Named.kt | 5 --- .../github/klee0kai/stone/weakref/Provider.kt | 5 --- .../klee0kai/stone/weakref/Qualifier.kt | 5 --- .../github/klee0kai/stone/weakref/Scope.kt | 3 -- .../klee0kai/stone/weakref/Singleton.kt | 3 -- .../github/klee0kai/stone/weakref/Inject.kt | 4 --- .../github/klee0kai/stone/weakref/Named.kt | 3 -- .../github/klee0kai/stone/weakref/Provider.kt | 5 --- .../klee0kai/stone/weakref/Qualifier.kt | 3 -- .../github/klee0kai/stone/weakref/Scope.kt | 3 -- .../klee0kai/stone/weakref/Singleton.kt | 3 -- .../github/klee0kai/stone/weakref/Inject.kt | 3 -- .../github/klee0kai/stone/weakref/Named.kt | 3 -- .../github/klee0kai/stone/weakref/Provider.kt | 5 --- .../klee0kai/stone/weakref/Qualifier.kt | 3 -- .../github/klee0kai/stone/weakref/Scope.kt | 3 -- .../klee0kai/stone/weakref/Singleton.kt | 3 -- .../ksp/helpers/ComponentDeclarationExt.kt | 10 ++++-- .../ksp/helpers/invokecall/ModulesGraph.kt | 5 +-- .../stone/ksp/helpers/wrap/WrapHelper.kt | 7 ++-- .../stone/ksp/ksp/AnnotationProtectedExt.kt | 21 ++++++++++- .../target/component/GenComponentProcessor.kt | 35 +++++++++++++------ .../stone/annotations/component/Component.kt | 1 - .../annotations/component/GcSoftScope.kt | 2 +- .../annotations/component/GcWeakScope.kt | 2 +- .../annotations/qualifier/IgnoreQualifier.kt | 2 -- tests/build.gradle.kts | 22 +++++++++--- .../com/github/klee0kai/test/wire/Wire.kt | 7 ++-- .../github/klee0kai/test/wire/types/Hdmi.kt | 8 +++-- .../klee0kai/test/wire/types/MiniUsb.kt | 7 ++-- .../github/klee0kai/test/wire/types/Usb.kt | 7 ++-- .../test/lifecycle/OnePhoneRepairTests.kt | 3 +- .../simple/GodWorkspaceComponent.js.kt | 2 +- .../simple/GodWorkspaceComponent.linuxX64.kt | 3 ++ .../simple/GodWorkspaceComponent.wasmJs.kt | 4 +++ .../inject/mowgli/identity/FamilyIdeology.kt | 9 +++-- .../klee0kai/stone/weakref/SoftRef.js.kt | 4 ++- 45 files changed, 127 insertions(+), 128 deletions(-) delete mode 100644 inject_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/weakref/Singleton.kt delete mode 100644 inject_multiplatform/src/jvmMain/kotlin/com/github/klee0kai/stone/weakref/Inject.kt delete mode 100644 inject_multiplatform/src/jvmMain/kotlin/com/github/klee0kai/stone/weakref/Named.kt delete mode 100644 inject_multiplatform/src/jvmMain/kotlin/com/github/klee0kai/stone/weakref/Provider.kt delete mode 100644 inject_multiplatform/src/jvmMain/kotlin/com/github/klee0kai/stone/weakref/Qualifier.kt delete mode 100644 inject_multiplatform/src/jvmMain/kotlin/com/github/klee0kai/stone/weakref/Scope.kt delete mode 100644 inject_multiplatform/src/jvmMain/kotlin/com/github/klee0kai/stone/weakref/Singleton.kt delete mode 100644 inject_multiplatform/src/nativeMain/kotlin/com/github/klee0kai/stone/weakref/Inject.kt delete mode 100644 inject_multiplatform/src/nativeMain/kotlin/com/github/klee0kai/stone/weakref/Named.kt delete mode 100644 inject_multiplatform/src/nativeMain/kotlin/com/github/klee0kai/stone/weakref/Provider.kt delete mode 100644 inject_multiplatform/src/nativeMain/kotlin/com/github/klee0kai/stone/weakref/Qualifier.kt delete mode 100644 inject_multiplatform/src/nativeMain/kotlin/com/github/klee0kai/stone/weakref/Scope.kt delete mode 100644 inject_multiplatform/src/nativeMain/kotlin/com/github/klee0kai/stone/weakref/Singleton.kt delete mode 100644 inject_multiplatform/src/webMain/kotlin/com/github/klee0kai/stone/weakref/Inject.kt delete mode 100644 inject_multiplatform/src/webMain/kotlin/com/github/klee0kai/stone/weakref/Named.kt delete mode 100644 inject_multiplatform/src/webMain/kotlin/com/github/klee0kai/stone/weakref/Provider.kt delete mode 100644 inject_multiplatform/src/webMain/kotlin/com/github/klee0kai/stone/weakref/Qualifier.kt delete mode 100644 inject_multiplatform/src/webMain/kotlin/com/github/klee0kai/stone/weakref/Scope.kt delete mode 100644 inject_multiplatform/src/webMain/kotlin/com/github/klee0kai/stone/weakref/Singleton.kt create mode 100644 tests/src/linuxX64Main/kotlin/com/github/klee0kai/test/di/bindinstance/simple/GodWorkspaceComponent.linuxX64.kt create mode 100644 tests/src/wasmJsMain/kotlin/com/github/klee0kai/test/di/bindinstance/simple/GodWorkspaceComponent.wasmJs.kt diff --git a/.gitignore b/.gitignore index 8b636d9c..306705a1 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ .gradle .idea build -.kotlin \ No newline at end of file +.kotlin +kotlin-js-store \ No newline at end of file diff --git a/inject_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/weakref/Inject.kt b/inject_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/weakref/Inject.kt index 316907d7..950bd144 100644 --- a/inject_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/weakref/Inject.kt +++ b/inject_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/weakref/Inject.kt @@ -8,4 +8,4 @@ package com.github.klee0kai.stone.weakref * in superclasses are injected before those in subclasses. Ordering of * injection among fields and among methods in the same class is not specified. */ -expect annotation class Inject() \ No newline at end of file +annotation class Inject \ No newline at end of file diff --git a/inject_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/weakref/Named.kt b/inject_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/weakref/Named.kt index fa7ff1d9..74f55518 100644 --- a/inject_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/weakref/Named.kt +++ b/inject_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/weakref/Named.kt @@ -18,6 +18,6 @@ package com.github.klee0kai.stone.weakref * } * ``` */ -expect annotation class Named( - val value: String = "" -) +annotation class Named( + val value: String +) \ No newline at end of file diff --git a/inject_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/weakref/Provider.kt b/inject_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/weakref/Provider.kt index 16d82c6a..694f04c1 100644 --- a/inject_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/weakref/Provider.kt +++ b/inject_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/weakref/Provider.kt @@ -5,8 +5,6 @@ package com.github.klee0kai.stone.weakref * any type [T] that can be injected, you can also inject * `Provider`. */ -expect interface Provider { - +fun interface Provider { fun get(): T - } \ No newline at end of file diff --git a/inject_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/weakref/Qualifier.kt b/inject_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/weakref/Qualifier.kt index d8cd3b75..4ff0f75d 100644 --- a/inject_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/weakref/Qualifier.kt +++ b/inject_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/weakref/Qualifier.kt @@ -29,4 +29,4 @@ package com.github.klee0kai.stone.weakref * * @see [Named] */ -expect annotation class Qualifier() \ No newline at end of file +annotation class Qualifier \ No newline at end of file diff --git a/inject_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/weakref/Scope.kt b/inject_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/weakref/Scope.kt index 4a95653f..6b3a3199 100644 --- a/inject_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/weakref/Scope.kt +++ b/inject_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/weakref/Scope.kt @@ -11,4 +11,4 @@ package com.github.klee0kai.stone.weakref * implementation should be thread safe. The implementation of the scope * itself is left up to the injector. */ -expect annotation class Scope() \ No newline at end of file +annotation class Scope \ No newline at end of file diff --git a/inject_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/weakref/Singleton.kt b/inject_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/weakref/Singleton.kt deleted file mode 100644 index bfc6f18c..00000000 --- a/inject_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/weakref/Singleton.kt +++ /dev/null @@ -1,8 +0,0 @@ -package com.github.klee0kai.stone.weakref - -/** - * Identifies a type that the injector only instantiates once. Not inherited. - * - * @see [Scope] - */ -expect annotation class Singleton() \ No newline at end of file diff --git a/inject_multiplatform/src/jvmMain/kotlin/com/github/klee0kai/stone/weakref/Inject.kt b/inject_multiplatform/src/jvmMain/kotlin/com/github/klee0kai/stone/weakref/Inject.kt deleted file mode 100644 index d160177c..00000000 --- a/inject_multiplatform/src/jvmMain/kotlin/com/github/klee0kai/stone/weakref/Inject.kt +++ /dev/null @@ -1,5 +0,0 @@ -package com.github.klee0kai.stone.weakref - -import javax.inject.Inject - -actual typealias Inject = Inject \ No newline at end of file diff --git a/inject_multiplatform/src/jvmMain/kotlin/com/github/klee0kai/stone/weakref/Named.kt b/inject_multiplatform/src/jvmMain/kotlin/com/github/klee0kai/stone/weakref/Named.kt deleted file mode 100644 index 971644a6..00000000 --- a/inject_multiplatform/src/jvmMain/kotlin/com/github/klee0kai/stone/weakref/Named.kt +++ /dev/null @@ -1,5 +0,0 @@ -package com.github.klee0kai.stone.weakref - -import javax.inject.Named - -actual typealias Named = Named \ No newline at end of file diff --git a/inject_multiplatform/src/jvmMain/kotlin/com/github/klee0kai/stone/weakref/Provider.kt b/inject_multiplatform/src/jvmMain/kotlin/com/github/klee0kai/stone/weakref/Provider.kt deleted file mode 100644 index c786672f..00000000 --- a/inject_multiplatform/src/jvmMain/kotlin/com/github/klee0kai/stone/weakref/Provider.kt +++ /dev/null @@ -1,5 +0,0 @@ -package com.github.klee0kai.stone.weakref - -import javax.inject.Provider - -actual typealias Provider = Provider \ No newline at end of file diff --git a/inject_multiplatform/src/jvmMain/kotlin/com/github/klee0kai/stone/weakref/Qualifier.kt b/inject_multiplatform/src/jvmMain/kotlin/com/github/klee0kai/stone/weakref/Qualifier.kt deleted file mode 100644 index cfe609f7..00000000 --- a/inject_multiplatform/src/jvmMain/kotlin/com/github/klee0kai/stone/weakref/Qualifier.kt +++ /dev/null @@ -1,5 +0,0 @@ -package com.github.klee0kai.stone.weakref - -import javax.inject.Qualifier - -actual typealias Qualifier = Qualifier \ No newline at end of file diff --git a/inject_multiplatform/src/jvmMain/kotlin/com/github/klee0kai/stone/weakref/Scope.kt b/inject_multiplatform/src/jvmMain/kotlin/com/github/klee0kai/stone/weakref/Scope.kt deleted file mode 100644 index 97f7550f..00000000 --- a/inject_multiplatform/src/jvmMain/kotlin/com/github/klee0kai/stone/weakref/Scope.kt +++ /dev/null @@ -1,3 +0,0 @@ -package com.github.klee0kai.stone.weakref - -actual typealias Scope = javax.inject.Scope \ No newline at end of file diff --git a/inject_multiplatform/src/jvmMain/kotlin/com/github/klee0kai/stone/weakref/Singleton.kt b/inject_multiplatform/src/jvmMain/kotlin/com/github/klee0kai/stone/weakref/Singleton.kt deleted file mode 100644 index 49e37e58..00000000 --- a/inject_multiplatform/src/jvmMain/kotlin/com/github/klee0kai/stone/weakref/Singleton.kt +++ /dev/null @@ -1,3 +0,0 @@ -package com.github.klee0kai.stone.weakref - -actual typealias Singleton = javax.inject.Singleton \ No newline at end of file diff --git a/inject_multiplatform/src/nativeMain/kotlin/com/github/klee0kai/stone/weakref/Inject.kt b/inject_multiplatform/src/nativeMain/kotlin/com/github/klee0kai/stone/weakref/Inject.kt deleted file mode 100644 index 1b06381a..00000000 --- a/inject_multiplatform/src/nativeMain/kotlin/com/github/klee0kai/stone/weakref/Inject.kt +++ /dev/null @@ -1,4 +0,0 @@ -package com.github.klee0kai.stone.weakref - - -actual annotation class Inject actual constructor() \ No newline at end of file diff --git a/inject_multiplatform/src/nativeMain/kotlin/com/github/klee0kai/stone/weakref/Named.kt b/inject_multiplatform/src/nativeMain/kotlin/com/github/klee0kai/stone/weakref/Named.kt deleted file mode 100644 index 6a8ffaf9..00000000 --- a/inject_multiplatform/src/nativeMain/kotlin/com/github/klee0kai/stone/weakref/Named.kt +++ /dev/null @@ -1,3 +0,0 @@ -package com.github.klee0kai.stone.weakref - -actual annotation class Named actual constructor(actual val value: String) \ No newline at end of file diff --git a/inject_multiplatform/src/nativeMain/kotlin/com/github/klee0kai/stone/weakref/Provider.kt b/inject_multiplatform/src/nativeMain/kotlin/com/github/klee0kai/stone/weakref/Provider.kt deleted file mode 100644 index cc771814..00000000 --- a/inject_multiplatform/src/nativeMain/kotlin/com/github/klee0kai/stone/weakref/Provider.kt +++ /dev/null @@ -1,5 +0,0 @@ -package com.github.klee0kai.stone.weakref - -actual interface Provider { - actual fun get(): T -} \ No newline at end of file diff --git a/inject_multiplatform/src/nativeMain/kotlin/com/github/klee0kai/stone/weakref/Qualifier.kt b/inject_multiplatform/src/nativeMain/kotlin/com/github/klee0kai/stone/weakref/Qualifier.kt deleted file mode 100644 index 7382be14..00000000 --- a/inject_multiplatform/src/nativeMain/kotlin/com/github/klee0kai/stone/weakref/Qualifier.kt +++ /dev/null @@ -1,3 +0,0 @@ -package com.github.klee0kai.stone.weakref - -actual annotation class Qualifier actual constructor() \ No newline at end of file diff --git a/inject_multiplatform/src/nativeMain/kotlin/com/github/klee0kai/stone/weakref/Scope.kt b/inject_multiplatform/src/nativeMain/kotlin/com/github/klee0kai/stone/weakref/Scope.kt deleted file mode 100644 index 14247bbd..00000000 --- a/inject_multiplatform/src/nativeMain/kotlin/com/github/klee0kai/stone/weakref/Scope.kt +++ /dev/null @@ -1,3 +0,0 @@ -package com.github.klee0kai.stone.weakref - -actual annotation class Scope actual constructor() \ No newline at end of file diff --git a/inject_multiplatform/src/nativeMain/kotlin/com/github/klee0kai/stone/weakref/Singleton.kt b/inject_multiplatform/src/nativeMain/kotlin/com/github/klee0kai/stone/weakref/Singleton.kt deleted file mode 100644 index 18f8cb56..00000000 --- a/inject_multiplatform/src/nativeMain/kotlin/com/github/klee0kai/stone/weakref/Singleton.kt +++ /dev/null @@ -1,3 +0,0 @@ -package com.github.klee0kai.stone.weakref - -actual annotation class Singleton actual constructor() \ No newline at end of file diff --git a/inject_multiplatform/src/webMain/kotlin/com/github/klee0kai/stone/weakref/Inject.kt b/inject_multiplatform/src/webMain/kotlin/com/github/klee0kai/stone/weakref/Inject.kt deleted file mode 100644 index 9d8e703d..00000000 --- a/inject_multiplatform/src/webMain/kotlin/com/github/klee0kai/stone/weakref/Inject.kt +++ /dev/null @@ -1,3 +0,0 @@ -package com.github.klee0kai.stone.weakref - -actual annotation class Inject actual constructor() \ No newline at end of file diff --git a/inject_multiplatform/src/webMain/kotlin/com/github/klee0kai/stone/weakref/Named.kt b/inject_multiplatform/src/webMain/kotlin/com/github/klee0kai/stone/weakref/Named.kt deleted file mode 100644 index 6a8ffaf9..00000000 --- a/inject_multiplatform/src/webMain/kotlin/com/github/klee0kai/stone/weakref/Named.kt +++ /dev/null @@ -1,3 +0,0 @@ -package com.github.klee0kai.stone.weakref - -actual annotation class Named actual constructor(actual val value: String) \ No newline at end of file diff --git a/inject_multiplatform/src/webMain/kotlin/com/github/klee0kai/stone/weakref/Provider.kt b/inject_multiplatform/src/webMain/kotlin/com/github/klee0kai/stone/weakref/Provider.kt deleted file mode 100644 index cc771814..00000000 --- a/inject_multiplatform/src/webMain/kotlin/com/github/klee0kai/stone/weakref/Provider.kt +++ /dev/null @@ -1,5 +0,0 @@ -package com.github.klee0kai.stone.weakref - -actual interface Provider { - actual fun get(): T -} \ No newline at end of file diff --git a/inject_multiplatform/src/webMain/kotlin/com/github/klee0kai/stone/weakref/Qualifier.kt b/inject_multiplatform/src/webMain/kotlin/com/github/klee0kai/stone/weakref/Qualifier.kt deleted file mode 100644 index 7382be14..00000000 --- a/inject_multiplatform/src/webMain/kotlin/com/github/klee0kai/stone/weakref/Qualifier.kt +++ /dev/null @@ -1,3 +0,0 @@ -package com.github.klee0kai.stone.weakref - -actual annotation class Qualifier actual constructor() \ No newline at end of file diff --git a/inject_multiplatform/src/webMain/kotlin/com/github/klee0kai/stone/weakref/Scope.kt b/inject_multiplatform/src/webMain/kotlin/com/github/klee0kai/stone/weakref/Scope.kt deleted file mode 100644 index 14247bbd..00000000 --- a/inject_multiplatform/src/webMain/kotlin/com/github/klee0kai/stone/weakref/Scope.kt +++ /dev/null @@ -1,3 +0,0 @@ -package com.github.klee0kai.stone.weakref - -actual annotation class Scope actual constructor() \ No newline at end of file diff --git a/inject_multiplatform/src/webMain/kotlin/com/github/klee0kai/stone/weakref/Singleton.kt b/inject_multiplatform/src/webMain/kotlin/com/github/klee0kai/stone/weakref/Singleton.kt deleted file mode 100644 index 18f8cb56..00000000 --- a/inject_multiplatform/src/webMain/kotlin/com/github/klee0kai/stone/weakref/Singleton.kt +++ /dev/null @@ -1,3 +0,0 @@ -package com.github.klee0kai.stone.weakref - -actual annotation class Singleton actual constructor() \ No newline at end of file diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/ComponentDeclarationExt.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/ComponentDeclarationExt.kt index d19a5c18..604861e2 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/ComponentDeclarationExt.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/ComponentDeclarationExt.kt @@ -7,7 +7,6 @@ import com.github.klee0kai.stone.annotations.qualifier.IgnoreQualifier import com.github.klee0kai.stone.lifecycle.StoneLifeCycleOwner import com.github.klee0kai.stone.weakref.Named import com.github.klee0kai.stone.weakref.Qualifier -import com.github.klee0kai.stone.weakref.Scope import com.github.klee0kai.thekey.stone.ksp.helpers.annotations.findComponentAnnotation import com.github.klee0kai.thekey.stone.ksp.ksp.isAnyType import com.github.klee0kai.thekey.stone.ksp.ksp.isChildOf @@ -18,6 +17,7 @@ import com.google.devtools.ksp.processing.Resolver import com.google.devtools.ksp.symbol.* import com.squareup.kotlinpoet.ClassName import com.squareup.kotlinpoet.asClassName +import com.github.klee0kai.stone.weakref.Scope as StoneScope fun Resolver.findComponentForModuleOrDep( moduleCl: ClassName, @@ -75,7 +75,7 @@ val KSAnnotated.scopeAnnotations: Sequence || funAnnotation.annotationType.resolveNotNullable().declaration.annotations.any { annotationOfAnnotation -> annotationOfAnnotation.annotationType.resolveNotNullable().declaration.isAnyType( GcScopeAnnotation::class, - Scope::class, + StoneScope::class, javax.inject.Scope::class ) } @@ -86,13 +86,17 @@ val KSAnnotated.qualifierAnnotations: Sequence get() { val standardQualifierAnnotations = listOf( Named::class, + javax.inject.Named::class, IgnoreQualifier::class, ) return annotations.filter { funAnnotation -> standardQualifierAnnotations.any { funAnnotation.annotationType.resolveNotNullable().declaration.isType(it) } || funAnnotation.annotationType.resolveNotNullable().declaration.annotations.any { annotationOfAnnotation -> - annotationOfAnnotation.annotationType.resolveNotNullable().declaration.isType(Qualifier::class) + annotationOfAnnotation.annotationType.resolveNotNullable().declaration.isAnyType( + Qualifier::class, + javax.inject.Qualifier::class + ) } } } diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/invokecall/ModulesGraph.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/invokecall/ModulesGraph.kt index 7f8273fa..fc3e3dd4 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/invokecall/ModulesGraph.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/invokecall/ModulesGraph.kt @@ -15,6 +15,7 @@ import com.github.klee0kai.thekey.stone.ksp.helpers.identifierParameters import com.github.klee0kai.thekey.stone.ksp.helpers.invokecall.model.* import com.github.klee0kai.thekey.stone.ksp.helpers.qualifierAnnotations import com.github.klee0kai.thekey.stone.ksp.helpers.wrap.WrapHelper +import com.github.klee0kai.thekey.stone.ksp.ksp.cacheProtected import com.github.klee0kai.thekey.stone.ksp.ksp.getAllMethods import com.github.klee0kai.thekey.stone.ksp.ksp.isNotPrimitive import com.github.klee0kai.thekey.stone.ksp.ksp.resolveNotNullable @@ -67,7 +68,7 @@ class ModulesGraph( val returnType = m.returnType?.resolveNotNullable()?.toTypeName() ?: continue val provTypeName = wrapHelper.nonWrappedType(returnType) val isCached = m.getAnnotationsByType(Provide::class) - .firstOrNull()?.cache !in listOf(Provide.CacheType.Factory, null) + .firstOrNull()?.cacheProtected !in listOf(Provide.CacheType.Factory, null) val isBindInstance = m.getAnnotationsByType(BindInstance::class).firstOrNull() != null provideTypeCodes.putIfAbsent(provTypeName, HashSet()) @@ -118,7 +119,7 @@ class ModulesGraph( val provTypeName = wrapHelper.nonWrappedType(returnType) val isCached = componentMethod.getAnnotationsByType(Provide::class) - .firstOrNull()?.cache !in listOf(Provide.CacheType.Factory, null) + .firstOrNull()?.cacheProtected !in listOf(Provide.CacheType.Factory, null) val isBindInstance = componentMethod.getAnnotationsByType(BindInstance::class).firstOrNull() != null provideTypeCodes.putIfAbsent(provTypeName, HashSet()) diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/wrap/WrapHelper.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/wrap/WrapHelper.kt index 3ad43f0a..d1b9e16d 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/wrap/WrapHelper.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/wrap/WrapHelper.kt @@ -1,5 +1,6 @@ package com.github.klee0kai.thekey.stone.ksp.helpers.wrap +import com.github.klee0kai.stone.weakref.Provider import com.github.klee0kai.stone.weakref.Ref import com.github.klee0kai.stone.weakref.SoftRef import com.github.klee0kai.stone.weakref.WeakRef @@ -16,7 +17,6 @@ import java.lang.ref.Reference import java.lang.ref.SoftReference import java.lang.ref.WeakReference import java.util.* -import javax.inject.Provider class WrapHelper { @@ -224,7 +224,7 @@ class WrapHelper { WeakRef::class, SoftRef::class, )) { - val creator = cl.asClassName() + val creator = cl.asClassName() val wrapType = WrapType( typeName = creator, @@ -282,6 +282,7 @@ class WrapHelper { PhantomProvide::class, Ref::class, Provider::class, + javax.inject.Provider::class, LazyProvide::class, AsyncCoroutineProvide::class )) { @@ -312,6 +313,8 @@ class WrapHelper { support(wrapType) } + + for (cl in listOf( LinkedList::class, ArrayList::class, diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/ksp/AnnotationProtectedExt.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/ksp/AnnotationProtectedExt.kt index d99e2638..eb709d71 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/ksp/AnnotationProtectedExt.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/ksp/AnnotationProtectedExt.kt @@ -1,5 +1,7 @@ package com.github.klee0kai.thekey.stone.ksp.ksp +import com.github.klee0kai.stone.annotations.component.ProtectInjected +import com.github.klee0kai.stone.annotations.component.SwitchCache import com.github.klee0kai.stone.annotations.module.BindInstance import com.github.klee0kai.stone.annotations.module.Provide @@ -11,4 +13,21 @@ val Provide.cacheProtected get() = runCatching { cache }.getOrNull() ?: Provide. /** * fix crash at :tests:kspKotlinWasmJs */ -val BindInstance.cacheProtected get() = runCatching { cache }.getOrNull() ?: BindInstance.CacheType.Soft \ No newline at end of file +val BindInstance.cacheProtected get() = runCatching { cache }.getOrNull() ?: BindInstance.CacheType.Soft + + +/** + * fix crash at :tests:kspKotlinWasmJs + */ +val SwitchCache.cacheProtected get() = runCatching { cache }.getOrNull() ?: SwitchCache.CacheType.Default + +/** + * fix crash at :tests:kspKotlinWasmJs + */ +val SwitchCache.timeMillisProtected get() = runCatching { timeMillis }.getOrNull() ?: -1 + + +/** + * fix crash at :tests:kspKotlinWasmJs + */ +val ProtectInjected.timeMillisProtected get() = runCatching { timeMillis }.getOrNull() ?: 5000L diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/component/GenComponentProcessor.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/component/GenComponentProcessor.kt index 31940563..fa0ae3be 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/component/GenComponentProcessor.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/component/GenComponentProcessor.kt @@ -22,12 +22,10 @@ import com.github.klee0kai.thekey.stone.ksp.helpers.invokecall.ModulesGraph import com.github.klee0kai.thekey.stone.ksp.helpers.invokecall.model.toFieldDetail import com.github.klee0kai.thekey.stone.ksp.helpers.invokecall.model.toQualifierAnn import com.github.klee0kai.thekey.stone.ksp.helpers.wrap.WrapHelper +import com.github.klee0kai.thekey.stone.ksp.ksp.* import com.github.klee0kai.thekey.stone.ksp.ksp.arch.GenSpec import com.github.klee0kai.thekey.stone.ksp.ksp.arch.SymbolsToProcess import com.github.klee0kai.thekey.stone.ksp.ksp.arch.TargetFileProcessor -import com.github.klee0kai.thekey.stone.ksp.ksp.getAllMethods -import com.github.klee0kai.thekey.stone.ksp.ksp.resolveAlias -import com.github.klee0kai.thekey.stone.ksp.ksp.resolveNotNullable import com.github.klee0kai.thekey.stone.ksp.poet.* import com.github.klee0kai.thekey.stone.ksp.target.module.GenModuleProcessor import com.google.devtools.ksp.KspExperimental @@ -441,7 +439,11 @@ class GenComponentProcessor : TargetFileProcessor { for (injectField in injectableCl.getAllProperties()) { - if (!injectField.anyAnnotation(Inject::class.asClassName()).any()) continue + if (!injectField.anyAnnotation( + Inject::class.asClassName(), + javax.inject.Inject::class.asClassName() + ).any() + ) continue val provideCode = modulesGraph.codeProvideType( methodName = null, @@ -469,7 +471,11 @@ class GenComponentProcessor : TargetFileProcessor { } for (injectMethod in injectableCl.getAllMethods(false, false, "")) { - if (!injectMethod.anyAnnotation(Inject::class.asClassName()).any()) continue + if (!injectMethod.anyAnnotation( + Inject::class.asClassName(), + javax.inject.Inject::class.asClassName() + ).any() + ) continue val providingArgsCode = CodeBlock.builder() for (injectField in injectMethod.parameters) { val provideCode = modulesGraph.codeProvideType( @@ -516,7 +522,11 @@ class GenComponentProcessor : TargetFileProcessor { lifeCycleOwnerArg.name!!.asString(), ) for (injectField in injectableCl.getAllProperties()) { - if (!injectField.anyAnnotation(Inject::class.asClassName()).any()) continue + if (!injectField.anyAnnotation( + Inject::class.asClassName(), + javax.inject.Inject::class.asClassName() + ).any() + ) continue if (wrapHelper.isNonCachingWrapper(injectField.type.resolveNotNullable().toClassName())) { //nothing to protect continue @@ -548,7 +558,7 @@ class GenComponentProcessor : TargetFileProcessor { wrapHelper: WrapHelper, ) { val protectTimeMillis = method.getAnnotationsByType(ProtectInjected::class) - .firstOrNull()?.timeMillis + .firstOrNull()?.timeMillisProtected ?: throw IncorrectSignatureException( message = "Use ProtectInjected annotation at method ${componentCl.simpleName.asString()}.${method.simpleName.asString()}", element = method, @@ -573,7 +583,12 @@ class GenComponentProcessor : TargetFileProcessor { for (injectField in injectableCl.getAllProperties()) { - if (!injectField.anyAnnotation(Inject::class.asClassName()).any()) continue + if (!injectField.anyAnnotation( + Inject::class.asClassName(), + javax.inject.Inject::class.asClassName() + ).any() + ) continue + if (wrapHelper.isNonCachingWrapper(injectField.type.resolveNotNullable().toTypeName())) { //nothing to protect continue @@ -653,8 +668,8 @@ class GenComponentProcessor : TargetFileProcessor { addStatement( "val switchCacheParams = %T( %T.%L , %L )", SwitchCacheParam::class, - SwitchCache.CacheType::class, switchCacheAnn.cache.name, - switchCacheAnn.timeMillis, + SwitchCache.CacheType::class, switchCacheAnn.cacheProtected.name, + switchCacheAnn.timeMillisProtected, ) addStatement( diff --git a/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/annotations/component/Component.kt b/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/annotations/component/Component.kt index de749644..40aceff2 100644 --- a/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/annotations/component/Component.kt +++ b/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/annotations/component/Component.kt @@ -231,7 +231,6 @@ annotation class Component( */ val identifiers: Array> = [], - /** * TODO Kdoc */ diff --git a/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/annotations/component/GcSoftScope.kt b/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/annotations/component/GcSoftScope.kt index 08107bd2..6e668afb 100644 --- a/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/annotations/component/GcSoftScope.kt +++ b/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/annotations/component/GcSoftScope.kt @@ -1,8 +1,8 @@ package com.github.klee0kai.stone.annotations.component - import com.github.klee0kai.stone.weakref.Scope + /** * A standard library scope that lists all cached objects using soft references. * Used for garbage collection and caching change methods. diff --git a/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/annotations/component/GcWeakScope.kt b/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/annotations/component/GcWeakScope.kt index 11b01e77..8a0dd7cf 100644 --- a/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/annotations/component/GcWeakScope.kt +++ b/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/annotations/component/GcWeakScope.kt @@ -1,8 +1,8 @@ package com.github.klee0kai.stone.annotations.component - import com.github.klee0kai.stone.weakref.Scope + /** * A standard library scope that enumerates all cacheable objects using weak references. * Used for garbage collection and caching change methods. diff --git a/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/annotations/qualifier/IgnoreQualifier.kt b/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/annotations/qualifier/IgnoreQualifier.kt index a07d1d49..02a854e5 100644 --- a/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/annotations/qualifier/IgnoreQualifier.kt +++ b/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/annotations/qualifier/IgnoreQualifier.kt @@ -1,7 +1,5 @@ package com.github.klee0kai.stone.annotations.qualifier -import com.github.klee0kai.stone.weakref.Qualifier - /** * For dependencies, we ignore all qualifier rules. * If we collect dependencies into a collection, all available implementations with all qualifiers will be collected. diff --git a/tests/build.gradle.kts b/tests/build.gradle.kts index 69730d2b..5828c731 100644 --- a/tests/build.gradle.kts +++ b/tests/build.gradle.kts @@ -16,13 +16,25 @@ kotlin { wasmJs() sourceSets { - commonMain.dependencies { - implementation(project(":stone_multiplatform")) - + val commonMain by getting { + dependencies { + implementation(project(":stone_multiplatform")) + } } - commonTest.dependencies { - implementation(kotlin("test")) + +// val linuxMain by getting + + val jsMain by getting + val wasmJsMain by getting + + + val commonTest by getting { + dependencies { + implementation(kotlin("test")) + } } + + } } diff --git a/tests/src/commonMain/kotlin/com/github/klee0kai/test/wire/Wire.kt b/tests/src/commonMain/kotlin/com/github/klee0kai/test/wire/Wire.kt index 838beec8..d4673252 100644 --- a/tests/src/commonMain/kotlin/com/github/klee0kai/test/wire/Wire.kt +++ b/tests/src/commonMain/kotlin/com/github/klee0kai/test/wire/Wire.kt @@ -1,10 +1,13 @@ +@file:OptIn(ExperimentalUuidApi::class) + package com.github.klee0kai.test.wire -import java.util.* +import kotlin.uuid.ExperimentalUuidApi +import kotlin.uuid.Uuid class Wire { - val uuid: UUID = UUID.randomUUID() + val uuid: String = Uuid.random().toString() var input: Input? = null diff --git a/tests/src/commonMain/kotlin/com/github/klee0kai/test/wire/types/Hdmi.kt b/tests/src/commonMain/kotlin/com/github/klee0kai/test/wire/types/Hdmi.kt index 8652a362..c3c1e50a 100644 --- a/tests/src/commonMain/kotlin/com/github/klee0kai/test/wire/types/Hdmi.kt +++ b/tests/src/commonMain/kotlin/com/github/klee0kai/test/wire/types/Hdmi.kt @@ -1,7 +1,11 @@ +@file:OptIn(ExperimentalUuidApi::class) + package com.github.klee0kai.test.wire.types -import java.util.* +import kotlin.uuid.ExperimentalUuidApi +import kotlin.uuid.Uuid + class Hdmi { - val uuid: UUID = UUID.randomUUID() + val uuid: String = Uuid.random().toString() } diff --git a/tests/src/commonMain/kotlin/com/github/klee0kai/test/wire/types/MiniUsb.kt b/tests/src/commonMain/kotlin/com/github/klee0kai/test/wire/types/MiniUsb.kt index b20f8055..27249cda 100644 --- a/tests/src/commonMain/kotlin/com/github/klee0kai/test/wire/types/MiniUsb.kt +++ b/tests/src/commonMain/kotlin/com/github/klee0kai/test/wire/types/MiniUsb.kt @@ -1,7 +1,10 @@ +@file:OptIn(ExperimentalUuidApi::class) + package com.github.klee0kai.test.wire.types -import java.util.* +import kotlin.uuid.ExperimentalUuidApi +import kotlin.uuid.Uuid class MiniUsb { - val uuid: UUID = UUID.randomUUID() + val uuid: String = Uuid.random().toString() } diff --git a/tests/src/commonMain/kotlin/com/github/klee0kai/test/wire/types/Usb.kt b/tests/src/commonMain/kotlin/com/github/klee0kai/test/wire/types/Usb.kt index 6da85181..2ba84ebb 100644 --- a/tests/src/commonMain/kotlin/com/github/klee0kai/test/wire/types/Usb.kt +++ b/tests/src/commonMain/kotlin/com/github/klee0kai/test/wire/types/Usb.kt @@ -1,7 +1,10 @@ +@file:OptIn(ExperimentalUuidApi::class) + package com.github.klee0kai.test.wire.types -import java.util.* +import kotlin.uuid.ExperimentalUuidApi +import kotlin.uuid.Uuid class Usb { - val uuid: UUID = UUID.randomUUID() + val uuid: String = Uuid.random().toString() } diff --git a/tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/lifecycle/OnePhoneRepairTests.kt b/tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/lifecycle/OnePhoneRepairTests.kt index cc799d0b..7757e39f 100644 --- a/tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/lifecycle/OnePhoneRepairTests.kt +++ b/tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/lifecycle/OnePhoneRepairTests.kt @@ -4,7 +4,6 @@ import com.github.klee0kai.stone.weakref.Memory import com.github.klee0kai.stone.weakref.WeakRef import com.github.klee0kai.test.di.base_phone.PhoneComponentStoneComponent import com.github.klee0kai.test.tech.phone.OnePhone -import java.util.* import kotlin.test.* /** @@ -49,7 +48,7 @@ class OnePhoneRepairTests { } @Test - @Throws(InterruptedException::class) +// @Throws(InterruptedException::class) fun onePhoneDropWatterTest() { //Given val DI = PhoneComponentStoneComponent() diff --git a/tests/src/jsMain/kotlin/com/github/klee0kai/test/di/bindinstance/simple/GodWorkspaceComponent.js.kt b/tests/src/jsMain/kotlin/com/github/klee0kai/test/di/bindinstance/simple/GodWorkspaceComponent.js.kt index 4f7a8258..53674937 100644 --- a/tests/src/jsMain/kotlin/com/github/klee0kai/test/di/bindinstance/simple/GodWorkspaceComponent.js.kt +++ b/tests/src/jsMain/kotlin/com/github/klee0kai/test/di/bindinstance/simple/GodWorkspaceComponent.js.kt @@ -1,3 +1,3 @@ package com.github.klee0kai.test.di.bindinstance.simple -actual fun genGodWorkspaceComponent() = GodWorkspaceComponentStoneComponent() \ No newline at end of file +actual fun genGodWorkspaceComponent(): GodWorkspaceComponent = GodWorkspaceComponentStoneComponent() \ No newline at end of file diff --git a/tests/src/linuxX64Main/kotlin/com/github/klee0kai/test/di/bindinstance/simple/GodWorkspaceComponent.linuxX64.kt b/tests/src/linuxX64Main/kotlin/com/github/klee0kai/test/di/bindinstance/simple/GodWorkspaceComponent.linuxX64.kt new file mode 100644 index 00000000..3befc68f --- /dev/null +++ b/tests/src/linuxX64Main/kotlin/com/github/klee0kai/test/di/bindinstance/simple/GodWorkspaceComponent.linuxX64.kt @@ -0,0 +1,3 @@ +package com.github.klee0kai.test.di.bindinstance.simple + +actual fun genGodWorkspaceComponent(): GodWorkspaceComponent = GodWorkspaceComponentStoneComponent() diff --git a/tests/src/wasmJsMain/kotlin/com/github/klee0kai/test/di/bindinstance/simple/GodWorkspaceComponent.wasmJs.kt b/tests/src/wasmJsMain/kotlin/com/github/klee0kai/test/di/bindinstance/simple/GodWorkspaceComponent.wasmJs.kt new file mode 100644 index 00000000..5fd02eef --- /dev/null +++ b/tests/src/wasmJsMain/kotlin/com/github/klee0kai/test/di/bindinstance/simple/GodWorkspaceComponent.wasmJs.kt @@ -0,0 +1,4 @@ +package com.github.klee0kai.test.di.bindinstance.simple + +actual fun genGodWorkspaceComponent( +): GodWorkspaceComponent = GodWorkspaceComponentStoneComponent() diff --git a/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/mowgli/identity/FamilyIdeology.kt b/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/mowgli/identity/FamilyIdeology.kt index 320f13cc..e851d989 100644 --- a/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/mowgli/identity/FamilyIdeology.kt +++ b/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/mowgli/identity/FamilyIdeology.kt @@ -1,12 +1,15 @@ +@file:OptIn(ExperimentalUuidApi::class) + package com.github.klee0kai.test_ext.inject.mowgli.identity import com.github.klee0kai.test.mowgli.identity.Ideology -import java.util.* +import kotlin.uuid.ExperimentalUuidApi +import kotlin.uuid.Uuid class FamilyIdeology : Ideology() { - override var uuid: UUID = UUID.randomUUID() - + override var uuid: String = Uuid.random().toString() override val isFamilyIdeology: Boolean get() = true + } diff --git a/weakref_multiplatform/src/jsMain/kotlin/com/github/klee0kai/stone/weakref/SoftRef.js.kt b/weakref_multiplatform/src/jsMain/kotlin/com/github/klee0kai/stone/weakref/SoftRef.js.kt index 02e7aac1..49001f4a 100644 --- a/weakref_multiplatform/src/jsMain/kotlin/com/github/klee0kai/stone/weakref/SoftRef.js.kt +++ b/weakref_multiplatform/src/jsMain/kotlin/com/github/klee0kai/stone/weakref/SoftRef.js.kt @@ -7,7 +7,9 @@ actual class SoftRef actual constructor(value: T) : Ref, AutoClose init { val hasWeakRef = js("typeof WeakRef !== 'undefined'") as Boolean - if (hasWeakRef) { + val isObject = value != null && jsTypeOf(value) == "object" + + if (hasWeakRef && isObject) { weakRefDynamic = js("new WeakRef")(value) strongFallback = null } else { From 81ca8144170dc0135fcdd698e3a7e135e6a33767 Mon Sep 17 00:00:00 2001 From: klee0kai Date: Sat, 21 Feb 2026 21:49:04 +0100 Subject: [PATCH 113/122] js weak refs --- tests/build.gradle.kts | 2 -- .../klee0kai/stone/weakref/SoftRef.js.kt | 34 ++++--------------- .../github/klee0kai/stone/weakref/WeakRef.kt | 32 ++++------------- .../src/jsMain/kotlin/js/WeakRef.kt | 5 +++ .../klee0kai/stone/weakref/WeakRefTest.kt | 26 ++++++++++++++ .../klee0kai/stone/weakref/SoftRef.js.kt | 19 +++++++++++ .../klee0kai/stone/weakref/SoftRef.wasmJs.kt | 18 ---------- .../github/klee0kai/stone/weakref/WeakRef.kt | 19 +++++++++++ .../klee0kai/stone/weakref/WeakRef.wasmJs.kt | 18 ---------- .../src/wasmJsMain/kotlin/js/WeakRef.kt | 5 +++ 10 files changed, 86 insertions(+), 92 deletions(-) create mode 100644 weakref_multiplatform/src/jsMain/kotlin/js/WeakRef.kt create mode 100644 weakref_multiplatform/src/jsTest/kotlin/com/github/klee0kai/stone/weakref/WeakRefTest.kt create mode 100644 weakref_multiplatform/src/wasmJsMain/kotlin/com/github/klee0kai/stone/weakref/SoftRef.js.kt delete mode 100644 weakref_multiplatform/src/wasmJsMain/kotlin/com/github/klee0kai/stone/weakref/SoftRef.wasmJs.kt create mode 100644 weakref_multiplatform/src/wasmJsMain/kotlin/com/github/klee0kai/stone/weakref/WeakRef.kt delete mode 100644 weakref_multiplatform/src/wasmJsMain/kotlin/com/github/klee0kai/stone/weakref/WeakRef.wasmJs.kt create mode 100644 weakref_multiplatform/src/wasmJsMain/kotlin/js/WeakRef.kt diff --git a/tests/build.gradle.kts b/tests/build.gradle.kts index 5828c731..2a704203 100644 --- a/tests/build.gradle.kts +++ b/tests/build.gradle.kts @@ -22,8 +22,6 @@ kotlin { } } -// val linuxMain by getting - val jsMain by getting val wasmJsMain by getting diff --git a/weakref_multiplatform/src/jsMain/kotlin/com/github/klee0kai/stone/weakref/SoftRef.js.kt b/weakref_multiplatform/src/jsMain/kotlin/com/github/klee0kai/stone/weakref/SoftRef.js.kt index 49001f4a..5a41b388 100644 --- a/weakref_multiplatform/src/jsMain/kotlin/com/github/klee0kai/stone/weakref/SoftRef.js.kt +++ b/weakref_multiplatform/src/jsMain/kotlin/com/github/klee0kai/stone/weakref/SoftRef.js.kt @@ -1,41 +1,19 @@ package com.github.klee0kai.stone.weakref -actual class SoftRef actual constructor(value: T) : Ref, AutoCloseable { - - private var weakRefDynamic: dynamic = null - private var strongFallback: T? = null - - init { - val hasWeakRef = js("typeof WeakRef !== 'undefined'") as Boolean - val isObject = value != null && jsTypeOf(value) == "object" +import js.WeakRef as JsWeakRef - if (hasWeakRef && isObject) { - weakRefDynamic = js("new WeakRef")(value) - strongFallback = null - } else { - weakRefDynamic = null - strongFallback = value - } - } +actual class SoftRef actual constructor(value: T) : Ref, AutoCloseable { + var weakRef: JsWeakRef? = JsWeakRef(value) - actual override fun get(): T? { - return if (weakRefDynamic != null) { - val derefResult = weakRefDynamic.deref?.invoke() - derefResult as T? - } else { - strongFallback - } - } + actual override fun get(): T? = weakRef?.deref() actual fun clear() { - weakRefDynamic = null - strongFallback = null + weakRef = null } actual override fun close() { - weakRefDynamic = null - strongFallback = null + weakRef = null } } \ No newline at end of file diff --git a/weakref_multiplatform/src/jsMain/kotlin/com/github/klee0kai/stone/weakref/WeakRef.kt b/weakref_multiplatform/src/jsMain/kotlin/com/github/klee0kai/stone/weakref/WeakRef.kt index 7be98009..7be54454 100644 --- a/weakref_multiplatform/src/jsMain/kotlin/com/github/klee0kai/stone/weakref/WeakRef.kt +++ b/weakref_multiplatform/src/jsMain/kotlin/com/github/klee0kai/stone/weakref/WeakRef.kt @@ -1,39 +1,19 @@ package com.github.klee0kai.stone.weakref -actual class WeakRef actual constructor(value: T) : Ref, AutoCloseable { - - private var weakRefDynamic: dynamic = null - private var strongFallback: T? = null +import js.WeakRef as JsWeakRef - init { - val hasWeakRef = js("typeof WeakRef !== 'undefined'") as Boolean - if (hasWeakRef) { - weakRefDynamic = js("new WeakRef")(value) - strongFallback = null - } else { - weakRefDynamic = null - strongFallback = value - } - } +actual class WeakRef actual constructor(value: T) : Ref, AutoCloseable { + var weakRef: JsWeakRef? = JsWeakRef(value) - actual override fun get(): T? { - return if (weakRefDynamic != null) { - val derefResult = weakRefDynamic.deref?.invoke() - derefResult as T? - } else { - strongFallback - } - } + actual override fun get(): T? = weakRef?.deref() actual fun clear() { - weakRefDynamic = null - strongFallback = null + weakRef = null } actual override fun close() { - weakRefDynamic = null - strongFallback = null + weakRef = null } } \ No newline at end of file diff --git a/weakref_multiplatform/src/jsMain/kotlin/js/WeakRef.kt b/weakref_multiplatform/src/jsMain/kotlin/js/WeakRef.kt new file mode 100644 index 00000000..c1540229 --- /dev/null +++ b/weakref_multiplatform/src/jsMain/kotlin/js/WeakRef.kt @@ -0,0 +1,5 @@ +package js + +external class WeakRef(target: T) { + fun deref(): T? +} \ No newline at end of file diff --git a/weakref_multiplatform/src/jsTest/kotlin/com/github/klee0kai/stone/weakref/WeakRefTest.kt b/weakref_multiplatform/src/jsTest/kotlin/com/github/klee0kai/stone/weakref/WeakRefTest.kt new file mode 100644 index 00000000..aae36d19 --- /dev/null +++ b/weakref_multiplatform/src/jsTest/kotlin/com/github/klee0kai/stone/weakref/WeakRefTest.kt @@ -0,0 +1,26 @@ +package com.github.klee0kai.stone.weakref + +import kotlin.test.Test + +class WeakRefTest { + + data class SimpleDataClass( + val value: String, + ) + + @Test + fun simpleTest() { + console.log("SimpleDataClass") + val obj = SimpleDataClass("hee") + val link = WeakRef(obj) +// js("console.log")(obj) +// val jsObj0: dynamic = js("{ name: 'Alex', age: 17 }") +// val jsObj: dynamic = js("new WeakRef ({ name: 'Alex', age: 17 })") + + println("name " + link.get()) + +// val a = js("")(obj) + + } + +} \ No newline at end of file diff --git a/weakref_multiplatform/src/wasmJsMain/kotlin/com/github/klee0kai/stone/weakref/SoftRef.js.kt b/weakref_multiplatform/src/wasmJsMain/kotlin/com/github/klee0kai/stone/weakref/SoftRef.js.kt new file mode 100644 index 00000000..5a41b388 --- /dev/null +++ b/weakref_multiplatform/src/wasmJsMain/kotlin/com/github/klee0kai/stone/weakref/SoftRef.js.kt @@ -0,0 +1,19 @@ +package com.github.klee0kai.stone.weakref + +import js.WeakRef as JsWeakRef + +actual class SoftRef actual constructor(value: T) : Ref, AutoCloseable { + + var weakRef: JsWeakRef? = JsWeakRef(value) + + actual override fun get(): T? = weakRef?.deref() + + actual fun clear() { + weakRef = null + } + + actual override fun close() { + weakRef = null + } + +} \ No newline at end of file diff --git a/weakref_multiplatform/src/wasmJsMain/kotlin/com/github/klee0kai/stone/weakref/SoftRef.wasmJs.kt b/weakref_multiplatform/src/wasmJsMain/kotlin/com/github/klee0kai/stone/weakref/SoftRef.wasmJs.kt deleted file mode 100644 index 192ac47a..00000000 --- a/weakref_multiplatform/src/wasmJsMain/kotlin/com/github/klee0kai/stone/weakref/SoftRef.wasmJs.kt +++ /dev/null @@ -1,18 +0,0 @@ -package com.github.klee0kai.stone.weakref - - -actual class SoftRef actual constructor(value: T) : Ref, AutoCloseable { - - private var ref: T? = value - - actual override fun get(): T? = ref - - actual fun clear() { - ref = null - } - - actual override fun close() { - ref = null - } - -} \ No newline at end of file diff --git a/weakref_multiplatform/src/wasmJsMain/kotlin/com/github/klee0kai/stone/weakref/WeakRef.kt b/weakref_multiplatform/src/wasmJsMain/kotlin/com/github/klee0kai/stone/weakref/WeakRef.kt new file mode 100644 index 00000000..7be54454 --- /dev/null +++ b/weakref_multiplatform/src/wasmJsMain/kotlin/com/github/klee0kai/stone/weakref/WeakRef.kt @@ -0,0 +1,19 @@ +package com.github.klee0kai.stone.weakref + +import js.WeakRef as JsWeakRef + +actual class WeakRef actual constructor(value: T) : Ref, AutoCloseable { + + var weakRef: JsWeakRef? = JsWeakRef(value) + + actual override fun get(): T? = weakRef?.deref() + + actual fun clear() { + weakRef = null + } + + actual override fun close() { + weakRef = null + } + +} \ No newline at end of file diff --git a/weakref_multiplatform/src/wasmJsMain/kotlin/com/github/klee0kai/stone/weakref/WeakRef.wasmJs.kt b/weakref_multiplatform/src/wasmJsMain/kotlin/com/github/klee0kai/stone/weakref/WeakRef.wasmJs.kt deleted file mode 100644 index 41c8b2f3..00000000 --- a/weakref_multiplatform/src/wasmJsMain/kotlin/com/github/klee0kai/stone/weakref/WeakRef.wasmJs.kt +++ /dev/null @@ -1,18 +0,0 @@ -package com.github.klee0kai.stone.weakref - - -actual class WeakRef actual constructor(value: T) : Ref, AutoCloseable { - - private var ref: T? = value - - actual override fun get(): T? = ref - - actual fun clear() { - ref = null - } - - actual override fun close() { - ref = null - } - -} \ No newline at end of file diff --git a/weakref_multiplatform/src/wasmJsMain/kotlin/js/WeakRef.kt b/weakref_multiplatform/src/wasmJsMain/kotlin/js/WeakRef.kt new file mode 100644 index 00000000..c1540229 --- /dev/null +++ b/weakref_multiplatform/src/wasmJsMain/kotlin/js/WeakRef.kt @@ -0,0 +1,5 @@ +package js + +external class WeakRef(target: T) { + fun deref(): T? +} \ No newline at end of file From e4842d7605035ef3b936966f0abff3c11552bb70 Mon Sep 17 00:00:00 2001 From: klee0kai Date: Sat, 21 Feb 2026 22:52:00 +0100 Subject: [PATCH 114/122] migrate gc tests to jvm --- inject_multiplatform/build.gradle.kts | 5 +- stone_multiplatform/build.gradle.kts | 6 +- tests/build.gradle.kts | 6 +- .../MoonSkyProtectInjectedTests.kt | 30 ------ .../stone/test/cache/EarthSwitchCacheTests.kt | 22 ----- .../test/inject/HorseProtectInjectTests.kt | 26 ------ .../test/lifecycle/GoodPhoneRepairTests.kt | 75 --------------- .../test/lifecycle/OnePhoneRepairTests.kt | 73 --------------- .../MoonSkyProtectInjectedGcTests.kt | 63 +++++++++++++ .../test/cache/EarthSwitchCacheGcTests.kt | 35 +++++++ .../test/inject/HorseProtectInjectGcTests.kt | 39 ++++++++ .../test/lifecycle/GoodPhoneRepairGcTests.kt | 91 +++++++++++++++++++ .../test/lifecycle/OnePhoneRepairGcTests.kt | 86 ++++++++++++++++++ weakref_multiplatform/build.gradle.kts | 5 +- .../klee0kai/stone/weakref/SoftRef.js.kt | 2 +- .../github/klee0kai/stone/weakref/WeakRef.kt | 2 +- .../src/wasmJsMain/kotlin/js/WeakRef.kt | 2 +- 17 files changed, 333 insertions(+), 235 deletions(-) create mode 100644 tests/src/jvmTest/kotlin/com/github/klee0kai/stone/test/bindinstance/singlemethod_inject/MoonSkyProtectInjectedGcTests.kt create mode 100644 tests/src/jvmTest/kotlin/com/github/klee0kai/stone/test/cache/EarthSwitchCacheGcTests.kt create mode 100644 tests/src/jvmTest/kotlin/com/github/klee0kai/stone/test/inject/HorseProtectInjectGcTests.kt create mode 100644 tests/src/jvmTest/kotlin/com/github/klee0kai/stone/test/lifecycle/GoodPhoneRepairGcTests.kt create mode 100644 tests/src/jvmTest/kotlin/com/github/klee0kai/stone/test/lifecycle/OnePhoneRepairGcTests.kt diff --git a/inject_multiplatform/build.gradle.kts b/inject_multiplatform/build.gradle.kts index 007827c7..3bc13cd6 100644 --- a/inject_multiplatform/build.gradle.kts +++ b/inject_multiplatform/build.gradle.kts @@ -16,7 +16,10 @@ kotlin { linuxX64() mingwX64() - wasmJs() + wasmJs { + browser() + nodejs() + } sourceSets { commonMain.dependencies { diff --git a/stone_multiplatform/build.gradle.kts b/stone_multiplatform/build.gradle.kts index 9957fdb3..1ec0e042 100644 --- a/stone_multiplatform/build.gradle.kts +++ b/stone_multiplatform/build.gradle.kts @@ -17,8 +17,10 @@ kotlin { linuxX64() mingwX64() - wasmJs() - + wasmJs { + browser() + nodejs() + } sourceSets { commonMain.dependencies { api(project(":inject_multiplatform")) diff --git a/tests/build.gradle.kts b/tests/build.gradle.kts index 2a704203..2b15cbb8 100644 --- a/tests/build.gradle.kts +++ b/tests/build.gradle.kts @@ -13,7 +13,10 @@ kotlin { linuxX64() mingwX64() - wasmJs() + wasmJs { + browser() + nodejs() + } sourceSets { val commonMain by getting { @@ -32,7 +35,6 @@ kotlin { } } - } } diff --git a/tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/bindinstance/singlemethod_inject/MoonSkyProtectInjectedTests.kt b/tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/bindinstance/singlemethod_inject/MoonSkyProtectInjectedTests.kt index df63be60..13371093 100644 --- a/tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/bindinstance/singlemethod_inject/MoonSkyProtectInjectedTests.kt +++ b/tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/bindinstance/singlemethod_inject/MoonSkyProtectInjectedTests.kt @@ -1,13 +1,11 @@ package com.github.klee0kai.stone.test.bindinstance.singlemethod_inject -import com.github.klee0kai.stone.weakref.Memory import com.github.klee0kai.stone.weakref.WeakRef import com.github.klee0kai.test.di.bindinstance.singlemethod_inject.StarSkyComponentStoneComponent import com.github.klee0kai.test.mowgli.MoonSky import com.github.klee0kai.test.mowgli.galaxy.Mercury import com.github.klee0kai.test.mowgli.galaxy.Sun import kotlin.test.Test -import kotlin.test.assertNotNull import kotlin.test.assertNull class MoonSkyProtectInjectedTests { @@ -33,32 +31,4 @@ class MoonSkyProtectInjectedTests { assertNull(star.get()) } - - @Test - fun withProtectInjectedTest() { - //Given - Memory.gc() - val component = StarSkyComponentStoneComponent() - val mercury = WeakRef(Mercury()) - val star = WeakRef(Sun()) - component.starModule().star(star.get()) - component.mercury(mercury.get()) - - //When - var moonSky: MoonSky? = MoonSky() - component.inject(moonSky) - component.protectInjected(moonSky) - moonSky = null - component.gcAll() - - assertNotNull(mercury.get()) - assertNotNull(star.get()) - - //Then after protect finished -// Thread.sleep(100) - Memory.gc() - assertNull(mercury.get()) - assertNull(star.get()) - } - } diff --git a/tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/cache/EarthSwitchCacheTests.kt b/tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/cache/EarthSwitchCacheTests.kt index 05aa5b00..8e64c0d1 100644 --- a/tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/cache/EarthSwitchCacheTests.kt +++ b/tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/cache/EarthSwitchCacheTests.kt @@ -39,28 +39,6 @@ class EarthSwitchCacheTests { assertNotNull(mountainSoft.get()) } - @Test - fun weakToStrongFewMillisTest() { - //Given - val DI = SwitchCacheComponentStoneComponent() - val mountainWeak = WeakRef(DI.earth().mountainWeak()) - - //When - DI.allStrongFewMillis() - Memory.gc() - - //Then: can't GC - assertNotNull(mountainWeak.get()) - - //When: after few millis -// Thread.sleep(110) - Memory.gc() - - //Then: can GC - assertNull(mountainWeak.get()) - } - - @Test fun mountainToWeakTest() { //Given diff --git a/tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/inject/HorseProtectInjectTests.kt b/tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/inject/HorseProtectInjectTests.kt index d4b6bd34..59d4d0f7 100644 --- a/tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/inject/HorseProtectInjectTests.kt +++ b/tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/inject/HorseProtectInjectTests.kt @@ -31,30 +31,4 @@ class HorseProtectInjectTests { assertNull(historyWeakReference.get()) } - @Test - fun withProtectInjectTest() { - // Given - val DI = ForestComponentStoneComponent() - var horse: Horse? = Horse() - - //When - DI.inject( - horse, - stoneLifeCycleOwner = {} - ) - - val historyWeakReference = WeakRef(horse!!.history) - DI.protectInjected(horse) - horse = null - DI.gcAll() - - //Then - assertNotNull(historyWeakReference.get()) - - //after protect finished -// Thread.sleep(50) - DI.gcAll() - assertNull(historyWeakReference.get()) - } - } diff --git a/tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/lifecycle/GoodPhoneRepairTests.kt b/tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/lifecycle/GoodPhoneRepairTests.kt index fb7702cf..0fa3ee18 100644 --- a/tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/lifecycle/GoodPhoneRepairTests.kt +++ b/tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/lifecycle/GoodPhoneRepairTests.kt @@ -49,79 +49,4 @@ class GoodPhoneRepairTests { assertNull(ramRef.get()) } - @Test -// @Throws(InterruptedException::class) - fun goodPhoneDropWatterTest() { - //Given - val DI = PhoneComponentStoneComponent() - val goodPhone = GoodPhone() - DI.inject(goodPhone, goodPhone.lifeCycleOwner, DataStorageSize("64G"), RamSize("4G")) - val batteryRef = WeakRef(goodPhone.battery) - val dataStorageRef = WeakRef(goodPhone.dataStorage) - val ramRef = WeakRef(goodPhone.ram) - - //When - goodPhone.dropToWater() - Memory.gc() - - //Then: Phone not link with his components - assertNull(goodPhone.battery) - assertNull(goodPhone.dataStorage) - assertNull(goodPhone.ram) - - //Then: Phone components is alive little time. - assertNotNull(batteryRef.get()) - assertNotNull(dataStorageRef.get()) - assertNotNull(ramRef.get()) - - //When: After little time -// Thread.sleep(120) - Memory.gc() - - //Then: Phone can not be repaired, components lost - assertNull(batteryRef.get()) - assertNull(dataStorageRef.get()) - assertNull(ramRef.get()) - } - - - @Test -// @Throws(InterruptedException::class) - fun goodPhoneDrownedRepairTest() { - //Given - val DI = PhoneComponentStoneComponent() - val goodPhone = GoodPhone() - DI.inject(goodPhone, goodPhone.lifeCycleOwner, DataStorageSize("64G"), RamSize("4G")) - val ramUuid = goodPhone.dataStorage!!.uuid - - //When - goodPhone.dropToWater() -// Thread.sleep(10) - Memory.gc() - DI.inject(goodPhone, goodPhone.lifeCycleOwner, DataStorageSize("64G"), RamSize("4G")) - - //Then: Can be repair after little time - assertEquals(ramUuid, goodPhone.dataStorage!!.uuid) - } - - - @Test -// @Throws(InterruptedException::class) - fun goodPhoneDeepDrownedRepairTest() { - //Given - val DI = PhoneComponentStoneComponent() - val goodPhone = GoodPhone() - DI.inject(goodPhone, goodPhone.lifeCycleOwner, DataStorageSize("64G"), RamSize("4G")) - val ramUuid = goodPhone.dataStorage!!.uuid - - //When - goodPhone.dropToWater() -// Thread.sleep(120) - Memory.gc() - DI.inject(goodPhone, goodPhone.lifeCycleOwner, DataStorageSize("64G"), RamSize("4G")) - - //Then: Can not be repair without new details - assertNotEquals(ramUuid, goodPhone.dataStorage!!.uuid) - } - } diff --git a/tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/lifecycle/OnePhoneRepairTests.kt b/tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/lifecycle/OnePhoneRepairTests.kt index 7757e39f..0b808bb7 100644 --- a/tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/lifecycle/OnePhoneRepairTests.kt +++ b/tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/lifecycle/OnePhoneRepairTests.kt @@ -47,78 +47,5 @@ class OnePhoneRepairTests { assertNull(ramRef.get()) } - @Test -// @Throws(InterruptedException::class) - fun onePhoneDropWatterTest() { - //Given - val DI = PhoneComponentStoneComponent() - val onePhone: OnePhone = OnePhone() - DI.inject(onePhone) - val batteryRef = WeakRef(onePhone.battery) - val dataStorageRef = WeakRef(onePhone.dataStorage) - val ramRef = WeakRef(onePhone.ram) - - //When - onePhone.dropToWatter() - Memory.gc() - - //Then: Phone not link with his components - assertNull(onePhone.battery) - assertNull(onePhone.dataStorage) - assertNull(onePhone.ram) - //Then: Phone components is alive little time. - assertNotNull(batteryRef.get()) - assertNotNull(dataStorageRef.get()) - assertNotNull(ramRef.get()) - - //When: After little time -// Thread.sleep(120) - Memory.gc() - - //Then: Phone can not be repaired, components lost - assertNull(batteryRef.get()) - assertNull(dataStorageRef.get()) - assertNull(ramRef.get()) - } - - - @Test -// @Throws(InterruptedException::class) - fun onePhoneDrownedRepairTest() { - //Given - val DI = PhoneComponentStoneComponent() - val onePhone: OnePhone = OnePhone() - DI.inject(onePhone) - val ramUuid: String = onePhone.dataStorage!!.uuid - - //When - onePhone.dropToWatter() -// Thread.sleep(10) - Memory.gc() - DI.inject(onePhone) - - //Then: Can be repair after little time - assertEquals(ramUuid, onePhone.dataStorage?.uuid) - } - - - @Test -// @Throws(InterruptedException::class) - fun onePhoneDeepDrownedRepairTest() { - //Given - val DI = PhoneComponentStoneComponent() - val onePhone: OnePhone = OnePhone() - DI.inject(onePhone) - val ramUuid: String = onePhone.dataStorage!!.uuid - - //When - onePhone.dropToWatter() -// Thread.sleep(120) - Memory.gc() - DI.inject(onePhone) - - //Then: Can not be repair without new details - assertNotEquals(ramUuid, onePhone.dataStorage!!.uuid) - } } diff --git a/tests/src/jvmTest/kotlin/com/github/klee0kai/stone/test/bindinstance/singlemethod_inject/MoonSkyProtectInjectedGcTests.kt b/tests/src/jvmTest/kotlin/com/github/klee0kai/stone/test/bindinstance/singlemethod_inject/MoonSkyProtectInjectedGcTests.kt new file mode 100644 index 00000000..aac6c4fd --- /dev/null +++ b/tests/src/jvmTest/kotlin/com/github/klee0kai/stone/test/bindinstance/singlemethod_inject/MoonSkyProtectInjectedGcTests.kt @@ -0,0 +1,63 @@ +package com.github.klee0kai.stone.test.bindinstance.singlemethod_inject + +import com.github.klee0kai.stone.weakref.Memory +import com.github.klee0kai.stone.weakref.WeakRef +import com.github.klee0kai.test.di.bindinstance.singlemethod_inject.StarSkyComponentStoneComponent +import com.github.klee0kai.test.mowgli.MoonSky +import com.github.klee0kai.test.mowgli.galaxy.Mercury +import com.github.klee0kai.test.mowgli.galaxy.Sun +import kotlin.test.Test +import kotlin.test.assertNotNull +import kotlin.test.assertNull + +class MoonSkyProtectInjectedGcTests { + + @Test + fun withoutProtectInjectedTest() { + //Given + val component = StarSkyComponentStoneComponent() + val mercury = WeakRef(Mercury()) + val star = WeakRef(Sun()) + component.starModule().star(star.get()) + component.mercury(mercury.get()) + + //When + var moonSky: MoonSky? = MoonSky() + component.inject(moonSky) + moonSky = null + component.gcAll() + + //Then + assertNull(mercury.get()) + assertNull(star.get()) + } + + + @Test + fun withProtectInjectedTest() { + //Given + Memory.gc() + val component = StarSkyComponentStoneComponent() + val mercury = WeakRef(Mercury()) + val star = WeakRef(Sun()) + component.starModule().star(star.get()) + component.mercury(mercury.get()) + + //When + var moonSky: MoonSky? = MoonSky() + component.inject(moonSky) + component.protectInjected(moonSky) + moonSky = null + component.gcAll() + + assertNotNull(mercury.get()) + assertNotNull(star.get()) + + //Then after protect finished + Thread.sleep(100) + Memory.gc() + assertNull(mercury.get()) + assertNull(star.get()) + } + +} diff --git a/tests/src/jvmTest/kotlin/com/github/klee0kai/stone/test/cache/EarthSwitchCacheGcTests.kt b/tests/src/jvmTest/kotlin/com/github/klee0kai/stone/test/cache/EarthSwitchCacheGcTests.kt new file mode 100644 index 00000000..d9d19838 --- /dev/null +++ b/tests/src/jvmTest/kotlin/com/github/klee0kai/stone/test/cache/EarthSwitchCacheGcTests.kt @@ -0,0 +1,35 @@ +package com.github.klee0kai.stone.test.cache + +import com.github.klee0kai.stone.weakref.Memory +import com.github.klee0kai.stone.weakref.WeakRef +import com.github.klee0kai.test.di.swcache.SwitchCacheComponentStoneComponent +import kotlin.test.Test +import kotlin.test.assertNotNull +import kotlin.test.assertNull + +class EarthSwitchCacheGcTests { + + + @Test + fun weakToStrongFewMillisTest() { + //Given + val DI = SwitchCacheComponentStoneComponent() + val mountainWeak = WeakRef(DI.earth().mountainWeak()) + + //When + DI.allStrongFewMillis() + Memory.gc() + + //Then: can't GC + assertNotNull(mountainWeak.get()) + + //When: after few millis + Thread.sleep(110) + Memory.gc() + + //Then: can GC + assertNull(mountainWeak.get()) + } + + +} diff --git a/tests/src/jvmTest/kotlin/com/github/klee0kai/stone/test/inject/HorseProtectInjectGcTests.kt b/tests/src/jvmTest/kotlin/com/github/klee0kai/stone/test/inject/HorseProtectInjectGcTests.kt new file mode 100644 index 00000000..31be5e5a --- /dev/null +++ b/tests/src/jvmTest/kotlin/com/github/klee0kai/stone/test/inject/HorseProtectInjectGcTests.kt @@ -0,0 +1,39 @@ +package com.github.klee0kai.stone.test.inject + +import com.github.klee0kai.stone.weakref.WeakRef +import com.github.klee0kai.test.di.base_forest.ForestComponentStoneComponent +import com.github.klee0kai.test.mowgli.animal.Horse +import kotlin.test.Test +import kotlin.test.assertNotNull +import kotlin.test.assertNull + +class HorseProtectInjectGcTests { + + + @Test + fun withProtectInjectTest() { + // Given + val DI = ForestComponentStoneComponent() + var horse: Horse? = Horse() + + //When + DI.inject( + horse, + stoneLifeCycleOwner = {} + ) + + val historyWeakReference = WeakRef(horse!!.history) + DI.protectInjected(horse) + horse = null + DI.gcAll() + + //Then + assertNotNull(historyWeakReference.get()) + + //after protect finished + Thread.sleep(50) + DI.gcAll() + assertNull(historyWeakReference.get()) + } + +} diff --git a/tests/src/jvmTest/kotlin/com/github/klee0kai/stone/test/lifecycle/GoodPhoneRepairGcTests.kt b/tests/src/jvmTest/kotlin/com/github/klee0kai/stone/test/lifecycle/GoodPhoneRepairGcTests.kt new file mode 100644 index 00000000..9a4c23f8 --- /dev/null +++ b/tests/src/jvmTest/kotlin/com/github/klee0kai/stone/test/lifecycle/GoodPhoneRepairGcTests.kt @@ -0,0 +1,91 @@ +package com.github.klee0kai.stone.test.lifecycle + +import com.github.klee0kai.stone.weakref.Memory +import com.github.klee0kai.stone.weakref.WeakRef +import com.github.klee0kai.test.di.base_phone.PhoneComponentStoneComponent +import com.github.klee0kai.test.di.base_phone.identifiers.DataStorageSize +import com.github.klee0kai.test.di.base_phone.identifiers.RamSize +import com.github.klee0kai.test.tech.phone.GoodPhone +import kotlin.test.* + +/** + * Test lifecycle owner over LifecycleUtils + */ +class GoodPhoneRepairGcTests { + + + + @Test + fun goodPhoneDropWatterGcTest() { + + //Given + val DI = PhoneComponentStoneComponent() + val goodPhone = GoodPhone() + DI.inject(goodPhone, goodPhone.lifeCycleOwner, DataStorageSize("64G"), RamSize("4G")) + val batteryRef = WeakRef(goodPhone.battery) + val dataStorageRef = WeakRef(goodPhone.dataStorage) + val ramRef = WeakRef(goodPhone.ram) + + //When + goodPhone.dropToWater() + Memory.gc() + + //Then: Phone not link with his components + assertNull(goodPhone.battery) + assertNull(goodPhone.dataStorage) + assertNull(goodPhone.ram) + + //Then: Phone components is alive little time. + assertNotNull(batteryRef.get()) + assertNotNull(dataStorageRef.get()) + assertNotNull(ramRef.get()) + + //When: After little time + Thread.sleep(120) + Memory.gc() + + //Then: Phone can not be repaired, components lost + assertNull(batteryRef.get()) + assertNull(dataStorageRef.get()) + assertNull(ramRef.get()) + } + + + @Test + fun goodPhoneDrownedRepairTest() { + //Given + val DI = PhoneComponentStoneComponent() + val goodPhone = GoodPhone() + DI.inject(goodPhone, goodPhone.lifeCycleOwner, DataStorageSize("64G"), RamSize("4G")) + val ramUuid = goodPhone.dataStorage!!.uuid + + //When + goodPhone.dropToWater() + Thread.sleep(10) + Memory.gc() + DI.inject(goodPhone, goodPhone.lifeCycleOwner, DataStorageSize("64G"), RamSize("4G")) + + //Then: Can be repair after little time + assertEquals(ramUuid, goodPhone.dataStorage!!.uuid) + } + + + @Test + fun goodPhoneDeepDrownedRepairTest() { + //Given + val DI = PhoneComponentStoneComponent() + val goodPhone = GoodPhone() + DI.inject(goodPhone, goodPhone.lifeCycleOwner, DataStorageSize("64G"), RamSize("4G")) + val ramUuid = goodPhone.dataStorage!!.uuid + + //When + goodPhone.dropToWater() + Thread.sleep(120) + Memory.gc() + DI.inject(goodPhone, goodPhone.lifeCycleOwner, DataStorageSize("64G"), RamSize("4G")) + + //Then: Can not be repair without new details + assertNotEquals(ramUuid, goodPhone.dataStorage!!.uuid) + } + +} diff --git a/tests/src/jvmTest/kotlin/com/github/klee0kai/stone/test/lifecycle/OnePhoneRepairGcTests.kt b/tests/src/jvmTest/kotlin/com/github/klee0kai/stone/test/lifecycle/OnePhoneRepairGcTests.kt new file mode 100644 index 00000000..52abd63b --- /dev/null +++ b/tests/src/jvmTest/kotlin/com/github/klee0kai/stone/test/lifecycle/OnePhoneRepairGcTests.kt @@ -0,0 +1,86 @@ +package com.github.klee0kai.stone.test.lifecycle + +import com.github.klee0kai.stone.weakref.Memory +import com.github.klee0kai.stone.weakref.WeakRef +import com.github.klee0kai.test.di.base_phone.PhoneComponentStoneComponent +import com.github.klee0kai.test.tech.phone.OnePhone +import kotlin.test.* + +/** + * Test lifecycle owner implemented in providing model + */ +class OnePhoneRepairGcTests { + + + @Test + fun onePhoneDropWatterTest() { + //Given + val DI = PhoneComponentStoneComponent() + val onePhone: OnePhone = OnePhone() + DI.inject(onePhone) + val batteryRef = WeakRef(onePhone.battery) + val dataStorageRef = WeakRef(onePhone.dataStorage) + val ramRef = WeakRef(onePhone.ram) + + //When + onePhone.dropToWatter() + Memory.gc() + + //Then: Phone not link with his components + assertNull(onePhone.battery) + assertNull(onePhone.dataStorage) + assertNull(onePhone.ram) + + //Then: Phone components is alive little time. + assertNotNull(batteryRef.get()) + assertNotNull(dataStorageRef.get()) + assertNotNull(ramRef.get()) + + //When: After little time + Thread.sleep(120) + Memory.gc() + + //Then: Phone can not be repaired, components lost + assertNull(batteryRef.get()) + assertNull(dataStorageRef.get()) + assertNull(ramRef.get()) + } + + + @Test + fun onePhoneDrownedRepairTest() { + //Given + val DI = PhoneComponentStoneComponent() + val onePhone: OnePhone = OnePhone() + DI.inject(onePhone) + val ramUuid: String = onePhone.dataStorage!!.uuid + + //When + onePhone.dropToWatter() + Thread.sleep(10) + Memory.gc() + DI.inject(onePhone) + + //Then: Can be repair after little time + assertEquals(ramUuid, onePhone.dataStorage?.uuid) + } + + + @Test + fun onePhoneDeepDrownedRepairTest() { + //Given + val DI = PhoneComponentStoneComponent() + val onePhone: OnePhone = OnePhone() + DI.inject(onePhone) + val ramUuid: String = onePhone.dataStorage!!.uuid + + //When + onePhone.dropToWatter() + Thread.sleep(120) + Memory.gc() + DI.inject(onePhone) + + //Then: Can not be repair without new details + assertNotEquals(ramUuid, onePhone.dataStorage!!.uuid) + } +} diff --git a/weakref_multiplatform/build.gradle.kts b/weakref_multiplatform/build.gradle.kts index 48d5574a..648ada89 100644 --- a/weakref_multiplatform/build.gradle.kts +++ b/weakref_multiplatform/build.gradle.kts @@ -16,7 +16,10 @@ kotlin { linuxX64() mingwX64() - wasmJs() + wasmJs { + browser() + nodejs() + } sourceSets { commonMain.dependencies { diff --git a/weakref_multiplatform/src/wasmJsMain/kotlin/com/github/klee0kai/stone/weakref/SoftRef.js.kt b/weakref_multiplatform/src/wasmJsMain/kotlin/com/github/klee0kai/stone/weakref/SoftRef.js.kt index 5a41b388..ed51832b 100644 --- a/weakref_multiplatform/src/wasmJsMain/kotlin/com/github/klee0kai/stone/weakref/SoftRef.js.kt +++ b/weakref_multiplatform/src/wasmJsMain/kotlin/com/github/klee0kai/stone/weakref/SoftRef.js.kt @@ -4,7 +4,7 @@ import js.WeakRef as JsWeakRef actual class SoftRef actual constructor(value: T) : Ref, AutoCloseable { - var weakRef: JsWeakRef? = JsWeakRef(value) + var weakRef = value?.let { JsWeakRef(value) } actual override fun get(): T? = weakRef?.deref() diff --git a/weakref_multiplatform/src/wasmJsMain/kotlin/com/github/klee0kai/stone/weakref/WeakRef.kt b/weakref_multiplatform/src/wasmJsMain/kotlin/com/github/klee0kai/stone/weakref/WeakRef.kt index 7be54454..1a633239 100644 --- a/weakref_multiplatform/src/wasmJsMain/kotlin/com/github/klee0kai/stone/weakref/WeakRef.kt +++ b/weakref_multiplatform/src/wasmJsMain/kotlin/com/github/klee0kai/stone/weakref/WeakRef.kt @@ -4,7 +4,7 @@ import js.WeakRef as JsWeakRef actual class WeakRef actual constructor(value: T) : Ref, AutoCloseable { - var weakRef: JsWeakRef? = JsWeakRef(value) + var weakRef = value?.let { JsWeakRef(value) } actual override fun get(): T? = weakRef?.deref() diff --git a/weakref_multiplatform/src/wasmJsMain/kotlin/js/WeakRef.kt b/weakref_multiplatform/src/wasmJsMain/kotlin/js/WeakRef.kt index c1540229..9f493110 100644 --- a/weakref_multiplatform/src/wasmJsMain/kotlin/js/WeakRef.kt +++ b/weakref_multiplatform/src/wasmJsMain/kotlin/js/WeakRef.kt @@ -1,5 +1,5 @@ package js -external class WeakRef(target: T) { +external class WeakRef(target: T) { fun deref(): T? } \ No newline at end of file From 9c0d8cf9845106a5534ed2ec08229de14a7bc067 Mon Sep 17 00:00:00 2001 From: klee0kai Date: Sat, 21 Feb 2026 23:15:56 +0100 Subject: [PATCH 115/122] test all build variants --- .github/workflows/deploy_dev.yml | 2 +- .github/workflows/deploy_pull_request.yml | 2 +- .../MoonSkyProtectInjectedTests.kt | 34 ----------- .../stone/test/cache/EarthSwitchCacheTests.kt | 58 ------------------- .../test/inject/HorseProtectInjectTests.kt | 34 ----------- .../test/lifecycle/GoodPhoneRepairTests.kt | 52 ----------------- .../test/lifecycle/OnePhoneRepairTests.kt | 51 ---------------- .../singlemethod_gc/PlanetRollingTests.kt | 0 .../test/cache/EarthSwitchCacheGcTests.kt | 46 +++++++++++++++ .../stone/test/gc/EarthLastDayTests.kt | 0 .../stone/test/gc/GodLastWorkDayTests.kt | 0 .../test/inject/HorseProtectInjectGcTests.kt | 22 +++++++ .../SchoolProtectInjectWrappersTests.kt | 2 +- .../test/lifecycle/GoodPhoneRepairGcTests.kt | 36 ++++++++++++ .../test/lifecycle/OnePhoneRepairGcTests.kt | 36 ++++++++++++ .../simple/GodWorkspaceComponent.mingwX64.kt | 3 + .../klee0kai/stone/weakref/WeakRefTests.kt | 8 ++- .../klee0kai/stone/weakref/WeakRefTest.kt | 26 --------- .../klee0kai/stone/weakref/SoftRef.js.kt | 4 +- .../github/klee0kai/stone/weakref/WeakRef.kt | 4 +- .../src/wasmJsMain/kotlin/js/WeakRef.kt | 2 +- 21 files changed, 157 insertions(+), 265 deletions(-) delete mode 100644 tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/bindinstance/singlemethod_inject/MoonSkyProtectInjectedTests.kt delete mode 100644 tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/cache/EarthSwitchCacheTests.kt delete mode 100644 tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/inject/HorseProtectInjectTests.kt delete mode 100644 tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/lifecycle/GoodPhoneRepairTests.kt delete mode 100644 tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/lifecycle/OnePhoneRepairTests.kt rename tests/src/{commonTest => jvmTest}/kotlin/com/github/klee0kai/stone/test/bindinstance/singlemethod_gc/PlanetRollingTests.kt (100%) rename tests/src/{commonTest => jvmTest}/kotlin/com/github/klee0kai/stone/test/gc/EarthLastDayTests.kt (100%) rename tests/src/{commonTest => jvmTest}/kotlin/com/github/klee0kai/stone/test/gc/GodLastWorkDayTests.kt (100%) rename tests/src/{commonTest => jvmTest}/kotlin/com/github/klee0kai/stone/test/inject/SchoolProtectInjectWrappersTests.kt (99%) create mode 100644 tests/src/mingwX64Main/kotlin/com/github/klee0kai/test/di/bindinstance/simple/GodWorkspaceComponent.mingwX64.kt delete mode 100644 weakref_multiplatform/src/jsTest/kotlin/com/github/klee0kai/stone/weakref/WeakRefTest.kt diff --git a/.github/workflows/deploy_dev.yml b/.github/workflows/deploy_dev.yml index e48d159e..02bdb867 100644 --- a/.github/workflows/deploy_dev.yml +++ b/.github/workflows/deploy_dev.yml @@ -32,7 +32,7 @@ jobs: - name: Grant execute permission for gradlew run: chmod +x gradlew - name: Test with Gradle - run: ./gradlew test + run: ./gradlew check - name: Upload test artifacts if: always() uses: actions/upload-artifact@v4 diff --git a/.github/workflows/deploy_pull_request.yml b/.github/workflows/deploy_pull_request.yml index c7dd90ab..86ad7d5b 100644 --- a/.github/workflows/deploy_pull_request.yml +++ b/.github/workflows/deploy_pull_request.yml @@ -28,7 +28,7 @@ jobs: - name: Grant execute permission for gradlew run: chmod +x gradlew - name: Test with Gradle - run: ./gradlew test + run: ./gradlew check - name: Upload test artifacts if: always() uses: actions/upload-artifact@v4 diff --git a/tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/bindinstance/singlemethod_inject/MoonSkyProtectInjectedTests.kt b/tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/bindinstance/singlemethod_inject/MoonSkyProtectInjectedTests.kt deleted file mode 100644 index 13371093..00000000 --- a/tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/bindinstance/singlemethod_inject/MoonSkyProtectInjectedTests.kt +++ /dev/null @@ -1,34 +0,0 @@ -package com.github.klee0kai.stone.test.bindinstance.singlemethod_inject - -import com.github.klee0kai.stone.weakref.WeakRef -import com.github.klee0kai.test.di.bindinstance.singlemethod_inject.StarSkyComponentStoneComponent -import com.github.klee0kai.test.mowgli.MoonSky -import com.github.klee0kai.test.mowgli.galaxy.Mercury -import com.github.klee0kai.test.mowgli.galaxy.Sun -import kotlin.test.Test -import kotlin.test.assertNull - -class MoonSkyProtectInjectedTests { - - @Test - fun withoutProtectInjectedTest() { - //Given - val component = StarSkyComponentStoneComponent() - val mercury = WeakRef(Mercury()) - val star = WeakRef(Sun()) - component.starModule().star(star.get()) - component.mercury(mercury.get()) - - //When - var moonSky: MoonSky? = MoonSky() - component.inject(moonSky) - moonSky = null - component.gcAll() - - - //Then - assertNull(mercury.get()) - assertNull(star.get()) - } - -} diff --git a/tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/cache/EarthSwitchCacheTests.kt b/tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/cache/EarthSwitchCacheTests.kt deleted file mode 100644 index 8e64c0d1..00000000 --- a/tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/cache/EarthSwitchCacheTests.kt +++ /dev/null @@ -1,58 +0,0 @@ -package com.github.klee0kai.stone.test.cache - -import com.github.klee0kai.stone.weakref.Memory -import com.github.klee0kai.stone.weakref.WeakRef -import com.github.klee0kai.test.di.swcache.SwitchCacheComponentStoneComponent -import kotlin.test.Test -import kotlin.test.assertNotNull -import kotlin.test.assertNull - -class EarthSwitchCacheTests { - - @Test - fun allToWeakTest() { - //Given - val DI = SwitchCacheComponentStoneComponent() - val mountain = WeakRef(DI.earth().mountainStrong()) - - //When - DI.allWeak() - Memory.gc() - - //Then - assertNull(mountain.get()) - } - - @Test - fun strongToWeakTest() { - //Given - val DI = SwitchCacheComponentStoneComponent() - val mountainStrong = WeakRef(DI.earth().mountainStrong()) - val mountainSoft = WeakRef(DI.earth().mountainSoft()) - - //When - DI.strongToWeak() - Memory.gc() - - //Then - assertNull(mountainStrong.get()) - assertNotNull(mountainSoft.get()) - } - - @Test - fun mountainToWeakTest() { - //Given - val DI = SwitchCacheComponentStoneComponent() - val mountain = WeakRef(DI.earth().mountainStrong()) - val river = WeakRef(DI.earth().riverSoft()) - - //When - DI.mountainToWeak() - Memory.gc() - - //Then - assertNull(mountain.get()) - assertNotNull(river.get()) - } - -} diff --git a/tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/inject/HorseProtectInjectTests.kt b/tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/inject/HorseProtectInjectTests.kt deleted file mode 100644 index 59d4d0f7..00000000 --- a/tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/inject/HorseProtectInjectTests.kt +++ /dev/null @@ -1,34 +0,0 @@ -package com.github.klee0kai.stone.test.inject - -import com.github.klee0kai.stone.weakref.Memory -import com.github.klee0kai.stone.weakref.WeakRef -import com.github.klee0kai.test.di.base_forest.ForestComponentStoneComponent -import com.github.klee0kai.test.mowgli.animal.Horse -import kotlin.test.Test -import kotlin.test.assertNotNull -import kotlin.test.assertNull - -class HorseProtectInjectTests { - - @Test - fun withoutProtectInjectTest() { - // Given - val DI = ForestComponentStoneComponent() - var horse: Horse? = Horse() - - - //When - DI.inject( - horse, - stoneLifeCycleOwner = { } - ) - - val historyWeakReference = WeakRef(horse?.history) - horse = null - Memory.gc() - - //Then: without protect all not uses should be garbage collected - assertNull(historyWeakReference.get()) - } - -} diff --git a/tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/lifecycle/GoodPhoneRepairTests.kt b/tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/lifecycle/GoodPhoneRepairTests.kt deleted file mode 100644 index 0fa3ee18..00000000 --- a/tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/lifecycle/GoodPhoneRepairTests.kt +++ /dev/null @@ -1,52 +0,0 @@ -package com.github.klee0kai.stone.test.lifecycle - -import com.github.klee0kai.stone.weakref.Memory -import com.github.klee0kai.stone.weakref.WeakRef -import com.github.klee0kai.test.di.base_phone.PhoneComponentStoneComponent -import com.github.klee0kai.test.di.base_phone.identifiers.DataStorageSize -import com.github.klee0kai.test.di.base_phone.identifiers.RamSize -import com.github.klee0kai.test.tech.phone.GoodPhone -import kotlin.test.* - -/** - * Test lifecycle owner over LifecycleUtils - */ -class GoodPhoneRepairTests { - - @Test - fun goodPhoneInjectTest() { - //Given - val DI = PhoneComponentStoneComponent() - - //When buy - val goodPhone = GoodPhone() - DI.inject(goodPhone, goodPhone.lifeCycleOwner, DataStorageSize("64G"), RamSize("4G")) - - //Then - assertNotNull(goodPhone.battery) - assertNotNull(goodPhone.dataStorage) - assertNotNull(goodPhone.ram) - } - - @Test - fun goodPhoneBrokeTest() { - //Given - val DI = PhoneComponentStoneComponent() - val goodPhone = GoodPhone() - DI.inject(goodPhone, goodPhone.lifeCycleOwner, DataStorageSize("64G"), RamSize("4G")) - val batteryRef = WeakRef(goodPhone.battery) - val dataStorageRef = WeakRef(goodPhone.dataStorage) - val ramRef = WeakRef(goodPhone.ram) - - //When broke and repair - goodPhone.broke() - Memory.gc() - DI.inject(goodPhone, DataStorageSize("64G"), RamSize("4G")) - - //Then: Need new details for repair phone. Old components collected by GC - assertNull(batteryRef.get()) - assertNull(dataStorageRef.get()) - assertNull(ramRef.get()) - } - -} diff --git a/tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/lifecycle/OnePhoneRepairTests.kt b/tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/lifecycle/OnePhoneRepairTests.kt deleted file mode 100644 index 0b808bb7..00000000 --- a/tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/lifecycle/OnePhoneRepairTests.kt +++ /dev/null @@ -1,51 +0,0 @@ -package com.github.klee0kai.stone.test.lifecycle - -import com.github.klee0kai.stone.weakref.Memory -import com.github.klee0kai.stone.weakref.WeakRef -import com.github.klee0kai.test.di.base_phone.PhoneComponentStoneComponent -import com.github.klee0kai.test.tech.phone.OnePhone -import kotlin.test.* - -/** - * Test lifecycle owner implemented in providing model - */ -class OnePhoneRepairTests { - - @Test - fun onePhoneInjectTest() { - //Given - val DI = PhoneComponentStoneComponent() - - //When - val onePhone = OnePhone() - DI.inject(onePhone) - - //Then - assertNotNull(onePhone.battery) - assertNotNull(onePhone.dataStorage) - assertNotNull(onePhone.ram) - } - - @Test - fun onePhoneBrokeTest() { - //Given - val DI = PhoneComponentStoneComponent() - val onePhone: OnePhone = OnePhone() - DI.inject(onePhone) - val batteryRef = WeakRef(onePhone.battery) - val dataStorageRef = WeakRef(onePhone.dataStorage) - val ramRef = WeakRef(onePhone.ram) - - //When - onePhone.broke() - Memory.gc() - DI.inject(onePhone) - - //Then: Need new details for repair phone. Old components collected by GC - assertNull(batteryRef.get()) - assertNull(dataStorageRef.get()) - assertNull(ramRef.get()) - } - - -} diff --git a/tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/bindinstance/singlemethod_gc/PlanetRollingTests.kt b/tests/src/jvmTest/kotlin/com/github/klee0kai/stone/test/bindinstance/singlemethod_gc/PlanetRollingTests.kt similarity index 100% rename from tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/bindinstance/singlemethod_gc/PlanetRollingTests.kt rename to tests/src/jvmTest/kotlin/com/github/klee0kai/stone/test/bindinstance/singlemethod_gc/PlanetRollingTests.kt diff --git a/tests/src/jvmTest/kotlin/com/github/klee0kai/stone/test/cache/EarthSwitchCacheGcTests.kt b/tests/src/jvmTest/kotlin/com/github/klee0kai/stone/test/cache/EarthSwitchCacheGcTests.kt index d9d19838..b9108278 100644 --- a/tests/src/jvmTest/kotlin/com/github/klee0kai/stone/test/cache/EarthSwitchCacheGcTests.kt +++ b/tests/src/jvmTest/kotlin/com/github/klee0kai/stone/test/cache/EarthSwitchCacheGcTests.kt @@ -10,6 +10,52 @@ import kotlin.test.assertNull class EarthSwitchCacheGcTests { + @Test + fun allToWeakTest() { + //Given + val DI = SwitchCacheComponentStoneComponent() + val mountain = WeakRef(DI.earth().mountainStrong()) + + //When + DI.allWeak() + Memory.gc() + + //Then + assertNull(mountain.get()) + } + + @Test + fun strongToWeakTest() { + //Given + val DI = SwitchCacheComponentStoneComponent() + val mountainStrong = WeakRef(DI.earth().mountainStrong()) + val mountainSoft = WeakRef(DI.earth().mountainSoft()) + + //When + DI.strongToWeak() + Memory.gc() + + //Then + assertNull(mountainStrong.get()) + assertNotNull(mountainSoft.get()) + } + + @Test + fun mountainToWeakTest() { + //Given + val DI = SwitchCacheComponentStoneComponent() + val mountain = WeakRef(DI.earth().mountainStrong()) + val river = WeakRef(DI.earth().riverSoft()) + + //When + DI.mountainToWeak() + Memory.gc() + + //Then + assertNull(mountain.get()) + assertNotNull(river.get()) + } + @Test fun weakToStrongFewMillisTest() { //Given diff --git a/tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/gc/EarthLastDayTests.kt b/tests/src/jvmTest/kotlin/com/github/klee0kai/stone/test/gc/EarthLastDayTests.kt similarity index 100% rename from tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/gc/EarthLastDayTests.kt rename to tests/src/jvmTest/kotlin/com/github/klee0kai/stone/test/gc/EarthLastDayTests.kt diff --git a/tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/gc/GodLastWorkDayTests.kt b/tests/src/jvmTest/kotlin/com/github/klee0kai/stone/test/gc/GodLastWorkDayTests.kt similarity index 100% rename from tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/gc/GodLastWorkDayTests.kt rename to tests/src/jvmTest/kotlin/com/github/klee0kai/stone/test/gc/GodLastWorkDayTests.kt diff --git a/tests/src/jvmTest/kotlin/com/github/klee0kai/stone/test/inject/HorseProtectInjectGcTests.kt b/tests/src/jvmTest/kotlin/com/github/klee0kai/stone/test/inject/HorseProtectInjectGcTests.kt index 31be5e5a..93141bdd 100644 --- a/tests/src/jvmTest/kotlin/com/github/klee0kai/stone/test/inject/HorseProtectInjectGcTests.kt +++ b/tests/src/jvmTest/kotlin/com/github/klee0kai/stone/test/inject/HorseProtectInjectGcTests.kt @@ -1,5 +1,6 @@ package com.github.klee0kai.stone.test.inject +import com.github.klee0kai.stone.weakref.Memory import com.github.klee0kai.stone.weakref.WeakRef import com.github.klee0kai.test.di.base_forest.ForestComponentStoneComponent import com.github.klee0kai.test.mowgli.animal.Horse @@ -9,6 +10,27 @@ import kotlin.test.assertNull class HorseProtectInjectGcTests { + @Test + fun withoutProtectInjectTest() { + // Given + val DI = ForestComponentStoneComponent() + var horse: Horse? = Horse() + + + //When + DI.inject( + horse, + stoneLifeCycleOwner = { } + ) + + val historyWeakReference = WeakRef(horse?.history) + horse = null + Memory.gc() + + //Then: without protect all not uses should be garbage collected + assertNull(historyWeakReference.get()) + } + @Test fun withProtectInjectTest() { diff --git a/tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/inject/SchoolProtectInjectWrappersTests.kt b/tests/src/jvmTest/kotlin/com/github/klee0kai/stone/test/inject/SchoolProtectInjectWrappersTests.kt similarity index 99% rename from tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/inject/SchoolProtectInjectWrappersTests.kt rename to tests/src/jvmTest/kotlin/com/github/klee0kai/stone/test/inject/SchoolProtectInjectWrappersTests.kt index b10a4628..da99844d 100644 --- a/tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/inject/SchoolProtectInjectWrappersTests.kt +++ b/tests/src/jvmTest/kotlin/com/github/klee0kai/stone/test/inject/SchoolProtectInjectWrappersTests.kt @@ -46,4 +46,4 @@ class SchoolProtectInjectWrappersTests { assertNull(knowledge3.get()) } -} +} \ No newline at end of file diff --git a/tests/src/jvmTest/kotlin/com/github/klee0kai/stone/test/lifecycle/GoodPhoneRepairGcTests.kt b/tests/src/jvmTest/kotlin/com/github/klee0kai/stone/test/lifecycle/GoodPhoneRepairGcTests.kt index 9a4c23f8..28e9bdc6 100644 --- a/tests/src/jvmTest/kotlin/com/github/klee0kai/stone/test/lifecycle/GoodPhoneRepairGcTests.kt +++ b/tests/src/jvmTest/kotlin/com/github/klee0kai/stone/test/lifecycle/GoodPhoneRepairGcTests.kt @@ -14,6 +14,42 @@ import kotlin.test.* class GoodPhoneRepairGcTests { + @Test + fun goodPhoneInjectTest() { + //Given + val DI = PhoneComponentStoneComponent() + + //When buy + val goodPhone = GoodPhone() + DI.inject(goodPhone, goodPhone.lifeCycleOwner, DataStorageSize("64G"), RamSize("4G")) + + //Then + assertNotNull(goodPhone.battery) + assertNotNull(goodPhone.dataStorage) + assertNotNull(goodPhone.ram) + } + + @Test + fun goodPhoneBrokeTest() { + //Given + val DI = PhoneComponentStoneComponent() + val goodPhone = GoodPhone() + DI.inject(goodPhone, goodPhone.lifeCycleOwner, DataStorageSize("64G"), RamSize("4G")) + val batteryRef = WeakRef(goodPhone.battery) + val dataStorageRef = WeakRef(goodPhone.dataStorage) + val ramRef = WeakRef(goodPhone.ram) + + //When broke and repair + goodPhone.broke() + Memory.gc() + DI.inject(goodPhone, DataStorageSize("64G"), RamSize("4G")) + + //Then: Need new details for repair phone. Old components collected by GC + assertNull(batteryRef.get()) + assertNull(dataStorageRef.get()) + assertNull(ramRef.get()) + } + @Test fun goodPhoneDropWatterGcTest() { diff --git a/tests/src/jvmTest/kotlin/com/github/klee0kai/stone/test/lifecycle/OnePhoneRepairGcTests.kt b/tests/src/jvmTest/kotlin/com/github/klee0kai/stone/test/lifecycle/OnePhoneRepairGcTests.kt index 52abd63b..01e62796 100644 --- a/tests/src/jvmTest/kotlin/com/github/klee0kai/stone/test/lifecycle/OnePhoneRepairGcTests.kt +++ b/tests/src/jvmTest/kotlin/com/github/klee0kai/stone/test/lifecycle/OnePhoneRepairGcTests.kt @@ -12,6 +12,42 @@ import kotlin.test.* class OnePhoneRepairGcTests { + @Test + fun onePhoneInjectTest() { + //Given + val DI = PhoneComponentStoneComponent() + + //When + val onePhone = OnePhone() + DI.inject(onePhone) + + //Then + assertNotNull(onePhone.battery) + assertNotNull(onePhone.dataStorage) + assertNotNull(onePhone.ram) + } + + @Test + fun onePhoneBrokeTest() { + //Given + val DI = PhoneComponentStoneComponent() + val onePhone: OnePhone = OnePhone() + DI.inject(onePhone) + val batteryRef = WeakRef(onePhone.battery) + val dataStorageRef = WeakRef(onePhone.dataStorage) + val ramRef = WeakRef(onePhone.ram) + + //When + onePhone.broke() + Memory.gc() + DI.inject(onePhone) + + //Then: Need new details for repair phone. Old components collected by GC + assertNull(batteryRef.get()) + assertNull(dataStorageRef.get()) + assertNull(ramRef.get()) + } + @Test fun onePhoneDropWatterTest() { //Given diff --git a/tests/src/mingwX64Main/kotlin/com/github/klee0kai/test/di/bindinstance/simple/GodWorkspaceComponent.mingwX64.kt b/tests/src/mingwX64Main/kotlin/com/github/klee0kai/test/di/bindinstance/simple/GodWorkspaceComponent.mingwX64.kt new file mode 100644 index 00000000..88b2bd9c --- /dev/null +++ b/tests/src/mingwX64Main/kotlin/com/github/klee0kai/test/di/bindinstance/simple/GodWorkspaceComponent.mingwX64.kt @@ -0,0 +1,3 @@ +package com.github.klee0kai.test.di.bindinstance.simple + +actual fun genGodWorkspaceComponent(): GodWorkspaceComponent = GodWorkspaceComponentStoneComponent() diff --git a/weakref_multiplatform/src/commonTest/kotlin/com/github/klee0kai/stone/weakref/WeakRefTests.kt b/weakref_multiplatform/src/commonTest/kotlin/com/github/klee0kai/stone/weakref/WeakRefTests.kt index 77cab36e..c1909699 100644 --- a/weakref_multiplatform/src/commonTest/kotlin/com/github/klee0kai/stone/weakref/WeakRefTests.kt +++ b/weakref_multiplatform/src/commonTest/kotlin/com/github/klee0kai/stone/weakref/WeakRefTests.kt @@ -6,11 +6,15 @@ import kotlin.test.assertNull class WeakRefTests { + class TestClass( + val string: String, + ) + @Test fun clearRefTest() { - val ref = WeakRef("some text") + val ref = WeakRef(TestClass("some text")) - assertEquals("some text", ref.get()) + assertEquals("some text", ref.get()?.string) ref.clear() diff --git a/weakref_multiplatform/src/jsTest/kotlin/com/github/klee0kai/stone/weakref/WeakRefTest.kt b/weakref_multiplatform/src/jsTest/kotlin/com/github/klee0kai/stone/weakref/WeakRefTest.kt deleted file mode 100644 index aae36d19..00000000 --- a/weakref_multiplatform/src/jsTest/kotlin/com/github/klee0kai/stone/weakref/WeakRefTest.kt +++ /dev/null @@ -1,26 +0,0 @@ -package com.github.klee0kai.stone.weakref - -import kotlin.test.Test - -class WeakRefTest { - - data class SimpleDataClass( - val value: String, - ) - - @Test - fun simpleTest() { - console.log("SimpleDataClass") - val obj = SimpleDataClass("hee") - val link = WeakRef(obj) -// js("console.log")(obj) -// val jsObj0: dynamic = js("{ name: 'Alex', age: 17 }") -// val jsObj: dynamic = js("new WeakRef ({ name: 'Alex', age: 17 })") - - println("name " + link.get()) - -// val a = js("")(obj) - - } - -} \ No newline at end of file diff --git a/weakref_multiplatform/src/wasmJsMain/kotlin/com/github/klee0kai/stone/weakref/SoftRef.js.kt b/weakref_multiplatform/src/wasmJsMain/kotlin/com/github/klee0kai/stone/weakref/SoftRef.js.kt index ed51832b..ee424923 100644 --- a/weakref_multiplatform/src/wasmJsMain/kotlin/com/github/klee0kai/stone/weakref/SoftRef.js.kt +++ b/weakref_multiplatform/src/wasmJsMain/kotlin/com/github/klee0kai/stone/weakref/SoftRef.js.kt @@ -4,9 +4,9 @@ import js.WeakRef as JsWeakRef actual class SoftRef actual constructor(value: T) : Ref, AutoCloseable { - var weakRef = value?.let { JsWeakRef(value) } + var weakRef = (value as? JsAny)?.let { JsWeakRef(value) } - actual override fun get(): T? = weakRef?.deref() + actual override fun get(): T? = weakRef?.deref() as T? actual fun clear() { weakRef = null diff --git a/weakref_multiplatform/src/wasmJsMain/kotlin/com/github/klee0kai/stone/weakref/WeakRef.kt b/weakref_multiplatform/src/wasmJsMain/kotlin/com/github/klee0kai/stone/weakref/WeakRef.kt index 1a633239..12dfb6f6 100644 --- a/weakref_multiplatform/src/wasmJsMain/kotlin/com/github/klee0kai/stone/weakref/WeakRef.kt +++ b/weakref_multiplatform/src/wasmJsMain/kotlin/com/github/klee0kai/stone/weakref/WeakRef.kt @@ -4,9 +4,9 @@ import js.WeakRef as JsWeakRef actual class WeakRef actual constructor(value: T) : Ref, AutoCloseable { - var weakRef = value?.let { JsWeakRef(value) } + var weakRef = (value as JsAny)?.let { JsWeakRef(value) } - actual override fun get(): T? = weakRef?.deref() + actual override fun get(): T? = weakRef?.deref() as T? actual fun clear() { weakRef = null diff --git a/weakref_multiplatform/src/wasmJsMain/kotlin/js/WeakRef.kt b/weakref_multiplatform/src/wasmJsMain/kotlin/js/WeakRef.kt index 9f493110..5b991f67 100644 --- a/weakref_multiplatform/src/wasmJsMain/kotlin/js/WeakRef.kt +++ b/weakref_multiplatform/src/wasmJsMain/kotlin/js/WeakRef.kt @@ -1,5 +1,5 @@ package js -external class WeakRef(target: T) { +external class WeakRef(target: T) { fun deref(): T? } \ No newline at end of file From 795a59fb849137b75c4f6905df47d5c724ab0f92 Mon Sep 17 00:00:00 2001 From: klee0kai Date: Thu, 26 Feb 2026 23:29:02 +0100 Subject: [PATCH 116/122] correct store annotations pkg --- .../com/github/klee0kai/stone/{weakref => }/Inject.kt | 2 +- .../kotlin/com/github/klee0kai/stone/{weakref => }/Named.kt | 2 +- .../com/github/klee0kai/stone/{weakref => }/Provider.kt | 2 +- .../com/github/klee0kai/stone/{weakref => }/Qualifier.kt | 2 +- .../kotlin/com/github/klee0kai/stone/{weakref => }/Scope.kt | 2 +- .../thekey/stone/ksp/helpers/ComponentDeclarationExt.kt | 6 +++--- .../klee0kai/thekey/stone/ksp/helpers/wrap/WrapHelper.kt | 2 +- .../stone/ksp/target/component/GenComponentProcessor.kt | 2 +- .../klee0kai/stone/annotations/component/GcSoftScope.kt | 2 +- .../klee0kai/stone/annotations/component/GcStrongScope.kt | 2 +- .../klee0kai/stone/annotations/component/GcWeakScope.kt | 2 +- .../klee0kai/test/core/di/wrapper/StoneCustomWrapper.kt | 2 +- .../com/github/klee0kai/test/di/base_phone/TechModule.kt | 2 +- .../klee0kai/test/di/bindinstance/singlemethod/SunModule.kt | 2 +- .../klee0kai/test/di/gcforest/scopes/GcMountainScope.kt | 2 +- .../github/klee0kai/test/di/gcforest/scopes/GcRiverScope.kt | 2 +- .../github/klee0kai/test/di/gcforest/scopes/GcSunScope.kt | 2 +- .../klee0kai/test/di/techfactory/ITechProviderComponent.kt | 2 ++ .../klee0kai/test/di/techfactory/TechFactoryModule.kt | 2 +- .../kotlin/com/github/klee0kai/test/house/InHouse.kt | 2 +- .../kotlin/com/github/klee0kai/test/mowgli/MoonSky.kt | 2 +- .../kotlin/com/github/klee0kai/test/mowgli/School.kt | 4 ++-- .../kotlin/com/github/klee0kai/test/mowgli/animal/Horse.kt | 2 +- .../kotlin/com/github/klee0kai/test/mowgli/animal/Mowgli.kt | 2 ++ .../kotlin/com/github/klee0kai/test/mowgli/animal/Snake.kt | 2 +- .../kotlin/com/github/klee0kai/test/tech/phone/GoodPhone.kt | 2 +- .../kotlin/com/github/klee0kai/test/tech/phone/OnePhone.kt | 4 ++-- .../github/klee0kai/test/boxed/di/inject/CarBoxedWrapper.kt | 2 +- .../test/car/di/wrapped/custom/wrappers/CarRefWrapper.kt | 2 +- .../com/github/klee0kai/wiki/wrapping/CarBoxedWrapper.kt | 2 +- 30 files changed, 36 insertions(+), 32 deletions(-) rename inject_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/{weakref => }/Inject.kt (92%) rename inject_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/{weakref => }/Named.kt (87%) rename inject_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/{weakref => }/Provider.kt (82%) rename inject_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/{weakref => }/Qualifier.kt (95%) rename inject_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/{weakref => }/Scope.kt (94%) diff --git a/inject_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/weakref/Inject.kt b/inject_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/Inject.kt similarity index 92% rename from inject_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/weakref/Inject.kt rename to inject_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/Inject.kt index 950bd144..459a95ab 100644 --- a/inject_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/weakref/Inject.kt +++ b/inject_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/Inject.kt @@ -1,4 +1,4 @@ -package com.github.klee0kai.stone.weakref +package com.github.klee0kai.stone /** * Identifies injectable constructors, methods, and fields. May apply to static diff --git a/inject_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/weakref/Named.kt b/inject_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/Named.kt similarity index 87% rename from inject_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/weakref/Named.kt rename to inject_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/Named.kt index 74f55518..730404c4 100644 --- a/inject_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/weakref/Named.kt +++ b/inject_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/Named.kt @@ -1,4 +1,4 @@ -package com.github.klee0kai.stone.weakref +package com.github.klee0kai.stone /** diff --git a/inject_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/weakref/Provider.kt b/inject_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/Provider.kt similarity index 82% rename from inject_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/weakref/Provider.kt rename to inject_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/Provider.kt index 694f04c1..71eb948d 100644 --- a/inject_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/weakref/Provider.kt +++ b/inject_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/Provider.kt @@ -1,4 +1,4 @@ -package com.github.klee0kai.stone.weakref +package com.github.klee0kai.stone /** * Provides instances of [T]. Typically implemented by an injector. For diff --git a/inject_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/weakref/Qualifier.kt b/inject_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/Qualifier.kt similarity index 95% rename from inject_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/weakref/Qualifier.kt rename to inject_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/Qualifier.kt index 4ff0f75d..2667f044 100644 --- a/inject_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/weakref/Qualifier.kt +++ b/inject_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/Qualifier.kt @@ -1,4 +1,4 @@ -package com.github.klee0kai.stone.weakref +package com.github.klee0kai.stone /** * Identifies qualifier annotations. Anyone can define a new qualifier. A diff --git a/inject_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/weakref/Scope.kt b/inject_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/Scope.kt similarity index 94% rename from inject_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/weakref/Scope.kt rename to inject_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/Scope.kt index 6b3a3199..097c44c6 100644 --- a/inject_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/weakref/Scope.kt +++ b/inject_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/Scope.kt @@ -1,4 +1,4 @@ -package com.github.klee0kai.stone.weakref +package com.github.klee0kai.stone /** * Identifies scope annotations. A scope annotation applies to a class diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/ComponentDeclarationExt.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/ComponentDeclarationExt.kt index 604861e2..8897ceb7 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/ComponentDeclarationExt.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/ComponentDeclarationExt.kt @@ -5,8 +5,8 @@ package com.github.klee0kai.thekey.stone.ksp.helpers import com.github.klee0kai.stone.annotations.component.* import com.github.klee0kai.stone.annotations.qualifier.IgnoreQualifier import com.github.klee0kai.stone.lifecycle.StoneLifeCycleOwner -import com.github.klee0kai.stone.weakref.Named -import com.github.klee0kai.stone.weakref.Qualifier +import com.github.klee0kai.stone.Named +import com.github.klee0kai.stone.Qualifier import com.github.klee0kai.thekey.stone.ksp.helpers.annotations.findComponentAnnotation import com.github.klee0kai.thekey.stone.ksp.ksp.isAnyType import com.github.klee0kai.thekey.stone.ksp.ksp.isChildOf @@ -17,7 +17,7 @@ import com.google.devtools.ksp.processing.Resolver import com.google.devtools.ksp.symbol.* import com.squareup.kotlinpoet.ClassName import com.squareup.kotlinpoet.asClassName -import com.github.klee0kai.stone.weakref.Scope as StoneScope +import com.github.klee0kai.stone.Scope as StoneScope fun Resolver.findComponentForModuleOrDep( moduleCl: ClassName, diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/wrap/WrapHelper.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/wrap/WrapHelper.kt index d1b9e16d..164191a5 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/wrap/WrapHelper.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/wrap/WrapHelper.kt @@ -1,6 +1,6 @@ package com.github.klee0kai.thekey.stone.ksp.helpers.wrap -import com.github.klee0kai.stone.weakref.Provider +import com.github.klee0kai.stone.Provider import com.github.klee0kai.stone.weakref.Ref import com.github.klee0kai.stone.weakref.SoftRef import com.github.klee0kai.stone.weakref.WeakRef diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/component/GenComponentProcessor.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/component/GenComponentProcessor.kt index fa0ae3be..a894571a 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/component/GenComponentProcessor.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/component/GenComponentProcessor.kt @@ -11,7 +11,7 @@ import com.github.klee0kai.stone.annotations.component.ProtectInjected import com.github.klee0kai.stone.annotations.component.SwitchCache import com.github.klee0kai.stone.annotations.dependencies.Dependencies import com.github.klee0kai.stone.annotations.module.Module -import com.github.klee0kai.stone.weakref.Inject +import com.github.klee0kai.stone.Inject import com.github.klee0kai.stone.weakref.Memory import com.github.klee0kai.thekey.stone.ksp.exceptions.IncorrectSignatureException import com.github.klee0kai.thekey.stone.ksp.exceptions.ObjectNotProvidedException diff --git a/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/annotations/component/GcSoftScope.kt b/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/annotations/component/GcSoftScope.kt index 6e668afb..a603c567 100644 --- a/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/annotations/component/GcSoftScope.kt +++ b/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/annotations/component/GcSoftScope.kt @@ -1,6 +1,6 @@ package com.github.klee0kai.stone.annotations.component -import com.github.klee0kai.stone.weakref.Scope +import com.github.klee0kai.stone.Scope /** diff --git a/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/annotations/component/GcStrongScope.kt b/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/annotations/component/GcStrongScope.kt index 4350ca91..40d39ad7 100644 --- a/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/annotations/component/GcStrongScope.kt +++ b/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/annotations/component/GcStrongScope.kt @@ -1,6 +1,6 @@ package com.github.klee0kai.stone.annotations.component -import com.github.klee0kai.stone.weakref.Scope +import com.github.klee0kai.stone.Scope /** diff --git a/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/annotations/component/GcWeakScope.kt b/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/annotations/component/GcWeakScope.kt index 8a0dd7cf..2fbbd30d 100644 --- a/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/annotations/component/GcWeakScope.kt +++ b/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/annotations/component/GcWeakScope.kt @@ -1,6 +1,6 @@ package com.github.klee0kai.stone.annotations.component -import com.github.klee0kai.stone.weakref.Scope +import com.github.klee0kai.stone.Scope /** diff --git a/test_feature_core_deps/src/main/java/com/github/klee0kai/test/core/di/wrapper/StoneCustomWrapper.kt b/test_feature_core_deps/src/main/java/com/github/klee0kai/test/core/di/wrapper/StoneCustomWrapper.kt index 9ab278cf..5d121179 100644 --- a/test_feature_core_deps/src/main/java/com/github/klee0kai/test/core/di/wrapper/StoneCustomWrapper.kt +++ b/test_feature_core_deps/src/main/java/com/github/klee0kai/test/core/di/wrapper/StoneCustomWrapper.kt @@ -1,7 +1,7 @@ package com.github.klee0kai.test.core.di.wrapper import com.github.klee0kai.stone.annotations.wrappers.WrappersHelper -import com.github.klee0kai.stone.weakref.Provider +import com.github.klee0kai.stone.Provider @WrappersHelper object StoneCustomWrapper { diff --git a/tests/src/commonMain/kotlin/com/github/klee0kai/test/di/base_phone/TechModule.kt b/tests/src/commonMain/kotlin/com/github/klee0kai/test/di/base_phone/TechModule.kt index 91ba9178..b366d808 100644 --- a/tests/src/commonMain/kotlin/com/github/klee0kai/test/di/base_phone/TechModule.kt +++ b/tests/src/commonMain/kotlin/com/github/klee0kai/test/di/base_phone/TechModule.kt @@ -2,7 +2,7 @@ package com.github.klee0kai.test.di.base_phone import com.github.klee0kai.stone.annotations.module.Module import com.github.klee0kai.stone.annotations.module.Provide -import com.github.klee0kai.stone.weakref.Named +import com.github.klee0kai.stone.Named import com.github.klee0kai.test.di.base_phone.identifiers.DataStorageSize import com.github.klee0kai.test.di.base_phone.identifiers.PhoneOsType import com.github.klee0kai.test.di.base_phone.identifiers.PhoneOsVersion diff --git a/tests/src/commonMain/kotlin/com/github/klee0kai/test/di/bindinstance/singlemethod/SunModule.kt b/tests/src/commonMain/kotlin/com/github/klee0kai/test/di/bindinstance/singlemethod/SunModule.kt index c4dd0dd2..69ab16b5 100644 --- a/tests/src/commonMain/kotlin/com/github/klee0kai/test/di/bindinstance/singlemethod/SunModule.kt +++ b/tests/src/commonMain/kotlin/com/github/klee0kai/test/di/bindinstance/singlemethod/SunModule.kt @@ -2,7 +2,7 @@ package com.github.klee0kai.test.di.bindinstance.singlemethod import com.github.klee0kai.stone.annotations.module.BindInstance import com.github.klee0kai.stone.annotations.module.Module -import com.github.klee0kai.stone.weakref.Named +import com.github.klee0kai.stone.Named import com.github.klee0kai.test.di.gcforest.scopes.GcSunScope import com.github.klee0kai.test.mowgli.galaxy.IStar import com.github.klee0kai.test.mowgli.galaxy.Sun diff --git a/tests/src/commonMain/kotlin/com/github/klee0kai/test/di/gcforest/scopes/GcMountainScope.kt b/tests/src/commonMain/kotlin/com/github/klee0kai/test/di/gcforest/scopes/GcMountainScope.kt index 23220034..8cbda2b5 100644 --- a/tests/src/commonMain/kotlin/com/github/klee0kai/test/di/gcforest/scopes/GcMountainScope.kt +++ b/tests/src/commonMain/kotlin/com/github/klee0kai/test/di/gcforest/scopes/GcMountainScope.kt @@ -1,6 +1,6 @@ package com.github.klee0kai.test.di.gcforest.scopes -import com.github.klee0kai.stone.weakref.Scope +import com.github.klee0kai.stone.Scope @Scope diff --git a/tests/src/commonMain/kotlin/com/github/klee0kai/test/di/gcforest/scopes/GcRiverScope.kt b/tests/src/commonMain/kotlin/com/github/klee0kai/test/di/gcforest/scopes/GcRiverScope.kt index cb30651a..10d235b0 100644 --- a/tests/src/commonMain/kotlin/com/github/klee0kai/test/di/gcforest/scopes/GcRiverScope.kt +++ b/tests/src/commonMain/kotlin/com/github/klee0kai/test/di/gcforest/scopes/GcRiverScope.kt @@ -1,6 +1,6 @@ package com.github.klee0kai.test.di.gcforest.scopes -import com.github.klee0kai.stone.weakref.Scope +import com.github.klee0kai.stone.Scope @Scope @Retention(AnnotationRetention.RUNTIME) diff --git a/tests/src/commonMain/kotlin/com/github/klee0kai/test/di/gcforest/scopes/GcSunScope.kt b/tests/src/commonMain/kotlin/com/github/klee0kai/test/di/gcforest/scopes/GcSunScope.kt index 1e66a762..479af8f4 100644 --- a/tests/src/commonMain/kotlin/com/github/klee0kai/test/di/gcforest/scopes/GcSunScope.kt +++ b/tests/src/commonMain/kotlin/com/github/klee0kai/test/di/gcforest/scopes/GcSunScope.kt @@ -1,6 +1,6 @@ package com.github.klee0kai.test.di.gcforest.scopes -import com.github.klee0kai.stone.weakref.Scope +import com.github.klee0kai.stone.Scope @Scope @Retention(AnnotationRetention.RUNTIME) diff --git a/tests/src/commonMain/kotlin/com/github/klee0kai/test/di/techfactory/ITechProviderComponent.kt b/tests/src/commonMain/kotlin/com/github/klee0kai/test/di/techfactory/ITechProviderComponent.kt index 1c07f96a..517c607f 100644 --- a/tests/src/commonMain/kotlin/com/github/klee0kai/test/di/techfactory/ITechProviderComponent.kt +++ b/tests/src/commonMain/kotlin/com/github/klee0kai/test/di/techfactory/ITechProviderComponent.kt @@ -1,5 +1,7 @@ package com.github.klee0kai.test.di.techfactory +import com.github.klee0kai.stone.Named +import com.github.klee0kai.stone.Provider import com.github.klee0kai.stone.weakref.* import com.github.klee0kai.stone.wrappers.LazyProvide import com.github.klee0kai.stone.wrappers.PhantomProvide diff --git a/tests/src/commonMain/kotlin/com/github/klee0kai/test/di/techfactory/TechFactoryModule.kt b/tests/src/commonMain/kotlin/com/github/klee0kai/test/di/techfactory/TechFactoryModule.kt index 544d00c0..9dfb92b2 100644 --- a/tests/src/commonMain/kotlin/com/github/klee0kai/test/di/techfactory/TechFactoryModule.kt +++ b/tests/src/commonMain/kotlin/com/github/klee0kai/test/di/techfactory/TechFactoryModule.kt @@ -2,7 +2,7 @@ package com.github.klee0kai.test.di.techfactory import com.github.klee0kai.stone.annotations.module.Module import com.github.klee0kai.stone.annotations.module.Provide -import com.github.klee0kai.stone.weakref.Named +import com.github.klee0kai.stone.Named import com.github.klee0kai.test.di.base_phone.identifiers.DataStorageSize import com.github.klee0kai.test.di.base_phone.identifiers.PhoneOsType import com.github.klee0kai.test.di.base_phone.identifiers.PhoneOsVersion diff --git a/tests/src/commonMain/kotlin/com/github/klee0kai/test/house/InHouse.kt b/tests/src/commonMain/kotlin/com/github/klee0kai/test/house/InHouse.kt index 13c9ea1f..7dbf9441 100644 --- a/tests/src/commonMain/kotlin/com/github/klee0kai/test/house/InHouse.kt +++ b/tests/src/commonMain/kotlin/com/github/klee0kai/test/house/InHouse.kt @@ -1,6 +1,6 @@ package com.github.klee0kai.test.house -import com.github.klee0kai.stone.weakref.Inject +import com.github.klee0kai.stone.Inject import com.github.klee0kai.test.house.kitchen.Kichen import com.github.klee0kai.test.house.kitchen.storagearea.StoreArea import com.github.klee0kai.test.house.rooms.BathRoom diff --git a/tests/src/commonMain/kotlin/com/github/klee0kai/test/mowgli/MoonSky.kt b/tests/src/commonMain/kotlin/com/github/klee0kai/test/mowgli/MoonSky.kt index 19efda6c..fce14271 100644 --- a/tests/src/commonMain/kotlin/com/github/klee0kai/test/mowgli/MoonSky.kt +++ b/tests/src/commonMain/kotlin/com/github/klee0kai/test/mowgli/MoonSky.kt @@ -1,6 +1,6 @@ package com.github.klee0kai.test.mowgli -import com.github.klee0kai.stone.weakref.Inject +import com.github.klee0kai.stone.Inject import com.github.klee0kai.test.mowgli.galaxy.* import kotlin.jvm.JvmField diff --git a/tests/src/commonMain/kotlin/com/github/klee0kai/test/mowgli/School.kt b/tests/src/commonMain/kotlin/com/github/klee0kai/test/mowgli/School.kt index 419e2374..f2cb93a6 100644 --- a/tests/src/commonMain/kotlin/com/github/klee0kai/test/mowgli/School.kt +++ b/tests/src/commonMain/kotlin/com/github/klee0kai/test/mowgli/School.kt @@ -1,7 +1,7 @@ package com.github.klee0kai.test.mowgli -import com.github.klee0kai.stone.weakref.Inject -import com.github.klee0kai.stone.weakref.Provider +import com.github.klee0kai.stone.Inject +import com.github.klee0kai.stone.Provider import com.github.klee0kai.stone.weakref.Ref import com.github.klee0kai.stone.wrappers.LazyProvide import com.github.klee0kai.stone.wrappers.PhantomProvide diff --git a/tests/src/commonMain/kotlin/com/github/klee0kai/test/mowgli/animal/Horse.kt b/tests/src/commonMain/kotlin/com/github/klee0kai/test/mowgli/animal/Horse.kt index 4ffbe5f4..2abc2b66 100644 --- a/tests/src/commonMain/kotlin/com/github/klee0kai/test/mowgli/animal/Horse.kt +++ b/tests/src/commonMain/kotlin/com/github/klee0kai/test/mowgli/animal/Horse.kt @@ -1,6 +1,6 @@ package com.github.klee0kai.test.mowgli.animal -import com.github.klee0kai.stone.weakref.Inject +import com.github.klee0kai.stone.Inject import com.github.klee0kai.test.mowgli.body.Blood import com.github.klee0kai.test.mowgli.community.History import com.github.klee0kai.test.mowgli.galaxy.Earth diff --git a/tests/src/commonMain/kotlin/com/github/klee0kai/test/mowgli/animal/Mowgli.kt b/tests/src/commonMain/kotlin/com/github/klee0kai/test/mowgli/animal/Mowgli.kt index 187088ab..4dbc904a 100644 --- a/tests/src/commonMain/kotlin/com/github/klee0kai/test/mowgli/animal/Mowgli.kt +++ b/tests/src/commonMain/kotlin/com/github/klee0kai/test/mowgli/animal/Mowgli.kt @@ -1,5 +1,7 @@ package com.github.klee0kai.test.mowgli.animal +import com.github.klee0kai.stone.Inject +import com.github.klee0kai.stone.Provider import com.github.klee0kai.stone.weakref.* import com.github.klee0kai.stone.wrappers.LazyProvide import com.github.klee0kai.stone.wrappers.PhantomProvide diff --git a/tests/src/commonMain/kotlin/com/github/klee0kai/test/mowgli/animal/Snake.kt b/tests/src/commonMain/kotlin/com/github/klee0kai/test/mowgli/animal/Snake.kt index 19490727..d6475dce 100644 --- a/tests/src/commonMain/kotlin/com/github/klee0kai/test/mowgli/animal/Snake.kt +++ b/tests/src/commonMain/kotlin/com/github/klee0kai/test/mowgli/animal/Snake.kt @@ -1,6 +1,6 @@ package com.github.klee0kai.test.mowgli.animal -import com.github.klee0kai.stone.weakref.Inject +import com.github.klee0kai.stone.Inject import com.github.klee0kai.test.mowgli.body.Blood import com.github.klee0kai.test.mowgli.community.History import com.github.klee0kai.test.mowgli.galaxy.Earth diff --git a/tests/src/commonMain/kotlin/com/github/klee0kai/test/tech/phone/GoodPhone.kt b/tests/src/commonMain/kotlin/com/github/klee0kai/test/tech/phone/GoodPhone.kt index ecad2aa9..4a98b8a3 100644 --- a/tests/src/commonMain/kotlin/com/github/klee0kai/test/tech/phone/GoodPhone.kt +++ b/tests/src/commonMain/kotlin/com/github/klee0kai/test/tech/phone/GoodPhone.kt @@ -1,7 +1,7 @@ package com.github.klee0kai.test.tech.phone import com.github.klee0kai.stone.lifecycle.StoneLifeCycleOwner -import com.github.klee0kai.stone.weakref.Inject +import com.github.klee0kai.stone.Inject import com.github.klee0kai.test.tech.components.Battery import com.github.klee0kai.test.tech.components.DataStorage import com.github.klee0kai.test.tech.components.OperationSystem diff --git a/tests/src/commonMain/kotlin/com/github/klee0kai/test/tech/phone/OnePhone.kt b/tests/src/commonMain/kotlin/com/github/klee0kai/test/tech/phone/OnePhone.kt index 9529c0e7..9af342a1 100644 --- a/tests/src/commonMain/kotlin/com/github/klee0kai/test/tech/phone/OnePhone.kt +++ b/tests/src/commonMain/kotlin/com/github/klee0kai/test/tech/phone/OnePhone.kt @@ -2,8 +2,8 @@ package com.github.klee0kai.test.tech.phone import com.github.klee0kai.stone.lifecycle.StoneLifeCycleListener import com.github.klee0kai.stone.lifecycle.StoneLifeCycleOwner -import com.github.klee0kai.stone.weakref.Inject -import com.github.klee0kai.stone.weakref.Named +import com.github.klee0kai.stone.Inject +import com.github.klee0kai.stone.Named import com.github.klee0kai.test.tech.components.Battery import com.github.klee0kai.test.tech.components.DataStorage import com.github.klee0kai.test.tech.components.Ram diff --git a/tests_wraps_kotlin/src/main/kotlin/com/github/klee0kai/test/boxed/di/inject/CarBoxedWrapper.kt b/tests_wraps_kotlin/src/main/kotlin/com/github/klee0kai/test/boxed/di/inject/CarBoxedWrapper.kt index aa8d775c..897c5717 100644 --- a/tests_wraps_kotlin/src/main/kotlin/com/github/klee0kai/test/boxed/di/inject/CarBoxedWrapper.kt +++ b/tests_wraps_kotlin/src/main/kotlin/com/github/klee0kai/test/boxed/di/inject/CarBoxedWrapper.kt @@ -1,7 +1,7 @@ package com.github.klee0kai.test.boxed.di.inject import com.github.klee0kai.stone.annotations.wrappers.WrappersHelper -import com.github.klee0kai.stone.weakref.Provider +import com.github.klee0kai.stone.Provider import com.github.klee0kai.test.car.di.wrapped.custom.wrappers.CarLazy import com.github.klee0kai.test.car.di.wrapped.custom.wrappers.CarProvide diff --git a/tests_wraps_kotlin/src/main/kotlin/com/github/klee0kai/test/car/di/wrapped/custom/wrappers/CarRefWrapper.kt b/tests_wraps_kotlin/src/main/kotlin/com/github/klee0kai/test/car/di/wrapped/custom/wrappers/CarRefWrapper.kt index 5539a793..30a70a9f 100644 --- a/tests_wraps_kotlin/src/main/kotlin/com/github/klee0kai/test/car/di/wrapped/custom/wrappers/CarRefWrapper.kt +++ b/tests_wraps_kotlin/src/main/kotlin/com/github/klee0kai/test/car/di/wrapped/custom/wrappers/CarRefWrapper.kt @@ -1,6 +1,6 @@ package com.github.klee0kai.test.car.di.wrapped.custom.wrappers -import com.github.klee0kai.stone.weakref.Provider +import com.github.klee0kai.stone.Provider object CarRefWrapper { diff --git a/wiki_kotlin/src/main/kotlin/com/github/klee0kai/wiki/wrapping/CarBoxedWrapper.kt b/wiki_kotlin/src/main/kotlin/com/github/klee0kai/wiki/wrapping/CarBoxedWrapper.kt index feb0eb30..1250c14f 100644 --- a/wiki_kotlin/src/main/kotlin/com/github/klee0kai/wiki/wrapping/CarBoxedWrapper.kt +++ b/wiki_kotlin/src/main/kotlin/com/github/klee0kai/wiki/wrapping/CarBoxedWrapper.kt @@ -1,7 +1,7 @@ package com.github.klee0kai.wiki.wrapping import com.github.klee0kai.stone.annotations.wrappers.WrappersHelper -import com.github.klee0kai.stone.weakref.Provider +import com.github.klee0kai.stone.Provider @WrappersHelper object CustomLazyWrapper { From 24ae76c6a9473c9d68dd860c866973bcd502c4c0 Mon Sep 17 00:00:00 2001 From: klee0kai Date: Sun, 1 Mar 2026 19:06:46 +0100 Subject: [PATCH 117/122] gen provider processor --- libs.versions.toml | 2 + stone_ksp/build.gradle.kts | 1 + .../klee0kai/thekey/stone/ksp/Processor.kt | 2 + .../stone/ksp/ksp/AnnotationProtectedExt.kt | 11 ++ .../thekey/stone/ksp/ksp/FileLocationExt.kt | 32 ++++ .../thekey/stone/ksp/poet/AnnotationExt.kt | 40 +++++ .../thekey/stone/ksp/psi/InMemoryPsiParser.kt | 48 ++++++ .../thekey/stone/ksp/psi/PsiKspExt.kt | 15 ++ .../target/provider/GenProviderProcessor.kt | 152 ++++++++++++++++++ .../stone/annotations/module/Module.kt | 4 +- .../stone/annotations/module/Provide.kt | 9 +- tests/build.gradle.kts | 4 +- .../di/techproviders/TechFactoryComponent.kt | 20 +++ .../TechFactoryGenProvideModule.kt | 50 ++++++ .../test/techproviders/TechProvidersTests.kt | 39 +++++ 15 files changed, 426 insertions(+), 3 deletions(-) create mode 100644 stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/ksp/FileLocationExt.kt create mode 100644 stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/poet/AnnotationExt.kt create mode 100644 stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/psi/InMemoryPsiParser.kt create mode 100644 stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/psi/PsiKspExt.kt create mode 100644 stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/provider/GenProviderProcessor.kt create mode 100644 tests/src/commonMain/kotlin/com/github/klee0kai/test/di/techproviders/TechFactoryComponent.kt create mode 100644 tests/src/commonMain/kotlin/com/github/klee0kai/test/di/techproviders/TechFactoryGenProvideModule.kt create mode 100644 tests/src/jvmTest/kotlin/com/github/klee0kai/stone/test/techproviders/TechProvidersTests.kt diff --git a/libs.versions.toml b/libs.versions.toml index f307bd83..b7da0deb 100644 --- a/libs.versions.toml +++ b/libs.versions.toml @@ -36,6 +36,8 @@ ksp = { group = "com.google.devtools.ksp", name = "symbol-processing-api", versi kotlinpoet = { group = "com.squareup", name = "kotlinpoet", version.ref = "kotlinpoet" } kotlinpoet-ksp = { group = "com.squareup", name = "kotlinpoet-ksp", version.ref = "kotlinpoet" } +kotlin-compiler = { group = "org.jetbrains.kotlin", name = "kotlin-compiler-embeddable", version.ref = "kotlin" } + jupiter-api = { group = "org.junit.jupiter", name = "junit-jupiter-api", version.ref = "junit" } jupiter-engine = { group = "org.junit.jupiter", name = "junit-jupiter-engine", version.ref = "junit" } jupiter-launcher = { group = "org.junit.platform", name = "junit-platform-launcher", version.ref = "junit-launcher" } diff --git a/stone_ksp/build.gradle.kts b/stone_ksp/build.gradle.kts index 6bffb8d7..446e4085 100644 --- a/stone_ksp/build.gradle.kts +++ b/stone_ksp/build.gradle.kts @@ -18,6 +18,7 @@ kotlin { implementation(libs.bundles.kotlin) implementation(libs.bundles.kotlinpoet) implementation(libs.ksp) + implementation(libs.kotlin.compiler) } } } diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/Processor.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/Processor.kt index d4676c21..437f47dd 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/Processor.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/Processor.kt @@ -13,6 +13,7 @@ import com.github.klee0kai.thekey.stone.ksp.target.hiddenmodule.GenHiddenModuleP import com.github.klee0kai.thekey.stone.ksp.target.module.GenModuleCacheControlProcessor import com.github.klee0kai.thekey.stone.ksp.target.module.GenModuleFactoryProcessor import com.github.klee0kai.thekey.stone.ksp.target.module.GenModuleProcessor +import com.github.klee0kai.thekey.stone.ksp.target.provider.GenProviderProcessor import com.github.klee0kai.thekey.stone.ksp.target.wrapper.GenWrappersSupportProcessor import com.google.devtools.ksp.containingFile import com.google.devtools.ksp.processing.CodeGenerator @@ -70,6 +71,7 @@ class Processor( val dispatcher by lazy { if (multithread) Dispatchers.Default else Dispatchers.Unconfined } val targetProcessors = arrayOf( + GenProviderProcessor(), GenModuleFactoryProcessor(), GenModuleCacheControlProcessor(), GenModuleProcessor(), diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/ksp/AnnotationProtectedExt.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/ksp/AnnotationProtectedExt.kt index eb709d71..0b4b87b3 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/ksp/AnnotationProtectedExt.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/ksp/AnnotationProtectedExt.kt @@ -3,6 +3,7 @@ package com.github.klee0kai.thekey.stone.ksp.ksp import com.github.klee0kai.stone.annotations.component.ProtectInjected import com.github.klee0kai.stone.annotations.component.SwitchCache import com.github.klee0kai.stone.annotations.module.BindInstance +import com.github.klee0kai.stone.annotations.module.Module import com.github.klee0kai.stone.annotations.module.Provide /** @@ -10,6 +11,11 @@ import com.github.klee0kai.stone.annotations.module.Provide */ val Provide.cacheProtected get() = runCatching { cache }.getOrNull() ?: Provide.CacheType.Factory +/** + * fix crash at :tests:kspKotlinWasmJs + */ +val Provide.provideWrapperProtected get() = runCatching { provideWrapper }.getOrNull() ?: Nothing::class + /** * fix crash at :tests:kspKotlinWasmJs */ @@ -31,3 +37,8 @@ val SwitchCache.timeMillisProtected get() = runCatching { timeMillis }.getOrNull * fix crash at :tests:kspKotlinWasmJs */ val ProtectInjected.timeMillisProtected get() = runCatching { timeMillis }.getOrNull() ?: 5000L + +/** + * fix crash at :tests:kspKotlinWasmJs + */ +val Module.genProviderNameProtected get() = runCatching { genProviderName }.getOrNull() diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/ksp/FileLocationExt.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/ksp/FileLocationExt.kt new file mode 100644 index 00000000..9fba373b --- /dev/null +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/ksp/FileLocationExt.kt @@ -0,0 +1,32 @@ +package com.github.klee0kai.thekey.stone.ksp.ksp + +import com.google.devtools.ksp.symbol.FileLocation +import com.google.devtools.ksp.symbol.Location +import java.io.File + +fun Location.findText( + count: Int = Int.MAX_VALUE, +): String { + if (this is FileLocation) { + val file = File(filePath) + val lines = file.readLines() + + return lines + .drop(lineNumber - 1) + .take(count) + .joinToString("\n") + } + return "" +} + + +fun Location.fileText(): String { + if (this is FileLocation) { + val file = File(filePath) + val lines = file.readLines() + + return lines.joinToString("\n") + } + return "" +} + diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/poet/AnnotationExt.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/poet/AnnotationExt.kt new file mode 100644 index 00000000..b1e9b0ec --- /dev/null +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/poet/AnnotationExt.kt @@ -0,0 +1,40 @@ +package com.github.klee0kai.thekey.stone.ksp.poet + +import com.google.devtools.ksp.symbol.KSAnnotation +import com.google.devtools.ksp.symbol.KSType +import com.squareup.kotlinpoet.AnnotationSpec +import com.squareup.kotlinpoet.FunSpec +import com.squareup.kotlinpoet.ksp.toClassName +import com.squareup.kotlinpoet.ksp.toTypeName + +fun FunSpec.Builder.addAnnotation( + ksAnnotation: KSAnnotation, +): FunSpec.Builder { + val typeName = ksAnnotation.annotationType.resolve().toClassName() + + val annotationBuilder = AnnotationSpec.builder(typeName) + + for (arg in ksAnnotation.arguments) { + val name = arg.name?.asString() ?: continue + val value = arg.value + + // value может быть: primitive, enum, class, array + annotationBuilder.addMember("%L = %L", name, formatAnnotationValue(value)) + } + + return this.addAnnotation(annotationBuilder.build()) +} + +fun formatAnnotationValue( + value: Any?, +): String = when (value) { + is String -> "\"${value}\"" + is KSAnnotation -> { + val type = value.annotationType.resolve().toTypeName() + "@$type" + } + + is KSType -> value.toTypeName().toString() + "::class" + is List<*> -> value.joinToString(", ", "{", "}") { formatAnnotationValue(it) } + else -> value.toString() +} \ No newline at end of file diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/psi/InMemoryPsiParser.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/psi/InMemoryPsiParser.kt new file mode 100644 index 00000000..a472d2fa --- /dev/null +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/psi/InMemoryPsiParser.kt @@ -0,0 +1,48 @@ +package com.github.klee0kai.thekey.stone.ksp.psi + +import org.jetbrains.kotlin.cli.jvm.compiler.EnvironmentConfigFiles +import org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment +import org.jetbrains.kotlin.com.intellij.openapi.Disposable +import org.jetbrains.kotlin.com.intellij.openapi.util.Disposer +import org.jetbrains.kotlin.com.intellij.psi.PsiElement +import org.jetbrains.kotlin.config.CompilerConfiguration +import org.jetbrains.kotlin.psi.KtPsiFactory +import java.lang.AutoCloseable + +class InMemoryPsiParser( + val fileCode: String, +) : AutoCloseable { + val disposable: Disposable = Disposer.newDisposable() + + val configuration = CompilerConfiguration() + val environment = KotlinCoreEnvironment.createForProduction( + disposable, + configuration, + EnvironmentConfigFiles.JVM_CONFIG_FILES + ) + + val project = environment.project + val psiFactory = KtPsiFactory(project, markGenerated = false) + + val ktFile = psiFactory.createFile(fileCode) + + val document = ktFile.containingFile.viewProvider.document + + override fun close() { + Disposer.dispose(disposable) + } + +} + + +fun PsiElement.fileNumber(): Int { + val document = containingFile.viewProvider.document + + if (document != null) { + val line = document.getLineNumber(textOffset) + val column = textOffset - document.getLineStartOffset(line) + + return column + 1 + } + return -1 +} diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/psi/PsiKspExt.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/psi/PsiKspExt.kt new file mode 100644 index 00000000..e91092ce --- /dev/null +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/psi/PsiKspExt.kt @@ -0,0 +1,15 @@ +package com.github.klee0kai.thekey.stone.ksp.psi + +import com.google.devtools.ksp.symbol.FileLocation +import com.google.devtools.ksp.symbol.KSNode +import org.jetbrains.kotlin.com.intellij.psi.impl.PsiElementBase + +fun PsiElementBase.isSamePlace(otherElement: KSNode): Boolean { + val document = containingFile.containingFile.viewProvider.document + val kspElementLine = ((otherElement.location as? FileLocation)?.lineNumber ?: 1) - 1 + + val psiFunLineStart = document.getLineNumber(textRange.startOffset) + val psiFunLineEnd = document.getLineNumber(textRange.endOffset) + + return kspElementLine in psiFunLineStart..psiFunLineEnd +} \ No newline at end of file diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/provider/GenProviderProcessor.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/provider/GenProviderProcessor.kt new file mode 100644 index 00000000..a6fb7561 --- /dev/null +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/provider/GenProviderProcessor.kt @@ -0,0 +1,152 @@ +@file:OptIn(KspExperimental::class) + +package com.github.klee0kai.thekey.stone.ksp.target.provider + +import com.github.klee0kai.stone.annotations.module.Module +import com.github.klee0kai.stone.annotations.module.Provide +import com.github.klee0kai.thekey.stone.ksp.exceptions.forEachFun +import com.github.klee0kai.thekey.stone.ksp.helpers.allIdentifierTypes +import com.github.klee0kai.thekey.stone.ksp.helpers.findComponentForModuleOrDep +import com.github.klee0kai.thekey.stone.ksp.helpers.identifierParameters +import com.github.klee0kai.thekey.stone.ksp.helpers.qualifierAnnotations +import com.github.klee0kai.thekey.stone.ksp.ksp.arch.GenSpec +import com.github.klee0kai.thekey.stone.ksp.ksp.arch.SymbolsToProcess +import com.github.klee0kai.thekey.stone.ksp.ksp.arch.TargetFileProcessor +import com.github.klee0kai.thekey.stone.ksp.ksp.fileText +import com.github.klee0kai.thekey.stone.ksp.ksp.genProviderNameProtected +import com.github.klee0kai.thekey.stone.ksp.ksp.getAllMethods +import com.github.klee0kai.thekey.stone.ksp.ksp.provideWrapperProtected +import com.github.klee0kai.thekey.stone.ksp.poet.* +import com.github.klee0kai.thekey.stone.ksp.psi.InMemoryPsiParser +import com.github.klee0kai.thekey.stone.ksp.psi.isSamePlace +import com.github.klee0kai.thekey.stone.ksp.target.isSuspend +import com.google.devtools.ksp.KspExperimental +import com.google.devtools.ksp.containingFile +import com.google.devtools.ksp.getAnnotationsByType +import com.google.devtools.ksp.processing.Dependencies +import com.google.devtools.ksp.processing.KSPLogger +import com.google.devtools.ksp.processing.Resolver +import com.google.devtools.ksp.symbol.KSAnnotated +import com.google.devtools.ksp.symbol.KSClassDeclaration +import com.squareup.kotlinpoet.ClassName +import com.squareup.kotlinpoet.KModifier +import com.squareup.kotlinpoet.ParameterSpec +import com.squareup.kotlinpoet.ParameterizedTypeName.Companion.parameterizedBy +import com.squareup.kotlinpoet.asClassName +import com.squareup.kotlinpoet.ksp.toClassName +import com.squareup.kotlinpoet.ksp.toTypeName +import org.jetbrains.kotlin.psi.KtClass +import org.jetbrains.kotlin.psi.KtNamedFunction + +class GenProviderProcessor : TargetFileProcessor { + + override suspend fun findSymbolsToProcess( + resolver: Resolver, + ) = SymbolsToProcess( + symbolsForProcessing = resolver + .getSymbolsWithAnnotation(Module::class.asClassName().canonicalName) + .toList(), + symbolsForReprocessing = emptyList(), + ) + + override suspend fun process( + validSymbol: KSAnnotated, + resolver: Resolver, + options: Map, + logger: KSPLogger + ): GenSpec? { + val fileOwner = validSymbol.containingFile ?: return null + val moduleCl = validSymbol as? KSClassDeclaration ?: return null + + val moduleAnn = moduleCl.getAnnotationsByType(Module::class) + .firstOrNull() ?: return null + + val componentCl = resolver.findComponentForModuleOrDep(moduleCl.toClassName()) + .firstOrNull() + + val identifierTypes = componentCl + ?.allIdentifierTypes?.toList() + ?: emptyList() + + if (moduleAnn.genProviderNameProtected.isNullOrBlank()) return null + + + val genProvideClName = ClassName( + moduleCl.packageName.asString(), + moduleAnn.genProviderName, + ) + + val filePsi = InMemoryPsiParser(moduleCl.location.fileText()) + + val fileSpec = genFileSpec(moduleCl.packageName.asString(), genProvideClName.simpleName) { + genLibComment() + + genInterface(genProvideClName) { + validSymbol.getAllMethods(false, false, "") + .forEachFun { funIdx, func -> + val idArguments = func.parameters.identifierParameters(identifierTypes) + val returnType = func.returnType?.resolve()?.toTypeName() ?: return@forEachFun + + + val provideWrapper = func.getAnnotationsByType(Provide::class) + .firstOrNull() + ?.provideWrapperProtected + ?.takeIf { it !in listOf(Nothing::class, Void::class) } + + val providingType = provideWrapper?.asClassName()?.parameterizedBy(returnType) + ?: returnType + + genFun(func.simpleName.asString()) { + if (func.isSuspend) addModifiers(KModifier.SUSPEND) + val psiFunc by lazy { + filePsi.ktFile.declarations + .filterIsInstance() + .firstOrNull() + ?.declarations + ?.filterIsInstance() + ?.firstOrNull { it.isSamePlace(func) } + } + addModifiers(KModifier.ABSTRACT) + returns(providingType) + func.qualifierAnnotations.forEach { + addAnnotation(it) + } + + idArguments.forEach { param -> + addParameter( + ParameterSpec.builder( + name = param.name?.asString() ?: "", + type = param.type.resolve().toTypeName(), + ).apply { + if (param.isVararg) addModifiers(KModifier.VARARG) + + if (param.hasDefault && psiFunc != null) { + val psiParam = psiFunc + ?.valueParameters + ?.firstOrNull { it.name == param.name?.asString() } + + if (!psiParam?.defaultValue?.text.isNullOrBlank()) { + defaultValue("%L", psiParam.defaultValue?.text) + } + } + }.build() + ) + } + } + } + + + } + } + + + filePsi.close() + + return GenSpec( + fileSpec = fileSpec, + // https://kotlinlang.org/docs/ksp-incremental.html + dependencies = Dependencies(aggregating = false, fileOwner), + ) + } + +} \ No newline at end of file diff --git a/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/annotations/module/Module.kt b/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/annotations/module/Module.kt index 91c0b934..59f8af7f 100644 --- a/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/annotations/module/Module.kt +++ b/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/annotations/module/Module.kt @@ -79,4 +79,6 @@ package com.github.klee0kai.stone.annotations.module */ @Retention(AnnotationRetention.BINARY) @Target(AnnotationTarget.CLASS) -annotation class Module +annotation class Module( + val genProviderName: String = "", +) diff --git a/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/annotations/module/Provide.kt b/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/annotations/module/Provide.kt index 8f9c65e2..c3081cc2 100644 --- a/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/annotations/module/Provide.kt +++ b/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/annotations/module/Provide.kt @@ -1,5 +1,7 @@ package com.github.klee0kai.stone.annotations.module +import kotlin.reflect.KClass + /** * Providing objects. * This annotation marks the methods in the module for providing objects. @@ -33,7 +35,12 @@ annotation class Provide( /** * Object caching type */ - val cache: CacheType = CacheType.Factory + val cache: CacheType = CacheType.Factory, + + /** + * provide dependency with wrapper packaging + */ + val provideWrapper: KClass<*> = Nothing::class, ) { enum class CacheType { Factory, diff --git a/tests/build.gradle.kts b/tests/build.gradle.kts index 2b15cbb8..8ac9c4bc 100644 --- a/tests/build.gradle.kts +++ b/tests/build.gradle.kts @@ -20,6 +20,8 @@ kotlin { sourceSets { val commonMain by getting { + kotlin.srcDir("build/generated/ksp/metadata/commonMain/kotlin") + dependencies { implementation(project(":stone_multiplatform")) } @@ -39,7 +41,7 @@ kotlin { } dependencies { - ksp(project(":stone_ksp")) + add("kspCommonMainMetadata", project(":stone_ksp")) } diff --git a/tests/src/commonMain/kotlin/com/github/klee0kai/test/di/techproviders/TechFactoryComponent.kt b/tests/src/commonMain/kotlin/com/github/klee0kai/test/di/techproviders/TechFactoryComponent.kt new file mode 100644 index 00000000..2b747c30 --- /dev/null +++ b/tests/src/commonMain/kotlin/com/github/klee0kai/test/di/techproviders/TechFactoryComponent.kt @@ -0,0 +1,20 @@ +package com.github.klee0kai.test.di.techproviders + +import com.github.klee0kai.stone.annotations.component.Component +import com.github.klee0kai.test.di.base_phone.identifiers.DataStorageSize +import com.github.klee0kai.test.di.base_phone.identifiers.PhoneOsType +import com.github.klee0kai.test.di.base_phone.identifiers.PhoneOsVersion +import com.github.klee0kai.test.di.base_phone.identifiers.RamSize + + +@Component( + identifiers = [ + RamSize::class, + DataStorageSize::class, + PhoneOsType::class, + PhoneOsVersion::class, + ] +) +interface TechFactoryGenProvideComponent : TechFactoryProviders { + fun factory(): TechFactoryGenProvideModule? +} diff --git a/tests/src/commonMain/kotlin/com/github/klee0kai/test/di/techproviders/TechFactoryGenProvideModule.kt b/tests/src/commonMain/kotlin/com/github/klee0kai/test/di/techproviders/TechFactoryGenProvideModule.kt new file mode 100644 index 00000000..0bb07977 --- /dev/null +++ b/tests/src/commonMain/kotlin/com/github/klee0kai/test/di/techproviders/TechFactoryGenProvideModule.kt @@ -0,0 +1,50 @@ +package com.github.klee0kai.test.di.techproviders + +import com.github.klee0kai.stone.Named +import com.github.klee0kai.stone.Provider +import com.github.klee0kai.stone.annotations.module.Module +import com.github.klee0kai.stone.annotations.module.Provide +import com.github.klee0kai.stone.weakref.Ref +import com.github.klee0kai.stone.weakref.WeakRef +import com.github.klee0kai.stone.wrappers.AsyncCoroutineProvide +import com.github.klee0kai.stone.wrappers.LazyProvide +import com.github.klee0kai.test.di.base_phone.identifiers.DataStorageSize +import com.github.klee0kai.test.di.base_phone.identifiers.PhoneOsType +import com.github.klee0kai.test.di.base_phone.identifiers.PhoneOsVersion +import com.github.klee0kai.test.di.base_phone.identifiers.RamSize +import com.github.klee0kai.test.tech.components.Battery +import com.github.klee0kai.test.tech.components.DataStorage +import com.github.klee0kai.test.tech.components.OperationSystem +import com.github.klee0kai.test.tech.components.Ram + +@Module(genProviderName = "TechFactoryProviders") +interface TechFactoryGenProvideModule { + + @Provide(cache = Provide.CacheType.Factory, provideWrapper = LazyProvide::class) + fun battery(): Battery? + + @Named("null_args") + @Provide(cache = Provide.CacheType.Factory) + fun dataStorage(): DataStorage? + + @Provide(cache = Provide.CacheType.Factory) + fun dataStorage(size: DataStorageSize?): DataStorage? + + @Named("null_args") + @Provide(cache = Provide.CacheType.Factory, provideWrapper = Provider::class) + fun ram(): Ram? + + @Provide(cache = Provide.CacheType.Factory, provideWrapper = Ref::class) + fun ram(ramSize: RamSize? = null): Ram? + + + @Named("null_args") + @Provide(cache = Provide.CacheType.Factory, provideWrapper = WeakRef::class) + fun phoneOsNamed(osType: PhoneOsType?): OperationSystem? + + @Provide(cache = Provide.CacheType.Factory, provideWrapper = AsyncCoroutineProvide::class) + fun phoneOs( + phoneOsType: PhoneOsType? = PhoneOsType.UbuntuTouch, + version: PhoneOsVersion? = PhoneOsVersion(version = "def_version") + ): OperationSystem? +} diff --git a/tests/src/jvmTest/kotlin/com/github/klee0kai/stone/test/techproviders/TechProvidersTests.kt b/tests/src/jvmTest/kotlin/com/github/klee0kai/stone/test/techproviders/TechProvidersTests.kt new file mode 100644 index 00000000..ffc9ea13 --- /dev/null +++ b/tests/src/jvmTest/kotlin/com/github/klee0kai/stone/test/techproviders/TechProvidersTests.kt @@ -0,0 +1,39 @@ +package com.github.klee0kai.stone.test.techproviders + +import com.github.klee0kai.test.di.base_phone.identifiers.PhoneOsType +import com.github.klee0kai.test.di.base_phone.identifiers.PhoneOsVersion +import com.github.klee0kai.test.di.techproviders.TechFactoryGenProvideComponentStoneComponent +import kotlinx.coroutines.runBlocking +import kotlin.test.Test +import kotlin.test.assertEquals +import kotlin.test.assertNotNull + +class TechProvidersTests { + + @Test + fun batteryProvideTest() { + //Given + val di = TechFactoryGenProvideComponentStoneComponent() + + //when + val battery = di.battery() + + //then + assertNotNull(battery.get()!!.uuid) + } + + @Test + fun phoneOsProvideTest() = runBlocking { + //Given + val di = TechFactoryGenProvideComponentStoneComponent() + + //when + val phoneOs = di.phoneOs() + + //then + assertNotNull(phoneOs.get()!!.uuid) + assertEquals(PhoneOsType.UbuntuTouch, phoneOs.get()!!.phoneOsType) + assertEquals(PhoneOsVersion(version = "def_version"), phoneOs.get()!!.version) + } + +} \ No newline at end of file From ed5e0110deac052b09635a165bcd5e8a9badfc83 Mon Sep 17 00:00:00 2001 From: klee0kai Date: Sun, 1 Mar 2026 19:26:46 +0100 Subject: [PATCH 118/122] using ReentrantMutex --- .../__hidden__/coroutines/CoroutinesExt.kt | 4 +- .../types/holders/SingleItemHolder.kt | 4 +- .../klee0kai/stone/mutex/ReentrantMutex.kt | 51 +++++++++++++++++++ .../coroutines/CoroutinesExt.jvm.kt | 5 +- .../coroutines/CoroutinesExt.native.kt | 4 +- .../coroutines/CoroutinesExt.web.kt | 4 +- 6 files changed, 61 insertions(+), 11 deletions(-) create mode 100644 stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/mutex/ReentrantMutex.kt diff --git a/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/__hidden__/coroutines/CoroutinesExt.kt b/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/__hidden__/coroutines/CoroutinesExt.kt index 6a0c067d..6129af69 100644 --- a/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/__hidden__/coroutines/CoroutinesExt.kt +++ b/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/__hidden__/coroutines/CoroutinesExt.kt @@ -1,9 +1,9 @@ package com.github.klee0kai.stone.__hidden__.coroutines -import kotlinx.coroutines.sync.Mutex +import com.github.klee0kai.stone.mutex.ReentrantMutex expect fun T.syncIfAvailable( - mutex: Mutex, + mutex: ReentrantMutex, block: T.() -> R ): R diff --git a/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/__hidden__/types/holders/SingleItemHolder.kt b/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/__hidden__/types/holders/SingleItemHolder.kt index 2df577d4..94cc22d6 100644 --- a/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/__hidden__/types/holders/SingleItemHolder.kt +++ b/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/__hidden__/types/holders/SingleItemHolder.kt @@ -3,11 +3,11 @@ package com.github.klee0kai.stone.__hidden__.types.holders import com.github.klee0kai.stone.__hidden__.StoneScope import com.github.klee0kai.stone.__hidden__.SwitchCacheParam import com.github.klee0kai.stone.annotations.component.SwitchCache +import com.github.klee0kai.stone.mutex.ReentrantMutex import com.github.klee0kai.stone.weakref.Ref import kotlinx.atomicfu.atomic import kotlinx.coroutines.delay import kotlinx.coroutines.launch -import kotlinx.coroutines.sync.Mutex /** * Stone Private class @@ -15,7 +15,7 @@ import kotlinx.coroutines.sync.Mutex @Suppress("UNCHECKED_CAST") class SingleItemHolder( private val defType: StoneRefType, - val mutex: Mutex = Mutex(), + val mutex: ReentrantMutex = ReentrantMutex(), ) { private var curRefType: StoneRefType = defType diff --git a/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/mutex/ReentrantMutex.kt b/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/mutex/ReentrantMutex.kt new file mode 100644 index 00000000..ab96dc25 --- /dev/null +++ b/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/mutex/ReentrantMutex.kt @@ -0,0 +1,51 @@ +@file:OptIn(ExperimentalTime::class) + +package com.github.klee0kai.stone.mutex + +import kotlinx.atomicfu.atomic +import kotlinx.coroutines.Job +import kotlinx.coroutines.currentCoroutineContext +import kotlinx.coroutines.sync.Mutex +import kotlin.time.ExperimentalTime + +class ReentrantMutex { + + private val mutex = Mutex() + private val owner = atomic(null) + private var count = 0 + + suspend fun lock() { + val current = coroutineId() + if (owner.value == current) { + count++ + return + } + mutex.lock() + owner.value = current + count = 1 + } + + suspend fun unlock() { + val current = coroutineId() + require(owner.value == current) { "Unlock from non-owner!" } + count-- + if (count == 0) { + owner.value = null + mutex.unlock() + } + } + + suspend fun withLock(action: suspend () -> T): T { + lock() + return try { + action() + } finally { + unlock() + } + } +} + +internal typealias CoroutineId = Long + +internal suspend fun coroutineId( +): CoroutineId = currentCoroutineContext()[Job]?.hashCode()?.toLong() ?: error("No Job in context") diff --git a/stone_multiplatform/src/jvmMain/kotlin/com/github/klee0kai/stone/__hidden__/coroutines/CoroutinesExt.jvm.kt b/stone_multiplatform/src/jvmMain/kotlin/com/github/klee0kai/stone/__hidden__/coroutines/CoroutinesExt.jvm.kt index c9b841e6..515af18c 100644 --- a/stone_multiplatform/src/jvmMain/kotlin/com/github/klee0kai/stone/__hidden__/coroutines/CoroutinesExt.jvm.kt +++ b/stone_multiplatform/src/jvmMain/kotlin/com/github/klee0kai/stone/__hidden__/coroutines/CoroutinesExt.jvm.kt @@ -1,11 +1,10 @@ package com.github.klee0kai.stone.__hidden__.coroutines +import com.github.klee0kai.stone.mutex.ReentrantMutex import kotlinx.coroutines.runBlocking -import kotlinx.coroutines.sync.Mutex -import kotlinx.coroutines.sync.withLock actual fun T.syncIfAvailable( - mutex: Mutex, + mutex: ReentrantMutex, block: T.() -> R, ): R = runBlocking { mutex.withLock { diff --git a/stone_multiplatform/src/nativeMain/kotlin/com/github/klee0kai/stone/__hidden__/coroutines/CoroutinesExt.native.kt b/stone_multiplatform/src/nativeMain/kotlin/com/github/klee0kai/stone/__hidden__/coroutines/CoroutinesExt.native.kt index 653283db..89f4491e 100644 --- a/stone_multiplatform/src/nativeMain/kotlin/com/github/klee0kai/stone/__hidden__/coroutines/CoroutinesExt.native.kt +++ b/stone_multiplatform/src/nativeMain/kotlin/com/github/klee0kai/stone/__hidden__/coroutines/CoroutinesExt.native.kt @@ -1,9 +1,9 @@ package com.github.klee0kai.stone.__hidden__.coroutines -import kotlinx.coroutines.sync.Mutex +import com.github.klee0kai.stone.mutex.ReentrantMutex actual fun T.syncIfAvailable( - mutex: Mutex, + mutex: ReentrantMutex, block: T.() -> R ): R = block() diff --git a/stone_multiplatform/src/webMain/kotlin/com/github/klee0kai/stone/__hidden__/coroutines/CoroutinesExt.web.kt b/stone_multiplatform/src/webMain/kotlin/com/github/klee0kai/stone/__hidden__/coroutines/CoroutinesExt.web.kt index 4a4df1b0..c3c9932c 100644 --- a/stone_multiplatform/src/webMain/kotlin/com/github/klee0kai/stone/__hidden__/coroutines/CoroutinesExt.web.kt +++ b/stone_multiplatform/src/webMain/kotlin/com/github/klee0kai/stone/__hidden__/coroutines/CoroutinesExt.web.kt @@ -1,8 +1,8 @@ package com.github.klee0kai.stone.__hidden__.coroutines -import kotlinx.coroutines.sync.Mutex +import com.github.klee0kai.stone.mutex.ReentrantMutex actual fun T.syncIfAvailable( - mutex: Mutex, + mutex: ReentrantMutex, block: T.() -> R, ): R = block() From 917306832debdd7eede3eaaa25ad2ce7b2abdee2 Mon Sep 17 00:00:00 2001 From: klee0kai Date: Sun, 1 Mar 2026 19:37:25 +0100 Subject: [PATCH 119/122] phantom async provide --- .../stone/ksp/helpers/wrap/WrapHelper.kt | 4 +++- .../wrapper/GenWrappersSupportProcessor.kt | 1 - .../stone/wrappers/FantomAsyncProvide.kt | 19 +++++++++++++++++++ .../create/CarWrappedCreateComponent.kt | 6 ++++++ .../test/car/wrapper/CarSingleWrapperTests.kt | 15 +++++++++++++++ 5 files changed, 43 insertions(+), 2 deletions(-) create mode 100644 stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/wrappers/FantomAsyncProvide.kt diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/wrap/WrapHelper.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/wrap/WrapHelper.kt index 164191a5..5c334bfe 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/wrap/WrapHelper.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/wrap/WrapHelper.kt @@ -5,6 +5,7 @@ import com.github.klee0kai.stone.weakref.Ref import com.github.klee0kai.stone.weakref.SoftRef import com.github.klee0kai.stone.weakref.WeakRef import com.github.klee0kai.stone.wrappers.AsyncCoroutineProvide +import com.github.klee0kai.stone.wrappers.FantomAsyncProvide import com.github.klee0kai.stone.wrappers.LazyProvide import com.github.klee0kai.stone.wrappers.PhantomProvide import com.github.klee0kai.thekey.stone.ksp.exceptions.StoneException @@ -284,7 +285,8 @@ class WrapHelper { Provider::class, javax.inject.Provider::class, LazyProvide::class, - AsyncCoroutineProvide::class + AsyncCoroutineProvide::class, + FantomAsyncProvide::class, )) { val isNoCachingWrapper = cl != LazyProvide::class && cl != AsyncCoroutineProvide::class diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/wrapper/GenWrappersSupportProcessor.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/wrapper/GenWrappersSupportProcessor.kt index 759ab690..8ce49fe6 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/wrapper/GenWrappersSupportProcessor.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/wrapper/GenWrappersSupportProcessor.kt @@ -33,7 +33,6 @@ class GenWrappersSupportProcessor : TargetFileProcessor { ) } - override suspend fun findSymbolsToProcess( resolver: Resolver ) = SymbolsToProcess( diff --git a/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/wrappers/FantomAsyncProvide.kt b/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/wrappers/FantomAsyncProvide.kt new file mode 100644 index 00000000..fa41a2d3 --- /dev/null +++ b/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/wrappers/FantomAsyncProvide.kt @@ -0,0 +1,19 @@ +package com.github.klee0kai.stone.wrappers + +import com.github.klee0kai.stone.weakref.Ref + +/** + * Transparent provider of an object or dependency. + * Does not cache the value after provisioning. + */ +class FantomAsyncProvide( + private val provider: suspend () -> T +) { + + constructor(call: Ref) : this(provider = { call.get() }) + + suspend fun get(): T = provider() + + suspend operator fun invoke(): T = provider() + +} \ No newline at end of file diff --git a/tests_wraps_kotlin/src/main/kotlin/com/github/klee0kai/test/car/di/wrapped/create/CarWrappedCreateComponent.kt b/tests_wraps_kotlin/src/main/kotlin/com/github/klee0kai/test/car/di/wrapped/create/CarWrappedCreateComponent.kt index 1afa774a..9410f735 100644 --- a/tests_wraps_kotlin/src/main/kotlin/com/github/klee0kai/test/car/di/wrapped/create/CarWrappedCreateComponent.kt +++ b/tests_wraps_kotlin/src/main/kotlin/com/github/klee0kai/test/car/di/wrapped/create/CarWrappedCreateComponent.kt @@ -2,7 +2,9 @@ package com.github.klee0kai.test.car.di.wrapped.create import com.github.klee0kai.stone.annotations.component.Component import com.github.klee0kai.stone.wrappers.AsyncCoroutineProvide +import com.github.klee0kai.stone.wrappers.FantomAsyncProvide import com.github.klee0kai.stone.wrappers.LazyProvide +import com.github.klee0kai.test.car.model.Bumper import com.github.klee0kai.test.car.model.Car import com.github.klee0kai.test.car.model.Wheel import com.github.klee0kai.test.car.model.Window @@ -38,4 +40,8 @@ interface CarWrappedCreateComponent { fun car(): Car? fun carAsync(): AsyncCoroutineProvide? + + fun bumperAsyncPhantom(): FantomAsyncProvide + + } diff --git a/tests_wraps_kotlin/src/test/kotlin/com/github/klee0kai/stone/kotlin/test/car/wrapper/CarSingleWrapperTests.kt b/tests_wraps_kotlin/src/test/kotlin/com/github/klee0kai/stone/kotlin/test/car/wrapper/CarSingleWrapperTests.kt index e87372df..084496ed 100644 --- a/tests_wraps_kotlin/src/test/kotlin/com/github/klee0kai/stone/kotlin/test/car/wrapper/CarSingleWrapperTests.kt +++ b/tests_wraps_kotlin/src/test/kotlin/com/github/klee0kai/stone/kotlin/test/car/wrapper/CarSingleWrapperTests.kt @@ -8,6 +8,7 @@ import com.github.klee0kai.test.car.model.Window import kotlinx.coroutines.delay import kotlinx.coroutines.runBlocking import org.junit.jupiter.api.Assertions.assertEquals +import org.junit.jupiter.api.Assertions.assertNotEquals import org.junit.jupiter.api.Assertions.assertNotNull import org.junit.jupiter.api.BeforeEach import org.junit.jupiter.api.Test @@ -162,6 +163,20 @@ class CarSingleWrapperTests { assertEquals(1, Car.createCount) } + @Test + fun bumperAsyncPhantomTest() = runBlocking { + //Given + val DI = CarWrappedCreateComponentStoneComponent() + + //When + val bumper = DI.bumperAsyncPhantom() + + // Then + assertNotNull(bumper.get().uuid) + assertNotEquals(bumper.get().uuid, bumper.get().uuid) + assertEquals(3, Bumper.createCount) + } + @Test fun carProvideTest() { //Given From fe3eb49861805fa0c304f63a56729cfe7ecffe70 Mon Sep 17 00:00:00 2001 From: klee0kai Date: Sun, 1 Mar 2026 22:34:58 +0100 Subject: [PATCH 120/122] correct field synchronization --- .../itemholder/ItemHolderCodeHelper.kt | 2 + .../MultiKeyMapItemHolderCodeHelper.kt | 2 +- .../SimpleMapItemHolderCodeHelper.kt | 2 +- .../itemholder/SingleItemHolderCodeHelper.kt | 2 +- .../hiddenmodule/GenHiddenModuleProcessor.kt | 4 +- .../ksp/target/module/GenModuleProcessor.kt | 6 +-- .../__hidden__/coroutines/CoroutinesExt.kt | 4 +- .../__hidden__/types/holders/MapItemHolder.kt | 4 +- .../types/holders/SingleItemHolder.kt | 4 +- .../klee0kai/stone/mutex/ReentrantMutex.kt | 51 ------------------- .../coroutines/CoroutinesExt.jvm.kt | 5 +- .../coroutines/CoroutinesExt.native.kt | 4 +- .../coroutines/CoroutinesExt.web.kt | 4 +- 13 files changed, 24 insertions(+), 70 deletions(-) delete mode 100644 stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/mutex/ReentrantMutex.kt diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/itemholder/ItemHolderCodeHelper.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/itemholder/ItemHolderCodeHelper.kt index 5b750b52..b7458c1c 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/itemholder/ItemHolderCodeHelper.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/itemholder/ItemHolderCodeHelper.kt @@ -9,6 +9,8 @@ import com.squareup.kotlinpoet.TypeSpec interface ItemHolderCodeHelper { companion object; + val fieldName: String + fun TypeSpec.Builder.genCacheField() fun codeGetCachedValue(): CodeBlock diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/itemholder/MultiKeyMapItemHolderCodeHelper.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/itemholder/MultiKeyMapItemHolderCodeHelper.kt index d7beb9aa..de5d189c 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/itemholder/MultiKeyMapItemHolderCodeHelper.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/itemholder/MultiKeyMapItemHolderCodeHelper.kt @@ -10,7 +10,7 @@ import com.squareup.kotlinpoet.* import com.squareup.kotlinpoet.ParameterizedTypeName.Companion.parameterizedBy class MultiKeyMapItemHolderCodeHelper( - val fieldName: String, + override val fieldName: String, val returnType: TypeName, val nonWrappedReturnType: TypeName, val itemCacheType: ItemCacheType, diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/itemholder/SimpleMapItemHolderCodeHelper.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/itemholder/SimpleMapItemHolderCodeHelper.kt index 8cd75119..4f35fdb6 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/itemholder/SimpleMapItemHolderCodeHelper.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/itemholder/SimpleMapItemHolderCodeHelper.kt @@ -10,7 +10,7 @@ import com.squareup.kotlinpoet.ParameterizedTypeName.Companion.parameterizedBy import com.squareup.kotlinpoet.ksp.toTypeName class SimpleMapItemHolderCodeHelper( - val fieldName: String, + override val fieldName: String, val returnType: TypeName, val nonWrappedReturnType: TypeName, val itemCacheType: ItemCacheType, diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/itemholder/SingleItemHolderCodeHelper.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/itemholder/SingleItemHolderCodeHelper.kt index caf58951..c142a12d 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/itemholder/SingleItemHolderCodeHelper.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/itemholder/SingleItemHolderCodeHelper.kt @@ -8,7 +8,7 @@ import com.squareup.kotlinpoet.* import com.squareup.kotlinpoet.ParameterizedTypeName.Companion.parameterizedBy class SingleItemHolderCodeHelper( - val fieldName: String, + override val fieldName: String, val returnType: TypeName, val nonWrappedReturnType: TypeName, val itemCacheType: ItemCacheType, diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/hiddenmodule/GenHiddenModuleProcessor.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/hiddenmodule/GenHiddenModuleProcessor.kt index 5b58934d..77e112ea 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/hiddenmodule/GenHiddenModuleProcessor.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/hiddenmodule/GenHiddenModuleProcessor.kt @@ -182,7 +182,7 @@ class GenHiddenModuleProcessor : TargetFileProcessor { } genOverrideFun(function) { - beginControlFlow("return syncIfAvailable(%L.mutex)", overridedModuleFieldName) + beginControlFlow("return syncIfAvailable(%L.mutex)", itemHolderCodeHelper.fieldName) addStatement( "val cached = %L.get()?.%L( %T.getValueAction, %L ) ", overridedModuleFieldName, @@ -242,7 +242,7 @@ class GenHiddenModuleProcessor : TargetFileProcessor { addParameter(it.name!!.asString(), it.type.resolve().toTypeName()) } - beginControlFlow("return syncIfAvailable(%L.mutex)", overridedModuleFieldName) + beginControlFlow("return syncIfAvailable(%L.mutex)", itemHolderCodeHelper.fieldName) addStatement( "%L.get()?.%L( __action, %L ) ", overridedModuleFieldName, diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/module/GenModuleProcessor.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/module/GenModuleProcessor.kt index 36247089..f85903e8 100644 --- a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/module/GenModuleProcessor.kt +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/module/GenModuleProcessor.kt @@ -267,7 +267,7 @@ class GenModuleProcessor : TargetFileProcessor { } genOverrideFun(function) { - beginControlFlow("return syncIfAvailable(%L.mutex)", overridedModuleFieldName) + beginControlFlow("return syncIfAvailable(%L.mutex)", itemHolderCodeHelper.fieldName) addStatement( "val cached = %L.get()?.%L( %T.getValueAction, %L ) ", overridedModuleFieldName, @@ -316,7 +316,7 @@ class GenModuleProcessor : TargetFileProcessor { ) { val returnType = function.returnType?.resolve()?.toTypeName() ?: return genOverrideFun(function) { - beginControlFlow("return syncIfAvailable(%L.mutex)", overridedModuleFieldName) + beginControlFlow("return syncIfAvailable(%L.mutex)", itemHolderCodeHelper.fieldName) addStatement( "val cached = %L.get()?.%L( %T.getValueAction, %L ) ", overridedModuleFieldName, @@ -383,7 +383,7 @@ class GenModuleProcessor : TargetFileProcessor { addParameter(it.name!!.asString(), it.type.resolve().toTypeName()) } - beginControlFlow("return syncIfAvailable(%L.mutex)", overridedModuleFieldName) + beginControlFlow("return syncIfAvailable(%L.mutex)", itemHolderCodeHelper.fieldName) addStatement( "%L.get()?.%L( __action, %L ) ", overridedModuleFieldName, diff --git a/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/__hidden__/coroutines/CoroutinesExt.kt b/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/__hidden__/coroutines/CoroutinesExt.kt index 6129af69..6a0c067d 100644 --- a/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/__hidden__/coroutines/CoroutinesExt.kt +++ b/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/__hidden__/coroutines/CoroutinesExt.kt @@ -1,9 +1,9 @@ package com.github.klee0kai.stone.__hidden__.coroutines -import com.github.klee0kai.stone.mutex.ReentrantMutex +import kotlinx.coroutines.sync.Mutex expect fun T.syncIfAvailable( - mutex: ReentrantMutex, + mutex: Mutex, block: T.() -> R ): R diff --git a/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/__hidden__/types/holders/MapItemHolder.kt b/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/__hidden__/types/holders/MapItemHolder.kt index 34c65a35..075b3fc9 100644 --- a/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/__hidden__/types/holders/MapItemHolder.kt +++ b/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/__hidden__/types/holders/MapItemHolder.kt @@ -7,13 +7,15 @@ import com.github.klee0kai.stone.weakref.Ref import kotlinx.atomicfu.atomic import kotlinx.coroutines.delay import kotlinx.coroutines.launch +import kotlinx.coroutines.sync.Mutex /** * Stone Private class */ @Suppress("UNCHECKED_CAST") class MapItemHolder( - private val defType: StoneRefType + private val defType: StoneRefType, + val mutex: Mutex = Mutex(), ) { private var curRefType: StoneRefType = defType diff --git a/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/__hidden__/types/holders/SingleItemHolder.kt b/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/__hidden__/types/holders/SingleItemHolder.kt index 94cc22d6..2df577d4 100644 --- a/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/__hidden__/types/holders/SingleItemHolder.kt +++ b/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/__hidden__/types/holders/SingleItemHolder.kt @@ -3,11 +3,11 @@ package com.github.klee0kai.stone.__hidden__.types.holders import com.github.klee0kai.stone.__hidden__.StoneScope import com.github.klee0kai.stone.__hidden__.SwitchCacheParam import com.github.klee0kai.stone.annotations.component.SwitchCache -import com.github.klee0kai.stone.mutex.ReentrantMutex import com.github.klee0kai.stone.weakref.Ref import kotlinx.atomicfu.atomic import kotlinx.coroutines.delay import kotlinx.coroutines.launch +import kotlinx.coroutines.sync.Mutex /** * Stone Private class @@ -15,7 +15,7 @@ import kotlinx.coroutines.launch @Suppress("UNCHECKED_CAST") class SingleItemHolder( private val defType: StoneRefType, - val mutex: ReentrantMutex = ReentrantMutex(), + val mutex: Mutex = Mutex(), ) { private var curRefType: StoneRefType = defType diff --git a/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/mutex/ReentrantMutex.kt b/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/mutex/ReentrantMutex.kt deleted file mode 100644 index ab96dc25..00000000 --- a/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/mutex/ReentrantMutex.kt +++ /dev/null @@ -1,51 +0,0 @@ -@file:OptIn(ExperimentalTime::class) - -package com.github.klee0kai.stone.mutex - -import kotlinx.atomicfu.atomic -import kotlinx.coroutines.Job -import kotlinx.coroutines.currentCoroutineContext -import kotlinx.coroutines.sync.Mutex -import kotlin.time.ExperimentalTime - -class ReentrantMutex { - - private val mutex = Mutex() - private val owner = atomic(null) - private var count = 0 - - suspend fun lock() { - val current = coroutineId() - if (owner.value == current) { - count++ - return - } - mutex.lock() - owner.value = current - count = 1 - } - - suspend fun unlock() { - val current = coroutineId() - require(owner.value == current) { "Unlock from non-owner!" } - count-- - if (count == 0) { - owner.value = null - mutex.unlock() - } - } - - suspend fun withLock(action: suspend () -> T): T { - lock() - return try { - action() - } finally { - unlock() - } - } -} - -internal typealias CoroutineId = Long - -internal suspend fun coroutineId( -): CoroutineId = currentCoroutineContext()[Job]?.hashCode()?.toLong() ?: error("No Job in context") diff --git a/stone_multiplatform/src/jvmMain/kotlin/com/github/klee0kai/stone/__hidden__/coroutines/CoroutinesExt.jvm.kt b/stone_multiplatform/src/jvmMain/kotlin/com/github/klee0kai/stone/__hidden__/coroutines/CoroutinesExt.jvm.kt index 515af18c..c9b841e6 100644 --- a/stone_multiplatform/src/jvmMain/kotlin/com/github/klee0kai/stone/__hidden__/coroutines/CoroutinesExt.jvm.kt +++ b/stone_multiplatform/src/jvmMain/kotlin/com/github/klee0kai/stone/__hidden__/coroutines/CoroutinesExt.jvm.kt @@ -1,10 +1,11 @@ package com.github.klee0kai.stone.__hidden__.coroutines -import com.github.klee0kai.stone.mutex.ReentrantMutex import kotlinx.coroutines.runBlocking +import kotlinx.coroutines.sync.Mutex +import kotlinx.coroutines.sync.withLock actual fun T.syncIfAvailable( - mutex: ReentrantMutex, + mutex: Mutex, block: T.() -> R, ): R = runBlocking { mutex.withLock { diff --git a/stone_multiplatform/src/nativeMain/kotlin/com/github/klee0kai/stone/__hidden__/coroutines/CoroutinesExt.native.kt b/stone_multiplatform/src/nativeMain/kotlin/com/github/klee0kai/stone/__hidden__/coroutines/CoroutinesExt.native.kt index 89f4491e..653283db 100644 --- a/stone_multiplatform/src/nativeMain/kotlin/com/github/klee0kai/stone/__hidden__/coroutines/CoroutinesExt.native.kt +++ b/stone_multiplatform/src/nativeMain/kotlin/com/github/klee0kai/stone/__hidden__/coroutines/CoroutinesExt.native.kt @@ -1,9 +1,9 @@ package com.github.klee0kai.stone.__hidden__.coroutines -import com.github.klee0kai.stone.mutex.ReentrantMutex +import kotlinx.coroutines.sync.Mutex actual fun T.syncIfAvailable( - mutex: ReentrantMutex, + mutex: Mutex, block: T.() -> R ): R = block() diff --git a/stone_multiplatform/src/webMain/kotlin/com/github/klee0kai/stone/__hidden__/coroutines/CoroutinesExt.web.kt b/stone_multiplatform/src/webMain/kotlin/com/github/klee0kai/stone/__hidden__/coroutines/CoroutinesExt.web.kt index c3c9932c..4a4df1b0 100644 --- a/stone_multiplatform/src/webMain/kotlin/com/github/klee0kai/stone/__hidden__/coroutines/CoroutinesExt.web.kt +++ b/stone_multiplatform/src/webMain/kotlin/com/github/klee0kai/stone/__hidden__/coroutines/CoroutinesExt.web.kt @@ -1,8 +1,8 @@ package com.github.klee0kai.stone.__hidden__.coroutines -import com.github.klee0kai.stone.mutex.ReentrantMutex +import kotlinx.coroutines.sync.Mutex actual fun T.syncIfAvailable( - mutex: ReentrantMutex, + mutex: Mutex, block: T.() -> R, ): R = block() From c354f129528a703ccd5cc2ba2d3ce980f7bc7d56 Mon Sep 17 00:00:00 2001 From: klee0kai Date: Mon, 2 Mar 2026 09:05:38 +0100 Subject: [PATCH 121/122] correct kspCommonMainKotlinMetadata dependencies --- tests/build.gradle.kts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/tests/build.gradle.kts b/tests/build.gradle.kts index 8ac9c4bc..102c6aa5 100644 --- a/tests/build.gradle.kts +++ b/tests/build.gradle.kts @@ -40,8 +40,12 @@ kotlin { } } -dependencies { - add("kspCommonMainMetadata", project(":stone_ksp")) +// Trigger Common Metadata Generation from Native tasks +tasks.matching { it.name.startsWith("ksp") && it.name != "kspCommonMainKotlinMetadata" }.configureEach { + dependsOn("kspCommonMainKotlinMetadata") +} +dependencies { + kspCommonMainMetadata(project(":stone_ksp")) } From a4717ede0de8210324af0ed975241cac12d6a8be Mon Sep 17 00:00:00 2001 From: klee0kai Date: Mon, 2 Mar 2026 10:25:05 +0100 Subject: [PATCH 122/122] bump version 2.0.2_alpha --- libs.versions.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs.versions.toml b/libs.versions.toml index b7da0deb..155ce337 100644 --- a/libs.versions.toml +++ b/libs.versions.toml @@ -1,6 +1,6 @@ [versions] -stone = "2.0.0_alpha" +stone = "2.0.2_alpha" kotlin = "2.2.21" ksp = "2.3.2"