diff --git a/backend/mirai-console/build.gradle.kts b/backend/mirai-console/build.gradle.kts index f0b36a941..188201994 100644 --- a/backend/mirai-console/build.gradle.kts +++ b/backend/mirai-console/build.gradle.kts @@ -39,6 +39,8 @@ dependencies { compileAndTestRuntime(`kotlinx-serialization-json`) compileAndTestRuntime(`kotlin-reflect`) + implementation(project(":mirai-console-compiler-annotations")) + smartImplementation(yamlkt) smartImplementation(`jetbrains-annotations`) smartImplementation(`caller-finder`) diff --git a/settings.gradle.kts b/settings.gradle.kts index c69c29bf2..3dc506d99 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -1,3 +1,12 @@ +/* + * Copyright 2019-2021 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 + */ + pluginManagement { repositories { mavenLocal() @@ -17,6 +26,7 @@ fun includeProject(projectPath: String, path: String? = null) { if (path != null) project(projectPath).projectDir = file(path) } +includeProject(":mirai-console-compiler-annotations", "tools/compiler-annotations") includeProject(":mirai-console", "backend/mirai-console") includeProject(":mirai-console.codegen", "backend/codegen") includeProject(":mirai-console-terminal", "frontend/mirai-console-terminal") diff --git a/tools/compiler-annotations/README.md b/tools/compiler-annotations/README.md new file mode 100644 index 000000000..ddafb773e --- /dev/null +++ b/tools/compiler-annotations/README.md @@ -0,0 +1,5 @@ +# mirai-console-compiler-common + +Mirai Console 编译器注解模块。 + +提供 `ResolveContext` 和 `RestrictedScope`,帮助 [IntelliJ 插件](../intellij-plugin) 进行语境推断。 \ No newline at end of file diff --git a/tools/compiler-annotations/build.gradle.kts b/tools/compiler-annotations/build.gradle.kts new file mode 100644 index 000000000..df49450bd --- /dev/null +++ b/tools/compiler-annotations/build.gradle.kts @@ -0,0 +1,26 @@ +/* + * Copyright 2019-2021 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("UnusedImport") + +plugins { + kotlin("jvm") + id("java") + `maven-publish` + id("com.jfrog.bintray") +} + +version = Versions.console +description = "Mirai Console compiler annotations" + +kotlin { + explicitApi() +} + +configurePublishing("mirai-console-compiler-annotations") \ No newline at end of file diff --git a/backend/mirai-console/src/compiler/common/ResolveContext.kt b/tools/compiler-annotations/src/ResolveContext.kt similarity index 60% rename from backend/mirai-console/src/compiler/common/ResolveContext.kt rename to tools/compiler-annotations/src/ResolveContext.kt index 592c2179f..0646d9db0 100644 --- a/backend/mirai-console/src/compiler/common/ResolveContext.kt +++ b/tools/compiler-annotations/src/ResolveContext.kt @@ -1,22 +1,16 @@ /* - * Copyright 2019-2020 Mamoe Technologies and contributors. + * Copyright 2019-2021 Mamoe Technologies and contributors. * - * 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证. - * Use of this source code is governed by the GNU AFFERO GENERAL PUBLIC LICENSE version 3 license that can be found through the following link. + * 此源代码的使用受 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 + * https://github.com/mamoe/mirai/blob/master/LICENSE */ @file:Suppress("unused") package net.mamoe.mirai.console.compiler.common -import net.mamoe.mirai.console.command.Command -import net.mamoe.mirai.console.data.PluginData -import net.mamoe.mirai.console.data.value -import net.mamoe.mirai.console.permission.PermissionId -import net.mamoe.mirai.console.plugin.description.PluginDescription -import net.mamoe.mirai.console.util.SemVersion import kotlin.annotation.AnnotationTarget.* /** @@ -41,53 +35,57 @@ public annotation class ResolveContext( */ /** - * @see PluginDescription.id + * PluginDescription.id */ PLUGIN_ID, // ILLEGAL_PLUGIN_DESCRIPTION /** - * @see PluginDescription.name + * PluginDescription.name */ PLUGIN_NAME, // ILLEGAL_PLUGIN_DESCRIPTION /** - * @see PluginDescription.version - * @see SemVersion.Companion.invoke + * PluginDescription.version + * SemVersion.Companion.invoke */ SEMANTIC_VERSION, // ILLEGAL_PLUGIN_DESCRIPTION /** - * @see SemVersion.Companion.parseRangeRequirement + * SemVersion.Companion.parseRangeRequirement */ VERSION_REQUIREMENT, // ILLEGAL_VERSION_REQUIREMENT /** - * @see Command.allNames + * Command.allNames */ COMMAND_NAME, // ILLEGAL_COMMAND_NAME /** - * @see PermissionId.name + * PermissionId.name */ PERMISSION_NAMESPACE, // ILLEGAL_PERMISSION_NAMESPACE /** - * @see PermissionId.name + * PermissionId.name */ PERMISSION_NAME, // ILLEGAL_PERMISSION_NAME /** - * @see PermissionId.parseFromString + * PermissionId.parseFromString */ PERMISSION_ID, // ILLEGAL_PERMISSION_ID /** * 标注一个泛型, 要求这个泛型必须拥有一个公开无参 (或所有参数都可选) 构造器. * - * @see PluginData.value + * PluginData.value */ RESTRICTED_NO_ARG_CONSTRUCTOR, // NOT_CONSTRUCTABLE_TYPE - RESTRICTED_CONSOLE_COMMAND_OWNER, + RESTRICTED_CONSOLE_COMMAND_OWNER, ; + + public companion object } + + public companion object } \ No newline at end of file diff --git a/backend/mirai-console/src/compiler/common/RestrictedScope.kt b/tools/compiler-annotations/src/RestrictedScope.kt similarity index 50% rename from backend/mirai-console/src/compiler/common/RestrictedScope.kt rename to tools/compiler-annotations/src/RestrictedScope.kt index f4f4f1215..76957864d 100644 --- a/backend/mirai-console/src/compiler/common/RestrictedScope.kt +++ b/tools/compiler-annotations/src/RestrictedScope.kt @@ -1,21 +1,21 @@ /* - * Copyright 2019-2020 Mamoe Technologies and contributors. + * Copyright 2019-2021 Mamoe Technologies and contributors. * - * 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证. - * Use of this source code is governed by the GNU AFFERO GENERAL PUBLIC LICENSE version 3 license that can be found through the following link. + * 此源代码的使用受 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 + * https://github.com/mamoe/mirai/blob/master/LICENSE */ package net.mamoe.mirai.console.compiler.common -import net.mamoe.mirai.console.util.ConsoleExperimentalApi import kotlin.annotation.AnnotationTarget.FUNCTION /** * 标记一个函数, 在其函数体内限制特定一些函数的使用. + * + * @suppress 这是实验性 API, 可能会在未来有不兼容变更 */ -@ConsoleExperimentalApi @Target(FUNCTION) @Retention(AnnotationRetention.BINARY) public annotation class RestrictedScope( diff --git a/tools/compiler-common/build.gradle.kts b/tools/compiler-common/build.gradle.kts index b5226274c..1de7b5722 100644 --- a/tools/compiler-common/build.gradle.kts +++ b/tools/compiler-common/build.gradle.kts @@ -21,14 +21,15 @@ repositories { } version = Versions.console -description = "Mirai Console compiler common" +description = "Mirai Console compiler resolve" dependencies { api(`jetbrains-annotations`) // api(`kotlinx-coroutines-jdk8`) + api(project(":mirai-console-compiler-annotations")) compileOnly(`kotlin-compiler`) testRuntimeOnly(`kotlin-compiler`) } -configurePublishing("mirai-console-compiler-common") \ No newline at end of file +configurePublishing("mirai-console-compiler-resolve") \ No newline at end of file diff --git a/tools/compiler-common/src/resolve/resolveTypes.kt b/tools/compiler-common/src/resolve/resolveTypes.kt index 1fd39b20e..75086447d 100644 --- a/tools/compiler-common/src/resolve/resolveTypes.kt +++ b/tools/compiler-common/src/resolve/resolveTypes.kt @@ -1,16 +1,17 @@ /* - * Copyright 2019-2020 Mamoe Technologies and contributors. + * Copyright 2019-2021 Mamoe Technologies and contributors. * - * 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证. - * Use of this source code is governed by the GNU AFFERO GENERAL PUBLIC LICENSE version 3 license that can be found through the following link. + * 此源代码的使用受 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 + * https://github.com/mamoe/mirai/blob/master/LICENSE */ @file:Suppress("unused") package net.mamoe.mirai.console.compiler.common.resolve +import net.mamoe.mirai.console.compiler.common.ResolveContext import net.mamoe.mirai.console.compiler.common.castOrNull import net.mamoe.mirai.console.compiler.common.firstValue import org.jetbrains.kotlin.descriptors.annotations.Annotated @@ -60,27 +61,9 @@ val RESOLVE_CONTEXT_FQ_NAME = FqName("net.mamoe.mirai.console.compiler.common.Re /** * net.mamoe.mirai.console.compiler.common.ResolveContext.Kind */ -enum class ResolveContextKind { - PLUGIN_ID, - PLUGIN_NAME, - SEMANTIC_VERSION, +typealias ResolveContextKind = ResolveContext.Kind - VERSION_REQUIREMENT, - - COMMAND_NAME, - - PERMISSION_NAMESPACE, - PERMISSION_NAME, - PERMISSION_ID, - - RESTRICTED_NO_ARG_CONSTRUCTOR, - RESTRICTED_CONSOLE_COMMAND_OWNER, - ; - - companion object { - fun valueOfOrNull(string: String) = values().find { it.name == string } - } -} +fun ResolveContext.Kind.Companion.valueOfOrNull(string: String) = ResolveContext.Kind.values().find { it.name == string } val Annotated.resolveContextKinds: List? get() { diff --git a/tools/gradle-plugin/src/VersionConstants.kt b/tools/gradle-plugin/src/VersionConstants.kt index f7b4c78d9..8d629fbd9 100644 --- a/tools/gradle-plugin/src/VersionConstants.kt +++ b/tools/gradle-plugin/src/VersionConstants.kt @@ -10,6 +10,6 @@ package net.mamoe.mirai.console.gradle internal object VersionConstants { - const val CONSOLE_VERSION = "2.2.0-dev-5" // value is written here automatically during build - const val CORE_VERSION = "2.2.0-dev-5" // value is written here automatically during build + const val CONSOLE_VERSION = "2.2.0-dev-6" // value is written here automatically during build + const val CORE_VERSION = "2.2.0-dev-6" // value is written here automatically during build } \ No newline at end of file