Removed dependency on kotlin's Intrinsics.checkNotNull

This commit is contained in:
Andrew Golovashevich 2025-03-26 00:33:53 +03:00
parent d1773fd8ec
commit 9282313552
6 changed files with 73 additions and 11 deletions

View File

@ -42,6 +42,11 @@ xomrk {
compileTaskProvider.configure {
compilerOptions {
jvmTarget = JvmTarget.JVM_1_8
freeCompilerArgs.addAll(
"-Xno-call-assertions",
"-Xno-param-assertions",
"-Xno-receiver-assertions"
)
}
}
}

View File

@ -8,11 +8,18 @@ import kotlin.contracts.contract
import ru.landgrafhomyak.utility.highlevel_try_finally.safeAutoClose1
import ru.landgrafhomyak.utility.highlevel_try_finally.safeAutoClose2
public class CloseableReferenceCounter(private val _errMessage: String) {
private val _value = _AtomicLong(0L)
public class CloseableReferenceCounter {
private val _value: _AtomicLong
private val _errMessageClosed: String
public constructor(errMessageClosed: String) {
_Platform.jvm_assertNotNull(errMessageClosed, "param: errMessageClosed")
this._errMessageClosed = errMessageClosed
this._value = _AtomicLong(0L)
}
public fun throwClosed() {
throw IllegalStateException(this._errMessage)
throw IllegalStateException(this._errMessageClosed)
}
public fun incref() {
@ -47,6 +54,7 @@ public class CloseableReferenceCounter(private val _errMessage: String) {
}
public fun close(errExistRefs: String) {
_Platform.jvm_assertNotNull(errExistRefs, "param: errExistRefs")
val state = _CloseableReferenceCounter_LowLevel.compareAndExchange(this._value, 0, _CloseableReferenceCounter_LowLevel.CLOSED_STATE_VALUE)
when {
state > 0 -> throw IllegalStateException(errExistRefs)

View File

@ -9,11 +9,7 @@ import ru.landgrafhomyak.utility.highlevel_try_finally.safeAutoClose1
import ru.landgrafhomyak.utility.highlevel_try_finally.safeAutoClose2
@CloseableReferenceCounter_Debug.RequiresExplicitDebug
public class CloseableReferenceCounter_Debug(
private val _dbgName: String,
private val _errMessage: String,
private val _logger: Observer? = null,
) {
public class CloseableReferenceCounter_Debug {
public fun interface Observer {
public fun observeState(instance: CloseableReferenceCounter_Debug, actions: String)
}
@ -22,11 +18,25 @@ public class CloseableReferenceCounter_Debug(
@Retention(AnnotationRetention.BINARY)
public annotation class RequiresExplicitDebug
private val _dbgName: String
private val _errMessage: String
private val _logger: Observer?
private val _value: _AtomicLong
private val _id: Long
private val _value = _AtomicLong(0L)
public constructor(dbgName: String, errMessage: String, logger: Observer? = null) {
_Platform.jvm_assertNotNull(dbgName, "param: dbgName")
_Platform.jvm_assertNotNull(errMessage, "param: errMessage")
this._dbgName = dbgName
this._errMessage = dbgName
this._logger = logger
this._value = _AtomicLong(0L)
@Suppress("RemoveRedundantQualifierName")
private val _id = CloseableReferenceCounter_Debug._nextId.getAndUpdate(Long::inc)
this._id = CloseableReferenceCounter_Debug._nextId.getAndUpdate(Long::inc)
}
@Suppress("NOTHING_TO_INLINE")
private inline fun _throwErrors(valueToCheck: Long) {
@ -91,6 +101,7 @@ public class CloseableReferenceCounter_Debug(
}
public fun close(errExistRefs: String) {
_Platform.jvm_assertNotNull(errExistRefs, "param: errExistRefs")
val state = _CloseableReferenceCounter_LowLevel.compareAndExchange(this._value, 0, _CloseableReferenceCounter_LowLevel.CLOSED_STATE_VALUE)
this._throwErrors(state)
when {
@ -125,6 +136,8 @@ public class CloseableReferenceCounter_Debug(
public object ObserveToStdout : Observer {
override fun observeState(instance: CloseableReferenceCounter_Debug, actions: String) {
_Platform.jvm_assertNotNull(instance, "param: instance")
_Platform.jvm_assertNotNull(actions, "param: actions")
print("${instance} ${actions}\n")
}
}

View File

@ -0,0 +1,9 @@
package ru.landrafhomyak.utility.reference_counter
import kotlin.jvm.JvmStatic
@PublishedApi
internal expect object _Platform {
@PublishedApi
internal inline fun jvm_assertNotNull(x: Any?, name: String)
}

View File

@ -0,0 +1,17 @@
package ru.landrafhomyak.utility.reference_counter
import java.util.Objects
import kotlin.contracts.contract
@PublishedApi
internal actual object _Platform {
@Suppress("NOTHING_TO_INLINE")
@JvmStatic
@PublishedApi
internal actual inline fun jvm_assertNotNull(x: Any?, name: String) {
contract {
returns().implies(x != null)
}
Objects.requireNonNull(x, name)
}
}

View File

@ -0,0 +1,10 @@
package ru.landrafhomyak.utility.reference_counter
@PublishedApi
internal actual object _Platform {
@Suppress("NOTHING_TO_INLINE")
@PublishedApi
internal actual inline fun jvm_assertNotNull(x: Any?, name: String) {
}
}