API stabilization:

Extract ExtensionPoint;
Rename ExtensionPoint.extensionType;
Declare ExtensionPoint stable;
Improve ExtensionException
This commit is contained in:
Him188 2020-09-12 21:17:08 +08:00
parent 87373ef3ba
commit 65cba4fd0b
3 changed files with 30 additions and 40 deletions

View File

@ -154,7 +154,7 @@ internal abstract class AbstractConcurrentComponentStorage : ComponentStorage {
throwable: Throwable, throwable: Throwable,
) { ) {
throw ExtensionException( throw ExtensionException(
"Exception while executing extension ${extension.kClassQualifiedNameOrTip} provided by plugin '${plugin.name}', registered for ${this.type.qualifiedName}", "Exception while executing extension '${extension.kClassQualifiedNameOrTip}' provided by plugin '${plugin.name}', registered for '${this.extensionType.qualifiedName}'",
throwable throwable
) )
} }

View File

@ -0,0 +1,22 @@
/*
* Copyright 2020 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.
*
* https://github.com/mamoe/mirai/blob/master/LICENSE
*/
@file:Suppress("unused")
package net.mamoe.mirai.console.extension
/**
* 在调用一个 extension 时遇到的异常.
*/
public open class ExtensionException : RuntimeException {
public constructor() : super()
public constructor(message: String?) : super(message)
public constructor(message: String?, cause: Throwable?) : super(message, cause)
public constructor(cause: Throwable?) : super(cause)
}

View File

@ -11,52 +11,20 @@
package net.mamoe.mirai.console.extension package net.mamoe.mirai.console.extension
import net.mamoe.mirai.console.plugin.loader.PluginLoader
import net.mamoe.mirai.console.util.ConsoleExperimentalApi
import kotlin.reflect.KClass import kotlin.reflect.KClass
import kotlin.reflect.full.isSubclassOf
@ConsoleExperimentalApi /**
* [Extension] `companion` 实现.
*/
public interface ExtensionPoint<T : Extension> { public interface ExtensionPoint<T : Extension> {
public val type: KClass<T> public val extensionType: KClass<T>
public companion object {
@JvmStatic
@JvmSynthetic
@ConsoleExperimentalApi
public inline fun <reified T : Extension> ExtensionPoint<*>.isFor(exactType: Boolean = false): Boolean {
return if (exactType) {
T::class == type
} else T::class.isSubclassOf(type)
}
}
} }
@ConsoleExperimentalApi
public interface SingletonExtensionPoint<T : SingletonExtension<*>> : ExtensionPoint<T>
/**
* 表示一个扩展点
*/
@ConsoleExperimentalApi
public open class AbstractExtensionPoint<T : Extension>( public open class AbstractExtensionPoint<T : Extension>(
@ConsoleExperimentalApi public override val extensionType: KClass<T>,
public override val type: KClass<T>,
) : ExtensionPoint<T> ) : ExtensionPoint<T>
/** /**
* 在调用一个 extension 时遇到的异常. * 表示一个 [SingletonExtension] [ExtensionPoint]
*
* @see PluginLoader.load
* @see PluginLoader.enable
* @see PluginLoader.disable
* @see PluginLoader.description
*/ */
@ConsoleExperimentalApi public interface SingletonExtensionPoint<T : SingletonExtension<*>> : ExtensionPoint<T>
public open class ExtensionException : RuntimeException {
public constructor() : super()
public constructor(message: String?) : super(message)
public constructor(message: String?, cause: Throwable?) : super(message, cause)
public constructor(cause: Throwable?) : super(cause)
}