mirror of
https://github.com/mamoe/mirai.git
synced 2025-01-10 18:40:15 +08:00
Fix MessageScopeCodegen
This commit is contained in:
parent
6debc1d45b
commit
2dd808c0d7
@ -74,7 +74,7 @@ internal object MessageScopeCodegen {
|
|||||||
fun main(args: Array<String>) = super.startIndependently()
|
fun main(args: Array<String>) = super.startIndependently()
|
||||||
override val defaultInvokeArgs: List<KtType> = listOf(KtString) // invoke once
|
override val defaultInvokeArgs: List<KtType> = listOf(KtString) // invoke once
|
||||||
|
|
||||||
@Suppress("RedundantVisibilityModifier", "ClassName", "KDocUnresolvedReference")
|
@Suppress("RedundantVisibilityModifier", "ClassName", "KDocUnresolvedReference", "unused")
|
||||||
override fun StringBuilder.apply(ktType: KtType) {
|
override fun StringBuilder.apply(ktType: KtType) {
|
||||||
for (candidate in TypeCandidatesForMessageScope) {
|
for (candidate in TypeCandidatesForMessageScope) {
|
||||||
appendKCode(
|
appendKCode(
|
||||||
@ -109,7 +109,7 @@ internal object MessageScopeCodegen {
|
|||||||
appendLine()
|
appendLine()
|
||||||
}
|
}
|
||||||
|
|
||||||
for ((a, b) in (TypeCandidatesForMessageScope + KtMessageScope).distinctArrangements()) {
|
for ((a, b) in (TypeCandidatesForMessageScope + KtMessageScope).arrangements()) {
|
||||||
appendKCode(
|
appendKCode(
|
||||||
"""
|
"""
|
||||||
public fun ${a}.scopeWith(other: ${b}): MessageScope {
|
public fun ${a}.scopeWith(other: ${b}): MessageScope {
|
||||||
@ -120,7 +120,7 @@ internal object MessageScopeCodegen {
|
|||||||
appendLine()
|
appendLine()
|
||||||
}
|
}
|
||||||
|
|
||||||
for ((a, b) in (TypeCandidatesForMessageScope + KtMessageScope).distinctArrangements()) {
|
for ((a, b) in (TypeCandidatesForMessageScope + KtMessageScope).arrangements()) {
|
||||||
appendKCode(
|
appendKCode(
|
||||||
"""
|
"""
|
||||||
public fun ${a}?.scopeWithNotNull(other: ${b}?): MessageScope {
|
public fun ${a}?.scopeWithNotNull(other: ${b}?): MessageScope {
|
||||||
@ -163,7 +163,10 @@ internal object MessageScopeCodegen {
|
|||||||
for (a in (TypeCandidatesForMessageScope + KtMessageScope)) {
|
for (a in (TypeCandidatesForMessageScope + KtMessageScope)) {
|
||||||
appendKCode(
|
appendKCode(
|
||||||
"""
|
"""
|
||||||
@Deprecated("Senseless scopeWith. Use asMessageScope.", ReplaceWith("this.asMessageScope()", "net.mamoe.mirai.console.util.asMessageScope"))
|
@Deprecated(
|
||||||
|
"Senseless scopeWith. Use asMessageScope.",
|
||||||
|
ReplaceWith("this.asMessageScope()", "net.mamoe.mirai.console.util.asMessageScope")
|
||||||
|
)
|
||||||
public inline fun ${a}.scopeWith(): MessageScope = asMessageScope()
|
public inline fun ${a}.scopeWith(): MessageScope = asMessageScope()
|
||||||
"""
|
"""
|
||||||
)
|
)
|
||||||
@ -175,7 +178,11 @@ internal object MessageScopeCodegen {
|
|||||||
"""
|
"""
|
||||||
@Deprecated(
|
@Deprecated(
|
||||||
"Senseless scopeWith. Use .asMessageScope().invoke.",
|
"Senseless scopeWith. Use .asMessageScope().invoke.",
|
||||||
ReplaceWith("this.asMessageScope()(action)", "net.mamoe.mirai.console.util.asMessageScope", "net.mamoe.mirai.console.util.invoke")
|
ReplaceWith(
|
||||||
|
"this.asMessageScope()(action)",
|
||||||
|
"net.mamoe.mirai.console.util.asMessageScope",
|
||||||
|
"net.mamoe.mirai.console.util.invoke"
|
||||||
|
)
|
||||||
)
|
)
|
||||||
public inline fun <R> ${a}.scopeWith(action: MessageScope.() -> R): R = asMessageScope()(action)
|
public inline fun <R> ${a}.scopeWith(action: MessageScope.() -> R): R = asMessageScope()(action)
|
||||||
"""
|
"""
|
||||||
|
@ -155,6 +155,10 @@ public fun Contact.scopeWith(other: MessageScope): MessageScope {
|
|||||||
return CombinedScope(asMessageScope(), other.asMessageScope())
|
return CombinedScope(asMessageScope(), other.asMessageScope())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public fun CommandSender.scopeWith(other: Contact): MessageScope {
|
||||||
|
return CombinedScope(asMessageScope(), other.asMessageScope())
|
||||||
|
}
|
||||||
|
|
||||||
public fun CommandSender.scopeWith(other: CommandSender): MessageScope {
|
public fun CommandSender.scopeWith(other: CommandSender): MessageScope {
|
||||||
return CombinedScope(asMessageScope(), other.asMessageScope())
|
return CombinedScope(asMessageScope(), other.asMessageScope())
|
||||||
}
|
}
|
||||||
@ -163,6 +167,14 @@ public fun CommandSender.scopeWith(other: MessageScope): MessageScope {
|
|||||||
return CombinedScope(asMessageScope(), other.asMessageScope())
|
return CombinedScope(asMessageScope(), other.asMessageScope())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public fun MessageScope.scopeWith(other: Contact): MessageScope {
|
||||||
|
return CombinedScope(asMessageScope(), other.asMessageScope())
|
||||||
|
}
|
||||||
|
|
||||||
|
public fun MessageScope.scopeWith(other: CommandSender): MessageScope {
|
||||||
|
return CombinedScope(asMessageScope(), other.asMessageScope())
|
||||||
|
}
|
||||||
|
|
||||||
public fun MessageScope.scopeWith(other: MessageScope): MessageScope {
|
public fun MessageScope.scopeWith(other: MessageScope): MessageScope {
|
||||||
return CombinedScope(asMessageScope(), other.asMessageScope())
|
return CombinedScope(asMessageScope(), other.asMessageScope())
|
||||||
}
|
}
|
||||||
@ -200,6 +212,17 @@ public fun Contact?.scopeWithNotNull(other: MessageScope?): MessageScope {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public fun CommandSender?.scopeWithNotNull(other: Contact?): MessageScope {
|
||||||
|
@Suppress("DuplicatedCode")
|
||||||
|
return when {
|
||||||
|
this == null && other == null -> NoopMessageScope
|
||||||
|
this == null && other != null -> other.asMessageScope()
|
||||||
|
this != null && other == null -> this.asMessageScope()
|
||||||
|
this != null && other != null -> CombinedScope(asMessageScope(), other.asMessageScope())
|
||||||
|
else -> null!!
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public fun CommandSender?.scopeWithNotNull(other: CommandSender?): MessageScope {
|
public fun CommandSender?.scopeWithNotNull(other: CommandSender?): MessageScope {
|
||||||
@Suppress("DuplicatedCode")
|
@Suppress("DuplicatedCode")
|
||||||
return when {
|
return when {
|
||||||
@ -222,6 +245,28 @@ public fun CommandSender?.scopeWithNotNull(other: MessageScope?): MessageScope {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public fun MessageScope?.scopeWithNotNull(other: Contact?): MessageScope {
|
||||||
|
@Suppress("DuplicatedCode")
|
||||||
|
return when {
|
||||||
|
this == null && other == null -> NoopMessageScope
|
||||||
|
this == null && other != null -> other.asMessageScope()
|
||||||
|
this != null && other == null -> this.asMessageScope()
|
||||||
|
this != null && other != null -> CombinedScope(asMessageScope(), other.asMessageScope())
|
||||||
|
else -> null!!
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public fun MessageScope?.scopeWithNotNull(other: CommandSender?): MessageScope {
|
||||||
|
@Suppress("DuplicatedCode")
|
||||||
|
return when {
|
||||||
|
this == null && other == null -> NoopMessageScope
|
||||||
|
this == null && other != null -> other.asMessageScope()
|
||||||
|
this != null && other == null -> this.asMessageScope()
|
||||||
|
this != null && other != null -> CombinedScope(asMessageScope(), other.asMessageScope())
|
||||||
|
else -> null!!
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public fun MessageScope?.scopeWithNotNull(other: MessageScope?): MessageScope {
|
public fun MessageScope?.scopeWithNotNull(other: MessageScope?): MessageScope {
|
||||||
@Suppress("DuplicatedCode")
|
@Suppress("DuplicatedCode")
|
||||||
return when {
|
return when {
|
||||||
|
Loading…
Reference in New Issue
Block a user