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 net.mamoe.mirai.console.util.safeCast
import java.util.* import java.util.*
/**
* Builtin implementation of [CommandCallResolver]
*/
@ConsoleExperimentalApi @ConsoleExperimentalApi
@ExperimentalCommandDescriptors @ExperimentalCommandDescriptors
public object BuiltInCommandCallResolver : CommandCallResolver { 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.descriptor.ExperimentalCommandDescriptors
import net.mamoe.mirai.console.command.parse.CommandCall 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 [] * 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 @ExperimentalCommandDescriptors
public interface CommandCallResolver { public interface CommandCallResolver {

View File

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