mirror of
https://github.com/mamoe/mirai.git
synced 2025-01-11 11:00:15 +08:00
Merge remote-tracking branch 'origin/reborn' into reborn
# Conflicts: # backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/plugin/internal/PluginsLoader.kt
This commit is contained in:
commit
9c1b937aaf
@ -0,0 +1,11 @@
|
|||||||
|
/*
|
||||||
|
* 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
|
||||||
|
*/
|
||||||
|
|
||||||
|
package net.mamoe.mirai.console.codegen.setting
|
||||||
|
|
@ -0,0 +1,54 @@
|
|||||||
|
/*
|
||||||
|
* 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
|
||||||
|
*/
|
||||||
|
|
||||||
|
package net.mamoe.mirai.console.codegen
|
||||||
|
|
||||||
|
import java.io.File
|
||||||
|
|
||||||
|
fun codegen(targetFile: String, regionName: String, block: StringBuilder.() -> Unit) {
|
||||||
|
//// region PrimitiveValue CODEGEN START ////
|
||||||
|
//// region PrimitiveValue CODEGEN END ////
|
||||||
|
|
||||||
|
targetFile.findFileSmart().also {
|
||||||
|
println("Codegen target: ${it.absolutePath}")
|
||||||
|
}.apply {
|
||||||
|
writeText(
|
||||||
|
readText()
|
||||||
|
.replace(Regex("""//// region $regionName CODEGEN START ////([\s\S]*?)//// endregion $regionName CODEGEN END ////""")) {
|
||||||
|
val code = StringBuilder().apply(block).toString()
|
||||||
|
"""
|
||||||
|
|//// region $regionName CODEGEN START ////
|
||||||
|
|
|
||||||
|
|$code
|
||||||
|
|
|
||||||
|
|//// endregion $regionName CODEGEN END ////
|
||||||
|
""".trimMargin()
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun String.findFileSmart(): File = kotlin.run {
|
||||||
|
if (contains("/")) { // absolute
|
||||||
|
File(this)
|
||||||
|
} else {
|
||||||
|
val list = File(".").walk().filter { it.name == this }.toList()
|
||||||
|
if (list.isNotEmpty()) return list.single()
|
||||||
|
|
||||||
|
File(".").walk().filter { it.name.contains(this) }.single()
|
||||||
|
}
|
||||||
|
}.also {
|
||||||
|
require(it.exists()) { "file doesn't exist" }
|
||||||
|
}
|
||||||
|
|
||||||
|
fun main() {
|
||||||
|
codegen("Value.kt", "PrimitiveValue") {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -152,7 +152,8 @@ internal class PluginClassLoader(
|
|||||||
}
|
}
|
||||||
pluginsLoader.addClassCache(name, clazz)
|
pluginsLoader.addClassCache(name, clazz)
|
||||||
this.addClassCache(name, clazz)
|
this.addClassCache(name, clazz)
|
||||||
clazz
|
@Suppress("UNNECESSARY_NOT_NULL_ASSERTION")
|
||||||
}!!
|
clazz!! // compiler bug
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -43,7 +43,7 @@ typealias ValueSerializer<T> = KSerializer<Value<T>>
|
|||||||
* - [Char], [String]
|
* - [Char], [String]
|
||||||
*
|
*
|
||||||
* Note: The values are actually *boxed* because of the generic type T.
|
* Note: The values are actually *boxed* because of the generic type T.
|
||||||
* *Primitive* indicates only it is one of the 8 types mentioned above.
|
* *Primitive* indicates only it is one of the 9 types mentioned above.
|
||||||
*/
|
*/
|
||||||
interface PrimitiveValue<T> : Value<T>
|
interface PrimitiveValue<T> : Value<T>
|
||||||
|
|
||||||
|
@ -15,33 +15,33 @@ import net.mamoe.mirai.console.setting.Setting
|
|||||||
import net.mamoe.mirai.console.setting.Value
|
import net.mamoe.mirai.console.setting.Value
|
||||||
import kotlin.reflect.KClass
|
import kotlin.reflect.KClass
|
||||||
import kotlin.reflect.KType
|
import kotlin.reflect.KType
|
||||||
import kotlin.reflect.full.isSubclassOf
|
|
||||||
|
|
||||||
|
|
||||||
@PublishedApi
|
@PublishedApi
|
||||||
@Suppress("UnsafeCall", "SMARTCAST_IMPOSSIBLE")
|
@Suppress("UnsafeCall", "SMARTCAST_IMPOSSIBLE")
|
||||||
internal fun Setting.valueFromKTypeImpl(type: KType): Value<*> {
|
internal fun Setting.valueFromKTypeImpl(type: KType): Value<*> {
|
||||||
require(type.classifier is KClass<*>)
|
val classifier = type.classifier
|
||||||
|
require(classifier is KClass<*>)
|
||||||
|
|
||||||
if (type.classifier.isPrimitiveOrBuiltInSerializableValue()) {
|
if (classifier.isPrimitiveOrBuiltInSerializableValue()) {
|
||||||
TODO("是基础类型, 可以直接创建 ValueImpl. ")
|
TODO("是基础类型, 可以直接创建 ValueImpl. ")
|
||||||
}
|
}
|
||||||
|
|
||||||
// 复合类型
|
// 复合类型
|
||||||
|
|
||||||
when {
|
when {
|
||||||
type.classifier.isSubclassOf(Map::class) -> {
|
classifier == Map::class -> {
|
||||||
|
|
||||||
TODO()
|
TODO()
|
||||||
}
|
}
|
||||||
type.classifier.isSubclassOf(List::class) -> {
|
classifier == List::class -> {
|
||||||
|
|
||||||
TODO()
|
TODO()
|
||||||
}
|
}
|
||||||
type.classifier.isSubclassOf(Set::class) -> {
|
classifier == Set::class -> {
|
||||||
TODO()
|
TODO()
|
||||||
}
|
}
|
||||||
else -> error("Custom composite value is not supported yet (${type.classifier.qualifiedName})")
|
else -> error("Custom composite value is not supported yet (${classifier.qualifiedName})")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user