1
0
mirror of https://github.com/mamoe/mirai.git synced 2025-04-15 07:37:08 +08:00

Rename MutableTypeSafeMap to createMutableTypeSafeMap and so for TypeSafeMap, to avoid linking issue

This commit is contained in:
Him188 2022-05-26 19:13:11 +01:00
parent 9fa0b78d8c
commit 17430857a8
No known key found for this signature in database
GPG Key ID: BA439CDDCF652375
3 changed files with 13 additions and 13 deletions
mirai-core-utils/src
commonMain/kotlin
commonTest/kotlin/net/mamoe/mirai/utils
mirai-core/src/commonTest/kotlin/notice/processors

View File

@ -14,10 +14,10 @@ package net.mamoe.mirai.utils
import kotlinx.serialization.Serializable
import kotlin.contracts.InvocationKind
import kotlin.contracts.contract
import kotlin.jvm.JvmInline
import kotlin.properties.ReadOnlyProperty
import kotlin.properties.ReadWriteProperty
import kotlin.reflect.KProperty
import kotlin.jvm.JvmInline
@Serializable
@JvmInline
@ -175,13 +175,13 @@ internal class MutableTypeSafeMapImpl(
}
}
public fun TypeSafeMap.toMutableTypeSafeMap(): MutableTypeSafeMap = MutableTypeSafeMap(this.toMap())
public fun TypeSafeMap.toMutableTypeSafeMap(): MutableTypeSafeMap = createMutableTypeSafeMap(this.toMap())
public inline fun MutableTypeSafeMap(): MutableTypeSafeMap = MutableTypeSafeMapImpl()
public inline fun MutableTypeSafeMap(map: Map<String, Any>): MutableTypeSafeMap =
public inline fun createMutableTypeSafeMap(): MutableTypeSafeMap = MutableTypeSafeMapImpl()
public inline fun createMutableTypeSafeMap(map: Map<String, Any>): MutableTypeSafeMap =
MutableTypeSafeMapImpl().also { it.map.putAll(map) }
public inline fun TypeSafeMap(): TypeSafeMap = TypeSafeMap.EMPTY
public inline fun createTypeSafeMap(): TypeSafeMap = TypeSafeMap.EMPTY
public inline fun buildTypeSafeMap(block: MutableTypeSafeMap.() -> Unit): MutableTypeSafeMap {
contract { callsInPlace(block, InvocationKind.EXACTLY_ONCE) }

View File

@ -23,7 +23,7 @@ internal class TypeSafeMapTest {
@Test
fun `can set get`() {
val map = MutableTypeSafeMap()
val map = createMutableTypeSafeMap()
map[myKey] = "str"
map[myKey2] = "str2"
assertEquals(2, map.size)
@ -34,7 +34,7 @@ internal class TypeSafeMapTest {
@Test
fun `test nulls`() {
val map = MutableTypeSafeMap()
val map = createMutableTypeSafeMap()
map[myNullableKey] = null
map[myNullableKey2] = "str2"
assertEquals(2, map.size)
@ -44,7 +44,7 @@ internal class TypeSafeMapTest {
@Test
fun `key is inlined`() {
val map = MutableTypeSafeMap()
val map = createMutableTypeSafeMap()
map[TypeKey<String>("test")] = "str"
map[TypeKey<String>("test")] = "str2"
assertEquals(1, map.size)
@ -53,7 +53,7 @@ internal class TypeSafeMapTest {
@Test
fun `can toMap`() {
val map = MutableTypeSafeMap()
val map = createMutableTypeSafeMap()
map[myKey] = "str"
map[myKey2] = "str2"
assertEquals(2, map.size)
@ -67,7 +67,7 @@ internal class TypeSafeMapTest {
@Test
fun `test serialization`() {
val map = MutableTypeSafeMap()
val map = createMutableTypeSafeMap()
map[myKey] = "str"
map[myKey2] = "str2"
assertEquals(2, map.size)
@ -86,7 +86,7 @@ internal class TypeSafeMapTest {
val string = yaml.encodeToString(map1)
println(string) // { "test2": "str2" ,"test": "str" }
val result = MutableTypeSafeMap(Yaml.decodeMapFromString(string).cast())
val result = createMutableTypeSafeMap(Yaml.decodeMapFromString(string).cast())
assertEquals(map, result)
}
}

View File

@ -58,7 +58,7 @@ internal abstract class AbstractNoticeProcessorTest : AbstractCommonNHTest(), Gr
}
protected suspend inline fun use(
attributes: TypeSafeMap = TypeSafeMap(),
attributes: TypeSafeMap = createTypeSafeMap(),
pipeline: NoticeProcessorPipeline = bot.components.noticeProcessorPipeline,
block: UseTestContext.() -> ProtocolStruct
): Collection<Packet> {
@ -73,7 +73,7 @@ internal abstract class AbstractNoticeProcessorTest : AbstractCommonNHTest(), Gr
}
protected suspend inline fun use(
attributes: TypeSafeMap = TypeSafeMap(),
attributes: TypeSafeMap = createTypeSafeMap(),
crossinline createContext: NoticeProcessorPipelineImpl.(attributes: TypeSafeMap) -> NoticeProcessorPipelineImpl.ContextImpl,
block: UseTestContext.() -> ProtocolStruct
): Collection<Packet> =