Skip to content

Commit

Permalink
[Maintenance] removal of OptIn and Suppress
Browse files Browse the repository at this point in the history
Removal of redundant usages of `@OptIn`and `@Suppress` annotations
  • Loading branch information
GrzegorzBobryk committed Sep 26, 2024
1 parent 74f9198 commit 438e2b8
Show file tree
Hide file tree
Showing 23 changed files with 49 additions and 80 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import org.koin.test.android.helper.Helper.componentCallbacks
import org.koin.test.android.helper.Helper.koinComponent
import org.koin.test.android.helper.Helper.koinScopeComponent

@Suppress("OPT_IN_IS_NOT_ENABLED")
@OptIn(KoinInternalApi::class)
class AndroidKoinScopeExtTest : KoinTest {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,15 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
@file:Suppress("DeprecatedCallableAddReplaceWith")

package org.koin.androidx.compose.navigation

import androidx.compose.runtime.Composable
import androidx.lifecycle.*
import androidx.lifecycle.ViewModel
import androidx.lifecycle.ViewModelStoreOwner
import androidx.lifecycle.viewmodel.CreationExtras
import androidx.lifecycle.viewmodel.compose.LocalViewModelStoreOwner
import org.koin.androidx.viewmodel.resolveViewModel
import org.koin.compose.LocalKoinScope
import org.koin.compose.currentKoinScope
import org.koin.core.annotation.KoinInternalApi
import org.koin.core.parameter.ParametersDefinition
Expand Down Expand Up @@ -52,4 +51,4 @@ inline fun <reified T : ViewModel> koinNavViewModel(
return resolveViewModel(
T::class, viewModelStoreOwner.viewModelStore, key, extras, qualifier, scope, parameters
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
@file:Suppress("DeprecatedCallableAddReplaceWith")

package org.koin.androidx.compose.navigation

Expand All @@ -39,4 +38,4 @@ fun defaultNavExtras(viewModelStoreOwner: ViewModelStoreOwner): CreationExtras =
viewModelStoreOwner is NavBackStackEntry && viewModelStoreOwner.arguments != null -> viewModelStoreOwner.arguments?.toExtras(viewModelStoreOwner) ?: CreationExtras.Empty
viewModelStoreOwner is HasDefaultViewModelProviderFactory -> viewModelStoreOwner.defaultViewModelCreationExtras
else -> CreationExtras.Empty
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@ package org.koin.androidx.compose
import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember
import org.koin.compose.currentKoinScope
import org.koin.compose.rememberCurrentKoinScope
import org.koin.core.Koin
import org.koin.core.annotation.KoinInternalApi
import org.koin.core.context.GlobalContext
import org.koin.core.parameter.ParametersDefinition
import org.koin.core.qualifier.Qualifier
Expand All @@ -36,7 +34,6 @@ import org.koin.core.scope.Scope
* @author Arnaud Giuliani
* @author Henrique Horbovyi
*/
@OptIn(KoinInternalApi::class)
@Composable
@Deprecated("use koinInject() instead")
inline fun <reified T> get(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@
* limitations under the License.
*/

@file:OptIn(KoinInternalApi::class)

package org.koin.androidx.compose

import android.app.Application
Expand All @@ -28,7 +26,6 @@ import androidx.compose.ui.platform.LocalContext
import org.koin.android.ext.android.getKoin
import org.koin.compose.KoinContext
import org.koin.core.annotation.KoinExperimentalAPI
import org.koin.core.annotation.KoinInternalApi
import org.koin.core.component.KoinComponent
import org.koin.mp.KoinPlatformTools

Expand All @@ -52,7 +49,7 @@ import org.koin.mp.KoinPlatformTools
@Composable
@KoinExperimentalAPI
fun KoinAndroidContext(
content: @Composable () -> Unit
content: @Composable () -> Unit,
) {
val context = LocalContext.current
val koinApplication = remember(context) {
Expand All @@ -71,4 +68,4 @@ private fun Context.findContextForKoin(): ComponentCallbacks {
context = context.baseContext
}
return applicationContext as Application
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,15 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
@file:Suppress("DeprecatedCallableAddReplaceWith")

package org.koin.androidx.compose

import androidx.compose.runtime.Composable
import androidx.lifecycle.*
import androidx.lifecycle.ViewModel
import androidx.lifecycle.ViewModelStoreOwner
import androidx.lifecycle.viewmodel.CreationExtras
import androidx.lifecycle.viewmodel.compose.LocalViewModelStoreOwner
import org.koin.androidx.viewmodel.resolveViewModel
import org.koin.compose.LocalKoinScope
import org.koin.compose.currentKoinScope
import org.koin.compose.rememberCurrentKoinScope
import org.koin.core.annotation.KoinInternalApi
Expand Down Expand Up @@ -69,4 +68,4 @@ inline fun <reified T : ViewModel> koinViewModel(
return resolveViewModel(
T::class, viewModelStoreOwner.viewModelStore, key, extras, qualifier, scope, parameters
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
@file:Suppress("DeprecatedCallableAddReplaceWith")

package org.koin.compose.viewmodel

import androidx.compose.runtime.Composable
import androidx.lifecycle.*
import androidx.lifecycle.ViewModel
import androidx.lifecycle.ViewModelStoreOwner
import androidx.lifecycle.viewmodel.CreationExtras
import androidx.lifecycle.viewmodel.compose.LocalViewModelStoreOwner
import org.koin.compose.currentKoinScope
Expand Down Expand Up @@ -56,4 +56,4 @@ inline fun <reified T : ViewModel> koinNavViewModel(
return resolveViewModel(
T::class, viewModelStoreOwner.viewModelStore, key, extras, qualifier, scope, parameters
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
@file:Suppress("DeprecatedCallableAddReplaceWith")

package org.koin.compose.viewmodel

Expand Down Expand Up @@ -59,4 +58,4 @@ fun Bundle.toExtras(viewModelStoreOwner: ViewModelStoreOwner): CreationExtras? {
}
}.getOrNull()
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
@file:Suppress("DeprecatedCallableAddReplaceWith")

package org.koin.compose.viewmodel

import androidx.compose.runtime.Composable
import androidx.lifecycle.*
import androidx.lifecycle.ViewModel
import androidx.lifecycle.ViewModelStoreOwner
import androidx.lifecycle.viewmodel.CreationExtras
import androidx.lifecycle.viewmodel.compose.LocalViewModelStoreOwner
import org.koin.compose.currentKoinScope
Expand Down Expand Up @@ -57,4 +57,4 @@ inline fun <reified T : ViewModel> koinViewModel(
return resolveViewModel(
T::class, viewModelStoreOwner.viewModelStore, key, extras, qualifier, scope, parameters
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
@file:Suppress("UNCHECKED_CAST")

package org.koin.core.instance

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,9 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
@file:OptIn(KoinInternalApi::class)

package org.koin.core.module.dsl

import org.koin.core.annotation.KoinInternalApi
import org.koin.core.definition.KoinDefinition
import org.koin.core.module.Module

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,9 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
@file:OptIn(KoinInternalApi::class)

package org.koin.core.module.dsl

import org.koin.core.annotation.KoinInternalApi
import org.koin.core.definition.KoinDefinition
import org.koin.dsl.ScopeDSL

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,10 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
@file:OptIn(KoinInternalApi::class)

package org.koin.core.module.dsl

import org.koin.core.annotation.KoinInternalApi
import org.koin.core.definition.KoinDefinition
import org.koin.core.module.*
import org.koin.dsl.ScopeDSL

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,9 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
@file:OptIn(KoinInternalApi::class)

package org.koin.core.module.dsl

import org.koin.core.annotation.KoinInternalApi
import org.koin.core.definition.KoinDefinition
import org.koin.core.module.Module

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,6 @@ class Scope(
}
}

@Suppress("UNCHECKED_CAST")
private fun <T> resolveInstance(
qualifier: Qualifier?,
clazz: KClass<*>,
Expand Down Expand Up @@ -243,34 +242,34 @@ class Scope(
qualifier: Qualifier?,
clazz: KClass<*>,
instanceContext: InstanceContext,
parameterDef: ParametersDefinition?
parameterDef: ParametersDefinition?,
) = (
_koin.instanceRegistry.resolveInstance(qualifier, clazz, this.scopeQualifier, instanceContext)
?: run {
_koin.logger.debug("|- ? t:'${clazz.getFullName()}' - q:'$qualifier' look in injected parameters")
_parameterStackLocal.get()?.firstOrNull()?.getOrNull<T>(clazz)
}
?: run {
if (!isRoot){
_koin.logger.debug("|- ? t:'${clazz.getFullName()}' - q:'$qualifier' look at scope source" )
_source?.let { source ->
if (clazz.isInstance(source) && qualifier == null) {
_source as? T
?: run {
_koin.logger.debug("|- ? t:'${clazz.getFullName()}' - q:'$qualifier' look in injected parameters")
_parameterStackLocal.get()?.firstOrNull()?.getOrNull<T>(clazz)
}
?: run {
if (!isRoot) {
_koin.logger.debug("|- ? t:'${clazz.getFullName()}' - q:'$qualifier' look at scope source")
_source?.let { source ->
if (clazz.isInstance(source) && qualifier == null) {
_source as? T
} else null
}
} else null
}
} else null
}
?: run {
_koin.logger.debug("|- ? t:'${clazz.getFullName()}' - q:'$qualifier' look in other scopes" )
findInOtherScope<T>(clazz, qualifier, parameterDef)
}
?: run {
if (parameterDef != null) {
_parameterStackLocal.remove()
_koin.logger.debug("|- << parameters")
}
throwDefinitionNotFound(qualifier, clazz)
})
?: run {
_koin.logger.debug("|- ? t:'${clazz.getFullName()}' - q:'$qualifier' look in other scopes")
findInOtherScope<T>(clazz, qualifier, parameterDef)
}
?: run {
if (parameterDef != null) {
_parameterStackLocal.remove()
_koin.logger.debug("|- << parameters")
}
throwDefinitionNotFound(qualifier, clazz)
})

@Suppress("UNCHECKED_CAST")
private fun <T> getFromSource(clazz: KClass<*>): T? {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,15 @@ package org.koin.dsl
import org.koin.core.annotation.KoinInternalApi
import org.koin.core.definition.Definition
import org.koin.core.definition.KoinDefinition
import org.koin.core.module.*
import org.koin.core.module.KoinDslMarker
import org.koin.core.module.Module
import org.koin.core.module._scopedInstanceFactory
import org.koin.core.qualifier.Qualifier

/**
* DSL Scope Definition
*/
@OptIn(KoinInternalApi::class)
@Suppress("UNUSED_PARAMETER")
@KoinDslMarker
class ScopeDSL(val scopeQualifier: Qualifier, val module: Module) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ class Simple {
class AllFactory2(val strings: MyStringFactory, val ints: MyIntFactory)
}

@Suppress("unused")
class Errors {
class Boom {
init {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package org.koin.core

import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.async
import kotlinx.coroutines.awaitAll
import kotlinx.coroutines.test.TestResult
Expand Down Expand Up @@ -38,7 +37,6 @@ class ParametersInjectionTest {
assertEquals(42, a.id)
}

@OptIn(KoinInternalApi::class)
@Test
fun inject_param_get_or_null() {
ensureCanInjectParam(
Expand Down Expand Up @@ -355,10 +353,9 @@ class ParametersInjectionTest {
}

@Test
@OptIn(ExperimentalCoroutinesApi::class)
fun `inject across multiple threads`(): TestResult {
val times = 100

return runTest {
val app = koinApplication {
modules(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import org.koin.test.mock.declareMock
import org.mockito.BDDMockito.given
import org.mockito.Mockito

@Suppress("UNCHECKED_CAST")
class DeclareMockTests : AutoCloseKoinTest() {

@get:Rule
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import org.koin.test.KoinTest
import org.koin.test.Simple
import org.koin.test.inject

@Suppress("UNCHECKED_CAST")
class DeclareKoinContextFromExtensionTest : KoinTest {

@JvmField
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import org.koin.test.mock.declareMock
import org.mockito.BDDMockito.given
import org.mockito.Mockito

@Suppress("UNCHECKED_CAST")
class DeclareMockTests : AutoCloseKoinTest() {

@JvmField
Expand Down
Loading

0 comments on commit 438e2b8

Please sign in to comment.