From 21428094a81221f3139a4ab1542ebf6fb07fac40 Mon Sep 17 00:00:00 2001 From: Him188 Date: Tue, 17 Nov 2020 09:48:45 +0800 Subject: [PATCH] Fix StringConstant.toString and add notes for AbstractCommandValueParameter implementers --- .../src/command/descriptor/CommandParameter.kt | 6 +++--- .../src/command/descriptor/CommandSignature.kt | 4 ++-- backend/mirai-console/test/command/TestCommand.kt | 4 ++-- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/backend/mirai-console/src/command/descriptor/CommandParameter.kt b/backend/mirai-console/src/command/descriptor/CommandParameter.kt index 01f4b3533..732c56567 100644 --- a/backend/mirai-console/src/command/descriptor/CommandParameter.kt +++ b/backend/mirai-console/src/command/descriptor/CommandParameter.kt @@ -208,6 +208,8 @@ public sealed class AbstractCommandValueParameter : CommandValueParameter, public override val isVararg: Boolean, public override val type: KType, ) : AbstractCommandValueParameter() { + override fun toString(): String = super.toString() + init { requireNotNull(type.classifierAsKClassOrNull()) { "type.classifier must be KClass." @@ -237,7 +239,5 @@ public sealed class AbstractCommandValueParameter : CommandValueParameter, * Extended by [CommandValueArgumentParser] */ @ConsoleExperimentalApi - public abstract class Extended : AbstractCommandValueParameter() { - abstract override fun toString(): String - } + public abstract class Extended : AbstractCommandValueParameter() // For implementer: take care of toString() } \ No newline at end of file diff --git a/backend/mirai-console/src/command/descriptor/CommandSignature.kt b/backend/mirai-console/src/command/descriptor/CommandSignature.kt index efeb4618b..777a97c67 100644 --- a/backend/mirai-console/src/command/descriptor/CommandSignature.kt +++ b/backend/mirai-console/src/command/descriptor/CommandSignature.kt @@ -58,9 +58,9 @@ public abstract class AbstractCommandSignature : CommandSignature { override fun toString(): String { val receiverParameter = receiverParameter return if (receiverParameter == null) { - "CommandSignatureVariant(${valueParameters.joinToString()})" + "CommandSignature(${valueParameters.joinToString()})" } else { - "CommandSignatureVariant($receiverParameter, ${valueParameters.joinToString()})" + "CommandSignature($receiverParameter, ${valueParameters.joinToString()})" } } } diff --git a/backend/mirai-console/test/command/TestCommand.kt b/backend/mirai-console/test/command/TestCommand.kt index 82d7e524a..7b93718b8 100644 --- a/backend/mirai-console/test/command/TestCommand.kt +++ b/backend/mirai-console/test/command/TestCommand.kt @@ -181,8 +181,8 @@ internal class TestCommand { @Test fun `composite command descriptors`() { val overloads = TestCompositeCommand.overloads - assertEquals("CommandSignatureVariant(, seconds: Int = ...)", overloads[0].toString()) - assertEquals("CommandSignatureVariant(, target: Long, seconds: Int)", overloads[1].toString()) + assertEquals("CommandSignature(, seconds: Int = ...)", overloads[0].toString()) + assertEquals("CommandSignature(, target: Long, seconds: Int)", overloads[1].toString()) } @Test