This commit is contained in:
Him188 2020-10-22 13:40:22 +08:00
parent fa43f2689c
commit 4c30e3d9d7
3 changed files with 15 additions and 0 deletions

View File

@ -12,6 +12,9 @@ import net.mamoe.mirai.console.util.cast
import net.mamoe.mirai.console.util.safeCast
import java.util.*
/**
* Builtin implementation of [CommandCallResolver]
*/
@ConsoleExperimentalApi
@ExperimentalCommandDescriptors
public object BuiltInCommandCallResolver : CommandCallResolver {

View File

@ -11,9 +11,13 @@ package net.mamoe.mirai.console.command.resolve
import net.mamoe.mirai.console.command.descriptor.ExperimentalCommandDescriptors
import net.mamoe.mirai.console.command.parse.CommandCall
import net.mamoe.mirai.console.extensions.CommandCallResolverProvider
/**
* The resolver converting a [CommandCall] into [ResolvedCommandCall] based on registered []
*
* @see CommandCallResolverProvider The provider to instances of this class
* @see BuiltInCommandCallResolver The builtin implementation
*/
@ExperimentalCommandDescriptors
public interface CommandCallResolver {

View File

@ -11,6 +11,10 @@ package net.mamoe.mirai.console.util
import kotlin.contracts.contract
/**
* Perform `this as? T`.
*/
@JvmSynthetic
public inline fun <reified T : Any> Any?.safeCast(): T? {
contract {
returnsNotNull() implies (this@safeCast is T)
@ -18,6 +22,10 @@ public inline fun <reified T : Any> Any?.safeCast(): T? {
return this as? T
}
/**
* Perform `this as T`.
*/
@JvmSynthetic
public inline fun <reified T : Any> Any?.cast(): T {
contract {
returns() implies (this@cast is T)