From 6c84df87e942d25842e5423313a9d723c5b8c748 Mon Sep 17 00:00:00 2001 From: godotg Date: Sun, 7 Jul 2024 13:35:48 +0800 Subject: [PATCH] ref[kotlin]: refactor kotlin protocol --- .../protocol/serializer/kotlin/CodeGenerateKotlin.java | 8 ++++---- .../main/resources/kotlin/ProtocolRegistrationTemplate.kt | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/protocol/src/main/java/com/zfoo/protocol/serializer/kotlin/CodeGenerateKotlin.java b/protocol/src/main/java/com/zfoo/protocol/serializer/kotlin/CodeGenerateKotlin.java index 9ce874c91..ff41b21f7 100644 --- a/protocol/src/main/java/com/zfoo/protocol/serializer/kotlin/CodeGenerateKotlin.java +++ b/protocol/src/main/java/com/zfoo/protocol/serializer/kotlin/CodeGenerateKotlin.java @@ -92,7 +92,7 @@ public void mergerProtocol(List registrations) throws IOEx for (var registration : registrations) { var protocol_id = registration.protocolId(); var protocol_name = registration.protocolConstructor().getDeclaringClass().getSimpleName(); - protocol_manager_registrations.append(StringUtils.format("protocols[{}] = Registration{}()", protocol_id, protocol_name)).append(LS); + protocol_manager_registrations.append(StringUtils.format("protocols[{}] = {}Registration()", protocol_id, protocol_name)).append(LS); protocol_manager_registrations.append(StringUtils.format("protocolIdMap.put({}::class.java, {})", protocol_name, protocol_id)).append(LS); } @@ -137,8 +137,8 @@ public void foldProtocol(List registrations) throws IOExce var protocol_id = registration.protocolId(); var protocol_name = registration.protocolConstructor().getDeclaringClass().getSimpleName(); protocol_imports.append(StringUtils.format("import {}.{}.{}", protocolPackage, GenerateProtocolPath.protocolPathPeriod(protocol_id), protocol_name)).append(LS); - protocol_imports.append(StringUtils.format("import {}.{}.Registration{}", protocolPackage, GenerateProtocolPath.protocolPathPeriod(protocol_id), protocol_name)).append(LS); - protocol_manager_registrations.append(StringUtils.format("protocols[{}] = Registration{}()", protocol_id, protocol_name)).append(LS); + protocol_imports.append(StringUtils.format("import {}.{}.{}Registration", protocolPackage, GenerateProtocolPath.protocolPathPeriod(protocol_id), protocol_name)).append(LS); + protocol_manager_registrations.append(StringUtils.format("protocols[{}] = {}Registration()", protocol_id, protocol_name)).append(LS); protocol_manager_registrations.append(StringUtils.format("protocolIdMap[{}::class.java] = {}.toShort()", protocol_name, protocol_id)).append(LS); } @@ -178,7 +178,7 @@ public void defaultProtocol(List registrations) throws IOE for (var registration : registrations) { var protocol_id = registration.protocolId(); var protocol_name = registration.protocolConstructor().getDeclaringClass().getSimpleName(); - protocol_manager_registrations.append(StringUtils.format("protocols[{}] = Registration{}()", protocol_id, protocol_name)).append(LS); + protocol_manager_registrations.append(StringUtils.format("protocols[{}] = {}Registration()", protocol_id, protocol_name)).append(LS); protocol_manager_registrations.append(StringUtils.format("protocolIdMap[{}::class.java] = {}.toShort()", protocol_name, protocol_id)).append(LS); } diff --git a/protocol/src/main/resources/kotlin/ProtocolRegistrationTemplate.kt b/protocol/src/main/resources/kotlin/ProtocolRegistrationTemplate.kt index 5c8d1aa16..44ba6a186 100644 --- a/protocol/src/main/resources/kotlin/ProtocolRegistrationTemplate.kt +++ b/protocol/src/main/resources/kotlin/ProtocolRegistrationTemplate.kt @@ -1,4 +1,4 @@ -class Registration${protocol_name} : IProtocolRegistration { +class ${protocol_name}Registration : IProtocolRegistration { override fun protocolId(): Short { return ${protocol_id} }