Optimize codegen

This commit is contained in:
Him188 2020-06-20 23:23:19 +08:00
parent f9132124e7
commit e0c1600001
4 changed files with 16 additions and 16 deletions

View File

@ -53,14 +53,14 @@ class CodegenScope : MutableList<Replacer> by mutableListOf() {
@RegionCodegenDsl
operator fun RegionCodegen.invoke(ktTypes: Collection<KtType>) {
add(Replacer {
it.replace(Regex("""//// region $regionName CODEGEN START ////([\s\S]*?)//// endregion $regionName CODEGEN END ////""")) {
it.replace(Regex("""//// region $regionName CODEGEN ////([\s\S]*?)//// endregion $regionName CODEGEN ////""")) {
val code = CodegenScope().apply { (this@invoke as Codegen).invoke(*ktTypes.toTypedArray()) }.applyTo("")
"""
|//// region $regionName CODEGEN START ////
|//// region $regionName CODEGEN ////
|
|$code
|
|//// endregion $regionName CODEGEN END ////
|//// endregion $regionName CODEGEN ////
""".trimMargin()
}
})

View File

@ -92,8 +92,8 @@ val KtType.lowerCaseName: String get() = this.standardName.toLowerCase()
inline fun kCode(@Language("kt") source: String) = source.trimIndent()
fun codegen(targetFile: String, block: CodegenScope.() -> Unit) {
//// region PrimitiveValue CODEGEN START ////
//// region PrimitiveValue CODEGEN END ////
//// region PrimitiveValue CODEGEN ////
//// region PrimitiveValue CODEGEN ////
targetFile.findFileSmart().also {
println("Codegen target: ${it.absolutePath}")

View File

@ -40,13 +40,13 @@ internal abstract class SettingImpl {
}
//// region Setting.value primitives CODEGEN START ////
//// region Setting.value primitives CODEGEN ////
// TODO: 2020/6/19 CODEGEN
fun Setting.value(value: Int): IntValue = TODO("codegen")
//// endregion Setting.value primitives CODEGEN END ////
//// endregion Setting.value primitives CODEGEN ////
/**

View File

@ -7,7 +7,7 @@
* https://github.com/mamoe/mirai/blob/master/LICENSE
*/
@file:Suppress("INVISIBLE_REFERENCE", "INVISIBLE_MEMBER")
@file:Suppress("INVISIBLE_REFERENCE", "INVISIBLE_MEMBER", "unused")
package net.mamoe.mirai.console.setting
@ -48,7 +48,7 @@ typealias ValueSerializer<T> = KSerializer<Value<T>>
interface PrimitiveValue<T> : Value<T>
//// region PrimitiveValues CODEGEN START ////
//// region PrimitiveValues CODEGEN ////
/**
* Represents a non-null [Byte] value.
@ -96,7 +96,7 @@ interface BooleanValue : PrimitiveValue<Boolean>
interface StringValue : PrimitiveValue<String>
//// endregion PrimitiveValues CODEGEN END ////
//// endregion PrimitiveValues CODEGEN ////
@MiraiExperimentalAPI
@ -120,13 +120,13 @@ interface CompositeListValue<T> : ListValue<Value<T>>
interface PrimitiveListValue<T> : ListValue<T>
//// region PrimitiveListValue CODEGEN START ////
//// region PrimitiveListValue CODEGEN ////
interface PrimitiveIntListValue<T> : PrimitiveListValue<T>
interface PrimitiveLongListValue<T> : PrimitiveListValue<T>
// TODO + codegen
//// endregion PrimitiveListValue CODEGEN END ////
//// endregion PrimitiveListValue CODEGEN ////
/**
@ -147,13 +147,13 @@ interface CompositeSetValue<T> : SetValue<Value<T>>
interface PrimitiveSetValue<T> : SetValue<T>
//// region PrimitiveSetValue CODEGEN START ////
//// region PrimitiveSetValue CODEGEN ////
interface PrimitiveIntSetValue<T> : PrimitiveSetValue<T>
interface PrimitiveLongSetValue<T> : PrimitiveSetValue<T>
// TODO + codegen
//// endregion PrimitiveSetValue CODEGEN END ////
//// endregion PrimitiveSetValue CODEGEN ////
/**
@ -166,13 +166,13 @@ interface CompositeMapValue<K, V> : MapValue<Value<K>, Value<V>>
interface PrimitiveMapValue<K, V> : MapValue<K, V>
//// region PrimitiveMapValue CODEGEN START ////
//// region PrimitiveMapValue CODEGEN ////
interface PrimitiveIntIntMapValue : PrimitiveMapValue<Int, Int>
interface PrimitiveIntLongMapValue : PrimitiveMapValue<Int, Long>
// TODO + codegen
//// endregion PrimitiveSetValue CODEGEN END ////
//// endregion PrimitiveSetValue CODEGEN ////