mirror of
https://github.com/LamGC/ScalaBot.git
synced 2025-07-01 12:57:24 +00:00
refactor(utils): 加强 getPriority 方法的优先值判断.
加强优先级判断, 有利于后续使用时防止出现意外情况的问题. 顺便补充一手单元测试.
This commit is contained in:
@ -56,9 +56,14 @@ internal fun File.deepListFiles(
|
||||
* @return 获取 Finder 的优先级.
|
||||
* @throws NoSuchFieldException 如果 Finder 没有添加 [FinderRules] 注解时抛出该异常.
|
||||
*/
|
||||
internal fun ExtensionPackageFinder.getPriority() =
|
||||
this::class.java.getDeclaredAnnotation(FinderRules::class.java)?.priority
|
||||
internal fun ExtensionPackageFinder.getPriority(): Int {
|
||||
val value = this::class.java.getDeclaredAnnotation(FinderRules::class.java)?.priority
|
||||
?: throw NoSuchFieldException("Finder did not add `FinderRules` annotation")
|
||||
if (value < 0) {
|
||||
throw IllegalArgumentException("Priority cannot be lower than 0. (Class: ${this::class.java})")
|
||||
}
|
||||
return value
|
||||
}
|
||||
|
||||
/**
|
||||
* 为 [AutoCloseable] 对象注册 Jvm Shutdown 钩子.
|
||||
|
Reference in New Issue
Block a user