From af97db7af26d6f631ddfcb95105c4e9785a46916 Mon Sep 17 00:00:00 2001 From: Donghyun Kim Date: Wed, 18 Sep 2024 00:49:11 +0900 Subject: [PATCH] Organize message mark code --- flutter_package/bin/src/message.dart | 69 ++++++++++++++++++---------- 1 file changed, 45 insertions(+), 24 deletions(-) diff --git a/flutter_package/bin/src/message.dart b/flutter_package/bin/src/message.dart index fdb5a9ed..abb1539c 100644 --- a/flutter_package/bin/src/message.dart +++ b/flutter_package/bin/src/message.dart @@ -17,11 +17,11 @@ enum MarkType { rustAttribute, } -class MarkedMessage { +class MessageMark { MarkType markType; String name; int id; - MarkedMessage( + MessageMark( this.markType, this.name, this.id, @@ -672,19 +672,19 @@ Future insertTextToFile( await file.writeAsString(fileContent); } -Future>>> analyzeMarkedMessages( +Future>>> analyzeMarkedMessages( Uri protoPath, Map> resourcesInFolders, ) async { - final markedMessages = >>{}; + final messageMarks = >>{}; for (final entry in resourcesInFolders.entries) { final subpath = entry.key; final filenames = entry.value; - final markedMessagesInFiles = >{}; + final markedMessagesInFiles = >{}; for (final filename in filenames) { markedMessagesInFiles[filename] = []; } - markedMessages[subpath] = markedMessagesInFiles; + messageMarks[subpath] = markedMessagesInFiles; } int messageId = 0; for (final entry in resourcesInFolders.entries) { @@ -716,21 +716,51 @@ Future>>> analyzeMarkedMessages( // When the statement is not a message continue; } - MarkType? markType = null; + + // Find [DART-SIGNAL] if (statement.contains('[DART-SIGNAL]')) { - markType = MarkType.dartSignal; + if (statement.contains('DART-SIGNAL-BINARY')) { + throw Exception( + '`DART-SIGNAL` and `DART-SIGNAL-BINARY` cannot be used together', + ); + } + messageMarks[subPath]![filename]!.add(MessageMark( + MarkType.dartSignal, + messageName, + messageId, + )); } else if (statement.contains('[DART-SIGNAL-BINARY]')) { - markType = MarkType.dartSignalBinary; - } else if (statement.contains('[RUST-SIGNAL]')) { - markType = MarkType.rustSignal; + messageMarks[subPath]![filename]!.add(MessageMark( + MarkType.dartSignalBinary, + messageName, + messageId, + )); + } + + // Find [RUST-SIGNAL] + if (statement.contains('[RUST-SIGNAL]')) { + if (statement.contains('RUST-SIGNAL-BINARY')) { + throw Exception( + '`RUST-SIGNAL` and `RUST-SIGNAL-BINARY` cannot be used together', + ); + } + messageMarks[subPath]![filename]!.add(MessageMark( + MarkType.rustSignal, + messageName, + messageId, + )); } else if (statement.contains('[RUST-SIGNAL-BINARY]')) { - markType = MarkType.rustSignalBinary; + messageMarks[subPath]![filename]!.add(MessageMark( + MarkType.rustSignalBinary, + messageName, + messageId, + )); } - // find [RUST-ATTRIBUTE(...)] + // Find [RUST-ATTRIBUTE(...)] var attr = attrExp.stringMatch(statement); if (attr != null) { - markedMessages[subPath]![filename]!.add(MarkedMessage( + messageMarks[subPath]![filename]!.add(MessageMark( MarkType.rustAttribute, "--prost_opt=type_attribute=$filename.$messageName=${attr.replaceAll(",", "\\,")}", -1, @@ -738,20 +768,11 @@ Future>>> analyzeMarkedMessages( continue; } - if (markType == null) { - // If there's no mark in the message, just ignore it - continue; - } - markedMessages[subPath]![filename]!.add(MarkedMessage( - markType, - messageName, - messageId, - )); messageId += 1; } } } - return markedMessages; + return messageMarks; } String pascalToCamel(String input) {