diff --git a/backend/mirai-console/src/internal/MiraiConsoleBuildConstants.kt b/backend/mirai-console/src/internal/MiraiConsoleBuildConstants.kt index 418852398..141cb973b 100644 --- a/backend/mirai-console/src/internal/MiraiConsoleBuildConstants.kt +++ b/backend/mirai-console/src/internal/MiraiConsoleBuildConstants.kt @@ -14,8 +14,8 @@ import java.time.Instant internal object MiraiConsoleBuildConstants { // auto-filled on build (task :mirai-console:fillBuildConstants) @JvmStatic - val buildDate: Instant = Instant.ofEpochSecond(1604041264) - const val versionConst: String = "1.0-RC-1" + val buildDate: Instant = Instant.ofEpochSecond(1605147625) + const val versionConst: String = "1.0-RC2-dev-4" @JvmStatic val version: SemVersion = SemVersion(versionConst) diff --git a/tools/intellij-plugin/run/projects/test-project/src/main/kotlin/org/example/myplugin/MyPluginMain.kt b/tools/intellij-plugin/run/projects/test-project/src/main/kotlin/org/example/myplugin/MyPluginMain.kt index ca1f36d57..34a50f190 100644 --- a/tools/intellij-plugin/run/projects/test-project/src/main/kotlin/org/example/myplugin/MyPluginMain.kt +++ b/tools/intellij-plugin/run/projects/test-project/src/main/kotlin/org/example/myplugin/MyPluginMain.kt @@ -2,6 +2,7 @@ package org.example.myplugin import kotlinx.serialization.Serializable import net.mamoe.mirai.console.data.AutoSavePluginConfig +import net.mamoe.mirai.console.data.AutoSavePluginData import net.mamoe.mirai.console.data.value import net.mamoe.mirai.console.permission.PermissionId import net.mamoe.mirai.console.permission.PermissionService @@ -29,3 +30,9 @@ object MyPluginMain : KotlinPlugin( } } + + +object MyData : AutoSavePluginData("") { + val value by value("") + val value2 by value>() +} \ No newline at end of file diff --git a/tools/intellij-plugin/src/diagnostics/PluginDataValuesChecker.kt b/tools/intellij-plugin/src/diagnostics/PluginDataValuesChecker.kt index 7eb1c0f6b..e05db2e83 100644 --- a/tools/intellij-plugin/src/diagnostics/PluginDataValuesChecker.kt +++ b/tools/intellij-plugin/src/diagnostics/PluginDataValuesChecker.kt @@ -18,10 +18,12 @@ import org.jetbrains.kotlin.descriptors.ClassDescriptor import org.jetbrains.kotlin.descriptors.DeclarationDescriptor import org.jetbrains.kotlin.idea.inspections.collections.isCalling import org.jetbrains.kotlin.idea.refactoring.fqName.fqName +import org.jetbrains.kotlin.js.descriptorUtils.getJetTypeFqName import org.jetbrains.kotlin.psi.KtDeclaration import org.jetbrains.kotlin.resolve.checkers.DeclarationChecker import org.jetbrains.kotlin.resolve.checkers.DeclarationCheckerContext import org.jetbrains.kotlin.types.SimpleType +import org.jetbrains.kotlinx.serialization.compiler.resolve.* class PluginDataValuesChecker : DeclarationChecker { @@ -39,26 +41,78 @@ class PluginDataValuesChecker : DeclarationChecker { && t is SimpleType }.forEach { (e, callExpr) -> val (_, type) = e - val classDescriptor = type.constructor.declarationDescriptor?.castOrNull() + val classDescriptor = type.constructor.declarationDescriptor?.castOrNull() ?: return@forEach + + if (canBeSerializedInternally(classDescriptor)) return@forEach val inspectionTarget = kotlin.run { val fqName = type.fqName ?: return@run null callExpr.typeArguments.find { it.typeReference?.isReferencing(fqName) == true } } ?: return@forEach - if (classDescriptor == null - || !classDescriptor.hasNoArgConstructor() - ) return@forEach context.report(MiraiConsoleErrors.NOT_CONSTRUCTABLE_TYPE.on( - inspectionTarget, - callExpr, - type.fqName?.asString().toString()) - ) + if (!classDescriptor.hasNoArgConstructor()) + return@forEach context.report(MiraiConsoleErrors.NOT_CONSTRUCTABLE_TYPE.on( + inspectionTarget, + callExpr, + type.fqName?.asString().toString()) + ) - if (!classDescriptor.hasAnnotation(SERIALIZABLE_FQ_NAME)) // TODO: 2020/9/18 external serializers + if (!classDescriptor.hasAnnotation(SERIALIZABLE_FQ_NAME)) return@forEach context.report(MiraiConsoleErrors.UNSERIALIZABLE_TYPE.on( inspectionTarget, classDescriptor )) } } -} \ No newline at end of file +} + +private fun canBeSerializedInternally(descriptor: ClassDescriptor): Boolean { + @Suppress("UNUSED_VARIABLE") val name = when (descriptor.defaultType.getJetTypeFqName(false)) { + "kotlin.Unit" -> "UnitSerializer" + "Z", "kotlin.Boolean" -> "BooleanSerializer" + "B", "kotlin.Byte" -> "ByteSerializer" + "S", "kotlin.Short" -> "ShortSerializer" + "I", "kotlin.Int" -> "IntSerializer" + "J", "kotlin.Long" -> "LongSerializer" + "F", "kotlin.Float" -> "FloatSerializer" + "D", "kotlin.Double" -> "DoubleSerializer" + "C", "kotlin.Char" -> "CharSerializer" + "kotlin.String" -> "StringSerializer" + "kotlin.Pair" -> "PairSerializer" + "kotlin.Triple" -> "TripleSerializer" + "kotlin.collections.Collection", "kotlin.collections.List", + "kotlin.collections.ArrayList", "kotlin.collections.MutableList", + -> "ArrayListSerializer" + "kotlin.collections.Set", "kotlin.collections.LinkedHashSet", "kotlin.collections.MutableSet" -> "LinkedHashSetSerializer" + "kotlin.collections.HashSet" -> "HashSetSerializer" + "kotlin.collections.Map", "kotlin.collections.LinkedHashMap", "kotlin.collections.MutableMap" -> "LinkedHashMapSerializer" + "kotlin.collections.HashMap" -> "HashMapSerializer" + "kotlin.collections.Map.Entry" -> "MapEntrySerializer" + "kotlin.ByteArray" -> "ByteArraySerializer" + "kotlin.ShortArray" -> "ShortArraySerializer" + "kotlin.IntArray" -> "IntArraySerializer" + "kotlin.LongArray" -> "LongArraySerializer" + "kotlin.CharArray" -> "CharArraySerializer" + "kotlin.FloatArray" -> "FloatArraySerializer" + "kotlin.DoubleArray" -> "DoubleArraySerializer" + "kotlin.BooleanArray" -> "BooleanArraySerializer" + "java.lang.Boolean" -> "BooleanSerializer" + "java.lang.Byte" -> "ByteSerializer" + "java.lang.Short" -> "ShortSerializer" + "java.lang.Integer" -> "IntSerializer" + "java.lang.Long" -> "LongSerializer" + "java.lang.Float" -> "FloatSerializer" + "java.lang.Double" -> "DoubleSerializer" + "java.lang.Character" -> "CharSerializer" + "java.lang.String" -> "StringSerializer" + "java.util.Collection", "java.util.List", "java.util.ArrayList" -> "ArrayListSerializer" + "java.util.Set", "java.util.LinkedHashSet" -> "LinkedHashSetSerializer" + "java.util.HashSet" -> "HashSetSerializer" + "java.util.Map", "java.util.LinkedHashMap" -> "LinkedHashMapSerializer" + "java.util.HashMap" -> "HashMapSerializer" + "java.util.Map.Entry" -> "MapEntrySerializer" + else -> return false + } + return true +} +