Skip to content

Commit

Permalink
Upgraded kotlin to 1.9.20
Browse files Browse the repository at this point in the history
### WHat's done:
- upgraded kotlin
- removed actual\expected class
- added required OptIn

It handles of #554
  • Loading branch information
nulls committed Nov 8, 2023
1 parent a36c12a commit 5ab159a
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 30 deletions.
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[versions]
kotlin = "1.9.10"
kotlin = "1.9.20"
okio = "3.6.0"
serialization = "1.6.0"
diktat = "1.2.5"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ package com.saveourtool.save.core.logging
import com.saveourtool.save.core.config.LogType
import com.saveourtool.save.core.config.OutputStreamType
import com.saveourtool.save.core.utils.GenericAtomicReference
import com.saveourtool.save.core.utils.createGenericAtomicReference
import com.saveourtool.save.core.utils.writeToStream

import kotlin.native.concurrent.SharedImmutable
Expand All @@ -21,7 +22,7 @@ import kotlinx.datetime.toLocalDateTime
* Logging mode
*/
@SharedImmutable
val logType: GenericAtomicReference<LogType> = GenericAtomicReference(LogType.WARN)
val logType: GenericAtomicReference<LogType> = createGenericAtomicReference(LogType.WARN)

/**
* Whether to add time stamps to log messages
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,10 @@ enum class CurrentOs {
}

/**
* Class that holds value and shares atomic reference to the value (native only)
* Interface that holds value and shares atomic reference to the value (native only)
*
* @param valueToStore value to store
*/
@Suppress("USE_DATA_CLASS")
expect class GenericAtomicReference<T>(valueToStore: T) {
interface GenericAtomicReference<T> {
/**
* @return stored value
*/
Expand All @@ -33,6 +31,12 @@ expect class GenericAtomicReference<T>(valueToStore: T) {
fun set(newValue: T)
}

/**
* @param valueToStore value to store
* @return a new [GenericAtomicReference] with default value [valueToStore]
*/
expect fun <T> createGenericAtomicReference(valueToStore: T): GenericAtomicReference<T>

/**
* Get type of current OS
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ package com.saveourtool.save.core.utils

import com.saveourtool.save.core.config.OutputStreamType

@Suppress("USE_DATA_CLASS")
actual class GenericAtomicReference<T> actual constructor(valueToStore: T) {
private var value: T = valueToStore
actual fun get(): T = value
actual fun set(newValue: T) {
value = newValue
}
}
actual fun <T> createGenericAtomicReference(valueToStore: T): GenericAtomicReference<T> =
object : GenericAtomicReference<T> {
private var value: T = valueToStore
override fun get(): T = value
override fun set(newValue: T) {
value = newValue
}
}

actual fun getCurrentOs(): CurrentOs = error("Not implemented for JS")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ package com.saveourtool.save.core.utils

import com.saveourtool.save.core.config.OutputStreamType

@Suppress("USE_DATA_CLASS")
actual class GenericAtomicReference<T> actual constructor(valueToStore: T) {
private val holder: java.util.concurrent.atomic.AtomicReference<T> = java.util.concurrent.atomic.AtomicReference(valueToStore)
actual fun get(): T = holder.get()
actual fun set(newValue: T) {
holder.set(newValue)
}
}
actual fun <T> createGenericAtomicReference(valueToStore: T): GenericAtomicReference<T> =
object : GenericAtomicReference<T> {
private val holder = java.util.concurrent.atomic.AtomicReference(valueToStore)
override fun get(): T = holder.get()
override fun set(newValue: T) {
holder.set(newValue)
}
}

actual fun getCurrentOs() = when {
System.getProperty("os.name").startsWith("Linux", ignoreCase = true) -> CurrentOs.LINUX
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,16 @@ import platform.posix.stderr
import platform.posix.stdout

import kotlinx.cinterop.ExperimentalForeignApi
import kotlin.experimental.ExperimentalNativeApi

@Suppress("USE_DATA_CLASS")
actual class GenericAtomicReference<T> actual constructor(valueToStore: T) {
private val holder: kotlin.concurrent.AtomicReference<T> = kotlin.concurrent.AtomicReference(valueToStore)
actual fun get(): T = holder.value
actual fun set(newValue: T) {
holder.value = newValue
}
}
actual fun <T> createGenericAtomicReference(valueToStore: T): GenericAtomicReference<T> =

Check failure

Code scanning / ktlint

[TOP_LEVEL_ORDER] the declaration part of a top level elements should be in the proper order: actual fun createGenericAtomicReference(valueToStore: T): GenericAtomicReference =... Error

[TOP_LEVEL_ORDER] the declaration part of a top level elements should be in the proper order: actual fun createGenericAtomicReference(valueToStore: T): GenericAtomicReference =...
object : GenericAtomicReference<T> {
private val holder = kotlin.concurrent.AtomicReference(valueToStore)
override fun get(): T = holder.value
override fun set(newValue: T) {
holder.value = newValue
}
}

/**
* Escaping percent symbol in the string in case it is not escaped already
Expand All @@ -51,6 +52,7 @@ fun String.escapePercent(): String {
return stringBuilder.toString()
}

@OptIn(ExperimentalNativeApi::class)
actual fun getCurrentOs() = when (Platform.osFamily) {
OsFamily.LINUX -> CurrentOs.LINUX
OsFamily.MACOSX -> CurrentOs.MACOS
Expand Down

0 comments on commit 5ab159a

Please sign in to comment.