Skip to content

Commit

Permalink
Organize message mark code
Browse files Browse the repository at this point in the history
  • Loading branch information
temeddix committed Sep 17, 2024
1 parent 0294d91 commit af97db7
Showing 1 changed file with 45 additions and 24 deletions.
69 changes: 45 additions & 24 deletions flutter_package/bin/src/message.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -672,19 +672,19 @@ Future<void> insertTextToFile(
await file.writeAsString(fileContent);
}

Future<Map<String, Map<String, List<MarkedMessage>>>> analyzeMarkedMessages(
Future<Map<String, Map<String, List<MessageMark>>>> analyzeMarkedMessages(
Uri protoPath,
Map<String, List<String>> resourcesInFolders,
) async {
final markedMessages = <String, Map<String, List<MarkedMessage>>>{};
final messageMarks = <String, Map<String, List<MessageMark>>>{};
for (final entry in resourcesInFolders.entries) {
final subpath = entry.key;
final filenames = entry.value;
final markedMessagesInFiles = <String, List<MarkedMessage>>{};
final markedMessagesInFiles = <String, List<MessageMark>>{};
for (final filename in filenames) {
markedMessagesInFiles[filename] = [];
}
markedMessages[subpath] = markedMessagesInFiles;
messageMarks[subpath] = markedMessagesInFiles;
}
int messageId = 0;
for (final entry in resourcesInFolders.entries) {
Expand Down Expand Up @@ -716,42 +716,63 @@ Future<Map<String, Map<String, List<MarkedMessage>>>> 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,
));
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) {
Expand Down

0 comments on commit af97db7

Please sign in to comment.