PluginData: do not add supertype ConcurrentMap for shadowed maps even though original map implements it

This commit is contained in:
Him188 2021-05-09 00:15:35 +08:00
parent 048a0bbdd6
commit 55281ed228

View File

@ -11,7 +11,6 @@
package net.mamoe.mirai.console.internal.data package net.mamoe.mirai.console.internal.data
import java.util.concurrent.ConcurrentMap
import java.util.function.BiConsumer import java.util.function.BiConsumer
import java.util.function.BiFunction import java.util.function.BiFunction
import java.util.function.Function import java.util.function.Function
@ -153,32 +152,12 @@ internal open class ShadowMap<K, V, KR, VR>(
} }
} }
@Suppress(
"MANY_IMPL_MEMBER_NOT_IMPLEMENTED", "MANY_INTERFACES_MEMBER_NOT_IMPLEMENTED",
"UNCHECKED_CAST", "USELESS_CAST", "ACCIDENTAL_OVERRIDE", "TYPE_MISMATCH",
"EXPLICIT_OVERRIDE_REQUIRED_IN_MIXED_MODE", "CONFLICTING_INHERITED_JVM_DECLARATIONS"
)
internal open class ConcurrentShadowMap<K, V, KR, VR>(
originMapComputer: () -> MutableMap<K, V>,
kTransform: (K) -> KR,
kTransformBack: (KR) -> K,
vTransform: (V) -> VR,
vTransformBack: (VR) -> V
) : ShadowMap<K, V, KR, VR>(
originMapComputer, kTransform, kTransformBack, vTransform, vTransformBack
), ConcurrentMap<KR, VR>
internal fun <K, V, KR, VR> MutableMap<K, V>.shadowMap( internal fun <K, V, KR, VR> MutableMap<K, V>.shadowMap(
kTransform: (K) -> KR, kTransform: (K) -> KR,
kTransformBack: (KR) -> K, kTransformBack: (KR) -> K,
vTransform: (V) -> VR, vTransform: (V) -> VR,
vTransformBack: (VR) -> V vTransformBack: (VR) -> V
): MutableMap<KR, VR> = if (this is ConcurrentMap<K, V>) { ): MutableMap<KR, VR> = ShadowMap({ this }, kTransform, kTransformBack, vTransform, vTransformBack)
ConcurrentShadowMap({ this }, kTransform, kTransformBack, vTransform, vTransformBack)
} else {
ShadowMap({ this }, kTransform, kTransformBack, vTransform, vTransformBack)
}
internal inline fun <E, R> MutableCollection<E>.shadowMap( internal inline fun <E, R> MutableCollection<E>.shadowMap(
@ -454,14 +433,7 @@ internal fun <K, V> MutableMap<K, V>.observable(onChanged: () -> Unit): MutableM
this@observable.merge(key, value, remappingFunction).also { onChanged() } this@observable.merge(key, value, remappingFunction).also { onChanged() }
} }
@Suppress( return ObservableMap()
"MANY_IMPL_MEMBER_NOT_IMPLEMENTED", "MANY_INTERFACES_MEMBER_NOT_IMPLEMENTED",
"UNCHECKED_CAST", "USELESS_CAST", "ACCIDENTAL_OVERRIDE", "TYPE_MISMATCH",
"EXPLICIT_OVERRIDE_REQUIRED_IN_MIXED_MODE", "CONFLICTING_INHERITED_JVM_DECLARATIONS"
)
return if (this is ConcurrentMap<*, *>) {
object : ConcurrentMap<K, V>, MutableMap<K, V>, ObservableMap() {}
} else ObservableMap()
} }
internal inline fun <T> MutableList<T>.observable(crossinline onChanged: () -> Unit): MutableList<T> { internal inline fun <T> MutableList<T>.observable(crossinline onChanged: () -> Unit): MutableList<T> {