diff --git a/.github/workflows/deploy_dev.yml b/.github/workflows/deploy_dev.yml index f27c5de9..02bdb867 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 @@ -25,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 }} @@ -34,47 +32,36 @@ 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@v3 + 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@v3 - 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@v3 + 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 ab8cee27..86ad7d5b 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 }} @@ -30,47 +28,36 @@ 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@v3 + 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@v3 - 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@v3 + 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_release.yml b/.github/workflows/deploy_release.yml index 1971eb2b..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: | @@ -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 @@ -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: | diff --git a/.gitignore b/.gitignore index 835e8dca..306705a1 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ .gradle .idea -build \ No newline at end of file +build +.kotlin +kotlin-js-store \ No newline at end of file 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/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 481bb434..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. -# -# 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 b/build.gradle deleted file mode 100644 index 77949b39..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..bd73b8bf --- /dev/null +++ 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/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/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 41dfb879..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-7.4-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-9.1.0-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/inject_multiplatform/build.gradle.kts b/inject_multiplatform/build.gradle.kts new file mode 100644 index 00000000..3bc13cd6 --- /dev/null +++ b/inject_multiplatform/build.gradle.kts @@ -0,0 +1,78 @@ +plugins { + alias(libs.plugins.kotlin.multiplatform) + alias(libs.plugins.publish.stone) + alias(libs.plugins.publish.maven) +} + +group = "com.github.klee0kai.stone" +version = libs.versions.stone.get() + +kotlin { + jvm() + js(IR) { + browser() + nodejs() + } + + linuxX64() + mingwX64() + wasmJs { + browser() + nodejs() + } + + 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) + } + } +} + +publishing { + publications.withType().configureEach { + pom { + name.set("Stone") + description.set("Library DI designed on weak references.") + } + } +} + diff --git a/inject_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/Inject.kt b/inject_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/Inject.kt new file mode 100644 index 00000000..459a95ab --- /dev/null +++ b/inject_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/Inject.kt @@ -0,0 +1,11 @@ +package com.github.klee0kai.stone + +/** + * 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. + */ +annotation class Inject \ No newline at end of file diff --git a/inject_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/Named.kt b/inject_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/Named.kt new file mode 100644 index 00000000..730404c4 --- /dev/null +++ b/inject_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/Named.kt @@ -0,0 +1,23 @@ +package com.github.klee0kai.stone + + +/** + * String-based [Qualifier]. + * + * Example usage: + * + * ``` + * class Car { + * @Inject + * @Named("driver") + * var driverSeat : DriverSeat + * + * @Inject + * @Named("passenger") + * var passengerSeat: Seat + * } + * ``` + */ +annotation class Named( + val value: String +) \ No newline at end of file diff --git a/inject_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/Provider.kt b/inject_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/Provider.kt new file mode 100644 index 00000000..71eb948d --- /dev/null +++ b/inject_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/Provider.kt @@ -0,0 +1,10 @@ +package com.github.klee0kai.stone + +/** + * Provides instances of [T]. Typically implemented by an injector. For + * any type [T] that can be injected, you can also inject + * `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/Qualifier.kt b/inject_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/Qualifier.kt new file mode 100644 index 00000000..2667f044 --- /dev/null +++ b/inject_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/Qualifier.kt @@ -0,0 +1,32 @@ +package com.github.klee0kai.stone + +/** + * 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] + */ +annotation class Qualifier \ No newline at end of file diff --git a/inject_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/Scope.kt b/inject_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/Scope.kt new file mode 100644 index 00000000..097c44c6 --- /dev/null +++ b/inject_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/Scope.kt @@ -0,0 +1,14 @@ +package com.github.klee0kai.stone + +/** + * 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. + */ +annotation class Scope \ No newline at end of file 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/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 diff --git a/kotlin_lib/build.gradle b/kotlin_lib/build.gradle deleted file mode 100644 index 917356d0..00000000 --- a/kotlin_lib/build.gradle +++ /dev/null @@ -1,34 +0,0 @@ -plugins { - id "org.jetbrains.kotlin.jvm" version '1.7.0' - id "org.jetbrains.kotlin.kapt" version "1.7.21" -} - -apply from: '../jitpack.gradle' - -java { - withSourcesJar() - withJavadocJar() -} - -publishing { - publications { - maven(MavenPublication) { - from components.java - } - } -} - -compileKotlin { - kotlinOptions.jvmTarget = JavaVersion.VERSION_11 -} - -compileTestKotlin { - kotlinOptions.jvmTarget = JavaVersion.VERSION_11 -} - - -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 new file mode 100644 index 00000000..155ce337 --- /dev/null +++ b/libs.versions.toml @@ -0,0 +1,61 @@ +[versions] + +stone = "2.0.2_alpha" + +kotlin = "2.2.21" +ksp = "2.3.2" +agp = "8.12.3" + +javax-inject = "1" +kotlinx-coroutines = "1.10.1" +jetbrain-immutable = "0.3.7" +jetbrain-coroutines = "1.10.1" +kotlinx-atomicfu = "0.29.0" + +kotlinpoet = "2.0.0" + +junit = "6.0.0" +junit-launcher = "6.0.0" +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" } + +# 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" } + +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" } + +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" } + +testing-kapt-compile = { group = "com.google.testing.compile", name = "compile-testing", version.ref = "testing-compile" } + +[bundles] + +junit = ["jupiter-api", "jupiter-engine", "jupiter-launcher"] +kotlinpoet = ["kotlinpoet", "kotlinpoet-ksp"] +kotlin = ["jetbrain-coroutines", "jetbrain-immutable"] + +[plugins] + +kotlin-ksp = { id = "com.google.devtools.ksp", version.ref = "ksp" } +kotlin-jvm = { id = "org.jetbrains.kotlin.jvm", version.ref = "kotlin" } +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/android_lib/.gitignore b/plugin_publish/.gitignore similarity index 100% rename from android_lib/.gitignore rename to plugin_publish/.gitignore 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..6834955b --- /dev/null +++ b/plugin_publish/src/main/kotlin/com/github/klee0kai/stone/publish/MavenPublishExt.kt @@ -0,0 +1,30 @@ +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.withType + + +fun PublishingExtension.stoneToMaven(project: Project) { + publications.withType().configureEach { + version = project.version.toString() + + 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") + } + } + } + } +} \ 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/readme.md b/readme.md index f1c83d5e..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_lib:1.0.7") - kapt("com.github.klee0kai.stone:stone_processor:1.0.7") + implementation("com.github.klee0kai.stone:stone_multiplatform:2.0.0_alpha") + ksp("com.github.klee0kai.stone:stone_ksp:2.0.0_alpha") } ``` @@ -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 ``` 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..97fc81db --- /dev/null +++ b/settings.gradle.kts @@ -0,0 +1,43 @@ +pluginManagement { + repositories { + gradlePluginPortal() + google() + mavenCentral() + } +} + +dependencyResolutionManagement { + repositories { + google() + mavenCentral() + } + versionCatalogs { + create("libs") { + from(files("libs.versions.toml")) + } + } +} + +rootProject.name = "Stone" +includeBuild("plugin_publish") +include("weakref_multiplatform") +include("inject_multiplatform") +include(":stone_multiplatform") + +include(":wiki_kotlin") +include(":tests") +include(":tests_ext") +include(":tests_kotlin") +include(":tests_wraps_kotlin") +// 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") +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/stone_ksp/build.gradle.kts b/stone_ksp/build.gradle.kts new file mode 100644 index 00000000..446e4085 --- /dev/null +++ b/stone_ksp/build.gradle.kts @@ -0,0 +1,35 @@ +plugins { + alias(libs.plugins.kotlin.multiplatform) + alias(libs.plugins.publish.stone) + alias(libs.plugins.publish.maven) +} + +group = "com.github.klee0kai.stone" +version = libs.versions.stone.get() + + +kotlin { + jvm() + + sourceSets { + val commonMain by getting { + dependencies { + implementation(project(":stone_multiplatform")) + implementation(libs.bundles.kotlin) + implementation(libs.bundles.kotlinpoet) + implementation(libs.ksp) + implementation(libs.kotlin.compiler) + } + } + } +} + +publishing { + publications.withType().configureEach { + pom { + name.set("Stone") + description.set("Library DI designed on weak references.") + } + } +} + 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..437f47dd --- /dev/null +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/Processor.kt @@ -0,0 +1,190 @@ +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 +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.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.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 +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" + + 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.car.di.cachecontrol.gc" + } + + + val dispatcher by lazy { if (multithread) Dispatchers.Default else Dispatchers.Unconfined } + val targetProcessors = arrayOf( + GenProviderProcessor(), + GenModuleFactoryProcessor(), + GenModuleCacheControlProcessor(), + GenModuleProcessor(), + GenHiddenModuleProcessor(), + GenHiddenModuleCacheControlProcessor(), + GenWrappersSupportProcessor(), + GenComponentProcessor(), + ) + + override fun process( + resolver: Resolver + ): List = runBlocking(dispatcher) { + + 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) } + + if (debug && debugPkgFilter != null) { + symbols = symbols + .filter { + it.containingFile?.packageName + ?.asString()?.startsWith(debugPkgFilter!!) ?: true + } + } + + var takeSymbolsCount = 0 + processSymbolsCounter.updateAndGet { totalCount -> + takeSymbolsCount = min( + symbols.symbolsForProcessing.size, + oneRunSymbolsCount - totalCount + ) + + 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 } + + + globalSymbolsForReprocessing.addAll(symbols.symbolsForReprocessing) + + try { + genSpecs.addAll( + symbols.symbolsForProcessing + .mapNotNull { targetSymbol -> + wrapKsNoteInfo(targetSymbol) { + processor.process( + validSymbol = targetSymbol, + resolver = resolver, + options = options, + logger = logger, + ) + } + } + ) + } catch (e: StoneException) { + logger.error( + message = e.message ?: "", + symbol = e.findLastErrorElement(), + ) + throw e + } + + } + } + } + + // 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() + + 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() + } + + 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/StoneProcessorProvider.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/StoneProcessorProvider.kt new file mode 100644 index 00000000..8271c8bf --- /dev/null +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/StoneProcessorProvider.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 StoneProcessorProvider : 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/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/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..968460ea --- /dev/null +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/exceptions/StoneException.kt @@ -0,0 +1,24 @@ +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( + message: String? = null, + cause: Throwable? = null, + val element: KSNode? = null, +) : IllegalStateException(message, cause) { + + fun findLastErrorElement(): KSNode? { + var sourceElement: KSNode? = null + if (cause is StoneException) { + sourceElement = (cause as StoneException).findLastErrorElement() + } + 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 new file mode 100644 index 00000000..9c69bc76 --- /dev/null +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/exceptions/WrapExt.kt @@ -0,0 +1,40 @@ +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?, + block: T.() -> R, +): R { + return try { + block() + } catch (e: Throwable) { + throw StoneException( + message = "${e.message}. At ${ksNode?.location} ", + element = ksNode, + cause = e, + ) + } +} + +fun Sequence.forEachFun( + action: (index: Int, KSFunctionDeclaration) -> Unit +) { + forEachIndexed { idx, func -> + wrapKsNoteInfo(func) { + 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 new file mode 100644 index 00000000..8897ceb7 --- /dev/null +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/ComponentDeclarationExt.kt @@ -0,0 +1,105 @@ +@file:OptIn(KspExperimental::class) + +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.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 +import com.github.klee0kai.thekey.stone.ksp.ksp.isType +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.* +import com.squareup.kotlinpoet.ClassName +import com.squareup.kotlinpoet.asClassName +import com.github.klee0kai.stone.Scope as StoneScope + +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.allParentDeclarations: Sequence + get() = (sequenceOf(this) + + superTypes.mapNotNull { it.resolveNotNullable().declaration as? KSClassDeclaration }) + +val KSClassDeclaration.allIdentifierTypes: Sequence + get() = allParentDeclarations + .flatMap { it.findComponentAnnotation() } + .flatMap { it.identifiers } + +fun List.identifierParameters( + allIdentifierTypes: List, +) = filter { it.type.resolveNotNullable() in allIdentifierTypes } + +fun List.notIdentifierParameters( + allIdentifierTypes: List, +) = filter { it.type.resolveNotNullable() !in allIdentifierTypes } + +fun List.lifeCycleParameter() = firstOrNull { + (it.type.resolveNotNullable().declaration as? KSClassDeclaration) + ?.isChildOf(StoneLifeCycleOwner::class.asClassName()) == true +} + + +val KSClassDeclaration.wrapperProviders: Sequence + get() { + val componentCl = this@wrapperProviders + val allParentsSequence = (sequenceOf(componentCl) + superTypes) + return allParentsSequence + .flatMap { it.findComponentAnnotation() } + .flatMap { it.wrapperProviders } + } + +val KSAnnotated.scopeAnnotations: Sequence + get() { + val standardScopeAnnotations = listOf( + GcAllScope::class, GcWeakScope::class, + GcSoftScope::class, GcStrongScope::class + ) + + return annotations.filter { funAnnotation -> + standardScopeAnnotations.any { funAnnotation.annotationType.resolveNotNullable().declaration.isType(it) } + || funAnnotation.annotationType.resolveNotNullable().declaration.annotations.any { annotationOfAnnotation -> + annotationOfAnnotation.annotationType.resolveNotNullable().declaration.isAnyType( + GcScopeAnnotation::class, + StoneScope::class, + javax.inject.Scope::class + ) + } + } + } + +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.isAnyType( + Qualifier::class, + javax.inject.Qualifier::class + ) + } + } + } + + + 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..8fabad5e --- /dev/null +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/StoneFileNamesExt.kt @@ -0,0 +1,58 @@ +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" + +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 KSFunctionDeclaration.cacheControlMethodName get() = simpleName.asString().cacheControlMethodName +val String.cacheControlMethodName get() = "__" + this + "_cache" + +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 ClassName.cacheControlStoneClName + get() = ClassName( + packageName, + simpleName.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/TypeHelpersExt.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/TypeHelpersExt.kt new file mode 100644 index 00000000..eeaf8493 --- /dev/null +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/TypeHelpersExt.kt @@ -0,0 +1,24 @@ +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 +} 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..c5d9920c --- /dev/null +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/annotations/ComponentAnnMirror.kt @@ -0,0 +1,99 @@ +package com.github.klee0kai.thekey.stone.ksp.helpers.annotations + +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.WrappersHelper +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.toTypeName + +class ComponentAnnMirror( + val identifiers: List, + val wrapperProviders: List, + val wrapperHelpers: List, +) + +fun KSAnnotated.annotations( + className: ClassName, +): Sequence = annotations + .filter { it.annotationType.resolve().toTypeName() == className } + + +fun KSAnnotated.anyAnnotation( + vararg classNames: ClassName, +): Sequence = annotations + .filter { it.annotationType.resolve().toTypeName() in classNames } + + +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(), + RunGc::class.asClassName(), + SwitchCache::class.asClassName(), + Init::class.asClassName(), + BindInstance::class.asClassName(), + Provide::class.asClassName(), + + ) + + +fun KSAnnotated.hasOnlyAnnotation( + className: ClassName, +): Boolean { + if (annotations.count() != 1) return false + 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 + .filter { it.annotationType.resolve().toTypeName() == className } + + +@Suppress("UNCHECKED_CAST") +fun KSAnnotated.findComponentAnnotation( +): Sequence = annotations + .filter { it.annotationType.resolve().toTypeName() == 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() + + 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/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..0147daeb --- /dev/null +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/invokecall/InvokeCall.kt @@ -0,0 +1,240 @@ +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.poet.codeBlock +import com.github.klee0kai.thekey.stone.ksp.utils.LocalFieldName +import com.squareup.kotlinpoet.CodeBlock +import com.squareup.kotlinpoet.ParameterizedTypeName.Companion.parameterizedBy +import com.squareup.kotlinpoet.TypeName +import com.squareup.kotlinpoet.asClassName +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( + var wrapHelper: WrapHelper, + val invokeSequenceVariants: List>, + val qualifierAnnotations: Set, + val flags: InvokeProvideFlags = InvokeProvideFlags(), +) { + + companion object; + + fun bestSequence(): List = invokeSequenceVariants[0] + + /** + * 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.args.map { arg -> + ProvideDep( + methodName = null, + typeName = wrapHelper.listWrapTypeIfNeed(arg.type), + qualifierAnns = arg.qualifierAnns.toSet(), + ) + }) + } + } + return argsTypes + } + + /** + * Providing type in this invoke sequence + * + * @return return type + */ + fun resultType(): TypeName = wrapHelper.nonWrappedType(rawReturnType()) + + fun rawReturnType(): TypeName { + val invokeSequence = bestSequence() + return invokeSequence[invokeSequence.size - 1].returnType + } + + fun best() = InvokeCall.fromSequence( + wrapHelper, + callSequence = bestSequence(), + qualifierAnnotations = qualifierAnnotations, + ) + + /** + * 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, + argGen: (FieldDetail) -> CodeBlock? = { null }, + ): CodeBlock { + val argGens = LinkedList<(FieldDetail) -> CodeBlock?>() + argGens.add(unwrapArgument(envFields)) + argGens.add(argGen) + + val invokeBuilder = CodeBlock.builder() + var invokeCount = 0 + for (m in bestSequence()) { + var argCount = 0 + val argsCodeBuilder = CodeBlock.builder() + for (arg in m.args) { + if (argCount++ > 0) argsCodeBuilder.add(",") + val argCode = argGens.firstNotNullOfOrNull { it.invoke(arg) } + argsCodeBuilder.add(argCode ?: CodeBlock.of("null")) + } + + if (invokeCount++ > 0) invokeBuilder.add(".") + if (m.isProperty) { + invokeBuilder.add("%L", m.methodName) + } else { + invokeBuilder.add("%L(%L)", m.methodName, argsCodeBuilder.build()) + } + } + + return invokeBuilder.build() + } + + fun invokeAllToList( + declaredFields: List, + ): CodeBlock = codeBlock { + val provType = List::class.asClassName().parameterizedBy(resultType()) + val listFieldName: String = LocalFieldName.genLocalFieldName() + add( + "%T{ %L -> \n", + ProvideBuilder::class.asClassName().parameterizedBy(resultType()), + listFieldName, + ) + for (sequence in invokeSequenceVariants) { + val invokeCall = InvokeCall.fromSequence(wrapHelper, sequence, qualifierAnnotations = qualifierAnnotations) + val seqCodeBlock = invokeCall.invokeCode(declaredFields) + + if (wrapHelper.isList(invokeCall.rawReturnType())) { + add( + "%L.addAll( %L ?: emptyList() );\n", + listFieldName, + wrapHelper.transform( + invokeCall.rawReturnType(), + provType.copy(nullable = true), + seqCodeBlock + ) + ) + } else { + add( + "%L.add( %L );\n", + listFieldName, + wrapHelper.transform( + invokeCall.rawReturnType(), + resultType().copy(nullable = true), + seqCodeBlock + ) + ) + } + } + + add(" }.all();\n") + } + + + 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.lastOrNull { f -> + wrapHelper.isList(f.type) && (arg.qualifierAnns == f.qualifierAnns) + } else null + + if (field == null) { + //non list + field = typeFields.firstOrNull { f -> + (arg.qualifierAnns == f.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) { + 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.methodName) + .append("(") + .append(m.args.joinToString(", ") { it.type.toString() }) + .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) + } +} + + +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) }, + qualifierAnnotations = qualifierAnnotations, +) \ No newline at end of file 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..fc3e3dd4 --- /dev/null +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/invokecall/ModulesGraph.kt @@ -0,0 +1,444 @@ +@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.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 +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.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 +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.KSClassDeclaration +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.toTypeName +import java.util.* + +class ModulesGraph( + val wrapHelper: WrapHelper, + val identifierTypes: List, +) { + + private val provideTypeCodes = HashMap>() + private val cacheControlTypeCodes = HashMap>() + + + fun collectFromComponent( + componentCl: KSClassDeclaration, + ) { + val componentsAllMethods = componentCl + .getAllMethods(includeObjectMethods = false, allowDoubles = false, "") + val hiddenModuleProvideMethod = MethodDetail( + methodName = GenComponentProcessor.hiddenModuleFieldName, + returnType = componentCl.hiddenModuleStoneClName, + isProperty = true, + ) + + componentsAllMethods + .filter { it.isModuleProvideMethod || it.isDepsProvideMethod } + .forEachFun { _, moduleProvideMethod -> + + val module = moduleProvideMethod.returnType?.resolveNotNullable() + ?.declaration as? KSClassDeclaration ?: return@forEachFun + + for (m in module.getAllMethods(includeObjectMethods = false, allowDoubles = true, "")) { + if (m.returnType?.resolveNotNullable()?.isNotPrimitive == false) continue + + val returnType = m.returnType?.resolveNotNullable()?.toTypeName() ?: continue + val provTypeName = wrapHelper.nonWrappedType(returnType) + val isCached = m.getAnnotationsByType(Provide::class) + .firstOrNull()?.cacheProtected !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(moduleProvideMethod.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[provTypeName]?.add( + InvokeCall.fromSequence( + wrapHelper = wrapHelper, + 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()?.cacheProtected !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(hiddenModuleProvideMethod, cacheControlMethod) + ) + ) + } + } + + + 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.isNullOrEmpty()) 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() + val localVariables = LinkedList(declaredFields) + + val codeBlock = CodeBlock.builder() + codeBlock.add("%T{ %L -> \n", provideBuilder, listFieldName) + + for (inv in provideTypeInvokes) { + 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 + ) + val listDepField = FieldDetail( + name = genLocalFieldName(), + type = Ref::class.asClassName().parameterizedBy( + List::class.asClassName().parameterizedBy( + inv.resultType() + ) + ), + 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( + 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("// 2 ${inv.qualifierAnnotations.joinToString(",") { it.logString() }} \n") + codeBlock.add("val %L = %T{ ", singleDepField.name, Ref::class) + .add( + wrapHelper.transform( + inv.best().rawReturnType(), + inv.resultType(), + inv.best().invokeCode(localVariables), + ) + ) + .addStatement(" } ") + + localVariables.add(singleDepField) + } + } + + 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(" } ") + + localVariables.add(listDepField) + } + + + if (inv.resultType().copy(nullable = false) == providingType.copy(nullable = false)) { + if (wrapHelper.isList(returnType)) { + codeBlock.add( + "%L.addAll( %L ?: emptyList() )\n", + listFieldName, + wrapHelper.transform( + listDepField.type, + provideBuilderList.copy(nullable = true), + CodeBlock.of(listDepField.name) + ) + ) + } else { + codeBlock.add( + "%L.add( %L )\n", + listFieldName, + wrapHelper.transform( + singleDepField.type, + providingType.copy(nullable = true), + CodeBlock.of(singleDepField.name) + ) + ) + } + if (!wrapHelper.isList(returnType)) break + } + } + + codeBlock.add(" }") + if (wrapHelper.isList(returnType)) { + codeBlock.add(".all() ") + + return wrapHelper.transform( + List::class.asClassName().parameterizedBy(providingType), + returnType, + codeBlock.build() + ) + + } else { + codeBlock.add(if (providingType.isNullable) ".firstOrNull()" else ".first() ") + + return wrapHelper.transform( + providingType, + returnType, + codeBlock.build() + ) + } + } + + + 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.toTypeName() == 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) + } + + 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 == it2.qualifierAnnotations + } + ) + provideTypeInvokes.reverse() + 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? = provideTypeInvokeCall( + cacheControlTypeCodes, + typeName, + qualifierAnns, + provideMethodName?.cacheControlMethodName, + false + ) + + + private fun provideTypeInvokeCall( + provideTypeCodes: Map>, + typeName: TypeName, + qualifierAnns: Set, + provideMethodName: String?, + listVariants: Boolean, + ): InvokeCall? { + val invokeCalls = provideTypeCodes.getOrDefault(typeName, null) + if (invokeCalls == null || invokeCalls.isEmpty()) return null + + var filtered = invokeCalls.toList() + if (qualifierAnns.none { it.typeName == IgnoreQualifier::class.asClassName() }) { + filtered = invokeCalls.filter { it.qualifierAnnotations == qualifierAnns } + } + + 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.fromVariants( + wrapHelper, + variants = filtered.toList(), + qualifierAnnotations = qualifierAnns, + ) + } else { + null + } + } + + companion object { + 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 new file mode 100644 index 00000000..c23719eb --- /dev/null +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/invokecall/ProvideDep.kt @@ -0,0 +1,13 @@ +package com.github.klee0kai.thekey.stone.ksp.helpers.invokecall + +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, +) { + 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 new file mode 100644 index 00000000..f424f7f0 --- /dev/null +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/invokecall/model/FieldDetail.kt @@ -0,0 +1,24 @@ +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.resolveNotNullable +import com.google.devtools.ksp.symbol.KSValueParameter +import com.squareup.kotlinpoet.TypeName +import com.squareup.kotlinpoet.ksp.toTypeName + +data class FieldDetail( + val name: String, + val type: TypeName, + val qualifierAnns: Set = emptySet(), +) { + companion object; +} + +fun FieldDetail.Companion.simple(name: String, type: TypeName) = FieldDetail(name, type) + +fun KSValueParameter.toFieldDetail() = FieldDetail( + name = name?.asString() ?: "it", + 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/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..7a66e1ef --- /dev/null +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/invokecall/model/MethodDetail.kt @@ -0,0 +1,25 @@ +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.KSFunctionDeclaration +import com.squareup.kotlinpoet.TypeName +import com.squareup.kotlinpoet.asClassName +import com.squareup.kotlinpoet.ksp.toTypeName + +data class MethodDetail( + val methodName: String, + val returnType: TypeName, + val args: List = emptyList(), + val qualifierAnns: Set = emptySet(), + val isProperty: Boolean = false, +) { + companion object; +} + +fun KSFunctionDeclaration.toMethodDetail() = MethodDetail( + methodName = simpleName.asString(), + returnType = returnType?.resolve()?.toTypeName() ?: Unit::class.asClassName(), + args = parameters.map { it.toFieldDetail() }, + 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..1ecd8d77 --- /dev/null +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/invokecall/model/QualifierAnn.kt @@ -0,0 +1,35 @@ +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 +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.resolveAlias().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/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..9e63fb5b --- /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 com.squareup.kotlinpoet.asClassName + +enum class ItemCacheType { + Strong, Soft, Weak; + + val gcScopeClassName + get() = when (this) { + Weak -> GcWeakScope::class + Strong -> GcStrongScope::class + Soft -> GcSoftScope::class + }.asClassName() +} + +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 -> 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/ItemHolderCodeHelper.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/itemholder/ItemHolderCodeHelper.kt new file mode 100644 index 00000000..b7458c1c --- /dev/null +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/itemholder/ItemHolderCodeHelper.kt @@ -0,0 +1,69 @@ +package com.github.klee0kai.thekey.stone.ksp.helpers.itemholder + +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 { + companion object; + + val fieldName: String + + fun TypeSpec.Builder.genCacheField() + + fun codeGetCachedValue(): CodeBlock + + fun codeSetCachedValue( + value: CodeBlock, + onlyIfNull: Boolean, + ): CodeBlock + + fun statementSwitchRef( + paramsCode: CodeBlock, + ): CodeBlock + + fun clearNullsStatement(): CodeBlock + +} + +fun ItemHolderCodeHelper.Companion.of( + fieldName: String, + returnType: TypeName, + idArguments: List, + cacheType: ItemCacheType, + wrapHelper: WrapHelper, +): ItemHolderCodeHelper { + + return when { + idArguments.isEmpty() -> SingleItemHolderCodeHelper( + fieldName = fieldName, + returnType = returnType, + nonWrappedReturnType = wrapHelper.nonWrappedType(returnType), + itemCacheType = cacheType, + isListCaching = wrapHelper.isList(returnType), + defRefType = if (wrapHelper.isList(returnType)) cacheType.toRefTypeList() else cacheType.toRefTypeSingle(), + ) + + idArguments.size == 1 -> SimpleMapItemHolderCodeHelper( + fieldName = fieldName, + returnType = returnType, + nonWrappedReturnType = wrapHelper.nonWrappedType(returnType), + itemCacheType = cacheType, + isListCaching = wrapHelper.isList(returnType), + defRefType = if (wrapHelper.isList(returnType)) cacheType.toRefTypeList() else cacheType.toRefTypeSingle(), + keyParam = idArguments.first(), + ) + + else -> MultiKeyMapItemHolderCodeHelper( + fieldName = fieldName, + returnType = returnType, + nonWrappedReturnType = wrapHelper.nonWrappedType(returnType), + itemCacheType = cacheType, + 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 new file mode 100644 index 00000000..de5d189c --- /dev/null +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/itemholder/MultiKeyMapItemHolderCodeHelper.kt @@ -0,0 +1,72 @@ +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.google.devtools.ksp.symbol.KSValueParameter +import com.squareup.kotlinpoet.* +import com.squareup.kotlinpoet.ParameterizedTypeName.Companion.parameterizedBy + +class MultiKeyMapItemHolderCodeHelper( + override val fieldName: String, + val returnType: TypeName, + val nonWrappedReturnType: TypeName, + val itemCacheType: ItemCacheType, + val isListCaching: Boolean, + val defRefType: StoneRefType, + val keyArguments: List, +) : ItemHolderCodeHelper { + + override fun TypeSpec.Builder.genCacheField() { + val cacheType = MapItemHolder::class.asClassName() + .parameterizedBy( + MultiKey::class.asClassName(), + nonWrappedReturnType, + ) + + genProperty(fieldName, cacheType) { + addModifiers(KModifier.PRIVATE) + initializer("%T(%T.%L)", cacheType, StoneRefType::class, defRefType) + } + } + + + override fun codeGetCachedValue( + ) = codeBlock { + val getMethod = if (isListCaching) "getList" else "get" + add( + "%L.%L(key = %T(%L))", + fieldName, getMethod, + MultiKey::class.asClassName(), keyArguments.joinToString(",") { it.name!!.asString() }, + ) + } + + override fun codeSetCachedValue( + value: CodeBlock, + onlyIfNull: Boolean + ) = codeBlock { + 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("}") + } + + 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/SimpleMapItemHolderCodeHelper.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/itemholder/SimpleMapItemHolderCodeHelper.kt new file mode 100644 index 00000000..4f35fdb6 --- /dev/null +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/itemholder/SimpleMapItemHolderCodeHelper.kt @@ -0,0 +1,68 @@ +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.google.devtools.ksp.symbol.KSValueParameter +import com.squareup.kotlinpoet.* +import com.squareup.kotlinpoet.ParameterizedTypeName.Companion.parameterizedBy +import com.squareup.kotlinpoet.ksp.toTypeName + +class SimpleMapItemHolderCodeHelper( + override val fieldName: String, + val returnType: TypeName, + val nonWrappedReturnType: TypeName, + val itemCacheType: ItemCacheType, + val isListCaching: Boolean, + val defRefType: StoneRefType, + val keyParam: KSValueParameter, +) : ItemHolderCodeHelper { + + override fun TypeSpec.Builder.genCacheField() { + val cacheType = MapItemHolder::class.asClassName() + .parameterizedBy( + keyParam.type.resolve().toTypeName(), + nonWrappedReturnType, + ) + + genProperty(fieldName, cacheType) { + addModifiers(KModifier.PRIVATE) + initializer("%T(%T.%L)", cacheType, StoneRefType::class, defRefType) + } + } + + override fun codeGetCachedValue( + ) = codeBlock { + val getMethod = if (isListCaching) "getList" else "get" + add( + "%L.%L(key = %L)", + fieldName, getMethod, keyParam.name!!.asString() + ) + } + + override fun codeSetCachedValue( + value: CodeBlock, + onlyIfNull: Boolean + ) = codeBlock { + val setMethod = if (isListCaching) "setList" else "set" + add( + "%L.%L(key = %L, onlyIfNull = %L ){ ", + fieldName, setMethod, keyParam.name!!.asString(), onlyIfNull + ) + add(value) + add("}") + } + + 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/SingleItemHolderCodeHelper.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/itemholder/SingleItemHolderCodeHelper.kt new file mode 100644 index 00000000..c142a12d --- /dev/null +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/itemholder/SingleItemHolderCodeHelper.kt @@ -0,0 +1,53 @@ +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.squareup.kotlinpoet.* +import com.squareup.kotlinpoet.ParameterizedTypeName.Companion.parameterizedBy + +class SingleItemHolderCodeHelper( + override val fieldName: String, + val returnType: TypeName, + val nonWrappedReturnType: TypeName, + val itemCacheType: ItemCacheType, + val isListCaching: Boolean, + val defRefType: StoneRefType, +) : ItemHolderCodeHelper { + + override fun TypeSpec.Builder.genCacheField() { + val cacheType = SingleItemHolder::class.asClassName() + .parameterizedBy(nonWrappedReturnType) + + genProperty(fieldName, cacheType) { + addModifiers(KModifier.PRIVATE) + initializer("%T(%T.%L)", cacheType, StoneRefType::class, defRefType) + } + } + + override fun codeGetCachedValue( + ) = codeBlock { + val getMethod = if (isListCaching) "getList" else "get" + add("%L.%L()", fieldName, getMethod) + } + + override fun codeSetCachedValue( + value: CodeBlock, + onlyIfNull: Boolean + ) = codeBlock { + val setMethod = if (isListCaching) "setList" else "set" + add("%L.%L(onlyIfNull = %L ){ ", fieldName, setMethod, onlyIfNull) + add(value) + add(" }") + } + + 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/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..3b4c874f --- /dev/null +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/wrap/ClassNameUtils.kt @@ -0,0 +1,38 @@ +package com.github.klee0kai.thekey.stone.ksp.helpers.wrap + +import com.squareup.kotlinpoet.ParameterizedTypeName +import com.squareup.kotlinpoet.TypeName +import com.squareup.kotlinpoet.WildcardTypeName + +object ClassNameUtils { + + 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.copy(nullable = false) + } + + + fun noWildCardType(type: TypeName): TypeName { + if (type is WildcardTypeName) { + val upperBounds = type.outTypes + return if (!upperBounds.isEmpty()) { + noWildCardType(upperBounds.first()) + } else { + type + } + } + return type + } + +} + + +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/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..13ee5573 --- /dev/null +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/wrap/FormatInList.kt @@ -0,0 +1,18 @@ +package com.github.klee0kai.thekey.stone.ksp.helpers.wrap + +import com.squareup.kotlinpoet.CodeBlock +import com.squareup.kotlinpoet.TypeName + +fun interface FormatInList { + + /** + * @param itemTransformFun format each type + * @return + */ + fun formatCode( + originalListType: TypeName, + or: CodeBlock, + itemTransformFun: FormatSimple, + ): 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 new file mode 100644 index 00000000..2324b215 --- /dev/null +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/wrap/FormatSimple.kt @@ -0,0 +1,52 @@ +package com.github.klee0kai.thekey.stone.ksp.helpers.wrap + +import com.squareup.kotlinpoet.CodeBlock + + +fun interface FormatSimple { + + /** + * @param code code witch return original type + * @return code witch return wanna type + */ + fun formatCode( + or: CodeBlock, + ): 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 new file mode 100644 index 00000000..5c334bfe --- /dev/null +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/helpers/wrap/WrapHelper.kt @@ -0,0 +1,380 @@ +package com.github.klee0kai.thekey.stone.ksp.helpers.wrap + +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 +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 +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 +import java.lang.ref.SoftReference +import java.lang.ref.WeakReference +import java.util.* + + +class WrapHelper { + + private var wrapTypes = HashMap() + + init { + std() + } + + fun support(wrapType: WrapType) { + wrapTypes.putIfAbsent(wrapType.typeName, wrapType) + } + + fun isSupport(typeName: TypeName): Boolean = wrapTypes.containsKey(rawTypeOf(typeName)) + + 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 + } + + fun isList(typeName: TypeName): Boolean = allParamTypes(typeName).any { + val wrapType = wrapTypes.get(rawTypeOf(it)) + wrapType != null && wrapType.isList + } + + fun paramType(typeName: TypeName): TypeName { + if (typeName is ParameterizedTypeName) { + if (isSupport(typeName.rawType) && !typeName.typeArguments.isEmpty()) { + return typeName.typeArguments.first() + } + } + 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()) { + return nonWrappedType(typeName.typeArguments.first()) + } + } + if (typeName is WildcardTypeName) { + if (!typeName.outTypes.isEmpty()) return nonWrappedType(typeName.outTypes.first()) + } + return typeName.copy(nullable = false) + } + + /** + * 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 = noWildCardType(typeName) + val allParams = LinkedList() + while (true) { + allParams.add(typeName) + val paramType = typeName as? ParameterizedTypeName + if (paramType == null || paramType.typeArguments.isEmpty()) break + typeName = noWildCardType(paramType.typeArguments[0]) + } + return allParams + } + + + fun transform( + providingType: TypeName, + wannaType: TypeName, + code: CodeBlock + ): 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() + && unwrapPathNames.last().rawType() == wrapPathNames.first().rawType() + ) { + unwrapPathNames.pollLast() + wrapPathNames.pollFirst() + } + + val wrapTypeFormat: (TypeName) -> WrapType = { it: TypeName -> + wrapTypes[it.rawType()] + ?: throw StoneException(message = "Type Transform non support $providingType -> $wannaType") + } + + 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.first() + 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 + } + } + unwrapPath.pollFirst() + unwrapPathNames.pollFirst() + + currentNullable = ( + wrapPath.firstOrNull()?.typeName?.let { paramType(it) } + ?: wannaType) + .isNullable + + codeBuilder = unwrapType.unwrap.formatCode( + or = codeBuilder.build(), + srcNullable = unwrapType.typeName.isNullable, + targetNullable = currentNullable + ).toBuilder() + } + + while (!wrapPath.isEmpty()) { + 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 (currentNullable && !wannaType.isNullable) { + codeBuilder.add("!!") + } + + return codeBuilder.build() + } + + private fun std() { + 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( + typeName = wrapper, + 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( + WeakRef::class, + SoftRef::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, + )) { + val wrapper = cl.asClassName() + val wrapType = WrapType( + typeName = wrapper, + isNoCachingWrapper = false, + wrap = { or, srcNullable, targetNullable, argTypeNullable -> + codeBlock { + when { + !srcNullable || argTypeNullable -> add("lazy{ %L } ", or) + else -> add("lazy{ %L!! } ", or) + } + } + }, + unwrap = { or, srcNullable, targetNullable -> + codeBlock { + when { + targetNullable -> add("%L?.value", or) + !srcNullable -> add("%L.value", or) + else -> add("%L!!.value", or) + } + } + }, + ) + support(wrapType) + } + + for (cl in listOf( + PhantomProvide::class, + Ref::class, + Provider::class, + javax.inject.Provider::class, + LazyProvide::class, + AsyncCoroutineProvide::class, + FantomAsyncProvide::class, + )) { + val isNoCachingWrapper = cl != LazyProvide::class && cl != AsyncCoroutineProvide::class + + val wrapper = cl.asClassName() + val wrapType = WrapType( + typeName = wrapper, + isNoCachingWrapper = isNoCachingWrapper, + wrap = { or, srcNullable, targetNullable, argTypeNullable -> + codeBlock { + when { + !srcNullable || argTypeNullable -> add("%T{ %L }", wrapper, or) + else -> add("%T{ %L!! } ", wrapper, or) + } + } + }, + unwrap = { or, srcNullable, targetNullable -> + codeBlock { + when { + targetNullable -> add("%L?.get()", or) + !srcNullable -> add("%L.get()", or) + else -> add("%L!!.get()!!", or) + } + } + }, + ) + support(wrapType) + } + + + + for (cl in listOf( + LinkedList::class, + ArrayList::class, + List::class, + Collection::class, + )) { + val wrapper = cl.asClassName() + val constructor = when (cl) { + LinkedList::class, ArrayList::class -> wrapper + else -> null + } + + val wrapType = WrapType( + typeName = wrapper, + isNoCachingWrapper = false, + wrap = { or, srcNullable, targetNullable, argTypeNullable -> + codeBlock { + when { + 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) + } + + } + }, + unwrap = { or, srcNullable, targetNullable -> + codeBlock { + when { + targetNullable -> add("%L?.firstOrNull()", or) + !srcNullable -> add("%L.first()", or) + else -> add("%L!!.first()", or) + } + } + }, + inListFormat = { originalListType, originalListCode, itemTransformFun -> + codeBlock { + val itemTransform = itemTransformFun.formatCode(CodeBlock.of("it")) + if (itemTransform.toString() == "it") { + //no transforms + add(originalListCode) + } else { + add("( %L?.map{ it -> %L } ?: emptyList() )", originalListCode, itemTransform) + } + + if (wrapper.rawType() != originalListType.rawType()) { + if (constructor != null) { + add("!!.let { %T(it) }", constructor) + } else { + add("!!.toList()") + } + } + } + }, + ) + + support(wrapType) + } + } +} \ 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..f4e01da7 --- /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 + +data class WrapType( + val typeName: TypeName, + 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/AnnotationProtectedExt.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/ksp/AnnotationProtectedExt.kt new file mode 100644 index 00000000..0b4b87b3 --- /dev/null +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/ksp/AnnotationProtectedExt.kt @@ -0,0 +1,44 @@ +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 + +/** + * fix crash at :tests:kspKotlinWasmJs + */ +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 + */ +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 + +/** + * 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/ksp/KSClassDeclarationExt.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/ksp/KSClassDeclarationExt.kt new file mode 100644 index 00000000..ce07eb96 --- /dev/null +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/ksp/KSClassDeclarationExt.kt @@ -0,0 +1,118 @@ +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.* +import com.squareup.kotlinpoet.ClassName +import com.squareup.kotlinpoet.ksp.toClassName +import com.squareup.kotlinpoet.ksp.toClassNameOrNull +import kotlin.reflect.KClass + + +fun KSTypeReference.resolveAlias(): KSType = resolve().unwrapAlias() + +fun KSTypeReference.resolveNotNullable(): KSType = resolve().makeNotNullable().unwrapAlias() + +fun KSType.unwrapAlias(): KSType { + var current: KSType = this + if (current.declaration is KSTypeAlias) { + val alias = current.declaration as KSTypeAlias + current = alias.type.resolve().replace(current.arguments) + } + return current +} + + +fun KSClassDeclaration.findConstructor( + parameters: List, +): KSFunctionDeclaration? = getDeclaredFunctions() + .filter { function -> + function.simpleName.asString() == "" + && function.parameters.all { it.type.resolveNotNullable() in parameters || it.hasDefault } + }.maxByOrNull { it.parameters.size } + +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() + +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() + allMethods.addAll(getDeclaredFunctions()) + + getAllSuperTypes().forEach { superType -> + allMethods.addAll( + (superType.declaration as KSClassDeclaration) + .getAllMethods( + includeObjectMethods = includeObjectMethods, + allowDoubles = allowDoubles, + exceptNames = exceptNames, + ) + ) + } + + yieldAll( + allMethods + .filter { it.simpleName.asString() !in exceptNames } + .then(!allowDoubles) { + removeDoubles { it1, it2 -> + it1.isSameMethods(it2) + } + } + ) +} + + +fun KSClassDeclaration.isChildOf( + parentType: ClassName, +): Boolean { + if (toClassName() == parentType) return true + superTypes.forEach { type -> + if (type.resolve().toClassNameOrNull() == 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 + 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 new file mode 100644 index 00000000..f546e830 --- /dev/null +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/ksp/KSFunctionDeclarationExt.kt @@ -0,0 +1,46 @@ +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, +): Boolean { + if (simpleName != other.simpleName + || parameters.size != other.parameters.size + ) { + return false + } + for (idx in parameters.indices) { + if (parameters[idx].type.resolve() != other.parameters[idx].type.resolve()) { + return false + } + } + + return true +} + +fun KSFunctionDeclaration.joinInvokeArguments( + availableVariables: List, +): String { + return parameters.mapNotNull { parameter -> + val availableVariable = availableVariables + .firstOrNull { it.type.resolveNotNullable() == parameter.type.resolveNotNullable() } + if (availableVariable != null) { + val notNullablePostFix = if (availableVariable.type.resolve().isMarkedNullable + && !parameter.type.resolve().isMarkedNullable + ) { + "!!" + } else { + "" + } + + "${parameter.name!!.asString()} = ${availableVariable.name!!.asString()}${notNullablePostFix}" + } else { + null + } + }.joinToString(", ") +} + +fun KSFunctionDeclaration.isClassReturn( +): Boolean = returnType?.resolve()?.isNotPrimitive ?: false diff --git a/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/ksp/arch/GenSpec.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/ksp/arch/GenSpec.kt new file mode 100644 index 00000000..159da457 --- /dev/null +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/ksp/arch/GenSpec.kt @@ -0,0 +1,9 @@ +package com.github.klee0kai.thekey.stone.ksp.ksp.arch + +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/arch/SymbolsToProcess.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/ksp/arch/SymbolsToProcess.kt new file mode 100644 index 00000000..1f29ef01 --- /dev/null +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/ksp/arch/SymbolsToProcess.kt @@ -0,0 +1,36 @@ +package com.github.klee0kai.thekey.stone.ksp.ksp.arch + +import com.google.devtools.ksp.symbol.KSAnnotated + +data class SymbolsToProcess( + val symbolsForProcessing: List, + val symbolsForReprocessing: List, +) + +fun SymbolsToProcess.nowTakeOnly( + takeSymbolsCount: Int, +): SymbolsToProcess { + return copy( + symbolsForProcessing = symbolsForProcessing.take(takeSymbolsCount), + symbolsForReprocessing = symbolsForReprocessing + symbolsForProcessing.drop(takeSymbolsCount), + ) +} + +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 { + 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/arch/TargetFileProcessor.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/ksp/arch/TargetFileProcessor.kt new file mode 100644 index 00000000..a200b8be --- /dev/null +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/ksp/arch/TargetFileProcessor.kt @@ -0,0 +1,20 @@ +package com.github.klee0kai.thekey.stone.ksp.ksp.arch + +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( + validSymbol: 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/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/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/FileSpecDsl.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/poet/FileSpecDsl.kt new file mode 100644 index 00000000..bfcc3c7e --- /dev/null +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/poet/FileSpecDsl.kt @@ -0,0 +1,79 @@ +package com.github.klee0kai.thekey.stone.ksp.poet + +import com.squareup.kotlinpoet.* + +@PoetDsl +fun genFileSpec( + packageName: String, + fileName: String, + block: FileSpec.Builder.() -> Unit, +): FileSpec { + return FileSpec.builder(packageName, fileName) + .also(block) + .build() +} + +@PoetDsl +fun FileSpec.Builder.genProperty( + name: String, + type: TypeName, + vararg modifiers: KModifier, + block: PropertySpec.Builder.() -> Unit = {} +) { + addProperty( + PropertySpec.builder(name, type, *modifiers) + .apply(block) + .build() + ) +} + +@PoetDsl +fun FileSpec.Builder.genClass( + className: ClassName, + block: TypeSpec.Builder.() -> Unit = {}, +) { + addType( + TypeSpec.classBuilder(className) + .apply(block) + .build() + ) +} + + +@PoetDsl +fun FileSpec.Builder.genObject( + className: ClassName, + block: TypeSpec.Builder.() -> Unit = {}, +) { + addType( + TypeSpec.objectBuilder(className) + .apply(block) + .build() + ) +} + +@PoetDsl +fun FileSpec.Builder.genInterface( + className: ClassName, + block: TypeSpec.Builder.() -> Unit = {}, +) { + addType( + TypeSpec.interfaceBuilder(className) + .apply(block) + .build() + ) +} + +@PoetDsl +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/FunSpecDsl.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/poet/FunSpecDsl.kt new file mode 100644 index 00000000..75c53e90 --- /dev/null +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/poet/FunSpecDsl.kt @@ -0,0 +1,27 @@ +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, + block: CodeBlock.Builder.() -> Unit, +) = apply { + beginControlFlow(controlFlow, *args) + .add(CodeBlock.builder().apply(block).build()) + .endControlFlow() + .add("\n") +} + +@PoetDsl +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/NamingExt.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/poet/NamingExt.kt new file mode 100644 index 00000000..563ac3fa --- /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.stonePackageName: String + get() { + 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/poet/PoetExt.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/poet/PoetExt.kt new file mode 100644 index 00000000..bbce7438 --- /dev/null +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/poet/PoetExt.kt @@ -0,0 +1,30 @@ +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 + +@DslMarker +annotation class PoetDsl + +fun FileSpec.Builder.genLibComment() { + addFileComment("Generated by Stone Library\n") + addFileComment("Project " + Processor.PROJECT_URL + "\n") + addFileComment("Copyright (c) 2022 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..2bc38c11 --- /dev/null +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/poet/PropertySpecDsl.kt @@ -0,0 +1,29 @@ +package com.github.klee0kai.thekey.stone.ksp.poet + +import com.squareup.kotlinpoet.FunSpec +import com.squareup.kotlinpoet.PropertySpec + +@PoetDsl +fun PropertySpec.Builder.genGetter( + block: FunSpec.Builder.() -> Unit = {} +): FunSpec { + return FunSpec.getterBuilder() + .apply(block) + .build() + .also { + getter(it) + } +} + + +@PoetDsl +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..aec3c014 --- /dev/null +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/poet/TypeSpecDsl.kt @@ -0,0 +1,107 @@ +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.toTypeName + +@PoetDsl +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) + } +} + +@PoetDsl +fun TypeSpec.Builder.genClass( + className: ClassName, + block: TypeSpec.Builder.() -> Unit = {}, +) { + addType( + TypeSpec.classBuilder(className) + .apply(block) + .build() + ) +} + +@PoetDsl +fun TypeSpec.Builder.genObject( + className: ClassName, + block: TypeSpec.Builder.() -> Unit = {}, +) { + addType( + TypeSpec.objectBuilder(className) + .apply(block) + .build() + ) +} + +@PoetDsl +fun TypeSpec.Builder.genInterface( + className: ClassName, + block: TypeSpec.Builder.() -> Unit = {}, +) { + addType( + TypeSpec.interfaceBuilder(className) + .apply(block) + .build() + ) +} + +@PoetDsl +fun TypeSpec.Builder.genFun( + name: String, + block: FunSpec.Builder.() -> Unit = {}, +) { + addFunction( + FunSpec.builder(name) + .apply(block) + .build() + ) +} + +@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()?.toTypeName()?.let { returns(it) } + wrapKsNoteInfo(func) { block() } + } +} + +@PoetDsl +fun TypeSpec.Builder.genPrimaryConstructor( + block: FunSpec.Builder.() -> Unit = {}, +) { + primaryConstructor( + FunSpec.constructorBuilder() + .apply(block) + .build() + ) +} + +@PoetDsl +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/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..ab53b2e6 --- /dev/null +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/property/Property.kt @@ -0,0 +1,71 @@ +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, + ) { + if (block === updateThisValueSubscription) { + return + } + 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/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/CommonPoetExt.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/CommonPoetExt.kt new file mode 100644 index 00000000..cb5ea061 --- /dev/null +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/CommonPoetExt.kt @@ -0,0 +1,42 @@ +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.* +import com.squareup.kotlinpoet.ParameterizedTypeName.Companion.parameterizedBy +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()?.toTypeName() + 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()?.toTypeName()?.let { returns(it) } + function.extensionReceiver?.resolve()?.toTypeName()?.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/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..97b4b8ca --- /dev/null +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/component/ComponentGraphExt.kt @@ -0,0 +1,75 @@ +package com.github.klee0kai.thekey.stone.ksp.target.component + +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.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.resolveNotNullable +import com.github.klee0kai.thekey.stone.ksp.poet.codeBlock +import com.google.devtools.ksp.symbol.KSClassDeclaration +import com.squareup.kotlinpoet.ksp.toClassName + +fun KSClassDeclaration.collectWrapHelper( +): WrapHelper { + val wrapHelper = WrapHelper() + val wrapperHelpers = allParentDeclarations + .filter { it.findComponentAnnotation().any() } + .flatMap { parentComponentCl -> + parentComponentCl.findComponentAnnotation().firstOrNull()?.wrapperHelpers ?: emptyList() + } + + 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?.resolveNotNullable() + ?.declaration as? KSClassDeclaration) + ?.toClassName() ?: return@forEachFun + + val outputType = (m.returnType?.resolveNotNullable() + ?.declaration as? KSClassDeclaration) + ?.toClassName() ?: return@forEachFun + + wrapHelper.support( + WrapType( + isNoCachingWrapper = false, + typeName = outputType, + wrap = { or, srcNullable, targetNullable, argTypeNullable -> + codeBlock { + add( + "%T.%L{ %L!! }", + wrapperHelperClDec.toClassName(), + m.simpleName.asString(), + or, + ) + } + }, + unwrap = { or, srcNullable, targetNullable -> + codeBlock { + + } + } + ) + ) + } + } + + return wrapHelper +} + + +fun KSClassDeclaration.collectComponentGraph( + +): ModulesGraph { + val modulesGraph = ModulesGraph( + wrapHelper = collectWrapHelper(), + identifierTypes = allIdentifierTypes.toList(), + ) + 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/ComponentsMethodsExt.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/component/ComponentsMethodsExt.kt new file mode 100644 index 00000000..c1ffa260 --- /dev/null +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/component/ComponentsMethodsExt.kt @@ -0,0 +1,308 @@ +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.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 +import com.github.klee0kai.thekey.stone.ksp.ksp.isUnit +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 +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, + 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( + message = "${simpleName.asString()} must no have arguments", + element = this, + ) + } + if (!hasOnlyAnnotation(ModuleOriginFactory::class.asClassName())) { + throw IncorrectSignatureException( + message = "${simpleName.asString()} must have only one annotation ${ModuleOriginFactory::class.simpleName}", + element = this, + ) + } + 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( + message = "${simpleName.asString()} must no have arguments", + element = this, + ) + } + if (annotations.any()) { + throw IncorrectSignatureException( + message = "${simpleName.asString()} must no have annotations", + element = this, + ) + } + 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( + message = "${simpleName.asString()} must no have arguments", + element = this, + ) + } + if (annotations.any()) { + throw IncorrectSignatureException( + message = "${simpleName.asString()} must no have annotations", + element = this, + ) + } + checkMethodNameBusy() + return true + } + +val KSFunctionDeclaration.isObjectProvideMethod: Boolean + get() = isProvideMethodSimple + && !isModuleProvideMethod + && !isDepsProvideMethod + && !isModuleFactoryProvideMethod + && stoneControlAnnotations().none() + +val KSFunctionDeclaration.isModuleInitMethod: Boolean + get() { + if (!annotations(Init::class.asClassName()).any()) return false + + if (!hasOnlyAnnotation(Init::class.asClassName())) { + throw IncorrectSignatureException( + message = "${simpleName.asString()} must have only one annotation ${Init::class.simpleName}", + element = this, + ) + } + if (returnType?.resolve()?.isUnit == false) { + throw IncorrectSignatureException( + message = "${simpleName.asString()} must return unit", + element = this, + ) + } + + parameters.forEach { + 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, + ) + + + if (!clDeclaration.anyAnnotation(Module::class.asClassName(), Dependencies::class.asClassName()).any()) { + throw IncorrectSignatureException( + message = "${simpleName.asString()} must have only one parameter of Dependency or Module instance", + element = this, + ) + } + } + checkMethodNameBusy() + return true + } + +fun KSFunctionDeclaration.isExtOfMethod( + clOwner: KSClassDeclaration, +): Boolean { + if (!annotations(ExtendOf::class.asClassName()).any()) return false + + if (!hasOnlyAnnotation(ExtendOf::class.asClassName())) { + throw IncorrectSignatureException( + message = "${simpleName.asString()} must have only one annotation ${ExtendOf::class.simpleName}", + element = this, + ) + } + if (parameters.size != 1) { + throw IncorrectSignatureException( + message = "${simpleName.asString()} must have only one parameter of Component instance", + element = this, + ) + } + if (returnType?.resolve()?.isUnit == false) { + throw IncorrectSignatureException( + message = "${simpleName.asString()} must return unit", + element = this, + ) + } + val argumentType = parameters.firstOrNull()?.type + ?.resolveNotNullable()?.declaration as? KSClassDeclaration + ?: throw IncorrectSignatureException( + message = "${simpleName.asString()} must have only one parameter of Component instance", + element = this, + ) + + if (!argumentType.annotations(Component::class.asClassName()).any()) { + throw IncorrectSignatureException( + message = "${argumentType.simpleName.asString()} must have @Component annotation", + element = this, + ) + } + 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()}.", + element = this, + ) + } + + checkMethodNameBusy() + return true +} + + +val KSFunctionDeclaration.isBindInstanceMethod: BindInstanceType? + get() { + if (!annotations(BindInstance::class.asClassName()).any()) return null + + if (parameters.size != 1) { + throw IncorrectSignatureException( + message = "${simpleName.asString()} must have only one parameter of binding type", + element = this, + ) + } + checkMethodNameBusy() + val parameterIsNotPrimitive = parameters.first().type.resolveNotNullable().isNotPrimitive + + when { + parameterIsNotPrimitive + && returnType?.resolveNotNullable()?.toTypeName() == parameters.first().type.resolveNotNullable().toTypeName() -> { + return BindInstanceType.BindInstanceAndProvide + } + + parameterIsNotPrimitive -> { + return BindInstanceType.BindInstance + } + + + } + + throw IncorrectSignatureException( + message = "${simpleName.asString()} has incorrect signature", + element = this, + ) + } + +val KSFunctionDeclaration.isGcMethod: Boolean + get() { + if (!annotations(RunGc::class.asClassName()).any()) return false + if (!scopeAnnotations.any()) { + throw IncorrectSignatureException( + message = "${simpleName.asString()} must use GC scope annotation", + element = this, + ) + } + + if (returnType?.resolve()?.isUnit == false) { + throw IncorrectSignatureException( + message = "${simpleName.asString()} must have return type is Unit", + element = this, + ) + } + + checkMethodNameBusy() + return true + } + + +val KSFunctionDeclaration.isSwitchCacheMethod: Boolean + get() { + if (!annotations(SwitchCache::class.asClassName()).any()) return false + + if (parameters.isNotEmpty()) { + throw IncorrectSignatureException( + message = "${simpleName.asString()} must no have arguments", + element = this, + ) + } + if (returnType?.resolve()?.isUnit == false) { + throw IncorrectSignatureException( + message = "${simpleName.asString()} must have return type is Unit", + element = this, + ) + } + checkMethodNameBusy() + return true + } + +val KSFunctionDeclaration.isInjectMethod: Boolean + get() { + if (annotations.any()) return false + if (returnType?.resolve()?.isUnit == false) return false + if (parameters.isEmpty()) 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( + message = "${simpleName.asString()} must have return type is Unit", + element = this, + ) + } + if (parameters.size != 1) { + throw IncorrectSignatureException( + message = "${simpleName.asString()} must have only one parameter", + element = this, + ) + } + checkMethodNameBusy() + return true + } + + +fun KSFunctionDeclaration.checkMethodNameBusy() { + val reserved = + simpleName.asString() in GenModuleProcessor.allReserveMethodNames + GenComponentProcessor.allReserveMethodNames + if (reserved) { + throw IncorrectSignatureException( + message = "Function name ${simpleName.asString()} is reserved by stone library", + element = this, + ) + } +} + + +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..a894571a --- /dev/null +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/component/GenComponentProcessor.kt @@ -0,0 +1,848 @@ +@file:OptIn(KspExperimental::class) + +package com.github.klee0kai.thekey.stone.ksp.target.component + +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.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 +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.* +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.* +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.getAnnotationsByType +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.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 kotlin.reflect.KClass +import com.google.devtools.ksp.processing.Dependencies as KspDependencies + +class GenComponentProcessor : TargetFileProcessor { + + companion object { + val refCollectionGlFieldName = "__refCollection" + val scopeFieldName = "__scope" + val hiddenModuleFieldName = "__hiddenModule" + val relatedComponentsListFieldName = "__related" + val protectRecursiveField = "__protectRecursive" + val eachModuleMethodName = "__eachModule" + val initMethodName = "__init" + val initDepsMethodName = "__initDependencies" + val bindMethodName = "__bind" + val extOfMethodName = "__extOf" + + val allReserveMethodNames = listOf( + refCollectionGlFieldName, + scopeFieldName, + hiddenModuleFieldName, + relatedComponentsListFieldName, + protectRecursiveField, + eachModuleMethodName, + initMethodName, + initDepsMethodName, + bindMethodName, + extOfMethodName, + ) + } + + private class DelayedCodeBlocks( + val initDepsMethodBody: CodeBlock.Builder = CodeBlock.builder(), + ) + + 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 wrapHelper = componentCl.collectWrapHelper() + val modulesGraph = componentCl.collectComponentGraph() + val delayedCodeBlocks = DelayedCodeBlocks() + + val genComponentClassName = componentCl.componentStoneClName + + val fileSpec = genFileSpec(genComponentClassName.packageName, genComponentClassName.simpleName) { + 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.forEachFun { _, 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()?.toTypeName() == m.returnType?.resolve()?.toTypeName() + } + ?: 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 -> { + 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 -> { + 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?.let{ %L( %L ) }", + param.name!!.asString(), + initMethodName, + param.name!!.asString() + ) + } + + paramType.anyAnnotation( + Dependencies::class.asClassName(), + ).any() -> { + addStatement( + "%L?.let{ %L( %L ) }", + param.name!!.asString(), + initDepsMethodName, + param.name!!.asString() + ) + } + + else -> { + throw IncorrectSignatureException( + message = "wrong return type. Must by Module type", + element = param, + ) + } + } + + } + } + } + + m.isExtOfMethod(componentCl) -> { + genOverrideFun(m) { + addCode( + "(%L as? %T)?.let{ %L(it) }", + parameters.first().name, + IPrivateComponent::class.asClassName(), + extOfMethodName + ) + } + } + + m.isObjectProvideMethod -> { + genProvideObjMethod( + componentCl = componentCl, + method = m, + modulesGraph = modulesGraph, + ) + } + + m.isBindInstanceMethod != null -> { + genBindInstanceMethod( + componentCl = componentCl, + method = m, + modulesGraph = modulesGraph, + wrapHelper = wrapHelper, + ) + } + + m.isGcMethod -> { + genGcMthod( + componentCl = componentCl, + method = m, + wrapHelper = wrapHelper, + ) + } + + m.isSwitchCacheMethod -> { + genSwitchRefMethod( + componentCl = componentCl, + method = m, + ) + } + + m.isInjectMethod -> { + genInjectMethod( + componentCl = componentCl, + method = m, + wrapHelper = wrapHelper, + modulesGraph = modulesGraph, + ) + } + + m.isProtectInjectedMethod -> { + genProtectInjected( + componentCl = componentCl, + method = m, + wrapHelper = wrapHelper, + ) + } + + m.isAbstract -> { + throw IncorrectSignatureException( + message = "What is purpose for Method ${m.simpleName.asString()}. " + + "Declared in ${componentCl.simpleName.asString()} ", + element = m, + ) + } + } + } + + genIComponentMethods( + componentCl = componentCl, + delayedCodeBlocks = delayedCodeBlocks, + + ) + } + } + + return GenSpec( + fileSpec = fileSpec, + // https://kotlinlang.org/docs/ksp-incremental.html + dependencies = KspDependencies(aggregating = false, fileOwner), + ) + } + + private fun TypeSpec.Builder.genProvideObjMethod( + componentCl: KSClassDeclaration, + method: KSFunctionDeclaration, + modulesGraph: ModulesGraph, + ) { + val returnType = method.returnType?.resolveAlias()?.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.genBindInstanceMethod( + componentCl: KSClassDeclaration, + method: KSFunctionDeclaration, + modulesGraph: ModulesGraph, + wrapHelper: WrapHelper, + ) { + val returnType = method.returnType?.resolveAlias()?.toTypeName() ?: return + val identifierTypes = componentCl.allIdentifierTypes.toList() + + val setValueArg = method.parameters.firstOrNull { it.type.resolveNotNullable() !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.copy(nullable = true)) + .copy(nullable = true) + } else { + nonWrappedBindType.copy(nullable = true) + } + + // 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, + wrapHelper: WrapHelper, + modulesGraph: ModulesGraph, + ) { + val identifierTypes = componentCl.allIdentifierTypes.toList() + 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, + ) + } + + genOverrideFun(method) { + for (injectableField in injectableArguments) { + val injectableCl = injectableField.type.resolveNotNullable().declaration as? KSClassDeclaration + ?: throw IncorrectSignatureException( + message = "parameter must be a class", + element = injectableField, + ) + + + for (injectField in injectableCl.getAllProperties()) { + if (!injectField.anyAnnotation( + Inject::class.asClassName(), + javax.inject.Inject::class.asClassName() + ).any() + ) continue + + val provideCode = modulesGraph.codeProvideType( + methodName = null, + 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.resolveNotNullable().toTypeName()) + throw ObjectNotProvidedException( + message = "Error provide type ${injectField.type.resolveNotNullable().toTypeName()}. " + + "Required in ${injectableCl.toClassName()}.${injectField.simpleName.asString()}", + element = method, + ) + } + + addCode( + "%L?.%L = ", + injectableField.name!!.asString(), + injectField.simpleName.asString(), + ) + addCode(provideCode) + addStatement("") + } + + for (injectMethod in injectableCl.getAllMethods(false, false, "")) { + 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( + null, + 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.resolveAlias().toTypeName()}. " + + "Required in ${injectableCl.toClassName()}.${injectMethod.simpleName.asString()}", + element = method, + ) + } + + if (!providingArgsCode.isEmpty()) providingArgsCode.add(", ") + providingArgsCode.add(provideCode) + } + + addCode("%L?.%L( ", injectableField.name!!.asString(), injectMethod.simpleName.asString()) + addCode(providingArgsCode.build()) + addStatement(")"); + } + + } + + + //protect by lifecycle owner + for (injectableField in injectableArguments) { + val injectableCl = injectableField.type.resolveNotNullable().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(), + javax.inject.Inject::class.asClassName() + ).any() + ) continue + if (wrapHelper.isNonCachingWrapper(injectField.type.resolveNotNullable().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()) + } + } + } + } + + private fun TypeSpec.Builder.genProtectInjected( + componentCl: KSClassDeclaration, + method: KSFunctionDeclaration, + wrapHelper: WrapHelper, + ) { + val protectTimeMillis = method.getAnnotationsByType(ProtectInjected::class) + .firstOrNull()?.timeMillisProtected + ?: 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.resolveNotNullable().declaration as? KSClassDeclaration + ?: throw IncorrectSignatureException( + message = "parameter must be a class", + element = injectableField, + ) + + + for (injectField in injectableCl.getAllProperties()) { + if (!injectField.anyAnnotation( + Inject::class.asClassName(), + javax.inject.Inject::class.asClassName() + ).any() + ) continue + + if (wrapHelper.isNonCachingWrapper(injectField.type.resolveNotNullable().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.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.cacheProtected.name, + switchCacheAnn.timeMillisProtected, + ) + + addStatement( + "%L{ m -> m.%L(scopes, switchCacheParams) } ", + eachModuleMethodName, GenModuleProcessor.switchRefMethodName, + ) + } + } + + private fun TypeSpec.Builder.genIComponentMethods( + componentCl: KSClassDeclaration, + delayedCodeBlocks: DelayedCodeBlocks, + ) { + val relatedListType = WeakList::class.asClassName().parameterizedBy(IPrivateComponent::class.asClassName()) + genProperty( + name = relatedComponentsListFieldName, + type = relatedListType, + ) { + addModifiers(KModifier.PRIVATE) + initializer("%T()", relatedListType) + } + genProperty( + name = protectRecursiveField, + type = BOOLEAN, + ) { + addModifiers(KModifier.PRIVATE) + 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.stoneCoroutineScope ", StoneScope::class) + } + + genProperty( + name = hiddenModuleFieldName, + type = componentCl.hiddenModuleStoneClName, + ) { + addModifiers(KModifier.OVERRIDE) + initializer("%T()", componentCl.hiddenModuleStoneClName) + } + + 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() + } + + 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.allParentDeclarations) { + 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(), + ) + } + + addStatement("// bind instance methods ignore nullability checks ") + for (bindInstMethod in bindInstanceAndProvideMethods) { + addStatement( + "runCatching{ %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/GenHiddenModuleCacheControlProcessor.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/hiddenmodule/GenHiddenModuleCacheControlProcessor.kt new file mode 100644 index 00000000..9d1490dc --- /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.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 +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 new file mode 100644 index 00000000..77e112ea --- /dev/null +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/hiddenmodule/GenHiddenModuleProcessor.kt @@ -0,0 +1,433 @@ +@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.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 +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.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.* +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 +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.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 { + + + 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( + 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 wrapHelper = componentCl.collectWrapHelper() + val codeBlocks = DelayedCodeBlocks() + + val fileSpec = genFileSpec(genHiddenModuleCl.packageName, genHiddenModuleCl.simpleName) { + genLibComment() + + addImport("com.github.klee0kai.stone.__hidden__.coroutines", "syncIfAvailable") + + genClass(genHiddenModuleCl) { + addSuperinterface(IModule::class) + 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) + + 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()}$itemHolderIdx", + returnType = returnType, + idArguments = idArguments, + cacheType = bindAnn.cacheProtected.toItemCacheType(), + wrapHelper = wrapHelper, + ) + gcScopes += bindAnn.cacheProtected.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::class == %T::class) {\n", + rawTypeOf(nonWrappedType), + ) + add(codeSetCachedValue(CodeBlock.of("or as? %T", nonWrappedType), 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, + wrapHelper = wrapHelper, + ) + } + + genIModelMethods( + componentCl = componentCl, + codeBlocks = codeBlocks, + ) + } + + } + + return GenSpec( + fileSpec = fileSpec, + // https://kotlinlang.org/docs/ksp-incremental.html + dependencies = Dependencies(aggregating = false, fileOwner), + ) + } + + 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.resolveNotNullable().toTypeName() == function.returnType?.resolveNotNullable()?.toTypeName() + } + + genOverrideFun(function) { + beginControlFlow("return syncIfAvailable(%L.mutex)", itemHolderCodeHelper.fieldName) + 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@syncIfAvailable ") + 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@syncIfAvailable ") + addCode( + wrapHelper.transform( + wrapHelper.listWrapTypeIfNeed(returnType), + returnType, + itemHolderCodeHelper.codeGetCachedValue(), + ) + ) + addStatement(" as %T", returnType) + endControlFlow() + } + } + + + private fun TypeSpec.Builder.genCacheControlFun( + 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)) + addParameter("__action", CacheAction::class) + idArguments.forEach { + addParameter(it.name!!.asString(), it.type.resolve().toTypeName()) + } + + beginControlFlow("return syncIfAvailable(%L.mutex)", itemHolderCodeHelper.fieldName) + 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("if ( __action.value != null ) ") + addCode( + codeBlock = itemHolderCodeHelper.codeSetCachedValue( + CodeBlock.of("__action.value as? %T", cacheControlType), + onlyIfNull = false, + ) + ) + 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), + onlyIfNull = true, + ) + ) + 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@syncIfAvailable ") + addCode(codeBlock = itemHolderCodeHelper.codeGetCachedValue()) + addStatement("") + endControlFlow() + } + } + + private fun TypeSpec.Builder.genIModelMethods( + componentCl: KSClassDeclaration, + + codeBlocks: DelayedCodeBlocks, + ) { + genProperty( + name = factoryFieldName, + type = ANY.copy(nullable = true), + ) { + addModifiers(KModifier.OVERRIDE) + initializer("null") + } + + val cacheControlHolder = SingleItemHolder::class.asClassName() + .parameterizedBy(componentCl.hiddenModuleStoneClName.cacheControlStoneClName) + genProperty( + name = overridedModuleFieldName, + type = cacheControlHolder, + ) { + mutable(true) + initializer("%T(%T.WeakObject)", cacheControlHolder, StoneRefType::class) + } + + 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(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(initCachesFromMethodName) { + addModifiers(KModifier.OVERRIDE) + addParameter("m", IModule::class) + addStatement("if (m == this) return") + + 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 + + addStatement( + "%L( %T.setIfNullValueAction( module.%L( %T.getValueAction ) ) )", + cacheControlMethod, CacheAction::class, + cacheControlMethod, CacheAction::class, + ) + } + + addStatement("return") + endControlFlow() + } + + } + + genFun(updateBindInstancesFrom) { + addModifiers(KModifier.OVERRIDE) + addParameter("m", IModule::class) + addStatement("if (m == this) return") + + 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 + + addStatement( + "%L( %T.setValueAction( module.%L( %T.getValueAction ) ) )", + cacheControlMethod, CacheAction::class, + cacheControlMethod, CacheAction::class, + ) + } + addStatement("return") + endControlFlow() + } + + } + + genFun(clearNullsMethodName) { + addModifiers(KModifier.OVERRIDE) + addCode(codeBlocks.clearNullsMethodBody.build()) + } + } + +} 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 new file mode 100644 index 00000000..b465f292 --- /dev/null +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/module/GenModuleCacheControlProcessor.kt @@ -0,0 +1,117 @@ +@file:OptIn(KspExperimental::class) + +package com.github.klee0kai.thekey.stone.ksp.target.module + +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.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.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 +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 com.squareup.kotlinpoet.ksp.toTypeName +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 wrapHelper = componentCl?.collectWrapHelper() ?: WrapHelper() + + val identifierTypes = componentCl + ?.allIdentifierTypes?.toList() + ?: emptyList() + + val genCacheControlClassName = moduleCl.toClassName().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) + } + + val methods = validSymbol.getAllMethods(includeObjectMethods = false, allowDoubles = false, "") + methods.forEachFun { _, function -> + val idArguments = function.parameters.identifierParameters(identifierTypes) + val returnType = function.returnType?.resolveNotNullable()?.toTypeName() ?: return@forEachFun + val cacheControlType = wrapHelper.listWrapTypeIfNeed(returnType).copy(nullable = true) + + genOverrideFun(function) { + modifiers.remove(KModifier.OVERRIDE) + modifiers.add(KModifier.ABSTRACT) + } + genFun(function.cacheControlMethodName) { + modifiers.add(KModifier.ABSTRACT) + returns(returnType = cacheControlType) + 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/module/GenModuleFactoryProcessor.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/module/GenModuleFactoryProcessor.kt new file mode 100644 index 00000000..c0ed2806 --- /dev/null +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/module/GenModuleFactoryProcessor.kt @@ -0,0 +1,141 @@ +@file:OptIn(KspExperimental::class) + +package com.github.klee0kai.thekey.stone.ksp.target.module + +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.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 +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.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 +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 +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 { + + 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 wrapHelper = componentCl?.collectWrapHelper() ?: WrapHelper() + + val genFactoryClassName = moduleCl.factoryStoneClName + val fileSpec = genFileSpec(genFactoryClassName.packageName, fileName = genFactoryClassName.simpleName) { + genLibComment() + + genClass(genFactoryClassName) { + if (moduleCl.classKind == ClassKind.INTERFACE) { + addSuperinterface(moduleCl.toClassName()) + } else { + superclass(moduleCl.toClassName()) + } + addSuperinterface(IModuleFactory::class) + addModifiers(KModifier.OPEN) + + validSymbol.getAllMethods(false, false, "") + .forEachFun { _, function -> + if (!function.modifiers.contains(Modifier.ABSTRACT) && moduleCl.classKind != ClassKind.INTERFACE) 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 { + nonWrappedClDec?.findConstructor( + parameters = function.parameters.map { it.type.resolveNotNullable() }) + } + + genOverrideFun(function) { + when { + bindInstanceAnn != null -> { + addStatement( + "throw %T(%S)", + NotImplementedError::class.asClassName(), + "Object generation is not available for bind instance methods" + ) + } + + constructorFun != null -> { + addCode( + "return %L", + wrapHelper.transform( + providingType = nonWrappedType, + wannaType = returnType, + CodeBlock.of( + "%T( %L )", + nonWrappedType, + constructorFun!!.joinInvokeArguments(function.parameters), + ) + ) + ) + } + + 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 + 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/module/GenModuleProcessor.kt b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/module/GenModuleProcessor.kt new file mode 100644 index 00000000..f85903e8 --- /dev/null +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/module/GenModuleProcessor.kt @@ -0,0 +1,612 @@ +@file:OptIn(KspExperimental::class) + +package com.github.klee0kai.thekey.stone.ksp.target.module + +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.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 +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 +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.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.* +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 +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.* +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 { + + 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 switchRefMethodName: String = "__switchRef" + const val clearNullsMethodName: String = "__clearNulls" + + val allReserveMethodNames = listOf( + initMethodName, + initCachesFromMethodName, + updateBindInstancesFrom, + bindMethodName, + switchRefMethodName, + clearNullsMethodName, + ) + } + + 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( + 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 wrapHelper = componentCl?.collectWrapHelper() ?: WrapHelper() + + val identifierTypes = componentCl + ?.allIdentifierTypes?.toList() + ?: emptyList() + + val genModuleClassName = moduleCl.moduleStoneClName + + 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()) + } else { + superclass(moduleCl.toClassName()) + } + addSuperinterface(IModule::class) + + 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) + + 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() + + + when { + bindAnn != null -> { + val itemHolderCodeHelper = ItemHolderCodeHelper.of( + fieldName = "${function.simpleName.asString()}$holderIdx", + returnType = returnType, + idArguments = idArguments, + cacheType = bindAnn.cacheProtected.toItemCacheType(), + wrapHelper = wrapHelper, + ) + gcScopes += bindAnn.cacheProtected.toItemCacheType().gcScopeClassName + codeBlocks.switchRefStatementBuilders.getOrPut(gcScopes) { CodeBlock.builder() } + .add(itemHolderCodeHelper.statementSwitchRef(CodeBlock.of("__params"))) + + codeBlocks.clearNullsMethodBody.add(itemHolderCodeHelper.clearNullsStatement()) + + with(itemHolderCodeHelper) { + genCacheField() + + 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) + } + } + } + + genBindInstance( + function = function, + idArguments = idArguments, + itemHolderCodeHelper = itemHolderCodeHelper, + wrapHelper = wrapHelper, + ) + genCacheControlFun( + function = function, + idArguments = idArguments, + itemHolderCodeHelper = itemHolderCodeHelper, + wrapHelper = wrapHelper, + ) + + + } + + provideAnn == null || provideAnn.cacheProtected == 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 cacheControlType = function.returnType?.resolveNotNullable() + ?.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()) + } + addStatement("return null") + } + } + + else -> { + val itemHolderCodeHelper = ItemHolderCodeHelper.of( + fieldName = "${function.simpleName.asString()}$holderIdx", + returnType = returnType, + idArguments = idArguments, + cacheType = provideAnn.cacheProtected.toItemCacheType() ?: return@forEachFun, + wrapHelper = wrapHelper, + ) + gcScopes += provideAnn.cacheProtected.toItemCacheType()!!.gcScopeClassName + codeBlocks.switchRefStatementBuilders.getOrPut(gcScopes) { CodeBlock.builder() } + .add(itemHolderCodeHelper.statementSwitchRef(CodeBlock.of("__params"))) + codeBlocks.clearNullsMethodBody.add(itemHolderCodeHelper.clearNullsStatement()) + with(itemHolderCodeHelper) { + genCacheField() + } + genProvideCachedFun( + function = function, + idArguments = idArguments, + itemHolderCodeHelper = itemHolderCodeHelper, + wrapHelper = wrapHelper, + ) + genCacheControlFun( + function = function, + idArguments = idArguments, + itemHolderCodeHelper = itemHolderCodeHelper, + wrapHelper = wrapHelper, + ) + } + } + + } + + + genIModelMethods( + moduleCl = moduleCl, + identifierTypes = identifierTypes, + codeBlocks = codeBlocks, + ) + } + } + + return GenSpec( + fileSpec = fileSpec, + // https://kotlinlang.org/docs/ksp-incremental.html + dependencies = Dependencies(aggregating = false, fileOwner), + ) + } + + + 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.resolveNotNullable().toTypeName() == function.returnType?.resolveNotNullable()?.toTypeName() + } + + genOverrideFun(function) { + beginControlFlow("return syncIfAvailable(%L.mutex)", itemHolderCodeHelper.fieldName) + 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@syncIfAvailable ") + 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@syncIfAvailable ") + addCode( + wrapHelper.transform( + wrapHelper.listWrapTypeIfNeed(returnType).copy(nullable = true), + returnType, + itemHolderCodeHelper.codeGetCachedValue(), + ) + ) + endControlFlow() + } + } + + private fun TypeSpec.Builder.genProvideCachedFun( + function: KSFunctionDeclaration, + idArguments: List, + itemHolderCodeHelper: ItemHolderCodeHelper, + wrapHelper: WrapHelper, + ) { + val returnType = function.returnType?.resolve()?.toTypeName() ?: return + genOverrideFun(function) { + beginControlFlow("return syncIfAvailable(%L.mutex)", itemHolderCodeHelper.fieldName) + 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@syncIfAvailable ") + addCode( + wrapHelper.transform( + wrapHelper.listWrapTypeIfNeed(returnType), + returnType, + CodeBlock.of("cached"), + ) + ) + addStatement("") + + // set value if null + val argStrList = function.parameters.joinToString(", ") { it.name!!.asString() } + addCode("val creator = %T{ ", Ref::class.asClassName().parameterizedBy(returnType)) + addCode( + "%L.get()?.%L(%L)", + overridedModuleFieldName, function.simpleName.asString(), argStrList, + ) + addCode(" ?: ") + addCode("%L.%L(%L)", factoryFieldName, function.simpleName.asString(), argStrList) + addCode("}\n") + addCode( + itemHolderCodeHelper.codeSetCachedValue( + wrapHelper.transform( + returnType, + wrapHelper.listWrapTypeIfNeed(returnType), + CodeBlock.of("creator.get()"), + ), + onlyIfNull = true, + ) + ) + addCode("\n") + addCode("return@syncIfAvailable ") + addCode( + wrapHelper.transform( + wrapHelper.listWrapTypeIfNeed(returnType).copy(nullable = true), + returnType, + itemHolderCodeHelper.codeGetCachedValue(), + ) + ) + endControlFlow() + } + } + + private fun TypeSpec.Builder.genCacheControlFun( + function: KSFunctionDeclaration, + idArguments: List, + itemHolderCodeHelper: ItemHolderCodeHelper, + wrapHelper: WrapHelper, + ) { + val returnType = function.returnType?.resolveNotNullable()?.toTypeName() ?: return + val cacheControlType = wrapHelper.listWrapTypeIfNeed(returnType).copy(nullable = true) + genFun(function.cacheControlMethodName) { + modifiers.add(KModifier.OVERRIDE) + returns(cacheControlType.copy(nullable = true)) + addParameter("__action", CacheAction::class) + idArguments.forEach { + addParameter(it.name!!.asString(), it.type.resolve().toTypeName()) + } + + beginControlFlow("return syncIfAvailable(%L.mutex)", itemHolderCodeHelper.fieldName) + 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("if ( __action.value != null ) ") + addCode( + codeBlock = itemHolderCodeHelper.codeSetCachedValue( + CodeBlock.of("__action.value as? %T", cacheControlType), + onlyIfNull = false + ) + ) + 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), + onlyIfNull = true + ) + ) + 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@syncIfAvailable ") + addCode(codeBlock = itemHolderCodeHelper.codeGetCachedValue()) + endControlFlow() + } + } + + private fun TypeSpec.Builder.genIModelMethods( + moduleCl: KSClassDeclaration, + identifierTypes: List, + codeBlocks: DelayedCodeBlocks, + ) { + + genProperty( + name = factoryFieldName, + type = moduleCl.toClassName(), + ) { + addModifiers(KModifier.OVERRIDE) + mutable(true) + initializer("%T()", moduleCl.factoryStoneClName) + } + + val cacheControlHolder = SingleItemHolder::class.asClassName() + .parameterizedBy(moduleCl.toClassName().cacheControlStoneClName) + genProperty( + name = overridedModuleFieldName, + type = cacheControlHolder, + ) { + mutable(true) + initializer("%T(%T.WeakObject)", cacheControlHolder, StoneRefType::class) + } + + genFun(initMethodName) { + addModifiers(KModifier.OVERRIDE) + returns(BOOLEAN) + addParameter("or", Any::class) + addStatement("if (or === this) return false") + addStatement("var %L = false", appliedLocalFieldName) + + // check module class + beginControlFlow( + "if ( (or is %T) ) ", + moduleCl.toClassName().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(bindMethodName) { + addModifiers(KModifier.OVERRIDE) + addParameter("or", Any::class) + returns(BOOLEAN) + addStatement("%L.get()?.%L(or)", overridedModuleFieldName, bindMethodName) + + 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(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.identifierParameters(identifierTypes) + if (idArguments.isNotEmpty()) { + // 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.identifierParameters(identifierTypes) + if (idArguments.isNotEmpty()) { + // 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) { + addModifiers(KModifier.OVERRIDE) + addCode(codeBlocks.clearNullsMethodBody.build()) + } + + } + + +} \ 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_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..8ce49fe6 --- /dev/null +++ b/stone_ksp/src/commonMain/kotlin/com/github/klee0kai/thekey/stone/ksp/target/wrapper/GenWrappersSupportProcessor.kt @@ -0,0 +1,80 @@ +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_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..c74c1b83 --- /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, +): List { + val out = LinkedList() + for (item in this) { + val contains = out.any { compare.invoke(item, it) } + if (!contains) out.add(item) + } + return out.toList() +} \ No newline at end of file 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/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..80c94406 --- /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_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_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 new file mode 100644 index 00000000..0745d06f --- /dev/null +++ b/stone_ksp/src/commonMain/resources/META-INF/services/com.google.devtools.ksp.processing.SymbolProcessorProvider @@ -0,0 +1 @@ +com.github.klee0kai.thekey.stone.ksp.StoneProcessorProvider \ No newline at end of file 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/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 new file mode 100644 index 00000000..1ec0e042 --- /dev/null +++ b/stone_multiplatform/build.gradle.kts @@ -0,0 +1,80 @@ +plugins { + alias(libs.plugins.kotlin.multiplatform) + alias(libs.plugins.publish.stone) + alias(libs.plugins.publish.maven) +} + +group = "com.github.klee0kai.stone" +version = libs.versions.stone.get() + + +kotlin { + jvm() + js(IR) { + browser() + nodejs() + } + + linuxX64() + mingwX64() + wasmJs { + browser() + nodejs() + } + sourceSets { + commonMain.dependencies { + api(project(":inject_multiplatform")) + api(project(":weakref_multiplatform")) + implementation(libs.kotlinx.coroutines) + implementation(libs.kotlinx.atomicfu) + } + 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) + } + } +} + + +publishing { + publications.withType().configureEach { + pom { + name.set("Stone") + description.set("Library DI designed on weak references.") + } + } +} 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..6de62fde --- /dev/null +++ b/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/__hidden__/CacheAction.kt @@ -0,0 +1,51 @@ +package com.github.klee0kai.stone.__hidden__ + +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 getValueAction: 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__/IModule.kt b/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/__hidden__/IModule.kt new file mode 100644 index 00000000..ed839571 --- /dev/null +++ b/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/__hidden__/IModule.kt @@ -0,0 +1,57 @@ +package com.github.klee0kai.stone.__hidden__ + +import kotlin.reflect.KClass + +/** + * Stone Private class + */ +interface IModule { + + /** + * get component's factory + * + * @return + */ + val factory: Any? + + /** + * 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 or - An instance of bindable objects + */ + fun __bind(or: Any): Boolean + + + /** + * Switch cache type for scope + */ + public fun __switchRef(scopes: Set>, __params: SwitchCacheParam) + + /** + * Clear null refs. + * Useful after gc + */ + fun __clearNulls() +} diff --git a/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/__hidden__/IModuleFactory.kt b/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/__hidden__/IModuleFactory.kt new file mode 100644 index 00000000..00a61bd2 --- /dev/null +++ b/stone_multiplatform/src/commonMain/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/commonMain/kotlin/com/github/klee0kai/stone/__hidden__/IPrivateComponent.kt b/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/__hidden__/IPrivateComponent.kt new file mode 100644 index 00000000..69d020e4 --- /dev/null +++ b/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/__hidden__/IPrivateComponent.kt @@ -0,0 +1,51 @@ +package com.github.klee0kai.stone.__hidden__ + + +/** + * Private Stone class + * Each Stone component implement this interface. + */ +interface IPrivateComponent { + + /** + * hidden module + */ + val __hiddenModule: IModule + + /** + * 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) + + + /** + * + * @param callback + */ + fun __eachModule(callback: (IModule) -> Unit) +} 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__/SwitchCacheParam.kt b/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/__hidden__/SwitchCacheParam.kt new file mode 100644 index 00000000..009e8956 --- /dev/null +++ b/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/__hidden__/SwitchCacheParam.kt @@ -0,0 +1,16 @@ +package com.github.klee0kai.stone.__hidden__ + +import com.github.klee0kai.stone.annotations.component.SwitchCache + +/** + * Stone Private class + */ +class SwitchCacheParam( + val cache: SwitchCache.CacheType, + val time: Long = -1, +) { + companion object { + 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__/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() + +} 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__/provide/ProvideBuilder.kt b/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/__hidden__/provide/ProvideBuilder.kt new file mode 100644 index 00000000..26552f79 --- /dev/null +++ b/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/__hidden__/provide/ProvideBuilder.kt @@ -0,0 +1,32 @@ +package com.github.klee0kai.stone.__hidden__.provide + +class ProvideBuilder( + private val provideBody: ProvideBody +) { + + fun interface ProvideBody { + fun provide(consumer: ProvideConsumer) + } + + 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) + 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/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/MapItemHolder.kt b/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/__hidden__/types/holders/MapItemHolder.kt new file mode 100644 index 00000000..075b3fc9 --- /dev/null +++ b/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/__hidden__/types/holders/MapItemHolder.kt @@ -0,0 +1,206 @@ +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.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, + val mutex: Mutex = Mutex(), +) { + + 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?>?)?.mapNotNull { it?.get() } + } + + else -> null + } + } + + 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, + creator: Ref, + ) { + 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?, + onlyIfNull: Boolean, + creator: Ref?>, + ) { + 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] = getListNullable(key) + curRefType = refType.forList() + 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, onlyIfNull = false) { itemMap[key] } + } + } + + + 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 = getListNullable(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 > 0) { + 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 new file mode 100644 index 00000000..2df577d4 --- /dev/null +++ b/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/__hidden__/types/holders/SingleItemHolder.kt @@ -0,0 +1,155 @@ +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.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, + val mutex: Mutex = Mutex(), +) { + 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?>?)?.mapNotNull { it?.get() } + 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, + creator: Ref, + ) { + 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( + onlyIfNull: Boolean, + creator: Ref?>, + ) { + 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 (!onlyIfNull || refList == null) { + 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.getListNullable() + curRefType = refType.forList() + setList(onlyIfNull = false) { ob } + } else { + val ob = get() + curRefType = refType.forSingle() + set(onlyIfNull = false) { ob } + } + } + + + 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 > 0) { + 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 new file mode 100644 index 00000000..d36240a5 --- /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/__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/annotations/component/Component.kt b/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/annotations/component/Component.kt new file mode 100644 index 00000000..40aceff2 --- /dev/null +++ b/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/annotations/component/Component.kt @@ -0,0 +1,238 @@ +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> = [], + + /** + * TODO Kdoc + */ + val wrapperHelpers: Array> = [], +) diff --git a/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/annotations/component/ExtendOf.kt b/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/annotations/component/ExtendOf.kt new file mode 100644 index 00000000..366a3693 --- /dev/null +++ b/stone_multiplatform/src/commonMain/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/commonMain/kotlin/com/github/klee0kai/stone/annotations/component/GcAllScope.kt b/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/annotations/component/GcAllScope.kt new file mode 100644 index 00000000..28333808 --- /dev/null +++ b/stone_multiplatform/src/commonMain/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/commonMain/kotlin/com/github/klee0kai/stone/annotations/component/GcScopeAnnotation.kt b/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/annotations/component/GcScopeAnnotation.kt new file mode 100644 index 00000000..a62b149a --- /dev/null +++ b/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/annotations/component/GcScopeAnnotation.kt @@ -0,0 +1,28 @@ +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/commonMain/kotlin/com/github/klee0kai/stone/annotations/component/GcSoftScope.kt b/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/annotations/component/GcSoftScope.kt new file mode 100644 index 00000000..a603c567 --- /dev/null +++ b/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/annotations/component/GcSoftScope.kt @@ -0,0 +1,14 @@ +package com.github.klee0kai.stone.annotations.component + +import com.github.klee0kai.stone.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/commonMain/kotlin/com/github/klee0kai/stone/annotations/component/GcStrongScope.kt b/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/annotations/component/GcStrongScope.kt new file mode 100644 index 00000000..40d39ad7 --- /dev/null +++ b/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/annotations/component/GcStrongScope.kt @@ -0,0 +1,14 @@ +package com.github.klee0kai.stone.annotations.component + +import com.github.klee0kai.stone.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/commonMain/kotlin/com/github/klee0kai/stone/annotations/component/GcWeakScope.kt b/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/annotations/component/GcWeakScope.kt new file mode 100644 index 00000000..2fbbd30d --- /dev/null +++ b/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/annotations/component/GcWeakScope.kt @@ -0,0 +1,14 @@ +package com.github.klee0kai.stone.annotations.component + +import com.github.klee0kai.stone.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/commonMain/kotlin/com/github/klee0kai/stone/annotations/component/Init.kt b/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/annotations/component/Init.kt new file mode 100644 index 00000000..f3e0d55a --- /dev/null +++ b/stone_multiplatform/src/commonMain/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/commonMain/kotlin/com/github/klee0kai/stone/annotations/component/ModuleOriginFactory.kt b/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/annotations/component/ModuleOriginFactory.kt new file mode 100644 index 00000000..02248c55 --- /dev/null +++ b/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/annotations/component/ModuleOriginFactory.kt @@ -0,0 +1,25 @@ +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/commonMain/kotlin/com/github/klee0kai/stone/annotations/component/ProtectInjected.kt b/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/annotations/component/ProtectInjected.kt new file mode 100644 index 00000000..b53b048c --- /dev/null +++ b/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/annotations/component/ProtectInjected.kt @@ -0,0 +1,30 @@ +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/commonMain/kotlin/com/github/klee0kai/stone/annotations/component/RunGc.kt b/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/annotations/component/RunGc.kt new file mode 100644 index 00000000..1dbb8a79 --- /dev/null +++ b/stone_multiplatform/src/commonMain/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/commonMain/kotlin/com/github/klee0kai/stone/annotations/component/SwitchCache.kt b/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/annotations/component/SwitchCache.kt new file mode 100644 index 00000000..0cba3ec7 --- /dev/null +++ b/stone_multiplatform/src/commonMain/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/commonMain/kotlin/com/github/klee0kai/stone/annotations/dependencies/Dependencies.kt b/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/annotations/dependencies/Dependencies.kt new file mode 100644 index 00000000..049d2ea0 --- /dev/null +++ b/stone_multiplatform/src/commonMain/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/commonMain/kotlin/com/github/klee0kai/stone/annotations/module/BindInstance.kt b/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/annotations/module/BindInstance.kt new file mode 100644 index 00000000..898ac693 --- /dev/null +++ b/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/annotations/module/BindInstance.kt @@ -0,0 +1,83 @@ +package com.github.klee0kai.stone.annotations.module + + +/** + * 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) +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/commonMain/kotlin/com/github/klee0kai/stone/annotations/module/Module.kt b/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/annotations/module/Module.kt new file mode 100644 index 00000000..59f8af7f --- /dev/null +++ b/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/annotations/module/Module.kt @@ -0,0 +1,84 @@ +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( + 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 new file mode 100644 index 00000000..c3081cc2 --- /dev/null +++ b/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/annotations/module/Provide.kt @@ -0,0 +1,51 @@ +package com.github.klee0kai.stone.annotations.module + +import kotlin.reflect.KClass + +/** + * 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) +annotation class Provide( + /** + * Object caching type + */ + val cache: CacheType = CacheType.Factory, + + /** + * provide dependency with wrapper packaging + */ + val provideWrapper: KClass<*> = Nothing::class, +) { + enum class CacheType { + Factory, + Weak, + Soft, + Strong + } +} 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..02a854e5 --- /dev/null +++ b/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/annotations/qualifier/IgnoreQualifier.kt @@ -0,0 +1,19 @@ +package com.github.klee0kai.stone.annotations.qualifier + +/** + * 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( + AnnotationTarget.FUNCTION, + AnnotationTarget.PROPERTY_GETTER, + AnnotationTarget.PROPERTY_SETTER, + AnnotationTarget.PROPERTY, + AnnotationTarget.VALUE_PARAMETER, +) +@MustBeDocumented +annotation class IgnoreQualifier + 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/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 new file mode 100644 index 00000000..d785a86b --- /dev/null +++ b/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/lifecycle/StoneLifeCycleListener.kt @@ -0,0 +1,7 @@ +package com.github.klee0kai.stone.lifecycle + +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 new file mode 100644 index 00000000..15998e94 --- /dev/null +++ b/stone_multiplatform/src/commonMain/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);
+ *
+ * }
+`
* + */ +fun interface StoneLifeCycleOwner { + + fun subscribe(listener: StoneLifeCycleListener) + +} 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 new file mode 100644 index 00000000..d6939165 --- /dev/null +++ b/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/wrappers/AsyncCoroutineProvide.kt @@ -0,0 +1,24 @@ +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 +import kotlinx.coroutines.async + +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() + +} \ No newline at end of file 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/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 new file mode 100644 index 00000000..b6895c0d --- /dev/null +++ b/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/wrappers/LazyProvide.kt @@ -0,0 +1,25 @@ +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. + *
`ㅤ@Component
+ * interface Component {
+ *
+ * LazyProvide presenter();
+ *
+ * }
+`
* + */ +class LazyProvide(private val call: Ref) : Ref { + + private var value: T? = null + + 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 new file mode 100644 index 00000000..5799a649 --- /dev/null +++ b/stone_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/wrappers/PhantomProvide.kt @@ -0,0 +1,25 @@ +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, + * 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 = 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/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/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 new file mode 100644 index 00000000..c9b841e6 --- /dev/null +++ b/stone_multiplatform/src/jvmMain/kotlin/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/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/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..653283db --- /dev/null +++ b/stone_multiplatform/src/nativeMain/kotlin/com/github/klee0kai/stone/__hidden__/coroutines/CoroutinesExt.native.kt @@ -0,0 +1,9 @@ +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/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/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/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 98c30799..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( null $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/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..ac46d45c --- /dev/null +++ b/test_feature/companies/consulting/build.gradle.kts @@ -0,0 +1,26 @@ +plugins { + alias(libs.plugins.kotlin.jvm) + alias(libs.plugins.kotlin.ksp) +} + +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_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.java b/test_feature/companies/consulting/src/main/java/com/github/klee0kai/stone/test_feature/consulting/di/ConsultingComponent.java deleted file mode 100644 index 33ee98e9..00000000 --- a/test_feature/companies/consulting/src/main/java/com/github/klee0kai/stone/test_feature/consulting/di/ConsultingComponent.java +++ /dev/null @@ -1,23 +0,0 @@ -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; - -@Component -public interface ConsultingComponent extends ConsultingDependencies { - - DepartmentsModule departmentsModule(); - - AccountingModule accountingModule(); - - ProjectsModule projectsModule(); - - @BindInstance(cache = BindInstance.CacheType.Strong) - WorkCalendar workCalendar(WorkCalendar workCalendar); - - -} 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 new file mode 100644 index 00000000..d20a0a50 --- /dev/null +++ b/test_feature/companies/consulting/src/main/java/com/github/klee0kai/stone/test_feature/consulting/di/ConsultingComponent.kt @@ -0,0 +1,21 @@ +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 + +@Component +interface ConsultingComponent : ConsultingDependencies { + + fun departmentsModule(): DepartmentsModule? + + fun accountingModule(): AccountingModule? + + fun projectsModule(): ProjectsModule? + + @BindInstance(cache = BindInstance.CacheType.Strong) + fun workCalendar(workCalendar: WorkCalendar?): WorkCalendar? +} 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.java deleted file mode 100644 index 772aa65f..00000000 --- a/test_feature/companies/consulting/src/main/java/com/github/klee0kai/stone/test_feature/consulting/di/ConsultingDependencies.java +++ /dev/null @@ -1,8 +0,0 @@ -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; - -public interface ConsultingDependencies extends HrDependencies, PlanningDependencies, AccountingDependencies { -} 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 new file mode 100644 index 00000000..e2e1615b --- /dev/null +++ b/test_feature/companies/consulting/src/main/java/com/github/klee0kai/stone/test_feature/consulting/di/ConsultingDependencies.kt @@ -0,0 +1,7 @@ +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 + +interface ConsultingDependencies : HrDependencies, PlanningDependencies, AccountingDependencies 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.java deleted file mode 100644 index ba1a8d84..00000000 --- a/test_feature/companies/consulting/src/test/java/com/github/klee0kai/stone/test_feature/consulting/dependencies/ProvideDependenciesTests.java +++ /dev/null @@ -1,44 +0,0 @@ -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 static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotNull; - -public class ProvideDependenciesTests { - - @Test - void hrNoDepsTest() { - //Given - ConsultingComponent appDI = Stone.createComponent(ConsultingComponent.class); - HrComponent featureDi = Stone.createComponent(HrComponent.class); - - //When - featureDi.initDeps(appDI); - - //Then - HrDependencies hrDeps = featureDi.hrDependencies(); - assertEquals(appDI, hrDeps); - } - - @Test - void provideLogisticProjectDepsTest() { - //Given - ConsultingComponent appDI = Stone.createComponent(ConsultingComponent.class); - AccountingComponent featureDi = Stone.createComponent(AccountingComponent.class); - - //When - featureDi.initDeps(appDI); - - //Then - 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/ProvideDependenciesTests.kt b/test_feature/companies/consulting/src/test/java/com/github/klee0kai/stone/test_feature/consulting/dependencies/ProvideDependenciesTests.kt new file mode 100644 index 00000000..6d04b583 --- /dev/null +++ b/test_feature/companies/consulting/src/test/java/com/github/klee0kai/stone/test_feature/consulting/dependencies/ProvideDependenciesTests.kt @@ -0,0 +1,45 @@ +package com.github.klee0kai.stone.test_feature.consulting.dependencies + +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 + + +class ProvideDependenciesTests { + + @Test + fun hrNoDepsTest() { + //Given + val appDI: ConsultingComponent = ConsultingComponentStoneComponent() + val featureDi: HrComponent = HrComponentStoneComponent() + + //When + featureDi.initDeps(appDI) + + //Then + val hrDeps = featureDi.hrDependencies() + assertEquals(appDI, hrDeps) + } + + @Test + fun provideLogisticProjectDepsTest() { + //Given + val appDI: ConsultingComponent? = ConsultingComponentStoneComponent() + val featureDi: AccountingComponent = AccountingComponentStoneComponent() + + //When + featureDi.initDeps(appDI) + + //Then + 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.java b/test_feature/companies/consulting/src/test/java/com/github/klee0kai/stone/test_feature/consulting/dependencies/inject/PlanningRunInject2Tests.java deleted file mode 100644 index c36b60b6..00000000 --- a/test_feature/companies/consulting/src/test/java/com/github/klee0kai/stone/test_feature/consulting/dependencies/inject/PlanningRunInject2Tests.java +++ /dev/null @@ -1,54 +0,0 @@ -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 static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotNull; - -public class PlanningRunInject2Tests { - - @Test - public void 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); - - //When - planningRun.start(); - - //Then - assertNotNull(planningRun.logisticProject); - assertNotNull(planningRun.workCalendar); - assertNotNull(planningRun.securityDepartment); - } - - - @Test - public void 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); - - //When - 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); - } - -} 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 new file mode 100644 index 00000000..efd6e2b3 --- /dev/null +++ b/test_feature/companies/consulting/src/test/java/com/github/klee0kai/stone/test_feature/consulting/dependencies/inject/PlanningRunInject2Tests.kt @@ -0,0 +1,53 @@ +package com.github.klee0kai.stone.test_feature.consulting.dependencies.inject + +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 + +class PlanningRunInject2Tests { + + @Test + fun simpleInjectTest() { + //Given + 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() + + //Then + assertNotNull(planningRun.logisticProject) + assertNotNull(planningRun.workCalendar) + assertNotNull(planningRun.securityDepartment) + } + + + @Test + fun commonComponentsInjectTest() { + //Given + 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() + + //Then + 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.java b/test_feature/companies/consulting/src/test/java/com/github/klee0kai/stone/test_feature/consulting/dependencies/inject/PlanningRunInjectTests.java deleted file mode 100644 index b5b6e2bf..00000000 --- a/test_feature/companies/consulting/src/test/java/com/github/klee0kai/stone/test_feature/consulting/dependencies/inject/PlanningRunInjectTests.java +++ /dev/null @@ -1,54 +0,0 @@ -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 static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotNull; - -public class PlanningRunInjectTests { - - @Test - public void 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); - - //When - planningRun.start(); - - //Then - assertNotNull(planningRun.logisticProject); - assertNotNull(planningRun.workCalendar); - assertNotNull(planningRun.securityDepartment); - } - - - @Test - public void 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); - - //When - 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); - } - -} 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 new file mode 100644 index 00000000..4e482b58 --- /dev/null +++ b/test_feature/companies/consulting/src/test/java/com/github/klee0kai/stone/test_feature/consulting/dependencies/inject/PlanningRunInjectTests.kt @@ -0,0 +1,53 @@ +package com.github.klee0kai.stone.test_feature.consulting.dependencies.inject + +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 + +class PlanningRunInjectTests { + + @Test + fun simpleInjectTest() { + //Given + 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() + + //Then + assertNotNull(planningRun.logisticProject) + assertNotNull(planningRun.workCalendar) + assertNotNull(planningRun.securityDepartment) + } + + + @Test + fun commonComponentsInjectTest() { + //Given + 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() + + //Then + 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 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..921c79fa --- /dev/null +++ b/test_feature/finance/api/build.gradle.kts @@ -0,0 +1,10 @@ +plugins { + alias(libs.plugins.kotlin.jvm) +} + +group = "com.github.klee0kai.stone.test_feature.finance" + +tasks.test { + useJUnitPlatform() +} + 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.java deleted file mode 100644 index 65d02ddb..00000000 --- a/test_feature/finance/api/src/main/java/com/github/klee0kai/stone/test_feature/finance/accounting/Accounting.java +++ /dev/null @@ -1,11 +0,0 @@ -package com.github.klee0kai.stone.test_feature.finance.accounting; - -import com.github.klee0kai.stone.test_feature.finance.model.BalanceInfo; - -public interface Accounting { - - BalanceInfo currentBalance(); - - BalanceInfo plannedBalance(long days); - -} 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 new file mode 100644 index 00000000..26cd8414 --- /dev/null +++ b/test_feature/finance/api/src/main/java/com/github/klee0kai/stone/test_feature/finance/accounting/Accounting.kt @@ -0,0 +1,11 @@ +package com.github.klee0kai.stone.test_feature.finance.accounting + +import com.github.klee0kai.stone.test_feature.finance.model.BalanceInfo + +interface Accounting { + + fun currentBalance(): BalanceInfo? + + fun plannedBalance(days: Long): BalanceInfo? + +} 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.java deleted file mode 100644 index 5b33266e..00000000 --- a/test_feature/finance/api/src/main/java/com/github/klee0kai/stone/test_feature/finance/model/BalanceInfo.java +++ /dev/null @@ -1,7 +0,0 @@ -package com.github.klee0kai.stone.test_feature.finance.model; - -public class BalanceInfo { - - public Long balance; - -} 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 new file mode 100644 index 00000000..f57bbd5e --- /dev/null +++ b/test_feature/finance/api/src/main/java/com/github/klee0kai/stone/test_feature/finance/model/BalanceInfo.kt @@ -0,0 +1,5 @@ +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.java b/test_feature/finance/api/src/main/java/com/github/klee0kai/stone/test_feature/finance/model/WorkCalendar.java deleted file mode 100644 index 3c621323..00000000 --- a/test_feature/finance/api/src/main/java/com/github/klee0kai/stone/test_feature/finance/model/WorkCalendar.java +++ /dev/null @@ -1,19 +0,0 @@ -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; - } - -} 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 new file mode 100644 index 00000000..7a982028 --- /dev/null +++ b/test_feature/finance/api/src/main/java/com/github/klee0kai/stone/test_feature/finance/model/WorkCalendar.kt @@ -0,0 +1,11 @@ +package com.github.klee0kai.stone.test_feature.finance.model + +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 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..bf9e4414 --- /dev/null +++ b/test_feature/finance/impl/build.gradle.kts @@ -0,0 +1,20 @@ +plugins { + alias(libs.plugins.kotlin.jvm) + alias(libs.plugins.kotlin.ksp) +} + +group = "com.github.klee0kai.stone.test_feature.finance" + +tasks.test { + useJUnitPlatform() +} + +dependencies { + implementation(project(":test_feature:finance:api")) + implementation(project(":test_feature:hr:api")) + implementation(project(":test_feature:planning:api")) + + 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.java b/test_feature/finance/impl/src/main/java/com/github/klee0kai/stone/test_feature/finance/accounting/AccountingImpl.java deleted file mode 100644 index e40ea467..00000000 --- a/test_feature/finance/impl/src/main/java/com/github/klee0kai/stone/test_feature/finance/accounting/AccountingImpl.java +++ /dev/null @@ -1,15 +0,0 @@ -package com.github.klee0kai.stone.test_feature.finance.accounting; - -import com.github.klee0kai.stone.test_feature.finance.model.BalanceInfo; - -public class AccountingImpl implements Accounting { - @Override - public BalanceInfo currentBalance() { - return null; - } - - @Override - public BalanceInfo plannedBalance(long days) { - return null; - } -} 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 new file mode 100644 index 00000000..5853911a --- /dev/null +++ b/test_feature/finance/impl/src/main/java/com/github/klee0kai/stone/test_feature/finance/accounting/AccountingImpl.kt @@ -0,0 +1,14 @@ +package com.github.klee0kai.stone.test_feature.finance.accounting + +import com.github.klee0kai.stone.test_feature.finance.model.BalanceInfo + +class AccountingImpl : Accounting { + + override fun currentBalance(): BalanceInfo? { + 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.java b/test_feature/finance/impl/src/main/java/com/github/klee0kai/stone/test_feature/finance/di/AccountingComponent.java deleted file mode 100644 index e20014d6..00000000 --- a/test_feature/finance/impl/src/main/java/com/github/klee0kai/stone/test_feature/finance/di/AccountingComponent.java +++ /dev/null @@ -1,16 +0,0 @@ -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; - -@Component -public interface AccountingComponent { - - AccountingDependencies dependencies(); - - AccountingModule accounting(); - - @Init - void initDeps(AccountingDependencies deps); - -} 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 new file mode 100644 index 00000000..fc64877a --- /dev/null +++ b/test_feature/finance/impl/src/main/java/com/github/klee0kai/stone/test_feature/finance/di/AccountingComponent.kt @@ -0,0 +1,14 @@ +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 + +@Component +interface AccountingComponent { + fun dependencies(): AccountingDependencies? + + fun accounting(): AccountingModule? + + @Init + fun initDeps(deps: AccountingDependencies?) +} 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.java deleted file mode 100644 index 4af33b25..00000000 --- a/test_feature/finance/impl/src/main/java/com/github/klee0kai/stone/test_feature/finance/di/AccountingDependencies.java +++ /dev/null @@ -1,20 +0,0 @@ -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; - -@Dependencies -public interface AccountingDependencies { - - SecurityDepartment securityDepartment(); - - SoftwareDepartment softwareDepartment(); - - LogisticProject logisticProject(); - - BuildFactoryProject buildFactoryProject(); - -} 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 new file mode 100644 index 00000000..68993b82 --- /dev/null +++ b/test_feature/finance/impl/src/main/java/com/github/klee0kai/stone/test_feature/finance/di/AccountingDependencies.kt @@ -0,0 +1,20 @@ +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 + +@Dependencies +interface AccountingDependencies { + + fun securityDepartment(): SecurityDepartment? + + fun softwareDepartment(): SoftwareDepartment? + + fun logisticProject(): LogisticProject? + + fun buildFactoryProject(): BuildFactoryProject? + +} 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.java deleted file mode 100644 index ff8c0cef..00000000 --- a/test_feature/finance/impl/src/main/java/com/github/klee0kai/stone/test_feature/finance/di/AccountingModule.java +++ /dev/null @@ -1,19 +0,0 @@ -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; - -@Module -public abstract class AccountingModule { - - @Provide(cache = Provide.CacheType.Soft) - public Accounting accounting() { - return null; - } - - @Provide(cache = Provide.CacheType.Soft) - public abstract AccountingStore accountingStore(); - -} 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 new file mode 100644 index 00000000..25afa1d7 --- /dev/null +++ b/test_feature/finance/impl/src/main/java/com/github/klee0kai/stone/test_feature/finance/di/AccountingModule.kt @@ -0,0 +1,18 @@ +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 + +@Module +abstract class AccountingModule { + + @Provide(cache = Provide.CacheType.Soft) + open fun accounting(): Accounting? { + return null + } + + @Provide(cache = Provide.CacheType.Soft) + abstract fun accountingStore(): AccountingStore? +} 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.java deleted file mode 100644 index e8922639..00000000 --- a/test_feature/finance/impl/src/main/java/com/github/klee0kai/stone/test_feature/finance/store/AccountingStore.java +++ /dev/null @@ -1,4 +0,0 @@ -package com.github.klee0kai.stone.test_feature.finance.store; - -public class 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 new file mode 100644 index 00000000..97850742 --- /dev/null +++ b/test_feature/finance/impl/src/main/java/com/github/klee0kai/stone/test_feature/finance/store/AccountingStore.kt @@ -0,0 +1,3 @@ +package com.github.klee0kai.stone.test_feature.finance.store + +class AccountingStore 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..5bfa0fcb --- /dev/null +++ b/test_feature/hr/api/build.gradle.kts @@ -0,0 +1,10 @@ +plugins { + alias(libs.plugins.kotlin.jvm) +} + +group = "com.github.klee0kai.stone.test_feature.hr" + +tasks.test { + useJUnitPlatform() +} + 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.java deleted file mode 100644 index 59f4c81c..00000000 --- a/test_feature/hr/api/src/main/java/com/github/klee0kai/stone/test_feature/hr/department/Department.java +++ /dev/null @@ -1,20 +0,0 @@ -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 java.util.List; - -public interface Department { - - String getId(); - - DepartmentInfo getInfo(); - - List employers(); - - void hireEmployee(EmployeeInfo employeeInfo); - - void fireEmployee(EmployeeInfo employeeInfo); - -} 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 new file mode 100644 index 00000000..3f227ccd --- /dev/null +++ b/test_feature/hr/api/src/main/java/com/github/klee0kai/stone/test_feature/hr/department/Department.kt @@ -0,0 +1,16 @@ +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 + +interface Department { + val id: String? + + val info: DepartmentInfo? + + fun employers(): MutableList? + + 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.java b/test_feature/hr/api/src/main/java/com/github/klee0kai/stone/test_feature/hr/department/SecurityDepartment.java deleted file mode 100644 index 11ab549b..00000000 --- a/test_feature/hr/api/src/main/java/com/github/klee0kai/stone/test_feature/hr/department/SecurityDepartment.java +++ /dev/null @@ -1,4 +0,0 @@ -package com.github.klee0kai.stone.test_feature.hr.department; - -public interface SecurityDepartment extends Department { -} 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 new file mode 100644 index 00000000..6b252486 --- /dev/null +++ b/test_feature/hr/api/src/main/java/com/github/klee0kai/stone/test_feature/hr/department/SecurityDepartment.kt @@ -0,0 +1,3 @@ +package com.github.klee0kai.stone.test_feature.hr.department + +interface SecurityDepartment : Department 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.java deleted file mode 100644 index e27ef207..00000000 --- a/test_feature/hr/api/src/main/java/com/github/klee0kai/stone/test_feature/hr/department/SoftwareDepartment.java +++ /dev/null @@ -1,4 +0,0 @@ -package com.github.klee0kai.stone.test_feature.hr.department; - -public interface SoftwareDepartment extends 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 new file mode 100644 index 00000000..7725c0be --- /dev/null +++ b/test_feature/hr/api/src/main/java/com/github/klee0kai/stone/test_feature/hr/department/SoftwareDepartment.kt @@ -0,0 +1,3 @@ +package com.github.klee0kai.stone.test_feature.hr.department + +interface SoftwareDepartment : Department 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.java deleted file mode 100644 index 0646e7b6..00000000 --- a/test_feature/hr/api/src/main/java/com/github/klee0kai/stone/test_feature/hr/department/WorkingGroup.java +++ /dev/null @@ -1,4 +0,0 @@ -package com.github.klee0kai.stone.test_feature.hr.department; - -public interface WorkingGroup { -} 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 new file mode 100644 index 00000000..67b30fd5 --- /dev/null +++ b/test_feature/hr/api/src/main/java/com/github/klee0kai/stone/test_feature/hr/department/WorkingGroup.kt @@ -0,0 +1,3 @@ +package com.github.klee0kai.stone.test_feature.hr.department + +interface WorkingGroup 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.java deleted file mode 100644 index 4db30937..00000000 --- a/test_feature/hr/api/src/main/java/com/github/klee0kai/stone/test_feature/hr/model/DepartmentInfo.java +++ /dev/null @@ -1,12 +0,0 @@ -package com.github.klee0kai.stone.test_feature.hr.model; - -public class DepartmentInfo { - - public Long id; - - public String name; - - public String description; - - -} 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 new file mode 100644 index 00000000..1379742b --- /dev/null +++ b/test_feature/hr/api/src/main/java/com/github/klee0kai/stone/test_feature/hr/model/DepartmentInfo.kt @@ -0,0 +1,9 @@ +package com.github.klee0kai.stone.test_feature.hr.model + +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.java b/test_feature/hr/api/src/main/java/com/github/klee0kai/stone/test_feature/hr/model/EmployeeInfo.java deleted file mode 100644 index 7429338d..00000000 --- a/test_feature/hr/api/src/main/java/com/github/klee0kai/stone/test_feature/hr/model/EmployeeInfo.java +++ /dev/null @@ -1,13 +0,0 @@ -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; - -} 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 new file mode 100644 index 00000000..08e435d0 --- /dev/null +++ b/test_feature/hr/api/src/main/java/com/github/klee0kai/stone/test_feature/hr/model/EmployeeInfo.kt @@ -0,0 +1,11 @@ +package com.github.klee0kai.stone.test_feature.hr.model + +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.java b/test_feature/hr/api/src/main/java/com/github/klee0kai/stone/test_feature/hr/model/EmployeeStatus.java deleted file mode 100644 index 49a02cbe..00000000 --- a/test_feature/hr/api/src/main/java/com/github/klee0kai/stone/test_feature/hr/model/EmployeeStatus.java +++ /dev/null @@ -1,7 +0,0 @@ -package com.github.klee0kai.stone.test_feature.hr.model; - -public enum EmployeeStatus { - TERM_CONTRACT, - UNTERM_CONTRACT, - FIRED, -} 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 new file mode 100644 index 00000000..c268a508 --- /dev/null +++ b/test_feature/hr/api/src/main/java/com/github/klee0kai/stone/test_feature/hr/model/EmployeeStatus.kt @@ -0,0 +1,7 @@ +package com.github.klee0kai.stone.test_feature.hr.model + +enum class EmployeeStatus { + TERM_CONTRACT, + UNTERM_CONTRACT, + FIRED, +} 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..6b3e7a92 --- /dev/null +++ b/test_feature/hr/impl/build.gradle.kts @@ -0,0 +1,19 @@ +plugins { + alias(libs.plugins.kotlin.jvm) + alias(libs.plugins.kotlin.ksp) +} + +group = "com.github.klee0kai.stone.test_feature.hr" + +tasks.test { + useJUnitPlatform() +} + +dependencies { + implementation(project(":test_feature:hr:api")) + + 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.java b/test_feature/hr/impl/src/main/java/com/github/klee0kai/stone/test_feature/hr/department/DepartmentImpl.java deleted file mode 100644 index 56c1a3a8..00000000 --- a/test_feature/hr/impl/src/main/java/com/github/klee0kai/stone/test_feature/hr/department/DepartmentImpl.java +++ /dev/null @@ -1,37 +0,0 @@ -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 java.util.List; -import java.util.UUID; - -public class DepartmentImpl implements Department { - - public String uuid = UUID.randomUUID().toString(); - - @Override - public String getId() { - return uuid; - } - - @Override - public DepartmentInfo getInfo() { - return null; - } - - @Override - public List employers() { - return null; - } - - @Override - public void hireEmployee(EmployeeInfo employeeInfo) { - - } - - @Override - public void fireEmployee(EmployeeInfo employeeInfo) { - - } -} 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 new file mode 100644 index 00000000..75a512a3 --- /dev/null +++ b/test_feature/hr/impl/src/main/java/com/github/klee0kai/stone/test_feature/hr/department/DepartmentImpl.kt @@ -0,0 +1,23 @@ +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 java.util.* + +open class DepartmentImpl : Department { + var uuid: String? = UUID.randomUUID().toString() + + override val id: String? get() = uuid + + override val info: DepartmentInfo? get() = null + + override fun employers(): MutableList? { + return null + } + + override fun hireEmployee(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.java b/test_feature/hr/impl/src/main/java/com/github/klee0kai/stone/test_feature/hr/department/SecurityDepartmentImpl.java deleted file mode 100644 index 609d087d..00000000 --- a/test_feature/hr/impl/src/main/java/com/github/klee0kai/stone/test_feature/hr/department/SecurityDepartmentImpl.java +++ /dev/null @@ -1,5 +0,0 @@ -package com.github.klee0kai.stone.test_feature.hr.department; - -public class SecurityDepartmentImpl extends DepartmentImpl implements SecurityDepartment { - -} 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 new file mode 100644 index 00000000..b3d94fab --- /dev/null +++ b/test_feature/hr/impl/src/main/java/com/github/klee0kai/stone/test_feature/hr/department/SecurityDepartmentImpl.kt @@ -0,0 +1,3 @@ +package com.github.klee0kai.stone.test_feature.hr.department + +class SecurityDepartmentImpl : DepartmentImpl(), SecurityDepartment 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.java deleted file mode 100644 index 38bd4ce4..00000000 --- a/test_feature/hr/impl/src/main/java/com/github/klee0kai/stone/test_feature/hr/department/SoftwareDepartmentImpl.java +++ /dev/null @@ -1,5 +0,0 @@ -package com.github.klee0kai.stone.test_feature.hr.department; - -public class SoftwareDepartmentImpl extends DepartmentImpl implements SoftwareDepartment { - -} 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 new file mode 100644 index 00000000..f25e212f --- /dev/null +++ b/test_feature/hr/impl/src/main/java/com/github/klee0kai/stone/test_feature/hr/department/SoftwareDepartmentImpl.kt @@ -0,0 +1,3 @@ +package com.github.klee0kai.stone.test_feature.hr.department + +class SoftwareDepartmentImpl : DepartmentImpl(), SoftwareDepartment 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.java deleted file mode 100644 index 9bfbc306..00000000 --- a/test_feature/hr/impl/src/main/java/com/github/klee0kai/stone/test_feature/hr/di/DepartmentsModule.java +++ /dev/null @@ -1,30 +0,0 @@ -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; - -@Module -public class DepartmentsModule { - - @Provide(cache = Provide.CacheType.Strong) - public EmployeesStore employeesStore() { - return new EmployeesStore(); - } - - - @Provide(cache = Provide.CacheType.Soft) - public SecurityDepartment securityDepartment() { - return new SecurityDepartmentImpl(); - } - - @Provide(cache = Provide.CacheType.Soft) - public SoftwareDepartment softwareDepartment() { - return new SoftwareDepartmentImpl(); - } - -} 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 new file mode 100644 index 00000000..8c48ef98 --- /dev/null +++ b/test_feature/hr/impl/src/main/java/com/github/klee0kai/stone/test_feature/hr/di/DepartmentsModule.kt @@ -0,0 +1,29 @@ +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 + +@Module +interface DepartmentsModule { + + @Provide(cache = Provide.CacheType.Strong) + fun employeesStore(): EmployeesStore { + return EmployeesStore() + } + + + @Provide(cache = Provide.CacheType.Soft) + fun securityDepartment(): SecurityDepartment { + return SecurityDepartmentImpl() + } + + @Provide(cache = Provide.CacheType.Soft) + fun softwareDepartment(): SoftwareDepartment { + return SoftwareDepartmentImpl() + } +} 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.java deleted file mode 100644 index 7158c96f..00000000 --- a/test_feature/hr/impl/src/main/java/com/github/klee0kai/stone/test_feature/hr/di/HrComponent.java +++ /dev/null @@ -1,19 +0,0 @@ -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; - -@Component -public interface HrComponent { - - DepartmentsModule departmentsModule(); - - HrDependencies hrDependencies(); - - EmployeesStore employeesStore(); - - @Init - void initDeps(HrDependencies deps); - -} 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 new file mode 100644 index 00000000..2ef05b22 --- /dev/null +++ b/test_feature/hr/impl/src/main/java/com/github/klee0kai/stone/test_feature/hr/di/HrComponent.kt @@ -0,0 +1,17 @@ +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 + +@Component +interface HrComponent { + fun departmentsModule(): DepartmentsModule? + + fun hrDependencies(): HrDependencies? + + fun employeesStore(): EmployeesStore? + + @Init + fun initDeps(deps: HrDependencies?) +} 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.java deleted file mode 100644 index 94b3c326..00000000 --- a/test_feature/hr/impl/src/main/java/com/github/klee0kai/stone/test_feature/hr/di/HrDependencies.java +++ /dev/null @@ -1,9 +0,0 @@ -package com.github.klee0kai.stone.test_feature.hr.di; - -import com.github.klee0kai.stone.annotations.dependencies.Dependencies; - -@Dependencies -public interface 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 new file mode 100644 index 00000000..1927ce85 --- /dev/null +++ b/test_feature/hr/impl/src/main/java/com/github/klee0kai/stone/test_feature/hr/di/HrDependencies.kt @@ -0,0 +1,6 @@ +package com.github.klee0kai.stone.test_feature.hr.di + +import com.github.klee0kai.stone.annotations.dependencies.Dependencies + +@Dependencies +interface HrDependencies 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.java deleted file mode 100644 index 2fb22d13..00000000 --- a/test_feature/hr/impl/src/main/java/com/github/klee0kai/stone/test_feature/hr/store/EmployeesStore.java +++ /dev/null @@ -1,4 +0,0 @@ -package com.github.klee0kai.stone.test_feature.hr.store; - -public class EmployeesStore { -} 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 new file mode 100644 index 00000000..e3efc06f --- /dev/null +++ b/test_feature/hr/impl/src/main/java/com/github/klee0kai/stone/test_feature/hr/store/EmployeesStore.kt @@ -0,0 +1,3 @@ +package com.github.klee0kai.stone.test_feature.hr.store + +class EmployeesStore 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..f1f36e5d --- /dev/null +++ b/test_feature/planning/api/build.gradle.kts @@ -0,0 +1,11 @@ +plugins { + alias(libs.plugins.kotlin.jvm) +} + +group = "com.github.klee0kai.stone.test_feature.planning" + +tasks.test { + useJUnitPlatform() +} + + 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.java deleted file mode 100644 index 45149b2a..00000000 --- a/test_feature/planning/api/src/main/java/com/github/klee0kai/stone/test_feature/planning/model/ProjectInfo.java +++ /dev/null @@ -1,4 +0,0 @@ -package com.github.klee0kai.stone.test_feature.planning.model; - -public class ProjectInfo { -} 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 new file mode 100644 index 00000000..1081f23f --- /dev/null +++ b/test_feature/planning/api/src/main/java/com/github/klee0kai/stone/test_feature/planning/model/ProjectInfo.kt @@ -0,0 +1,3 @@ +package com.github.klee0kai.stone.test_feature.planning.model + +class ProjectInfo 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.java deleted file mode 100644 index 4f914eb3..00000000 --- a/test_feature/planning/api/src/main/java/com/github/klee0kai/stone/test_feature/planning/model/TaskInfo.java +++ /dev/null @@ -1,4 +0,0 @@ -package com.github.klee0kai.stone.test_feature.planning.model; - -public class TaskInfo { -} 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 new file mode 100644 index 00000000..e675da01 --- /dev/null +++ b/test_feature/planning/api/src/main/java/com/github/klee0kai/stone/test_feature/planning/model/TaskInfo.kt @@ -0,0 +1,3 @@ +package com.github.klee0kai.stone.test_feature.planning.model + +class TaskInfo 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.java deleted file mode 100644 index e9dee39a..00000000 --- a/test_feature/planning/api/src/main/java/com/github/klee0kai/stone/test_feature/planning/project/BuildFactoryProject.java +++ /dev/null @@ -1,4 +0,0 @@ -package com.github.klee0kai.stone.test_feature.planning.project; - -public interface BuildFactoryProject extends Project { -} 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 new file mode 100644 index 00000000..e8fdc0fc --- /dev/null +++ b/test_feature/planning/api/src/main/java/com/github/klee0kai/stone/test_feature/planning/project/BuildFactoryProject.kt @@ -0,0 +1,3 @@ +package com.github.klee0kai.stone.test_feature.planning.project + +interface BuildFactoryProject : Project 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.java deleted file mode 100644 index 35a08b1a..00000000 --- a/test_feature/planning/api/src/main/java/com/github/klee0kai/stone/test_feature/planning/project/LogisticProject.java +++ /dev/null @@ -1,4 +0,0 @@ -package com.github.klee0kai.stone.test_feature.planning.project; - -public interface LogisticProject extends 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 new file mode 100644 index 00000000..fb704ac3 --- /dev/null +++ b/test_feature/planning/api/src/main/java/com/github/klee0kai/stone/test_feature/planning/project/LogisticProject.kt @@ -0,0 +1,3 @@ +package com.github.klee0kai.stone.test_feature.planning.project + +interface LogisticProject : Project 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.java deleted file mode 100644 index db1b25bb..00000000 --- a/test_feature/planning/api/src/main/java/com/github/klee0kai/stone/test_feature/planning/project/Project.java +++ /dev/null @@ -1,16 +0,0 @@ -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; - -public interface Project { - - String getId(); - - ProjectInfo projectInfo(); - - void addTask(TaskInfo taskInfo); - - TaskInfo findTask(String taskId); - -} 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 new file mode 100644 index 00000000..3c36cff5 --- /dev/null +++ b/test_feature/planning/api/src/main/java/com/github/klee0kai/stone/test_feature/planning/project/Project.kt @@ -0,0 +1,15 @@ +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 + +interface Project { + + val id: String? + + fun projectInfo(): ProjectInfo? + + fun addTask(taskInfo: TaskInfo?) + + fun findTask(taskId: String?): TaskInfo? +} 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..9f31db36 --- /dev/null +++ b/test_feature/planning/impl/build.gradle.kts @@ -0,0 +1,20 @@ +plugins { + alias(libs.plugins.kotlin.jvm) + alias(libs.plugins.kotlin.ksp) +} + +group = "com.github.klee0kai.stone.test_feature.planning" + +tasks.test { + useJUnitPlatform() +} + +dependencies { + implementation(project(":test_feature:planning:api")) + implementation(project(":test_feature:finance:api")) + implementation(project(":test_feature:hr:api")) + + 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.java b/test_feature/planning/impl/src/main/java/com/github/klee0kai/stone/test_feature/planning/PlanningRun.java deleted file mode 100644 index 57a56e87..00000000 --- a/test_feature/planning/impl/src/main/java/com/github/klee0kai/stone/test_feature/planning/PlanningRun.java +++ /dev/null @@ -1,31 +0,0 @@ -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 javax.inject.Inject; - -public class PlanningRun { - - @Inject - public WorkCalendar workCalendar; - - @Inject - public LogisticProject logisticProject; - - @Inject - public SecurityDepartment securityDepartment; - - private final PlanningComponent component; - - public PlanningRun(PlanningComponent component) { - this.component = component; - } - - public void start() { - component.inject(this); - } - -} 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 new file mode 100644 index 00000000..a5f002d7 --- /dev/null +++ b/test_feature/planning/impl/src/main/java/com/github/klee0kai/stone/test_feature/planning/PlanningRun.kt @@ -0,0 +1,23 @@ +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 javax.inject.Inject + +class PlanningRun(private val component: PlanningComponent) { + + @Inject + var workCalendar: WorkCalendar? = null + + @Inject + var logisticProject: LogisticProject? = null + + @Inject + var securityDepartment: SecurityDepartment? = null + + fun start() { + component.inject(this) + } +} 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.java deleted file mode 100644 index 3123a356..00000000 --- a/test_feature/planning/impl/src/main/java/com/github/klee0kai/stone/test_feature/planning/di/PlanningComponent.java +++ /dev/null @@ -1,19 +0,0 @@ -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; - -@Component -public interface PlanningComponent { - - PlanningDependencies dependencies(); - - ProjectsModule projectsModule(); - - void inject(PlanningRun planningRun); - - @Init - void initDep(PlanningDependencies planningRun); - -} 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 new file mode 100644 index 00000000..ab04d5cb --- /dev/null +++ b/test_feature/planning/impl/src/main/java/com/github/klee0kai/stone/test_feature/planning/di/PlanningComponent.kt @@ -0,0 +1,17 @@ +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 + +@Component +interface PlanningComponent { + fun dependencies(): PlanningDependencies? + + fun projectsModule(): ProjectsModule? + + fun inject(planningRun: PlanningRun?) + + @Init + fun initDep(planningRun: PlanningDependencies?) +} 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.java deleted file mode 100644 index 1c5c4133..00000000 --- a/test_feature/planning/impl/src/main/java/com/github/klee0kai/stone/test_feature/planning/di/PlanningDependencies.java +++ /dev/null @@ -1,14 +0,0 @@ -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; - -@Dependencies -public interface PlanningDependencies { - - WorkCalendar workCalendar(); - - SecurityDepartment securityDepartment(); - -} 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 new file mode 100644 index 00000000..9f94e358 --- /dev/null +++ b/test_feature/planning/impl/src/main/java/com/github/klee0kai/stone/test_feature/planning/di/PlanningDependencies.kt @@ -0,0 +1,12 @@ +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 + +@Dependencies +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.java b/test_feature/planning/impl/src/main/java/com/github/klee0kai/stone/test_feature/planning/di/ProjectsModule.java deleted file mode 100644 index a335a900..00000000 --- a/test_feature/planning/impl/src/main/java/com/github/klee0kai/stone/test_feature/planning/di/ProjectsModule.java +++ /dev/null @@ -1,28 +0,0 @@ -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; - -@Module -public abstract class ProjectsModule { - - @Provide(cache = Provide.CacheType.Strong) - public abstract ProjectsStore projectsStore(); - - @Provide(cache = Provide.CacheType.Soft) - public LogisticProject logisticProject() { - return new LogisticProjectImpl(); - } - - @Provide(cache = Provide.CacheType.Soft) - public BuildFactoryProject buildFactoryProject() { - return new BuildFactoryProjectImpl(); - } - - -} 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 new file mode 100644 index 00000000..d072206e --- /dev/null +++ b/test_feature/planning/impl/src/main/java/com/github/klee0kai/stone/test_feature/planning/di/ProjectsModule.kt @@ -0,0 +1,25 @@ +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 + +@Module +abstract class ProjectsModule { + @Provide(cache = Provide.CacheType.Strong) + abstract fun projectsStore(): ProjectsStore? + + @Provide(cache = Provide.CacheType.Soft) + open fun logisticProject(): LogisticProject { + return LogisticProjectImpl() + } + + @Provide(cache = Provide.CacheType.Soft) + 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.java b/test_feature/planning/impl/src/main/java/com/github/klee0kai/stone/test_feature/planning/project/BuildFactoryProjectImpl.java deleted file mode 100644 index b7bce2f0..00000000 --- a/test_feature/planning/impl/src/main/java/com/github/klee0kai/stone/test_feature/planning/project/BuildFactoryProjectImpl.java +++ /dev/null @@ -1,4 +0,0 @@ -package com.github.klee0kai.stone.test_feature.planning.project; - -public class BuildFactoryProjectImpl extends ProjectImpl implements BuildFactoryProject { -} 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 new file mode 100644 index 00000000..01874427 --- /dev/null +++ b/test_feature/planning/impl/src/main/java/com/github/klee0kai/stone/test_feature/planning/project/BuildFactoryProjectImpl.kt @@ -0,0 +1,3 @@ +package com.github.klee0kai.stone.test_feature.planning.project + +class BuildFactoryProjectImpl : ProjectImpl(), BuildFactoryProject 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.java deleted file mode 100644 index 49dcdfea..00000000 --- a/test_feature/planning/impl/src/main/java/com/github/klee0kai/stone/test_feature/planning/project/LogisticProjectImpl.java +++ /dev/null @@ -1,4 +0,0 @@ -package com.github.klee0kai.stone.test_feature.planning.project; - -public class LogisticProjectImpl extends ProjectImpl implements LogisticProject { -} 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 new file mode 100644 index 00000000..b3b40384 --- /dev/null +++ b/test_feature/planning/impl/src/main/java/com/github/klee0kai/stone/test_feature/planning/project/LogisticProjectImpl.kt @@ -0,0 +1,3 @@ +package com.github.klee0kai.stone.test_feature.planning.project + +class LogisticProjectImpl : ProjectImpl(), LogisticProject 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.java deleted file mode 100644 index 93ef9879..00000000 --- a/test_feature/planning/impl/src/main/java/com/github/klee0kai/stone/test_feature/planning/project/ProjectImpl.java +++ /dev/null @@ -1,31 +0,0 @@ -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 java.util.UUID; - -public class ProjectImpl implements Project { - - public UUID uuid = UUID.randomUUID(); - - @Override - public String getId() { - return uuid.toString(); - } - - @Override - public ProjectInfo projectInfo() { - return null; - } - - @Override - public void addTask(TaskInfo taskInfo) { - - } - - @Override - public TaskInfo findTask(String taskId) { - return null; - } -} 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 new file mode 100644 index 00000000..96ed1e09 --- /dev/null +++ b/test_feature/planning/impl/src/main/java/com/github/klee0kai/stone/test_feature/planning/project/ProjectImpl.kt @@ -0,0 +1,23 @@ +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 java.util.* + +open class ProjectImpl : Project { + var uuid: UUID = UUID.randomUUID() + + override val id: String? + get() = uuid.toString() + + override fun projectInfo(): ProjectInfo? { + return null + } + + override fun addTask(taskInfo: TaskInfo?) { + } + + 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.java b/test_feature/planning/impl/src/main/java/com/github/klee0kai/stone/test_feature/planning/store/ProjectsStore.java deleted file mode 100644 index 1d16639c..00000000 --- a/test_feature/planning/impl/src/main/java/com/github/klee0kai/stone/test_feature/planning/store/ProjectsStore.java +++ /dev/null @@ -1,4 +0,0 @@ -package com.github.klee0kai.stone.test_feature.planning.store; - -public class ProjectsStore { -} 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 new file mode 100644 index 00000000..4093d966 --- /dev/null +++ b/test_feature/planning/impl/src/main/java/com/github/klee0kai/stone/test_feature/planning/store/ProjectsStore.kt @@ -0,0 +1,3 @@ +package com.github.klee0kai.stone.test_feature.planning.store + +class ProjectsStore 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..8bc4d7fe --- /dev/null +++ b/test_feature_core_deps/build.gradle.kts @@ -0,0 +1,15 @@ +plugins { + alias(libs.plugins.kotlin.jvm) + alias(libs.plugins.kotlin.ksp) +} + +tasks.test { + useJUnitPlatform() +} + +dependencies { + 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..5d121179 --- /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.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) 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..102c6aa5 --- /dev/null +++ b/tests/build.gradle.kts @@ -0,0 +1,51 @@ +plugins { + alias(libs.plugins.kotlin.multiplatform) + alias(libs.plugins.kotlin.ksp) +} + + +kotlin { + jvm() + js(IR) { + browser() + nodejs() + } + + linuxX64() + mingwX64() + wasmJs { + browser() + nodejs() + } + + sourceSets { + val commonMain by getting { + kotlin.srcDir("build/generated/ksp/metadata/commonMain/kotlin") + + dependencies { + implementation(project(":stone_multiplatform")) + } + } + + val jsMain by getting + val wasmJsMain by getting + + + val commonTest by getting { + dependencies { + implementation(kotlin("test")) + } + } + + } +} + +// Trigger Common Metadata Generation from Native tasks +tasks.matching { it.name.startsWith("ksp") && it.name != "kspCommonMainKotlinMetadata" }.configureEach { + dependsOn("kspCommonMainKotlinMetadata") +} + +dependencies { + kspCommonMainMetadata(project(":stone_ksp")) +} + diff --git a/tests/src/commonMain/kotlin/com/github/klee0kai/test/di/base_forest/ForestComponent.kt b/tests/src/commonMain/kotlin/com/github/klee0kai/test/di/base_forest/ForestComponent.kt new file mode 100644 index 00000000..8b36385d --- /dev/null +++ b/tests/src/commonMain/kotlin/com/github/klee0kai/test/di/base_forest/ForestComponent.kt @@ -0,0 +1,48 @@ +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 + + +@Component +interface ForestComponent { + + fun united(): UnitedModule? + + fun identity(): IdentityModule? + + fun inject(horse: Horse?, stoneLifeCycleOwner: StoneLifeCycleOwner?) + + fun inject(horse: Horse?) + + + fun inject(mowgli: Mowgli?) + + fun inject(snake: Snake?) + + fun inject(school: School?) + + @Init + fun initUnitedModule(unitedModule: UnitedModule?) + + @Init + fun iniAllModules(unitedModule: UnitedModule?, identityModule: IdentityModule?) + + @RunGc + @GcAllScope + fun gcAll() + + @ProtectInjected(timeMillis = 30) + fun protectInjected(horse: Horse?) + + + @ProtectInjected(timeMillis = 30) + fun protectInjected(horse: Mowgli?) + + @ProtectInjected(timeMillis = 30) + fun protectInjected(school: School?) +} diff --git a/tests/src/commonMain/kotlin/com/github/klee0kai/test/di/base_forest/IdentityModule.kt b/tests/src/commonMain/kotlin/com/github/klee0kai/test/di/base_forest/IdentityModule.kt new file mode 100644 index 00000000..c71bb87c --- /dev/null +++ b/tests/src/commonMain/kotlin/com/github/klee0kai/test/di/base_forest/IdentityModule.kt @@ -0,0 +1,21 @@ +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 + + +@Module +interface IdentityModule { + + @Provide(cache = Provide.CacheType.Factory) + fun knowledge(): Knowledge? + + @Provide(cache = Provide.CacheType.Factory) + fun conscience(): Conscience? + + @Provide(cache = Provide.CacheType.Soft) + fun ideology(): Ideology? +} diff --git a/tests/src/commonMain/kotlin/com/github/klee0kai/test/di/base_forest/UnitedBlueModule.kt b/tests/src/commonMain/kotlin/com/github/klee0kai/test/di/base_forest/UnitedBlueModule.kt new file mode 100644 index 00000000..dcc29a2e --- /dev/null +++ b/tests/src/commonMain/kotlin/com/github/klee0kai/test/di/base_forest/UnitedBlueModule.kt @@ -0,0 +1,15 @@ +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 + +@Module +abstract class UnitedBlueModule : UnitedModule() { + + @Provide(cache = Provide.CacheType.Strong) + override fun blood(): Blood? { + return Blood(1) + } + +} diff --git a/tests/src/commonMain/kotlin/com/github/klee0kai/test/di/base_forest/UnitedModule.kt b/tests/src/commonMain/kotlin/com/github/klee0kai/test/di/base_forest/UnitedModule.kt new file mode 100644 index 00000000..21206cc7 --- /dev/null +++ b/tests/src/commonMain/kotlin/com/github/klee0kai/test/di/base_forest/UnitedModule.kt @@ -0,0 +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 + +@Module +abstract class UnitedModule { + + @Provide(cache = Provide.CacheType.Strong) + open fun blood(): Blood? { + return Blood(color = 2) + } + + @Provide(cache = Provide.CacheType.Soft) + abstract fun earth(): Earth? + + @Provide(cache = Provide.CacheType.Weak) + abstract fun history(): History? +} 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 new file mode 100644 index 00000000..a705eb8e --- /dev/null +++ b/tests/src/commonMain/kotlin/com/github/klee0kai/test/di/base_phone/PhoneComponent.kt @@ -0,0 +1,31 @@ +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 + +@Component( + identifiers = [ + DataStorageSize::class, RamSize::class, PhoneOsType::class, PhoneOsVersion::class + ] +) +interface PhoneComponent { + + fun components(): TechModule? + + fun inject(onePhone: OnePhone?) + + fun inject(goodPhone: GoodPhone?, dataStorageSize: DataStorageSize?, ramSize: RamSize?) + + fun inject( + goodPhone: GoodPhone?, + lifeCycleOwner: StoneLifeCycleOwner?, + dataStorageSize: DataStorageSize?, + ramSize: RamSize? + ) +} 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 new file mode 100644 index 00000000..b366d808 --- /dev/null +++ b/tests/src/commonMain/kotlin/com/github/klee0kai/test/di/base_phone/TechModule.kt @@ -0,0 +1,40 @@ +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.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 +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 +interface TechModule { + @Provide(cache = Provide.CacheType.Weak) + fun battery(): Battery? + + @Named("null_args") + @Provide(cache = Provide.CacheType.Weak) + fun dataStorage(): DataStorage? + + @Provide(cache = Provide.CacheType.Weak) + fun dataStorage(size: DataStorageSize?): DataStorage? + + @Provide(cache = Provide.CacheType.Weak) + fun ram(ramSize: RamSize?): Ram? + + @Named("null_args") + @Provide(cache = Provide.CacheType.Weak) + fun ram(): Ram? + + @Named("null_args") + @Provide(cache = Provide.CacheType.Weak) + fun phoneOs(osType: PhoneOsType?): OperationSystem? + + @Provide(cache = Provide.CacheType.Weak) + fun phoneOs(osType: PhoneOsType?, version: PhoneOsVersion?): OperationSystem? +} 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/commonMain/kotlin/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 new file mode 100644 index 00000000..d3acb5fd --- /dev/null +++ b/tests/src/commonMain/kotlin/com/github/klee0kai/test/di/base_phone/identifiers/PhoneOsType.kt @@ -0,0 +1,7 @@ +package com.github.klee0kai.test.di.base_phone.identifiers + +enum class PhoneOsType { + Android, + Ios, + UbuntuTouch, +} 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/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 new file mode 100644 index 00000000..09c41256 --- /dev/null +++ b/tests/src/commonMain/kotlin/com/github/klee0kai/test/di/bindinstance/simple/GodWorkspaceComponent.kt @@ -0,0 +1,34 @@ +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 + +expect fun genGodWorkspaceComponent(): GodWorkspaceComponent + +@Component +interface GodWorkspaceComponent { + + fun sunSystem(): SunSystemModule + + @BindInstance + fun bindPlanet(planet: IPlanet?) + + @BindInstance + fun planet(planet: IPlanet?): IPlanet? + + @BindInstance + fun bindSun(sun: Sun?) + + @BindInstance + fun bindEarth(earth: Earth?) + + @BindInstance + fun bindSaturn(saturn: Saturn?) + + fun providePlanet(): IPlanet? + +} diff --git a/tests/src/commonMain/kotlin/com/github/klee0kai/test/di/bindinstance/simple/SunSystemModule.kt b/tests/src/commonMain/kotlin/com/github/klee0kai/test/di/bindinstance/simple/SunSystemModule.kt new file mode 100644 index 00000000..704d2821 --- /dev/null +++ b/tests/src/commonMain/kotlin/com/github/klee0kai/test/di/bindinstance/simple/SunSystemModule.kt @@ -0,0 +1,24 @@ +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.* + + +@Module +interface SunSystemModule { + @BindInstance + fun sun(): Sun? + + @BindInstance + fun star(): IStar? + + @BindInstance + fun planet(): IPlanet? + + @BindInstance + fun earth(): Earth? + + @BindInstance + fun saturn(): Saturn? +} diff --git a/tests/src/commonMain/kotlin/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 new file mode 100644 index 00000000..f2424b1d --- /dev/null +++ b/tests/src/commonMain/kotlin/com/github/klee0kai/test/di/bindinstance/simple_inject/SevenPlanetComponent.kt @@ -0,0 +1,26 @@ +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 + +@Component +interface SevenPlanetComponent { + fun planets(): SevenPlanetModule? + + fun stars(): StarsModule? + + @BindInstance + fun bind(earth: Earth?) + + @BindInstance + fun bind(mercury: Mercury?) + + @BindInstance + fun bindPlanet(planet: IPlanet?) + + fun inject(moonSky: MoonSky?) +} diff --git a/tests/src/commonMain/kotlin/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 new file mode 100644 index 00000000..d18c690a --- /dev/null +++ b/tests/src/commonMain/kotlin/com/github/klee0kai/test/di/bindinstance/simple_inject/SevenPlanetModule.kt @@ -0,0 +1,19 @@ +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 + +@Module +interface SevenPlanetModule { + @BindInstance + fun earth(): Earth? + + @BindInstance + fun mercury(): Mercury? + + @BindInstance + fun planet(): IPlanet? +} diff --git a/tests/src/commonMain/kotlin/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 new file mode 100644 index 00000000..dbc97295 --- /dev/null +++ b/tests/src/commonMain/kotlin/com/github/klee0kai/test/di/bindinstance/simple_inject/StarsModule.kt @@ -0,0 +1,17 @@ +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 + +@Module +interface StarsModule { + + @BindInstance + fun star(): IStar? + + @BindInstance + fun sun(): Sun? + +} diff --git a/tests/src/commonMain/kotlin/com/github/klee0kai/test/di/bindinstance/singlemethod/PlanetComponent.kt b/tests/src/commonMain/kotlin/com/github/klee0kai/test/di/bindinstance/singlemethod/PlanetComponent.kt new file mode 100644 index 00000000..253e7790 --- /dev/null +++ b/tests/src/commonMain/kotlin/com/github/klee0kai/test/di/bindinstance/singlemethod/PlanetComponent.kt @@ -0,0 +1,23 @@ +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 + +@Component +interface PlanetComponent { + fun sunModule(): SunModule? + + @BindInstance + fun planet(planet: IPlanet?): IPlanet? + + @BindInstance(cache = BindInstance.CacheType.Weak) + fun earth(earth: Earth?): Earth? + + fun providePlanet(): IPlanet? + + @BindInstance + fun bindSun(sun: Sun?) +} 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 new file mode 100644 index 00000000..69ab16b5 --- /dev/null +++ b/tests/src/commonMain/kotlin/com/github/klee0kai/test/di/bindinstance/singlemethod/SunModule.kt @@ -0,0 +1,33 @@ +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.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 + + +@Module +interface SunModule { + + @GcSunScope + @Named("strong") + @BindInstance(cache = BindInstance.CacheType.Strong) + fun sunStrong(sun: Sun?): Sun? + + @GcSunScope + @Named("soft") + @BindInstance(cache = BindInstance.CacheType.Soft) + fun sunSoft(sun: Sun?): Sun? + + + @GcSunScope + @BindInstance + fun sun(sun: Sun?): Sun? + + + @GcSunScope + @BindInstance(cache = BindInstance.CacheType.Weak) + fun star(star: IStar?): IStar? +} diff --git a/tests/src/commonMain/kotlin/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 new file mode 100644 index 00000000..394748a9 --- /dev/null +++ b/tests/src/commonMain/kotlin/com/github/klee0kai/test/di/bindinstance/singlemethod_gc/PlanetRollingComponent.kt @@ -0,0 +1,60 @@ +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 + +@Component +interface PlanetRollingComponent { + + fun sunModule(): SunModule? + + @GcPlanetScope + @BindInstance(cache = BindInstance.CacheType.Strong) + fun earthStrong(earth: Earth?): Earth? + + @GcPlanetScope + @BindInstance(cache = BindInstance.CacheType.Soft) + fun earthSoft(earth: Earth?): Earth? + + @GcPlanetScope + @BindInstance(cache = BindInstance.CacheType.Weak) + fun planet(planet: IPlanet?): IPlanet? + + @GcPlanetScope + @BindInstance(cache = BindInstance.CacheType.Weak) + fun earth(earth: Earth?): Earth? + + fun providePlanet(): IPlanet? + + @RunGc + @GcAllScope + fun gcAll() + + @RunGc + @GcStrongScope + fun gcStrong() + + @RunGc + @GcSoftScope + fun gcSoft() + + @RunGc + @GcWeakScope + fun gcWeak() + + + @RunGc + @GcSoftScope + @GcSunScope + fun gcSoftSun() + + @RunGc + @GcSoftScope + @GcPlanetScope + fun gcSoftPlanets() +} diff --git a/tests/src/commonMain/kotlin/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 new file mode 100644 index 00000000..ee91380d --- /dev/null +++ b/tests/src/commonMain/kotlin/com/github/klee0kai/test/di/bindinstance/singlemethod_inject/StarSkyComponent.kt @@ -0,0 +1,35 @@ +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 +interface StarSkyComponent { + fun starModule(): StarSkyModule? + + @BindInstance + fun planet(planet: IPlanet?): IPlanet? + + @BindInstance + fun earth(earth: Earth?): Earth? + + @BindInstance(cache = BindInstance.CacheType.Weak) + fun mercury(earth: Mercury?): Mercury? + + @RunGc + @GcAllScope + fun gcAll() + + fun inject(moonSky: MoonSky?) + + @ProtectInjected(timeMillis = 50) + fun protectInjected(moonSky: MoonSky?) + +} diff --git a/tests/src/commonMain/kotlin/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 new file mode 100644 index 00000000..bb1fc839 --- /dev/null +++ b/tests/src/commonMain/kotlin/com/github/klee0kai/test/di/bindinstance/singlemethod_inject/StarSkyModule.kt @@ -0,0 +1,21 @@ +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 + + +@Module +interface StarSkyModule { + + @GcSunScope + @BindInstance + fun sun(sun: Sun?): Sun? + + + @GcSunScope + @BindInstance(cache = BindInstance.CacheType.Weak) + fun star(star: IStar?): IStar? +} diff --git a/tests/src/commonMain/kotlin/com/github/klee0kai/test/di/bindinstance/solarsystem/PlanetModule.kt b/tests/src/commonMain/kotlin/com/github/klee0kai/test/di/bindinstance/solarsystem/PlanetModule.kt new file mode 100644 index 00000000..d4eaebdb --- /dev/null +++ b/tests/src/commonMain/kotlin/com/github/klee0kai/test/di/bindinstance/solarsystem/PlanetModule.kt @@ -0,0 +1,28 @@ +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.* + +@Module +open class PlanetModule { + @Provide(cache = Provide.CacheType.Strong) + open fun sun(solarSystem: SolarSystem?): Sun? { + return Sun() + } + + @Provide(cache = Provide.CacheType.Soft) + open fun earth(sun: Sun?): Earth? { + return Earth() + } + + @Provide(cache = Provide.CacheType.Soft) + open fun mercury(sun: Sun?): Mercury? { + return Mercury() + } + + @Provide(cache = Provide.CacheType.Soft) + open fun saturn(sun: Sun?): Saturn? { + return Saturn() + } +} diff --git a/tests/src/commonMain/kotlin/com/github/klee0kai/test/di/bindinstance/solarsystem/SolarSystemComponent.kt b/tests/src/commonMain/kotlin/com/github/klee0kai/test/di/bindinstance/solarsystem/SolarSystemComponent.kt new file mode 100644 index 00000000..113d3f45 --- /dev/null +++ b/tests/src/commonMain/kotlin/com/github/klee0kai/test/di/bindinstance/solarsystem/SolarSystemComponent.kt @@ -0,0 +1,14 @@ +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 + +@Component +interface SolarSystemComponent : SolarSystemDependencies { + + fun planets(): PlanetModule? + + @BindInstance + fun bind(system: SolarSystem?): SolarSystem? +} diff --git a/tests/src/commonMain/kotlin/com/github/klee0kai/test/di/bindinstance/solarsystem/SolarSystemDependencies.kt b/tests/src/commonMain/kotlin/com/github/klee0kai/test/di/bindinstance/solarsystem/SolarSystemDependencies.kt new file mode 100644 index 00000000..ec2ee6c6 --- /dev/null +++ b/tests/src/commonMain/kotlin/com/github/klee0kai/test/di/bindinstance/solarsystem/SolarSystemDependencies.kt @@ -0,0 +1,14 @@ +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 + +interface SolarSystemDependencies { + fun earth(): LazyProvide? + + fun mercury(): LazyProvide? + + fun saturn(): LazyProvide? +} diff --git a/tests/src/commonMain/kotlin/com/github/klee0kai/test/di/earthmirror/EarthComponent.kt b/tests/src/commonMain/kotlin/com/github/klee0kai/test/di/earthmirror/EarthComponent.kt new file mode 100644 index 00000000..5cb67888 --- /dev/null +++ b/tests/src/commonMain/kotlin/com/github/klee0kai/test/di/earthmirror/EarthComponent.kt @@ -0,0 +1,12 @@ +package com.github.klee0kai.test.di.earthmirror + +import com.github.klee0kai.stone.annotations.component.Component +import com.github.klee0kai.test.mowgli.earth.Cave.CaveType + +@Component(identifiers = [CaveType::class, Int::class]) +interface EarthComponent { + + fun east(): EastModule + + fun west(): WestModule +} diff --git a/tests/src/commonMain/kotlin/com/github/klee0kai/test/di/earthmirror/EastModule.kt b/tests/src/commonMain/kotlin/com/github/klee0kai/test/di/earthmirror/EastModule.kt new file mode 100644 index 00000000..edcf56d3 --- /dev/null +++ b/tests/src/commonMain/kotlin/com/github/klee0kai/test/di/earthmirror/EastModule.kt @@ -0,0 +1,15 @@ +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.test.mowgli.earth.Cave.CaveType + +@Module +interface EastModule { + @Provide(cache = Provide.CacheType.Soft) + fun cave(): Cave? + + @Provide(cache = Provide.CacheType.Soft) + fun cave(type: CaveType?, deep: Int?): Cave? +} diff --git a/tests/src/commonMain/kotlin/com/github/klee0kai/test/di/earthmirror/WestModule.kt b/tests/src/commonMain/kotlin/com/github/klee0kai/test/di/earthmirror/WestModule.kt new file mode 100644 index 00000000..9c705765 --- /dev/null +++ b/tests/src/commonMain/kotlin/com/github/klee0kai/test/di/earthmirror/WestModule.kt @@ -0,0 +1,25 @@ +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.test.mowgli.earth.Cave.CaveType + +@Module +abstract class WestModule { + @Provide(cache = Provide.CacheType.Factory) + open fun riverImpl(): IRiver? { + return River() + } + + @Provide(cache = Provide.CacheType.Soft) + open fun mountainImp(): IMountain? { + return Mountain() + } + + @Provide(cache = Provide.CacheType.Soft) + abstract fun cave(): Cave? + + @Provide(cache = Provide.CacheType.Soft) + abstract fun cave(type: CaveType?, deep: Int?): Cave? +} diff --git a/tests/src/commonMain/kotlin/com/github/klee0kai/test/di/gcforest/GcEarthComponent.kt b/tests/src/commonMain/kotlin/com/github/klee0kai/test/di/gcforest/GcEarthComponent.kt new file mode 100644 index 00000000..149f3570 --- /dev/null +++ b/tests/src/commonMain/kotlin/com/github/klee0kai/test/di/gcforest/GcEarthComponent.kt @@ -0,0 +1,33 @@ +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 + +abstract class GcEarthComponent { + + @RunGc + @GcMountainScope + abstract fun gcMountains() + + @RunGc + @GcSoftScope + @GcMountainScope + abstract fun gcSoftMountains() + + @RunGc + @GcStrongScope + @GcMountainScope + abstract fun gcStrongMountains() + + @RunGc + @GcRiverScope + abstract fun gcRivers() + + fun gcMountainsAndRivers() { + gcMountains() + gcRivers() + } +} diff --git a/tests/src/commonMain/kotlin/com/github/klee0kai/test/di/gcforest/GcEarthModule.kt b/tests/src/commonMain/kotlin/com/github/klee0kai/test/di/gcforest/GcEarthModule.kt new file mode 100644 index 00000000..54387b55 --- /dev/null +++ b/tests/src/commonMain/kotlin/com/github/klee0kai/test/di/gcforest/GcEarthModule.kt @@ -0,0 +1,59 @@ +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 + +@Module +abstract class GcEarthModule { + + @GcMountainScope + @Provide(cache = Provide.CacheType.Strong) + abstract fun mountainStrong(): Mountain? + + @GcMountainScope + @Provide(cache = Provide.CacheType.Soft) + abstract fun mountainSoft(): Mountain? + + @GcMountainScope + @Provide(cache = Provide.CacheType.Weak) + abstract fun mountainWeak(): Mountain? + + @GcMountainScope + @Provide(cache = Provide.CacheType.Factory) + open fun mountainFactory(): Mountain? { + return Mountain() + } + + @GcMountainScope + @Provide + abstract fun mountainDefaultFactory(): Mountain? + + @GcMountainScope + abstract fun mountainDefault2Factory(): Mountain? + + @GcRiverScope + @Provide(cache = Provide.CacheType.Strong) + abstract fun riverStrong(): River? + + @GcRiverScope + @Provide(cache = Provide.CacheType.Soft) + abstract fun riverSoft(): River? + + @GcRiverScope + @Provide(cache = Provide.CacheType.Weak) + abstract fun riverWeak(): River? + + @GcRiverScope + @Provide(cache = Provide.CacheType.Factory) + abstract fun riverFactory(): River? + + @GcRiverScope + @Provide + open fun riverDefaultSoft(): River? { + return River() + } +} diff --git a/tests/src/commonMain/kotlin/com/github/klee0kai/test/di/gcforest/GcGodComponent.kt b/tests/src/commonMain/kotlin/com/github/klee0kai/test/di/gcforest/GcGodComponent.kt new file mode 100644 index 00000000..bc1203bb --- /dev/null +++ b/tests/src/commonMain/kotlin/com/github/klee0kai/test/di/gcforest/GcGodComponent.kt @@ -0,0 +1,55 @@ +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 + +@Component +abstract class GcGodComponent : GcEarthComponent() { + abstract fun sunSystem(): GcSunSystemModule? + + abstract fun earth(): GcEarthModule? + + @BindInstance + abstract fun bind(sun: Sun?) + + @BindInstance + abstract fun bind(earth: Earth?) + + @BindInstance + abstract fun bind(saturn: Saturn?) + + + @RunGc + @GcAllScope + abstract fun gcAll() + + @RunGc + @GcStrongScope + abstract fun gcStrong() + + @RunGc + @GcSoftScope + abstract fun gcSoft() + + @RunGc + @GcWeakScope + abstract fun gcWeak() + + @RunGc + @GcSunScope + abstract fun gcSun() + + @RunGc + @GcPlanetScope + abstract fun gcPlanets() + + fun gcSunAndPlanets() { + gcSun() + gcPlanets() + } +} diff --git a/tests/src/commonMain/kotlin/com/github/klee0kai/test/di/gcforest/GcSunSystemModule.kt b/tests/src/commonMain/kotlin/com/github/klee0kai/test/di/gcforest/GcSunSystemModule.kt new file mode 100644 index 00000000..35b46681 --- /dev/null +++ b/tests/src/commonMain/kotlin/com/github/klee0kai/test/di/gcforest/GcSunSystemModule.kt @@ -0,0 +1,30 @@ +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 + +@Module +interface GcSunSystemModule { + @GcSunScope + @BindInstance(cache = BindInstance.CacheType.Strong) + fun sun(): Sun? + + @GcPlanetScope + @BindInstance(cache = BindInstance.CacheType.Strong) + fun planet(): IPlanet? + + @GcPlanetScope + @BindInstance(cache = BindInstance.CacheType.Soft) + fun earth(): Earth? + + + @GcPlanetScope + @BindInstance(cache = BindInstance.CacheType.Weak) + fun saturn(): Saturn? +} 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 new file mode 100644 index 00000000..8cbda2b5 --- /dev/null +++ b/tests/src/commonMain/kotlin/com/github/klee0kai/test/di/gcforest/scopes/GcMountainScope.kt @@ -0,0 +1,9 @@ +package com.github.klee0kai.test.di.gcforest.scopes + +import com.github.klee0kai.stone.Scope + + +@Scope +@Retention(AnnotationRetention.RUNTIME) +@Target(AnnotationTarget.FUNCTION, AnnotationTarget.PROPERTY_GETTER, AnnotationTarget.PROPERTY_SETTER) +annotation class GcMountainScope diff --git a/tests/src/commonMain/kotlin/com/github/klee0kai/test/di/gcforest/scopes/GcPlanetScope.kt b/tests/src/commonMain/kotlin/com/github/klee0kai/test/di/gcforest/scopes/GcPlanetScope.kt new file mode 100644 index 00000000..3e36efbc --- /dev/null +++ b/tests/src/commonMain/kotlin/com/github/klee0kai/test/di/gcforest/scopes/GcPlanetScope.kt @@ -0,0 +1,8 @@ +package com.github.klee0kai.test.di.gcforest.scopes + +import com.github.klee0kai.stone.annotations.component.GcScopeAnnotation + +@GcScopeAnnotation +@Retention(AnnotationRetention.RUNTIME) +@Target(AnnotationTarget.FUNCTION, AnnotationTarget.PROPERTY_GETTER, AnnotationTarget.PROPERTY_SETTER) +annotation class GcPlanetScope 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 new file mode 100644 index 00000000..10d235b0 --- /dev/null +++ b/tests/src/commonMain/kotlin/com/github/klee0kai/test/di/gcforest/scopes/GcRiverScope.kt @@ -0,0 +1,8 @@ +package com.github.klee0kai.test.di.gcforest.scopes + +import com.github.klee0kai.stone.Scope + +@Scope +@Retention(AnnotationRetention.RUNTIME) +@Target(AnnotationTarget.FUNCTION, AnnotationTarget.PROPERTY_GETTER, AnnotationTarget.PROPERTY_SETTER) +annotation class GcRiverScope 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 new file mode 100644 index 00000000..479af8f4 --- /dev/null +++ b/tests/src/commonMain/kotlin/com/github/klee0kai/test/di/gcforest/scopes/GcSunScope.kt @@ -0,0 +1,8 @@ +package com.github.klee0kai.test.di.gcforest.scopes + +import com.github.klee0kai.stone.Scope + +@Scope +@Retention(AnnotationRetention.RUNTIME) +@Target(AnnotationTarget.FUNCTION, AnnotationTarget.PROPERTY_GETTER, AnnotationTarget.PROPERTY_SETTER) +annotation class GcSunScope diff --git a/tests/src/commonMain/kotlin/com/github/klee0kai/test/di/house/nulls/HouseNullsComponent.kt b/tests/src/commonMain/kotlin/com/github/klee0kai/test/di/house/nulls/HouseNullsComponent.kt new file mode 100644 index 00000000..6b362891 --- /dev/null +++ b/tests/src/commonMain/kotlin/com/github/klee0kai/test/di/house/nulls/HouseNullsComponent.kt @@ -0,0 +1,11 @@ +package com.github.klee0kai.test.di.house.nulls + +import com.github.klee0kai.stone.annotations.component.Component +import com.github.klee0kai.test.house.House + +@Component +interface HouseNullsComponent { + fun module(): HouseNullsModule? + + fun house(): House? +} diff --git a/tests/src/commonMain/kotlin/com/github/klee0kai/test/di/house/nulls/HouseNullsModule.kt b/tests/src/commonMain/kotlin/com/github/klee0kai/test/di/house/nulls/HouseNullsModule.kt new file mode 100644 index 00000000..95e8229a --- /dev/null +++ b/tests/src/commonMain/kotlin/com/github/klee0kai/test/di/house/nulls/HouseNullsModule.kt @@ -0,0 +1,16 @@ +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 + +@Module +open class HouseNullsModule { + open fun kichen(): Kichen? { + return Kichen(null, null, null) + } + + open fun house(kichen: Kichen?): House? { + return House(kichen, null, null, null) + } +} diff --git a/tests/src/commonMain/kotlin/com/github/klee0kai/test/di/house/simple/AreasModule.kt b/tests/src/commonMain/kotlin/com/github/klee0kai/test/di/house/simple/AreasModule.kt new file mode 100644 index 00000000..f02ee3af --- /dev/null +++ b/tests/src/commonMain/kotlin/com/github/klee0kai/test/di/house/simple/AreasModule.kt @@ -0,0 +1,28 @@ +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.* + +@Module +abstract class AreasModule { + @Provide(cache = Provide.CacheType.Soft) + abstract fun cookingArea(): CookingArea? + + @Provide(cache = Provide.CacheType.Soft) + abstract fun sinkArea(): SinkArea? + + @Provide(cache = Provide.CacheType.Factory) + abstract fun storeArea( + type: StoreAreaType?, + cookware: Cookware?, + clothes: Clothes?, + sanitizers: Sanitizers? + ): StoreArea? + + @Provide(cache = Provide.CacheType.Soft) + abstract fun garageStore(cookware: Cookware?, clothes: Clothes?, sanitizers: Sanitizers?): GarageStore? +} diff --git a/tests/src/commonMain/kotlin/com/github/klee0kai/test/di/house/simple/HouseComponent.kt b/tests/src/commonMain/kotlin/com/github/klee0kai/test/di/house/simple/HouseComponent.kt new file mode 100644 index 00000000..23e4f698 --- /dev/null +++ b/tests/src/commonMain/kotlin/com/github/klee0kai/test/di/house/simple/HouseComponent.kt @@ -0,0 +1,32 @@ +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 + +@Component(identifiers = [StoreAreaType::class]) +interface HouseComponent { + fun module(): HouseModule? + + @ModuleOriginFactory + fun moduleFactory(): HouseModule? + + fun rooms(): RoomsModule? + + fun area(): AreasModule? + + fun tools(): ToolsModule? + + fun house(): House? + + fun sanitizers(): Sanitizers + + fun house(type: StoreAreaType?): House + + fun inject(storeAreaType: StoreAreaType?, inHouse: InHouse?) + + fun inject(inHouse: InHouse?) +} diff --git a/tests/src/commonMain/kotlin/com/github/klee0kai/test/di/house/simple/HouseModule.kt b/tests/src/commonMain/kotlin/com/github/klee0kai/test/di/house/simple/HouseModule.kt new file mode 100644 index 00000000..cd3949fe --- /dev/null +++ b/tests/src/commonMain/kotlin/com/github/klee0kai/test/di/house/simple/HouseModule.kt @@ -0,0 +1,15 @@ +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 + +@Module +interface HouseModule { + @Provide(cache = Provide.CacheType.Soft) + fun house(kichen: Kichen?, bathRoom: BathRoom?, bedRoom: BedRoom?, garage: Garage?): House? +} diff --git a/tests/src/commonMain/kotlin/com/github/klee0kai/test/di/house/simple/RoomsModule.kt b/tests/src/commonMain/kotlin/com/github/klee0kai/test/di/house/simple/RoomsModule.kt new file mode 100644 index 00000000..5464827d --- /dev/null +++ b/tests/src/commonMain/kotlin/com/github/klee0kai/test/di/house/simple/RoomsModule.kt @@ -0,0 +1,27 @@ +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 + +@Module +interface RoomsModule { + @Provide(cache = Provide.CacheType.Soft) + fun kitchen(cookingArea: CookingArea?, sinkArea: SinkArea?, storeArea: StoreArea?): Kichen? + + @Provide(cache = Provide.CacheType.Soft) + fun bathRoom(storeArea: StoreArea?): BathRoom? + + @Provide(cache = Provide.CacheType.Soft) + fun bedRoom(storeArea: StoreArea?): BedRoom? + + @Provide(cache = Provide.CacheType.Soft) + fun garage(garageStore: GarageStore?): Garage? +} diff --git a/tests/src/commonMain/kotlin/com/github/klee0kai/test/di/house/simple/ToolsModule.kt b/tests/src/commonMain/kotlin/com/github/klee0kai/test/di/house/simple/ToolsModule.kt new file mode 100644 index 00000000..b2cd63ce --- /dev/null +++ b/tests/src/commonMain/kotlin/com/github/klee0kai/test/di/house/simple/ToolsModule.kt @@ -0,0 +1,19 @@ +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 + +@Module +interface ToolsModule { + @Provide(cache = Provide.CacheType.Factory) + fun cookware(): Cookware? + + @Provide(cache = Provide.CacheType.Factory) + fun clothes(): Clothes? + + @Provide(cache = Provide.CacheType.Factory) + fun sanitizers(): Sanitizers? +} diff --git a/tests/src/commonMain/kotlin/com/github/klee0kai/test/di/swcache/SwitchCacheComponent.kt b/tests/src/commonMain/kotlin/com/github/klee0kai/test/di/swcache/SwitchCacheComponent.kt new file mode 100644 index 00000000..ebe2ee9f --- /dev/null +++ b/tests/src/commonMain/kotlin/com/github/klee0kai/test/di/swcache/SwitchCacheComponent.kt @@ -0,0 +1,31 @@ +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 + +@Component +interface SwitchCacheComponent { + fun earth(): GcEarthModule? + + @GcAllScope + @SwitchCache(cache = SwitchCache.CacheType.Weak) + fun allWeak() + + + @GcAllScope + @SwitchCache(cache = SwitchCache.CacheType.Strong, timeMillis = 100) + fun allStrongFewMillis() + + + @GcStrongScope + @SwitchCache(cache = SwitchCache.CacheType.Weak) + fun strongToWeak() + + @GcMountainScope + @SwitchCache(cache = SwitchCache.CacheType.Weak) + fun mountainToWeak() +} 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 new file mode 100644 index 00000000..517c607f --- /dev/null +++ b/tests/src/commonMain/kotlin/com/github/klee0kai/test/di/techfactory/ITechProviderComponent.kt @@ -0,0 +1,40 @@ +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 +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 + +interface ITechProviderComponent { + + fun batteryLazy(): LazyProvide? + + fun batteryProviderIRef(): Ref? + + fun batteryPhantomProvider(): PhantomProvide? + + fun batteryProvider(): Provider? + + fun batterySoft(): SoftRef? + + fun batteryWeak(): WeakRef? + + @Named("null_args") + fun ram(): Ram? + + fun ram(ramSize: RamSize?): Ram? + + @Named("null_args") + fun phoneOs(): OperationSystem? + + fun phoneOs(osType: PhoneOsType?): OperationSystem? + + fun phoneOs(phoneOsType: PhoneOsType?, version: PhoneOsVersion?): OperationSystem? +} diff --git a/tests/src/commonMain/kotlin/com/github/klee0kai/test/di/techfactory/TechFactoryComponent.kt b/tests/src/commonMain/kotlin/com/github/klee0kai/test/di/techfactory/TechFactoryComponent.kt new file mode 100644 index 00000000..2a10e0f7 --- /dev/null +++ b/tests/src/commonMain/kotlin/com/github/klee0kai/test/di/techfactory/TechFactoryComponent.kt @@ -0,0 +1,19 @@ +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 + +@Component( + identifiers = [ + RamSize::class, + DataStorageSize::class, + PhoneOsType::class, + PhoneOsVersion::class, + ] +) +interface TechFactoryComponent : ITechProviderComponent { + fun factory(): TechFactoryModule? +} 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 new file mode 100644 index 00000000..9dfb92b2 --- /dev/null +++ b/tests/src/commonMain/kotlin/com/github/klee0kai/test/di/techfactory/TechFactoryModule.kt @@ -0,0 +1,43 @@ +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.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 +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 +interface TechFactoryModule { + + @Provide(cache = Provide.CacheType.Factory) + 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) + fun ram(): Ram? + + @Provide(cache = Provide.CacheType.Factory) + fun ram(ramSize: RamSize?): Ram? + + + @Named("null_args") + @Provide(cache = Provide.CacheType.Factory) + fun phoneOs(osType: PhoneOsType?): OperationSystem? + + @Provide(cache = Provide.CacheType.Factory) + fun phoneOs(phoneOsType: PhoneOsType?, version: PhoneOsVersion?): OperationSystem? +} 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/commonMain/kotlin/com/github/klee0kai/test/di/wire/WireComponent.kt b/tests/src/commonMain/kotlin/com/github/klee0kai/test/di/wire/WireComponent.kt new file mode 100644 index 00000000..73fd8afc --- /dev/null +++ b/tests/src/commonMain/kotlin/com/github/klee0kai/test/di/wire/WireComponent.kt @@ -0,0 +1,25 @@ +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 + +@Component +abstract class WireComponent { + + abstract fun module(): WireModule? + + abstract fun usb_hdmi(): Wire? + + abstract fun usb_usb(): WeakRef?>? + + abstract fun simple(): Wire<*, *>? + + @BindInstance + abstract fun miniusb_miniusb(wire: Wire?): Wire? + +} diff --git a/tests/src/commonMain/kotlin/com/github/klee0kai/test/di/wire/WireModule.kt b/tests/src/commonMain/kotlin/com/github/klee0kai/test/di/wire/WireModule.kt new file mode 100644 index 00000000..60ea3b48 --- /dev/null +++ b/tests/src/commonMain/kotlin/com/github/klee0kai/test/di/wire/WireModule.kt @@ -0,0 +1,29 @@ +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 + +@Module +abstract class WireModule { + + @Provide(cache = Provide.CacheType.Soft) + abstract fun usb_miniusb(): Wire? + + @Provide(cache = Provide.CacheType.Soft) + abstract fun usb_usb(): Wire? + + @Provide(cache = Provide.CacheType.Soft) + open fun usb_hdmi(): Wire? { + return Wire() + } + + @Provide(cache = Provide.CacheType.Soft) + 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/commonMain/kotlin/com/github/klee0kai/test/house/InHouse.kt b/tests/src/commonMain/kotlin/com/github/klee0kai/test/house/InHouse.kt new file mode 100644 index 00000000..7dbf9441 --- /dev/null +++ b/tests/src/commonMain/kotlin/com/github/klee0kai/test/house/InHouse.kt @@ -0,0 +1,25 @@ +package com.github.klee0kai.test.house + +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 +import com.github.klee0kai.test.house.rooms.Garage + +class InHouse { + + @Inject + var kichen: Kichen? = null + + @Inject + var bathRoom: BathRoom? = null + + @Inject + var bedRoom: BathRoom? = null + + @Inject + var garage: Garage? = null + + @Inject + var bedStoreArea: StoreArea? = null +} diff --git a/tests/src/commonMain/kotlin/com/github/klee0kai/test/house/identifiers/StoreAreaType.kt b/tests/src/commonMain/kotlin/com/github/klee0kai/test/house/identifiers/StoreAreaType.kt new file mode 100644 index 00000000..a582791e --- /dev/null +++ b/tests/src/commonMain/kotlin/com/github/klee0kai/test/house/identifiers/StoreAreaType.kt @@ -0,0 +1,7 @@ +package com.github.klee0kai.test.house.identifiers + +enum class StoreAreaType { + CLOSED, + LOCKER, + CUPBOARD, +} diff --git a/tests/src/commonMain/kotlin/com/github/klee0kai/test/house/kitchen/Kichen.kt b/tests/src/commonMain/kotlin/com/github/klee0kai/test/house/kitchen/Kichen.kt new file mode 100644 index 00000000..7231f126 --- /dev/null +++ b/tests/src/commonMain/kotlin/com/github/klee0kai/test/house/kitchen/Kichen.kt @@ -0,0 +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 kotlin.uuid.ExperimentalUuidApi +import kotlin.uuid.Uuid + +class Kichen( + val cookingArea: CookingArea?, + val sinkArea: SinkArea?, + val storeArea: StoreArea? +) { + 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/commonMain/kotlin/com/github/klee0kai/test/house/kitchen/storagearea/Sanitizers.kt b/tests/src/commonMain/kotlin/com/github/klee0kai/test/house/kitchen/storagearea/Sanitizers.kt new file mode 100644 index 00000000..8c2d2800 --- /dev/null +++ b/tests/src/commonMain/kotlin/com/github/klee0kai/test/house/kitchen/storagearea/Sanitizers.kt @@ -0,0 +1,19 @@ +@file:OptIn(ExperimentalUuidApi::class) + +package com.github.klee0kai.test.house.kitchen.storagearea + +import kotlin.uuid.ExperimentalUuidApi +import kotlin.uuid.Uuid + +class Sanitizers { + + var uuid: String = Uuid.random().toString() + + init { + createCount++ + } + + companion object { + var createCount: Int = 0 + } +} 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/commonMain/kotlin/com/github/klee0kai/test/house/rooms/Garage.kt b/tests/src/commonMain/kotlin/com/github/klee0kai/test/house/rooms/Garage.kt new file mode 100644 index 00000000..1c301199 --- /dev/null +++ b/tests/src/commonMain/kotlin/com/github/klee0kai/test/house/rooms/Garage.kt @@ -0,0 +1,11 @@ +@file:OptIn(ExperimentalUuidApi::class) + +package com.github.klee0kai.test.house.rooms + +import com.github.klee0kai.test.house.kitchen.storagearea.GarageStore +import kotlin.uuid.ExperimentalUuidApi +import kotlin.uuid.Uuid + +class Garage(val garageStore: GarageStore?) { + var uuid: String = Uuid.random().toString() +} 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 new file mode 100644 index 00000000..fce14271 --- /dev/null +++ b/tests/src/commonMain/kotlin/com/github/klee0kai/test/mowgli/MoonSky.kt @@ -0,0 +1,29 @@ +package com.github.klee0kai.test.mowgli + +import com.github.klee0kai.stone.Inject +import com.github.klee0kai.test.mowgli.galaxy.* +import kotlin.jvm.JvmField + +class MoonSky { + + @JvmField + @Inject + var star: IStar? = null + + @JvmField + @Inject + var sun: Sun? = null + + + @JvmField + @Inject + var planet: IPlanet? = null + + @JvmField + @Inject + var mercury: Mercury? = null + + @JvmField + @Inject + var earth: Earth? = null +} 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 new file mode 100644 index 00000000..f2cb93a6 --- /dev/null +++ b/tests/src/commonMain/kotlin/com/github/klee0kai/test/mowgli/School.kt @@ -0,0 +1,30 @@ +package com.github.klee0kai.test.mowgli + +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 +import com.github.klee0kai.test.mowgli.community.History +import com.github.klee0kai.test.mowgli.identity.Knowledge +import kotlin.jvm.JvmField + +class School { + + @JvmField + @Inject + var historyLazyProvide: LazyProvide? = null + + @JvmField + @Inject + var knowledgePhantomProvide2: Ref? = null + + @JvmField + @Inject + var knowledgePhantomProvide3: Provider? = null + + @JvmField + @Inject + var knowledgePhantomProvide: PhantomProvide? = null + +} 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 new file mode 100644 index 00000000..2abc2b66 --- /dev/null +++ b/tests/src/commonMain/kotlin/com/github/klee0kai/test/mowgli/animal/Horse.kt @@ -0,0 +1,40 @@ +package com.github.klee0kai.test.mowgli.animal + +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 +import com.github.klee0kai.test.mowgli.identity.Conscience +import com.github.klee0kai.test.mowgli.identity.Ideology +import com.github.klee0kai.test.mowgli.identity.Knowledge + +open class Horse : IAnimal { + + @Inject + var blood: Blood? = null + + @Inject + var earth: Earth? = null + + @Inject + var history: History? = null + + @Inject + var conscience: Conscience? = null + + @Inject + var knowledge: Knowledge? = null + + @Inject + open var ideology: Ideology? = null + + var methodInjectedConscience: Conscience? = null + + var methodInjectedKnowledge: Knowledge? = null + + @Inject + fun initInject(conscience: Conscience?, knowledge: Knowledge?) { + methodInjectedConscience = conscience + methodInjectedKnowledge = knowledge + } +} diff --git a/tests/src/commonMain/kotlin/com/github/klee0kai/test/mowgli/animal/IAnimal.kt b/tests/src/commonMain/kotlin/com/github/klee0kai/test/mowgli/animal/IAnimal.kt new file mode 100644 index 00000000..77ef45ee --- /dev/null +++ b/tests/src/commonMain/kotlin/com/github/klee0kai/test/mowgli/animal/IAnimal.kt @@ -0,0 +1,3 @@ +package com.github.klee0kai.test.mowgli.animal + +interface IAnimal 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 new file mode 100644 index 00000000..4dbc904a --- /dev/null +++ b/tests/src/commonMain/kotlin/com/github/klee0kai/test/mowgli/animal/Mowgli.kt @@ -0,0 +1,93 @@ +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 +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 kotlin.jvm.JvmField + +class Mowgli : IAnimal { + + @Inject + var blood: Blood? = null + + @Inject + var earth: Earth? = null + + @Inject + var history: History? = null + + @Inject + var conscience: Conscience? = null + + @JvmField + @Inject + var knowledge: Knowledge? = null + + @JvmField + @Inject + var knowledgeWeakRef: WeakRef? = null + + @JvmField + @Inject + var knowledgeSoftRef: SoftRef? = null + + @JvmField + @Inject + var knowledgeLazyProvide: LazyProvide? = null + + @JvmField + @Inject + var knowledgePhantomProvide2: Ref? = null + + @Inject + var knowledgePhantomProvide3: Provider? = null + + @JvmField + @Inject + var knowledgePhantomProvide: PhantomProvide? = null + + @JvmField + var methodKnowledgeWeakRef: WeakRef? = null + + @JvmField + var methodKnowledgeSoftRef: SoftRef? = null + + @JvmField + var methodKnowledgeLazyProvide: LazyProvide? = null + + @JvmField + var methodKnowledgePhantomProvide2: Ref? = null + + @JvmField + var methodKnowledgePhantomProvide3: Provider? = null + + @JvmField + var methodKnowledgePhantomProvide: PhantomProvide? = null + + @Inject + fun refInject(knowledgeWeakRef: WeakRef?, knowledgeSoftRef: SoftRef?) { + methodKnowledgeWeakRef = knowledgeWeakRef + methodKnowledgeSoftRef = knowledgeSoftRef + } + + + @Inject + fun wrapperInject( + knowledgeLazyProvide: LazyProvide?, + knowledgePhantomProvide2: Ref?, + knowledgePhantomProvide3: Provider?, + knowledgePhantomProvide: PhantomProvide? + ) { + methodKnowledgeLazyProvide = knowledgeLazyProvide + methodKnowledgePhantomProvide2 = knowledgePhantomProvide2 + methodKnowledgePhantomProvide3 = knowledgePhantomProvide3 + methodKnowledgePhantomProvide = knowledgePhantomProvide + } +} 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 new file mode 100644 index 00000000..d6475dce --- /dev/null +++ b/tests/src/commonMain/kotlin/com/github/klee0kai/test/mowgli/animal/Snake.kt @@ -0,0 +1,31 @@ +package com.github.klee0kai.test.mowgli.animal + +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 +import com.github.klee0kai.test.mowgli.identity.Conscience +import com.github.klee0kai.test.mowgli.identity.Knowledge +import kotlin.jvm.JvmField + +class Snake : 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 +} 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/commonMain/kotlin/com/github/klee0kai/test/mowgli/earth/Cave.kt b/tests/src/commonMain/kotlin/com/github/klee0kai/test/mowgli/earth/Cave.kt new file mode 100644 index 00000000..5281a4c6 --- /dev/null +++ b/tests/src/commonMain/kotlin/com/github/klee0kai/test/mowgli/earth/Cave.kt @@ -0,0 +1,18 @@ +@file:OptIn(ExperimentalUuidApi::class) + +package com.github.klee0kai.test.mowgli.earth + +import kotlin.uuid.ExperimentalUuidApi +import kotlin.uuid.Uuid + +class Cave : IMountain { + var uuid: String = Uuid.random().toString() + + constructor() + + constructor(type: CaveType?, deep: Int?) + + enum class CaveType { + Solutional, Glacier, Fracture + } +} diff --git a/tests/src/commonMain/kotlin/com/github/klee0kai/test/mowgli/earth/IMountain.kt b/tests/src/commonMain/kotlin/com/github/klee0kai/test/mowgli/earth/IMountain.kt new file mode 100644 index 00000000..48c5dd37 --- /dev/null +++ b/tests/src/commonMain/kotlin/com/github/klee0kai/test/mowgli/earth/IMountain.kt @@ -0,0 +1,3 @@ +package com.github.klee0kai.test.mowgli.earth + +interface IMountain diff --git a/tests/src/commonMain/kotlin/com/github/klee0kai/test/mowgli/earth/IRiver.kt b/tests/src/commonMain/kotlin/com/github/klee0kai/test/mowgli/earth/IRiver.kt new file mode 100644 index 00000000..4eee30db --- /dev/null +++ b/tests/src/commonMain/kotlin/com/github/klee0kai/test/mowgli/earth/IRiver.kt @@ -0,0 +1,3 @@ +package com.github.klee0kai.test.mowgli.earth + +interface IRiver 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/commonMain/kotlin/com/github/klee0kai/test/mowgli/galaxy/IPlanet.kt b/tests/src/commonMain/kotlin/com/github/klee0kai/test/mowgli/galaxy/IPlanet.kt new file mode 100644 index 00000000..2b78c169 --- /dev/null +++ b/tests/src/commonMain/kotlin/com/github/klee0kai/test/mowgli/galaxy/IPlanet.kt @@ -0,0 +1,3 @@ +package com.github.klee0kai.test.mowgli.galaxy + +interface IPlanet diff --git a/tests/src/commonMain/kotlin/com/github/klee0kai/test/mowgli/galaxy/IStar.kt b/tests/src/commonMain/kotlin/com/github/klee0kai/test/mowgli/galaxy/IStar.kt new file mode 100644 index 00000000..17d6230d --- /dev/null +++ b/tests/src/commonMain/kotlin/com/github/klee0kai/test/mowgli/galaxy/IStar.kt @@ -0,0 +1,3 @@ +package com.github.klee0kai.test.mowgli.galaxy + +interface IStar 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/commonMain/kotlin/com/github/klee0kai/test/mowgli/galaxy/SolarSystem.kt b/tests/src/commonMain/kotlin/com/github/klee0kai/test/mowgli/galaxy/SolarSystem.kt new file mode 100644 index 00000000..2150cf1f --- /dev/null +++ b/tests/src/commonMain/kotlin/com/github/klee0kai/test/mowgli/galaxy/SolarSystem.kt @@ -0,0 +1,7 @@ +package com.github.klee0kai.test.mowgli.galaxy + +class SolarSystem { + constructor() + + constructor(sun: Sun?, earth: Earth?) +} 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/commonMain/kotlin/com/github/klee0kai/test/tech/components/DataStorage.kt b/tests/src/commonMain/kotlin/com/github/klee0kai/test/tech/components/DataStorage.kt new file mode 100644 index 00000000..30f04173 --- /dev/null +++ b/tests/src/commonMain/kotlin/com/github/klee0kai/test/tech/components/DataStorage.kt @@ -0,0 +1,24 @@ +@file:OptIn(ExperimentalUuidApi::class) + +package com.github.klee0kai.test.tech.components + +import com.github.klee0kai.test.di.base_phone.identifiers.DataStorageSize +import kotlin.jvm.JvmField +import kotlin.uuid.ExperimentalUuidApi +import kotlin.uuid.Uuid + +class DataStorage { + @JvmField + var uuid: String = Uuid.random().toString() + + @JvmField + val size: String? + + constructor() { + size = null + } + + constructor(size: DataStorageSize?) { + this.size = size?.size + } +} diff --git a/tests/src/commonMain/kotlin/com/github/klee0kai/test/tech/components/OperationSystem.kt b/tests/src/commonMain/kotlin/com/github/klee0kai/test/tech/components/OperationSystem.kt new file mode 100644 index 00000000..8eb609c1 --- /dev/null +++ b/tests/src/commonMain/kotlin/com/github/klee0kai/test/tech/components/OperationSystem.kt @@ -0,0 +1,31 @@ +@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 kotlin.jvm.JvmField +import kotlin.uuid.ExperimentalUuidApi +import kotlin.uuid.Uuid + +class OperationSystem { + + @JvmField + var uuid: String = Uuid.random().toString() + + @JvmField + val phoneOsType: PhoneOsType? + + @JvmField + val version: PhoneOsVersion? + + constructor(phoneOsType: PhoneOsType?) { + this.phoneOsType = phoneOsType + this.version = PhoneOsVersion("default") + } + + constructor(phoneOsType: PhoneOsType?, version: PhoneOsVersion?) { + this.phoneOsType = phoneOsType + this.version = version + } +} diff --git a/tests/src/commonMain/kotlin/com/github/klee0kai/test/tech/components/Ram.kt b/tests/src/commonMain/kotlin/com/github/klee0kai/test/tech/components/Ram.kt new file mode 100644 index 00000000..9f563f19 --- /dev/null +++ b/tests/src/commonMain/kotlin/com/github/klee0kai/test/tech/components/Ram.kt @@ -0,0 +1,22 @@ +@file:OptIn(ExperimentalUuidApi::class) + +package com.github.klee0kai.test.tech.components + +import com.github.klee0kai.test.di.base_phone.identifiers.RamSize +import kotlin.uuid.ExperimentalUuidApi +import kotlin.uuid.Uuid + +open class Ram { + open val uuid: String = Uuid.random().toString() + + + val size: String? + + constructor() { + size = "default" + } + + constructor(ramSize: RamSize?) { + this.size = ramSize?.size + } +} 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 new file mode 100644 index 00000000..4a98b8a3 --- /dev/null +++ b/tests/src/commonMain/kotlin/com/github/klee0kai/test/tech/phone/GoodPhone.kt @@ -0,0 +1,43 @@ +package com.github.klee0kai.test.tech.phone + +import com.github.klee0kai.stone.lifecycle.StoneLifeCycleOwner +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 +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 + +class GoodPhone : ATech() { + + var lifeCycleOwner: StoneLifeCycleOwner = LifecycleUtils.createFromATech(this) + + + @Inject + var battery: Battery? = null + + @Inject + var dataStorage: DataStorage? = null + + @Inject + var ram: Ram? = null + + @Inject + var os: OperationSystem? = null + + fun dropToWater() { + onDrown() + battery = null + dataStorage = null + ram = null + } + + fun broke() { + onBroken() + battery = null + dataStorage = null + ram = null + } + +} 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 new file mode 100644 index 00000000..9af342a1 --- /dev/null +++ b/tests/src/commonMain/kotlin/com/github/klee0kai/test/tech/phone/OnePhone.kt @@ -0,0 +1,59 @@ +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.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 +import com.github.klee0kai.test.tech.phone.base.ATech +import com.github.klee0kai.test.tech.phone.base.ATechLifecycle +import kotlin.jvm.JvmField + +class OnePhone : ATech(), StoneLifeCycleOwner { + + @JvmField + @Inject + var battery: Battery? = null + + @JvmField + @Inject + @Named("null_args") + var dataStorage: DataStorage? = null + + @JvmField + @Inject + @Named("null_args") + var ram: Ram? = null + + + override fun subscribe(listener: StoneLifeCycleListener) { + super.subscribe(object : ATechLifecycle { + override fun onBuy() { + } + + override fun onBroken() { + } + + override fun onDrown() { + listener.protectForInjected(100) + } + }) + } + + + fun dropToWatter() { + onDrown() + battery = null + dataStorage = null + ram = null + } + + fun broke() { + onBroken() + battery = null + dataStorage = null + ram = null + } +} diff --git a/tests/src/commonMain/kotlin/com/github/klee0kai/test/tech/phone/base/ATech.kt b/tests/src/commonMain/kotlin/com/github/klee0kai/test/tech/phone/base/ATech.kt new file mode 100644 index 00000000..b8075e43 --- /dev/null +++ b/tests/src/commonMain/kotlin/com/github/klee0kai/test/tech/phone/base/ATech.kt @@ -0,0 +1,22 @@ +package com.github.klee0kai.test.tech.phone.base + +abstract class ATech { + + private val listeners = mutableListOf() + + fun subscribe(listener: ATechLifecycle?) { + this.listeners.add(listener!!) + } + + fun onBuy() { + for (lis in listeners) lis.onBuy() + } + + fun onBroken() { + for (lis in listeners) lis.onBroken() + } + + fun onDrown() { + for (lis in listeners) lis.onDrown() + } +} diff --git a/tests/src/commonMain/kotlin/com/github/klee0kai/test/tech/phone/base/ATechLifecycle.kt b/tests/src/commonMain/kotlin/com/github/klee0kai/test/tech/phone/base/ATechLifecycle.kt new file mode 100644 index 00000000..eecc256d --- /dev/null +++ b/tests/src/commonMain/kotlin/com/github/klee0kai/test/tech/phone/base/ATechLifecycle.kt @@ -0,0 +1,9 @@ +package com.github.klee0kai.test.tech.phone.base + +interface ATechLifecycle { + fun onBuy() + + fun onBroken() + + fun onDrown() +} diff --git a/tests/src/commonMain/kotlin/com/github/klee0kai/test/tech/phone/base/LifecycleUtils.kt b/tests/src/commonMain/kotlin/com/github/klee0kai/test/tech/phone/base/LifecycleUtils.kt new file mode 100644 index 00000000..a349018f --- /dev/null +++ b/tests/src/commonMain/kotlin/com/github/klee0kai/test/tech/phone/base/LifecycleUtils.kt @@ -0,0 +1,24 @@ +package com.github.klee0kai.test.tech.phone.base + +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 fun onBroken() { + } + + override fun onDrown() { + listener!!.protectForInjected(100) + } + } + ) + } + } +} 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 new file mode 100644 index 00000000..d4673252 --- /dev/null +++ b/tests/src/commonMain/kotlin/com/github/klee0kai/test/wire/Wire.kt @@ -0,0 +1,15 @@ +@file:OptIn(ExperimentalUuidApi::class) + +package com.github.klee0kai.test.wire + +import kotlin.uuid.ExperimentalUuidApi +import kotlin.uuid.Uuid + +class Wire { + + val uuid: String = Uuid.random().toString() + + var input: Input? = null + + var output: Output? = 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 new file mode 100644 index 00000000..c3c1e50a --- /dev/null +++ b/tests/src/commonMain/kotlin/com/github/klee0kai/test/wire/types/Hdmi.kt @@ -0,0 +1,11 @@ +@file:OptIn(ExperimentalUuidApi::class) + +package com.github.klee0kai.test.wire.types + +import kotlin.uuid.ExperimentalUuidApi +import kotlin.uuid.Uuid + + +class Hdmi { + 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 new file mode 100644 index 00000000..27249cda --- /dev/null +++ b/tests/src/commonMain/kotlin/com/github/klee0kai/test/wire/types/MiniUsb.kt @@ -0,0 +1,10 @@ +@file:OptIn(ExperimentalUuidApi::class) + +package com.github.klee0kai.test.wire.types + +import kotlin.uuid.ExperimentalUuidApi +import kotlin.uuid.Uuid + +class MiniUsb { + 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 new file mode 100644 index 00000000..2ba84ebb --- /dev/null +++ b/tests/src/commonMain/kotlin/com/github/klee0kai/test/wire/types/Usb.kt @@ -0,0 +1,10 @@ +@file:OptIn(ExperimentalUuidApi::class) + +package com.github.klee0kai.test.wire.types + +import kotlin.uuid.ExperimentalUuidApi +import kotlin.uuid.Uuid + +class Usb { + val uuid: String = Uuid.random().toString() +} 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 new file mode 100644 index 00000000..04b7782e --- /dev/null +++ b/tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/bindinstance/simple/GodFirstWorkDayTest.kt @@ -0,0 +1,86 @@ +package com.github.klee0kai.stone.test.bindinstance.simple + +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 +import kotlin.test.Test +import kotlin.test.assertEquals +import kotlin.test.assertNull + +class GodFirstWorkDayTest { + + @Test + fun firstCreateSunTest() { + //Given + val DI = genGodWorkspaceComponent() + 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 = genGodWorkspaceComponent() + 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 = genGodWorkspaceComponent() + 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 = genGodWorkspaceComponent() + 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()) + } +} diff --git a/tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/bindinstance/simple/GodTouchTest.kt b/tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/bindinstance/simple/GodTouchTest.kt new file mode 100644 index 00000000..de89b7bc --- /dev/null +++ b/tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/bindinstance/simple/GodTouchTest.kt @@ -0,0 +1,83 @@ +package com.github.klee0kai.stone.test.bindinstance.simple + +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 kotlin.test.Test +import kotlin.test.assertEquals +import kotlin.test.assertNull + + +class GodTouchTest { + + @Test + fun firstCreateSunTest() { + //Given + val DI = GodWorkspaceComponentStoneComponent() + 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 = GodWorkspaceComponentStoneComponent() + 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 = GodWorkspaceComponentStoneComponent() + + 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 = GodWorkspaceComponentStoneComponent() + val earth = Earth() + + //When + DI.planet(earth) + DI.planet(null) + + //Then + assertEquals(earth, DI.planet(null)) + assertEquals(earth, DI.providePlanet()) + } +} 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 new file mode 100644 index 00000000..13528ccb --- /dev/null +++ b/tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/bindinstance/simple_inject/SevenPlanetTests.kt @@ -0,0 +1,33 @@ +package com.github.klee0kai.stone.test.bindinstance.simple_inject + +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 kotlin.test.Test +import kotlin.test.assertEquals + +class SevenPlanetTests { + + @Test + fun moonSkyTest() { + //Given + val component = SevenPlanetComponentStoneComponent() + 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) + } + +} diff --git a/tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/bindinstance/singlemethod/PlanetProvideTests.kt b/tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/bindinstance/singlemethod/PlanetProvideTests.kt new file mode 100644 index 00000000..bf21849c --- /dev/null +++ b/tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/bindinstance/singlemethod/PlanetProvideTests.kt @@ -0,0 +1,80 @@ +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 kotlin.test.Test +import kotlin.test.assertEquals +import kotlin.test.assertNull + +class PlanetProvideTests { + + @Test + fun bindPlanetTest() { + //Given + val DI = PlanetComponentStoneComponent() + 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 = PlanetComponentStoneComponent() + 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 = PlanetComponentStoneComponent() + 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 separateBindEarthTest() { + //Given + val DI = PlanetRollingComponentStoneComponent() + val earth1 = Earth() + val earth2 = Earth() + val earth3 = Earth() + + //When + 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)) + } +} diff --git a/tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/bindinstance/singlemethod/StarProvideTests.kt b/tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/bindinstance/singlemethod/StarProvideTests.kt new file mode 100644 index 00000000..ccfbcf8d --- /dev/null +++ b/tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/bindinstance/singlemethod/StarProvideTests.kt @@ -0,0 +1,61 @@ +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 kotlin.test.Test +import kotlin.test.assertEquals +import kotlin.test.assertNull + +class StarProvideTests { + + @Test + fun bindSunTest() { + //Given + val DI = PlanetComponentStoneComponent() + 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 = PlanetComponentStoneComponent() + 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)) + } + + + @Test + fun separateSunBindingTest() { + //Given + 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) + + //Then + assertEquals(sun1, DI.sunModule().sunStrong(null)) + assertEquals(sun2, DI.sunModule().sunSoft(null)) + assertEquals(sun3, DI.sunModule().sun(null)) + } + +} diff --git a/tests/src/commonTest/kotlin/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 new file mode 100644 index 00000000..cebaa045 --- /dev/null +++ b/tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/bindinstance/singlemethod_inject/MoonSkyTests.kt @@ -0,0 +1,37 @@ +package com.github.klee0kai.stone.test.bindinstance.singlemethod_inject + +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 kotlin.test.Test +import kotlin.test.assertEquals + +class MoonSkyTests { + + @Test + fun moonSkyTest() { + //Given + 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 + val moonSky: MoonSky = MoonSky() + component.inject(moonSky) + + //Then + assertEquals(sun, moonSky.sun) + assertEquals(star, moonSky.star) + assertEquals(earth, moonSky.earth) + assertEquals(planet, moonSky.planet) + } + +} 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 new file mode 100644 index 00000000..df082453 --- /dev/null +++ b/tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/bindinstance/solarsystem/SolarSystemTests.kt @@ -0,0 +1,38 @@ +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 kotlin.test.Test +import kotlin.test.assertEquals +import kotlin.test.assertNotNull + +class SolarSystemTests { + + @Test + fun provideSolarSystemTest() { + //Given + val DI = SolarSystemComponentStoneComponent() + val solarSystem = SolarSystem() + + // When + DI.bind(solarSystem) + + // Then + assertEquals(solarSystem, DI.bind(null)) + } + + + @Test + fun provideEarthTest() { + //Given + val DI = SolarSystemComponentStoneComponent() + val solarSystem = SolarSystem() + + // When + DI.bind(solarSystem) + + // Then + assertNotNull(DI.earth()) + } + +} 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 new file mode 100644 index 00000000..616f52dd --- /dev/null +++ b/tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/cache/EarthCacheTests.kt @@ -0,0 +1,144 @@ +package com.github.klee0kai.stone.test.cache + +import com.github.klee0kai.test.di.gcforest.GcGodComponentStoneComponent +import kotlin.test.Test +import kotlin.test.assertEquals +import kotlin.test.assertNotEquals + +class EarthCacheTests { + + @Test + fun strongCacheTest() { + //Given + val DI = GcGodComponentStoneComponent() + + //When + val mountain1 = DI.earth().mountainStrong() + val mountain2 = DI.earth().mountainStrong() + + //Then + assertEquals( + mountain1?.uuid, + mountain2?.uuid + ) + } + + + @Test + fun softCacheTest() { + //Given + val DI = GcGodComponentStoneComponent() + + //When + val mountain1 = DI.earth().mountainSoft() + val mountain2 = DI.earth().mountainSoft() + + //Then + assertEquals( + mountain1?.uuid, + mountain2?.uuid + ) + } + + @Test + fun weakCacheTest() { + //Given + val DI = GcGodComponentStoneComponent() + + //When + val mountain1 = DI.earth().mountainWeak() + val mountain2 = DI.earth().mountainWeak() + + //Then + assertEquals( + mountain1?.uuid, + mountain2?.uuid + ) + } + + @Test + fun defCacheTest() { + //Given + val DI = GcGodComponentStoneComponent() + + //When + val mountain1 = DI.earth().mountainDefaultFactory() + val mountain2 = DI.earth().mountainDefaultFactory() + + //Then + assertNotEquals( + mountain1?.uuid, + mountain2?.uuid, + "Default is factory providing" + ) + } + + @Test + fun defCache2Test() { + //Given + val DI = GcGodComponentStoneComponent() + + //When + val mountain1 = DI.earth().mountainDefault2Factory() + val mountain2 = DI.earth().mountainDefault2Factory() + + //Then + assertNotEquals( + mountain1?.uuid, + mountain2?.uuid, + "Default is factory providing" + ) + } + + @Test + fun differentMethodDifferentCacheTest() { + //Given + val DI = GcGodComponentStoneComponent() + + //When + val mountainStrong = DI.earth().mountainStrong() + val mountainSoft = DI.earth().mountainSoft() + + //Then + assertNotEquals( + mountainStrong?.uuid, + mountainSoft?.uuid + ) + } + + + @Test + fun factoryNotCacheTest() { + //Given + val DI = GcGodComponentStoneComponent() + + //When + val mountain1 = DI.earth().mountainFactory() + val mountain2 = DI.earth().mountainFactory() + + //Then + assertNotEquals( + mountain1?.uuid, + mountain2?.uuid + ) + } + + + @Test + fun differentDIDifferentCacheTest() { + //Given + val DI1 = GcGodComponentStoneComponent() + val DI2 = GcGodComponentStoneComponent() + + //When + val mountain1 = DI1.earth().mountainStrong() + val mountain2 = DI2.earth().mountainStrong() + + //Then + assertNotEquals( + mountain1?.uuid, + mountain2?.uuid, + ) + } + +} 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 new file mode 100644 index 00000000..594064b1 --- /dev/null +++ b/tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/deps/HouseFactoryTests.kt @@ -0,0 +1,38 @@ +package com.github.klee0kai.stone.test.deps + +import com.github.klee0kai.test.di.house.simple.HouseComponentStoneComponent +import kotlin.test.Test +import kotlin.test.assertEquals +import kotlin.test.assertNotEquals + +class HouseFactoryTests { + + + @Test + fun cacheTest() { + //Given + val di = HouseComponentStoneComponent() + + //when + val house1 = di.module().house(null, null, null, null) + val house2 = di.module().house(null, null, null, null) + + //then + assertEquals(house1?.uuid, house2?.uuid) + } + + + @Test + fun factoryTest() { + //Given + val di = HouseComponentStoneComponent() + + //when + val house1 = di.moduleFactory()?.house(null, null, null, null) + val house2 = di.moduleFactory()?.house(null, null, null, null) + + //then + assertNotEquals(house1?.uuid, house2?.uuid) + } + +} diff --git a/tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/deps/HouseNullsTests.kt b/tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/deps/HouseNullsTests.kt new file mode 100644 index 00000000..73908abb --- /dev/null +++ b/tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/deps/HouseNullsTests.kt @@ -0,0 +1,24 @@ +package com.github.klee0kai.stone.test.deps + +import com.github.klee0kai.test.di.house.nulls.HouseNullsComponentStoneComponent +import kotlin.test.Test +import kotlin.test.assertNull + +class HouseNullsTests { + + @Test + fun buildOnlyKitchenTest() { + //Given + val di = HouseNullsComponentStoneComponent() + + //when + val house = di.house() + + //then + assertNull(house?.bathRoom) + assertNull(house?.kichen?.cookingArea) + assertNull(house?.kichen?.storeArea) + assertNull(house?.kichen?.sinkArea) + } + +} 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 new file mode 100644 index 00000000..187ec1ae --- /dev/null +++ b/tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/deps/HouseTests.kt @@ -0,0 +1,88 @@ +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 kotlin.test.* + +class HouseTests { + + @Test + fun buildHouseTest() { + //Given + val di = HouseComponentStoneComponent() + + //when + val house = di.house() + + //then + assertNotNull(house?.bathRoom) + assertNotNull(house?.kichen?.cookingArea) + assertNotNull(house?.kichen?.storeArea) + assertNotNull(house?.kichen?.sinkArea) + } + + @Test + fun identifiersTest() { + //Given + val di = HouseComponentStoneComponent() + + //when + val house = di.house(StoreAreaType.CLOSED) + + //then + assertEquals(StoreAreaType.CLOSED, house?.kichen?.storeArea?.type) + } + + @Test + fun identifiersNullTest() { + //Given + val di = HouseComponentStoneComponent() + + //when + val house = di.house() + + //then + assertNull(house?.kichen?.storeArea?.type) + } + + + @Test + fun cacheTest() { + //Given + val di = HouseComponentStoneComponent() + + //when + val house1: House? = di.house() + val house2: House? = di.house() + + //then + assertEquals( + house1?.kichen?.uuid, + house2?.kichen?.uuid + ) + } + + + @Test + fun factoryTest() { + //Given + val di = HouseComponentStoneComponent() + + //when + 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 + ) + } +} 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 new file mode 100644 index 00000000..25ce8481 --- /dev/null +++ b/tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/deps/InHouseTests.kt @@ -0,0 +1,97 @@ +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 kotlin.test.* + +class InHouseTests { + + @Test + fun buildHouseTest() { + //Given + val di = HouseComponentStoneComponent() + val inHouse = InHouse() + + //when + di.inject(inHouse) + + //then + assertNotNull(inHouse.bathRoom) + assertNotNull(inHouse.kichen?.cookingArea) + assertNotNull(inHouse.kichen?.storeArea) + assertNotNull(inHouse.kichen?.sinkArea) + assertNotNull(inHouse.bedStoreArea) + } + + @Test + fun identifiersTest() { + //Given + val di = HouseComponentStoneComponent() + val inHouse = InHouse() + + //when + di.inject(StoreAreaType.CLOSED, inHouse) + + + //then + assertEquals(StoreAreaType.CLOSED, inHouse.kichen?.storeArea?.type) + } + + @Test + fun identifiersNullTest() { + //Given + val di = HouseComponentStoneComponent() + val inHouse = InHouse() + + //when + di.inject(inHouse) + + + //then + assertNull(inHouse.kichen?.storeArea?.type) + } + + + @Test + fun cacheTest() { + //Given + val di = HouseComponentStoneComponent() + val inHouse1 = InHouse() + val inHouse2 = InHouse() + + //when + di.inject(inHouse1) + di.inject(inHouse2) + + //then + assertEquals( + inHouse1.kichen?.uuid, + inHouse2.kichen?.uuid + ) + } + + + @Test + fun factoryTest() { + //Given + val di = HouseComponentStoneComponent() + val inHouse1 = InHouse() + val inHouse2 = InHouse() + + //when + 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, + ) + } + +} 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 new file mode 100644 index 00000000..3bd99a44 --- /dev/null +++ b/tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/identifiers/GoodPhoneInjectTests.kt @@ -0,0 +1,41 @@ +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.DataStorageSize +import com.github.klee0kai.test.di.base_phone.identifiers.RamSize +import com.github.klee0kai.test.tech.phone.GoodPhone +import kotlin.test.Test +import kotlin.test.assertEquals + +class GoodPhoneInjectTests { + + @Test + fun createGoodPhoneTest() { + //Given + val DI = PhoneComponentStoneComponent() + 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 = PhoneComponentStoneComponent() + 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) + } + +} 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 new file mode 100644 index 00000000..61b296c6 --- /dev/null +++ b/tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/identifiers/MultiIdentifiersTests.kt @@ -0,0 +1,65 @@ +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 kotlin.test.Test +import kotlin.test.assertEquals +import kotlin.test.assertNotEquals + +class MultiIdentifiersTests { + + @Test + fun differentCreatePhoneTest() { + //Given + val DI = PhoneComponentStoneComponent() + + //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 = PhoneComponentStoneComponent() + + //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 = PhoneComponentStoneComponent() + + //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 = PhoneComponentStoneComponent() + + //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) + } + +} 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 new file mode 100644 index 00000000..a81523d5 --- /dev/null +++ b/tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/identifiers/TechComponentsTests.kt @@ -0,0 +1,66 @@ +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 kotlin.test.Test +import kotlin.test.assertEquals +import kotlin.test.assertNotEquals + +class TechComponentsTests { + + @Test + fun differentCreateTest() { + //Given + val DI = PhoneComponentStoneComponent() + + //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 = PhoneComponentStoneComponent() + + //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 = PhoneComponentStoneComponent() + + //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 = PhoneComponentStoneComponent() + + //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) + } + +} 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 new file mode 100644 index 00000000..8fdc8adb --- /dev/null +++ b/tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/identifiers/TechFactoryComponentTests.kt @@ -0,0 +1,100 @@ +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.PhoneOsVersion +import com.github.klee0kai.test.di.base_phone.identifiers.RamSize +import com.github.klee0kai.test.di.techfactory.TechFactoryComponentStoneComponent +import kotlin.test.Test +import kotlin.test.assertEquals +import kotlin.test.assertNotEquals +import kotlin.test.assertNull + +class TechFactoryComponentTests { + + @Test + fun nonArgProvideTest() { + //Given + val DI = TechFactoryComponentStoneComponent() + + //When + val ram = DI.ram() + + //Then + assertEquals("default", ram?.size) + } + + @Test + fun singleArgProvideTest() { + //Given + val DI = TechFactoryComponentStoneComponent() + + + //When + val ram = DI.ram(RamSize("4G")) + + //Then + assertEquals("4G", ram?.size) + } + + + @Test + fun nullGenerateArgProvideTest() { + //Given + val DI = TechFactoryComponentStoneComponent() + + + //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 = TechFactoryComponentStoneComponent() + + + //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 = TechFactoryComponentStoneComponent() + + + //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 = TechFactoryComponentStoneComponent() + + //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) + } + +} 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 new file mode 100644 index 00000000..40a4e563 --- /dev/null +++ b/tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/identifiers/TechFactoryTests.kt @@ -0,0 +1,39 @@ +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 kotlin.test.Test +import kotlin.test.assertNotEquals + +class TechFactoryTests { + + @Test + fun differentCreateTest() { + //Given + val DI = TechFactoryComponentStoneComponent() + + //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 = TechFactoryComponentStoneComponent() + + //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) + } +} 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 new file mode 100644 index 00000000..a74a49a7 --- /dev/null +++ b/tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/identifiers/TechFactoryWrappersTests.kt @@ -0,0 +1,95 @@ +package com.github.klee0kai.stone.test.identifiers + +import com.github.klee0kai.test.di.techfactory.TechFactoryComponentStoneComponent +import kotlin.test.Test +import kotlin.test.assertEquals +import kotlin.test.assertNotEquals +import kotlin.test.assertNotNull + +class TechFactoryWrappersTests { + + @Test + fun lazyProvideTest() { + //Given + val DI = TechFactoryComponentStoneComponent() + + //When + val battery = DI.batteryLazy() + + //Then + assertEquals( + battery?.get()?.uuid, + battery?.get()?.uuid, + ) + } + + @Test + fun softRefProvideTest() { + //Given + val DI = TechFactoryComponentStoneComponent() + + //When + val battery = DI.batterySoft() + + //Then + assertNotNull(battery!!.get()) + } + + @Test + fun weakRefProvideTest() { + //Given + val DI = TechFactoryComponentStoneComponent() + + //When + val battery = DI.batteryWeak() + + //Then + assertNotNull(battery!!.get()) + } + + @Test + fun phantom1ProvideTest() { + //Given + val DI = TechFactoryComponentStoneComponent() + + //When + val battery = DI.batteryPhantomProvider() + + //Then + assertNotEquals( + battery!!.get()!!.uuid, + battery.get()!!.uuid, + ) + } + + @Test + fun phantom2ProvideTest() { + //Given + val DI = TechFactoryComponentStoneComponent() + + //When + val battery = DI.batteryProvider() + + //Then + assertNotEquals( + battery!!.get()!!.uuid, + battery.get()!!.uuid, + ) + } + + @Test + fun phantom3ProvideTest() { + //Given + val DI = TechFactoryComponentStoneComponent() + + //When + val battery = DI.batteryProviderIRef() + + //Then + assertNotEquals( + battery!!.get()!!.uuid, + battery.get()!!.uuid, + ) + } + +} 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 new file mode 100644 index 00000000..3cbe2f9b --- /dev/null +++ b/tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/inject/HorseInjectTests.kt @@ -0,0 +1,89 @@ +package com.github.klee0kai.stone.test.inject + +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 kotlin.test.Test +import kotlin.test.assertEquals +import kotlin.test.assertNotEquals +import kotlin.test.assertNotNull + +class HorseInjectTests { + + @Test + fun horseBornTest() { + //Given + val DI = ForestComponentStoneComponent() + val horse = Horse() + + + //When + DI.inject( + horse, + stoneLifeCycleOwner = StoneLifeCycleOwner { listener -> } + ) + + //Then + assertNotNull(horse.blood) + assertNotNull(horse.knowledge) + assertNotNull(horse.conscience) + assertNotNull(horse.methodInjectedConscience) + assertNotNull(horse.methodInjectedKnowledge) + } + + @Test + fun mowgliBornTest() { + //Given + val DI = ForestComponentStoneComponent() + val mowgli = Mowgli() + + + //When + DI.inject(mowgli) + + //Then + assertNotNull(mowgli.blood) + assertNotNull(mowgli.knowledge) + assertNotNull(mowgli.conscience) + } + + @Test + fun oneBloodTest() { + //Given + val DI = ForestComponentStoneComponent() + 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 = ForestComponentStoneComponent() + val mowgli = Mowgli() + val snake = Snake() + + + //When + DI.inject(mowgli) + DI.inject(snake) + + //Then + assertNotEquals( + mowgli.conscience!!.uuid, + snake.conscience!!.uuid, + ) + } +} 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 new file mode 100644 index 00000000..09864eb4 --- /dev/null +++ b/tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/inject/MowgliInjectMethodWrappersTests.kt @@ -0,0 +1,82 @@ +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 kotlin.test.Test +import kotlin.test.assertEquals +import kotlin.test.assertNotEquals +import kotlin.test.assertNotNull + +class MowgliInjectMethodWrappersTests { + + @Test + fun supportWrappersTest() { + //Given + val DI = ForestComponentStoneComponent() + val mowgli = Mowgli() + + + //When + 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()) + } + + + @Test + fun refWrapperTest() { + //Given + val DI = ForestComponentStoneComponent() + val mowgli = Mowgli() + + //When + DI.inject(mowgli) + + + //Then + assertEquals( + mowgli.methodKnowledgeWeakRef!!.get()!!.uuid, + mowgli.methodKnowledgeWeakRef!!.get()!!.uuid, + ) + assertEquals( + mowgli.methodKnowledgeSoftRef!!.get()!!.uuid, + mowgli.methodKnowledgeSoftRef!!.get()!!.uuid + ) + assertEquals( + mowgli.methodKnowledgeLazyProvide!!.get()!!.uuid, + mowgli.methodKnowledgeLazyProvide!!.get()!!.uuid, + ) + } + + @Test + fun genWrapperTest() { + //Given + val DI = ForestComponentStoneComponent() + val mowgli = Mowgli() + + //When + DI.inject(mowgli) + + + //Then + assertNotEquals( + mowgli.methodKnowledgePhantomProvide!!.get()!!.uuid, + mowgli.methodKnowledgePhantomProvide!!.get()!!.uuid, + ) + assertNotEquals( + mowgli.methodKnowledgePhantomProvide2!!.get()!!.uuid, + mowgli.methodKnowledgePhantomProvide2!!.get()!!.uuid, + ) + assertNotEquals( + mowgli.methodKnowledgePhantomProvide3!!.get()!!.uuid, + mowgli.methodKnowledgePhantomProvide3!!.get()!!.uuid, + ) + } + +} 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 new file mode 100644 index 00000000..1d668f18 --- /dev/null +++ b/tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/inject/MowgliInjectWrappersTests.kt @@ -0,0 +1,80 @@ +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 kotlin.test.Test +import kotlin.test.assertEquals +import kotlin.test.assertNotEquals +import kotlin.test.assertNotNull + +class MowgliInjectWrappersTests { + + @Test + fun supportWrappersTest() { + //Given + val DI = ForestComponentStoneComponent() + 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 = ForestComponentStoneComponent() + 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 = ForestComponentStoneComponent() + 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, + ) + } +} diff --git a/tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/interfaceprovide/DeepCaveTest.kt b/tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/interfaceprovide/DeepCaveTest.kt new file mode 100644 index 00000000..c1c3ccf4 --- /dev/null +++ b/tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/interfaceprovide/DeepCaveTest.kt @@ -0,0 +1,30 @@ +package com.github.klee0kai.stone.test.interfaceprovide + +import com.github.klee0kai.test.di.earthmirror.EarthComponentStoneComponent +import com.github.klee0kai.test.mowgli.earth.Cave +import kotlin.test.Test +import kotlin.test.assertNotNull + +class DeepCaveTest { + + @Test + fun justCaveTest() { + //When + val di = EarthComponentStoneComponent() + + //Then: Cave simple constructor is available + assertNotNull(di.east().cave()) + assertNotNull(di.west().cave()) + } + + @Test + fun theCaveTest() { + //When + 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)) + } + +} diff --git a/tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/interfaceprovide/EarthWayTest.kt b/tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/interfaceprovide/EarthWayTest.kt new file mode 100644 index 00000000..0271ce80 --- /dev/null +++ b/tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/interfaceprovide/EarthWayTest.kt @@ -0,0 +1,19 @@ +package com.github.klee0kai.stone.test.interfaceprovide + +import com.github.klee0kai.test.di.earthmirror.EarthComponentStoneComponent +import kotlin.test.Test +import kotlin.test.assertNotNull + +class EarthWayTest { + + @Test + fun christopherColumbusTest() { + //When + val di = EarthComponentStoneComponent() + + //Then + assertNotNull(di.west().mountainImp()) + assertNotNull(di.west().riverImpl()) + } + +} 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 new file mode 100644 index 00000000..be59ec29 --- /dev/null +++ b/tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/moduleinit/BeginOfBegins2Tests.kt @@ -0,0 +1,63 @@ +package com.github.klee0kai.stone.test.moduleinit + +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 kotlin.test.Test +import kotlin.test.assertEquals + +class BeginOfBegins2Tests { + + @Test + fun initByFactory() { + //Given + val module = object : UnitedModule() { + override fun earth(): Earth = earth + override fun history(): History? = null + + } + val DI = ForestComponentStoneComponent() + + //When + DI.initUnitedModule(module) + + //Then + assertEquals(earth, DI.united().earth()) + } + + @Test + fun initAllModules() { + //Given + 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) + + //Then + assertEquals(earth, DI.united().earth()) + assertEquals(ideology, DI.identity().ideology()) + + } + + companion object { + private val earth: Earth = Earth() + private val ideology: Ideology = Ideology() + } + +} diff --git a/tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/moduleinit/BeginOfBeginsTests.kt b/tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/moduleinit/BeginOfBeginsTests.kt new file mode 100644 index 00000000..83f9326f --- /dev/null +++ b/tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/moduleinit/BeginOfBeginsTests.kt @@ -0,0 +1,30 @@ +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.galaxy.Earth +import kotlin.test.Test +import kotlin.test.assertEquals + +class BeginOfBeginsTests { + + @Test + fun initByFactory() { + //Given + val module: UnitedModule = object : UnitedModule() { + override fun earth(): Earth = earth + override fun history() = null + } + val DI = ForestComponentStoneComponent() + + //When + DI.initUnitedModule(module) + + //Then + assertEquals(earth, DI.united().earth()) + } + + companion object { + private val earth: Earth = Earth() + } +} 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 new file mode 100644 index 00000000..4d4f3c60 --- /dev/null +++ b/tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/parameterized/WireTest.kt @@ -0,0 +1,48 @@ +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 kotlin.test.Test +import kotlin.test.assertEquals +import kotlin.test.assertNotEquals +import kotlin.test.assertNotNull + +class WireTest { + + @Test + fun usbUsbProvideTest() { + //When + 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, + ) + } + + @Test + fun miniUsbBindTest() { + //When + val di = WireComponentStoneComponent() + val wire = Wire() + di.miniusb_miniusb(wire) + + + //Then + assertEquals( + wire.uuid, + di.miniusb_miniusb(null)!!.uuid, + ) + } +} diff --git a/tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/types/ListUtilTests.java b/tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/types/ListUtilTests.java new file mode 100644 index 00000000..ee5b6ec3 --- /dev/null +++ b/tests/src/commonTest/kotlin/com/github/klee0kai/stone/test/types/ListUtilTests.java @@ -0,0 +1,41 @@ +package com.github.klee0kai.stone.test.types; + +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; + +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())); + } + + + @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())); + } +} 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..53674937 --- /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(): GodWorkspaceComponent = 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 diff --git a/tests/src/jvmTest/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 new file mode 100644 index 00000000..6a9c2f68 --- /dev/null +++ b/tests/src/jvmTest/kotlin/com/github/klee0kai/stone/test/bindinstance/singlemethod_gc/PlanetRollingTests.kt @@ -0,0 +1,222 @@ +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 kotlin.test.Test +import kotlin.test.assertNotNull +import kotlin.test.assertNull + +class PlanetRollingTests { + + @Test + fun gcAllTest() { + //Given + val DI = PlanetRollingComponentStoneComponent() + 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()) + DI.sunModule().sunStrong(sunStrong.get()) + DI.sunModule().sunSoft(sunSoft.get()) + DI.sunModule().star(starWeak.get()) + + //When + DI.gcAll() + + //Then + for (ref in listOf( + earthStrong, earthSoft, planetWeak, + sunStrong, sunSoft, starWeak + )) { + assertNull(ref.get()) + } + } + + + @Test + fun gcStrongTest() { + //Given + val DI = PlanetRollingComponentStoneComponent() + 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()) + DI.sunModule().sunStrong(sunStrong.get()) + DI.sunModule().sunSoft(sunSoft.get()) + DI.sunModule().star(starWeak.get()) + + //When + DI.gcStrong() + + //Then + for (ref in listOf( + earthStrong, planetWeak, + sunStrong, starWeak + )) { + assertNull(ref.get()) + } + + for (ref in listOf( + earthSoft, + sunSoft + )) { + assertNotNull(ref.get()) + } + } + + @Test + fun gcSoftTest() { + //Given + val DI = PlanetRollingComponentStoneComponent() + 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()) + DI.sunModule().sunStrong(sunStrong.get()) + DI.sunModule().sunSoft(sunSoft.get()) + DI.sunModule().star(starWeak.get()) + + //When + DI.gcSoft() + + //Then + for (ref in listOf( + earthSoft, planetWeak, + sunSoft, starWeak + )) { + assertNull(ref.get()) + } + + for (ref in listOf( + earthStrong, + sunStrong + )) { + assertNotNull(ref.get()) + } + } + + @Test + fun gcWeakTest() { + //Given + val DI = PlanetRollingComponentStoneComponent() + 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()) + DI.sunModule().sunStrong(sunStrong.get()) + DI.sunModule().sunSoft(sunSoft.get()) + DI.sunModule().star(starWeak.get()) + + //When + DI.gcWeak() + + //Then + for (ref in listOf( + planetWeak, + starWeak + )) { + assertNull(ref.get()) + } + + for (ref in listOf( + earthStrong, earthSoft, + sunStrong, sunSoft + )) { + assertNotNull(ref.get()) + } + } + + @Test + fun gcSoftSunTest() { + //Given + val DI = PlanetRollingComponentStoneComponent() + 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()) + DI.sunModule().sunStrong(sunStrong.get()) + DI.sunModule().sunSoft(sunSoft.get()) + DI.sunModule().star(starWeak.get()) + + //When + DI.gcSoftSun() + + //Then + for (ref in listOf( + planetWeak, + sunSoft, starWeak + )) { + assertNull(ref.get()) + } + + for (ref in listOf( + earthStrong, earthSoft, + sunStrong + )) { + assertNotNull(ref.get()) + } + } + + @Test + fun gcSoftPlanetsTest() { + //Given + val DI = PlanetRollingComponentStoneComponent() + 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()) + DI.sunModule().sunStrong(sunStrong.get()) + DI.sunModule().sunSoft(sunSoft.get()) + DI.sunModule().star(starWeak.get()) + + //When + DI.gcSoftPlanets() + + //Then + for (ref in listOf( + earthSoft, planetWeak, + starWeak + )) { + assertNull(ref.get()) + } + + for (ref in listOf( + earthStrong, + sunStrong, sunSoft + )) { + assertNotNull(ref.get()) + } + } +} 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..b9108278 --- /dev/null +++ b/tests/src/jvmTest/kotlin/com/github/klee0kai/stone/test/cache/EarthSwitchCacheGcTests.kt @@ -0,0 +1,81 @@ +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 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 + 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/gc/EarthLastDayTests.kt b/tests/src/jvmTest/kotlin/com/github/klee0kai/stone/test/gc/EarthLastDayTests.kt new file mode 100644 index 00000000..82b6cbc6 --- /dev/null +++ b/tests/src/jvmTest/kotlin/com/github/klee0kai/stone/test/gc/EarthLastDayTests.kt @@ -0,0 +1,281 @@ +package com.github.klee0kai.stone.test.gc + +import com.github.klee0kai.stone.weakref.WeakRef +import com.github.klee0kai.test.di.gcforest.GcGodComponentStoneComponent +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/jvmTest/kotlin/com/github/klee0kai/stone/test/gc/GodLastWorkDayTests.kt b/tests/src/jvmTest/kotlin/com/github/klee0kai/stone/test/gc/GodLastWorkDayTests.kt new file mode 100644 index 00000000..5fb56367 --- /dev/null +++ b/tests/src/jvmTest/kotlin/com/github/klee0kai/stone/test/gc/GodLastWorkDayTests.kt @@ -0,0 +1,158 @@ +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 +import com.github.klee0kai.test.mowgli.galaxy.Sun +import kotlin.test.Test +import kotlin.test.assertNotNull +import kotlin.test.assertNull + +class GodLastWorkDayTests { + + @Test + fun gcAllTest() { + //Given + val di = GcGodComponentStoneComponent() + val sunRef = WeakRef(Sun()) + val earthRef = WeakRef(Earth()) + val saturnRef = WeakRef(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 = GcGodComponentStoneComponent() + val sunRef = WeakRef(Sun()) + val earthRef = WeakRef(Earth()) + val saturnRef = WeakRef(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 = GcGodComponentStoneComponent() + val sunRef = WeakRef(Sun()) + val earthRef = WeakRef(Earth()) + val saturnRef = WeakRef(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 = GcGodComponentStoneComponent() + val sunRef = WeakRef(Sun()) + val earthRef = WeakRef(Earth()) + val saturnRef = WeakRef(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 = GcGodComponentStoneComponent() + val sunRef = WeakRef(Sun()) + val earthRef = WeakRef(Earth()) + val saturnRef = WeakRef(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 = GcGodComponentStoneComponent() + val sunRef = WeakRef(Sun()) + val earthRef = WeakRef(Earth()) + val saturnRef = WeakRef(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 = GcGodComponentStoneComponent() + val sunRef = WeakRef(Sun()) + val earthRef = WeakRef(Earth()) + val saturnRef = WeakRef(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/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..93141bdd --- /dev/null +++ b/tests/src/jvmTest/kotlin/com/github/klee0kai/stone/test/inject/HorseProtectInjectGcTests.kt @@ -0,0 +1,61 @@ +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 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() { + // 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/inject/SchoolProtectInjectWrappersTests.kt b/tests/src/jvmTest/kotlin/com/github/klee0kai/stone/test/inject/SchoolProtectInjectWrappersTests.kt new file mode 100644 index 00000000..da99844d --- /dev/null +++ b/tests/src/jvmTest/kotlin/com/github/klee0kai/stone/test/inject/SchoolProtectInjectWrappersTests.kt @@ -0,0 +1,49 @@ +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 kotlin.test.Test +import kotlin.test.assertNotNull +import kotlin.test.assertNull + +class SchoolProtectInjectWrappersTests { + + @Test + fun lazyWrapperProtectTest() { + // Given + val DI = ForestComponentStoneComponent() + val school = School() + + //When + DI.inject(school) + + val history = WeakRef(school.historyLazyProvide!!.get()) + DI.protectInjected(school) + DI.gcAll() + + //Then + assertNotNull(history.get()) + } + + @Test + fun ignoreProvideWrapperProtectTest() { + // Given + val DI = ForestComponentStoneComponent() + val school: School = School() + + //When + DI.inject(school) + val knowledge1 = WeakRef(school.knowledgePhantomProvide!!.get()) + val knowledge2 = WeakRef(school.knowledgePhantomProvide2!!.get()) + val knowledge3 = WeakRef(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/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..28e9bdc6 --- /dev/null +++ b/tests/src/jvmTest/kotlin/com/github/klee0kai/stone/test/lifecycle/GoodPhoneRepairGcTests.kt @@ -0,0 +1,127 @@ +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 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() { + + //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..01e62796 --- /dev/null +++ b/tests/src/jvmTest/kotlin/com/github/klee0kai/stone/test/lifecycle/OnePhoneRepairGcTests.kt @@ -0,0 +1,122 @@ +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 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 + 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/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 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/main/java/com/github/klee0kai/test/di/base_forest/ForestComponent.java b/tests/src/main/java/com/github/klee0kai/test/di/base_forest/ForestComponent.java deleted file mode 100644 index a61afb3a..00000000 --- a/tests/src/main/java/com/github/klee0kai/test/di/base_forest/ForestComponent.java +++ /dev/null @@ -1,51 +0,0 @@ -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; - -@Component -public interface ForestComponent { - - UnitedModule united(); - - IdentityModule identity(); - - void inject(Horse horse, StoneLifeCycleOwner stoneLifeCycleOwner); - - void inject(Horse horse); - - - void inject(Mowgli mowgli); - - void inject(Snake snake); - - void inject(School school); - - @Init - void initUnitedModule(UnitedModule unitedModule); - - @Init - void initUnitedModule(Class unitedModule); - - @Init - void iniAllModules(UnitedModule unitedModule, IdentityModule identityModule); - - @RunGc - @GcAllScope - void gcAll(); - - @ProtectInjected(timeMillis = 30) - void protectInjected(Horse horse); - - - @ProtectInjected(timeMillis = 30) - void protectInjected(Mowgli horse); - - @ProtectInjected(timeMillis = 30) - void protectInjected(School school); - -} 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.java deleted file mode 100644 index 867ff812..00000000 --- a/tests/src/main/java/com/github/klee0kai/test/di/base_forest/IdentityModule.java +++ /dev/null @@ -1,22 +0,0 @@ -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; - -@Module -public interface IdentityModule { - - @Provide(cache = Provide.CacheType.Factory) - Knowledge knowledge(); - - @Provide(cache = Provide.CacheType.Factory) - Conscience conscience(); - - @Provide(cache = Provide.CacheType.Soft) - Ideology ideology(); - -} 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.java deleted file mode 100644 index eb8f76e1..00000000 --- a/tests/src/main/java/com/github/klee0kai/test/di/base_forest/UnitedBlueModule.java +++ /dev/null @@ -1,18 +0,0 @@ -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.*; - - -@Module -public abstract class UnitedBlueModule extends UnitedModule { - - @Provide(cache = Provide.CacheType.Strong) - public Blood blood() { - return new Blood(Color.BLUE); - } - -} 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.java deleted file mode 100644 index dd35cb87..00000000 --- a/tests/src/main/java/com/github/klee0kai/test/di/base_forest/UnitedModule.java +++ /dev/null @@ -1,27 +0,0 @@ -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.*; - - -@Module -public abstract class UnitedModule { - - @Provide(cache = Provide.CacheType.Strong) - public Blood blood() { - return new Blood(Color.RED); - } - - @Provide(cache = Provide.CacheType.Soft) - public abstract Earth earth(); - - @Provide(cache = Provide.CacheType.Weak) - public abstract History history(); - - -} 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.java deleted file mode 100644 index 29b04a5c..00000000 --- a/tests/src/main/java/com/github/klee0kai/test/di/base_phone/PhoneComponent.java +++ /dev/null @@ -1,29 +0,0 @@ -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; - -@Component( - identifiers = { - DataStorageSize.class, - RamSize.class, - PhoneOsType.class, - PhoneOsVersion.class - } -) -public interface PhoneComponent { - - TechModule components(); - - void inject(OnePhone onePhone); - - void inject(GoodPhone goodPhone, DataStorageSize dataStorageSize, RamSize ramSize); - - void inject(GoodPhone goodPhone, StoneLifeCycleOwner lifeCycleOwner, DataStorageSize dataStorageSize, RamSize ramSize); -} 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.java deleted file mode 100644 index 65cd6a55..00000000 --- a/tests/src/main/java/com/github/klee0kai/test/di/base_phone/TechModule.java +++ /dev/null @@ -1,45 +0,0 @@ -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 { - - @Provide(cache = Provide.CacheType.Weak) - Battery battery(); - - @Named("null_args") - @Provide(cache = Provide.CacheType.Weak) - DataStorage dataStorage(); - - @Provide(cache = Provide.CacheType.Weak) - DataStorage dataStorage(DataStorageSize size); - - @Provide(cache = Provide.CacheType.Weak) - Ram ram(RamSize ramSize); - - - @Named("null_args") - @Provide(cache = Provide.CacheType.Weak) - Ram ram(); - - @Named("null_args") - @Provide(cache = Provide.CacheType.Weak) - OperationSystem phoneOs(PhoneOsType osType); - - @Provide(cache = Provide.CacheType.Weak) - OperationSystem phoneOs(PhoneOsType osType, PhoneOsVersion version); - -} 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.java deleted file mode 100644 index 20523d65..00000000 --- a/tests/src/main/java/com/github/klee0kai/test/di/base_phone/identifiers/DataStorageSize.java +++ /dev/null @@ -1,25 +0,0 @@ -package com.github.klee0kai.test.di.base_phone.identifiers; - -import java.util.Objects; - -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); - } - - @Override - public int hashCode() { - return Objects.hash(size); - } -} 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.java deleted file mode 100644 index cb9fbb95..00000000 --- a/tests/src/main/java/com/github/klee0kai/test/di/base_phone/identifiers/PhoneOsType.java +++ /dev/null @@ -1,7 +0,0 @@ -package com.github.klee0kai.test.di.base_phone.identifiers; - -public enum PhoneOsType { - Android, - Ios, - UbuntuTouch, -} 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.java deleted file mode 100644 index 86f53638..00000000 --- a/tests/src/main/java/com/github/klee0kai/test/di/base_phone/identifiers/PhoneOsVersion.java +++ /dev/null @@ -1,24 +0,0 @@ -package com.github.klee0kai.test.di.base_phone.identifiers; - -import java.util.Objects; - -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); - } - - @Override - public int hashCode() { - return Objects.hash(version); - } -} 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.java deleted file mode 100644 index 3cc35231..00000000 --- a/tests/src/main/java/com/github/klee0kai/test/di/base_phone/identifiers/RamSize.java +++ /dev/null @@ -1,26 +0,0 @@ -package com.github.klee0kai.test.di.base_phone.identifiers; - -import java.util.Objects; - -public class RamSize { - - public String size; - - public RamSize(String size) { - this.size = 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 - public int hashCode() { - return Objects.hash(size); - } - -} 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.java deleted file mode 100644 index 29c0b8f5..00000000 --- a/tests/src/main/java/com/github/klee0kai/test/di/bindinstance/simple/GodWorkspaceComponent.java +++ /dev/null @@ -1,33 +0,0 @@ -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; - -@Component -public interface GodWorkspaceComponent { - - SunSystemModule sunSystem(); - - @BindInstance - void bindPlanet(IPlanet planet); - - @BindInstance - IPlanet planet(IPlanet planet); - - @BindInstance - void bindSun(Sun sun); - - @BindInstance - void bindEarth(Earth earth); - - @BindInstance - void bindSaturn(Saturn saturn); - - - IPlanet providePlanet(); - -} 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.java deleted file mode 100644 index 2bc6f54b..00000000 --- a/tests/src/main/java/com/github/klee0kai/test/di/bindinstance/simple/SunSystemModule.java +++ /dev/null @@ -1,27 +0,0 @@ -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.*; - -@Module -public interface SunSystemModule { - - @BindInstance - Sun sun(); - - @BindInstance - IStar star(); - - @BindInstance - IPlanet planet(); - - @BindInstance - Earth earth(); - - @BindInstance - Saturn saturn(); - - -} 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.java deleted file mode 100644 index b3a54562..00000000 --- a/tests/src/main/java/com/github/klee0kai/test/di/bindinstance/simple_inject/SevenPlanetComponent.java +++ /dev/null @@ -1,28 +0,0 @@ -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; - -@Component -public interface SevenPlanetComponent { - - - SevenPlanetModule planets(); - - StarsModule stars(); - - @BindInstance - void bind(Earth earth); - - @BindInstance - void bind(Mercury mercury); - - @BindInstance - void bindPlanet(IPlanet planet); - - void inject(MoonSky moonSky); -} 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.java deleted file mode 100644 index 6852b640..00000000 --- a/tests/src/main/java/com/github/klee0kai/test/di/bindinstance/simple_inject/SevenPlanetModule.java +++ /dev/null @@ -1,22 +0,0 @@ -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; - -@Module -public interface SevenPlanetModule { - - - @BindInstance - Earth earth(); - - @BindInstance - Mercury mercury(); - - @BindInstance - IPlanet planet(); - -} 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.java deleted file mode 100644 index 853357f9..00000000 --- a/tests/src/main/java/com/github/klee0kai/test/di/bindinstance/simple_inject/StarsModule.java +++ /dev/null @@ -1,18 +0,0 @@ -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; - -@Module -public interface StarsModule { - - @BindInstance - IStar star(); - - @BindInstance - Sun sun(); - - -} 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.java deleted file mode 100644 index fa5670ef..00000000 --- a/tests/src/main/java/com/github/klee0kai/test/di/bindinstance/singlemethod/PlanetComponent.java +++ /dev/null @@ -1,25 +0,0 @@ -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; - -@Component -public interface PlanetComponent { - - SunModule sunModule(); - - @BindInstance - IPlanet planet(IPlanet planet); - - @BindInstance(cache = BindInstance.CacheType.Weak) - Earth earth(Earth earth); - - IPlanet providePlanet(); - - @BindInstance - void bindSun(Sun sun); - -} 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.java deleted file mode 100644 index 5c1ccef4..00000000 --- a/tests/src/main/java/com/github/klee0kai/test/di/bindinstance/singlemethod/SunModule.java +++ /dev/null @@ -1,36 +0,0 @@ -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; - -@Module -public interface SunModule { - - @GcSunScope - @Named("strong") - @BindInstance(cache = BindInstance.CacheType.Strong) - Sun sunStrong(Sun sun); - - @GcSunScope - @Named("soft") - @BindInstance(cache = BindInstance.CacheType.Soft) - Sun sunSoft(Sun sun); - - - @GcSunScope - @BindInstance - Sun sun(Sun sun); - - - @GcSunScope - @BindInstance(cache = BindInstance.CacheType.Weak) - IStar star(IStar star); - - -} 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.java deleted file mode 100644 index 63ba5444..00000000 --- a/tests/src/main/java/com/github/klee0kai/test/di/bindinstance/singlemethod_gc/PlanetRollingComponent.java +++ /dev/null @@ -1,62 +0,0 @@ -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; - -@Component -public interface PlanetRollingComponent { - - SunModule sunModule(); - - @GcPlanetScope - @BindInstance(cache = BindInstance.CacheType.Strong) - Earth earthStrong(Earth earth); - - @GcPlanetScope - @BindInstance(cache = BindInstance.CacheType.Soft) - Earth earthSoft(Earth earth); - - @GcPlanetScope - @BindInstance(cache = BindInstance.CacheType.Weak) - IPlanet planet(IPlanet planet); - - @GcPlanetScope - @BindInstance(cache = BindInstance.CacheType.Weak) - Earth earth(Earth earth); - - IPlanet providePlanet(); - - @RunGc - @GcAllScope - void gcAll(); - - @RunGc - @GcStrongScope - void gcStrong(); - - @RunGc - @GcSoftScope - void gcSoft(); - - @RunGc - @GcWeakScope - void gcWeak(); - - - @RunGc - @GcSoftScope - @GcSunScope - void gcSoftSun(); - - @RunGc - @GcSoftScope - @GcPlanetScope - void gcSoftPlanets(); - - -} 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.java deleted file mode 100644 index cda2ae9e..00000000 --- a/tests/src/main/java/com/github/klee0kai/test/di/bindinstance/singlemethod_inject/StarSkyComponent.java +++ /dev/null @@ -1,35 +0,0 @@ -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(); - - @BindInstance - IPlanet planet(IPlanet planet); - - @BindInstance - Earth earth(Earth earth); - - @BindInstance(cache = BindInstance.CacheType.Weak) - Mercury mercury(Mercury earth); - - @RunGc - @GcAllScope - void gcAll(); - - void inject(MoonSky moonSky); - - @ProtectInjected(timeMillis = 50) - void protectInjected(MoonSky moonSky); -} 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.java deleted file mode 100644 index 34346bc2..00000000 --- a/tests/src/main/java/com/github/klee0kai/test/di/bindinstance/singlemethod_inject/StarSkyModule.java +++ /dev/null @@ -1,23 +0,0 @@ -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; - -@Module -public interface StarSkyModule { - - @GcSunScope - @BindInstance - Sun sun(Sun sun); - - - @GcSunScope - @BindInstance(cache = BindInstance.CacheType.Weak) - IStar star(IStar star); - - -} 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.java deleted file mode 100644 index 363448b7..00000000 --- a/tests/src/main/java/com/github/klee0kai/test/di/bindinstance/solarsystem/PlanetModule.java +++ /dev/null @@ -1,31 +0,0 @@ -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.*; - -@Module -public class PlanetModule { - - @Provide(cache = Provide.CacheType.Strong) - Sun sun(SolarSystem solarSystem) { - return new Sun(); - } - - @Provide(cache = Provide.CacheType.Soft) - Earth earth(Sun sun){ - return new Earth(); - } - - @Provide(cache = Provide.CacheType.Soft) - Mercury mercury(Sun sun){ - return new Mercury(); - } - - @Provide(cache = Provide.CacheType.Soft) - Saturn saturn(Sun sun){ - return new Saturn(); - } - - -} 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.java deleted file mode 100644 index d7bdfc93..00000000 --- a/tests/src/main/java/com/github/klee0kai/test/di/bindinstance/solarsystem/SolarSystemComponent.java +++ /dev/null @@ -1,15 +0,0 @@ -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; - -@Component -public interface SolarSystemComponent extends SolarSystemDependencies { - - PlanetModule planets(); - - - @BindInstance - SolarSystem bind(SolarSystem system); -} 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.java deleted file mode 100644 index 59e28e7a..00000000 --- a/tests/src/main/java/com/github/klee0kai/test/di/bindinstance/solarsystem/SolarSystemDependencies.java +++ /dev/null @@ -1,15 +0,0 @@ -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; - -public interface SolarSystemDependencies { - - LazyProvide earth(); - - LazyProvide mercury(); - - LazyProvide saturn(); -} 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.java deleted file mode 100644 index 645cc96e..00000000 --- a/tests/src/main/java/com/github/klee0kai/test/di/earthmirror/EarthComponent.java +++ /dev/null @@ -1,15 +0,0 @@ -package com.github.klee0kai.test.di.earthmirror; - -import com.github.klee0kai.stone.annotations.component.Component; -import com.github.klee0kai.test.mowgli.earth.Cave; - -@Component( - identifiers = {Cave.CaveType.class, Integer.class} -) -public interface EarthComponent { - - EastModule east(); - - WestModule west(); - -} 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.java deleted file mode 100644 index f5bc070b..00000000 --- a/tests/src/main/java/com/github/klee0kai/test/di/earthmirror/EastModule.java +++ /dev/null @@ -1,16 +0,0 @@ -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; - -@Module -public interface EastModule { - - @Provide(cache = Provide.CacheType.Soft) - Cave cave(); - - @Provide(cache = Provide.CacheType.Soft) - Cave cave(Cave.CaveType type, Integer deep); - -} 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.java deleted file mode 100644 index 175345d3..00000000 --- a/tests/src/main/java/com/github/klee0kai/test/di/earthmirror/WestModule.java +++ /dev/null @@ -1,26 +0,0 @@ -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.*; - -@Module -public abstract class WestModule { - - @Provide(cache = Provide.CacheType.Factory) - public IRiver riverImpl() { - return new River(); - } - - @Provide(cache = Provide.CacheType.Soft) - public IMountain mountainImp() { - return new Mountain(); - } - - @Provide(cache = Provide.CacheType.Soft) - public abstract Cave cave(); - - @Provide(cache = Provide.CacheType.Soft) - public abstract Cave cave(Cave.CaveType type, Integer deep); - -} 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.java deleted file mode 100644 index 9f945659..00000000 --- a/tests/src/main/java/com/github/klee0kai/test/di/gcforest/GcEarthComponent.java +++ /dev/null @@ -1,34 +0,0 @@ -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 { - - - @RunGc - @GcMountainScope - public abstract void gcMountains(); - - @RunGc - @GcSoftScope - @GcMountainScope - public abstract void gcSoftMountains(); - - @RunGc - @GcStrongScope - @GcMountainScope - public abstract void gcStrongMountains(); - - @RunGc - @GcRiverScope - public abstract void gcRivers(); - - public void gcMountainsAndRivers() { - gcMountains(); - gcRivers(); - } -} 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.java deleted file mode 100644 index cc9ce1c5..00000000 --- a/tests/src/main/java/com/github/klee0kai/test/di/gcforest/GcEarthModule.java +++ /dev/null @@ -1,61 +0,0 @@ -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; - -@Module -public abstract class GcEarthModule { - - @GcMountainScope - @Provide(cache = Provide.CacheType.Strong) - abstract public Mountain mountainStrong(); - - @GcMountainScope - @Provide(cache = Provide.CacheType.Soft) - abstract public Mountain mountainSoft(); - - @GcMountainScope - @Provide(cache = Provide.CacheType.Weak) - abstract public Mountain mountainWeak(); - - @GcMountainScope - @Provide(cache = Provide.CacheType.Factory) - public Mountain mountainFactory() { - return new Mountain(); - } - - @GcMountainScope - @Provide - abstract public Mountain mountainDefaultFactory(); - - @GcMountainScope - abstract public Mountain mountainDefault2Factory(); - - @GcRiverScope - @Provide(cache = Provide.CacheType.Strong) - abstract public River riverStrong(); - - @GcRiverScope - @Provide(cache = Provide.CacheType.Soft) - abstract public River riverSoft(); - - @GcRiverScope - @Provide(cache = Provide.CacheType.Weak) - abstract public River riverWeak(); - - @GcRiverScope - @Provide(cache = Provide.CacheType.Factory) - abstract public River riverFactory(); - - @GcRiverScope - @Provide - public River riverDefaultSoft() { - return new River(); - } - - -} 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.java deleted file mode 100644 index d9f7de65..00000000 --- a/tests/src/main/java/com/github/klee0kai/test/di/gcforest/GcGodComponent.java +++ /dev/null @@ -1,57 +0,0 @@ -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; - -@Component -public abstract class GcGodComponent extends GcEarthComponent { - - public abstract GcSunSystemModule sunSystem(); - - public abstract GcEarthModule earth(); - - @BindInstance - public abstract void bind(Sun sun); - - @BindInstance - public abstract void bind(Earth earth); - - @BindInstance - public abstract void bind(Saturn saturn); - - - @RunGc - @GcAllScope - public abstract void gcAll(); - - @RunGc - @GcStrongScope - public abstract void gcStrong(); - - @RunGc - @GcSoftScope - public abstract void gcSoft(); - - @RunGc - @GcWeakScope - public abstract void gcWeak(); - - @RunGc - @GcSunScope - public abstract void gcSun(); - - @RunGc - @GcPlanetScope - public abstract void gcPlanets(); - - public void gcSunAndPlanets() { - gcSun(); - gcPlanets(); - } - -} 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.java deleted file mode 100644 index 1397fe37..00000000 --- a/tests/src/main/java/com/github/klee0kai/test/di/gcforest/GcSunSystemModule.java +++ /dev/null @@ -1,33 +0,0 @@ -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; - -@Module -public interface GcSunSystemModule { - - @GcSunScope - @BindInstance(cache = BindInstance.CacheType.Strong) - Sun sun(); - - @GcPlanetScope - @BindInstance(cache = BindInstance.CacheType.Strong) - IPlanet planet(); - - @GcPlanetScope - @BindInstance(cache = BindInstance.CacheType.Soft) - Earth earth(); - - - @GcPlanetScope - @BindInstance(cache = BindInstance.CacheType.Weak) - Saturn saturn(); - - -} 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.java deleted file mode 100644 index d69d1b13..00000000 --- a/tests/src/main/java/com/github/klee0kai/test/di/gcforest/scopes/GcMountainScope.java +++ /dev/null @@ -1,14 +0,0 @@ -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; - -@Scope -@Retention(RUNTIME) -@Target(METHOD) -public @interface GcMountainScope { -} 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.java deleted file mode 100644 index c4c8d2f4..00000000 --- a/tests/src/main/java/com/github/klee0kai/test/di/gcforest/scopes/GcPlanetScope.java +++ /dev/null @@ -1,15 +0,0 @@ -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; - -@GcScopeAnnotation -@Retention(RUNTIME) -@Target(METHOD) -public @interface GcPlanetScope { -} 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.java deleted file mode 100644 index 211da4cf..00000000 --- a/tests/src/main/java/com/github/klee0kai/test/di/gcforest/scopes/GcRiverScope.java +++ /dev/null @@ -1,14 +0,0 @@ -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; - -@Scope -@Retention(RUNTIME) -@Target(METHOD) -public @interface GcRiverScope { -} 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.java deleted file mode 100644 index aafc4459..00000000 --- a/tests/src/main/java/com/github/klee0kai/test/di/gcforest/scopes/GcSunScope.java +++ /dev/null @@ -1,14 +0,0 @@ -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; - -@Scope -@Retention(RUNTIME) -@Target(METHOD) -public @interface GcSunScope { -} 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.java deleted file mode 100644 index b6225d9d..00000000 --- a/tests/src/main/java/com/github/klee0kai/test/di/house/nulls/HouseNullsComponent.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.github.klee0kai.test.di.house.nulls; - -import com.github.klee0kai.stone.annotations.component.Component; -import com.github.klee0kai.test.house.House; - -@Component -public interface HouseNullsComponent { - - HouseNullsModule module(); - - House house(); - -} 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.java deleted file mode 100644 index dbb85d84..00000000 --- a/tests/src/main/java/com/github/klee0kai/test/di/house/nulls/HouseNullsModule.java +++ /dev/null @@ -1,18 +0,0 @@ -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; - -@Module -public class HouseNullsModule { - - public Kichen kichen() { - return new Kichen(null, null, null); - } - - public House house(Kichen kichen) { - return new House(kichen, null, null, null); - } - -} 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.java deleted file mode 100644 index c843e935..00000000 --- a/tests/src/main/java/com/github/klee0kai/test/di/house/simple/AreasModule.java +++ /dev/null @@ -1,25 +0,0 @@ -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.*; - -@Module -abstract class AreasModule { - - @Provide(cache = Provide.CacheType.Soft) - public abstract CookingArea cookingArea(); - - @Provide(cache = Provide.CacheType.Soft) - public abstract SinkArea sinkArea(); - - @Provide(cache = Provide.CacheType.Factory) - public abstract StoreArea storeArea(StoreAreaType type, Cookware cookware, Clothes clothes, Sanitizers sanitizers); - - @Provide(cache = Provide.CacheType.Soft) - abstract public GarageStore garageStore(Cookware cookware, Clothes clothes, Sanitizers sanitizers); - -} 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.java deleted file mode 100644 index fe27883b..00000000 --- a/tests/src/main/java/com/github/klee0kai/test/di/house/simple/HouseComponent.java +++ /dev/null @@ -1,36 +0,0 @@ -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; - -@Component( - identifiers = {StoreAreaType.class} -) -public interface HouseComponent { - - HouseModule module(); - - @ModuleOriginFactory - HouseModule moduleFactory(); - - RoomsModule rooms(); - - AreasModule area(); - - ToolsModule tools(); - - House house(); - - Sanitizers sanitizers(); - - House house(StoreAreaType type); - - void inject(StoreAreaType storeAreaType, InHouse inHouse); - - void inject(InHouse inHouse); - -} 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.java deleted file mode 100644 index 0a9f83b7..00000000 --- a/tests/src/main/java/com/github/klee0kai/test/di/house/simple/HouseModule.java +++ /dev/null @@ -1,17 +0,0 @@ -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; - -@Module -public interface HouseModule { - - @Provide(cache = Provide.CacheType.Soft) - House house(Kichen kichen, BathRoom bathRoom, BedRoom bedRoom, Garage garage); - -} 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.java deleted file mode 100644 index 82583dbb..00000000 --- a/tests/src/main/java/com/github/klee0kai/test/di/house/simple/RoomsModule.java +++ /dev/null @@ -1,29 +0,0 @@ -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; - -@Module -public interface RoomsModule { - - @Provide(cache = Provide.CacheType.Soft) - Kichen kitchen(CookingArea cookingArea, SinkArea sinkArea, StoreArea storeArea); - - @Provide(cache = Provide.CacheType.Soft) - BathRoom bathRoom(StoreArea storeArea); - - @Provide(cache = Provide.CacheType.Soft) - BedRoom bedRoom(StoreArea storeArea); - - @Provide(cache = Provide.CacheType.Soft) - Garage garage(GarageStore garageStore); - -} 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.java deleted file mode 100644 index 934535fb..00000000 --- a/tests/src/main/java/com/github/klee0kai/test/di/house/simple/ToolsModule.java +++ /dev/null @@ -1,21 +0,0 @@ -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; - -@Module -public interface ToolsModule { - - @Provide(cache = Provide.CacheType.Factory) - Cookware cookware(); - - @Provide(cache = Provide.CacheType.Factory) - Clothes clothes(); - - @Provide(cache = Provide.CacheType.Factory) - Sanitizers sanitizers(); - -} 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.java deleted file mode 100644 index 75f40714..00000000 --- a/tests/src/main/java/com/github/klee0kai/test/di/swcache/SwitchCacheComponent.java +++ /dev/null @@ -1,33 +0,0 @@ -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; - -@Component -public interface SwitchCacheComponent { - - GcEarthModule earth(); - - @GcAllScope - @SwitchCache(cache = SwitchCache.CacheType.Weak) - void allWeak(); - - - @GcAllScope - @SwitchCache(cache = SwitchCache.CacheType.Strong, timeMillis = 100) - void allStrongFewMillis(); - - - @GcStrongScope - @SwitchCache(cache = SwitchCache.CacheType.Weak) - void strongToWeak(); - - @GcMountainScope - @SwitchCache(cache = SwitchCache.CacheType.Weak) - void mountainToWeak(); - -} 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.java deleted file mode 100644 index e5c1ff49..00000000 --- a/tests/src/main/java/com/github/klee0kai/test/di/techfactory/ITechProviderComponent.java +++ /dev/null @@ -1,45 +0,0 @@ -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 javax.inject.Named; -import javax.inject.Provider; -import java.lang.ref.SoftReference; -import java.lang.ref.WeakReference; - -public interface ITechProviderComponent { - - LazyProvide batteryLazy(); - - Ref batteryProviderIRef(); - - PhantomProvide batteryPhantomProvider(); - - Provider batteryProvider(); - - SoftReference batterySoft(); - - WeakReference batteryWeak(); - - @Named("null_args") - Ram ram(); - - Ram ram(RamSize ramSize); - - @Named("null_args") - OperationSystem phoneOs(); - - OperationSystem phoneOs(PhoneOsType osType); - - OperationSystem phoneOs(PhoneOsType phoneOsType, PhoneOsVersion version); - - -} 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.java deleted file mode 100644 index 39368ece..00000000 --- a/tests/src/main/java/com/github/klee0kai/test/di/techfactory/TechFactoryComponent.java +++ /dev/null @@ -1,20 +0,0 @@ -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; - -@Component( - identifiers = { - RamSize.class, DataStorageSize.class, - PhoneOsType.class, PhoneOsVersion.class - } -) -public interface TechFactoryComponent extends ITechProviderComponent { - - TechFactoryModule factory(); - - -} 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.java deleted file mode 100644 index 5308dfe7..00000000 --- a/tests/src/main/java/com/github/klee0kai/test/di/techfactory/TechFactoryModule.java +++ /dev/null @@ -1,46 +0,0 @@ -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 { - - @Provide(cache = Provide.CacheType.Factory) - Battery battery(); - - @Named("null_args") - @Provide(cache = Provide.CacheType.Factory) - DataStorage dataStorage(); - - @Provide(cache = Provide.CacheType.Factory) - DataStorage dataStorage(DataStorageSize size); - - - @Named("null_args") - @Provide(cache = Provide.CacheType.Factory) - Ram ram(); - - @Provide(cache = Provide.CacheType.Factory) - Ram ram(RamSize ramSize); - - - @Named("null_args") - @Provide(cache = Provide.CacheType.Factory) - OperationSystem phoneOs(PhoneOsType osType); - - @Provide(cache = Provide.CacheType.Factory) - OperationSystem phoneOs(PhoneOsType phoneOsType, PhoneOsVersion version); - -} 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.java deleted file mode 100644 index c6aac113..00000000 --- a/tests/src/main/java/com/github/klee0kai/test/di/wire/WireComponent.java +++ /dev/null @@ -1,26 +0,0 @@ -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; - -@Component -public abstract class WireComponent { - - public abstract WireModule module(); - - public abstract Wire usb_hdmi(); - - public abstract WeakReference> usb_usb(); - - public abstract Wire simple(); - - @BindInstance - public abstract Wire miniusb_miniusb(Wire wire); - -} 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.java deleted file mode 100644 index 3fead851..00000000 --- a/tests/src/main/java/com/github/klee0kai/test/di/wire/WireModule.java +++ /dev/null @@ -1,30 +0,0 @@ -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; - -@Module -public abstract class WireModule { - - @Provide(cache = Provide.CacheType.Soft) - public abstract Wire usb_miniusb(); - - @Provide(cache = Provide.CacheType.Soft) - public abstract Wire usb_usb(); - - @Provide(cache = Provide.CacheType.Soft) - public Wire usb_hdmi() { - return new Wire<>(); - } - - @Provide(cache = Provide.CacheType.Soft) - public Wire simple() { - return new Wire(); - } - - -} 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.java deleted file mode 100644 index d7bbd8bb..00000000 --- a/tests/src/main/java/com/github/klee0kai/test/house/House.java +++ /dev/null @@ -1,25 +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.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; - } -} 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.java deleted file mode 100644 index 599de537..00000000 --- a/tests/src/main/java/com/github/klee0kai/test/house/InHouse.java +++ /dev/null @@ -1,27 +0,0 @@ -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 { - - @Inject - public Kichen kichen; - - @Inject - public BathRoom bathRoom; - - @Inject - public BathRoom bedRoom; - - @Inject - public Garage garage; - - @Inject - public StoreArea bedStoreArea; - -} 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.java deleted file mode 100644 index 1b3b780c..00000000 --- a/tests/src/main/java/com/github/klee0kai/test/house/identifiers/StoreAreaType.java +++ /dev/null @@ -1,7 +0,0 @@ -package com.github.klee0kai.test.house.identifiers; - -public enum StoreAreaType { - CLOSED, - LOCKER, - CUPBOARD, -} 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.java deleted file mode 100644 index 292f5d6b..00000000 --- a/tests/src/main/java/com/github/klee0kai/test/house/kitchen/Kichen.java +++ /dev/null @@ -1,23 +0,0 @@ -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; - } -} 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.java deleted file mode 100644 index 1f4f9351..00000000 --- a/tests/src/main/java/com/github/klee0kai/test/house/kitchen/cookingarea/CookingArea.java +++ /dev/null @@ -1,9 +0,0 @@ -package com.github.klee0kai.test.house.kitchen.cookingarea; - -import java.util.UUID; - -public class CookingArea { - - public UUID uuid = UUID.randomUUID(); - -} 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.java deleted file mode 100644 index c4082cd7..00000000 --- a/tests/src/main/java/com/github/klee0kai/test/house/kitchen/sinkarea/SinkArea.java +++ /dev/null @@ -1,9 +0,0 @@ -package com.github.klee0kai.test.house.kitchen.sinkarea; - -import java.util.UUID; - -public class SinkArea { - - public UUID uuid = UUID.randomUUID(); - -} 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.java deleted file mode 100644 index a58f5d02..00000000 --- a/tests/src/main/java/com/github/klee0kai/test/house/kitchen/storagearea/Clothes.java +++ /dev/null @@ -1,9 +0,0 @@ -package com.github.klee0kai.test.house.kitchen.storagearea; - -import java.util.UUID; - -public class Clothes { - - public UUID uuid = UUID.randomUUID(); - -} 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.java deleted file mode 100644 index 11236c1e..00000000 --- a/tests/src/main/java/com/github/klee0kai/test/house/kitchen/storagearea/Cookware.java +++ /dev/null @@ -1,9 +0,0 @@ -package com.github.klee0kai.test.house.kitchen.storagearea; - -import java.util.UUID; - -public class Cookware { - - public UUID uuid = UUID.randomUUID(); - -} 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.java deleted file mode 100644 index 6ae93877..00000000 --- a/tests/src/main/java/com/github/klee0kai/test/house/kitchen/storagearea/GarageStore.java +++ /dev/null @@ -1,15 +0,0 @@ -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; - } - -} 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.java deleted file mode 100644 index 608afec9..00000000 --- a/tests/src/main/java/com/github/klee0kai/test/house/kitchen/storagearea/Sanitizers.java +++ /dev/null @@ -1,15 +0,0 @@ -package com.github.klee0kai.test.house.kitchen.storagearea; - -import java.util.UUID; - -public class Sanitizers { - - public static int createCount = 0; - - public UUID uuid = UUID.randomUUID(); - - public Sanitizers() { - createCount++; - } - -} 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.java deleted file mode 100644 index 56c66e37..00000000 --- a/tests/src/main/java/com/github/klee0kai/test/house/kitchen/storagearea/StoreArea.java +++ /dev/null @@ -1,19 +0,0 @@ -package com.github.klee0kai.test.house.kitchen.storagearea; - -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; - } -} 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.java deleted file mode 100644 index f760d1b9..00000000 --- a/tests/src/main/java/com/github/klee0kai/test/house/rooms/BathRoom.java +++ /dev/null @@ -1,17 +0,0 @@ -package com.github.klee0kai.test.house.rooms; - -import com.github.klee0kai.test.house.kitchen.storagearea.StoreArea; - -import java.util.UUID; - -public class BathRoom { - - public UUID uuid = UUID.randomUUID(); - - public final StoreArea storeArea; - - - public BathRoom(StoreArea storeArea) { - this.storeArea = storeArea; - } -} 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.java deleted file mode 100644 index 32f9c81b..00000000 --- a/tests/src/main/java/com/github/klee0kai/test/house/rooms/BedRoom.java +++ /dev/null @@ -1,17 +0,0 @@ -package com.github.klee0kai.test.house.rooms; - -import com.github.klee0kai.test.house.kitchen.storagearea.StoreArea; - -import java.util.UUID; - -public class BedRoom { - - public UUID uuid = UUID.randomUUID(); - - public final StoreArea storeArea; - - - public BedRoom(StoreArea storeArea) { - this.storeArea = storeArea; - } -} 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.java deleted file mode 100644 index 84ab5d71..00000000 --- a/tests/src/main/java/com/github/klee0kai/test/house/rooms/Garage.java +++ /dev/null @@ -1,17 +0,0 @@ -package com.github.klee0kai.test.house.rooms; - -import com.github.klee0kai.test.house.kitchen.storagearea.GarageStore; - -import java.util.UUID; - -public class Garage { - - public UUID uuid = UUID.randomUUID(); - - public final GarageStore garageStore; - - - public Garage(GarageStore garageStore) { - this.garageStore = garageStore; - } -} 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.java deleted file mode 100644 index ae304044..00000000 --- a/tests/src/main/java/com/github/klee0kai/test/mowgli/MoonSky.java +++ /dev/null @@ -1,26 +0,0 @@ -package com.github.klee0kai.test.mowgli; - -import com.github.klee0kai.test.mowgli.galaxy.*; - -import javax.inject.Inject; - -public class MoonSky { - - @Inject - public IStar star; - - @Inject - public Sun sun; - - - @Inject - public IPlanet planet; - - @Inject - public Mercury mercury; - - @Inject - public Earth earth; - - -} 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.java deleted file mode 100644 index 3d1ef96a..00000000 --- a/tests/src/main/java/com/github/klee0kai/test/mowgli/School.java +++ /dev/null @@ -1,27 +0,0 @@ -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 { - - @Inject - public LazyProvide historyLazyProvide; - - @Inject - public Ref knowledgePhantomProvide2; - - @Inject - public Provider knowledgePhantomProvide3; - - @Inject - public PhantomProvide knowledgePhantomProvide; - - -} 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.java deleted file mode 100644 index 984d1a39..00000000 --- a/tests/src/main/java/com/github/klee0kai/test/mowgli/animal/Horse.java +++ /dev/null @@ -1,37 +0,0 @@ -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 { - - @Inject - public Blood blood; - @Inject - public Earth earth; - @Inject - public History history; - @Inject - public Conscience conscience; - @Inject - public Knowledge knowledge; - @Inject - public Ideology ideology; - - - public Conscience methodInjectedConscience; - public Knowledge methodInjectedKnowledge; - - @Inject - public void initInject(Conscience conscience, Knowledge knowledge) { - methodInjectedConscience = conscience; - methodInjectedKnowledge = knowledge; - } - -} 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.java deleted file mode 100644 index 92bc4fe1..00000000 --- a/tests/src/main/java/com/github/klee0kai/test/mowgli/animal/IAnimal.java +++ /dev/null @@ -1,6 +0,0 @@ -package com.github.klee0kai.test.mowgli.animal; - -public interface IAnimal { - - -} 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.java deleted file mode 100644 index fc4f06e6..00000000 --- a/tests/src/main/java/com/github/klee0kai/test/mowgli/animal/Mowgli.java +++ /dev/null @@ -1,82 +0,0 @@ -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 { - - @Inject - public Blood blood; - @Inject - public Earth earth; - @Inject - public History history; - @Inject - public Conscience conscience; - @Inject - public Knowledge knowledge; - - @Inject - public WeakReference knowledgeWeakRef; - - @Inject - public SoftReference knowledgeSoftRef; - - @Inject - public LazyProvide knowledgeLazyProvide; - - @Inject - public Ref knowledgePhantomProvide2; - - @Inject - public Provider knowledgePhantomProvide3; - - @Inject - public PhantomProvide knowledgePhantomProvide; - - - public WeakReference methodKnowledgeWeakRef; - - public SoftReference methodKnowledgeSoftRef; - - public LazyProvide methodKnowledgeLazyProvide; - - public Ref methodKnowledgePhantomProvide2; - - public Provider methodKnowledgePhantomProvide3; - - public PhantomProvide methodKnowledgePhantomProvide; - - @Inject - public void refInject(WeakReference knowledgeWeakRef, SoftReference knowledgeSoftRef) { - methodKnowledgeWeakRef = knowledgeWeakRef; - methodKnowledgeSoftRef = knowledgeSoftRef; - } - - - @Inject - public void wrapperInject( - LazyProvide knowledgeLazyProvide, - Ref knowledgePhantomProvide2, - Provider knowledgePhantomProvide3, - PhantomProvide knowledgePhantomProvide - ) { - methodKnowledgeLazyProvide = knowledgeLazyProvide; - methodKnowledgePhantomProvide2 = knowledgePhantomProvide2; - methodKnowledgePhantomProvide3 = knowledgePhantomProvide3; - methodKnowledgePhantomProvide = knowledgePhantomProvide; - } - - -} 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.java deleted file mode 100644 index 513fa258..00000000 --- a/tests/src/main/java/com/github/klee0kai/test/mowgli/animal/Snake.java +++ /dev/null @@ -1,24 +0,0 @@ -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 { - - @Inject - public Blood blood; - @Inject - public Earth earth; - @Inject - public History history; - @Inject - public Conscience conscience; - @Inject - public Knowledge knowledge; - -} 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.java deleted file mode 100644 index 3f454145..00000000 --- a/tests/src/main/java/com/github/klee0kai/test/mowgli/body/Blood.java +++ /dev/null @@ -1,15 +0,0 @@ -package com.github.klee0kai.test.mowgli.body; - -import java.awt.*; -import java.util.UUID; - -public class Blood { - - public UUID uuid = UUID.randomUUID(); - - public Color color = null; - - public Blood(Color color) { - this.color = color; - } -} 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.java deleted file mode 100644 index 42632864..00000000 --- a/tests/src/main/java/com/github/klee0kai/test/mowgli/community/History.java +++ /dev/null @@ -1,10 +0,0 @@ -package com.github.klee0kai.test.mowgli.community; - -import java.util.UUID; - -public class History { - - public UUID uuid = UUID.randomUUID(); - - -} 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.java deleted file mode 100644 index 499b30f5..00000000 --- a/tests/src/main/java/com/github/klee0kai/test/mowgli/earth/Cave.java +++ /dev/null @@ -1,22 +0,0 @@ -package com.github.klee0kai.test.mowgli.earth; - -import java.util.UUID; - - -public class Cave implements IMountain { - - public UUID uuid = UUID.randomUUID(); - - public Cave() { - //nothing - } - - public Cave(CaveType type, Integer deep) { - //nothing - } - - public enum CaveType { - Solutional, Glacier, Fracture - } - -} 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.java deleted file mode 100644 index 910219eb..00000000 --- a/tests/src/main/java/com/github/klee0kai/test/mowgli/earth/IMountain.java +++ /dev/null @@ -1,4 +0,0 @@ -package com.github.klee0kai.test.mowgli.earth; - -public interface IMountain { -} 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.java deleted file mode 100644 index 85f2e91f..00000000 --- a/tests/src/main/java/com/github/klee0kai/test/mowgli/earth/IRiver.java +++ /dev/null @@ -1,4 +0,0 @@ -package com.github.klee0kai.test.mowgli.earth; - -public interface IRiver { -} 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.java deleted file mode 100644 index b45d4c8d..00000000 --- a/tests/src/main/java/com/github/klee0kai/test/mowgli/earth/Mountain.java +++ /dev/null @@ -1,9 +0,0 @@ -package com.github.klee0kai.test.mowgli.earth; - -import java.util.UUID; - -public class Mountain implements IMountain{ - - public UUID uuid = UUID.randomUUID(); - -} 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.java deleted file mode 100644 index 669e7d21..00000000 --- a/tests/src/main/java/com/github/klee0kai/test/mowgli/earth/River.java +++ /dev/null @@ -1,9 +0,0 @@ -package com.github.klee0kai.test.mowgli.earth; - -import java.util.UUID; - -public class River implements IRiver { - - public UUID uuid = UUID.randomUUID(); - -} 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.java deleted file mode 100644 index 76354546..00000000 --- a/tests/src/main/java/com/github/klee0kai/test/mowgli/galaxy/Earth.java +++ /dev/null @@ -1,10 +0,0 @@ -package com.github.klee0kai.test.mowgli.galaxy; - -import java.util.UUID; - -public class Earth implements IPlanet { - - public UUID uuid = UUID.randomUUID(); - - -} 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.java deleted file mode 100644 index 8bc6fa39..00000000 --- a/tests/src/main/java/com/github/klee0kai/test/mowgli/galaxy/IPlanet.java +++ /dev/null @@ -1,4 +0,0 @@ -package com.github.klee0kai.test.mowgli.galaxy; - -public interface IPlanet { -} 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.java deleted file mode 100644 index 6839e573..00000000 --- a/tests/src/main/java/com/github/klee0kai/test/mowgli/galaxy/IStar.java +++ /dev/null @@ -1,4 +0,0 @@ -package com.github.klee0kai.test.mowgli.galaxy; - -public interface IStar { -} 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.java deleted file mode 100644 index 6cfe9e46..00000000 --- a/tests/src/main/java/com/github/klee0kai/test/mowgli/galaxy/Mercury.java +++ /dev/null @@ -1,10 +0,0 @@ -package com.github.klee0kai.test.mowgli.galaxy; - -import java.util.UUID; - -public class Mercury implements IPlanet { - - public UUID uuid = UUID.randomUUID(); - - -} 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.java deleted file mode 100644 index c9577da5..00000000 --- a/tests/src/main/java/com/github/klee0kai/test/mowgli/galaxy/Saturn.java +++ /dev/null @@ -1,10 +0,0 @@ -package com.github.klee0kai.test.mowgli.galaxy; - -import java.util.UUID; - -public class Saturn implements IPlanet { - - public UUID uuid = UUID.randomUUID(); - - -} 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.java deleted file mode 100644 index acbe21a6..00000000 --- a/tests/src/main/java/com/github/klee0kai/test/mowgli/galaxy/SolarSystem.java +++ /dev/null @@ -1,12 +0,0 @@ -package com.github.klee0kai.test.mowgli.galaxy; - -public class SolarSystem { - - - public SolarSystem() { - } - - public SolarSystem(Sun sun, Earth earth) { - - } -} 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.java deleted file mode 100644 index eda821ed..00000000 --- a/tests/src/main/java/com/github/klee0kai/test/mowgli/galaxy/Sun.java +++ /dev/null @@ -1,9 +0,0 @@ -package com.github.klee0kai.test.mowgli.galaxy; - -import java.util.UUID; - -public class Sun implements IStar{ - - public UUID uuid = UUID.randomUUID(); - -} 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.java deleted file mode 100644 index 8dd6401e..00000000 --- a/tests/src/main/java/com/github/klee0kai/test/mowgli/identity/Conscience.java +++ /dev/null @@ -1,14 +0,0 @@ -package com.github.klee0kai.test.mowgli.identity; - -import java.util.UUID; - -public class Conscience { - - public UUID uuid = UUID.randomUUID(); - - public boolean isOldConscience() { - return false; - } - - -} 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.java deleted file mode 100644 index a9d9370d..00000000 --- a/tests/src/main/java/com/github/klee0kai/test/mowgli/identity/Ideology.java +++ /dev/null @@ -1,14 +0,0 @@ -package com.github.klee0kai.test.mowgli.identity; - -import java.util.UUID; - -public class Ideology { - - public UUID uuid = UUID.randomUUID(); - - - public boolean isFamilyIdeology(){ - return false; - } - -} 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.java deleted file mode 100644 index 2501ac1a..00000000 --- a/tests/src/main/java/com/github/klee0kai/test/mowgli/identity/Knowledge.java +++ /dev/null @@ -1,14 +0,0 @@ -package com.github.klee0kai.test.mowgli.identity; - -import java.util.UUID; - -public class Knowledge { - - public UUID uuid = UUID.randomUUID(); - - - public boolean isOldKnowledge(){ - return false; - } - -} 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.java deleted file mode 100644 index c06f839a..00000000 --- a/tests/src/main/java/com/github/klee0kai/test/tech/components/Battery.java +++ /dev/null @@ -1,9 +0,0 @@ -package com.github.klee0kai.test.tech.components; - -import java.util.UUID; - -public class Battery { - - public final UUID uuid = UUID.randomUUID(); - -} 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.java deleted file mode 100644 index 632491a4..00000000 --- a/tests/src/main/java/com/github/klee0kai/test/tech/components/DataStorage.java +++ /dev/null @@ -1,21 +0,0 @@ -package com.github.klee0kai.test.tech.components; - -import com.github.klee0kai.test.di.base_phone.identifiers.DataStorageSize; - -import java.util.UUID; - -public class DataStorage { - - public final UUID uuid = UUID.randomUUID(); - - public final String size; - - public DataStorage() { - size = null; - } - - public DataStorage(DataStorageSize size) { - this.size = size.size; - } - -} 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.java deleted file mode 100644 index 7bd8ce88..00000000 --- a/tests/src/main/java/com/github/klee0kai/test/tech/components/OperationSystem.java +++ /dev/null @@ -1,24 +0,0 @@ -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.UUID; - -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"); - } - - public OperationSystem(PhoneOsType phoneOsType, PhoneOsVersion version) { - this.phoneOsType = phoneOsType; - this.version = version; - } -} 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.java deleted file mode 100644 index 3e6246d1..00000000 --- a/tests/src/main/java/com/github/klee0kai/test/tech/components/Ram.java +++ /dev/null @@ -1,20 +0,0 @@ -package com.github.klee0kai.test.tech.components; - -import com.github.klee0kai.test.di.base_phone.identifiers.RamSize; - -import java.util.UUID; - -public class Ram { - - public final UUID uuid = UUID.randomUUID(); - - public final String size; - - public Ram() { - size = "default"; - } - - public Ram(RamSize ramSize) { - this.size = ramSize.size; - } -} 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.java deleted file mode 100644 index 16c07746..00000000 --- a/tests/src/main/java/com/github/klee0kai/test/tech/phone/GoodPhone.java +++ /dev/null @@ -1,45 +0,0 @@ -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 javax.inject.Inject; - -public class GoodPhone extends ATech { - - public StoneLifeCycleOwner lifeCycleOwner = LifecycleUtils.createFromATech(this); - - - @Inject - public Battery battery; - - @Inject - public DataStorage dataStorage; - - - @Inject - public Ram ram; - - @Inject - public OperationSystem os; - - public void dropToWater() { - onDrown(); - battery = null; - dataStorage = null; - ram = null; - } - - public void broke() { - onBroken(); - battery = null; - dataStorage = null; - ram = null; - } - -} 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.java deleted file mode 100644 index 88fee4bb..00000000 --- a/tests/src/main/java/com/github/klee0kai/test/tech/phone/OnePhone.java +++ /dev/null @@ -1,63 +0,0 @@ -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 { - - @Inject - public Battery battery; - - @Inject - @Named("null_args") - public DataStorage dataStorage; - - @Inject - @Named("null_args") - public Ram ram; - - - @Override - public void subscribe(StoneLifeCycleListener listener) { - super.subscribe(new ATechLifecycle() { - @Override - public void onBuy() { - - } - - @Override - public void onBroken() { - - } - - @Override - public void onDrown() { - listener.protectForInjected(100); - } - }); - } - - - public void dropToWatter() { - onDrown(); - battery = null; - dataStorage = null; - ram = null; - } - - public void broke() { - onBroken(); - battery = null; - dataStorage = null; - ram = null; - } - -} 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.java deleted file mode 100644 index 81f12fcf..00000000 --- a/tests/src/main/java/com/github/klee0kai/test/tech/phone/base/ATech.java +++ /dev/null @@ -1,29 +0,0 @@ -package com.github.klee0kai.test.tech.phone.base; - -import java.util.LinkedList; - -public abstract class ATech { - - private LinkedList listeners = new LinkedList<>(); - - public void subscribe(ATechLifecycle listener) { - this.listeners.add(listener); - } - - public void onBuy() { - for (ATechLifecycle lis : listeners) - lis.onBuy(); - } - - public void onBroken() { - for (ATechLifecycle lis : listeners) - lis.onBroken(); - } - - public void onDrown() { - for (ATechLifecycle lis : listeners) - lis.onDrown(); - } - - -} 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.java deleted file mode 100644 index 4fd81a7a..00000000 --- a/tests/src/main/java/com/github/klee0kai/test/tech/phone/base/ATechLifecycle.java +++ /dev/null @@ -1,11 +0,0 @@ -package com.github.klee0kai.test.tech.phone.base; - -public interface ATechLifecycle { - - void onBuy(); - - void onBroken(); - - void onDrown(); - -} 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.java deleted file mode 100644 index 5cdd8e36..00000000 --- a/tests/src/main/java/com/github/klee0kai/test/tech/phone/base/LifecycleUtils.java +++ /dev/null @@ -1,29 +0,0 @@ -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() { - - } - - @Override - public void onBroken() { - - } - - @Override - public void onDrown() { - listener.protectForInjected(100); - } - } - ); - } - - -} 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.java deleted file mode 100644 index 28b96a73..00000000 --- a/tests/src/main/java/com/github/klee0kai/test/wire/Wire.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.github.klee0kai.test.wire; - -import java.util.UUID; - -public class Wire { - - public final UUID uuid = UUID.randomUUID(); - - public Input input; - - public Output output; - -} 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.java deleted file mode 100644 index e9537c9f..00000000 --- a/tests/src/main/java/com/github/klee0kai/test/wire/types/Hdmi.java +++ /dev/null @@ -1,9 +0,0 @@ -package com.github.klee0kai.test.wire.types; - -import java.util.UUID; - -public class Hdmi { - - public final UUID uuid = UUID.randomUUID(); - -} 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.java deleted file mode 100644 index 8b15f098..00000000 --- a/tests/src/main/java/com/github/klee0kai/test/wire/types/MiniUsb.java +++ /dev/null @@ -1,9 +0,0 @@ -package com.github.klee0kai.test.wire.types; - -import java.util.UUID; - -public class MiniUsb { - - public final UUID uuid = UUID.randomUUID(); - -} 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.java deleted file mode 100644 index 7b5c8165..00000000 --- a/tests/src/main/java/com/github/klee0kai/test/wire/types/Usb.java +++ /dev/null @@ -1,9 +0,0 @@ -package com.github.klee0kai.test.wire.types; - -import java.util.UUID; - -public class Usb { - - public final UUID uuid = UUID.randomUUID(); - -} 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/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.java deleted file mode 100644 index da4bc33b..00000000 --- a/tests/src/test/java/com/github/klee0kai/stone/test/bindinstance/simple/GodFirstWorkDayTest.java +++ /dev/null @@ -1,90 +0,0 @@ -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 static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNull; - -public class GodFirstWorkDayTest { - - @Test - public void firstCreateSunTest() { - //Given - GodWorkspaceComponent DI = Stone.createComponent(GodWorkspaceComponent.class); - Sun sun = new Sun(); - - //When - DI.bindSun(sun); - - //Then - assertEquals(sun.uuid, DI.sunSystem().sun().uuid); - assertNull(DI.sunSystem().earth()); - } - - - @Test - public void createSunAndEarthTest() { - //Given - GodWorkspaceComponent DI = Stone.createComponent(GodWorkspaceComponent.class); - Sun sun = new Sun(); - Earth earth = new 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 - public void createSunEarthSaturnTest() { - //Given - GodWorkspaceComponent DI = Stone.createComponent(GodWorkspaceComponent.class); - Sun sun = new Sun(); - Earth earth = new Earth(); - Saturn saturn = new 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 - public void createSaturnEarthSunTest() { - //Given - GodWorkspaceComponent DI = Stone.createComponent(GodWorkspaceComponent.class); - Sun sun = new Sun(); - Earth earth = new Earth(); - Saturn saturn = new 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()); - } - - -} 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.java deleted file mode 100644 index 638b9d17..00000000 --- a/tests/src/test/java/com/github/klee0kai/stone/test/bindinstance/simple/GodTouchTest.java +++ /dev/null @@ -1,85 +0,0 @@ -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 static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNull; - -public class GodTouchTest { - - @Test - public void firstCreateSunTest() { - //Given - GodWorkspaceComponent DI = Stone.createComponent(GodWorkspaceComponent.class); - Sun sun = new Sun(); - - //When - DI.bindSun(sun); - - //Then - assertEquals(sun.uuid, DI.sunSystem().sun().uuid); - assertNull(DI.sunSystem().earth()); - } - - - @Test - public void createSunAndEarthTest() { - //Given - GodWorkspaceComponent DI = Stone.createComponent(GodWorkspaceComponent.class); - Sun sun = new Sun(); - Earth earth = new 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 - public void createSaturnEarthSunTest() { - //Given - GodWorkspaceComponent DI = Stone.createComponent(GodWorkspaceComponent.class); - Sun sun = new Sun(); - Earth earth = new Earth(); - Saturn saturn = new 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 - public void planetIsPlanetTest() { - //Given - GodWorkspaceComponent DI = Stone.createComponent(GodWorkspaceComponent.class); - Earth earth = new Earth(); - - //When - DI.planet(earth); - DI.planet(null); - - //Then - 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.java b/tests/src/test/java/com/github/klee0kai/stone/test/bindinstance/simple_inject/SevenPlanetTests.java deleted file mode 100644 index efb11448..00000000 --- a/tests/src/test/java/com/github/klee0kai/stone/test/bindinstance/simple_inject/SevenPlanetTests.java +++ /dev/null @@ -1,35 +0,0 @@ -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 static org.junit.jupiter.api.Assertions.assertEquals; - -public class SevenPlanetTests { - - @Test - public void 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); - - //When - MoonSky moonSky = new MoonSky(); - component.inject(moonSky); - - //Then - 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.java b/tests/src/test/java/com/github/klee0kai/stone/test/bindinstance/singlemethod/PlanetProvideTests.java deleted file mode 100644 index 83dc1330..00000000 --- a/tests/src/test/java/com/github/klee0kai/stone/test/bindinstance/singlemethod/PlanetProvideTests.java +++ /dev/null @@ -1,83 +0,0 @@ -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 static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNull; - -public class PlanetProvideTests { - - @Test - public void bindPlanetTest() { - //Given - PlanetComponent DI = Stone.createComponent(PlanetComponent.class); - Earth earth = new 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 - public void bindEarthTest() { - //Given - PlanetComponent DI = Stone.createComponent(PlanetComponent.class); - Earth earth = new Earth(); - - //When - DI.earth(earth); - - //Then - assertEquals(earth, DI.earth(null)); - assertEquals(earth, DI.earth(null)); - assertNull(DI.planet(null)); - assertNull(DI.providePlanet()); - } - - @Test - public void bindEarthCommonTest() { - //Given - PlanetComponent DI = Stone.createComponent(PlanetComponent.class); - Earth earth = new Earth(); - - //When - DI.earth(earth); - - //Then - assertEquals(earth, DI.earth(null)); - assertEquals(earth, DI.earth(null)); - assertNull(DI.planet(null)); - assertNull(DI.providePlanet()); - } - - - @Test - public void separateBindEarthTest() { - //Given - PlanetRollingComponent DI = Stone.createComponent(PlanetRollingComponent.class); - Earth earth1 = new Earth(); - Earth earth2 = new Earth(); - Earth earth3 = new Earth(); - - //When - 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)); - } - -} 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.java deleted file mode 100644 index d80a8921..00000000 --- a/tests/src/test/java/com/github/klee0kai/stone/test/bindinstance/singlemethod/StarProvideTests.java +++ /dev/null @@ -1,64 +0,0 @@ -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 static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNull; - -public class StarProvideTests { - - @Test - public void bindSunTest() { - //Given - PlanetComponent DI = Stone.createComponent(PlanetComponent.class); - Sun sun = new 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 - public void bindStarTest() { - //Given - PlanetComponent DI = Stone.createComponent(PlanetComponent.class); - Sun sun = new Sun(); - - //When - DI.sunModule().star(sun); - - //Then - assertEquals(sun, DI.sunModule().star(null)); - assertEquals(sun, DI.sunModule().star(null)); - assertNull(DI.sunModule().sun(null)); - } - - - @Test - public void separateSunBindingTest() { - //Given - PlanetComponent DI = Stone.createComponent(PlanetComponent.class); - Sun sun1 = new Sun(); - Sun sun2 = new Sun(); - Sun sun3 = new Sun(); - - //When - 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)); - } - - -} 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.java deleted file mode 100644 index 12df635b..00000000 --- a/tests/src/test/java/com/github/klee0kai/stone/test/bindinstance/singlemethod_gc/PlanetRollingTests.java +++ /dev/null @@ -1,228 +0,0 @@ -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 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 { - - @Test - public void 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()); - - //When - DI.gcAll(); - - //Then - for (WeakReference ref : Arrays.asList( - earthStrong, earthSoft, planetWeak, - sunStrong, sunSoft, starWeak - )) { - assertNull(ref.get()); - } - } - - - @Test - public void 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()); - - //When - DI.gcStrong(); - - //Then - for (WeakReference ref : Arrays.asList( - earthStrong, planetWeak, - sunStrong, starWeak - )) { - assertNull(ref.get()); - } - - for (WeakReference ref : Arrays.asList( - earthSoft, - sunSoft - )) { - assertNotNull(ref.get()); - } - } - - @Test - public void 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()); - - //When - DI.gcSoft(); - - //Then - for (WeakReference ref : Arrays.asList( - earthSoft, planetWeak, - sunSoft, starWeak - )) { - assertNull(ref.get()); - } - - for (WeakReference ref : Arrays.asList( - earthStrong, - sunStrong - )) { - assertNotNull(ref.get()); - } - } - - @Test - public void 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()); - - //When - DI.gcWeak(); - - //Then - for (WeakReference ref : Arrays.asList( - planetWeak, - starWeak - )) { - assertNull(ref.get()); - } - - for (WeakReference ref : Arrays.asList( - earthStrong, earthSoft, - sunStrong, sunSoft - )) { - assertNotNull(ref.get()); - } - } - - @Test - public void 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()); - - //When - DI.gcSoftSun(); - - //Then - for (WeakReference ref : Arrays.asList( - planetWeak, - sunSoft, starWeak - )) { - assertNull(ref.get()); - } - - for (WeakReference ref : Arrays.asList( - earthStrong, earthSoft, - sunStrong - )) { - assertNotNull(ref.get()); - } - } - - @Test - public void 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()); - - //When - DI.gcSoftPlanets(); - - //Then - for (WeakReference ref : Arrays.asList( - earthSoft, planetWeak, - starWeak - )) { - assertNull(ref.get()); - } - - for (WeakReference ref : Arrays.asList( - earthStrong, - sunStrong, sunSoft - )) { - assertNotNull(ref.get()); - } - } - - -} 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.java deleted file mode 100644 index 3ab408a7..00000000 --- a/tests/src/test/java/com/github/klee0kai/stone/test/bindinstance/singlemethod_inject/MoonSkyProtectInjectedTests.java +++ /dev/null @@ -1,65 +0,0 @@ -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 java.lang.ref.WeakReference; - -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertNull; - -public class MoonSkyProtectInjectedTests { - - @Test - public void 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()); - - //When - MoonSky moonSky = new MoonSky(); - component.inject(moonSky); - moonSky = null; - component.gcAll(); - - - //Then - assertNull(mercury.get()); - assertNull(star.get()); - } - - - @Test - public void withProtectInjectedTest() throws InterruptedException { - //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()); - - //When - MoonSky moonSky = new MoonSky(); - component.inject(moonSky); - component.protectInjected(moonSky); - moonSky = null; - component.gcAll(); - - assertNotNull(mercury.get()); - assertNotNull(star.get()); - - //Then after protect finished - 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.java b/tests/src/test/java/com/github/klee0kai/stone/test/bindinstance/singlemethod_inject/MoonSkyTests.java deleted file mode 100644 index ca1aaeb0..00000000 --- a/tests/src/test/java/com/github/klee0kai/stone/test/bindinstance/singlemethod_inject/MoonSkyTests.java +++ /dev/null @@ -1,39 +0,0 @@ -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 static org.junit.jupiter.api.Assertions.assertEquals; - -public class MoonSkyTests { - - @Test - public void 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); - - //When - MoonSky moonSky = new MoonSky(); - component.inject(moonSky); - - //Then - 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.java b/tests/src/test/java/com/github/klee0kai/stone/test/bindinstance/solarsystem/SolarSystemTests.java deleted file mode 100644 index 1975bee6..00000000 --- a/tests/src/test/java/com/github/klee0kai/stone/test/bindinstance/solarsystem/SolarSystemTests.java +++ /dev/null @@ -1,41 +0,0 @@ -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 static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotNull; - -public class SolarSystemTests { - - @Test - public void provideSolarSystemTest() { - //Given - SolarSystemComponent DI = Stone.createComponent(SolarSystemComponent.class); - SolarSystem solarSystem = new SolarSystem(); - - // When - DI.bind(solarSystem); - - // Then - assertEquals(solarSystem, DI.bind(null)); - } - - - @Test - public void provideEarthTest() { - //Given - SolarSystemComponent DI = Stone.createComponent(SolarSystemComponent.class); - SolarSystem solarSystem = new SolarSystem(); - - // When - DI.bind(solarSystem); - - // Then - assertNotNull(DI.earth()); - } - - -} 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.java deleted file mode 100644 index d3236967..00000000 --- a/tests/src/test/java/com/github/klee0kai/stone/test/cache/EarthCacheTests.java +++ /dev/null @@ -1,148 +0,0 @@ -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 { - - - @Test - public void strongCacheTest() { - //Given - GcGodComponent DI = Stone.createComponent(GcGodComponent.class); - - //When - Mountain mountain1 = DI.earth().mountainStrong(); - Mountain mountain2 = DI.earth().mountainStrong(); - - //Then - assertEquals( - mountain1.uuid, - mountain2.uuid - ); - } - - - @Test - public void softCacheTest() { - //Given - GcGodComponent DI = Stone.createComponent(GcGodComponent.class); - - //When - Mountain mountain1 = DI.earth().mountainSoft(); - Mountain mountain2 = DI.earth().mountainSoft(); - - //Then - assertEquals( - mountain1.uuid, - mountain2.uuid - ); - } - - @Test - public void weakCacheTest() { - //Given - GcGodComponent DI = Stone.createComponent(GcGodComponent.class); - - //When - Mountain mountain1 = DI.earth().mountainWeak(); - Mountain mountain2 = DI.earth().mountainWeak(); - - //Then - assertEquals( - mountain1.uuid, - mountain2.uuid - ); - } - - @Test - public void defCacheTest() { - //Given - GcGodComponent DI = Stone.createComponent(GcGodComponent.class); - - //When - Mountain mountain1 = DI.earth().mountainDefaultFactory(); - Mountain mountain2 = DI.earth().mountainDefaultFactory(); - - //Then - assertNotEquals( - mountain1.uuid, - mountain2.uuid, - "Default is factory providing" - ); - } - - @Test - public void defCache2Test() { - //Given - GcGodComponent DI = Stone.createComponent(GcGodComponent.class); - - //When - Mountain mountain1 = DI.earth().mountainDefault2Factory(); - Mountain mountain2 = DI.earth().mountainDefault2Factory(); - - //Then - assertNotEquals( - mountain1.uuid, - mountain2.uuid, - "Default is factory providing" - ); - } - - @Test - public void differentMethodDifferentCacheTest() { - //Given - GcGodComponent DI = Stone.createComponent(GcGodComponent.class); - - //When - Mountain mountainStrong = DI.earth().mountainStrong(); - Mountain mountainSoft = DI.earth().mountainSoft(); - - //Then - assertNotEquals( - mountainStrong.uuid, - mountainSoft.uuid - ); - } - - - @Test - public void factoryNotCacheTest() { - //Given - GcGodComponent DI = Stone.createComponent(GcGodComponent.class); - - //When - Mountain mountain1 = DI.earth().mountainFactory(); - Mountain mountain2 = DI.earth().mountainFactory(); - - //Then - assertNotEquals( - mountain1.uuid, - mountain2.uuid - ); - } - - - @Test - public void differentDIDifferentCacheTest() { - //Given - GcGodComponent DI1 = Stone.createComponent(GcGodComponent.class); - GcGodComponent DI2 = Stone.createComponent(GcGodComponent.class); - - //When - Mountain mountain1 = DI1.earth().mountainStrong(); - Mountain mountain2 = DI2.earth().mountainStrong(); - - //Then - assertNotEquals( - mountain1.uuid, - mountain2.uuid - ); - } - -} 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.java deleted file mode 100644 index b62ee09d..00000000 --- a/tests/src/test/java/com/github/klee0kai/stone/test/cache/EarthSwitchCacheTests.java +++ /dev/null @@ -1,87 +0,0 @@ -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 { - - - @Test - public void allToWeakTest() { - //Given - SwitchCacheComponent DI = Stone.createComponent(SwitchCacheComponent.class); - WeakReference mountain = new WeakReference<>(DI.earth().mountainStrong()); - - //When - DI.allWeak(); - System.gc(); - - //Then - assertNull(mountain.get()); - } - - @Test - public void strongToWeakTest() { - //Given - SwitchCacheComponent DI = Stone.createComponent(SwitchCacheComponent.class); - WeakReference mountainStrong = new WeakReference<>(DI.earth().mountainStrong()); - WeakReference mountainSoft = new WeakReference<>(DI.earth().mountainSoft()); - - //When - DI.strongToWeak(); - System.gc(); - - //Then - assertNull(mountainStrong.get()); - assertNotNull(mountainSoft.get()); - } - - @Test - public void weakToStrongFewMillisTest() throws InterruptedException { - //Given - SwitchCacheComponent DI = Stone.createComponent(SwitchCacheComponent.class); - WeakReference mountainWeak = new WeakReference<>(DI.earth().mountainWeak()); - - //When - DI.allStrongFewMillis(); - System.gc(); - - //Then: can't GC - assertNotNull(mountainWeak.get()); - - //When: after few millis - sleep(110); - System.gc(); - - //Then: can GC - assertNull(mountainWeak.get()); - } - - - @Test - public void mountainToWeakTest() { - //Given - SwitchCacheComponent DI = Stone.createComponent(SwitchCacheComponent.class); - WeakReference mountain = new WeakReference<>(DI.earth().mountainStrong()); - WeakReference river = new WeakReference<>(DI.earth().riverSoft()); - - //When - DI.mountainToWeak(); - System.gc(); - - //Then - assertNull(mountain.get()); - assertNotNull(river.get()); - } - - -} 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.java deleted file mode 100644 index 15d46efc..00000000 --- a/tests/src/test/java/com/github/klee0kai/stone/test/deps/HouseFactoryTests.java +++ /dev/null @@ -1,40 +0,0 @@ -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 static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotEquals; - -public class HouseFactoryTests { - - @Test - public void cacheTest() { - //Given - HouseComponent di = Stone.createComponent(HouseComponent.class); - - //when - House house1 = di.module().house(null, null, null, null); - House house2 = di.module().house(null, null, null, null); - - //then - assertEquals(house1.uuid, house2.uuid); - } - - - @Test - public void factoryTest() { - //Given - HouseComponent di = Stone.createComponent(HouseComponent.class); - - //when - House house1 = di.moduleFactory().house(null, null, null, null); - House house2 = di.moduleFactory().house(null, null, null, null); - - //then - assertNotEquals(house1.uuid, house2.uuid); - } - -} 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.java deleted file mode 100644 index 2437a54a..00000000 --- a/tests/src/test/java/com/github/klee0kai/stone/test/deps/HouseNullsTests.java +++ /dev/null @@ -1,27 +0,0 @@ -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 static org.junit.jupiter.api.Assertions.assertNull; - -public class HouseNullsTests { - - @Test - public void buildOnlyKitchenTest() { - //Given - HouseNullsComponent di = Stone.createComponent(HouseNullsComponent.class); - - //when - House house = di.house(); - - //then - 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.java b/tests/src/test/java/com/github/klee0kai/stone/test/deps/HouseTests.java deleted file mode 100644 index a2eea9b8..00000000 --- a/tests/src/test/java/com/github/klee0kai/stone/test/deps/HouseTests.java +++ /dev/null @@ -1,85 +0,0 @@ -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 static org.junit.jupiter.api.Assertions.*; - -public class HouseTests { - - @Test - public void buildHouseTest() { - //Given - HouseComponent di = Stone.createComponent(HouseComponent.class); - - //when - House house = di.house(); - - //then - assertNotNull(house.bathRoom); - assertNotNull(house.kichen.cookingArea); - assertNotNull(house.kichen.storeArea); - assertNotNull(house.kichen.sinkArea); - } - - @Test - public void identifiersTest() { - //Given - HouseComponent di = Stone.createComponent(HouseComponent.class); - - //when - House house = di.house(StoreAreaType.CLOSED); - - //then - assertEquals(StoreAreaType.CLOSED, house.kichen.storeArea.type); - } - - @Test - public void identifiersNullTest() { - //Given - HouseComponent di = Stone.createComponent(HouseComponent.class); - - //when - House house = di.house(); - - //then - assertNull(house.kichen.storeArea.type); - } - - - @Test - public void cacheTest() { - //Given - HouseComponent di = Stone.createComponent(HouseComponent.class); - - //when - House house1 = di.house(); - House house2 = di.house(); - - //then - assertEquals(house1.kichen.uuid, house2.kichen.uuid); - } - - - @Test - public void factoryTest() { - //Given - HouseComponent di = Stone.createComponent(HouseComponent.class); - - //when - House house = di.house(); - Sanitizers sanitizers1 = di.sanitizers(); - Sanitizers 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); - } - - -} 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.java deleted file mode 100644 index bdd5d5cf..00000000 --- a/tests/src/test/java/com/github/klee0kai/stone/test/deps/InHouseTests.java +++ /dev/null @@ -1,91 +0,0 @@ -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() { - //Given - HouseComponent di = Stone.createComponent(HouseComponent.class); - InHouse inHouse = new InHouse(); - - //when - di.inject(inHouse); - - //then - assertNotNull(inHouse.bathRoom); - assertNotNull(inHouse.kichen.cookingArea); - assertNotNull(inHouse.kichen.storeArea); - assertNotNull(inHouse.kichen.sinkArea); - assertNotNull(inHouse.bedStoreArea); - } - - @Test - public void identifiersTest() { - //Given - HouseComponent di = Stone.createComponent(HouseComponent.class); - InHouse inHouse = new InHouse(); - - //when - di.inject(StoreAreaType.CLOSED,inHouse); - - - //then - assertEquals(StoreAreaType.CLOSED, inHouse.kichen.storeArea.type); - } - - @Test - public void identifiersNullTest() { - //Given - HouseComponent di = Stone.createComponent(HouseComponent.class); - InHouse inHouse = new InHouse(); - - //when - di.inject(inHouse); - - - //then - assertNull(inHouse.kichen.storeArea.type); - } - - - @Test - public void cacheTest() { - //Given - HouseComponent di = Stone.createComponent(HouseComponent.class); - InHouse inHouse1 = new InHouse(); - InHouse inHouse2 = new InHouse(); - - //when - di.inject(inHouse1); - di.inject(inHouse2); - - //then - assertEquals(inHouse1.kichen.uuid, inHouse2.kichen.uuid); - } - - - @Test - public void factoryTest() { - //Given - HouseComponent di = Stone.createComponent(HouseComponent.class); - InHouse inHouse1 = new InHouse(); - InHouse inHouse2 = new InHouse(); - - //when - 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); - } - -} 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.java deleted file mode 100644 index 39a492ac..00000000 --- a/tests/src/test/java/com/github/klee0kai/stone/test/gc/EarthLastDayTests.java +++ /dev/null @@ -1,288 +0,0 @@ -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 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 { - - @Test - void 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()); - - //When - di.gcAll(); - - //Then - for (Reference ref : Arrays.asList( - mountainStrong, mountainSoft, mountainDef2, mountainWeak, mountainDef, - riverStrong, riverSoft, riverWeak, riverDef - )) { - assertNull(ref.get()); - } - } - - @Test - void 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()); - - //When - di.gcStrong(); - - //Then - for (Reference ref : Arrays.asList( - mountainStrong, mountainWeak, mountainDef, mountainDef2, - riverStrong, riverWeak, riverDef - )) { - assertNull(ref.get()); - } - - for (Reference ref : Arrays.asList( - mountainSoft, - riverSoft - )) { - assertNotNull(ref.get()); - } - } - - @Test - void 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()); - - //When - di.gcSoft(); - - //Then - for (Reference ref : Arrays.asList( - mountainSoft, mountainWeak, mountainDef, mountainDef2, - riverSoft, riverWeak, riverDef - )) { - assertNull(ref.get()); - } - for (Reference ref : Arrays.asList( - mountainStrong, - riverStrong - )) { - assertNotNull(ref.get()); - } - } - - @Test - void 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()); - - //When - di.gcWeak(); - - //Then - for (Reference ref : Arrays.asList( - mountainWeak, mountainDef, - riverWeak, riverDef - )) { - assertNull(ref.get()); - } - for (Reference ref : Arrays.asList( - mountainStrong, mountainSoft, - riverStrong, riverSoft - )) { - assertNotNull(ref.get()); - } - } - - @Test - void 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()); - - //When - di.gcMountains(); - - //Then - for (Reference ref : Arrays.asList( - mountainStrong, mountainSoft, mountainWeak, mountainDef, - riverWeak, riverDef - )) { - assertNull(ref.get()); - } - for (Reference ref : Arrays.asList( - riverStrong, riverSoft - )) { - assertNotNull(ref.get()); - } - } - - @Test - void 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()); - - //When - di.gcRivers(); - - //Then - for (Reference ref : Arrays.asList( - mountainWeak, mountainDef, - riverStrong, riverSoft, riverWeak, riverDef - )) { - assertNull(ref.get()); - } - for (Reference ref : Arrays.asList( - mountainStrong, mountainSoft - )) { - assertNotNull(ref.get()); - } - } - - @Test - void 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()); - - //When - di.gcMountainsAndRivers(); - - //Then - for (Reference ref : Arrays.asList( - mountainStrong, mountainSoft, mountainWeak, mountainDef, - riverStrong, riverSoft, riverWeak, riverDef - )) { - assertNull(ref.get()); - } - } - - - @Test - void 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()); - - //When - di.gcSoftMountains(); - - //Then - for (Reference ref : Arrays.asList( - mountainSoft, mountainWeak, mountainDef, - riverWeak, riverDef - )) { - assertNull(ref.get()); - } - for (Reference ref : Arrays.asList( - mountainStrong, - riverStrong, riverSoft - )) { - assertNotNull(ref.get()); - } - } - - @Test - void 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()); - - //When - di.gcStrongMountains(); - - //Then - for (Reference ref : Arrays.asList( - mountainStrong, mountainWeak, mountainDef, - riverWeak, riverDef - )) { - assertNull(ref.get()); - } - for (Reference ref : Arrays.asList( - mountainSoft, - riverStrong, riverSoft - )) { - assertNotNull(ref.get()); - } - } - -} 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.java deleted file mode 100644 index 8d92eee5..00000000 --- a/tests/src/test/java/com/github/klee0kai/stone/test/gc/GodLastWorkDayTests.java +++ /dev/null @@ -1,162 +0,0 @@ -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 { - - - @Test - void 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()); - - //When - di.gcAll(); - - //Then - assertNull(sunRef.get()); - assertNull(earthRef.get()); - assertNull(saturnRef.get()); - } - - - @Test - void 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()); - - //When - di.gcWeak(); - - //Then - assertNotNull(sunRef.get()); - assertNotNull(earthRef.get()); - assertNull(saturnRef.get()); - } - - - @Test - void 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()); - - //When - di.gcSoft(); - - //Then - assertNotNull(sunRef.get()); - assertNull(earthRef.get()); - assertNull(saturnRef.get()); - } - - @Test - void 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()); - - //When - di.gcStrong(); - - //Then - assertNull(sunRef.get()); - assertNotNull(earthRef.get()); - assertNull(saturnRef.get()); - } - - - @Test - void 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()); - - //When - di.gcSun(); - - //Then - assertNull(sunRef.get()); - assertNotNull(earthRef.get()); - assertNull(saturnRef.get()); - } - - - @Test - void 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()); - - //When - di.gcPlanets(); - - //Then - assertNotNull(sunRef.get()); - assertNull(earthRef.get()); - assertNull(saturnRef.get()); - } - - @Test - void 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()); - - //When - di.gcSunAndPlanets(); - - //Then - assertNull(sunRef.get()); - assertNull(earthRef.get()); - assertNull(saturnRef.get()); - } -} 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.java deleted file mode 100644 index 369f25eb..00000000 --- a/tests/src/test/java/com/github/klee0kai/stone/test/identifiers/GoodPhoneInjectTests.java +++ /dev/null @@ -1,44 +0,0 @@ -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 { - - - @Test - public void createGoodPhoneTest() { - //Given - PhoneComponent DI = Stone.createComponent(PhoneComponent.class); - GoodPhone goodPhone = new GoodPhone(); - - //When - DI.inject(goodPhone, goodPhone.lifeCycleOwner, new DataStorageSize("120GB"), new RamSize("8GB")); - - //Then - assertEquals("120GB", goodPhone.dataStorage.size); - assertEquals("8GB", goodPhone.ram.size); - } - - @Test - public void cacheInjectedPhoneTest() { - //Given - PhoneComponent DI = Stone.createComponent(PhoneComponent.class); - GoodPhone goodPhone1 = new GoodPhone(); - GoodPhone goodPhone2 = new GoodPhone(); - - //When - DI.inject(goodPhone1, goodPhone1.lifeCycleOwner, new DataStorageSize("120GB"), new RamSize("8GB")); - DI.inject(goodPhone2, goodPhone2.lifeCycleOwner, new DataStorageSize("120GB"), new RamSize("8GB")); - - //Then - assertEquals(goodPhone1.ram.uuid, goodPhone2.ram.uuid); - } - -} 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.java deleted file mode 100644 index 29d825c3..00000000 --- a/tests/src/test/java/com/github/klee0kai/stone/test/identifiers/MultiIdentifiersTests.java +++ /dev/null @@ -1,66 +0,0 @@ -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 static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotEquals; - -public class MultiIdentifiersTests { - @Test - public void differentCreatePhoneTest() { - //Given - PhoneComponent DI = Stone.createComponent(PhoneComponent.class); - - //When - OperationSystem androidDemo = DI.components().phoneOs(PhoneOsType.Android, null); - OperationSystem android11 = DI.components().phoneOs(PhoneOsType.Android, new PhoneOsVersion("11")); - - //Then - assertNotEquals(androidDemo.uuid, android11.uuid); - } - - - @Test - public void differentMethodDifferentCacheTest() { - //Given - PhoneComponent DI = Stone.createComponent(PhoneComponent.class); - - //When - OperationSystem android11 = DI.components().phoneOs(PhoneOsType.Android, new PhoneOsVersion("11")); - OperationSystem androidSimple = DI.components().phoneOs(PhoneOsType.Android); - - //Then - assertNotEquals(androidSimple.uuid, android11.uuid); - } - - @Test - public void cacheByIdentifiersTest() { - //Given - PhoneComponent DI = Stone.createComponent(PhoneComponent.class); - - //When - OperationSystem android11 = DI.components().phoneOs(PhoneOsType.Android, new PhoneOsVersion("11")); - OperationSystem android11_2 = DI.components().phoneOs(PhoneOsType.Android, new PhoneOsVersion("11")); - - //Then - assertEquals(android11.uuid, android11_2.uuid); - } - - @Test - public void sepCacheByIdentifiersTest() { - //Given - PhoneComponent DI = Stone.createComponent(PhoneComponent.class); - - //When - OperationSystem android11 = DI.components().phoneOs(PhoneOsType.Android, new PhoneOsVersion("11")); - OperationSystem android12 = DI.components().phoneOs(PhoneOsType.Android, new PhoneOsVersion("12")); - - //Then - assertNotEquals(android11.uuid, android12.uuid); - } -} 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.java deleted file mode 100644 index 5f57ca62..00000000 --- a/tests/src/test/java/com/github/klee0kai/stone/test/identifiers/TechComponentsTests.java +++ /dev/null @@ -1,71 +0,0 @@ -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 static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotEquals; - -public class TechComponentsTests { - - @Test - public void differentCreateTest() { - //Given - PhoneComponent DI = Stone.createComponent(PhoneComponent.class); - - //When - Ram ram8Gb = DI.components().ram(new RamSize("8GB")); - Ram ram9Gb = DI.components().ram(new RamSize("9GB")); - - //Then: created components are different - assertNotEquals(ram8Gb.uuid, ram9Gb.uuid); - } - - @Test - public void singleCacheTest() { - //Given - PhoneComponent DI = Stone.createComponent(PhoneComponent.class); - - //When - Ram ram1 = DI.components().ram(new RamSize("8GB")); - Ram ram2 = DI.components().ram(new RamSize("8GB")); - - //Then: cached ram - assertEquals(ram1.uuid, ram2.uuid); - } - - @Test - public void enumDifferentTest() { - //Given - PhoneComponent DI = Stone.createComponent(PhoneComponent.class); - - //When - OperationSystem android = DI.components().phoneOs(PhoneOsType.Android); - OperationSystem osNull = DI.components().phoneOs(null); - OperationSystem ios = DI.components().phoneOs(PhoneOsType.Ios); - - //Then: created components are different - assertNotEquals(android.uuid, osNull.uuid); - assertNotEquals(android.uuid, ios.uuid); - } - - @Test - public void enumCachedTest() { - //Given - PhoneComponent DI = Stone.createComponent(PhoneComponent.class); - - //When - OperationSystem android = DI.components().phoneOs(PhoneOsType.Android); - OperationSystem android2 = DI.components().phoneOs(PhoneOsType.Android); - - //Then: created components are different - assertEquals(android.uuid, android2.uuid); - } - - -} 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.java deleted file mode 100644 index 4122779a..00000000 --- a/tests/src/test/java/com/github/klee0kai/stone/test/identifiers/TechFactoryComponentTests.java +++ /dev/null @@ -1,99 +0,0 @@ -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 static org.junit.jupiter.api.Assertions.*; - -public class TechFactoryComponentTests { - - @Test - public void nonArgProvideTest() { - //Given - TechFactoryComponent DI = Stone.createComponent(TechFactoryComponent.class); - - //When - Ram ram = DI.ram(); - - //Then - assertEquals("default", ram.size); - } - - @Test - public void singleArgProvideTest() { - //Given - TechFactoryComponent DI = Stone.createComponent(TechFactoryComponent.class); - - //When - Ram ram = DI.ram(new RamSize("4G")); - - //Then - assertEquals("4G", ram.size); - } - - - @Test - public void nullGenerateArgProvideTest() { - //Given - TechFactoryComponent DI = Stone.createComponent(TechFactoryComponent.class); - - //When - OperationSystem os = DI.phoneOs(); - - //Then: should pass null missing args - assertNull(os.phoneOsType); // missing args - assertEquals("default", os.version.version); // default from constructor - } - - @Test - public void coupleArgsProvideTest() { - //Given - TechFactoryComponent DI = Stone.createComponent(TechFactoryComponent.class); - - //When - OperationSystem os = DI.phoneOs(PhoneOsType.Ios, new PhoneOsVersion("11")); - - //Then - assertEquals(PhoneOsType.Ios, os.phoneOsType); - assertEquals("11", os.version.version); - } - - - @Test - public void differentCreateTest() { - //Given - TechFactoryComponent DI = Stone.createComponent(TechFactoryComponent.class); - - //When - Ram ram8Gb = DI.ram(new RamSize("8GB")); - Ram ram8Gb2 = DI.ram(new RamSize("8GB")); - - //Then: created components are different - assertEquals("8GB", ram8Gb.size); - assertNotEquals(ram8Gb.uuid, ram8Gb2.uuid); - } - - - @Test - public void enumDifferentTest() { - //Given - TechFactoryComponent DI = Stone.createComponent(TechFactoryComponent.class); - - //When - OperationSystem android = DI.phoneOs(PhoneOsType.Android); - OperationSystem android2 = DI.phoneOs(PhoneOsType.Android); - OperationSystem osNull = DI.phoneOs(null); - - //Then: created components are different - assertNotEquals(android.uuid, osNull.uuid); - assertNotEquals(android.uuid, android2.uuid); - } - - -} 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.java deleted file mode 100644 index 96e837eb..00000000 --- a/tests/src/test/java/com/github/klee0kai/stone/test/identifiers/TechFactoryTests.java +++ /dev/null @@ -1,45 +0,0 @@ -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 static org.junit.jupiter.api.Assertions.assertNotEquals; - -public class TechFactoryTests { - - @Test - public void differentCreateTest() { - //Given - TechFactoryComponent DI = Stone.createComponent(TechFactoryComponent.class); - - //When - Ram ram8Gb = DI.factory().ram(new RamSize("8GB")); - Ram ram8Gb2 = DI.factory().ram(new RamSize("8GB")); - - //Then: created components are different - assertNotEquals(ram8Gb.uuid, ram8Gb2.uuid); - } - - - @Test - public void enumDifferentTest() { - //Given - TechFactoryComponent DI = Stone.createComponent(TechFactoryComponent.class); - - //When - OperationSystem android = DI.factory().phoneOs(PhoneOsType.Android); - OperationSystem android2 = DI.factory().phoneOs(PhoneOsType.Android); - OperationSystem osNull = DI.factory().phoneOs(null); - - //Then: created components are different - assertNotEquals(android.uuid, osNull.uuid); - assertNotEquals(android.uuid, android2.uuid); - } - - -} 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.java deleted file mode 100644 index f239b749..00000000 --- a/tests/src/test/java/com/github/klee0kai/stone/test/identifiers/TechFactoryWrappersTests.java +++ /dev/null @@ -1,101 +0,0 @@ -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 javax.inject.Provider; -import java.lang.ref.Reference; - -import static org.junit.jupiter.api.Assertions.*; - -public class TechFactoryWrappersTests { - - @Test - public void lazyProvideTest() { - //Given - TechFactoryComponent DI = Stone.createComponent(TechFactoryComponent.class); - - //When - Ref battery = DI.batteryLazy(); - - //Then - assertEquals( - battery.get().uuid, - battery.get().uuid - ); - } - - @Test - public void softRefProvideTest() { - //Given - TechFactoryComponent DI = Stone.createComponent(TechFactoryComponent.class); - - //When - Reference battery = DI.batterySoft(); - - //Then - assertNotNull(battery.get()); - } - - @Test - public void weakRefProvideTest() { - //Given - TechFactoryComponent DI = Stone.createComponent(TechFactoryComponent.class); - - //When - Reference battery = DI.batteryWeak(); - - //Then - assertNotNull(battery.get()); - } - - @Test - public void phantom1ProvideTest() { - //Given - TechFactoryComponent DI = Stone.createComponent(TechFactoryComponent.class); - - //When - Ref battery = DI.batteryPhantomProvider(); - - //Then - assertNotEquals( - battery.get().uuid, - battery.get().uuid - ); - } - - @Test - public void phantom2ProvideTest() { - //Given - TechFactoryComponent DI = Stone.createComponent(TechFactoryComponent.class); - - //When - Provider battery = DI.batteryProvider(); - - //Then - assertNotEquals( - battery.get().uuid, - battery.get().uuid - ); - } - - @Test - public void phantom3ProvideTest() { - //Given - TechFactoryComponent DI = Stone.createComponent(TechFactoryComponent.class); - - //When - Ref battery = DI.batteryProviderIRef(); - - //Then - assertNotEquals( - battery.get().uuid, - battery.get().uuid - ); - } - - -} 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.java deleted file mode 100644 index 70de85fe..00000000 --- a/tests/src/test/java/com/github/klee0kai/stone/test/inject/HorseInjectTests.java +++ /dev/null @@ -1,85 +0,0 @@ -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 static org.junit.jupiter.api.Assertions.*; - - -public class HorseInjectTests { - - @Test - public void horseBornTest() { - //Given - ForestComponent DI = Stone.createComponent(ForestComponent.class); - Horse horse = new Horse(); - - - //When - DI.inject(horse, listener -> { - - }); - - //Then - assertNotNull(horse.blood); - assertNotNull(horse.knowledge); - assertNotNull(horse.conscience); - assertNotNull(horse.methodInjectedConscience); - assertNotNull(horse.methodInjectedKnowledge); - } - - - @Test - public void mowgliBornTest() { - //Given - ForestComponent DI = Stone.createComponent(ForestComponent.class); - Mowgli mowgli = new Mowgli(); - - - //When - DI.inject(mowgli); - - //Then - assertNotNull(mowgli.blood); - assertNotNull(mowgli.knowledge); - assertNotNull(mowgli.conscience); - } - - @Test - public void oneBloodTest() { - //Given - ForestComponent DI = Stone.createComponent(ForestComponent.class); - Mowgli mowgli = new Mowgli(); - Snake snake = new Snake(); - - - //When - DI.inject(mowgli); - DI.inject(snake); - - //Then - assertEquals(mowgli.blood.uuid, snake.blood.uuid); - } - - @Test - public void personalityTest() { - //Given - ForestComponent DI = Stone.createComponent(ForestComponent.class); - Mowgli mowgli = new Mowgli(); - Snake snake = new Snake(); - - - //When - DI.inject(mowgli); - DI.inject(snake); - - //Then - assertNotEquals(mowgli.conscience.uuid, snake.conscience.uuid); - } - - -} 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.java deleted file mode 100644 index 46be3676..00000000 --- a/tests/src/test/java/com/github/klee0kai/stone/test/inject/HorseProtectInjectTests.java +++ /dev/null @@ -1,62 +0,0 @@ -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 { - - - @Test - public void withoutProtectInjectTest() { - // Given - ForestComponent DI = Stone.createComponent(ForestComponent.class); - Horse horse = new Horse(); - - - //When - DI.inject(horse, listener -> { - - }); - WeakReference historyWeakReference = new WeakReference<>(horse.history); - horse = null; - System.gc(); - - //Then: without protect all not uses should be garbage collected - assertNull(historyWeakReference.get()); - - } - - @Test - public void withProtectInjectTest() throws InterruptedException { - // Given - ForestComponent DI = Stone.createComponent(ForestComponent.class); - Horse horse = new Horse(); - - //When - DI.inject(horse, listener -> { - - }); - WeakReference historyWeakReference = new 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()); - } - -} 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.java deleted file mode 100644 index ea347da3..00000000 --- a/tests/src/test/java/com/github/klee0kai/stone/test/inject/MowgliInjectMethodWrappersTests.java +++ /dev/null @@ -1,83 +0,0 @@ -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 java.util.Objects; - -import static org.junit.jupiter.api.Assertions.*; - -public class MowgliInjectMethodWrappersTests { - - @Test - public void supportWrappersTest() { - //Given - ForestComponent DI = Stone.createComponent(ForestComponent.class); - Mowgli mowgli = new Mowgli(); - - - //When - 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()); - } - - - @Test - public void refWrapperTest() { - //Given - ForestComponent DI = Stone.createComponent(ForestComponent.class); - Mowgli mowgli = new Mowgli(); - - //When - DI.inject(mowgli); - - - //Then - assertEquals( - Objects.requireNonNull(mowgli.methodKnowledgeWeakRef.get()).uuid, - Objects.requireNonNull(mowgli.methodKnowledgeWeakRef.get()).uuid - ); - assertEquals( - Objects.requireNonNull(mowgli.methodKnowledgeSoftRef.get()).uuid, - Objects.requireNonNull(mowgli.methodKnowledgeSoftRef.get()).uuid - ); - assertEquals( - Objects.requireNonNull(mowgli.methodKnowledgeLazyProvide.get()).uuid, - Objects.requireNonNull(mowgli.methodKnowledgeLazyProvide.get()).uuid - ); - } - - @Test - public void genWrapperTest() { - //Given - ForestComponent DI = Stone.createComponent(ForestComponent.class); - Mowgli mowgli = new Mowgli(); - - //When - DI.inject(mowgli); - - - //Then - assertNotEquals( - mowgli.methodKnowledgePhantomProvide.get().uuid, - mowgli.methodKnowledgePhantomProvide.get().uuid - ); - assertNotEquals( - mowgli.methodKnowledgePhantomProvide2.get().uuid, - mowgli.methodKnowledgePhantomProvide2.get().uuid - ); - assertNotEquals( - mowgli.methodKnowledgePhantomProvide3.get().uuid, - mowgli.methodKnowledgePhantomProvide3.get().uuid - ); - } -} 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.java deleted file mode 100644 index ada55cd4..00000000 --- a/tests/src/test/java/com/github/klee0kai/stone/test/inject/MowgliInjectWrappersTests.java +++ /dev/null @@ -1,83 +0,0 @@ -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 java.util.Objects; - -import static org.junit.jupiter.api.Assertions.*; - -public class MowgliInjectWrappersTests { - - @Test - public void supportWrappersTest() { - //Given - ForestComponent DI = Stone.createComponent(ForestComponent.class); - Mowgli mowgli = new 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 - public void refWrapperTest() { - //Given - ForestComponent DI = Stone.createComponent(ForestComponent.class); - Mowgli mowgli = new Mowgli(); - - //When - DI.inject(mowgli); - - - //Then - assertEquals( - Objects.requireNonNull(mowgli.knowledgeWeakRef.get()).uuid, - Objects.requireNonNull(mowgli.knowledgeWeakRef.get()).uuid - ); - assertEquals( - Objects.requireNonNull(mowgli.knowledgeSoftRef.get()).uuid, - Objects.requireNonNull(mowgli.knowledgeSoftRef.get()).uuid - ); - assertEquals( - Objects.requireNonNull(mowgli.knowledgeLazyProvide.get()).uuid, - Objects.requireNonNull(mowgli.knowledgeLazyProvide.get()).uuid - ); - } - - @Test - public void genWrapperTest() { - //Given - ForestComponent DI = Stone.createComponent(ForestComponent.class); - Mowgli mowgli = new 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 - ); - } -} 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.java deleted file mode 100644 index 7dd5b85a..00000000 --- a/tests/src/test/java/com/github/klee0kai/stone/test/inject/SchoolProtectInjectWrappersTests.java +++ /dev/null @@ -1,55 +0,0 @@ -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 java.lang.ref.WeakReference; - -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertNull; - - -public class SchoolProtectInjectWrappersTests { - - @Test - public void lazyWrapperProtectTest() { - // Given - ForestComponent DI = Stone.createComponent(ForestComponent.class); - School school = new School(); - - //When - DI.inject(school); - - WeakReference history = new WeakReference<>(school.historyLazyProvide.get()); - DI.protectInjected(school); - DI.gcAll(); - - //Then - assertNotNull(history.get()); - } - - @Test - public void ignoreProvideWrapperProtectTest() { - // Given - ForestComponent DI = Stone.createComponent(ForestComponent.class); - School school = new 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(); - - //Then - assertNull(knowledge1.get()); - assertNull(knowledge2.get()); - assertNull(knowledge3.get()); - - } -} 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.java deleted file mode 100644 index 499740e6..00000000 --- a/tests/src/test/java/com/github/klee0kai/stone/test/interfaceprovide/DeepCaveTest.java +++ /dev/null @@ -1,34 +0,0 @@ -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 { - - - @Test - public void justCaveTest() { - //When - EarthComponent di = Stone.createComponent(EarthComponent.class); - - //Then: Cave simple constructor is available - assertNotNull(di.east().cave()); - assertNotNull(di.west().cave()); - } - - @Test - public void theCaveTest() { - //When - EarthComponent di = Stone.createComponent(EarthComponent.class); - - //Then: Cave 2 params constructor is available - 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.java b/tests/src/test/java/com/github/klee0kai/stone/test/interfaceprovide/EarthWayTest.java deleted file mode 100644 index b8964593..00000000 --- a/tests/src/test/java/com/github/klee0kai/stone/test/interfaceprovide/EarthWayTest.java +++ /dev/null @@ -1,20 +0,0 @@ -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 static org.junit.jupiter.api.Assertions.assertNotNull; - -public class EarthWayTest { - - @Test - public void ChristopherColumbusTest() { - //When - EarthComponent di = Stone.createComponent(EarthComponent.class); - - //Then - assertNotNull(di.west().mountainImp()); - assertNotNull(di.west().riverImpl()); - } -} 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.java deleted file mode 100644 index e7dc3309..00000000 --- a/tests/src/test/java/com/github/klee0kai/stone/test/lifecycle/GoodPhoneRepairTests.java +++ /dev/null @@ -1,132 +0,0 @@ -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.*; - - -/** - * Test lifecycle owner over LifecycleUtils - */ -public class GoodPhoneRepairTests { - - @Test - public void goodPhoneInjectTest() { - //Given - PhoneComponent DI = Stone.createComponent(PhoneComponent.class); - - //When buy - GoodPhone goodPhone = new GoodPhone(); - DI.inject(goodPhone, goodPhone.lifeCycleOwner, new DataStorageSize("64G"), new RamSize("4G")); - - //Then - assertNotNull(goodPhone.battery); - assertNotNull(goodPhone.dataStorage); - assertNotNull(goodPhone.ram); - } - - @Test - public void 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); - - //When broke and repair - goodPhone.broke(); - System.gc(); - DI.inject(goodPhone, new DataStorageSize("64G"), new RamSize("4G")); - - //Then: Need new details for repair phone. Old components collected by GC - assertNull(batteryRef.get()); - assertNull(dataStorageRef.get()); - assertNull(ramRef.get()); - } - - @Test - public void goodPhoneDropWatterTest() throws InterruptedException { - //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); - - //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 - public void goodPhoneDrownedRepairTest() throws InterruptedException { - //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; - - //When - goodPhone.dropToWater(); - Thread.sleep(10); - System.gc(); - DI.inject(goodPhone, goodPhone.lifeCycleOwner, new DataStorageSize("64G"), new RamSize("4G")); - - //Then: Can be repair after little time - assertEquals(ramUuid, goodPhone.dataStorage.uuid); - } - - - @Test - public void goodPhoneDeepDrownedRepairTest() throws InterruptedException { - //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; - - //When - goodPhone.dropToWater(); - Thread.sleep(120); - System.gc(); - DI.inject(goodPhone, goodPhone.lifeCycleOwner, new DataStorageSize("64G"), new RamSize("4G")); - - //Then: Can not be repair without new details - assertNotEquals(ramUuid, goodPhone.dataStorage.uuid); - } - -} 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.java deleted file mode 100644 index 259c57b8..00000000 --- a/tests/src/test/java/com/github/klee0kai/stone/test/lifecycle/OnePhoneRepairTests.java +++ /dev/null @@ -1,131 +0,0 @@ -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.*; - - -/** - * Test lifecycle owner implemented in providing model - */ -public class OnePhoneRepairTests { - - - @Test - public void onePhoneInjectTest() { - //Given - PhoneComponent DI = Stone.createComponent(PhoneComponent.class); - - //When - OnePhone onePhone = new OnePhone(); - DI.inject(onePhone); - - //Then - assertNotNull(onePhone.battery); - assertNotNull(onePhone.dataStorage); - assertNotNull(onePhone.ram); - } - - @Test - public void 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); - - //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 - public void onePhoneDropWatterTest() throws InterruptedException { - //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); - - //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 - public void onePhoneDrownedRepairTest() throws InterruptedException { - //Given - PhoneComponent DI = Stone.createComponent(PhoneComponent.class); - OnePhone onePhone = new OnePhone(); - DI.inject(onePhone); - UUID 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 - public void onePhoneDeepDrownedRepairTest() throws InterruptedException { - //Given - PhoneComponent DI = Stone.createComponent(PhoneComponent.class); - OnePhone onePhone = new OnePhone(); - DI.inject(onePhone); - UUID 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); - } - -} 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.java deleted file mode 100644 index 33c78f3c..00000000 --- a/tests/src/test/java/com/github/klee0kai/stone/test/moduleinit/BeginOfBegins2Tests.java +++ /dev/null @@ -1,112 +0,0 @@ -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 static org.junit.jupiter.api.Assertions.assertEquals; - -public class BeginOfBegins2Tests { - - private static final Earth earth = new Earth(); - private static final Ideology ideology = new Ideology(); - - @Test - public void initByFactory() { - //Given - UnitedModule module = new UnitedModule() { - @Override - public Earth earth() { - return earth; - } - - @Override - public History history() { - return null; - } - }; - ForestComponent DI = Stone.createComponent(ForestComponent.class); - - //When - DI.initUnitedModule(module); - - //Then - assertEquals(earth, DI.united().earth()); - } - - - @Test - public void initByFactoryClass() { - //Given - ForestComponent DI = Stone.createComponent(ForestComponent.class); - - //When - DI.initUnitedModule(UnitedModuleFactory.class); - - //Then - assertEquals(earth, DI.united().earth()); - } - - - @Test - public void 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); - - //When - DI.iniAllModules(module, identityModule); - - //Then - assertEquals(earth, DI.united().earth()); - assertEquals(ideology, DI.identity().ideology()); - } - - public static class UnitedModuleFactory extends UnitedModule { - - @Override - public Earth earth() { - return earth; - } - - @Override - public History history() { - return null; - } - } - -} 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.java deleted file mode 100644 index b3169b32..00000000 --- a/tests/src/test/java/com/github/klee0kai/stone/test/moduleinit/BeginOfBeginsTests.java +++ /dev/null @@ -1,67 +0,0 @@ -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 static org.junit.jupiter.api.Assertions.assertEquals; - -public class BeginOfBeginsTests { - - private static final Earth earth = new Earth(); - - @Test - public void initByFactory() { - //Given - UnitedModule module = new UnitedModule() { - - - @Override - public Earth earth() { - return earth; - } - - @Override - public History history() { - return null; - } - }; - ForestComponent DI = Stone.createComponent(ForestComponent.class); - - //When - DI.initUnitedModule(module); - - //Then - assertEquals(earth, DI.united().earth()); - } - - - @Test - public void initByFactoryClass() { - //Given - ForestComponent DI = Stone.createComponent(ForestComponent.class); - - //When - DI.initUnitedModule(UnitedModuleFactory.class); - - //Then - assertEquals(earth, DI.united().earth()); - } - - public static class UnitedModuleFactory extends UnitedModule { - - @Override - public Earth earth() { - return earth; - } - - @Override - public History history() { - return null; - } - } - -} 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.java deleted file mode 100644 index 9196176d..00000000 --- a/tests/src/test/java/com/github/klee0kai/stone/test/parameterized/WireTest.java +++ /dev/null @@ -1,38 +0,0 @@ -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 static org.junit.jupiter.api.Assertions.*; - -public class WireTest { - - @Test - public void usbUsbProvideTest() { - //When - WireComponent di = Stone.createComponent(WireComponent.class); - - //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); - } - - @Test - public void miniUsbBindTest() { - //When - WireComponent di = Stone.createComponent(WireComponent.class); - Wire wire = new Wire<>(); - di.miniusb_miniusb(wire); - - - //Then - 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 deleted file mode 100644 index 2d97c2de..00000000 --- a/tests/src/test/java/com/github/klee0kai/stone/test/types/ListUtilTests.java +++ /dev/null @@ -1,45 +0,0 @@ -package com.github.klee0kai.stone.test.types; - -import com.github.klee0kai.stone._hidden_.types.ListUtils; -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 - 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())); - } - - - @Test - 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())); - } -} 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_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..90afe6de --- /dev/null +++ b/tests_compile/build.gradle.kts @@ -0,0 +1,22 @@ +plugins { + alias(libs.plugins.kotlin.jvm) + +} + +tasks.test { + useJUnitPlatform() +} + + +dependencies { + implementation(project(":stone_multiplatform")) + implementation(project(":stone_ksp")) + + testImplementation(libs.bundles.junit) + 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/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..ad39040f --- /dev/null +++ b/tests_ext/build.gradle.kts @@ -0,0 +1,19 @@ +plugins { + alias(libs.plugins.kotlin.jvm) + alias(libs.plugins.kotlin.ksp) +} + +tasks.test { + useJUnitPlatform() +} + +dependencies { + implementation(project(":stone_multiplatform")) + ksp(project(":stone_ksp")) + + implementation(project(":tests")) + + testImplementation(libs.bundles.junit) +} + + 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.java deleted file mode 100644 index 7e291215..00000000 --- a/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/di/base_phone/PhoneExtComponent.java +++ /dev/null @@ -1,25 +0,0 @@ -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; - -@Component -public interface PhoneExtComponent extends PhoneComponent { - - TechExtModule components(); - - @ExtendOf - void extOf(PhoneComponent parent); - - void injectExt(OnePhone onePhone); - - void injectExt(GoodPhone goodPhone, DataStorageSize dataStorageSize, RamSize ramSize); - - void injectExt(GoodPhone goodPhone, StoneLifeCycleOwner lifeCycleOwner, DataStorageSize dataStorageSize, RamSize ramSize); -} 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 new file mode 100644 index 00000000..a4e746c7 --- /dev/null +++ b/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/di/base_phone/PhoneExtComponent.kt @@ -0,0 +1,30 @@ +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 + +@Component +interface PhoneExtComponent : PhoneComponent { + + override fun components(): TechExtModule? + + @ExtendOf + fun extOf(parent: PhoneComponent?) + + fun injectExt(onePhone: OnePhone?) + + fun injectExt(goodPhone: GoodPhone?, 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.java b/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/di/base_phone/TechExtModule.java deleted file mode 100644 index d4383f4f..00000000 --- a/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/di/base_phone/TechExtModule.java +++ /dev/null @@ -1,22 +0,0 @@ -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 { - - @Override - @Provide(cache = Provide.CacheType.Weak) - DDR3Ram ram(); - - @Override - @Provide(cache = Provide.CacheType.Weak) - DDR3Ram ram(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 new file mode 100644 index 00000000..df5ee1b3 --- /dev/null +++ b/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/di/base_phone/TechExtModule.kt @@ -0,0 +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 + +@Module +interface TechExtModule : TechModule { + + @Provide(cache = Provide.CacheType.Weak) + override fun ram(): DDR3Ram + + @Provide(cache = Provide.CacheType.Weak) + override fun ram(ramSize: RamSize?): DDR3Ram + +} 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.java deleted file mode 100644 index 9cc055eb..00000000 --- a/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/di/bindinstance/simple/GodRebrandingComponent.java +++ /dev/null @@ -1,16 +0,0 @@ -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; - -@Component -public interface GodRebrandingComponent extends GodWorkspaceComponent { - - @Override - SunSystemRebrandingModule sunSystem(); - - @ExtendOf - void extendComponent(GodWorkspaceComponent parent); - -} 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 new file mode 100644 index 00000000..37ba8fc0 --- /dev/null +++ b/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/di/bindinstance/simple/GodRebrandingComponent.kt @@ -0,0 +1,15 @@ +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 + +@Component +interface GodRebrandingComponent : GodWorkspaceComponent { + + override fun sunSystem(): SunSystemRebrandingModule + + @ExtendOf + fun extendComponent(parent: GodWorkspaceComponent) + +} 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.java deleted file mode 100644 index 006b17ce..00000000 --- a/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/di/bindinstance/simple/SunSystemRebrandingModule.java +++ /dev/null @@ -1,14 +0,0 @@ -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; - -@Module -public interface SunSystemRebrandingModule extends SunSystemModule { - - @BindInstance - Pluton pluton(); - -} 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 new file mode 100644 index 00000000..43cb33c9 --- /dev/null +++ b/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/di/bindinstance/simple/SunSystemRebrandingModule.kt @@ -0,0 +1,14 @@ +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 + +@Module +interface SunSystemRebrandingModule : SunSystemModule { + + @BindInstance + fun pluton(): Pluton? + +} 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.java deleted file mode 100644 index b7e721b4..00000000 --- a/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/di/bindinstance/singlemethod/ExtPlanetComponent.java +++ /dev/null @@ -1,13 +0,0 @@ -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; - -@Component -public interface ExtPlanetComponent extends PlanetComponent { - - @ExtendOf - void extendOf(PlanetComponent parent); - -} 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 new file mode 100644 index 00000000..1b5cb891 --- /dev/null +++ b/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/di/bindinstance/singlemethod/ExtPlanetComponent.kt @@ -0,0 +1,13 @@ +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 + +@Component +interface ExtPlanetComponent : PlanetComponent { + + @ExtendOf + fun extendOf(parent: PlanetComponent?) + +} 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.java deleted file mode 100644 index cb1121d4..00000000 --- a/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/di/bindinstance/singlemethod/PlanetSputnikComponent.java +++ /dev/null @@ -1,21 +0,0 @@ -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; - -@Component -public interface PlanetSputnikComponent extends PlanetComponent { - - @Override - StarModule sunModule(); - - @BindInstance(cache = BindInstance.CacheType.Weak) - Moon moon(Moon moon); - - @ExtendOf - void extendOf(PlanetComponent parent); - -} 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 new file mode 100644 index 00000000..4a0c6bbe --- /dev/null +++ b/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/di/bindinstance/singlemethod/PlanetSputnikComponent.kt @@ -0,0 +1,20 @@ +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 + +@Component +interface PlanetSputnikComponent : PlanetComponent { + + override fun sunModule(): StarModule + + @BindInstance(cache = BindInstance.CacheType.Weak) + fun moon(moon: Moon?): Moon? + + @ExtendOf + fun extendOf(parent: PlanetComponent?) + +} 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.java deleted file mode 100644 index 184c857e..00000000 --- a/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/di/bindinstance/singlemethod/StarModule.java +++ /dev/null @@ -1,31 +0,0 @@ -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; - -@Module -public interface StarModule extends SunModule { - - @GcSiriusScope - @BindInstance(cache = BindInstance.CacheType.Strong) - Sirius siriusStrong(Sirius sirius); - - @GcSiriusScope - @BindInstance(cache = BindInstance.CacheType.Soft) - Sirius siriusSoft(Sirius sirius); - - - @GcSiriusScope - @BindInstance - Sirius sirius(Sirius sirius); - - - @GcSiriusScope - @BindInstance(cache = BindInstance.CacheType.Weak) - Sirius siriusWeak(Sirius star); - - -} 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 new file mode 100644 index 00000000..b47db8b7 --- /dev/null +++ b/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/di/bindinstance/singlemethod/StarModule.kt @@ -0,0 +1,28 @@ +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 + +@Module +interface StarModule : SunModule { + + @GcSiriusScope + @BindInstance(cache = BindInstance.CacheType.Strong) + fun siriusStrong(sirius: Sirius?): Sirius? + + @GcSiriusScope + @BindInstance(cache = BindInstance.CacheType.Soft) + fun siriusSoft(sirius: Sirius?): Sirius? + + @GcSiriusScope + @BindInstance + fun sirius(sirius: Sirius?): Sirius? + + @GcSiriusScope + @BindInstance(cache = BindInstance.CacheType.Weak) + fun siriusWeak(star: Sirius?): Sirius? + +} 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.java deleted file mode 100644 index 3533f474..00000000 --- a/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/di/bindinstance/singlemethod_gc/ExtPlanetRollingComponent.java +++ /dev/null @@ -1,75 +0,0 @@ -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 { - - @Override - StarModule sunModule(); - - @ExtendOf - void extOf(PlanetRollingComponent ext); - - @GcSputnikScope - @BindInstance(cache = BindInstance.CacheType.Strong) - Moon moonStrong(Moon moon); - - @GcSputnikScope - @BindInstance(cache = BindInstance.CacheType.Soft) - Moon moonSoft(Moon moon); - - @GcSputnikScope - @BindInstance(cache = BindInstance.CacheType.Weak) - Moon moonWeak(Moon moon); - - - @RunGc - @GcAllScope - void gcAllExt(); - - @RunGc - @GcStrongScope - void gcStrongExt(); - - @RunGc - @GcSoftScope - void gcSoftExt(); - - @RunGc - @GcWeakScope - void gcWeakExt(); - - - @RunGc - @GcSoftScope - @GcSunScope - void gcSoftSunExt(); - - @RunGc - @GcSoftScope - @GcPlanetScope - void gcSoftPlanetsExt(); - - - @RunGc - @GcSoftScope - @GcSputnikScope - void gcSoftSputniksExt(); - - - @RunGc - @GcSoftScope - @GcSiriusScope - void gcSoftSiriusExt(); - - -} 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 new file mode 100644 index 00000000..f350a3d9 --- /dev/null +++ b/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/di/bindinstance/singlemethod_gc/ExtPlanetRollingComponent.kt @@ -0,0 +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 + +@Component +interface ExtPlanetRollingComponent : PlanetRollingComponent { + + override fun sunModule(): StarModule? + + @ExtendOf + fun extOf(ext: PlanetRollingComponent?) + + @GcSputnikScope + @BindInstance(cache = BindInstance.CacheType.Strong) + fun moonStrong(moon: Moon?): Moon? + + @GcSputnikScope + @BindInstance(cache = BindInstance.CacheType.Soft) + fun moonSoft(moon: Moon?): Moon? + + @GcSputnikScope + @BindInstance(cache = BindInstance.CacheType.Weak) + fun moonWeak(moon: Moon?): Moon? + + + @RunGc + @GcAllScope + fun gcAllExt() + + @RunGc + @GcStrongScope + fun gcStrongExt() + + @RunGc + @GcSoftScope + fun gcSoftExt() + + @RunGc + @GcWeakScope + fun gcWeakExt() + + @RunGc + @GcSoftScope + @GcSunScope + fun gcSoftSunExt() + + @RunGc + @GcSoftScope + @GcPlanetScope + fun gcSoftPlanetsExt() + + @RunGc + @GcSoftScope + @GcSputnikScope + fun gcSoftSputniksExt() + + @RunGc + @GcSoftScope + @GcSiriusScope + fun gcSoftSiriusExt() +} 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.java deleted file mode 100644 index ea5c7dfa..00000000 --- a/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/di/forest/DiseasesModule.java +++ /dev/null @@ -1,13 +0,0 @@ -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; - -@Module -abstract public class DiseasesModule { - - @Provide - abstract public Osteoarthritis osteoarthritis(); - -} 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 new file mode 100644 index 00000000..493464e4 --- /dev/null +++ b/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/di/forest/DiseasesModule.kt @@ -0,0 +1,13 @@ +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 + +@Module +abstract class DiseasesModule { + + @Provide + abstract fun osteoarthritis(): Osteoarthritis + +} 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.java deleted file mode 100644 index 176b65ee..00000000 --- a/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/di/forest/OldForestComponent.java +++ /dev/null @@ -1,24 +0,0 @@ -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; - -@Component -public interface OldForestComponent extends ForestComponent { - - @Override - OldIdentityModule identity(); - - @ExtendOf - void extOf(ForestComponent parent); - - DiseasesModule diseases(); - - void inject(OldHorse horse, StoneLifeCycleOwner stoneLifeCycleOwner); - - void inject(OldHorse horse); - -} 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 new file mode 100644 index 00000000..a026837e --- /dev/null +++ b/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/di/forest/OldForestComponent.kt @@ -0,0 +1,23 @@ +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 + +@Component +interface OldForestComponent : ForestComponent { + + override fun identity(): OldIdentityModule + + @ExtendOf + fun extOf(parent: ForestComponent) + + fun diseases(): DiseasesModule? + + fun inject(horse: OldHorse?, stoneLifeCycleOwner: StoneLifeCycleOwner?) + + fun inject(horse: OldHorse?) + +} 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.java deleted file mode 100644 index 8d47ebc7..00000000 --- a/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/di/forest/OldIdentityModule.java +++ /dev/null @@ -1,21 +0,0 @@ -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; - - -@Module -public interface OldIdentityModule extends IdentityModule { - - @Override - @Provide(cache = Provide.CacheType.Factory) - OldKnowledge knowledge(); - - @Override - @Provide(cache = Provide.CacheType.Soft) - FamilyIdeology ideology(); -} 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 new file mode 100644 index 00000000..8a7db278 --- /dev/null +++ b/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/di/forest/OldIdentityModule.kt @@ -0,0 +1,19 @@ +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 + + +@Module +interface OldIdentityModule : IdentityModule { + + @Provide(cache = Provide.CacheType.Factory) + override fun knowledge(): OldKnowledge + + @Provide(cache = Provide.CacheType.Soft) + override fun ideology(): FamilyIdeology + +} 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.java deleted file mode 100644 index 0ac282a9..00000000 --- a/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/di/gcforest/GcEarthExtModule.java +++ /dev/null @@ -1,50 +0,0 @@ -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; - -@Module -public abstract class GcEarthExtModule extends GcEarthModule { - - @Provide(cache = Provide.CacheType.Strong) - abstract public Desert desertStrong(); - - @Provide(cache = Provide.CacheType.Soft) - abstract public Desert desertSoft(); - - @Provide(cache = Provide.CacheType.Weak) - abstract public Desert desertWeak(); - - @Provide(cache = Provide.CacheType.Factory) - public Desert desertFactory() { - return new Desert(); - } - - - @GcRiverScope - @Provide(cache = Provide.CacheType.Strong) - abstract public WaterFlow riverStrong(); - - @GcRiverScope - @Provide(cache = Provide.CacheType.Soft) - abstract public WaterFlow riverSoft(); - - @GcRiverScope - @Provide(cache = Provide.CacheType.Weak) - abstract public WaterFlow riverWeak(); - - @GcRiverScope - @Provide(cache = Provide.CacheType.Factory) - abstract public WaterFlow riverFactory(); - - @GcRiverScope - @Provide - public WaterFlow riverDefaultSoft() { - return new WaterFlow(); - } - -} 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 new file mode 100644 index 00000000..2d889156 --- /dev/null +++ b/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/di/gcforest/GcEarthExtModule.kt @@ -0,0 +1,49 @@ +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 + +@Module +abstract class GcEarthExtModule : GcEarthModule() { + + @Provide(cache = Provide.CacheType.Strong) + abstract fun desertStrong(): Desert? + + @Provide(cache = Provide.CacheType.Soft) + abstract fun desertSoft(): Desert? + + @Provide(cache = Provide.CacheType.Weak) + abstract fun desertWeak(): Desert? + + @Provide(cache = Provide.CacheType.Factory) + open fun desertFactory(): Desert { + return Desert() + } + + @GcRiverScope + @Provide(cache = Provide.CacheType.Strong) + public abstract override fun riverStrong(): WaterFlow? + + @GcRiverScope + @Provide(cache = Provide.CacheType.Soft) + public abstract override fun riverSoft(): WaterFlow? + + @GcRiverScope + @Provide(cache = Provide.CacheType.Weak) + public abstract override fun riverWeak(): WaterFlow? + + @GcRiverScope + @Provide(cache = Provide.CacheType.Factory) + public abstract override fun riverFactory(): WaterFlow? + + @GcRiverScope + @Provide + public override fun riverDefaultSoft(): WaterFlow? { + return WaterFlow() + } + +} 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.java deleted file mode 100644 index 13420cb1..00000000 --- a/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/di/gcforest/GcGodExtComponent.java +++ /dev/null @@ -1,46 +0,0 @@ -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; - -@Component -public abstract class GcGodExtComponent extends GcGodComponent implements IGcEarthExtComponent { - - - @ExtendOf - public abstract void extOf(GcGodComponent parent); - - @Override - public abstract GcSunSystemExtModule sunSystem(); - - @Override - public abstract GcEarthExtModule earth(); - - @RunGc - @GcAllScope - public abstract void gcAllExt(); - - @RunGc - @GcStrongScope - public abstract void gcStrongExt(); - - @RunGc - @GcSoftScope - public abstract void gcSoftExt(); - - @RunGc - @GcWeakScope - public abstract void gcWeakExt(); - - - @RunGc - @GcSunScope - public abstract void gcSunExt(); - - @RunGc - @GcPlanetScope - public abstract void gcPlanetsExt(); - -} 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 new file mode 100644 index 00000000..50d8da79 --- /dev/null +++ b/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/di/gcforest/GcGodExtComponent.kt @@ -0,0 +1,43 @@ +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 + +@Component +abstract class GcGodExtComponent : GcGodComponent(), IGcEarthExtComponent { + + @ExtendOf + abstract fun extOf(parent: GcGodComponent?) + + public abstract override fun sunSystem(): GcSunSystemExtModule? + + public abstract override fun earth(): GcEarthExtModule? + + @RunGc + @GcAllScope + abstract fun gcAllExt() + + @RunGc + @GcStrongScope + abstract fun gcStrongExt() + + @RunGc + @GcSoftScope + abstract fun gcSoftExt() + + @RunGc + @GcWeakScope + abstract fun gcWeakExt() + + + @RunGc + @GcSunScope + abstract fun gcSunExt() + + @RunGc + @GcPlanetScope + abstract fun gcPlanetsExt() + +} 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.java deleted file mode 100644 index bc1a8bb8..00000000 --- a/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/di/gcforest/GcSunSystemExtModule.java +++ /dev/null @@ -1,11 +0,0 @@ -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; - -@Module -public interface GcSunSystemExtModule extends GcSunSystemModule { - - - -} 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 new file mode 100644 index 00000000..03f507c3 --- /dev/null +++ b/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/di/gcforest/GcSunSystemExtModule.kt @@ -0,0 +1,7 @@ +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 + +@Module +interface GcSunSystemExtModule : GcSunSystemModule 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.java deleted file mode 100644 index 853279af..00000000 --- a/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/di/gcforest/IGcEarthExtComponent.java +++ /dev/null @@ -1,30 +0,0 @@ -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 { - - - @RunGc - @GcMountainScope - void gcMountainsExt(); - - @RunGc - @GcSoftScope - @GcMountainScope - void gcSoftMountainsExt(); - - @RunGc - @GcStrongScope - @GcMountainScope - void gcStrongMountainsExt(); - - @RunGc - @GcRiverScope - void gcRiversExt(); - -} 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 new file mode 100644 index 00000000..946076a2 --- /dev/null +++ b/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/di/gcforest/IGcEarthExtComponent.kt @@ -0,0 +1,29 @@ +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 + +interface IGcEarthExtComponent { + + @RunGc + @GcMountainScope + fun gcMountainsExt() + + @RunGc + @GcSoftScope + @GcMountainScope + fun gcSoftMountainsExt() + + @RunGc + @GcStrongScope + @GcMountainScope + fun gcStrongMountainsExt() + + @RunGc + @GcRiverScope + fun gcRiversExt() + +} 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.java deleted file mode 100644 index 72bcd01f..00000000 --- a/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/di/gcscopes/GcSiriusScope.java +++ /dev/null @@ -1,14 +0,0 @@ -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; - -@Scope -@Retention(RUNTIME) -@Target(METHOD) -public @interface GcSiriusScope { -} 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 new file mode 100644 index 00000000..f9b4267b --- /dev/null +++ b/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/di/gcscopes/GcSiriusScope.kt @@ -0,0 +1,8 @@ +package com.github.klee0kai.test_ext.inject.di.gcscopes + +import javax.inject.Scope + +@Scope +@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.java b/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/di/gcscopes/GcSputnikScope.java deleted file mode 100644 index dbb68076..00000000 --- a/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/di/gcscopes/GcSputnikScope.java +++ /dev/null @@ -1,14 +0,0 @@ -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; - -@Scope -@Retention(RUNTIME) -@Target(METHOD) -public @interface GcSputnikScope { -} 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 new file mode 100644 index 00000000..1e87616f --- /dev/null +++ b/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/di/gcscopes/GcSputnikScope.kt @@ -0,0 +1,8 @@ +package com.github.klee0kai.test_ext.inject.di.gcscopes + +import javax.inject.Scope + +@Scope +@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.java b/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/di/swcache/SwitchCacheExtComponent.java deleted file mode 100644 index 0b904987..00000000 --- a/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/di/swcache/SwitchCacheExtComponent.java +++ /dev/null @@ -1,24 +0,0 @@ -package com.github.klee0kai.test_ext.inject.di.swcache; - -import com.github.klee0kai.stone.annotations.component.*; -import com.github.klee0kai.test.di.swcache.SwitchCacheComponent; - -@Component -public interface SwitchCacheExtComponent extends SwitchCacheComponent { - - @ExtendOf - void extOf(SwitchCacheComponent parent); - - @GcAllScope - @SwitchCache(cache = SwitchCache.CacheType.Weak) - void allWeakExt(); - - @GcAllScope - @SwitchCache(cache = SwitchCache.CacheType.Strong, timeMillis = 100) - void allStrongFewMillisExt(); - - @GcStrongScope - @SwitchCache(cache = SwitchCache.CacheType.Weak) - void strongToWeakExt(); - -} 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 new file mode 100644 index 00000000..0809d3f0 --- /dev/null +++ b/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/di/swcache/SwitchCacheExtComponent.kt @@ -0,0 +1,24 @@ +package com.github.klee0kai.test_ext.inject.di.swcache + +import com.github.klee0kai.stone.annotations.component.* +import com.github.klee0kai.test.di.swcache.SwitchCacheComponent + +@Component +interface SwitchCacheExtComponent : SwitchCacheComponent { + + @ExtendOf + fun extOf(parent: SwitchCacheComponent?) + + @GcAllScope + @SwitchCache(cache = SwitchCache.CacheType.Weak) + fun allWeakExt() + + @GcAllScope + @SwitchCache(cache = SwitchCache.CacheType.Strong, timeMillis = 100) + fun allStrongFewMillisExt() + + @GcStrongScope + @SwitchCache(cache = SwitchCache.CacheType.Weak) + fun strongToWeakExt() + +} 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.java deleted file mode 100644 index 104d9c23..00000000 --- a/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/di/techfactory/ITechProviderExtComponent.java +++ /dev/null @@ -1,28 +0,0 @@ -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 javax.inject.Named; - -public interface ITechProviderExtComponent { - - Ram ramExt(); - - Ram ramExt(RamSize ramSize); - - Ram ramExt(RamSize ramSize, Frequency frequency); - - - @Named() - DDR3Ram ramDDr3Ext(); - - @Named("size") - DDR3Ram ramDdr3Ext(RamSize ramSize); - - @Named("size-frequency") - DDR3Ram ramDDr3Ext(RamSize ramSize, Frequency frequency); - -} 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 new file mode 100644 index 00000000..ce22ea4e --- /dev/null +++ b/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/di/techfactory/ITechProviderExtComponent.kt @@ -0,0 +1,27 @@ +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 javax.inject.Named + +interface ITechProviderExtComponent { + + fun ramExt(): Ram? + + fun ramExt(ramSize: RamSize?): Ram? + + fun ramExt(ramSize: RamSize?, frequency: Frequency?): Ram + + + @Named + fun ramDDr3Ext(): DDR3Ram? + + @Named("size") + fun ramDdr3Ext(ramSize: RamSize?): DDR3Ram + + @Named("size-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.java b/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/di/techfactory/TechFactoryExtComponent.java deleted file mode 100644 index 4936cd59..00000000 --- a/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/di/techfactory/TechFactoryExtComponent.java +++ /dev/null @@ -1,20 +0,0 @@ -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; - -@Component( - identifiers = {Frequency.class} -) -public interface TechFactoryExtComponent extends TechFactoryComponent, ITechProviderExtComponent { - - @Override - TechFactoryExtModule factory(); - - @ExtendOf - void extOf(TechFactoryComponent parent); - -} 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 new file mode 100644 index 00000000..e418fb4b --- /dev/null +++ b/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/di/techfactory/TechFactoryExtComponent.kt @@ -0,0 +1,21 @@ +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 + + +@Component( + identifiers = [ + Frequency::class + ], +) +interface TechFactoryExtComponent : TechFactoryComponent, ITechProviderExtComponent { + + override fun factory(): TechFactoryExtModule? + + @ExtendOf + fun extOf(parent: TechFactoryComponent?) + +} 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.java deleted file mode 100644 index 2973a165..00000000 --- a/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/di/techfactory/TechFactoryExtModule.java +++ /dev/null @@ -1,29 +0,0 @@ -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; - -@Module -public interface TechFactoryExtModule extends TechFactoryModule { - - @Override - @Named() - @Provide(cache = Provide.CacheType.Factory) - DDR3Ram ram(); - - @Override - @Named("size") - @Provide(cache = Provide.CacheType.Factory) - DDR3Ram ram(RamSize ramSize); - - @Named("size-frequency") - @Provide(cache = Provide.CacheType.Factory) - DDR3Ram ram(RamSize ramSize, Frequency frequency); - -} 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 new file mode 100644 index 00000000..a22a7640 --- /dev/null +++ b/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/di/techfactory/TechFactoryExtModule.kt @@ -0,0 +1,26 @@ +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 + +@Module +interface TechFactoryExtModule : TechFactoryModule { + + @Named + @Provide(cache = Provide.CacheType.Factory) + override fun ram(): DDR3Ram? + + @Named("size") + @Provide(cache = Provide.CacheType.Factory) + override fun ram(ramSize: RamSize?): DDR3Ram? + + @Named("size-frequency") + @Provide(cache = Provide.CacheType.Factory) + 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.java b/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/di/techfactory/identifiers/Frequency.java deleted file mode 100644 index 31263510..00000000 --- a/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/di/techfactory/identifiers/Frequency.java +++ /dev/null @@ -1,26 +0,0 @@ -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); - } -} 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 new file mode 100644 index 00000000..71ad9b51 --- /dev/null +++ b/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/di/techfactory/identifiers/Frequency.kt @@ -0,0 +1,5 @@ +package com.github.klee0kai.test_ext.inject.di.techfactory.identifiers + +data class Frequency( + var frequency: String?, +) 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.java deleted file mode 100644 index 6238aed2..00000000 --- a/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/mowgli/animal/OldHorse.java +++ /dev/null @@ -1,21 +0,0 @@ -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 javax.inject.Inject; - -public class OldHorse extends Horse { - - @Inject - public OldKnowledge oldKnowledge; - - @Inject - public Osteoarthritis osteoarthritis; - - @Inject - public Ideology ideology; - -} 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 new file mode 100644 index 00000000..0a737083 --- /dev/null +++ b/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/mowgli/animal/OldHorse.kt @@ -0,0 +1,20 @@ +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 javax.inject.Inject + +class OldHorse : Horse() { + + @Inject + lateinit var oldKnowledge: OldKnowledge + + @Inject + lateinit var osteoarthritis: Osteoarthritis + + @Inject + override var ideology: Ideology? = null + +} 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.java deleted file mode 100644 index 24b86fc0..00000000 --- a/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/mowgli/diseases/Osteoarthritis.java +++ /dev/null @@ -1,11 +0,0 @@ -package com.github.klee0kai.test_ext.inject.mowgli.diseases; - - -import java.util.UUID; - -public class Osteoarthritis { - - public UUID uuid = UUID.randomUUID(); - - -} 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 new file mode 100644 index 00000000..a9f8574c --- /dev/null +++ b/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/mowgli/diseases/Osteoarthritis.kt @@ -0,0 +1,8 @@ +package com.github.klee0kai.test_ext.inject.mowgli.diseases + +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.java b/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/mowgli/earth/Bay.java deleted file mode 100644 index 8ca0b11d..00000000 --- a/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/mowgli/earth/Bay.java +++ /dev/null @@ -1,9 +0,0 @@ -package com.github.klee0kai.test_ext.inject.mowgli.earth; - -import java.util.UUID; - -public class Bay { - - public 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 new file mode 100644 index 00000000..e651e849 --- /dev/null +++ b/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/mowgli/earth/Bay.kt @@ -0,0 +1,7 @@ +package com.github.klee0kai.test_ext.inject.mowgli.earth + +import java.util.* + +class Bay { + var uuid: UUID = UUID.randomUUID() +} 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.java deleted file mode 100644 index 076b42b7..00000000 --- a/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/mowgli/earth/Desert.java +++ /dev/null @@ -1,9 +0,0 @@ -package com.github.klee0kai.test_ext.inject.mowgli.earth; - -import java.util.UUID; - -public class Desert { - - public 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 new file mode 100644 index 00000000..f7c14511 --- /dev/null +++ b/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/mowgli/earth/Desert.kt @@ -0,0 +1,7 @@ +package com.github.klee0kai.test_ext.inject.mowgli.earth + +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.java b/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/mowgli/earth/WaterFlow.java deleted file mode 100644 index 81c2a69d..00000000 --- a/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/mowgli/earth/WaterFlow.java +++ /dev/null @@ -1,12 +0,0 @@ -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(); - - -} 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 new file mode 100644 index 00000000..1edc5a30 --- /dev/null +++ b/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/mowgli/earth/WaterFlow.kt @@ -0,0 +1,11 @@ +@file:OptIn(ExperimentalUuidApi::class) + +package com.github.klee0kai.test_ext.inject.mowgli.earth + +import com.github.klee0kai.test.mowgli.earth.River +import kotlin.uuid.ExperimentalUuidApi +import kotlin.uuid.Uuid + +class WaterFlow : River() { + override var uuid: String = Uuid.random().toString() +} 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.java deleted file mode 100644 index a90eb939..00000000 --- a/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/mowgli/galaxy/Pluton.java +++ /dev/null @@ -1,12 +0,0 @@ -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(); - - -} 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 new file mode 100644 index 00000000..2fdfe802 --- /dev/null +++ b/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/mowgli/galaxy/Pluton.kt @@ -0,0 +1,8 @@ +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.java b/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/mowgli/galaxy/sputniks/Calypso.java deleted file mode 100644 index 4814c248..00000000 --- a/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/mowgli/galaxy/sputniks/Calypso.java +++ /dev/null @@ -1,9 +0,0 @@ -package com.github.klee0kai.test_ext.inject.mowgli.galaxy.sputniks; - -import java.util.UUID; - -public class Calypso { - - public 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 new file mode 100644 index 00000000..c27a4f4c --- /dev/null +++ b/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/mowgli/galaxy/sputniks/Calypso.kt @@ -0,0 +1,7 @@ +package com.github.klee0kai.test_ext.inject.mowgli.galaxy.sputniks + +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.java b/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/mowgli/galaxy/sputniks/Moon.java deleted file mode 100644 index e72f5242..00000000 --- a/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/mowgli/galaxy/sputniks/Moon.java +++ /dev/null @@ -1,10 +0,0 @@ -package com.github.klee0kai.test_ext.inject.mowgli.galaxy.sputniks; - -import java.util.UUID; - -public class Moon { - - public 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 new file mode 100644 index 00000000..9dc99fb2 --- /dev/null +++ b/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/mowgli/galaxy/sputniks/Moon.kt @@ -0,0 +1,7 @@ +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.java b/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/mowgli/galaxy/stars/Sirius.java deleted file mode 100644 index 8279cad6..00000000 --- a/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/mowgli/galaxy/stars/Sirius.java +++ /dev/null @@ -1,12 +0,0 @@ -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(); - - -} 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 new file mode 100644 index 00000000..dd10a751 --- /dev/null +++ b/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/mowgli/galaxy/stars/Sirius.kt @@ -0,0 +1,8 @@ +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.java b/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/mowgli/identity/FamilyIdeology.java deleted file mode 100644 index 6f927760..00000000 --- a/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/mowgli/identity/FamilyIdeology.java +++ /dev/null @@ -1,16 +0,0 @@ -package com.github.klee0kai.test_ext.inject.mowgli.identity; - -import com.github.klee0kai.test.mowgli.identity.Ideology; - -import java.util.UUID; - -public class FamilyIdeology extends Ideology { - - public UUID uuid = UUID.randomUUID(); - - - public boolean isFamilyIdeology() { - return true; - } - -} 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 new file mode 100644 index 00000000..e851d989 --- /dev/null +++ b/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/mowgli/identity/FamilyIdeology.kt @@ -0,0 +1,15 @@ +@file:OptIn(ExperimentalUuidApi::class) + +package com.github.klee0kai.test_ext.inject.mowgli.identity + +import com.github.klee0kai.test.mowgli.identity.Ideology +import kotlin.uuid.ExperimentalUuidApi +import kotlin.uuid.Uuid + +class FamilyIdeology : Ideology() { + override var uuid: String = Uuid.random().toString() + + override val isFamilyIdeology: Boolean + get() = true + +} 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.java deleted file mode 100644 index afc0a76b..00000000 --- a/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/mowgli/identity/OldKnowledge.java +++ /dev/null @@ -1,16 +0,0 @@ -package com.github.klee0kai.test_ext.inject.mowgli.identity; - -import com.github.klee0kai.test.mowgli.identity.Knowledge; - -public class OldKnowledge extends Knowledge { - - - public boolean doChildKnowledge() { - return true; - } - - public boolean isOldKnowledge() { - return 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 new file mode 100644 index 00000000..1b7dc281 --- /dev/null +++ b/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/mowgli/identity/OldKnowledge.kt @@ -0,0 +1,14 @@ +package com.github.klee0kai.test_ext.inject.mowgli.identity + +import com.github.klee0kai.test.mowgli.identity.Knowledge + +class OldKnowledge : Knowledge() { + + fun doChildKnowledge(): Boolean { + 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.java b/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/tech/components/DDR3Ram.java deleted file mode 100644 index e5a325b4..00000000 --- a/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/tech/components/DDR3Ram.java +++ /dev/null @@ -1,30 +0,0 @@ -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.UUID; - -public class DDR3Ram extends Ram { - - public final UUID uuid = UUID.randomUUID(); - - public final String frequency; - - public DDR3Ram() { - super(); - frequency = "default"; - } - - public DDR3Ram(RamSize ramSize) { - super(ramSize); - this.frequency = "default"; - } - - public DDR3Ram(RamSize ramSize, Frequency frequency) { - super(ramSize); - this.frequency = frequency.frequency; - } - -} 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 new file mode 100644 index 00000000..1f6462e0 --- /dev/null +++ b/tests_ext/src/main/java/com/github/klee0kai/test_ext/inject/tech/components/DDR3Ram.kt @@ -0,0 +1,27 @@ +@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 kotlin.uuid.ExperimentalUuidApi +import kotlin.uuid.Uuid + +class DDR3Ram : Ram { + override val uuid: String = Uuid.random().toString() + + val frequency: String? + + constructor() : super() { + frequency = "default" + } + + constructor(ramSize: RamSize?) : super(ramSize) { + this.frequency = "default" + } + + constructor(ramSize: RamSize?, frequency: Frequency) : super(ramSize) { + this.frequency = frequency.frequency + } +} 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.java deleted file mode 100644 index d1749fd4..00000000 --- a/tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/bindinstance/simple/GodRebrandingAimedExtProtectTest.java +++ /dev/null @@ -1,102 +0,0 @@ -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 static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNull; - -public class GodRebrandingAimedExtProtectTest { - - @Test - public void createdIsReusableTest() { - // Given - GodWorkspaceComponent DI = Stone.createComponent(GodWorkspaceComponent.class); - Earth earth = new Earth(); - DI.bindEarth(earth); - - - //When - GodRebrandingComponent DIPro = Stone.createComponent(GodRebrandingComponent.class); - DIPro.extendComponent(DI); - - - //Then - assertEquals(earth, DI.sunSystem().earth()); - assertEquals(earth, DIPro.sunSystem().earth()); - assertNull(DI.sunSystem().planet()); - assertNull(DIPro.sunSystem().planet()); - } - - @Test - public void createdAfterRebrandingTest() { - // Given - GodWorkspaceComponent DI = Stone.createComponent(GodWorkspaceComponent.class); - GodRebrandingComponent DIPro = Stone.createComponent(GodRebrandingComponent.class); - DIPro.extendComponent(DI); - Earth earth = new Earth(); - - - //When - DI.bindEarth(earth); - - - //Then - assertEquals(earth, DI.sunSystem().earth()); - assertEquals(earth, DIPro.sunSystem().earth()); - assertNull(DI.sunSystem().planet()); - assertNull(DIPro.sunSystem().planet()); - } - - - @Test - public void rebrandedSunTest() { - // Given - GodWorkspaceComponent DI = Stone.createComponent(GodWorkspaceComponent.class); - Earth earth1 = new Earth(); - Earth earth2 = new Earth(); - DI.bindEarth(earth1); - - - //When - GodRebrandingComponent DIPro = Stone.createComponent(GodRebrandingComponent.class); - 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()); - } - - - @Test - public void 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); - - - //When - DI.bindEarth(earth3); - - - //Then - 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/GodRebrandingAimedExtProtectTest.kt b/tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/bindinstance/simple/GodRebrandingAimedExtProtectTest.kt new file mode 100644 index 00000000..3f8954d9 --- /dev/null +++ b/tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/bindinstance/simple/GodRebrandingAimedExtProtectTest.kt @@ -0,0 +1,100 @@ +package com.dirgub.klee0kai.stone.text_ext.bindinstance.simple + +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 + +class GodRebrandingAimedExtProtectTest { + + @Test + fun createdIsReusableTest() { + // Given + val DI = GodWorkspaceComponentStoneComponent() + val earth = Earth() + DI.bindEarth(earth) + + + //When + 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()) + } + + @Test + fun createdAfterRebrandingTest() { + // Given + val DI = GodWorkspaceComponentStoneComponent() + val DIPro = GodRebrandingComponentStoneComponent() + DIPro.extendComponent(DI) + val earth = Earth() + + + //When + DI.bindEarth(earth) + + + //Then + assertEquals(earth, DI.sunSystem().earth()) + assertEquals(earth, DIPro.sunSystem().earth()) + assertNull(DI.sunSystem().planet()) + assertNull(DIPro.sunSystem().planet()) + } + + + @Test + fun rebrandedSunTest() { + // Given + val DI = GodWorkspaceComponentStoneComponent() + val earth1 = Earth() + val earth2 = Earth() + DI.bindEarth(earth1) + + + //When + 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()) + } + + + @Test + fun updatedAfterRebrandingSunTest() { + // Given + 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) + + + //Then + 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.java b/tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/bindinstance/simple/GodRebrandingAimedTest.java deleted file mode 100644 index 71cc312a..00000000 --- a/tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/bindinstance/simple/GodRebrandingAimedTest.java +++ /dev/null @@ -1,102 +0,0 @@ -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 static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNull; - -public class GodRebrandingAimedTest { - - @Test - public void createdIsReusableTest() { - // Given - GodWorkspaceComponent DI = Stone.createComponent(GodWorkspaceComponent.class); - Earth earth = new Earth(); - DI.bindEarth(earth); - - - //When - GodRebrandingComponent DIPro = Stone.createComponent(GodRebrandingComponent.class); - DIPro.extendComponent(DI); - - - //Then - assertEquals(earth, DI.sunSystem().earth()); - assertEquals(earth, DIPro.sunSystem().earth()); - assertNull(DI.sunSystem().planet()); - assertNull(DIPro.sunSystem().planet()); - } - - @Test - public void createdAfterRebrandingTest() { - // Given - GodWorkspaceComponent DI = Stone.createComponent(GodWorkspaceComponent.class); - GodRebrandingComponent DIPro = Stone.createComponent(GodRebrandingComponent.class); - DIPro.extendComponent(DI); - Earth earth = new Earth(); - - - //When - DI.bindEarth(earth); - - - //Then - assertEquals(earth, DI.sunSystem().earth()); - assertEquals(earth, DIPro.sunSystem().earth()); - assertNull(DI.sunSystem().planet()); - assertNull(DIPro.sunSystem().planet()); - } - - - @Test - public void rebrandedSunTest() { - // Given - GodWorkspaceComponent DI = Stone.createComponent(GodWorkspaceComponent.class); - Earth earth1 = new Earth(); - Earth earth2 = new Earth(); - DI.bindEarth(earth1); - - - //When - GodRebrandingComponent DIPro = Stone.createComponent(GodRebrandingComponent.class); - 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()); - } - - - @Test - public void 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); - - - //When - DI.bindEarth(earth3); - - - //Then - 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 new file mode 100644 index 00000000..e40ad548 --- /dev/null +++ b/tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/bindinstance/simple/GodRebrandingAimedTest.kt @@ -0,0 +1,100 @@ +package com.dirgub.klee0kai.stone.text_ext.bindinstance.simple + +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 + +class GodRebrandingAimedTest { + + @Test + fun createdIsReusableTest() { + // Given + val DI = GodWorkspaceComponentStoneComponent() + val earth = Earth() + DI.bindEarth(earth) + + + //When + 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()) + } + + @Test + fun createdAfterRebrandingTest() { + // Given + val DI = GodWorkspaceComponentStoneComponent() + val DIPro = GodRebrandingComponentStoneComponent() + DIPro.extendComponent(DI) + val earth = Earth() + + + //When + DI.bindEarth(earth) + + + //Then + assertEquals(earth, DI.sunSystem().earth()) + assertEquals(earth, DIPro.sunSystem().earth()) + assertNull(DI.sunSystem().planet()) + assertNull(DIPro.sunSystem().planet()) + } + + + @Test + fun rebrandedSunTest() { + // Given + val DI = GodWorkspaceComponentStoneComponent() + val earth1 = Earth() + val earth2 = Earth() + DI.bindEarth(earth1) + + + //When + 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()) + } + + + @Test + fun updatedAfterRebrandingSunTest() { + // Given + 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) + + + //Then + 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.java b/tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/bindinstance/simple/GodRebrandingPlanetExtProtectTest.java deleted file mode 100644 index 838c028e..00000000 --- a/tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/bindinstance/simple/GodRebrandingPlanetExtProtectTest.java +++ /dev/null @@ -1,102 +0,0 @@ -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 static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNull; - -public class GodRebrandingPlanetExtProtectTest { - - @Test - public void createdIsReusableTest() { - // Given - GodWorkspaceComponent DI = Stone.createComponent(GodWorkspaceComponent.class); - Earth earth = new Earth(); - DI.bindPlanet(earth); - - - //When - GodRebrandingComponent DIPro = Stone.createComponent(GodRebrandingComponent.class); - DIPro.extendComponent(DI); - - - //Then - assertEquals(earth, DI.sunSystem().planet()); - assertEquals(earth, DIPro.sunSystem().planet()); - assertNull(DI.sunSystem().earth()); - assertNull(DIPro.sunSystem().earth()); - } - - @Test - public void createdAfterRebrandingTest() { - // Given - GodWorkspaceComponent DI = Stone.createComponent(GodWorkspaceComponent.class); - GodRebrandingComponent DIPro = Stone.createComponent(GodRebrandingComponent.class); - DIPro.extendComponent(DI); - Earth earth = new Earth(); - - - //When - DI.bindPlanet(earth); - - - //Then - assertEquals(earth, DI.sunSystem().planet()); - assertEquals(earth, DIPro.sunSystem().planet()); - assertNull(DI.sunSystem().earth()); - assertNull(DIPro.sunSystem().earth()); - } - - - @Test - public void rebrandedSunTest() { - // Given - GodWorkspaceComponent DI = Stone.createComponent(GodWorkspaceComponent.class); - Earth earth1 = new Earth(); - Earth earth2 = new Earth(); - DI.bindPlanet(earth1); - - - //When - GodRebrandingComponent DIPro = Stone.createComponent(GodRebrandingComponent.class); - 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()); - } - - - @Test - public void 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); - - - //When - DI.bindPlanet(earth3); - - - //Then - 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/GodRebrandingPlanetExtProtectTest.kt b/tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/bindinstance/simple/GodRebrandingPlanetExtProtectTest.kt new file mode 100644 index 00000000..26e66784 --- /dev/null +++ b/tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/bindinstance/simple/GodRebrandingPlanetExtProtectTest.kt @@ -0,0 +1,100 @@ +package com.dirgub.klee0kai.stone.text_ext.bindinstance.simple + +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 + +class GodRebrandingPlanetExtProtectTest { + + @Test + fun createdIsReusableTest() { + // Given + val DI = GodWorkspaceComponentStoneComponent() + val earth = Earth() + DI.bindPlanet(earth) + + + //When + 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()) + } + + @Test + fun createdAfterRebrandingTest() { + // Given + val DI = GodWorkspaceComponentStoneComponent() + val DIPro = GodRebrandingComponentStoneComponent() + DIPro.extendComponent(DI) + val earth = Earth() + + + //When + DI.bindPlanet(earth) + + + //Then + assertEquals(earth, DI.sunSystem().planet()) + assertEquals(earth, DIPro.sunSystem().planet()) + assertNull(DI.sunSystem().earth()) + assertNull(DIPro.sunSystem().earth()) + } + + + @Test + fun rebrandedSunTest() { + // Given + val DI = GodWorkspaceComponentStoneComponent() + val earth1 = Earth() + val earth2 = Earth() + DI.bindPlanet(earth1) + + + //When + 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()) + } + + + @Test + fun updatedAfterRebrandingSunTest() { + // Given + 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) + + + //Then + 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.java b/tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/bindinstance/simple/GodRebrandingPlanetTest.java deleted file mode 100644 index bd410d89..00000000 --- a/tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/bindinstance/simple/GodRebrandingPlanetTest.java +++ /dev/null @@ -1,102 +0,0 @@ -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 static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNull; - -public class GodRebrandingPlanetTest { - - @Test - public void createdIsReusableTest() { - // Given - GodWorkspaceComponent DI = Stone.createComponent(GodWorkspaceComponent.class); - Earth earth = new Earth(); - DI.bindPlanet(earth); - - - //When - GodRebrandingComponent DIPro = Stone.createComponent(GodRebrandingComponent.class); - DIPro.extendComponent(DI); - - - //Then - assertEquals(earth, DI.sunSystem().planet()); - assertEquals(earth, DIPro.sunSystem().planet()); - assertNull(DI.sunSystem().earth()); - assertNull(DIPro.sunSystem().earth()); - } - - @Test - public void createdAfterRebrandingTest() { - // Given - GodWorkspaceComponent DI = Stone.createComponent(GodWorkspaceComponent.class); - GodRebrandingComponent DIPro = Stone.createComponent(GodRebrandingComponent.class); - DIPro.extendComponent(DI); - Earth earth = new Earth(); - - - //When - DI.bindPlanet(earth); - - - //Then - assertEquals(earth, DI.sunSystem().planet()); - assertEquals(earth, DIPro.sunSystem().planet()); - assertNull(DI.sunSystem().earth()); - assertNull(DIPro.sunSystem().earth()); - } - - - @Test - public void rebrandedSunTest() { - // Given - GodWorkspaceComponent DI = Stone.createComponent(GodWorkspaceComponent.class); - Earth earth1 = new Earth(); - Earth earth2 = new Earth(); - DI.bindPlanet(earth1); - - - //When - GodRebrandingComponent DIPro = Stone.createComponent(GodRebrandingComponent.class); - 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()); - } - - - @Test - public void 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); - - - //When - DI.bindPlanet(earth3); - - - //Then - 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 new file mode 100644 index 00000000..240764fd --- /dev/null +++ b/tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/bindinstance/simple/GodRebrandingPlanetTest.kt @@ -0,0 +1,100 @@ +package com.dirgub.klee0kai.stone.text_ext.bindinstance.simple + +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 + +class GodRebrandingPlanetTest { + + @Test + fun createdIsReusableTest() { + // Given + val DI = GodWorkspaceComponentStoneComponent() + val earth = Earth() + DI.bindPlanet(earth) + + + //When + 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()) + } + + @Test + fun createdAfterRebrandingTest() { + // Given + val DI = GodRebrandingComponentStoneComponent() + val DIPro = GodRebrandingComponentStoneComponent() + DIPro.extendComponent(DI) + val earth = Earth() + + + //When + DI.bindPlanet(earth) + + + //Then + assertEquals(earth, DI.sunSystem().planet()) + assertEquals(earth, DIPro.sunSystem().planet()) + assertNull(DI.sunSystem().earth()) + assertNull(DIPro.sunSystem().earth()) + } + + + @Test + fun rebrandedSunTest() { + // Given + val DI = GodWorkspaceComponentStoneComponent() + val earth1 = Earth() + val earth2 = Earth() + DI.bindPlanet(earth1) + + + //When + 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()) + } + + + @Test + fun updatedAfterRebrandingSunTest() { + // Given + 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) + + + //Then + 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.java b/tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/bindinstance/simple/GodRebrandingTest.java deleted file mode 100644 index 599a7e74..00000000 --- a/tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/bindinstance/simple/GodRebrandingTest.java +++ /dev/null @@ -1,102 +0,0 @@ -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 static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNull; - -public class GodRebrandingTest { - - @Test - public void createdIsReusableTest() { - // Given - GodWorkspaceComponent DI = Stone.createComponent(GodWorkspaceComponent.class); - Earth earth = new Earth(); - DI.bindEarth(earth); - - - //When - GodRebrandingComponent DIPro = Stone.createComponent(GodRebrandingComponent.class); - DIPro.extendComponent(DI); - - - //Then - assertEquals(earth, DI.sunSystem().earth()); - assertEquals(earth, DIPro.sunSystem().earth()); - assertNull(DI.sunSystem().planet()); - assertNull(DIPro.sunSystem().planet()); - } - - @Test - public void createdAfterRebrandingTest() { - // Given - GodWorkspaceComponent DI = Stone.createComponent(GodWorkspaceComponent.class); - GodRebrandingComponent DIPro = Stone.createComponent(GodRebrandingComponent.class); - DIPro.extendComponent(DI); - Earth earth = new Earth(); - - - //When - DI.bindEarth(earth); - - - //Then - assertEquals(earth, DI.sunSystem().earth()); - assertEquals(earth, DIPro.sunSystem().earth()); - assertNull(DI.sunSystem().planet()); - assertNull(DIPro.sunSystem().planet()); - } - - - @Test - public void rebrandedSunTest() { - // Given - GodWorkspaceComponent DI = Stone.createComponent(GodWorkspaceComponent.class); - Earth earth1 = new Earth(); - Earth earth2 = new Earth(); - DI.bindEarth(earth1); - - - //When - GodRebrandingComponent DIPro = Stone.createComponent(GodRebrandingComponent.class); - 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()); - } - - - @Test - public void 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); - - - //When - DI.bindEarth(earth3); - - - //Then - 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/GodRebrandingTest.kt b/tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/bindinstance/simple/GodRebrandingTest.kt new file mode 100644 index 00000000..cdc12897 --- /dev/null +++ b/tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/bindinstance/simple/GodRebrandingTest.kt @@ -0,0 +1,100 @@ +package com.dirgub.klee0kai.stone.text_ext.bindinstance.simple + +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 + +class GodRebrandingTest { + + @Test + fun createdIsReusableTest() { + // Given + val DI = GodWorkspaceComponentStoneComponent() + val earth = Earth() + DI.bindEarth(earth) + + + //When + 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()) + } + + @Test + fun createdAfterRebrandingTest() { + // Given + val DI = GodWorkspaceComponentStoneComponent() + val DIPro = GodRebrandingComponentStoneComponent() + DIPro.extendComponent(DI) + val earth = Earth() + + + //When + DI.bindEarth(earth) + + + //Then + assertEquals(earth, DI.sunSystem().earth()) + assertEquals(earth, DIPro.sunSystem().earth()) + assertNull(DI.sunSystem().planet()) + assertNull(DIPro.sunSystem().planet()) + } + + + @Test + fun rebrandedSunTest() { + // Given + val DI = GodWorkspaceComponentStoneComponent() + val earth1 = Earth() + val earth2 = Earth() + DI.bindEarth(earth1) + + + //When + 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()) + } + + + @Test + fun updatedAfterRebrandingSunTest() { + // Given + 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) + + + //Then + 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.java b/tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/bindinstance/simple_inject/OldInjectTests.java deleted file mode 100644 index 76e13c15..00000000 --- a/tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/bindinstance/simple_inject/OldInjectTests.java +++ /dev/null @@ -1,118 +0,0 @@ - -package com.dirgub.klee0kai.stone.text_ext.bindinstance.simple_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_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 { - - @Test - public void oldHorseInjectTest() { - // Given - ForestComponent DI = Stone.createComponent(ForestComponent.class); - OldForestComponent DIPro = Stone.createComponent(OldForestComponent.class); - DIPro.extOf(DI); - OldHorse horse = new OldHorse(); - - // When - DIPro.inject(horse); - - // Then - assertNotNull(horse.blood); - assertNotNull(horse.knowledge); - assertNotNull(horse.conscience); - assertNotNull(horse.oldKnowledge); - assertNotNull(horse.osteoarthritis); - } - - - @Test - public void simpleProvideProTest() { - // Given - ForestComponent DI = Stone.createComponent(ForestComponent.class); - OldForestComponent DIPro = Stone.createComponent(OldForestComponent.class); - DIPro.extOf(DI); - OldHorse horse = new OldHorse(); - - // When - DIPro.inject(horse); - - // Then - assertTrue(horse.ideology.isFamilyIdeology()); - - } - - @Test - public void overrideProvideTest() { - // Given - ForestComponent DI = Stone.createComponent(ForestComponent.class); - OldForestComponent DIPro = Stone.createComponent(OldForestComponent.class); - DIPro.extOf(DI); - OldHorse horse = new OldHorse(); - - // When - DIPro.inject(horse); - - // Then: new items should generate from new DI component - assertTrue(horse.knowledge.isOldKnowledge()); - } - - - @Test - public void nonGenCacheTest() { - // Given - ForestComponent DI = Stone.createComponent(ForestComponent.class); - Horse horse = new Horse(); - - // When - DI.inject(horse); - - // simply connect dynamic feature - OldForestComponent DIPro = Stone.createComponent(OldForestComponent.class); - DIPro.extOf(DI); - DI.inject(horse); - - // Then - assertFalse(horse.ideology.isFamilyIdeology()); - } - - - @Test - public void overrideCacheTest() { - // Given - ForestComponent DI = Stone.createComponent(ForestComponent.class); - Horse horse = new Horse(); - - // When - DI.inject(horse); - - // simply connect dynamic feature - OldForestComponent DIPro = Stone.createComponent(OldForestComponent.class); - DIPro.extOf(DI); - DI.inject(horse); - - //use cached component if not need use overrided - assertFalse(horse.ideology.isFamilyIdeology()); - - OldHorse oldHorse = new OldHorse(); - DIPro.inject(oldHorse); - - //check override on DIPro - assertTrue(oldHorse.ideology.isFamilyIdeology()); - - // all use overrided features - DI.inject(horse); - - assertTrue(horse.ideology.isFamilyIdeology()); - - } - - -} 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 new file mode 100644 index 00000000..eb0cba00 --- /dev/null +++ b/tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/bindinstance/simple_inject/OldInjectTests.kt @@ -0,0 +1,115 @@ +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 + +class OldInjectTests { + + @Test + fun oldHorseInjectTest() { + // Given + val DI = ForestComponentStoneComponent() + val DIPro = OldForestComponentStoneComponent() + DIPro.extOf(DI) + val horse = OldHorse() + + // When + DIPro.inject(horse) + + // Then + assertNotNull(horse.blood) + assertNotNull(horse.knowledge) + assertNotNull(horse.conscience) + assertNotNull(horse.oldKnowledge) + assertNotNull(horse.osteoarthritis) + } + + + @Test + fun simpleProvideProTest() { + // Given + val DI = ForestComponentStoneComponent() + val DIPro = OldForestComponentStoneComponent() + DIPro.extOf(DI) + val horse = OldHorse() + + // When + DIPro.inject(horse) + + // Then + assertTrue(horse.ideology!!.isFamilyIdeology) + } + + @Test + fun overrideProvideTest() { + // Given + val DI = ForestComponentStoneComponent() + val DIPro = OldForestComponentStoneComponent() + DIPro.extOf(DI) + val horse = OldHorse() + + // When + DIPro.inject(horse) + + // Then: new items should generate from new DI component + assertTrue(horse.knowledge!!.isOldKnowledge) + } + + + @Test + fun nonGenCacheTest() { + // Given + val DI: ForestComponent = ForestComponentStoneComponent() + val horse = Horse() + + // When + DI.inject(horse) + + // simply connect dynamic feature + val DIPro: OldForestComponent = OldForestComponentStoneComponent() + DIPro.extOf(DI) + DI.inject(horse) + + // Then + assertFalse(horse.ideology!!.isFamilyIdeology) + } + + + @Test + fun overrideCacheTest() { + // Given + val DI: ForestComponent = ForestComponentStoneComponent() + val horse = Horse() + + // When + DI.inject(horse) + + // simply connect dynamic feature + val DIPro: OldForestComponent = OldForestComponentStoneComponent() + DIPro.extOf(DI) + DI.inject(horse) + + //use cached component if not need use overrided + assertFalse(horse.ideology!!.isFamilyIdeology) + + val oldHorse = OldHorse() + DIPro.inject(oldHorse) + + //check override on DIPro + assertTrue(oldHorse.ideology!!.isFamilyIdeology) + + // all use overrided features + DI.inject(horse) + + assertTrue(horse.ideology!!.isFamilyIdeology) + } + +} 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.java deleted file mode 100644 index 30a25be0..00000000 --- a/tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/bindinstance/singlemethod/ExtPlanetTests.java +++ /dev/null @@ -1,103 +0,0 @@ -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 static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNull; - -public class ExtPlanetTests { - - @Test - public void createdIsReusableTest() { - // Given - PlanetComponent DI = Stone.createComponent(PlanetComponent.class); - Earth earth = new Earth(); - DI.earth(earth); - - - //When - ExtPlanetComponent DIPro = Stone.createComponent(ExtPlanetComponent.class); - DIPro.extendOf(DI); - - - //Then - assertEquals(earth, DI.earth(null)); - assertEquals(earth, DIPro.earth(null)); - assertNull(DI.planet(null)); - assertNull(DIPro.planet(null)); - } - - @Test - public void createdAfterExtendTest() { - // Given - PlanetComponent DI = Stone.createComponent(PlanetComponent.class); - ExtPlanetComponent DIPro = Stone.createComponent(ExtPlanetComponent.class); - DIPro.extendOf(DI); - Earth earth = new Earth(); - - - //When - DI.earth(earth); - - - //Then - assertEquals(earth, DI.earth(null)); - assertEquals(earth, DIPro.earth(null)); - assertNull(DI.planet(null)); - assertNull(DIPro.planet(null)); - } - - - @Test - public void extendedEarthTest() { - // Given - PlanetComponent DI = Stone.createComponent(PlanetComponent.class); - Earth earth1 = new Earth(); - Earth earth2 = new Earth(); - DI.earth(earth1); - - - //When - ExtPlanetComponent DIPro = Stone.createComponent(ExtPlanetComponent.class); - 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)); - } - - - @Test - public void 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); - - - //When - DI.earth(earth3); - - - //Then - 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/ExtPlanetTests.kt b/tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/bindinstance/singlemethod/ExtPlanetTests.kt new file mode 100644 index 00000000..4dbcf225 --- /dev/null +++ b/tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/bindinstance/singlemethod/ExtPlanetTests.kt @@ -0,0 +1,101 @@ +package com.dirgub.klee0kai.stone.text_ext.bindinstance.singlemethod + +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 + +class ExtPlanetTests { + + @Test + fun createdIsReusableTest() { + // Given + val DI: PlanetComponent = PlanetComponentStoneComponent() + val earth = Earth() + DI.earth(earth) + + + //When + 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)) + } + + @Test + fun createdAfterExtendTest() { + // Given + val DI: PlanetComponent = PlanetComponentStoneComponent() + val DIPro: ExtPlanetComponent = ExtPlanetComponentStoneComponent() + DIPro.extendOf(DI) + val earth = Earth() + + + //When + DI.earth(earth) + + + //Then + assertEquals(earth, DI.earth(null)) + assertEquals(earth, DIPro.earth(null)) + assertNull(DI.planet(null)) + assertNull(DIPro.planet(null)) + } + + + @Test + fun extendedEarthTest() { + // Given + val DI: PlanetComponent = PlanetComponentStoneComponent() + val earth1 = Earth() + val earth2 = Earth() + DI.earth(earth1) + + + //When + 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)) + } + + + @Test + fun updatedAfterExtendEarthTest() { + // Given + 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) + + + //Then + 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.java b/tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/bindinstance/singlemethod/PlanetSputniksTests.java deleted file mode 100644 index 1fd34e29..00000000 --- a/tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/bindinstance/singlemethod/PlanetSputniksTests.java +++ /dev/null @@ -1,103 +0,0 @@ -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 static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNull; - -public class PlanetSputniksTests { - - @Test - public void createdIsReusableTest() { - // Given - PlanetComponent DI = Stone.createComponent(PlanetComponent.class); - Earth earth = new Earth(); - DI.earth(earth); - - - //When - PlanetSputnikComponent DIPro = Stone.createComponent(PlanetSputnikComponent.class); - DIPro.extendOf(DI); - - - //Then - assertEquals(earth, DI.earth(null)); - assertEquals(earth, DIPro.earth(null)); - assertNull(DI.planet(null)); - assertNull(DIPro.planet(null)); - } - - @Test - public void createdAfterExtendTest() { - // Given - PlanetComponent DI = Stone.createComponent(PlanetComponent.class); - PlanetSputnikComponent DIPro = Stone.createComponent(PlanetSputnikComponent.class); - DIPro.extendOf(DI); - Earth earth = new Earth(); - - - //When - DI.earth(earth); - - - //Then - assertEquals(earth, DI.earth(null)); - assertEquals(earth, DIPro.earth(null)); - assertNull(DI.planet(null)); - assertNull(DIPro.planet(null)); - } - - - @Test - public void extendedEarthTest() { - // Given - PlanetComponent DI = Stone.createComponent(PlanetComponent.class); - Earth earth1 = new Earth(); - Earth earth2 = new Earth(); - DI.earth(earth1); - - - //When - PlanetSputnikComponent DIPro = Stone.createComponent(PlanetSputnikComponent.class); - 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)); - } - - - @Test - public void 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); - - - //When - DI.earth(earth3); - - - //Then - 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 new file mode 100644 index 00000000..514a4294 --- /dev/null +++ b/tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/bindinstance/singlemethod/PlanetSputniksTests.kt @@ -0,0 +1,101 @@ +package com.dirgub.klee0kai.stone.text_ext.bindinstance.singlemethod + +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 + +class PlanetSputniksTests { + + @Test + fun createdIsReusableTest() { + // Given + val DI: PlanetComponent = PlanetComponentStoneComponent() + val earth = Earth() + DI.earth(earth) + + + //When + 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)) + } + + @Test + fun createdAfterExtendTest() { + // Given + val DI: PlanetComponent = PlanetComponentStoneComponent() + val DIPro: PlanetSputnikComponent = PlanetSputnikComponentStoneComponent() + DIPro.extendOf(DI) + val earth = Earth() + + + //When + DI.earth(earth) + + + //Then + assertEquals(earth, DI.earth(null)) + assertEquals(earth, DIPro.earth(null)) + assertNull(DI.planet(null)) + assertNull(DIPro.planet(null)) + } + + + @Test + fun extendedEarthTest() { + // Given + val DI: PlanetComponent = PlanetComponentStoneComponent() + val earth1 = Earth() + val earth2 = Earth() + DI.earth(earth1) + + + //When + 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)) + } + + + @org.junit.jupiter.api.Test + fun updatedAfterExtendEarthTest() { + // Given + 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) + + + //Then + 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.java b/tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/bindinstance/singlemethod/StarProvideTests.java deleted file mode 100644 index f5c758b0..00000000 --- a/tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/bindinstance/singlemethod/StarProvideTests.java +++ /dev/null @@ -1,75 +0,0 @@ -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 static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNull; - -public class StarProvideTests { - - @Test - public void sunReusableTest() { - //Given - PlanetComponent DI = Stone.createComponent(PlanetComponent.class); - Sun sun = new Sun(); - DI.sunModule().sun(sun); - - //When - PlanetSputnikComponent DIPro = Stone.createComponent(PlanetSputnikComponent.class); - 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)); - } - - - @Test - public void createAfterExtendTest() { - //Given - PlanetComponent DI = Stone.createComponent(PlanetComponent.class); - PlanetSputnikComponent DIPro = Stone.createComponent(PlanetSputnikComponent.class); - DIPro.extendOf(DI); - Sun sun = new Sun(); - - //When - 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)); - } - - - @Test - public void extendedSunTest() { - //Given - PlanetComponent DI = Stone.createComponent(PlanetComponent.class); - Sun sun1 = new Sun(); - Sun sun2 = new Sun(); - DI.sunModule().sun(sun1); - - //When - PlanetSputnikComponent DIPro = Stone.createComponent(PlanetSputnikComponent.class); - 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)); - } - - -} 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 new file mode 100644 index 00000000..ec534d88 --- /dev/null +++ b/tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/bindinstance/singlemethod/StarProvideTests.kt @@ -0,0 +1,72 @@ +package com.dirgub.klee0kai.stone.text_ext.bindinstance.singlemethod + +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 + +class StarProvideTests { + + @Test + fun sunReusableTest() { + //Given + val DI: PlanetComponent = PlanetComponentStoneComponent() + val sun = Sun() + DI.sunModule()?.sun(sun) + + //When + 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)) + } + + @Test + fun createAfterExtendTest() { + //Given + val DI: PlanetComponent = PlanetComponentStoneComponent() + val DIPro: PlanetSputnikComponent = PlanetSputnikComponentStoneComponent() + DIPro.extendOf(DI) + 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)) + assertNull(DIPro.sunModule()!!.star(null)) + } + + + @Test + fun extendedSunTest() { + //Given + val DI: PlanetComponent = PlanetComponentStoneComponent() + val sun1 = Sun() + val sun2 = Sun() + DI.sunModule()!!.sun(sun1) + + //When + 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)) + } +} 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.java deleted file mode 100644 index 604bd27a..00000000 --- a/tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/bindinstance/singlemethod_gc/ExtPlanetRollingTests.java +++ /dev/null @@ -1,459 +0,0 @@ -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 { - - @Test - public void 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()); - //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()); - - //When - DIPro.gcAllExt(); - - //Then - for (WeakReference ref : Arrays.asList( - earthStrong, earthSoft, planetWeak, - sunStrong, sunSoft, starWeak, - siriusStrong, siriusSoft, siriusWeak, - moonStrong, moonSoft, moonWeak - )) { - assertNull(ref.get()); - } - } - - - @Test - public void 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()); - //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()); - - //When - DIPro.gcStrongExt(); - - //Then - for (WeakReference ref : Arrays.asList( - earthStrong, planetWeak, - sunStrong, starWeak, - siriusStrong, siriusWeak, - moonStrong, moonWeak - )) { - assertNull(ref.get()); - } - - for (WeakReference ref : Arrays.asList( - earthSoft, - sunSoft, - siriusSoft, - moonSoft - )) { - assertNotNull(ref.get()); - } - } - - - @Test - public void 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()); - //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()); - - //When - DIPro.gcSoftExt(); - - //Then - for (WeakReference ref : Arrays.asList( - earthSoft, planetWeak, - sunSoft, starWeak, - siriusSoft, siriusWeak, - moonSoft, moonWeak - )) { - assertNull(ref.get()); - } - - for (WeakReference ref : Arrays.asList( - earthStrong, - sunStrong, - siriusStrong, - moonStrong - )) { - assertNotNull(ref.get()); - } - } - - - @Test - public void 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()); - //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()); - - //When - DIPro.gcWeakExt(); - - //Then - for (WeakReference ref : Arrays.asList( - planetWeak, - starWeak, - siriusWeak, - moonWeak - )) { - assertNull(ref.get()); - } - - for (WeakReference ref : Arrays.asList( - earthStrong, earthSoft, - sunStrong, sunSoft, - siriusStrong, siriusSoft, - moonStrong, moonSoft - )) { - assertNotNull(ref.get()); - } - } - - - @Test - public void 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()); - //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()); - - //When - DIPro.gcSoftSunExt(); - - //Then - for (WeakReference ref : Arrays.asList( - planetWeak, - sunSoft, starWeak, - siriusWeak, - moonWeak - )) { - assertNull(ref.get()); - } - - for (WeakReference ref : Arrays.asList( - earthStrong, earthSoft, - sunStrong, - siriusStrong, siriusSoft, - moonStrong, moonSoft - )) { - assertNotNull(ref.get()); - } - } - - - @Test - public void 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()); - //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()); - - //When - DIPro.gcSoftPlanetsExt(); - - //Then - for (WeakReference ref : Arrays.asList( - earthSoft, planetWeak, - starWeak, - siriusWeak, - moonWeak - )) { - assertNull(ref.get()); - } - - for (WeakReference ref : Arrays.asList( - earthStrong, - sunStrong, sunSoft, - siriusStrong, siriusSoft, - moonStrong, moonSoft - )) { - assertNotNull(ref.get()); - } - } - - - @Test - public void 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()); - //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()); - - //When - DIPro.gcSoftSiriusExt(); - - //Then - for (WeakReference ref : Arrays.asList( - planetWeak, - starWeak, - siriusSoft, siriusWeak, - moonWeak - )) { - assertNull(ref.get()); - } - - for (WeakReference ref : Arrays.asList( - earthStrong, earthSoft, - sunStrong, sunSoft, - siriusStrong, - moonStrong, moonSoft - )) { - assertNotNull(ref.get()); - } - } - - - @Test - public void 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()); - //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()); - - //When - DIPro.gcSoftSputniksExt(); - - //Then - for (WeakReference ref : Arrays.asList( - planetWeak, - starWeak, - siriusWeak, - moonSoft, moonWeak - )) { - assertNull(ref.get()); - } - - for (WeakReference ref : Arrays.asList( - earthStrong, earthSoft, - sunStrong, sunSoft, - siriusStrong, siriusSoft, - moonStrong - )) { - assertNotNull(ref.get()); - } - } - - -} 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 new file mode 100644 index 00000000..24639c42 --- /dev/null +++ b/tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/bindinstance/singlemethod_gc/ExtPlanetRollingTests.kt @@ -0,0 +1,456 @@ +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 ExtPlanetRollingTests { + + @Test + fun gcAllTest() { + //Given + 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 + 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() + + //Then + for (ref in listOf( + earthStrong, earthSoft, planetWeak, + sunStrong, sunSoft, starWeak, + siriusStrong, siriusSoft, siriusWeak, + moonStrong, moonSoft, moonWeak + )) { + assertNull(ref.get()) + } + } + + + @Test + fun gcStrongTest() { + //Given + 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 + 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() + + //Then + for (ref in listOf( + earthStrong, planetWeak, + sunStrong, starWeak, + siriusStrong, siriusWeak, + moonStrong, moonWeak + )) { + assertNull(ref.get()) + } + + for (ref in listOf( + earthSoft, + sunSoft, + siriusSoft, + moonSoft + )) { + assertNotNull(ref.get()) + } + } + + + @Test + fun gcSoftTest() { + //Given + 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 + 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() + + //Then + for (ref in listOf( + earthSoft, planetWeak, + sunSoft, starWeak, + siriusSoft, siriusWeak, + moonSoft, moonWeak + )) { + assertNull(ref.get()) + } + + for (ref in listOf( + earthStrong, + sunStrong, + siriusStrong, + moonStrong + )) { + assertNotNull(ref.get()) + } + } + + + @Test + fun gcWeakTest() { + //Given + 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 + 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.gcWeakExt() + + //Then + for (ref in listOf( + planetWeak, + starWeak, + siriusWeak, + moonWeak + )) { + assertNull(ref.get()) + } + + for (ref in listOf( + earthStrong, earthSoft, + sunStrong, sunSoft, + siriusStrong, siriusSoft, + moonStrong, moonSoft + )) { + assertNotNull(ref.get()) + } + } + + + @Test + fun gcSoftSunTest() { + //Given + 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 + 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.gcSoftSunExt() + + //Then + for (ref in listOf( + planetWeak, + sunSoft, starWeak, + siriusWeak, + moonWeak + )) { + assertNull(ref.get()) + } + + for (ref in listOf( + earthStrong, earthSoft, + sunStrong, + siriusStrong, siriusSoft, + moonStrong, moonSoft + )) { + assertNotNull(ref.get()) + } + } + + + @Test + fun gcSoftPlanetsTest() { + //Given + 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 + 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.gcSoftPlanetsExt() + + //Then + for (ref in listOf( + earthSoft, planetWeak, + starWeak, + siriusWeak, + moonWeak + )) { + assertNull(ref.get()) + } + + for (ref in listOf( + earthStrong, + sunStrong, sunSoft, + siriusStrong, siriusSoft, + moonStrong, moonSoft + )) { + assertNotNull(ref.get()) + } + } + + + @Test + fun gcSoftSiriusTest() { + //Given + 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 + 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.gcSoftSiriusExt() + + //Then + for (ref in listOf( + planetWeak, + starWeak, + siriusSoft, siriusWeak, + moonWeak + )) { + assertNull(ref.get()) + } + + for (ref in listOf( + earthStrong, earthSoft, + sunStrong, sunSoft, + siriusStrong, + moonStrong, moonSoft + )) { + assertNotNull(ref.get()) + } + } + + + @Test + fun gcSputniksMoonTest() { + //Given + 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 + 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.gcSoftSputniksExt() + + //Then + for (ref in listOf( + planetWeak, + starWeak, + siriusWeak, + moonSoft, moonWeak + )) { + assertNull(ref.get()) + } + + for (ref in listOf( + earthStrong, earthSoft, + sunStrong, sunSoft, + siriusStrong, siriusSoft, + moonStrong + )) { + assertNotNull(ref.get()) + } + } + +} 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.java deleted file mode 100644 index 69108664..00000000 --- a/tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/bindinstance/singlemethod_gc/PlanetRollingAndProTests.java +++ /dev/null @@ -1,347 +0,0 @@ -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 { - - @Test - public void 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()); - //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()); - - //When - DI.gcAll(); - - //Then - for (WeakReference ref : Arrays.asList( - earthStrong, earthSoft, planetWeak, - sunStrong, sunSoft, starWeak, - siriusStrong, siriusSoft, siriusWeak, - moonStrong, moonSoft, moonWeak - )) { - assertNull(ref.get()); - } - } - - - @Test - public void 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()); - //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()); - - //When - DI.gcStrong(); - - //Then - for (WeakReference ref : Arrays.asList( - earthStrong, planetWeak, - sunStrong, starWeak, - siriusStrong, siriusWeak, - moonStrong, moonWeak - )) { - assertNull(ref.get()); - } - - for (WeakReference ref : Arrays.asList( - earthSoft, - sunSoft, - siriusSoft, - moonSoft - )) { - assertNotNull(ref.get()); - } - } - - - @Test - public void 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()); - //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()); - - //When - DI.gcSoft(); - - //Then - for (WeakReference ref : Arrays.asList( - earthSoft, planetWeak, - sunSoft, starWeak, - siriusSoft, siriusWeak, - moonSoft, moonWeak - )) { - assertNull(ref.get()); - } - - for (WeakReference ref : Arrays.asList( - earthStrong, - sunStrong, - siriusStrong, - moonStrong - )) { - assertNotNull(ref.get()); - } - } - - - @Test - public void 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()); - //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()); - - //When - DI.gcWeak(); - - //Then - for (WeakReference ref : Arrays.asList( - planetWeak, - starWeak, - siriusWeak, - moonWeak - )) { - assertNull(ref.get()); - } - - for (WeakReference ref : Arrays.asList( - earthStrong, earthSoft, - sunStrong, sunSoft, - siriusStrong, siriusSoft, - moonStrong, moonSoft - )) { - assertNotNull(ref.get()); - } - } - - - @Test - public void 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()); - //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()); - - //When - DI.gcSoftSun(); - - //Then - for (WeakReference ref : Arrays.asList( - planetWeak, - sunSoft, starWeak, - siriusWeak, - moonWeak - )) { - assertNull(ref.get()); - } - - for (WeakReference ref : Arrays.asList( - earthStrong, earthSoft, - sunStrong, - siriusStrong, siriusSoft, - moonStrong, moonSoft - )) { - assertNotNull(ref.get()); - } - } - - - @Test - public void 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()); - //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()); - - //When - DI.gcSoftPlanets(); - - //Then - for (WeakReference ref : Arrays.asList( - earthSoft, planetWeak, - starWeak, - siriusWeak, - moonWeak - )) { - assertNull(ref.get()); - } - - for (WeakReference ref : Arrays.asList( - earthStrong, - sunStrong, sunSoft, - siriusStrong, siriusSoft, - moonStrong, moonSoft - )) { - 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 new file mode 100644 index 00000000..981f8e58 --- /dev/null +++ b/tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/bindinstance/singlemethod_gc/PlanetRollingAndProTests.kt @@ -0,0 +1,343 @@ +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 + 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()) + 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 + 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() + + //Then + for (ref in listOf( + earthStrong, earthSoft, planetWeak, + sunStrong, sunSoft, starWeak, + siriusStrong, siriusSoft, siriusWeak, + moonStrong, moonSoft, moonWeak + )) { + assertNull(ref.get()) + } + } + + + @Test + fun gcStrongTest() { + //Given + 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 + 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() + + //Then + for (ref in listOf( + earthStrong, planetWeak, + sunStrong, starWeak, + siriusStrong, siriusWeak, + moonStrong, moonWeak + )) { + assertNull(ref.get()) + } + + for (ref in listOf( + earthSoft, + sunSoft, + siriusSoft, + moonSoft + )) { + assertNotNull(ref.get()) + } + } + + + @Test + fun gcSoftTest() { + //Given + 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 + 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() + + //Then + for (ref in listOf( + earthSoft, planetWeak, + sunSoft, starWeak, + siriusSoft, siriusWeak, + moonSoft, moonWeak + )) { + assertNull(ref.get()) + } + + for (ref in listOf( + earthStrong, + sunStrong, + siriusStrong, + moonStrong + )) { + assertNotNull(ref.get()) + } + } + + + @Test + fun gcWeakTest() { + //Given + 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 + 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() + + //Then + for (ref in listOf( + planetWeak, + starWeak, + siriusWeak, + moonWeak + )) { + assertNull(ref.get()) + } + + for (ref in listOf( + earthStrong, earthSoft, + sunStrong, sunSoft, + siriusStrong, siriusSoft, + moonStrong, moonSoft + )) { + assertNotNull(ref.get()) + } + } + + + @Test + fun gcSoftSunTest() { + //Given + 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 + 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() + + //Then + for (ref in listOf( + planetWeak, + sunSoft, starWeak, + siriusWeak, + moonWeak + )) { + assertNull(ref.get()) + } + + for (ref in listOf( + earthStrong, earthSoft, + sunStrong, + siriusStrong, siriusSoft, + moonStrong, moonSoft + )) { + assertNotNull(ref.get()) + } + } + + + @Test + fun gcSoftPlanetsTest() { + //Given + 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 + 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() + + //Then + for (ref in listOf( + earthSoft, planetWeak, + starWeak, + siriusWeak, + moonWeak + )) { + assertNull(ref.get()) + } + + for (ref in listOf( + earthStrong, + sunStrong, sunSoft, + siriusStrong, siriusSoft, + moonStrong, moonSoft + )) { + assertNotNull(ref.get()) + } + } +} 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.java deleted file mode 100644 index e8cbe1d2..00000000 --- a/tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/bindinstance/singlemethod_gc/PlanetRollingFromProTests.java +++ /dev/null @@ -1,347 +0,0 @@ -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 { - - @Test - public void 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()); - //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()); - - //When - DIPro.gcAll(); - - //Then - for (WeakReference ref : Arrays.asList( - earthStrong, earthSoft, planetWeak, - sunStrong, sunSoft, starWeak, - siriusStrong, siriusSoft, siriusWeak, - moonStrong, moonSoft, moonWeak - )) { - assertNull(ref.get()); - } - } - - - @Test - public void 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()); - //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()); - - //When - DIPro.gcStrong(); - - //Then - for (WeakReference ref : Arrays.asList( - earthStrong, planetWeak, - sunStrong, starWeak, - siriusStrong, siriusWeak, - moonStrong, moonWeak - )) { - assertNull(ref.get()); - } - - for (WeakReference ref : Arrays.asList( - earthSoft, - sunSoft, - siriusSoft, - moonSoft - )) { - assertNotNull(ref.get()); - } - } - - - @Test - public void 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()); - //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()); - - //When - DIPro.gcSoft(); - - //Then - for (WeakReference ref : Arrays.asList( - earthSoft, planetWeak, - sunSoft, starWeak, - siriusSoft, siriusWeak, - moonSoft, moonWeak - )) { - assertNull(ref.get()); - } - - for (WeakReference ref : Arrays.asList( - earthStrong, - sunStrong, - siriusStrong, - moonStrong - )) { - assertNotNull(ref.get()); - } - } - - - @Test - public void 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()); - //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()); - - //When - DIPro.gcWeak(); - - //Then - for (WeakReference ref : Arrays.asList( - planetWeak, - starWeak, - siriusWeak, - moonWeak - )) { - assertNull(ref.get()); - } - - for (WeakReference ref : Arrays.asList( - earthStrong, earthSoft, - sunStrong, sunSoft, - siriusStrong, siriusSoft, - moonStrong, moonSoft - )) { - assertNotNull(ref.get()); - } - } - - - @Test - public void 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()); - //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()); - - //When - DIPro.gcSoftSun(); - - //Then - for (WeakReference ref : Arrays.asList( - planetWeak, - sunSoft, starWeak, - siriusWeak, - moonWeak - )) { - assertNull(ref.get()); - } - - for (WeakReference ref : Arrays.asList( - earthStrong, earthSoft, - sunStrong, - siriusStrong, siriusSoft, - moonStrong, moonSoft - )) { - assertNotNull(ref.get()); - } - } - - - @Test - public void 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()); - //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()); - - //When - DIPro.gcSoftPlanets(); - - //Then - for (WeakReference ref : Arrays.asList( - earthSoft, planetWeak, - starWeak, - siriusWeak, - moonWeak - )) { - assertNull(ref.get()); - } - - for (WeakReference ref : Arrays.asList( - earthStrong, - sunStrong, sunSoft, - siriusStrong, siriusSoft, - moonStrong, moonSoft - )) { - 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 new file mode 100644 index 00000000..ff82d22f --- /dev/null +++ b/tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/bindinstance/singlemethod_gc/PlanetRollingFromProTests.kt @@ -0,0 +1,344 @@ +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 + fun gcAllTest() { + //Given + 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 + 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() + + //Then + for (ref in listOf( + earthStrong, earthSoft, planetWeak, + sunStrong, sunSoft, starWeak, + siriusStrong, siriusSoft, siriusWeak, + moonStrong, moonSoft, moonWeak + )) { + assertNull(ref.get()) + } + } + + + @Test + fun gcStrongTest() { + //Given + 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 + 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() + + //Then + for (ref in listOf( + earthStrong, planetWeak, + sunStrong, starWeak, + siriusStrong, siriusWeak, + moonStrong, moonWeak + )) { + assertNull(ref.get()) + } + + for (ref in listOf( + earthSoft, + sunSoft, + siriusSoft, + moonSoft + )) { + assertNotNull(ref.get()) + } + } + + + @Test + fun gcSoftTest() { + //Given + 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 + 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() + + //Then + for (ref in listOf( + earthSoft, planetWeak, + sunSoft, starWeak, + siriusSoft, siriusWeak, + moonSoft, moonWeak + )) { + assertNull(ref.get()) + } + + for (ref in listOf( + earthStrong, + sunStrong, + siriusStrong, + moonStrong + )) { + assertNotNull(ref.get()) + } + } + + + @Test + fun gcWeakTest() { + //Given + 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 + 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() + + //Then + for (ref in listOf( + planetWeak, + starWeak, + siriusWeak, + moonWeak + )) { + assertNull(ref.get()) + } + + for (ref in listOf( + earthStrong, earthSoft, + sunStrong, sunSoft, + siriusStrong, siriusSoft, + moonStrong, moonSoft + )) { + assertNotNull(ref.get()) + } + } + + + @Test + fun gcSoftSunTest() { + //Given + 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 + 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() + + //Then + for (ref in listOf( + planetWeak, + sunSoft, starWeak, + siriusWeak, + moonWeak + )) { + assertNull(ref.get()) + } + + for (ref in listOf( + earthStrong, earthSoft, + sunStrong, + siriusStrong, siriusSoft, + moonStrong, moonSoft + )) { + assertNotNull(ref.get()) + } + } + + + @Test + fun gcSoftPlanetsTest() { + //Given + 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 + 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() + + //Then + for (ref in listOf( + earthSoft, planetWeak, + starWeak, + siriusWeak, + moonWeak + )) { + assertNull(ref.get()) + } + + for (ref in listOf( + earthStrong, + sunStrong, sunSoft, + siriusStrong, siriusSoft, + moonStrong, moonSoft + )) { + assertNotNull(ref.get()) + } + } + +} 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.java deleted file mode 100644 index 20baec07..00000000 --- a/tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/cache/EarthCacheAndProTests.java +++ /dev/null @@ -1,148 +0,0 @@ -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 EarthCacheAndProTests { - - - @Test - public void strongCacheTest() { - //Given - GcGodComponent DI = Stone.createComponent(GcGodComponent.class); - GcGodExtComponent DIPro = Stone.createComponent(GcGodExtComponent.class); - DIPro.extOf(DI); - - //When - Mountain mountain1 = DI.earth().mountainStrong(); - Mountain mountain2 = DI.earth().mountainStrong(); - - //Then - assertEquals( - mountain1.uuid, - mountain2.uuid - ); - } - - - @Test - public void softCacheTest() { - //Given - GcGodComponent DI = Stone.createComponent(GcGodComponent.class); - GcGodExtComponent DIPro = Stone.createComponent(GcGodExtComponent.class); - DIPro.extOf(DI); - - //When - Mountain mountain1 = DI.earth().mountainSoft(); - Mountain mountain2 = DI.earth().mountainSoft(); - - //Then - assertEquals( - mountain1.uuid, - mountain2.uuid - ); - } - - @Test - public void weakCacheTest() { - //Given - GcGodComponent DI = Stone.createComponent(GcGodComponent.class); - GcGodExtComponent DIPro = Stone.createComponent(GcGodExtComponent.class); - DIPro.extOf(DI); - - //When - Mountain mountain1 = DI.earth().mountainWeak(); - Mountain mountain2 = DI.earth().mountainWeak(); - - //Then - assertEquals( - mountain1.uuid, - mountain2.uuid - ); - } - - @Test - public void defCacheTest() { - //Given - GcGodComponent DI = Stone.createComponent(GcGodComponent.class); - GcGodExtComponent DIPro = Stone.createComponent(GcGodExtComponent.class); - DIPro.extOf(DI); - - //When - Mountain mountain1 = DI.earth().mountainDefaultFactory(); - Mountain mountain2 = DI.earth().mountainDefaultFactory(); - - //Then - assertNotEquals( - mountain1.uuid, - mountain2.uuid, - "Factory providing" - ); - } - - @Test - public void differentMethodDifferentCacheTest() { - //Given - GcGodComponent DI = Stone.createComponent(GcGodComponent.class); - GcGodExtComponent DIPro = Stone.createComponent(GcGodExtComponent.class); - DIPro.extOf(DI); - - //When - Mountain mountainStrong = DI.earth().mountainStrong(); - Mountain mountainSoft = DI.earth().mountainSoft(); - - //Then - assertNotEquals( - mountainStrong.uuid, - mountainSoft.uuid - ); - } - - - @Test - public void factoryNotCacheTest() { - //Given - GcGodComponent DI = Stone.createComponent(GcGodComponent.class); - GcGodExtComponent DIPro = Stone.createComponent(GcGodExtComponent.class); - DIPro.extOf(DI); - - //When - Mountain mountain1 = DI.earth().mountainFactory(); - Mountain mountain2 = DI.earth().mountainFactory(); - - //Then - assertNotEquals( - mountain1.uuid, - mountain2.uuid - ); - } - - - @Test - public void 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); - - //When - Mountain mountain1 = DI1.earth().mountainStrong(); - Mountain mountain2 = DI2.earth().mountainStrong(); - - //Then - assertNotEquals( - mountain1.uuid, - mountain2.uuid - ); - } - -} 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 new file mode 100644 index 00000000..8e8376b6 --- /dev/null +++ b/tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/cache/EarthCacheAndProTests.kt @@ -0,0 +1,146 @@ +package com.dirgub.klee0kai.stone.text_ext.cache + +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 EarthCacheAndProTests { + + @Test + fun strongCacheTest() { + //Given + val DI: GcGodComponent = GcGodComponentStoneComponent() + val DIPro: GcGodExtComponent = GcGodExtComponentStoneComponent() + DIPro.extOf(DI) + + //When + val mountain1: Mountain? = DI.earth()!!.mountainStrong() + val mountain2: Mountain? = DI.earth()!!.mountainStrong() + + //Then + assertEquals( + mountain1!!.uuid, + mountain2!!.uuid + ) + } + + @Test + fun softCacheTest() { + //Given + val DI: GcGodComponent = GcGodComponentStoneComponent() + val DIPro: GcGodExtComponent = GcGodExtComponentStoneComponent() + DIPro.extOf(DI) + + //When + val mountain1 = DI.earth()!!.mountainSoft() + val mountain2 = DI.earth()!!.mountainSoft() + + //Then + assertEquals( + mountain1!!.uuid, + mountain2!!.uuid + ) + } + + @Test + fun weakCacheTest() { + //Given + val DI: GcGodComponent = GcGodComponentStoneComponent() + val DIPro: GcGodExtComponent = GcGodExtComponentStoneComponent() + DIPro.extOf(DI) + + //When + val mountain1: Mountain? = DI.earth()!!.mountainWeak() + val mountain2: Mountain? = DI.earth()!!.mountainWeak() + + //Then + assertEquals( + mountain1!!.uuid, + mountain2!!.uuid, + ) + } + + @Test + fun defCacheTest() { + //Given + val DI: GcGodComponent = GcGodComponentStoneComponent() + val DIPro: GcGodExtComponent = GcGodExtComponentStoneComponent() + DIPro.extOf(DI) + + //When + val mountain1: Mountain? = DI.earth()!!.mountainDefaultFactory() + val mountain2: Mountain? = DI.earth()!!.mountainDefaultFactory() + + //Then + assertNotEquals( + mountain1!!.uuid, + mountain2!!.uuid, + "Factory providing" + ) + } + + @Test + fun differentMethodDifferentCacheTest() { + //Given + val DI: GcGodComponent = GcGodComponentStoneComponent() + val DIPro: GcGodExtComponent = GcGodExtComponentStoneComponent() + DIPro.extOf(DI) + + //When + val mountainStrong: Mountain? = DI.earth()!!.mountainStrong() + val mountainSoft: Mountain? = DI.earth()!!.mountainSoft() + + //Then + assertNotEquals( + mountainStrong!!.uuid, + mountainSoft!!.uuid + ) + } + + + @Test + fun factoryNotCacheTest() { + //Given + val DI: GcGodComponent = GcGodComponentStoneComponent() + val DIPro: GcGodExtComponent = GcGodExtComponentStoneComponent() + DIPro.extOf(DI) + + //When + val mountain1: Mountain? = DI.earth()!!.mountainFactory() + val mountain2: Mountain? = DI.earth()!!.mountainFactory() + + //Then + assertNotEquals( + mountain1!!.uuid, + mountain2!!.uuid + ) + } + + + @Test + fun differentDIDifferentCacheTest() { + //Given + val DI1: GcGodComponent = GcGodComponentStoneComponent() + val DIPro1: GcGodExtComponent = GcGodExtComponentStoneComponent() + DIPro1.extOf(DI1) + val DI2: GcGodComponent = GcGodComponentStoneComponent() + val DIPro2: GcGodExtComponent = GcGodExtComponentStoneComponent() + DIPro2.extOf(DI2) + + //When + val mountain1: Mountain? = DI1.earth()!!.mountainStrong() + val mountain2: Mountain? = DI2.earth()!!.mountainStrong() + + //Then + assertNotEquals( + mountain1!!.uuid, + mountain2!!.uuid + ) + } +} 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.java deleted file mode 100644 index 17064686..00000000 --- a/tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/cache/EarthCacheFromProTests.java +++ /dev/null @@ -1,167 +0,0 @@ -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 EarthCacheFromProTests { - - - @Test - public void strongCacheTest() { - //Given - GcGodComponent DI = Stone.createComponent(GcGodComponent.class); - GcGodExtComponent DIPro = Stone.createComponent(GcGodExtComponent.class); - DIPro.extOf(DI); - - //When - Mountain mountain1 = DIPro.earth().mountainStrong(); - Mountain mountain2 = DIPro.earth().mountainStrong(); - - //Then - assertEquals( - mountain1.uuid, - mountain2.uuid - ); - } - - - @Test - public void softCacheTest() { - //Given - GcGodComponent DI = Stone.createComponent(GcGodComponent.class); - GcGodExtComponent DIPro = Stone.createComponent(GcGodExtComponent.class); - DIPro.extOf(DI); - - //When - Mountain mountain1 = DIPro.earth().mountainSoft(); - Mountain mountain2 = DIPro.earth().mountainSoft(); - - //Then - assertEquals( - mountain1.uuid, - mountain2.uuid - ); - } - - @Test - public void weakCacheTest() { - //Given - GcGodComponent DI = Stone.createComponent(GcGodComponent.class); - GcGodExtComponent DIPro = Stone.createComponent(GcGodExtComponent.class); - DIPro.extOf(DI); - - //When - Mountain mountain1 = DIPro.earth().mountainWeak(); - Mountain mountain2 = DIPro.earth().mountainWeak(); - - //Then - assertEquals( - mountain1.uuid, - mountain2.uuid - ); - } - - @Test - public void defCacheTest() { - //Given - GcGodComponent DI = Stone.createComponent(GcGodComponent.class); - GcGodExtComponent DIPro = Stone.createComponent(GcGodExtComponent.class); - DIPro.extOf(DI); - - //When - Mountain mountain1 = DIPro.earth().mountainDefaultFactory(); - Mountain mountain2 = DIPro.earth().mountainDefaultFactory(); - - //Then - assertNotEquals( - mountain1.uuid, - mountain2.uuid, - "Factory Providing" - ); - } - - @Test - public void defCache2Test() { - //Given - GcGodComponent DI = Stone.createComponent(GcGodComponent.class); - GcGodExtComponent DIPro = Stone.createComponent(GcGodExtComponent.class); - DIPro.extOf(DI); - - //When - Mountain mountain1 = DIPro.earth().mountainDefault2Factory(); - Mountain mountain2 = DIPro.earth().mountainDefault2Factory(); - - //Then - assertNotEquals( - mountain1.uuid, - mountain2.uuid, - "Factory Providing" - ); - } - - @Test - public void differentMethodDifferentCacheTest() { - //Given - GcGodComponent DI = Stone.createComponent(GcGodComponent.class); - GcGodExtComponent DIPro = Stone.createComponent(GcGodExtComponent.class); - DIPro.extOf(DI); - - //When - Mountain mountainStrong = DIPro.earth().mountainStrong(); - Mountain mountainSoft = DIPro.earth().mountainSoft(); - - //Then - assertNotEquals( - mountainStrong.uuid, - mountainSoft.uuid - ); - } - - - @Test - public void factoryNotCacheTest() { - //Given - GcGodComponent DI = Stone.createComponent(GcGodComponent.class); - GcGodExtComponent DIPro = Stone.createComponent(GcGodExtComponent.class); - DIPro.extOf(DI); - - //When - Mountain mountain1 = DIPro.earth().mountainFactory(); - Mountain mountain2 = DIPro.earth().mountainFactory(); - - //Then - assertNotEquals( - mountain1.uuid, - mountain2.uuid - ); - } - - - @Test - public void 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); - - //When - Mountain mountain1 = DIPro1.earth().mountainStrong(); - Mountain mountain2 = DIPro2.earth().mountainStrong(); - - //Then - assertNotEquals( - 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 new file mode 100644 index 00000000..026e5ec8 --- /dev/null +++ b/tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/cache/EarthCacheFromProTests.kt @@ -0,0 +1,166 @@ +package com.dirgub.klee0kai.stone.text_ext.cache + +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 EarthCacheFromProTests { + + @Test + fun strongCacheTest() { + //Given + val DI = GcGodComponentStoneComponent() + val DIPro: GcGodExtComponent = GcGodExtComponentStoneComponent() + DIPro.extOf(DI) + + //When + val mountain1: Mountain? = DIPro.earth()!!.mountainStrong() + val mountain2: Mountain? = DIPro.earth()!!.mountainStrong() + + //Then + assertEquals( + mountain1!!.uuid, + mountain2!!.uuid + ) + } + + + @Test + fun softCacheTest() { + //Given + val DI: GcGodComponent = GcGodComponentStoneComponent() + val DIPro: GcGodExtComponent = GcGodExtComponentStoneComponent() + DIPro.extOf(DI) + + //When + val mountain1: Mountain? = DIPro.earth()!!.mountainSoft() + val mountain2: Mountain? = DIPro.earth()!!.mountainSoft() + + //Then + assertEquals( + mountain1!!.uuid, + mountain2!!.uuid + ) + } + + @Test + fun weakCacheTest() { + //Given + val DI: GcGodComponent = GcGodComponentStoneComponent() + val DIPro: GcGodExtComponent = GcGodExtComponentStoneComponent() + DIPro.extOf(DI) + + //When + val mountain1: Mountain? = DIPro.earth()!!.mountainWeak() + val mountain2: Mountain? = DIPro.earth()!!.mountainWeak() + + //Then + assertEquals( + mountain1!!.uuid, + mountain2!!.uuid + ) + } + + @Test + fun defCacheTest() { + //Given + val DI: GcGodComponent = GcGodComponentStoneComponent() + val DIPro: GcGodExtComponent = GcGodExtComponentStoneComponent() + DIPro.extOf(DI) + + //When + val mountain1: Mountain? = DIPro.earth()!!.mountainDefaultFactory() + val mountain2: Mountain? = DIPro.earth()!!.mountainDefaultFactory() + + //Then + assertNotEquals( + mountain1!!.uuid, + mountain2!!.uuid, + "Factory Providing" + ) + } + + @Test + fun defCache2Test() { + //Given + val DI: GcGodComponent = GcGodComponentStoneComponent() + val DIPro: GcGodExtComponent = GcGodExtComponentStoneComponent() + DIPro.extOf(DI) + + //When + val mountain1: Mountain? = DIPro.earth()!!.mountainDefault2Factory() + val mountain2: Mountain? = DIPro.earth()!!.mountainDefault2Factory() + + //Then + assertNotEquals( + mountain1!!.uuid, + mountain2!!.uuid, + "Factory Providing" + ) + } + + @Test + fun differentMethodDifferentCacheTest() { + //Given + val DI: GcGodComponent = GcGodComponentStoneComponent() + val DIPro: GcGodExtComponent = GcGodExtComponentStoneComponent() + DIPro.extOf(DI) + + //When + val mountainStrong: Mountain? = DIPro.earth()!!.mountainStrong() + val mountainSoft: Mountain? = DIPro.earth()!!.mountainSoft() + + //Then + assertNotEquals( + mountainStrong!!.uuid, + mountainSoft!!.uuid + ) + } + + + @Test + fun factoryNotCacheTest() { + //Given + val DI: GcGodComponent = GcGodComponentStoneComponent() + val DIPro: GcGodExtComponent = GcGodExtComponentStoneComponent() + DIPro.extOf(DI) + + //When + val mountain1: Mountain? = DIPro.earth()!!.mountainFactory() + val mountain2: Mountain? = DIPro.earth()!!.mountainFactory() + + //Then + assertNotEquals( + mountain1!!.uuid, + mountain2!!.uuid + ) + } + + + @Test + fun differentDIDifferentCacheTest() { + //Given + val DI1: GcGodComponent = GcGodComponentStoneComponent() + val DIPro1: GcGodExtComponent = GcGodExtComponentStoneComponent() + DIPro1.extOf(DI1) + val DI2: GcGodComponent = GcGodComponentStoneComponent() + val DIPro2: GcGodExtComponent = GcGodExtComponentStoneComponent() + DIPro2.extOf(DI2) + + //When + val mountain1: Mountain? = DIPro1.earth()!!.mountainStrong() + val mountain2: Mountain? = DIPro2.earth()!!.mountainStrong() + + //Then + assertNotEquals( + mountain1!!.uuid, + mountain2!!.uuid + ) + } +} 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.java deleted file mode 100644 index c11ee395..00000000 --- a/tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/cache/EarthCacheMixedTests.java +++ /dev/null @@ -1,167 +0,0 @@ -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 { - - - @Test - public void strongCacheTest() { - //Given - GcGodComponent DI = Stone.createComponent(GcGodComponent.class); - GcGodExtComponent DIPro = Stone.createComponent(GcGodExtComponent.class); - DIPro.extOf(DI); - - //When - Mountain mountain1 = DI.earth().mountainStrong(); - Mountain mountain2 = DIPro.earth().mountainStrong(); - - //Then - assertEquals( - mountain1.uuid, - mountain2.uuid - ); - } - - - @Test - public void softCacheTest() { - //Given - GcGodComponent DI = Stone.createComponent(GcGodComponent.class); - GcGodExtComponent DIPro = Stone.createComponent(GcGodExtComponent.class); - DIPro.extOf(DI); - - //When - Mountain mountain1 = DI.earth().mountainSoft(); - Mountain mountain2 = DIPro.earth().mountainSoft(); - - //Then - assertEquals( - mountain1.uuid, - mountain2.uuid - ); - } - - @Test - public void weakCacheTest() { - //Given - GcGodComponent DI = Stone.createComponent(GcGodComponent.class); - GcGodExtComponent DIPro = Stone.createComponent(GcGodExtComponent.class); - DIPro.extOf(DI); - - //When - Mountain mountain1 = DI.earth().mountainWeak(); - Mountain mountain2 = DIPro.earth().mountainWeak(); - - //Then - assertEquals( - mountain1.uuid, - mountain2.uuid - ); - } - - @Test - public void defCacheTest() { - //Given - GcGodComponent DI = Stone.createComponent(GcGodComponent.class); - GcGodExtComponent DIPro = Stone.createComponent(GcGodExtComponent.class); - DIPro.extOf(DI); - - //When - Mountain mountain1 = DI.earth().mountainDefaultFactory(); - Mountain mountain2 = DIPro.earth().mountainDefaultFactory(); - - //Then - assertNotEquals( - mountain1.uuid, - mountain2.uuid, - "Factory providing" - ); - } - - @Test - public void defCache2Test() { - //Given - GcGodComponent DI = Stone.createComponent(GcGodComponent.class); - GcGodExtComponent DIPro = Stone.createComponent(GcGodExtComponent.class); - DIPro.extOf(DI); - - //When - Mountain mountain1 = DI.earth().mountainDefault2Factory(); - Mountain mountain2 = DIPro.earth().mountainDefault2Factory(); - - //Then - assertNotEquals( - mountain1.uuid, - mountain2.uuid, - "Factory providing" - ); - } - - @Test - public void differentMethodDifferentCacheTest() { - //Given - GcGodComponent DI = Stone.createComponent(GcGodComponent.class); - GcGodExtComponent DIPro = Stone.createComponent(GcGodExtComponent.class); - DIPro.extOf(DI); - - //When - Mountain mountainStrong = DI.earth().mountainStrong(); - Mountain mountainSoft = DIPro.earth().mountainSoft(); - - //Then - assertNotEquals( - mountainStrong.uuid, - mountainSoft.uuid - ); - } - - - @Test - public void factoryNotCacheTest() { - //Given - GcGodComponent DI = Stone.createComponent(GcGodComponent.class); - GcGodExtComponent DIPro = Stone.createComponent(GcGodExtComponent.class); - DIPro.extOf(DI); - - //When - Mountain mountain1 = DI.earth().mountainFactory(); - Mountain mountain2 = DIPro.earth().mountainFactory(); - - //Then - assertNotEquals( - mountain1.uuid, - mountain2.uuid - ); - } - - - @Test - public void 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); - - //When - Mountain mountain1 = DI1.earth().mountainStrong(); - Mountain mountain2 = DIPro2.earth().mountainStrong(); - - //Then - assertNotEquals( - 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 new file mode 100644 index 00000000..36546888 --- /dev/null +++ b/tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/cache/EarthCacheMixedTests.kt @@ -0,0 +1,165 @@ +package com.dirgub.klee0kai.stone.text_ext.cache + +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 + fun strongCacheTest() { + //Given + val DI: GcGodComponent = GcGodComponentStoneComponent() + val DIPro: GcGodExtComponent = GcGodExtComponentStoneComponent() + DIPro.extOf(DI) + + //When + val mountain1: Mountain? = DI.earth()!!.mountainStrong() + val mountain2: Mountain? = DIPro.earth()!!.mountainStrong() + + //Then + assertEquals( + mountain1!!.uuid, + mountain2!!.uuid + ) + } + + + @Test + fun softCacheTest() { + //Given + val DI: GcGodComponent = GcGodComponentStoneComponent() + val DIPro: GcGodExtComponent = GcGodExtComponentStoneComponent() + DIPro.extOf(DI) + + //When + val mountain1: Mountain? = DI.earth()!!.mountainSoft() + val mountain2: Mountain? = DIPro.earth()!!.mountainSoft() + + //Then + assertEquals( + mountain1!!.uuid, + mountain2!!.uuid + ) + } + + @Test + fun weakCacheTest() { + //Given + val DI: GcGodComponent = GcGodComponentStoneComponent() + val DIPro: GcGodExtComponent = GcGodExtComponentStoneComponent() + DIPro.extOf(DI) + + //When + val mountain1: Mountain? = DI.earth()!!.mountainWeak() + val mountain2: Mountain? = DIPro.earth()!!.mountainWeak() + + //Then + assertEquals( + mountain1!!.uuid, + mountain2!!.uuid + ) + } + + @Test + fun defCacheTest() { + //Given + val DI: GcGodComponent = GcGodComponentStoneComponent() + val DIPro: GcGodExtComponent = GcGodExtComponentStoneComponent() + DIPro.extOf(DI) + + //When + val mountain1: Mountain? = DI.earth()!!.mountainDefaultFactory() + val mountain2: Mountain? = DIPro.earth()!!.mountainDefaultFactory() + + //Then + assertNotEquals( + mountain1!!.uuid, + mountain2!!.uuid, + "Factory providing" + ) + } + + @Test + fun defCache2Test() { + //Given + val DI: GcGodComponent = GcGodComponentStoneComponent() + val DIPro: GcGodExtComponent = GcGodExtComponentStoneComponent() + DIPro.extOf(DI) + + //When + val mountain1: Mountain? = DI.earth()!!.mountainDefault2Factory() + val mountain2: Mountain? = DIPro.earth()!!.mountainDefault2Factory() + + //Then + assertNotEquals( + mountain1!!.uuid, + mountain2!!.uuid, + "Factory providing" + ) + } + + @Test + fun differentMethodDifferentCacheTest() { + //Given + val DI: GcGodComponent = GcGodComponentStoneComponent() + val DIPro: GcGodExtComponent = GcGodExtComponentStoneComponent() + DIPro.extOf(DI) + + //When + val mountainStrong: Mountain? = DI.earth()!!.mountainStrong() + val mountainSoft: Mountain? = DIPro.earth()!!.mountainSoft() + + //Then + assertNotEquals( + mountainStrong!!.uuid, + mountainSoft!!.uuid + ) + } + + + @Test + fun factoryNotCacheTest() { + //Given + val DI: GcGodComponent = GcGodComponentStoneComponent() + val DIPro: GcGodExtComponent = GcGodExtComponentStoneComponent() + DIPro.extOf(DI) + + //When + val mountain1: Mountain? = DI.earth()!!.mountainFactory() + val mountain2: Mountain? = DIPro.earth()!!.mountainFactory() + + //Then + assertNotEquals( + mountain1!!.uuid, + mountain2!!.uuid + ) + } + + + @Test + fun differentDIDifferentCacheTest() { + //Given + val DI1: GcGodComponent = GcGodComponentStoneComponent() + val DIPro1: GcGodExtComponent = GcGodExtComponentStoneComponent() + DIPro1.extOf(DI1) + val DI2: GcGodComponent = GcGodComponentStoneComponent() + val DIPro2: GcGodExtComponent = GcGodExtComponentStoneComponent() + DIPro2.extOf(DI2) + + //When + val mountain1: Mountain? = DI1.earth()!!.mountainStrong() + val mountain2: Mountain? = DIPro2.earth()!!.mountainStrong() + + //Then + assertNotEquals( + mountain1!!.uuid, + mountain2!!.uuid + ) + } +} 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.java deleted file mode 100644 index d47c737b..00000000 --- a/tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/cache/EarthCacheProMixedTests.java +++ /dev/null @@ -1,168 +0,0 @@ -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 { - - - @Test - public void strongCacheTest() { - //Given - GcGodComponent DI = Stone.createComponent(GcGodComponent.class); - GcGodExtComponent DIPro = Stone.createComponent(GcGodExtComponent.class); - DIPro.extOf(DI); - - //When - Mountain mountain1 = DIPro.earth().mountainStrong(); - Mountain mountain2 = DI.earth().mountainStrong(); - - //Then - assertEquals( - mountain1.uuid, - mountain2.uuid - ); - } - - - @Test - public void softCacheTest() { - //Given - GcGodComponent DI = Stone.createComponent(GcGodComponent.class); - GcGodExtComponent DIPro = Stone.createComponent(GcGodExtComponent.class); - DIPro.extOf(DI); - - //When - Mountain mountain1 = DIPro.earth().mountainSoft(); - Mountain mountain2 = DI.earth().mountainSoft(); - - //Then - assertEquals( - mountain1.uuid, - mountain2.uuid - ); - } - - @Test - public void weakCacheTest() { - //Given - GcGodComponent DI = Stone.createComponent(GcGodComponent.class); - GcGodExtComponent DIPro = Stone.createComponent(GcGodExtComponent.class); - DIPro.extOf(DI); - - //When - Mountain mountain1 = DIPro.earth().mountainWeak(); - Mountain mountain2 = DI.earth().mountainWeak(); - - //Then - assertEquals( - mountain1.uuid, - mountain2.uuid - ); - } - - @Test - public void defCacheTest() { - //Given - GcGodComponent DI = Stone.createComponent(GcGodComponent.class); - GcGodExtComponent DIPro = Stone.createComponent(GcGodExtComponent.class); - DIPro.extOf(DI); - - //When - Mountain mountain1 = DIPro.earth().mountainDefaultFactory(); - Mountain mountain2 = DI.earth().mountainDefaultFactory(); - - //Then - assertNotEquals( - mountain1.uuid, - mountain2.uuid, - "Factory providing" - ); - } - - @Test - public void defCache2Test() { - //Given - GcGodComponent DI = Stone.createComponent(GcGodComponent.class); - GcGodExtComponent DIPro = Stone.createComponent(GcGodExtComponent.class); - DIPro.extOf(DI); - - //When - Mountain mountain1 = DIPro.earth().mountainDefault2Factory(); - Mountain mountain2 = DI.earth().mountainDefault2Factory(); - - //Then - assertNotEquals( - mountain1.uuid, - mountain2.uuid, - "Factory providing" - ); - } - - - @Test - public void differentMethodDifferentCacheTest() { - //Given - GcGodComponent DI = Stone.createComponent(GcGodComponent.class); - GcGodExtComponent DIPro = Stone.createComponent(GcGodExtComponent.class); - DIPro.extOf(DI); - - //When - Mountain mountainStrong = DIPro.earth().mountainStrong(); - Mountain mountainSoft = DI.earth().mountainSoft(); - - //Then - assertNotEquals( - mountainStrong.uuid, - mountainSoft.uuid - ); - } - - - @Test - public void factoryNotCacheTest() { - //Given - GcGodComponent DI = Stone.createComponent(GcGodComponent.class); - GcGodExtComponent DIPro = Stone.createComponent(GcGodExtComponent.class); - DIPro.extOf(DI); - - //When - Mountain mountain1 = DIPro.earth().mountainFactory(); - Mountain mountain2 = DI.earth().mountainFactory(); - - //Then - assertNotEquals( - mountain1.uuid, - mountain2.uuid - ); - } - - - @Test - public void 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); - - //When - Mountain mountain1 = DIPro1.earth().mountainStrong(); - Mountain mountain2 = DI2.earth().mountainStrong(); - - //Then - assertNotEquals( - 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 new file mode 100644 index 00000000..1bae1095 --- /dev/null +++ b/tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/cache/EarthCacheProMixedTests.kt @@ -0,0 +1,167 @@ +package com.dirgub.klee0kai.stone.text_ext.cache + +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 + fun strongCacheTest() { + //Given + val DI: GcGodComponent = GcGodComponentStoneComponent() + val DIPro: GcGodExtComponent = GcGodExtComponentStoneComponent() + DIPro.extOf(DI) + + //When + val mountain1: Mountain? = DIPro.earth()!!.mountainStrong() + val mountain2: Mountain? = DI.earth()!!.mountainStrong() + + //Then + assertEquals( + mountain1!!.uuid, + mountain2!!.uuid + ) + } + + + @Test + fun softCacheTest() { + //Given + val DI: GcGodComponent = GcGodComponentStoneComponent() + val DIPro: GcGodExtComponent = GcGodExtComponentStoneComponent() + DIPro.extOf(DI) + + //When + val mountain1: Mountain? = DIPro.earth()!!.mountainSoft() + val mountain2: Mountain? = DI.earth()!!.mountainSoft() + + //Then + assertEquals( + mountain1!!.uuid, + mountain2!!.uuid + ) + } + + @Test + fun weakCacheTest() { + //Given + val DI: GcGodComponent = GcGodComponentStoneComponent() + val DIPro: GcGodExtComponent = GcGodExtComponentStoneComponent() + DIPro.extOf(DI) + + //When + val mountain1: Mountain? = DIPro.earth()!!.mountainWeak() + val mountain2: Mountain? = DI.earth()!!.mountainWeak() + + //Then + assertEquals( + mountain1!!.uuid, + mountain2!!.uuid + ) + } + + @Test + fun defCacheTest() { + //Given + val DI: GcGodComponent = GcGodComponentStoneComponent() + val DIPro: GcGodExtComponent = GcGodExtComponentStoneComponent() + DIPro.extOf(DI) + + //When + val mountain1: Mountain? = DIPro.earth()!!.mountainDefaultFactory() + val mountain2: Mountain? = DI.earth()!!.mountainDefaultFactory() + + //Then + assertNotEquals( + mountain1!!.uuid, + mountain2!!.uuid, + "Factory providing" + ) + } + + @Test + fun defCache2Test() { + //Given + val DI: GcGodComponent = GcGodComponentStoneComponent() + val DIPro: GcGodExtComponent = GcGodExtComponentStoneComponent() + DIPro.extOf(DI) + + //When + val mountain1: Mountain? = DIPro.earth()!!.mountainDefault2Factory() + val mountain2: Mountain? = DI.earth()!!.mountainDefault2Factory() + + //Then + assertNotEquals( + mountain1!!.uuid, + mountain2!!.uuid, + "Factory providing" + ) + } + + + @Test + fun differentMethodDifferentCacheTest() { + //Given + val DI: GcGodComponent = GcGodComponentStoneComponent() + val DIPro: GcGodExtComponent = GcGodExtComponentStoneComponent() + DIPro.extOf(DI) + + //When + val mountainStrong: Mountain? = DIPro.earth()!!.mountainStrong() + val mountainSoft: Mountain? = DI.earth()!!.mountainSoft() + + //Then + assertNotEquals( + mountainStrong!!.uuid, + mountainSoft!!.uuid + ) + } + + + @Test + fun factoryNotCacheTest() { + //Given + val DI: GcGodComponent = GcGodComponentStoneComponent() + val DIPro: GcGodExtComponent = GcGodExtComponentStoneComponent() + DIPro.extOf(DI) + + //When + val mountain1: Mountain? = DIPro.earth()!!.mountainFactory() + val mountain2: Mountain? = DI.earth()!!.mountainFactory() + + //Then + assertNotEquals( + mountain1!!.uuid, + mountain2!!.uuid + ) + } + + + @Test + fun differentDIDifferentCacheTest() { + //Given + val DI1: GcGodComponent = GcGodComponentStoneComponent() + val DIPro1: GcGodExtComponent = GcGodExtComponentStoneComponent() + DIPro1.extOf(DI1) + val DI2: GcGodComponent = GcGodComponentStoneComponent() + val DIPro2: GcGodExtComponent = GcGodExtComponentStoneComponent() + DIPro2.extOf(DI2) + + //When + val mountain1: Mountain? = DIPro1.earth()!!.mountainStrong() + val mountain2: Mountain? = DI2.earth()!!.mountainStrong() + + //Then + assertNotEquals( + mountain1!!.uuid, + mountain2!!.uuid + ) + } + +} 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.java deleted file mode 100644 index e8a33dd1..00000000 --- a/tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/cache/EarthSwitchCacheAndProTests.java +++ /dev/null @@ -1,96 +0,0 @@ -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 { - - - @Test - public void allToWeakTest() { - //Given - SwitchCacheComponent DI = Stone.createComponent(SwitchCacheComponent.class); - SwitchCacheExtComponent DIPro = Stone.createComponent(SwitchCacheExtComponent.class); - DIPro.extOf(DI); - WeakReference mountain = new WeakReference<>(DIPro.earth().mountainStrong()); - - //When - DI.allWeak(); - System.gc(); - - //Then - assertNull(mountain.get()); - } - - @Test - public void 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()); - - //When - DI.strongToWeak(); - System.gc(); - - //Then - assertNull(mountainStrong.get()); - assertNotNull(mountainSoft.get()); - } - - @Test - public void weakToStrongFewMillisTest() throws InterruptedException { - //Given - SwitchCacheComponent DI = Stone.createComponent(SwitchCacheComponent.class); - SwitchCacheExtComponent DIPro = Stone.createComponent(SwitchCacheExtComponent.class); - DIPro.extOf(DI); - WeakReference mountainWeak = new WeakReference<>(DIPro.earth().mountainWeak()); - - //When - DI.allStrongFewMillis(); - System.gc(); - - //Then: can't GC - assertNotNull(mountainWeak.get()); - - //When: after few millis - sleep(110); - System.gc(); - - //Then: can GC - assertNull(mountainWeak.get()); - } - - - @Test - public void 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()); - - //When - DI.mountainToWeak(); - System.gc(); - - //Then - assertNull(mountain.get()); - assertNotNull(river.get()); - } - - -} 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 new file mode 100644 index 00000000..84bc0210 --- /dev/null +++ b/tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/cache/EarthSwitchCacheAndProTests.kt @@ -0,0 +1,93 @@ +package com.dirgub.klee0kai.stone.text_ext.cache + +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 + fun allToWeakTest() { + //Given + val DI: SwitchCacheComponent = SwitchCacheComponentStoneComponent() + val DIPro: SwitchCacheExtComponent = SwitchCacheExtComponentStoneComponent() + DIPro.extOf(DI) + val mountain = WeakReference(DIPro.earth()!!.mountainStrong()) + + //When + DI.allWeak() + System.gc() + + //Then + assertNull(mountain.get()) + } + + @Test + fun strongToWeakTest() { + //Given + 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() + + //Then + assertNull(mountainStrong.get()) + assertNotNull(mountainSoft.get()) + } + + @Test + @Throws(InterruptedException::class) + fun weakToStrongFewMillisTest() { + //Given + val DI: SwitchCacheComponent = SwitchCacheComponentStoneComponent() + val DIPro: SwitchCacheExtComponent = SwitchCacheExtComponentStoneComponent() + DIPro.extOf(DI) + val mountainWeak = WeakReference(DIPro.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: 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() + + //Then + assertNull(mountain.get()) + assertNotNull(river.get()) + } + +} 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.java deleted file mode 100644 index 4a432c6f..00000000 --- a/tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/cache/EarthSwitchCacheFromProTests.java +++ /dev/null @@ -1,96 +0,0 @@ -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 { - - - @Test - public void allToWeakTest() { - //Given - SwitchCacheComponent DI = Stone.createComponent(SwitchCacheComponent.class); - SwitchCacheExtComponent DIPro = Stone.createComponent(SwitchCacheExtComponent.class); - DIPro.extOf(DI); - WeakReference mountain = new WeakReference<>(DIPro.earth().mountainStrong()); - - //When - DIPro.allWeak(); - System.gc(); - - //Then - assertNull(mountain.get()); - } - - @Test - public void 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()); - - //When - DIPro.strongToWeak(); - System.gc(); - - //Then - assertNull(mountainStrong.get()); - assertNotNull(mountainSoft.get()); - } - - @Test - public void weakToStrongFewMillisTest() throws InterruptedException { - //Given - SwitchCacheComponent DI = Stone.createComponent(SwitchCacheComponent.class); - SwitchCacheExtComponent DIPro = Stone.createComponent(SwitchCacheExtComponent.class); - DIPro.extOf(DI); - WeakReference mountainWeak = new WeakReference<>(DIPro.earth().mountainWeak()); - - //When - DIPro.allStrongFewMillis(); - System.gc(); - - //Then: can't GC - assertNotNull(mountainWeak.get()); - - //When: after few millis - sleep(110); - System.gc(); - - //Then: can GC - assertNull(mountainWeak.get()); - } - - - @Test - public void 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()); - - //When - DIPro.mountainToWeak(); - System.gc(); - - //Then - 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 new file mode 100644 index 00000000..f9ab4eee --- /dev/null +++ b/tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/cache/EarthSwitchCacheFromProTests.kt @@ -0,0 +1,92 @@ +package com.dirgub.klee0kai.stone.text_ext.cache + +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 + fun allToWeakTest() { + //Given + val DI: SwitchCacheComponent? = SwitchCacheComponentStoneComponent() + val DIPro: SwitchCacheExtComponent = SwitchCacheExtComponentStoneComponent() + DIPro.extOf(DI) + val mountain = WeakReference(DIPro.earth()!!.mountainStrong()) + + //When + DIPro.allWeak() + System.gc() + + //Then + assertNull(mountain.get()) + } + + @Test + fun strongToWeakTest() { + //Given + 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() + + //Then + assertNull(mountainStrong.get()) + assertNotNull(mountainSoft.get()) + } + + @Test + @Throws(InterruptedException::class) + fun weakToStrongFewMillisTest() { + //Given + val DI: SwitchCacheComponent = SwitchCacheComponentStoneComponent() + val DIPro: SwitchCacheExtComponent = SwitchCacheExtComponentStoneComponent() + DIPro.extOf(DI) + val mountainWeak = WeakReference(DIPro.earth()!!.mountainWeak()) + + //When + DIPro.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()) + } + + + @org.junit.jupiter.api.Test + fun mountainToWeakTest() { + //Given + 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() + + //Then + assertNull(mountain.get()) + assertNotNull(river.get()) + } +} 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.java deleted file mode 100644 index 6edb163b..00000000 --- a/tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/cache/EarthSwitchCacheFromProtoTests.java +++ /dev/null @@ -1,96 +0,0 @@ -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 { - - - @Test - public void allToWeakTest() { - //Given - SwitchCacheComponent DI = Stone.createComponent(SwitchCacheComponent.class); - SwitchCacheExtComponent DIPro = Stone.createComponent(SwitchCacheExtComponent.class); - DIPro.extOf(DI); - WeakReference mountain = new WeakReference<>(DI.earth().mountainStrong()); - - //When - DIPro.allWeak(); - System.gc(); - - //Then - assertNull(mountain.get()); - } - - @Test - public void 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()); - - //When - DIPro.strongToWeak(); - System.gc(); - - //Then - assertNull(mountainStrong.get()); - assertNotNull(mountainSoft.get()); - } - - @Test - public void weakToStrongFewMillisTest() throws InterruptedException { - //Given - SwitchCacheComponent DI = Stone.createComponent(SwitchCacheComponent.class); - SwitchCacheExtComponent DIPro = Stone.createComponent(SwitchCacheExtComponent.class); - DIPro.extOf(DI); - WeakReference mountainWeak = new WeakReference<>(DI.earth().mountainWeak()); - - //When - DIPro.allStrongFewMillis(); - System.gc(); - - //Then: can't GC - assertNotNull(mountainWeak.get()); - - //When: after few millis - sleep(110); - System.gc(); - - //Then: can GC - assertNull(mountainWeak.get()); - } - - - @Test - public void 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()); - - //When - DIPro.mountainToWeak(); - System.gc(); - - //Then - 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 new file mode 100644 index 00000000..19e11877 --- /dev/null +++ b/tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/cache/EarthSwitchCacheFromProtoTests.kt @@ -0,0 +1,93 @@ +package com.dirgub.klee0kai.stone.text_ext.cache + +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 + fun allToWeakTest() { + //Given + val DI: SwitchCacheComponent = SwitchCacheComponentStoneComponent() + val DIPro: SwitchCacheExtComponent = SwitchCacheExtComponentStoneComponent() + DIPro.extOf(DI) + val mountain = WeakReference(DI.earth()!!.mountainStrong()) + + //When + DIPro.allWeak() + System.gc() + + //Then + assertNull(mountain.get()) + } + + @Test + fun strongToWeakTest() { + //Given + 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() + + //Then + assertNull(mountainStrong.get()) + assertNotNull(mountainSoft.get()) + } + + @Test + @Throws(InterruptedException::class) + fun weakToStrongFewMillisTest() { + //Given + val DI: SwitchCacheComponent = SwitchCacheComponentStoneComponent() + val DIPro: SwitchCacheExtComponent = SwitchCacheExtComponentStoneComponent() + DIPro.extOf(DI) + val mountainWeak = WeakReference(DI.earth()!!.mountainWeak()) + + //When + DIPro.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: 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() + + //Then + assertNull(mountain.get()) + assertNotNull(river.get()) + } + +} 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.java deleted file mode 100644 index daccfc00..00000000 --- a/tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/cache/ExtEarthSwitchCacheTests.java +++ /dev/null @@ -1,79 +0,0 @@ -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 { - - - @Test - public void allToWeakTest() { - //Given - SwitchCacheComponent DI = Stone.createComponent(SwitchCacheComponent.class); - SwitchCacheExtComponent DIPro = Stone.createComponent(SwitchCacheExtComponent.class); - DIPro.extOf(DI); - WeakReference mountain = new WeakReference<>(DIPro.earth().mountainStrong()); - - //When - DIPro.allWeakExt(); - System.gc(); - - //Then - assertNull(mountain.get()); - } - - @Test - public void 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()); - - //When - DIPro.strongToWeakExt(); - System.gc(); - - //Then - assertNull(mountainStrong.get()); - assertNotNull(mountainSoft.get()); - } - - @Test - public void weakToStrongFewMillisTest() throws InterruptedException { - //Given - SwitchCacheComponent DI = Stone.createComponent(SwitchCacheComponent.class); - SwitchCacheExtComponent DIPro = Stone.createComponent(SwitchCacheExtComponent.class); - DIPro.extOf(DI); - WeakReference mountainWeak = new WeakReference<>(DIPro.earth().mountainWeak()); - - //When - DIPro.allStrongFewMillisExt(); - System.gc(); - - //Then: can't GC - assertNotNull(mountainWeak.get()); - - //When: after few millis - sleep(110); - System.gc(); - - //Then: can GC - assertNull(mountainWeak.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 new file mode 100644 index 00000000..1b1c5f85 --- /dev/null +++ b/tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/cache/ExtEarthSwitchCacheTests.kt @@ -0,0 +1,72 @@ +package com.dirgub.klee0kai.stone.text_ext.cache + +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 + fun allToWeakTest() { + //Given + val DI: SwitchCacheComponent = SwitchCacheComponentStoneComponent() + val DIPro: SwitchCacheExtComponent = SwitchCacheExtComponentStoneComponent() + DIPro.extOf(DI) + val mountain = WeakReference(DIPro.earth()!!.mountainStrong()) + + //When + DIPro.allWeakExt() + System.gc() + + //Then + org.junit.jupiter.api.Assertions.assertNull(mountain.get()) + } + + @Test + fun strongToWeakTest() { + //Given + 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() + + //Then + assertNull(mountainStrong.get()) + assertNotNull(mountainSoft.get()) + } + + @Test + @Throws(InterruptedException::class) + fun weakToStrongFewMillisTest() { + //Given + val DI: SwitchCacheComponent = SwitchCacheComponentStoneComponent() + val DIPro: SwitchCacheExtComponent = SwitchCacheExtComponentStoneComponent() + DIPro.extOf(DI) + val mountainWeak = WeakReference(DIPro.earth()!!.mountainWeak()) + + //When + DIPro.allStrongFewMillisExt() + System.gc() + + //Then: can't GC + assertNotNull(mountainWeak.get()) + + //When: after few millis + Thread.sleep(110) + System.gc() + + //Then: can GC + assertNull(mountainWeak.get()) + } +} 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.java deleted file mode 100644 index 4262cc4f..00000000 --- a/tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/gc/EarthLastDayAndProTests.java +++ /dev/null @@ -1,425 +0,0 @@ -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 { - - @Test - void 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()); - - - //When - 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 - )) { - assertNull(ref.get()); - } - } - - @Test - void 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()); - - //When - DI.gcStrong(); - - //Then - for (Reference ref : Arrays.asList( - mountainStrong, mountainWeak, mountainDef, mountainDef2, - riverStrong, riverWeak, riverDef, - desertStrong, desertWeak, desertFactory, - waterFlowStrong, waterFlowWeak, waterFlowDefRef - )) { - assertNull(ref.get()); - } - - for (Reference ref : Arrays.asList( - mountainSoft, - riverSoft, - desertSoft, - waterFlowSoft - )) { - assertNotNull(ref.get()); - } - } - - @Test - void 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()); - - //When - DI.gcSoft(); - - //Then - for (Reference ref : Arrays.asList( - mountainSoft, mountainWeak, mountainDef, mountainDef2, - riverSoft, riverWeak, riverDef, - desertSoft, desertWeak, desertFactory, - waterFlowSoft, waterFlowDefRef, waterFlowWeak - )) { - assertNull(ref.get()); - } - for (Reference ref : Arrays.asList( - mountainStrong, - riverStrong, - desertStrong, - waterFlowStrong - )) { - assertNotNull(ref.get()); - } - } - - @Test - void 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()); - - //When - DI.gcWeak(); - - //Then - for (Reference ref : Arrays.asList( - mountainWeak, mountainDef, mountainDef2, - riverWeak, riverDef, - desertWeak, desertFactory, - waterFlowWeak, waterFlowDefRef - )) { - assertNull(ref.get()); - } - for (Reference ref : Arrays.asList( - mountainStrong, mountainSoft, - riverStrong, riverSoft, - desertStrong, desertSoft, - waterFlowStrong, waterFlowSoft - )) { - assertNotNull(ref.get()); - } - } - - @Test - void 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()); - - //When - DI.gcMountains(); - - //Then - for (Reference ref : Arrays.asList( - mountainStrong, mountainSoft, mountainWeak, mountainDef, mountainDef2, - riverWeak, riverDef, - desertWeak, desertFactory, - waterFlowWeak, waterFlowDefRef - )) { - assertNull(ref.get()); - } - for (Reference ref : Arrays.asList( - riverStrong, riverSoft, - desertStrong, desertSoft, - waterFlowStrong, waterFlowSoft - )) { - assertNotNull(ref.get()); - } - } - - @Test - void 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()); - - //When - DI.gcRivers(); - - //Then - for (Reference ref : Arrays.asList( - mountainWeak, mountainDef, mountainDef2, - riverStrong, riverSoft, riverWeak, riverDef, - desertWeak, desertFactory, - waterFlowStrong, waterFlowSoft, waterFlowDefRef, waterFlowWeak - )) { - assertNull(ref.get()); - } - for (Reference ref : Arrays.asList( - mountainStrong, mountainSoft, - desertStrong, desertSoft - )) { - assertNotNull(ref.get()); - } - } - - @Test - void 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()); - - //When - DI.gcMountainsAndRivers(); - - //Then - for (Reference ref : Arrays.asList( - mountainStrong, mountainSoft, mountainWeak, mountainDef, mountainDef2, - riverStrong, riverSoft, riverWeak, riverDef, - desertFactory, desertWeak, - waterFlowStrong, waterFlowSoft, waterFlowDefRef, waterFlowWeak - )) { - assertNull(ref.get()); - } - - for (Reference ref : Arrays.asList( - desertStrong, desertSoft - )) { - assertNotNull(ref.get()); - } - } - - - @Test - void 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()); - - //When - DI.gcSoftMountains(); - - //Then - for (Reference ref : Arrays.asList( - mountainSoft, mountainWeak, mountainDef, mountainDef2, - riverWeak, riverDef, - desertFactory, desertWeak, - waterFlowWeak, waterFlowDefRef - )) { - assertNull(ref.get()); - } - for (Reference ref : Arrays.asList( - mountainStrong, - riverStrong, riverSoft, - desertStrong, desertSoft, - waterFlowStrong, waterFlowSoft - )) { - assertNotNull(ref.get()); - } - } - - @Test - void 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()); - - //When - DI.gcStrongMountains(); - - //Then - for (Reference ref : Arrays.asList( - mountainStrong, mountainWeak, mountainDef, mountainDef2, - riverWeak, riverDef, - desertFactory, desertWeak, - waterFlowWeak, waterFlowDefRef - )) { - assertNull(ref.get()); - } - for (Reference ref : Arrays.asList( - mountainSoft, - riverStrong, riverSoft, - desertStrong, desertSoft, - waterFlowStrong, waterFlowSoft - )) { - assertNotNull(ref.get()); - } - } - -} 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 new file mode 100644 index 00000000..4f55a343 --- /dev/null +++ b/tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/gc/EarthLastDayAndProTests.kt @@ -0,0 +1,421 @@ +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 + fun gcAllTest() { + //Given + 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() + + //Then + for (ref in listOf( + mountainStrong, mountainSoft, mountainDef2, mountainWeak, mountainDef, + riverStrong, riverSoft, riverWeak, riverDef, + desertStrong, desertSoft, desertWeak, desertFactory, + waterFlowStrong, waterFlowSoft, waterFlowWeak, waterFlowDefRef + )) { + assertNull(ref.get()) + } + } + + @Test + fun gcStrongTest() { + //Given + 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() + + //Then + for (ref in listOf( + mountainStrong, mountainWeak, mountainDef, mountainDef2, + riverStrong, riverWeak, riverDef, + desertStrong, desertWeak, desertFactory, + waterFlowStrong, waterFlowWeak, waterFlowDefRef + )) { + assertNull(ref.get()) + } + + for (ref in listOf( + mountainSoft, + riverSoft, + desertSoft, + waterFlowSoft + )) { + assertNotNull(ref.get()) + } + } + + @Test + fun gcSoftTest() { + //Given + 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() + + //Then + for (ref in listOf( + mountainSoft, mountainWeak, mountainDef, mountainDef2, + riverSoft, riverWeak, riverDef, + desertSoft, desertWeak, desertFactory, + waterFlowSoft, waterFlowDefRef, waterFlowWeak + )) { + assertNull(ref.get()) + } + for (ref in listOf( + mountainStrong, + riverStrong, + desertStrong, + waterFlowStrong + )) { + assertNotNull(ref.get()) + } + } + + @Test + fun gcWeakTest() { + //Given + 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() + + //Then + for (ref in listOf( + mountainWeak, mountainDef, mountainDef2, + riverWeak, riverDef, + desertWeak, desertFactory, + waterFlowWeak, waterFlowDefRef + )) { + assertNull(ref.get()) + } + for (ref in listOf( + mountainStrong, mountainSoft, + riverStrong, riverSoft, + desertStrong, desertSoft, + waterFlowStrong, waterFlowSoft + )) { + assertNotNull(ref.get()) + } + } + + @Test + fun gcMountainTest() { + //Given + 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() + + //Then + for (ref in listOf( + mountainStrong, mountainSoft, mountainWeak, mountainDef, mountainDef2, + riverWeak, riverDef, + desertWeak, desertFactory, + waterFlowWeak, waterFlowDefRef + )) { + assertNull(ref.get()) + } + for (ref in listOf( + riverStrong, riverSoft, + desertStrong, desertSoft, + waterFlowStrong, waterFlowSoft + )) { + assertNotNull(ref.get()) + } + } + + @org.junit.jupiter.api.Test + fun gcRiverTest() { + //Given + 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() + + //Then + for (ref in listOf( + mountainWeak, mountainDef, mountainDef2, + riverStrong, riverSoft, riverWeak, riverDef, + desertWeak, desertFactory, + waterFlowStrong, waterFlowSoft, waterFlowDefRef, waterFlowWeak + )) { + assertNull(ref.get()) + } + for (ref in listOf( + mountainStrong, mountainSoft, + desertStrong, desertSoft + )) { + assertNotNull(ref.get()) + } + } + + @Test + fun gcMountainAndRiverTest() { + //Given + 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() + + //Then + for (ref in listOf( + mountainStrong, mountainSoft, mountainWeak, mountainDef, mountainDef2, + riverStrong, riverSoft, riverWeak, riverDef, + desertFactory, desertWeak, + waterFlowStrong, waterFlowSoft, waterFlowDefRef, waterFlowWeak + )) { + assertNull(ref.get()) + } + + for (ref in listOf( + desertStrong, desertSoft + )) { + assertNotNull(ref.get()) + } + } + + + @Test + fun gcSoftMountainTest() { + //Given + 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() + + //Then + for (ref in listOf( + mountainSoft, mountainWeak, mountainDef, mountainDef2, + riverWeak, riverDef, + desertFactory, desertWeak, + waterFlowWeak, waterFlowDefRef + )) { + assertNull(ref.get()) + } + for (ref in listOf( + mountainStrong, + riverStrong, riverSoft, + desertStrong, desertSoft, + waterFlowStrong, waterFlowSoft + )) { + assertNotNull(ref.get()) + } + } + + @Test + fun gcStrongMountainTest() { + //Given + 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() + + //Then + for (ref in listOf( + mountainStrong, mountainWeak, mountainDef, mountainDef2, + riverWeak, riverDef, + desertFactory, desertWeak, + waterFlowWeak, waterFlowDefRef + )) { + assertNull(ref.get()) + } + for (ref in listOf( + mountainSoft, + riverStrong, riverSoft, + desertStrong, desertSoft, + waterFlowStrong, waterFlowSoft + )) { + assertNotNull(ref.get()) + } + } + +} 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.java deleted file mode 100644 index 23f4e5f5..00000000 --- a/tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/gc/EarthLastDayFromProTests.java +++ /dev/null @@ -1,425 +0,0 @@ -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 { - - @Test - void 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()); - - - //When - 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 - )) { - assertNull(ref.get()); - } - } - - @Test - void 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()); - - //When - DIPro.gcStrong(); - - //Then - for (Reference ref : Arrays.asList( - mountainStrong, mountainWeak, mountainDef, mountainDef2, - riverStrong, riverWeak, riverDef, - desertStrong, desertWeak, desertFactory, - waterFlowStrong, waterFlowWeak, waterFlowDefRef - )) { - assertNull(ref.get()); - } - - for (Reference ref : Arrays.asList( - mountainSoft, - riverSoft, - desertSoft, - waterFlowSoft - )) { - assertNotNull(ref.get()); - } - } - - @Test - void 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()); - - //When - DIPro.gcSoft(); - - //Then - for (Reference ref : Arrays.asList( - mountainSoft, mountainWeak, mountainDef, mountainDef2, - riverSoft, riverWeak, riverDef, - desertSoft, desertWeak, desertFactory, - waterFlowSoft, waterFlowDefRef, waterFlowWeak - )) { - assertNull(ref.get()); - } - for (Reference ref : Arrays.asList( - mountainStrong, - riverStrong, - desertStrong, - waterFlowStrong - )) { - assertNotNull(ref.get()); - } - } - - @Test - void 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()); - - //When - DIPro.gcWeak(); - - //Then - for (Reference ref : Arrays.asList( - mountainWeak, mountainDef, mountainDef2, - riverWeak, riverDef, - desertWeak, desertFactory, - waterFlowWeak, waterFlowDefRef - )) { - assertNull(ref.get()); - } - for (Reference ref : Arrays.asList( - mountainStrong, mountainSoft, - riverStrong, riverSoft, - desertStrong, desertSoft, - waterFlowStrong, waterFlowSoft - )) { - assertNotNull(ref.get()); - } - } - - @Test - void 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()); - - //When - DIPro.gcMountains(); - - //Then - for (Reference ref : Arrays.asList( - mountainStrong, mountainSoft, mountainWeak, mountainDef, mountainDef2, - riverWeak, riverDef, - desertWeak, desertFactory, - waterFlowWeak, waterFlowDefRef - )) { - assertNull(ref.get()); - } - for (Reference ref : Arrays.asList( - riverStrong, riverSoft, - desertStrong, desertSoft, - waterFlowStrong, waterFlowSoft - )) { - assertNotNull(ref.get()); - } - } - - @Test - void 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()); - - //When - DIPro.gcRivers(); - - //Then - for (Reference ref : Arrays.asList( - mountainWeak, mountainDef, mountainDef2, - riverStrong, riverSoft, riverWeak, riverDef, - desertWeak, desertFactory, - waterFlowStrong, waterFlowSoft, waterFlowDefRef, waterFlowWeak - )) { - assertNull(ref.get()); - } - for (Reference ref : Arrays.asList( - mountainStrong, mountainSoft, - desertStrong, desertSoft - )) { - assertNotNull(ref.get()); - } - } - - @Test - void 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()); - - //When - DIPro.gcMountainsAndRivers(); - - //Then - for (Reference ref : Arrays.asList( - mountainStrong, mountainSoft, mountainWeak, mountainDef, mountainDef2, - riverStrong, riverSoft, riverWeak, riverDef, - desertFactory, desertWeak, - waterFlowStrong, waterFlowSoft, waterFlowDefRef, waterFlowWeak - )) { - assertNull(ref.get()); - } - - for (Reference ref : Arrays.asList( - desertStrong, desertSoft - )) { - assertNotNull(ref.get()); - } - } - - - @Test - void 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()); - - //When - DIPro.gcSoftMountains(); - - //Then - for (Reference ref : Arrays.asList( - mountainSoft, mountainWeak, mountainDef, mountainDef2, - riverWeak, riverDef, - desertFactory, desertWeak, - waterFlowWeak, waterFlowDefRef - )) { - assertNull(ref.get()); - } - for (Reference ref : Arrays.asList( - mountainStrong, - riverStrong, riverSoft, - desertStrong, desertSoft, - waterFlowStrong, waterFlowSoft - )) { - assertNotNull(ref.get()); - } - } - - @Test - void 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()); - - //When - DIPro.gcStrongMountains(); - - //Then - for (Reference ref : Arrays.asList( - mountainStrong, mountainWeak, mountainDef, mountainDef2, - riverWeak, riverDef, - desertFactory, desertWeak, - waterFlowWeak, waterFlowDefRef - )) { - assertNull(ref.get()); - } - for (Reference ref : Arrays.asList( - mountainSoft, - riverStrong, riverSoft, - desertStrong, desertSoft, - waterFlowStrong, waterFlowSoft - )) { - 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 new file mode 100644 index 00000000..5e753490 --- /dev/null +++ b/tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/gc/EarthLastDayFromProTests.kt @@ -0,0 +1,422 @@ +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 + fun gcAllTest() { + //Given + 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() + + //Then + for (ref in listOf( + mountainStrong, mountainSoft, mountainDef2, mountainWeak, mountainDef, + riverStrong, riverSoft, riverWeak, riverDef, + desertStrong, desertSoft, desertWeak, desertFactory, + waterFlowStrong, waterFlowSoft, waterFlowWeak, waterFlowDefRef + )) { + assertNull(ref.get()) + } + } + + @Test + fun gcStrongTest() { + //Given + 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() + + //Then + for (ref in listOf( + mountainStrong, mountainWeak, mountainDef, mountainDef2, + riverStrong, riverWeak, riverDef, + desertStrong, desertWeak, desertFactory, + waterFlowStrong, waterFlowWeak, waterFlowDefRef + )) { + assertNull(ref.get()) + } + + for (ref in listOf( + mountainSoft, + riverSoft, + desertSoft, + waterFlowSoft + )) { + assertNotNull(ref.get()) + } + } + + @Test + fun gcSoftTest() { + //Given + 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() + + //Then + for (ref in listOf( + mountainSoft, mountainWeak, mountainDef, mountainDef2, + riverSoft, riverWeak, riverDef, + desertSoft, desertWeak, desertFactory, + waterFlowSoft, waterFlowDefRef, waterFlowWeak + )) { + assertNull(ref.get()) + } + for (ref in listOf( + mountainStrong, + riverStrong, + desertStrong, + waterFlowStrong + )) { + assertNotNull(ref.get()) + } + } + + @Test + fun gcWeakTest() { + //Given + 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() + + //Then + for (ref in listOf( + mountainWeak, mountainDef, mountainDef2, + riverWeak, riverDef, + desertWeak, desertFactory, + waterFlowWeak, waterFlowDefRef + )) { + assertNull(ref.get()) + } + for (ref in listOf( + mountainStrong, mountainSoft, + riverStrong, riverSoft, + desertStrong, desertSoft, + waterFlowStrong, waterFlowSoft + )) { + assertNotNull(ref.get()) + } + } + + @Test + fun gcMountainTest() { + //Given + 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() + + //Then + for (ref in listOf( + mountainStrong, mountainSoft, mountainWeak, mountainDef, mountainDef2, + riverWeak, riverDef, + desertWeak, desertFactory, + waterFlowWeak, waterFlowDefRef + )) { + assertNull(ref.get()) + } + for (ref in listOf( + riverStrong, riverSoft, + desertStrong, desertSoft, + waterFlowStrong, waterFlowSoft + )) { + assertNotNull(ref.get()) + } + } + + @Test + fun gcRiverTest() { + //Given + 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() + + //Then + for (ref in listOf( + mountainWeak, mountainDef, mountainDef2, + riverStrong, riverSoft, riverWeak, riverDef, + desertWeak, desertFactory, + waterFlowStrong, waterFlowSoft, waterFlowDefRef, waterFlowWeak + )) { + assertNull(ref.get()) + } + for (ref in listOf( + mountainStrong, mountainSoft, + desertStrong, desertSoft + )) { + assertNotNull(ref.get()) + } + } + + @Test + fun gcMountainAndRiverTest() { + //Given + 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() + + //Then + for (ref in listOf( + mountainStrong, mountainSoft, mountainWeak, mountainDef, mountainDef2, + riverStrong, riverSoft, riverWeak, riverDef, + desertFactory, desertWeak, + waterFlowStrong, waterFlowSoft, waterFlowDefRef, waterFlowWeak + )) { + assertNull(ref.get()) + } + + for (ref in listOf( + desertStrong, desertSoft + )) { + assertNotNull(ref.get()) + } + } + + + @Test + fun gcSoftMountainTest() { + //Given + 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() + + //Then + for (ref in listOf( + mountainSoft, mountainWeak, mountainDef, mountainDef2, + riverWeak, riverDef, + desertFactory, desertWeak, + waterFlowWeak, waterFlowDefRef + )) { + assertNull(ref.get()) + } + for (ref in listOf( + mountainStrong, + riverStrong, riverSoft, + desertStrong, desertSoft, + waterFlowStrong, waterFlowSoft + )) { + assertNotNull(ref.get()) + } + } + + @Test + fun gcStrongMountainTest() { + //Given + 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() + + //Then + for (ref in listOf( + mountainStrong, mountainWeak, mountainDef, mountainDef2, + riverWeak, riverDef, + desertFactory, desertWeak, + waterFlowWeak, waterFlowDefRef + )) { + assertNull(ref.get()) + } + for (ref in listOf( + mountainSoft, + riverStrong, riverSoft, + desertStrong, desertSoft, + waterFlowStrong, waterFlowSoft + )) { + assertNotNull(ref.get()) + } + } + +} 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.java deleted file mode 100644 index 8fd19555..00000000 --- a/tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/gc/ExtEarthLastDayTests.java +++ /dev/null @@ -1,380 +0,0 @@ -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 ExtEarthLastDayTests { - - @Test - void 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()); - - - //When - 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 - )) { - assertNull(ref.get()); - } - } - - @Test - void 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()); - - //When - DIPro.gcStrongExt(); - - //Then - for (Reference ref : Arrays.asList( - mountainStrong, mountainWeak, mountainDef, mountainDef2, - riverStrong, riverWeak, riverDef, - desertStrong, desertWeak, desertFactory, - waterFlowStrong, waterFlowWeak, waterFlowDefRef - )) { - assertNull(ref.get()); - } - - for (Reference ref : Arrays.asList( - mountainSoft, - riverSoft, - desertSoft, - waterFlowSoft - )) { - assertNotNull(ref.get()); - } - } - - @Test - void 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()); - - //When - DIPro.gcSoftExt(); - - //Then - for (Reference ref : Arrays.asList( - mountainSoft, mountainWeak, mountainDef, mountainDef2, - riverSoft, riverWeak, riverDef, - desertSoft, desertWeak, desertFactory, - waterFlowSoft, waterFlowDefRef, waterFlowWeak - )) { - assertNull(ref.get()); - } - for (Reference ref : Arrays.asList( - mountainStrong, - riverStrong, - desertStrong, - waterFlowStrong - )) { - assertNotNull(ref.get()); - } - } - - @Test - void 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()); - - //When - DIPro.gcWeakExt(); - - //Then - for (Reference ref : Arrays.asList( - mountainWeak, mountainDef, mountainDef2, - riverWeak, riverDef, - desertWeak, desertFactory, - waterFlowWeak, waterFlowDefRef - )) { - assertNull(ref.get()); - } - for (Reference ref : Arrays.asList( - mountainStrong, mountainSoft, - riverStrong, riverSoft, - desertStrong, desertSoft, - waterFlowStrong, waterFlowSoft - )) { - assertNotNull(ref.get()); - } - } - - @Test - void 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()); - - //When - DIPro.gcMountainsExt(); - - //Then - for (Reference ref : Arrays.asList( - mountainStrong, mountainSoft, mountainWeak, mountainDef, mountainDef2, - riverWeak, riverDef, - desertWeak, desertFactory, - waterFlowWeak, waterFlowDefRef - )) { - assertNull(ref.get()); - } - for (Reference ref : Arrays.asList( - riverStrong, riverSoft, - desertStrong, desertSoft, - waterFlowStrong, waterFlowSoft - )) { - assertNotNull(ref.get()); - } - } - - @Test - void 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()); - - //When - DIPro.gcRiversExt(); - - //Then - for (Reference ref : Arrays.asList( - mountainWeak, mountainDef, mountainDef2, - riverStrong, riverSoft, riverWeak, riverDef, - desertWeak, desertFactory, - waterFlowStrong, waterFlowSoft, waterFlowDefRef, waterFlowWeak - )) { - assertNull(ref.get()); - } - for (Reference ref : Arrays.asList( - mountainStrong, mountainSoft, - desertStrong, desertSoft - )) { - assertNotNull(ref.get()); - } - } - - @Test - void 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()); - - //When - DIPro.gcSoftMountainsExt(); - - //Then - for (Reference ref : Arrays.asList( - mountainSoft, mountainWeak, mountainDef, mountainDef2, - riverWeak, riverDef, - desertFactory, desertWeak, - waterFlowWeak, waterFlowDefRef - )) { - assertNull(ref.get()); - } - for (Reference ref : Arrays.asList( - mountainStrong, - riverStrong, riverSoft, - desertStrong, desertSoft, - waterFlowStrong, waterFlowSoft - )) { - assertNotNull(ref.get()); - } - } - - @Test - void 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()); - - //When - DIPro.gcStrongMountainsExt(); - - //Then - for (Reference ref : Arrays.asList( - mountainStrong, mountainWeak, mountainDef, mountainDef2, - riverWeak, riverDef, - desertFactory, desertWeak, - waterFlowWeak, waterFlowDefRef - )) { - assertNull(ref.get()); - } - for (Reference ref : Arrays.asList( - mountainSoft, - riverStrong, riverSoft, - desertStrong, desertSoft, - waterFlowStrong, waterFlowSoft - )) { - assertNotNull(ref.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 new file mode 100644 index 00000000..2444f987 --- /dev/null +++ b/tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/gc/ExtEarthLastDayTests.kt @@ -0,0 +1,378 @@ +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 ExtEarthLastDayTests { + + + @Test + fun gcAllTest() { + //Given + 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() + + //Then + for (ref in listOf( + mountainStrong, mountainSoft, mountainDef2, mountainWeak, mountainDef, + riverStrong, riverSoft, riverWeak, riverDef, + desertStrong, desertSoft, desertWeak, desertFactory, + waterFlowStrong, waterFlowSoft, waterFlowWeak, waterFlowDefRef + )) { + assertNull(ref.get()) + } + } + + @Test + fun gcStrongTest() { + //Given + 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() + + //Then + for (ref in listOf( + mountainStrong, mountainWeak, mountainDef, mountainDef2, + riverStrong, riverWeak, riverDef, + desertStrong, desertWeak, desertFactory, + waterFlowStrong, waterFlowWeak, waterFlowDefRef + )) { + assertNull(ref.get()) + } + + for (ref in listOf( + mountainSoft, + riverSoft, + desertSoft, + waterFlowSoft + )) { + assertNotNull(ref.get()) + } + } + + @Test + fun gcSoftTest() { + //Given + 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() + + //Then + for (ref in listOf( + mountainSoft, mountainWeak, mountainDef, mountainDef2, + riverSoft, riverWeak, riverDef, + desertSoft, desertWeak, desertFactory, + waterFlowSoft, waterFlowDefRef, waterFlowWeak + )) { + assertNull(ref.get()) + } + for (ref in listOf( + mountainStrong, + riverStrong, + desertStrong, + waterFlowStrong + )) { + assertNotNull(ref.get()) + } + } + + @Test + fun gcWeakTest() { + //Given + 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() + + //Then + for (ref in listOf( + mountainWeak, mountainDef, mountainDef2, + riverWeak, riverDef, + desertWeak, desertFactory, + waterFlowWeak, waterFlowDefRef + )) { + assertNull(ref.get()) + } + for (ref in listOf( + mountainStrong, mountainSoft, + riverStrong, riverSoft, + desertStrong, desertSoft, + waterFlowStrong, waterFlowSoft + )) { + assertNotNull(ref.get()) + } + } + + @Test + fun gcMountainTest() { + //Given + 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() + + //Then + for (ref in listOf( + mountainStrong, mountainSoft, mountainWeak, mountainDef, mountainDef2, + riverWeak, riverDef, + desertWeak, desertFactory, + waterFlowWeak, waterFlowDefRef + )) { + assertNull(ref.get()) + } + for (ref in listOf( + riverStrong, riverSoft, + desertStrong, desertSoft, + waterFlowStrong, waterFlowSoft + )) { + assertNotNull(ref.get()) + } + } + + @Test + fun gcRiverTest() { + //Given + 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() + + //Then + for (ref in listOf( + mountainWeak, mountainDef, mountainDef2, + riverStrong, riverSoft, riverWeak, riverDef, + desertWeak, desertFactory, + waterFlowStrong, waterFlowSoft, waterFlowDefRef, waterFlowWeak + )) { + assertNull(ref.get()) + } + for (ref in listOf( + mountainStrong, mountainSoft, + desertStrong, desertSoft + )) { + assertNotNull(ref.get()) + } + } + + @Test + fun gcSoftMountainTest() { + //Given + 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() + + //Then + for (ref in listOf( + mountainSoft, mountainWeak, mountainDef, mountainDef2, + riverWeak, riverDef, + desertFactory, desertWeak, + waterFlowWeak, waterFlowDefRef + )) { + assertNull(ref.get()) + } + for (ref in listOf( + mountainStrong, + riverStrong, riverSoft, + desertStrong, desertSoft, + waterFlowStrong, waterFlowSoft + )) { + assertNotNull(ref.get()) + } + } + + @Test + fun gcStrongMountainTest() { + //Given + 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() + + //Then + for (ref in listOf( + mountainStrong, mountainWeak, mountainDef, mountainDef2, + riverWeak, riverDef, + desertFactory, desertWeak, + waterFlowWeak, waterFlowDefRef + )) { + assertNull(ref.get()) + } + for (ref in listOf( + mountainSoft, + riverStrong, riverSoft, + desertStrong, desertSoft, + waterFlowStrong, waterFlowSoft + )) { + assertNotNull(ref.get()) + } + } + +} 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.java deleted file mode 100644 index a2862a4d..00000000 --- a/tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/identifiers/GoodPhoneInjectExtTests.java +++ /dev/null @@ -1,114 +0,0 @@ -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 static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertTrue; - -public class GoodPhoneInjectExtTests { - - - @Test - @Disabled("https://github.com/klee0kai/stone/issues/42") - public void createdIsReusableTest() { - //Given - PhoneComponent DI = Stone.createComponent(PhoneComponent.class); - GoodPhone goodPhone1 = new GoodPhone(); - DI.inject(goodPhone1, goodPhone1.lifeCycleOwner, new DataStorageSize("120GB"), new 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")); - - //Then - assertEquals(goodPhone1.ram.uuid, goodPhone2.ram.uuid); - assertTrue(goodPhone1.ram instanceof DDR3Ram); - } - - - @Test - public void createGoodPhoneFromProtoTest() { - //Given - PhoneComponent DI = Stone.createComponent(PhoneComponent.class); - PhoneExtComponent DIPro = Stone.createComponent(PhoneExtComponent.class); - DIPro.extOf(DI); - - GoodPhone goodPhone = new GoodPhone(); - - //When - DI.inject(goodPhone, goodPhone.lifeCycleOwner, new DataStorageSize("120GB"), new RamSize("8GB")); - - //Then - assertEquals("120GB", goodPhone.dataStorage.size); - assertEquals("8GB", goodPhone.ram.size); - assertTrue(goodPhone.ram instanceof DDR3Ram); - } - - - @Test - public void createGoodPhoneFromProTest() { - //Given - PhoneComponent DI = Stone.createComponent(PhoneComponent.class); - PhoneExtComponent DIPro = Stone.createComponent(PhoneExtComponent.class); - DIPro.extOf(DI); - - GoodPhone goodPhone = new GoodPhone(); - - //When - DIPro.inject(goodPhone, goodPhone.lifeCycleOwner, new DataStorageSize("120GB"), new RamSize("8GB")); - - //Then - assertEquals("120GB", goodPhone.dataStorage.size); - assertEquals("8GB", goodPhone.ram.size); - assertTrue(goodPhone.ram instanceof DDR3Ram); - } - - - @Test - public void createGoodPhoneFromProExtTest() { - //Given - PhoneComponent DI = Stone.createComponent(PhoneComponent.class); - PhoneExtComponent DIPro = Stone.createComponent(PhoneExtComponent.class); - DIPro.extOf(DI); - GoodPhone goodPhone = new GoodPhone(); - - //When - DIPro.injectExt(goodPhone, goodPhone.lifeCycleOwner, new DataStorageSize("120GB"), new RamSize("8GB")); - - //Then - assertEquals("120GB", goodPhone.dataStorage.size); - assertEquals("8GB", goodPhone.ram.size); - assertTrue(goodPhone.ram instanceof DDR3Ram); - } - - - @Test - public void 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(); - - - //When - DI.inject(goodPhone1, goodPhone1.lifeCycleOwner, new DataStorageSize("120GB"), new RamSize("8GB")); - DIPro.inject(goodPhone2, goodPhone2.lifeCycleOwner, new DataStorageSize("120GB"), new RamSize("8GB")); - - //Then - assertEquals(goodPhone1.ram.uuid, goodPhone2.ram.uuid); - assertTrue(goodPhone1.ram instanceof DDR3Ram); - } - -} 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 new file mode 100644 index 00000000..363a10c1 --- /dev/null +++ b/tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/identifiers/GoodPhoneInjectExtTests.kt @@ -0,0 +1,114 @@ +package com.dirgub.klee0kai.stone.text_ext.identifiers + +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 + +class GoodPhoneInjectExtTests { + + + @Test + @Disabled("https://github.com/klee0kai/stone/issues/42") + fun createdIsReusableTest() { + //Given + val DI: PhoneComponent = PhoneComponentStoneComponent() + val goodPhone1 = GoodPhone() + DI.inject(goodPhone1, goodPhone1.lifeCycleOwner, DataStorageSize("120GB"), RamSize("8GB")) + + //When + 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 is DDR3Ram) + } + + + @Test + fun createGoodPhoneFromProtoTest() { + //Given + val DI: PhoneComponent = PhoneComponentStoneComponent() + val DIPro: PhoneExtComponent = PhoneExtComponentStoneComponent() + DIPro.extOf(DI) + + val goodPhone = GoodPhone() + + //When + DI.inject(goodPhone, goodPhone.lifeCycleOwner, DataStorageSize("120GB"), RamSize("8GB")) + + //Then + assertEquals("120GB", goodPhone.dataStorage!!.size) + assertEquals("8GB", goodPhone.ram!!.size) + assertTrue(goodPhone.ram is DDR3Ram) + } + + + @Test + fun createGoodPhoneFromProTest() { + //Given + val DI: PhoneComponent = PhoneComponentStoneComponent() + val DIPro: PhoneExtComponent = PhoneExtComponentStoneComponent() + DIPro.extOf(DI) + + val goodPhone = GoodPhone() + + //When + DIPro.inject(goodPhone, goodPhone.lifeCycleOwner, DataStorageSize("120GB"), RamSize("8GB")) + + //Then + assertEquals("120GB", goodPhone.dataStorage!!.size) + assertEquals("8GB", goodPhone.ram!!.size) + assertTrue(goodPhone.ram is DDR3Ram) + } + + + @Test + fun createGoodPhoneFromProExtTest() { + //Given + val DI: PhoneComponent = PhoneComponentStoneComponent() + val DIPro: PhoneExtComponent = PhoneExtComponentStoneComponent() + DIPro.extOf(DI) + val goodPhone = GoodPhone() + + //When + DIPro.injectExt(goodPhone, goodPhone.lifeCycleOwner, DataStorageSize("120GB"), RamSize("8GB")) + + //Then + assertEquals("120GB", goodPhone.dataStorage!!.size) + assertEquals("8GB", goodPhone.ram!!.size) + assertTrue(goodPhone.ram is DDR3Ram) + } + + + @Test + fun cacheInjectedPhoneTest() { + //Given + val DI: PhoneComponent = PhoneComponentStoneComponent() + val DIPro: PhoneExtComponent = PhoneExtComponentStoneComponent() + DIPro.extOf(DI) + val goodPhone1 = GoodPhone() + val goodPhone2 = GoodPhone() + + + //When + 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 is DDR3Ram) + } + +} 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.java deleted file mode 100644 index 9ced5c86..00000000 --- a/tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/identifiers/TechFactoryComponentFromProTests.java +++ /dev/null @@ -1,118 +0,0 @@ -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 { - - @Test - public void nonArgProvideTest() { - //Given - TechFactoryComponent DI = Stone.createComponent(TechFactoryComponent.class); - TechFactoryExtComponent DIPro = Stone.createComponent(TechFactoryExtComponent.class); - DIPro.extOf(DI); - - //When - Ram ram = DIPro.ram(); - - //Then - assertEquals("default", ram.size); - assertTrue(ram instanceof DDR3Ram); - } - - @Test - public void singleArgProvideTest() { - //Given - TechFactoryComponent DI = Stone.createComponent(TechFactoryComponent.class); - TechFactoryExtComponent DIPro = Stone.createComponent(TechFactoryExtComponent.class); - DIPro.extOf(DI); - - - //When - Ram ram = DIPro.ram(new RamSize("4G")); - - //Then - assertEquals("4G", ram.size); - assertTrue(ram instanceof DDR3Ram); - } - - - @Test - public void nullGenerateArgProvideTest() { - //Given - TechFactoryComponent DI = Stone.createComponent(TechFactoryComponent.class); - TechFactoryExtComponent DIPro = Stone.createComponent(TechFactoryExtComponent.class); - DIPro.extOf(DI); - - //When - OperationSystem os = DIPro.phoneOs(); - - //Then: should pass null missing args - assertNull(os.phoneOsType); // missing args - assertEquals("default", os.version.version); // default from constructor - } - - @Test - public void coupleArgsProvideTest() { - //Given - TechFactoryComponent DI = Stone.createComponent(TechFactoryComponent.class); - TechFactoryExtComponent DIPro = Stone.createComponent(TechFactoryExtComponent.class); - DIPro.extOf(DI); - - //When - OperationSystem os = DIPro.phoneOs(PhoneOsType.Ios, new PhoneOsVersion("11")); - - //Then - assertEquals(PhoneOsType.Ios, os.phoneOsType); - assertEquals("11", os.version.version); - } - - - @Test - public void differentCreateTest() { - //Given - TechFactoryComponent DI = Stone.createComponent(TechFactoryComponent.class); - TechFactoryExtComponent DIPro = Stone.createComponent(TechFactoryExtComponent.class); - DIPro.extOf(DI); - - //When - Ram ram8Gb = DIPro.ram(new RamSize("8GB")); - Ram ram8Gb2 = DIPro.ram(new RamSize("8GB")); - - //Then: created components are different - assertEquals("8GB", ram8Gb.size); - assertNotEquals(ram8Gb.uuid, ram8Gb2.uuid); - assertTrue(ram8Gb instanceof DDR3Ram); - assertTrue(ram8Gb2 instanceof DDR3Ram); - } - - - @Test - public void enumDifferentTest() { - //Given - TechFactoryComponent DI = Stone.createComponent(TechFactoryComponent.class); - TechFactoryExtComponent DIPro = Stone.createComponent(TechFactoryExtComponent.class); - DIPro.extOf(DI); - - //When - OperationSystem android = DIPro.phoneOs(PhoneOsType.Android); - OperationSystem android2 = DIPro.phoneOs(PhoneOsType.Android); - OperationSystem osNull = DIPro.phoneOs(null); - - //Then: created components are different - 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/TechFactoryComponentFromProTests.kt b/tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/identifiers/TechFactoryComponentFromProTests.kt new file mode 100644 index 00000000..1c6d8253 --- /dev/null +++ b/tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/identifiers/TechFactoryComponentFromProTests.kt @@ -0,0 +1,117 @@ +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 + fun nonArgProvideTest() { + //Given + val DI: TechFactoryComponent = TechFactoryComponentStoneComponent() + val DIPro: TechFactoryExtComponent = TechFactoryExtComponentStoneComponent() + DIPro.extOf(DI) + + //When + val ram: Ram? = DIPro.ram() + + //Then + assertEquals("default", ram!!.size) + assertTrue(ram is DDR3Ram) + } + + @Test + fun singleArgProvideTest() { + //Given + val DI: TechFactoryComponent = TechFactoryComponentStoneComponent() + val DIPro: TechFactoryExtComponent = TechFactoryExtComponentStoneComponent() + DIPro.extOf(DI) + + + //When + val ram: Ram? = DIPro.ram(RamSize("4G")) + + //Then + assertEquals("4G", ram!!.size) + assertTrue(ram is DDR3Ram) + } + + + @Test + fun nullGenerateArgProvideTest() { + //Given + val DI: TechFactoryComponent = TechFactoryComponentStoneComponent() + val DIPro: TechFactoryExtComponent = TechFactoryExtComponentStoneComponent() + DIPro.extOf(DI) + + //When + val os: OperationSystem? = DIPro.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: TechFactoryComponent = TechFactoryComponentStoneComponent() + val DIPro: TechFactoryExtComponent = TechFactoryExtComponentStoneComponent() + DIPro.extOf(DI) + + //When + val os: OperationSystem? = DIPro.phoneOs(PhoneOsType.Ios, PhoneOsVersion("11")) + + //Then + assertEquals(PhoneOsType.Ios, os!!.phoneOsType) + assertEquals("11", os.version!!.version) + } + + + @Test + fun differentCreateTest() { + //Given + val DI: TechFactoryComponent = TechFactoryComponentStoneComponent() + val DIPro: TechFactoryExtComponent = TechFactoryExtComponentStoneComponent() + DIPro.extOf(DI) + + //When + 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 is DDR3Ram) + assertTrue(ram8Gb2 is DDR3Ram) + } + + + @Test + fun enumDifferentTest() { + //Given + val DI = TechFactoryComponentStoneComponent() + val DIPro: TechFactoryExtComponent = TechFactoryExtComponentStoneComponent() + DIPro.extOf(DI) + + //When + 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) + } +} 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.java deleted file mode 100644 index 6c3570db..00000000 --- a/tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/identifiers/TechFactoryComponentOverriddenTests.java +++ /dev/null @@ -1,118 +0,0 @@ -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 { - - @Test - public void nonArgProvideTest() { - //Given - TechFactoryComponent DI = Stone.createComponent(TechFactoryComponent.class); - TechFactoryExtComponent DIPro = Stone.createComponent(TechFactoryExtComponent.class); - DIPro.extOf(DI); - - //When - Ram ram = DI.ram(); - - //Then - assertEquals("default", ram.size); - assertTrue(ram instanceof DDR3Ram); - } - - @Test - public void singleArgProvideTest() { - //Given - TechFactoryComponent DI = Stone.createComponent(TechFactoryComponent.class); - TechFactoryExtComponent DIPro = Stone.createComponent(TechFactoryExtComponent.class); - DIPro.extOf(DI); - - - //When - Ram ram = DI.ram(new RamSize("4G")); - - //Then - assertEquals("4G", ram.size); - assertTrue(ram instanceof DDR3Ram); - } - - - @Test - public void nullGenerateArgProvideTest() { - //Given - TechFactoryComponent DI = Stone.createComponent(TechFactoryComponent.class); - TechFactoryExtComponent DIPro = Stone.createComponent(TechFactoryExtComponent.class); - DIPro.extOf(DI); - - //When - OperationSystem os = DI.phoneOs(); - - //Then: should pass null missing args - assertNull(os.phoneOsType); // missing args - assertEquals("default", os.version.version); // default from constructor - } - - @Test - public void coupleArgsProvideTest() { - //Given - TechFactoryComponent DI = Stone.createComponent(TechFactoryComponent.class); - TechFactoryExtComponent DIPro = Stone.createComponent(TechFactoryExtComponent.class); - DIPro.extOf(DI); - - //When - OperationSystem os = DI.phoneOs(PhoneOsType.Ios, new PhoneOsVersion("11")); - - //Then - assertEquals(PhoneOsType.Ios, os.phoneOsType); - assertEquals("11", os.version.version); - } - - - @Test - public void differentCreateTest() { - //Given - TechFactoryComponent DI = Stone.createComponent(TechFactoryComponent.class); - TechFactoryExtComponent DIPro = Stone.createComponent(TechFactoryExtComponent.class); - DIPro.extOf(DI); - - //When - Ram ram8Gb = DI.ram(new RamSize("8GB")); - Ram ram8Gb2 = DI.ram(new RamSize("8GB")); - - //Then: created components are different - assertEquals("8GB", ram8Gb.size); - assertNotEquals(ram8Gb.uuid, ram8Gb2.uuid); - assertTrue(ram8Gb instanceof DDR3Ram); - assertTrue(ram8Gb2 instanceof DDR3Ram); - } - - - @Test - public void enumDifferentTest() { - //Given - TechFactoryComponent DI = Stone.createComponent(TechFactoryComponent.class); - TechFactoryExtComponent DIPro = Stone.createComponent(TechFactoryExtComponent.class); - DIPro.extOf(DI); - - //When - OperationSystem android = DI.phoneOs(PhoneOsType.Android); - OperationSystem android2 = DI.phoneOs(PhoneOsType.Android); - OperationSystem osNull = DI.phoneOs(null); - - //Then: created components are different - 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 new file mode 100644 index 00000000..e5316337 --- /dev/null +++ b/tests_ext/src/test/java/com/dirgub/klee0kai/stone/text_ext/identifiers/TechFactoryComponentOverriddenTests.kt @@ -0,0 +1,118 @@ +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 + fun nonArgProvideTest() { + //Given + val DI: TechFactoryComponent = TechFactoryComponentStoneComponent() + val DIPro: TechFactoryExtComponent = TechFactoryExtComponentStoneComponent() + DIPro.extOf(DI) + + //When + val ram: Ram? = DI.ram() + + //Then + assertEquals("default", ram!!.size) + assertTrue(ram is DDR3Ram) + } + + @Test + fun singleArgProvideTest() { + //Given + val DI: TechFactoryComponent = TechFactoryComponentStoneComponent() + val DIPro: TechFactoryExtComponent = TechFactoryExtComponentStoneComponent() + DIPro.extOf(DI) + + + //When + val ram: Ram? = DI.ram(RamSize("4G")) + + //Then + assertEquals("4G", ram!!.size) + assertTrue(ram is DDR3Ram) + } + + + @Test + fun nullGenerateArgProvideTest() { + //Given + val DI: TechFactoryComponent = TechFactoryComponentStoneComponent() + val DIPro: TechFactoryExtComponent = TechFactoryExtComponentStoneComponent() + DIPro.extOf(DI) + + //When + val os: OperationSystem? = 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: TechFactoryComponent = TechFactoryComponentStoneComponent() + val DIPro: TechFactoryExtComponent = TechFactoryExtComponentStoneComponent() + DIPro.extOf(DI) + + //When + val os: OperationSystem? = DI.phoneOs(PhoneOsType.Ios, PhoneOsVersion("11")) + + //Then + assertEquals(PhoneOsType.Ios, os!!.phoneOsType) + assertEquals("11", os.version!!.version) + } + + + @Test + fun differentCreateTest() { + //Given + val DI: TechFactoryComponent = TechFactoryComponentStoneComponent() + val DIPro: TechFactoryExtComponent = TechFactoryExtComponentStoneComponent() + DIPro.extOf(DI) + + //When + 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 is DDR3Ram) + assertTrue(ram8Gb2 is DDR3Ram) + } + + + @Test + fun enumDifferentTest() { + //Given + val DI: TechFactoryComponent = TechFactoryComponentStoneComponent() + val DIPro: TechFactoryExtComponent = TechFactoryExtComponentStoneComponent() + DIPro.extOf(DI) + + //When + 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) + } + +} diff --git a/tests_kotlin/build.gradle b/tests_kotlin/build.gradle deleted file mode 100644 index dbc03b68..00000000 --- a/tests_kotlin/build.gradle +++ /dev/null @@ -1,30 +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.0' - testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.9.0' -} - - diff --git a/tests_kotlin/build.gradle.kts b/tests_kotlin/build.gradle.kts new file mode 100644 index 00000000..180f5166 --- /dev/null +++ b/tests_kotlin/build.gradle.kts @@ -0,0 +1,20 @@ +plugins { + alias(libs.plugins.kotlin.jvm) + alias(libs.plugins.kotlin.ksp) +} + +tasks.test { + useJUnitPlatform() +} + +dependencies { + implementation(project(":tests")) + + implementation(project(":stone_multiplatform")) + ksp(project(":stone_ksp")) + + testImplementation(libs.bundles.junit) + +} + + 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, 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) 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..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 @@ -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,6 @@ import com.github.klee0kai.test.di.base_phone.identifiers.RamSize RamSize::class, PhoneOsType::class, PhoneOsVersion::class ], - wrapperProviders = [KotlinWrappersStone::class] ) interface CompFactoryComponent : ICompFactoryWrappersComponent { 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/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..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,12 +1,12 @@ package com.github.klee0kai.test_kotlin.tech -import com.github.klee0kai.stone.Stone import com.github.klee0kai.test_kotlin.di.base_comp.CompComponent +import com.github.klee0kai.test_kotlin.di.base_comp.CompComponentStoneComponent object ComputerStore { - var DI = Stone.createComponent(CompComponent::class.java) + var DI: CompComponent = CompComponentStoneComponent() fun recreate() { - DI = 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/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 b9005d8c..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.wrappers.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..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 51f3582d..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.wrappers.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_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/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 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..5948c0ca --- /dev/null +++ b/tests_wraps_kotlin/build.gradle.kts @@ -0,0 +1,18 @@ +plugins { + alias(libs.plugins.kotlin.jvm) + alias(libs.plugins.kotlin.ksp) +} + +tasks.test { + useJUnitPlatform() +} + +dependencies { + implementation(project(":tests")) + + 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/CarBoxedInjectComponent.kt b/tests_wraps_kotlin/src/main/kotlin/com/github/klee0kai/test/boxed/di/inject/CarBoxedInjectComponent.kt index 38f97b93..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 @@ -6,9 +6,14 @@ 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 +@Component( + 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/CarBoxedInjectModule.kt b/tests_wraps_kotlin/src/main/kotlin/com/github/klee0kai/test/boxed/di/inject/CarBoxedInjectModule.kt index 1fa659f5..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 @@ -2,18 +2,18 @@ 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 @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/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..897c5717 --- /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.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/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/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 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..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 @@ -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 @@ -9,6 +9,7 @@ import com.github.klee0kai.test.car.model.Window import javax.inject.Inject class CarBoxedInjectProvider { + @Inject var bumper: LazyProvide>? = null 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..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,7 +2,8 @@ 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.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 import com.github.klee0kai.test.car.model.Wheel @@ -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/bindinstance/simple/CarBindComponent.kt b/tests_wraps_kotlin/src/main/kotlin/com/github/klee0kai/test/car/di/bindinstance/simple/CarBindComponent.kt index e0014f85..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 @@ -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 @@ -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/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 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/inject/CarInjectComponent.kt b/tests_wraps_kotlin/src/main/kotlin/com/github/klee0kai/test/car/di/inject/CarInjectComponent.kt index 32803c19..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 @@ -2,14 +2,15 @@ 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 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/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..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 @@ -1,7 +1,8 @@ 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.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 import com.github.klee0kai.test.car.model.Wheel @@ -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?>? - fun windowsProviding(): List?>?>? + + @IgnoreQualifier + 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 2c9cf63a..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,7 +2,8 @@ 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.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 import com.github.klee0kai.test.car.model.Wheel @@ -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 5c72f8aa..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 @@ -1,7 +1,8 @@ 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.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 import com.github.klee0kai.test.car.model.Wheel @@ -12,12 +13,23 @@ import javax.inject.Provider @Component interface CarMultiComponent { + fun module(): CarMultiModule? + fun singleBumper(): Ref? + + @IgnoreQualifier fun wheels(): List?>?>? + fun wheel(): Wheel? + + @IgnoreQualifier fun windows(): List?>? - fun windowsProviding(): List?>?>? + + @IgnoreQualifier + fun windowsProviding(): List?>?>? + + @IgnoreQualifier fun cars(): List? @Named("blueCar") 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..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,7 +2,8 @@ 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.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 import com.github.klee0kai.test.car.model.Wheel @@ -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/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..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 @@ -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 @@ -14,6 +15,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) @@ -38,13 +40,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, + @IgnoreQualifier wheel: List, + window: List + ): Car { val car = Car(bumper, wheel, window) car.qualifier = "named_empty" return car @@ -53,9 +63,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, + @IgnoreQualifier wheel: List, + @IgnoreQualifier window: List ): Car { val car = Car(bumper, wheel, window) car.qualifier = "named_a" @@ -65,9 +75,9 @@ open class CarQCModule { @MyQualifier @Provide(cache = Provide.CacheType.Factory) open fun carMyQualifier( - @BumperQualifier bumper: List?, - wheel: List?, - window: List? + @BumperQualifier bumper: List, + @IgnoreQualifier wheel: List, + @IgnoreQualifier window: List ): Car { val car = Car(bumper, wheel, window) car.qualifier = "my_qualifier" @@ -77,9 +87,9 @@ open class CarQCModule { @MyQualifierWithString @Provide(cache = Provide.CacheType.Factory) open fun carIdQualifier( - @BumperQualifier bumper: List?, - wheel: List?, - window: List? + @BumperQualifier bumper: List, + @IgnoreQualifier wheel: List, + @IgnoreQualifier window: List ): Car { val car = Car(bumper, wheel, window) car.qualifier = "my_qualifier_with_string" @@ -89,9 +99,10 @@ 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, + @IgnoreQualifier window: List ): Car { val car = Car(bumper, wheel, window) car.qualifier = "my_qualifier_a" @@ -101,9 +112,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, + @IgnoreQualifier wheel: List, + @IgnoreQualifier window: List, ): Car { val car = Car(bumper, wheel, window) car.qualifier = "my_qualifier_b" @@ -113,9 +124,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, + @IgnoreQualifier window: List ): Car { val car = Car(bumper, wheel, window) car.qualifier = "qualifier_multi" @@ -125,9 +136,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, + @IgnoreQualifier wheel: List, + @IgnoreQualifier window: List ): Car { val car = Car(bumper, wheel, window) car.qualifier = "qualifier_multi_a1" @@ -137,9 +148,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, + @IgnoreQualifier window: List, ): Car { val car = Car(bumper, wheel, window) car.qualifier = "qualifier_multi_a2" @@ -149,9 +160,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, + @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..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 @@ -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 @@ -13,6 +14,8 @@ interface CarQComponent { fun module1(): CarQPModule? fun module2(): CarQCModule? + fun inject(carInject: CarsInjectQualifiers?) + @Named fun carNamedEmpty(): Car? @@ -42,6 +45,8 @@ interface CarQComponent { @MyQualifierMulti(type = MyQualifierMulti.Type.HARD, indx = 2, id = "a") fun carMyQualifierMultiA2Hard(): Car? + + @IgnoreQualifier fun allCars(): List? @Named @@ -49,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/di/qualifiers/CarQPModule.kt b/tests_wraps_kotlin/src/main/kotlin/com/github/klee0kai/test/car/di/qualifiers/CarQPModule.kt index e871ed2f..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 @@ -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 @@ -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) 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..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 @@ -1,8 +1,10 @@ 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.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 @@ -12,17 +14,34 @@ 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(): AsyncProvide? + + fun carAsync(): AsyncCoroutineProvide? + + fun bumperAsyncPhantom(): FantomAsyncProvide + + } 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/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/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/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 d879b581..00000000 --- a/tests_wraps_kotlin/src/main/kotlin/com/github/klee0kai/test/car/di/wrapped/custom/wrappers/CarProviderWrapper.kt +++ /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.ProviderWrapper -import javax.inject.Provider - -@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 - } - 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/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..30a70a9f --- /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.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 - } -} 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..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 @@ -6,8 +6,11 @@ class Car { var uuid = UUID.randomUUID().toString() var bumpers: List? + var wheels: List? + var windows: List? + var qualifier: String? = null constructor( @@ -21,7 +24,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/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 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/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..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 @@ -1,44 +1,42 @@ 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()) - assertNull(DI.provideBumper()!!.get()) + assertNull(DI.provideBumper()?.get()) assertEquals(0, DI.provideBumpers()!!.size) } @Test fun nullBindTest() { //Given - val DI = Stone.createComponent( - CarBindComponent::class.java - ) + val DI = CarBindComponentStoneComponent() //When 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) } @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..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 @@ -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,13 +39,13 @@ class BindWheelRefTests { @Test fun nullRefBindTest() { //Given - val DI = Stone.createComponent(CarBindComponent::class.java) + val DI = CarBindComponentStoneComponent() //When DI.bindWheelRef(WeakReference(null)) //Then - assertNull(DI.module()!!.wheel()) + assertNull(DI.module().wheel()) assertNull(DI.provideWheel()) assertNull(DI.provideWheelRef()) assertEquals(0, DI.provideWheels()!!.size) @@ -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..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 @@ -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() @@ -48,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) @@ -57,7 +56,7 @@ class BindWheelTests { @Test fun rebindWheelSimpleTest() { //Given - val DI = Stone.createComponent(CarBindComponent::class.java) + val DI = CarBindComponentStoneComponent() DI.bindWheel(Wheel()) //When @@ -66,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 5a2c26cd..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 @@ -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() @@ -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) } @@ -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..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 @@ -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() @@ -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) } @@ -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..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 @@ -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() @@ -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) } @@ -52,7 +52,7 @@ class BindWindowTests { @Test fun rebindWindowSimpleTest() { //Given - val DI = Stone.createComponent(CarBindComponent::class.java) + val DI = CarBindComponentStoneComponent() DI.bindWindow(Window()) //When @@ -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) } 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..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 @@ -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,15 +63,15 @@ class WindowPartialGcTests { @Test fun partialRecreateList2Test() { // Given - val DI = Stone.createComponent(CarGcComponent::class.java) - val uids1 = DI.windowsModule()!!.windowStrong().get()!!.map { it.uuid } - val holder = DI.windowsModule()!!.windowStrong().get()!![1] + val DI = CarGcComponentStoneComponent() + 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 @@ -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..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 @@ -1,18 +1,19 @@ 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 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 class MultiCachedProvideTest { + @BeforeEach fun init() { Bumper.createCount = 0 @@ -24,9 +25,7 @@ class MultiCachedProvideTest { @Test fun firstBumperFromCollection() { //Given - val DI = Stone.createComponent( - CarMultiCachedComponent::class.java - ) + val DI = CarMultiCachedComponentStoneComponent() //When assertEquals(0, Bumper.createCount) @@ -42,9 +41,7 @@ class MultiCachedProvideTest { @Test fun cachedBumperFromCollection() { //Given - val DI = Stone.createComponent( - CarMultiCachedComponent::class.java - ) + val DI = CarMultiCachedComponentStoneComponent() //When val bumperProvide = DI.singleBumper() @@ -62,9 +59,7 @@ class MultiCachedProvideTest { @Test fun fourWheelsAndSpare() { //Given - val DI = Stone.createComponent( - CarMultiCachedComponent::class.java - ) + val DI = CarMultiCachedComponentStoneComponent() //When assertEquals(0, Wheel.createCount) @@ -83,7 +78,7 @@ class MultiCachedProvideTest { @Test fun fourWheelsAndSpareCached() { //Given - val DI = Stone.createComponent(CarMultiCachedComponent::class.java) + val DI = CarMultiCachedComponentStoneComponent() //When val wheelsProviderList = DI.wheels() @@ -103,7 +98,7 @@ class MultiCachedProvideTest { @Test fun oneWheelFromList() { //Given - val DI = Stone.createComponent(CarMultiCachedComponent::class.java) + val DI = CarMultiCachedComponentStoneComponent() //When val wheel1 = DI.wheel() @@ -117,7 +112,7 @@ class MultiCachedProvideTest { @Test fun allWindowsInCar() { //Given - val DI = Stone.createComponent(CarMultiCachedComponent::class.java) + val DI = CarMultiCachedComponentStoneComponent() //When assertEquals(0, Window.createCount) @@ -135,7 +130,7 @@ class MultiCachedProvideTest { @Test fun allWindowsInCarFactory() { //Given - val DI = Stone.createComponent(CarMultiCachedComponent::class.java) + val DI = CarMultiCachedComponentStoneComponent() //When assertEquals(0, Window.createCount) @@ -153,7 +148,7 @@ class MultiCachedProvideTest { @Test fun allWindowsInCarProvideWrapper() { //Given - val DI = Stone.createComponent(CarMultiCachedComponent::class.java) + val DI = CarMultiCachedComponentStoneComponent() //When assertEquals(0, Window.createCount) @@ -172,7 +167,7 @@ class MultiCachedProvideTest { @Test fun createCarsWithDeps() { //Given - val DI = Stone.createComponent(CarMultiCachedComponent::class.java) + val DI = CarMultiCachedComponentStoneComponent() //When assertEquals(0, Car.createCount) @@ -187,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" @@ -197,7 +192,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..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 @@ -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) @@ -161,7 +161,7 @@ class MultiProvideTest { @Test fun createCarsWithDeps() { //Given - val DI = Stone.createComponent(CarMultiComponent::class.java) + val DI = CarMultiComponentStoneComponent() //When assertEquals(0, Car.createCount) @@ -176,6 +176,7 @@ class MultiProvideTest { assertNotNull(car[1]!!.bumpers) assertNotNull(car[1]!!.wheels) assertNotNull(car[1]!!.windows) + assertNotEquals( car[0]!!.windows!!.size, car[1]!!.windows!!.size, @@ -186,7 +187,7 @@ class MultiProvideTest { @Test fun factoryCreatedCar() { //Given - val DI = Stone.createComponent(CarMultiComponent::class.java) + val DI = CarMultiComponentStoneComponent() //When assertEquals(0, Car.createCount) 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..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 @@ -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 @@ -93,13 +91,13 @@ 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 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..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 @@ -1,17 +1,21 @@ 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.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 +import kotlin.time.Duration.Companion.milliseconds class CarSingleWrapperTests { + @BeforeEach fun init() { Bumper.createCount = 0 @@ -23,7 +27,7 @@ class CarSingleWrapperTests { @Test fun wheelSimpleTest() { //Given - val DI = Stone.createComponent(CarWrappedCreateComponent::class.java) + val DI = CarWrappedCreateComponentStoneComponent() //When val wheel1 = DI.wheel() @@ -38,7 +42,7 @@ class CarSingleWrapperTests { @Test fun wheelProvideTest() { //Given - val DI = Stone.createComponent(CarWrappedCreateComponent::class.java) + val DI = CarWrappedCreateComponentStoneComponent() //When val wheel1 = DI.wheelProvide() @@ -53,7 +57,7 @@ class CarSingleWrapperTests { @Test fun wheelLazyTest() { //Given - val DI = Stone.createComponent(CarWrappedCreateComponent::class.java) + val DI = CarWrappedCreateComponentStoneComponent() //When val wheel1 = DI.wheelLazy() @@ -68,7 +72,7 @@ class CarSingleWrapperTests { @Test fun wheelWeakTest() { //Given - val DI = Stone.createComponent(CarWrappedCreateComponent::class.java) + val DI = CarWrappedCreateComponentStoneComponent() //When val wheel1 = DI.wheelWeak() @@ -83,7 +87,7 @@ class CarSingleWrapperTests { @Test fun wheelProvideWeakTest() { //Given - val DI = Stone.createComponent(CarWrappedCreateComponent::class.java) + val DI = CarWrappedCreateComponentStoneComponent() //When val wheel1 = DI.whellProviderWeak() @@ -98,7 +102,7 @@ class CarSingleWrapperTests { @Test fun wheelLazyProvideWeakTest() { //Given - val DI = Stone.createComponent(CarWrappedCreateComponent::class.java) + val DI = CarWrappedCreateComponentStoneComponent() //When val wheel1 = DI.whellLazyProviderWeak() @@ -116,7 +120,7 @@ class CarSingleWrapperTests { @Test fun wheelProviderTest() { //Given - val DI = Stone.createComponent(CarWrappedCreateComponent::class.java) + val DI = CarWrappedCreateComponentStoneComponent() //When val wheel1 = DI.whellProvider() @@ -131,7 +135,7 @@ class CarSingleWrapperTests { @Test fun carLazyTest() { //Given - val DI = Stone.createComponent(CarWrappedCreateComponent::class.java) + val DI = CarWrappedCreateComponentStoneComponent() //When val car1 = DI.carLazy() @@ -145,9 +149,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() @@ -159,10 +163,24 @@ 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 - val DI = Stone.createComponent(CarWrappedCreateComponent::class.java) + val DI = CarWrappedCreateComponentStoneComponent() //When val car1 = DI.carProvider() @@ -178,7 +196,7 @@ class CarSingleWrapperTests { @Test fun carWeakTest() { //Given - val DI = Stone.createComponent(CarWrappedCreateComponent::class.java) + val DI = CarWrappedCreateComponentStoneComponent() //When val car1 = DI.carWeak() @@ -193,7 +211,7 @@ class CarSingleWrapperTests { @Test fun windowTest() { //Given - val DI = Stone.createComponent(CarWrappedCreateComponent::class.java) + val DI = CarWrappedCreateComponentStoneComponent() //When val window1 = DI.window() @@ -208,7 +226,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() diff --git a/weakref_multiplatform/build.gradle.kts b/weakref_multiplatform/build.gradle.kts new file mode 100644 index 00000000..648ada89 --- /dev/null +++ b/weakref_multiplatform/build.gradle.kts @@ -0,0 +1,87 @@ +plugins { + alias(libs.plugins.kotlin.multiplatform) + alias(libs.plugins.publish.stone) + alias(libs.plugins.publish.maven) +} + +group = "com.github.klee0kai.stone" +version = libs.versions.stone.get() + +kotlin { + jvm() + js(IR) { + browser() + nodejs() + } + + linuxX64() + mingwX64() + wasmJs { + browser() + nodejs() + } + + sourceSets { + commonMain.dependencies { + api(libs.java.inject) + api(libs.kotlinx.coroutines) + } + 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() + 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) + } + } +} + + +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/Memory.kt b/weakref_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/weakref/Memory.kt new file mode 100644 index 00000000..dafd477b --- /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/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..7de041ca --- /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..0851cea6 --- /dev/null +++ b/weakref_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/weakref/SoftRef.kt @@ -0,0 +1,12 @@ +package com.github.klee0kai.stone.weakref + +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 new file mode 100644 index 00000000..1ad20843 --- /dev/null +++ b/weakref_multiplatform/src/commonMain/kotlin/com/github/klee0kai/stone/weakref/WeakRef.kt @@ -0,0 +1,11 @@ +package com.github.klee0kai.stone.weakref + +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/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/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..c1909699 --- /dev/null +++ b/weakref_multiplatform/src/commonTest/kotlin/com/github/klee0kai/stone/weakref/WeakRefTests.kt @@ -0,0 +1,24 @@ +package com.github.klee0kai.stone.weakref + +import kotlin.test.Test +import kotlin.test.assertEquals +import kotlin.test.assertNull + +class WeakRefTests { + + class TestClass( + val string: String, + ) + + @Test + fun clearRefTest() { + val ref = WeakRef(TestClass("some text")) + + assertEquals("some text", ref.get()?.string) + + ref.clear() + + assertNull(ref.get()) + } + +} \ No newline at end of file diff --git a/weakref_multiplatform/src/jsMain/kotlin/com/github/klee0kai/stone/weakref/Memory.web.kt b/weakref_multiplatform/src/jsMain/kotlin/com/github/klee0kai/stone/weakref/Memory.web.kt new file mode 100644 index 00000000..966e1622 --- /dev/null +++ b/weakref_multiplatform/src/jsMain/kotlin/com/github/klee0kai/stone/weakref/Memory.web.kt @@ -0,0 +1,13 @@ +package com.github.klee0kai.stone.weakref + +import kotlin.js.js + +actual object Memory { + + actual fun gc() { + runCatching { + js("gc()") + } + } + +} \ No newline at end of file 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 new file mode 100644 index 00000000..5a41b388 --- /dev/null +++ b/weakref_multiplatform/src/jsMain/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/jsMain/kotlin/com/github/klee0kai/stone/weakref/WeakRef.kt b/weakref_multiplatform/src/jsMain/kotlin/com/github/klee0kai/stone/weakref/WeakRef.kt new file mode 100644 index 00000000..7be54454 --- /dev/null +++ b/weakref_multiplatform/src/jsMain/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/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/jvmMain/kotlin/com/github/klee0kai/stone/weakref/Memory.jvm.kt b/weakref_multiplatform/src/jvmMain/kotlin/com/github/klee0kai/stone/weakref/Memory.jvm.kt new file mode 100644 index 00000000..de0e5b50 --- /dev/null +++ b/weakref_multiplatform/src/jvmMain/kotlin/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/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..87cf984c --- /dev/null +++ b/weakref_multiplatform/src/jvmMain/kotlin/com/github/klee0kai/stone/weakref/SoftRef.kt @@ -0,0 +1,19 @@ +package com.github.klee0kai.stone.weakref + +import java.lang.ref.SoftReference + +actual class SoftRef actual constructor(value: T) : Ref, AutoCloseable { + + val weakRef: SoftReference = SoftReference(value) + + actual override fun get(): T? = weakRef.get() + + actual fun clear() { + 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 new file mode 100644 index 00000000..a75e89d5 --- /dev/null +++ b/weakref_multiplatform/src/jvmMain/kotlin/com/github/klee0kai/stone/weakref/WeakRef.kt @@ -0,0 +1,19 @@ +package com.github.klee0kai.stone.weakref + +import java.lang.ref.WeakReference + +actual class WeakRef actual constructor(value: T) : Ref, AutoCloseable { + + val weakRef: WeakReference = WeakReference(value) + + actual override fun get(): T? = weakRef.get() + + actual fun clear() { + 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/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/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..7fdd623c --- /dev/null +++ b/weakref_multiplatform/src/nativeMain/kotlin/com/github/klee0kai/stone/weakref/SoftRef.kt @@ -0,0 +1,22 @@ +@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, AutoCloseable { + + val weakRef: WeakReference? = value?.let { WeakReference(value) } + + actual override fun get(): T? = weakRef?.get() + + actual fun clear() { + 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 new file mode 100644 index 00000000..3ec60902 --- /dev/null +++ b/weakref_multiplatform/src/nativeMain/kotlin/com/github/klee0kai/stone/weakref/WeakRef.kt @@ -0,0 +1,22 @@ +@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) : Ref, AutoCloseable { + + val weakRef: WeakReference? = value?.let { WeakReference(value) } + + actual override fun get(): T? = weakRef?.get() + + actual fun clear() { + 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.js.kt b/weakref_multiplatform/src/wasmJsMain/kotlin/com/github/klee0kai/stone/weakref/SoftRef.js.kt new file mode 100644 index 00000000..ee424923 --- /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 = (value as? JsAny)?.let { JsWeakRef(value) } + + actual override fun get(): T? = weakRef?.deref() as T? + + 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.kt b/weakref_multiplatform/src/wasmJsMain/kotlin/com/github/klee0kai/stone/weakref/WeakRef.kt new file mode 100644 index 00000000..12dfb6f6 --- /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 = (value as JsAny)?.let { JsWeakRef(value) } + + actual override fun get(): T? = weakRef?.deref() as T? + + 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/js/WeakRef.kt b/weakref_multiplatform/src/wasmJsMain/kotlin/js/WeakRef.kt new file mode 100644 index 00000000..5b991f67 --- /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 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/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 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..ab8e94d2 --- /dev/null +++ b/wiki_kotlin/build.gradle.kts @@ -0,0 +1,18 @@ +plugins { + alias(libs.plugins.kotlin.jvm) + alias(libs.plugins.kotlin.ksp) +} + +tasks.test { + useJUnitPlatform() +} + +dependencies { + implementation(project(":tests")) + implementation(project(":test_feature:finance:api")) + + 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..1250c14f --- /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.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