mirror of
https://github.com/mamoe/mirai.git
synced 2025-03-26 07:20:09 +08:00
Add contract for MessageScope extensions
This commit is contained in:
parent
2f0972296c
commit
80fa25c316
mirai-console/backend
@ -1,10 +1,10 @@
|
||||
/*
|
||||
* Copyright 2019-2021 Mamoe Technologies and contributors.
|
||||
* Copyright 2019-2022 Mamoe Technologies and contributors.
|
||||
*
|
||||
* 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证.
|
||||
* Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link.
|
||||
* 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证.
|
||||
* Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link.
|
||||
*
|
||||
* https://github.com/mamoe/mirai/blob/master/LICENSE
|
||||
* https://github.com/mamoe/mirai/blob/dev/LICENSE
|
||||
*/
|
||||
|
||||
package net.mamoe.mirai.console.codegen
|
||||
@ -151,6 +151,7 @@ internal object MessageScopeCodegen {
|
||||
appendKCode(
|
||||
"""
|
||||
public inline fun <R> ${a}?.scopeWith(vararg others: ${b}?, action: MessageScope.() -> R): R {
|
||||
contract { callsInPlace(action, InvocationKind.EXACTLY_ONCE) }
|
||||
return scopeWith(*others).invoke(action)
|
||||
}
|
||||
"""
|
||||
@ -182,7 +183,10 @@ internal object MessageScopeCodegen {
|
||||
"net.mamoe.mirai.console.util.invoke",
|
||||
)
|
||||
) // diagnostic deprecation
|
||||
public inline fun <R> ${a}.scopeWith(action: MessageScope.() -> R): R = asMessageScope()(action)
|
||||
public inline fun <R> ${a}.scopeWith(action: MessageScope.() -> R): R {
|
||||
contract { callsInPlace(action, InvocationKind.EXACTLY_ONCE) }
|
||||
return asMessageScope()(action)
|
||||
}
|
||||
"""
|
||||
)
|
||||
appendLine()
|
||||
|
@ -1,10 +1,10 @@
|
||||
/*
|
||||
* Copyright 2019-2021 Mamoe Technologies and contributors.
|
||||
* Copyright 2019-2022 Mamoe Technologies and contributors.
|
||||
*
|
||||
* 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证.
|
||||
* Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link.
|
||||
* 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证.
|
||||
* Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link.
|
||||
*
|
||||
* https://github.com/mamoe/mirai/blob/master/LICENSE
|
||||
* https://github.com/mamoe/mirai/blob/dev/LICENSE
|
||||
*/
|
||||
|
||||
@file:Suppress(
|
||||
@ -22,6 +22,8 @@ import net.mamoe.mirai.console.command.CommandSender
|
||||
import net.mamoe.mirai.contact.Contact
|
||||
import net.mamoe.mirai.contact.User
|
||||
import net.mamoe.mirai.message.data.Message
|
||||
import kotlin.contracts.InvocationKind
|
||||
import kotlin.contracts.contract
|
||||
import kotlin.internal.LowPriorityInOverloadResolution
|
||||
|
||||
/**
|
||||
@ -290,38 +292,47 @@ public fun MessageScope?.scopeWith(other: MessageScope?): MessageScope {
|
||||
}
|
||||
|
||||
public inline fun <R> Contact?.scopeWith(vararg others: Contact?, action: MessageScope.() -> R): R {
|
||||
contract { callsInPlace(action, InvocationKind.EXACTLY_ONCE) }
|
||||
return scopeWith(*others).invoke(action)
|
||||
}
|
||||
|
||||
public inline fun <R> Contact?.scopeWith(vararg others: CommandSender?, action: MessageScope.() -> R): R {
|
||||
contract { callsInPlace(action, InvocationKind.EXACTLY_ONCE) }
|
||||
return scopeWith(*others).invoke(action)
|
||||
}
|
||||
|
||||
public inline fun <R> Contact?.scopeWith(vararg others: MessageScope?, action: MessageScope.() -> R): R {
|
||||
contract { callsInPlace(action, InvocationKind.EXACTLY_ONCE) }
|
||||
return scopeWith(*others).invoke(action)
|
||||
}
|
||||
|
||||
public inline fun <R> CommandSender?.scopeWith(vararg others: Contact?, action: MessageScope.() -> R): R {
|
||||
contract { callsInPlace(action, InvocationKind.EXACTLY_ONCE) }
|
||||
return scopeWith(*others).invoke(action)
|
||||
}
|
||||
|
||||
public inline fun <R> CommandSender?.scopeWith(vararg others: CommandSender?, action: MessageScope.() -> R): R {
|
||||
contract { callsInPlace(action, InvocationKind.EXACTLY_ONCE) }
|
||||
return scopeWith(*others).invoke(action)
|
||||
}
|
||||
|
||||
public inline fun <R> CommandSender?.scopeWith(vararg others: MessageScope?, action: MessageScope.() -> R): R {
|
||||
contract { callsInPlace(action, InvocationKind.EXACTLY_ONCE) }
|
||||
return scopeWith(*others).invoke(action)
|
||||
}
|
||||
|
||||
public inline fun <R> MessageScope?.scopeWith(vararg others: Contact?, action: MessageScope.() -> R): R {
|
||||
contract { callsInPlace(action, InvocationKind.EXACTLY_ONCE) }
|
||||
return scopeWith(*others).invoke(action)
|
||||
}
|
||||
|
||||
public inline fun <R> MessageScope?.scopeWith(vararg others: CommandSender?, action: MessageScope.() -> R): R {
|
||||
contract { callsInPlace(action, InvocationKind.EXACTLY_ONCE) }
|
||||
return scopeWith(*others).invoke(action)
|
||||
}
|
||||
|
||||
public inline fun <R> MessageScope?.scopeWith(vararg others: MessageScope?, action: MessageScope.() -> R): R {
|
||||
contract { callsInPlace(action, InvocationKind.EXACTLY_ONCE) }
|
||||
return scopeWith(*others).invoke(action)
|
||||
}
|
||||
|
||||
@ -351,7 +362,10 @@ public inline fun MessageScope.scopeWith(): MessageScope = asMessageScope()
|
||||
"net.mamoe.mirai.console.util.invoke",
|
||||
)
|
||||
) // diagnostic deprecation
|
||||
public inline fun <R> Contact.scopeWith(action: MessageScope.() -> R): R = asMessageScope()(action)
|
||||
public inline fun <R> Contact.scopeWith(action: MessageScope.() -> R): R {
|
||||
contract { callsInPlace(action, InvocationKind.EXACTLY_ONCE) }
|
||||
return asMessageScope()(action)
|
||||
}
|
||||
|
||||
@Deprecated(
|
||||
"Senseless scopeWith. Use .asMessageScope().invoke.",
|
||||
@ -361,7 +375,10 @@ public inline fun <R> Contact.scopeWith(action: MessageScope.() -> R): R = asMes
|
||||
"net.mamoe.mirai.console.util.invoke",
|
||||
)
|
||||
) // diagnostic deprecation
|
||||
public inline fun <R> CommandSender.scopeWith(action: MessageScope.() -> R): R = asMessageScope()(action)
|
||||
public inline fun <R> CommandSender.scopeWith(action: MessageScope.() -> R): R {
|
||||
contract { callsInPlace(action, InvocationKind.EXACTLY_ONCE) }
|
||||
return asMessageScope()(action)
|
||||
}
|
||||
|
||||
@Deprecated(
|
||||
"Senseless scopeWith. Use .asMessageScope().invoke.",
|
||||
@ -371,7 +388,10 @@ public inline fun <R> CommandSender.scopeWith(action: MessageScope.() -> R): R =
|
||||
"net.mamoe.mirai.console.util.invoke",
|
||||
)
|
||||
) // diagnostic deprecation
|
||||
public inline fun <R> MessageScope.scopeWith(action: MessageScope.() -> R): R = asMessageScope()(action)
|
||||
public inline fun <R> MessageScope.scopeWith(action: MessageScope.() -> R): R {
|
||||
contract { callsInPlace(action, InvocationKind.EXACTLY_ONCE) }
|
||||
return asMessageScope()(action)
|
||||
}
|
||||
|
||||
//// endregion MessageScopeBuilders CODEGEN ////
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user